Author: toshok
Date: 2007-07-20 18:44:01 -0400 (Fri, 20 Jul 2007)
New Revision: 82392
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/canvas.cpp
trunk/moon/src/canvas.h
trunk/moon/src/panel.cpp
trunk/moon/src/panel.h
Log:
* canvas.cpp, canvas.h, panel.cpp, panel.h: move much of the guts
from Canvas to Panel. I consider this cleaning up the source, as
it's entirely possible to write Panel subclasses that aren't
Canvas subclasses, but if you did that you'd have no
rendering/event handling.
Now pretty much all logic that involves iterating over the list of
children is in Panel. This also greatly simplifies Canvas. It is
now just a Panel with 2 interesting things about it: 1) it
provides 2 attached properties to lay out its children, and 2) it
allows the surface to dictate its bounds if it's the toplevel
element.
2007-07-20 Chris Toshok <[EMAIL PROTECTED]>
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-07-20 22:30:46 UTC (rev 82391)
+++ trunk/moon/src/ChangeLog 2007-07-20 22:44:01 UTC (rev 82392)
@@ -1,5 +1,20 @@
2007-07-20 Chris Toshok <[EMAIL PROTECTED]>
+ * canvas.cpp, canvas.h, panel.cpp, panel.h: move much of the guts
+ from Canvas to Panel. I consider this cleaning up the source, as
+ it's entirely possible to write Panel subclasses that aren't
+ Canvas subclasses, but if you did that you'd have no
+ rendering/event handling.
+
+ Now pretty much all logic that involves iterating over the list of
+ children is in Panel. This also greatly simplifies Canvas. It is
+ now just a Panel with 2 interesting things about it: 1) it
+ provides 2 attached properties to lay out its children, and 2) it
+ allows the surface to dictate its bounds if it's the toplevel
+ element.
+
+2007-07-20 Chris Toshok <[EMAIL PROTECTED]>
+
* downloader.cpp (Open): set the uri of the downloader.
2007-07-20 Chris Toshok <[EMAIL PROTECTED]>
Modified: trunk/moon/src/canvas.cpp
===================================================================
--- trunk/moon/src/canvas.cpp 2007-07-20 22:30:46 UTC (rev 82391)
+++ trunk/moon/src/canvas.cpp 2007-07-20 22:44:01 UTC (rev 82392)
@@ -14,14 +14,13 @@
#include <gtk/gtk.h>
-#include "geometry.h"
#include "brush.h"
#include "rect.h"
#include "canvas.h"
#include "runtime.h"
#include "collection.h"
-Canvas::Canvas () : surface (NULL), mouse_over (NULL)
+Canvas::Canvas () : surface (NULL)
{
}
@@ -50,35 +49,6 @@
}
void
-Canvas::UpdateTransform ()
-{
- VisualCollection *children = GetChildren ();
- UIElement::UpdateTransform ();
- Collection::Node *n;
-
- //printf ("Am the canvas, and the xform is: %g %g\n",
absolute_xform.x0, absolute_xform.y0);
- n = (Collection::Node *) children->list->First ();
- while (n != NULL) {
- UIElement *item = (UIElement *) n->obj;
-
- item->UpdateTransform ();
-
- n = (Collection::Node *) n->Next ();
- }
-}
-
-#define DEBUG_BOUNDS 0
-
-#if DEBUG_BOUNDS
-void space (int n)
-{
- for (int i = 0; i < n; i++)
- putchar (' ');
-}
-static int levelb = 0;
-#endif
-
-void
Canvas::ComputeBounds ()
{
if (surface) {
@@ -86,72 +56,8 @@
bounds = Rect (0, 0, surface->GetWidth(), surface->GetHeight());
}
else {
- VisualCollection *children = GetChildren ();
- Collection::Node *cn;
- bool first = true;
-
-#if DEBUG_BOUNDS
- levelb += 4;
- space (levelb);
- printf ("Canvas: Enter ComputeBounds\n");
-#endif
- cn = (Collection::Node *) children->list->First ();
- for ( ; cn != NULL; cn = (Collection::Node *) cn->Next ()) {
- UIElement *item = (UIElement *) cn->obj;
-
- // if the item doesn't take part in layout
- // calculations, skip it
- if (!item->GetLayoutVisible ())
- continue;
-
- Rect r = item->GetBounds ();
-
-#if DEBUG_BOUNDS
- space (levelb + 4);
- printf ("Item (%s) bounds %g %g %g %g\n",
- dependency_object_get_name (item),r.x, r.y,
r.w, r.h);
-#endif
- if (first) {
- bounds = r;
- first = false;
- }
- else {
- bounds = bounds.Union (r);
- }
- }
-
- // If we found nothing.
- double x1, x2, y1, y2;
-
- x1 = y1 = 0.0;
- x2 = framework_element_get_width (this);
- y2 = framework_element_get_height (this);
-
- if (x2 != 0.0 && y2 != 0.0) {
- cairo_matrix_transform_point (&absolute_xform, &x1,
&y1);
- cairo_matrix_transform_point (&absolute_xform, &x2,
&y2);
-
- Rect fw_rect = Rect (x1, y1, x2 - x1, y2 - y1);
-
- if (first)
- bounds = fw_rect;
- else
- bounds = bounds.Union (fw_rect);
- }
-
- /* standard "grow the rectangle by enough to cover our
- asses because of cairo's floating point rendering"
- thing */
- bounds.x -= 1;
- bounds.y -= 1;
- bounds.w += 2;
- bounds.h += 2;
+ Panel::ComputeBounds ();
}
-#if DEBUG_BOUNDS
- space (levelb);
- printf ("Canvas: Leave ComputeBounds (%g %g %g %g)\n", bounds.x,
bounds.y, bounds.w, bounds.h);
- levelb -= 4;
-#endif
}
bool
@@ -174,143 +80,6 @@
return false;
}
-bool
-Canvas::InsideObject (cairo_t *cr, double x, double y)
-{
- /* if we have explicitly set width/height, we check them */
- if (FrameworkElement::InsideObject (cr, x, y)) {
- return true;
- }
-
- /* otherwise we try to figure out if we're inside one of our child
elements */
- UIElement *mouseover = FindMouseOver (cr, x, y);
-
- return mouseover != NULL;
-}
-
-bool
-Canvas::CheckOver (cairo_t *cr, UIElement *item, double x, double y)
-{
- // if the item isn't visible, it's really easy
- if (!item->GetVisible ())
- return false;
-
- // if the item doesn't take part in hit testing, it's also easy
- if (!item->GetHitTestVisible ())
- return false;
-
- // first a quick bounds check
- if (!item->GetBounds().PointInside (x, y))
- return false;
-
- // then, if that passes, a more tailored shape check
- if (!item->InsideObject (cr, x, y))
- return false;
-
- return true;
-}
-
-UIElement *
-Canvas::FindMouseOver (cairo_t *cr, double x, double y)
-{
- VisualCollection *children = GetChildren ();
- Collection::Node *cn;
-
- // Walk the list in reverse order, since it's sorted in ascending
z-index order
- //
- for (cn = (Collection::Node *) children->z_sorted_list->Last (); cn !=
NULL; cn = (Collection::Node *) cn->Prev ()) {
- UIElement *item = (UIElement *) cn->obj;
-
- if (CheckOver (cr, item, x, y)) {
- // printf (" mouse_over = %s\n",
item->GetName());
- return item;
- }
- }
-
- return NULL;
-}
-
-void
-Canvas::HandleMotion (cairo_t *cr, int state, double x, double y, MouseCursor
*cursor)
-{
- UIElement *new_over = FindMouseOver (cr, x, y);
-
- if (new_over != mouse_over) {
- if (mouse_over)
- mouse_over->Leave ();
-
- mouse_over = new_over;
-
- if (mouse_over)
- mouse_over->Enter (cr, state, x, y);
- }
-
- if (cursor && *cursor == MouseCursorDefault)
- *cursor = (MouseCursor)GetValue
(UIElement::CursorProperty)->AsInt32();
-
- if (mouse_over)
- mouse_over->HandleMotion (cr, state, x, y, cursor);
-
- if (mouse_over || InsideObject (cr, x, y))
- UIElement::HandleMotion (cr, state, x, y, NULL);
-}
-
-void
-Canvas::HandleButtonPress (cairo_t *cr, int state, double x, double y)
-{
- // not sure if this is correct, but we don't bother updating
- // the current mouse_over here (and along with that, emitting
- // enter/leave events).
- if (mouse_over) {
- if (mouse_over->GetBounds().PointInside (x, y)
- && mouse_over->InsideObject (cr, x, y)) {
-
- mouse_over->HandleButtonPress (cr, state, x, y);
- }
- }
-
- UIElement::HandleButtonPress (cr, state, x, y);
-}
-
-void
-Canvas::HandleButtonRelease (cairo_t *cr, int state, double x, double y)
-{
- // not sure if this is correct, but we don't bother updating
- // the current mouse_over here (and along with that, emitting
- // enter/leave events).
- if (mouse_over) {
- if (mouse_over->GetBounds().PointInside (x, y)
- && mouse_over->InsideObject (cr, x, y)) {
-
- mouse_over->HandleButtonRelease (cr, state, x, y);
- }
- }
-
- UIElement::HandleButtonRelease (cr, state, x, y);
-}
-
-void
-Canvas::Enter (cairo_t *cr, int state, double x, double y)
-{
- mouse_over = FindMouseOver (cr, x, y);
-
- if (mouse_over)
- mouse_over->Enter (cr, state, x, y);
-
- UIElement::Enter (cr, state, x, y);
-}
-
-void
-Canvas::Leave ()
-{
- if (mouse_over) {
- mouse_over->Leave ();
- mouse_over = NULL;
- }
-
- UIElement::Leave ();
-}
-
Point
Canvas::GetTransformOrigin ()
{
@@ -319,109 +88,6 @@
framework_element_get_height (this) *
user_xform_origin.y);
}
-static int level = 0;
-
-//#define DEBUG_INVALIDATE 1
-
-void
-Canvas::Render (cairo_t *cr, int x, int y, int width, int height)
-{
- VisualCollection *children = GetChildren ();
- Collection::Node *cn;
-
- cairo_save (cr); // for UIElement::ClipProperty
-
- cairo_set_matrix (cr, &absolute_xform);
-
- Value *value = GetValue (Canvas::ClipProperty);
- if (value) {
- Geometry *geometry = value->AsGeometry ();
- geometry->Draw (cr);
- cairo_clip (cr);
- }
-
- value = GetValue (Panel::BackgroundProperty);
- if (value) {
- double fwidth = framework_element_get_width (this);
- double fheight = framework_element_get_height (this);
-
- if (fwidth > 0 && fheight > 0){
- Brush *background = value->AsBrush ();
- background->SetupBrush (cr, this);
-
- // FIXME - UIElement::Opacity may play a role here
- cairo_rectangle (cr, 0, 0, fwidth, fheight);
- cairo_fill (cr);
- }
- }
-
- Rect render_rect (x, y, width, height);
-
- level += 4;
-
- //
- // from this point on, we use the identity matrix to set the clipping
- // path for the children
- //
- cairo_identity_matrix (cr);
- cn = (Collection::Node *) children->z_sorted_list->First ();
- for ( ; cn != NULL; cn = (Collection::Node *) cn->Next ()) {
- UIElement *item = (UIElement *) cn->obj;
-
- if (!item->GetVisible()) {
-#ifdef DEBUG_INVALIDATE
- printf ("skipping invisible object %s: %p (%s)\n",
item->GetName (), item, item->GetTypeName());
-#endif
- continue;
- }
-
- //space (level);
- //printf ("%s %g %g %g %g\n", dependency_object_get_name
(item), item->x1, item->y1, item->x2, item->y2);
-
- if (render_rect.IntersectsWith (item->GetBounds())) {
- Rect inter =
render_rect.Intersection(item->GetBounds());
-#if CAIRO_CLIP
-#if TIME_CLIP
- STARTTIMER(clip, "cairo clip setup");
-#endif
- cairo_save (cr);
-
- //printf ("Clipping to %g %g %g %g\n", inter.x,
inter.y, inter.w, inter.h);
- // at the very least we need to clip based on the
expose area.
- // there's also a UIElement::ClipProperty
- cairo_rectangle (cr, inter.x-1, inter.y-1, inter.w + 2,
inter.h + 2);
- cairo_clip (cr);
-#if TIME_CLIP
- ENDTIMER(clip, "cairo clip setup");
-#endif
-#endif
- item->DoRender (cr, (int)inter.x-1, (int)inter.y-1,
(int)inter.w + 2, (int)inter.h + 2);
-
-#if CAIRO_CLIP
-#if TIME_CLIP
- STARTTIMER(endclip, "cairo clip teardown");
-#endif
- cairo_restore (cr);
-
-#if TIME_CLIP
- ENDTIMER(endclip, "cairo clip teardown");
-#endif
-#endif
- }
-#ifdef DEBUG_INVALIDATE
- else {
- printf ("skipping object %s: %p (%s)\n",
item->GetName(), item, item->GetTypeName());
- }
-#endif
-
- }
- //printf ("RENDER: LEAVE\n");
- //draw_grid (cr);
-
- level -= 4;
- cairo_restore (cr);
-}
-
Canvas *
canvas_new (void)
{
Modified: trunk/moon/src/canvas.h
===================================================================
--- trunk/moon/src/canvas.h 2007-07-20 22:30:46 UTC (rev 82391)
+++ trunk/moon/src/canvas.h 2007-07-20 22:44:01 UTC (rev 82392)
@@ -32,32 +32,13 @@
virtual Surface *GetSurface ();
- //
- // Contains the last element where the mouse entered
- //
- UIElement *mouse_over;
-
virtual Type::Kind GetObjectType () { return Type::CANVAS; }
Point GetTransformOrigin ();
- virtual void Render (cairo_t *cr, int x, int y, int width, int height);
virtual void ComputeBounds ();
- virtual void UpdateTransform ();
virtual void GetTransformFor (UIElement *item, cairo_matrix_t *result);
- bool CheckOver (cairo_t *cr, UIElement *item, double x, double y);
-
- virtual UIElement* FindMouseOver (cairo_t *cr, double x, double y);
-
- virtual bool InsideObject (cairo_t *cr, double x, double y);
-
- virtual void HandleMotion (cairo_t *cr, int state, double x, double y,
MouseCursor *cursor);
- virtual void HandleButtonPress (cairo_t *cr, int state, double x,
double y);
- virtual void HandleButtonRelease (cairo_t *cr, int state, double x,
double y);
- virtual void Enter (cairo_t *cr, int state, double x, double y);
- virtual void Leave ();
-
virtual bool OnChildPropertyChanged (DependencyProperty *prop,
DependencyObject *child);
static DependencyProperty* TopProperty;
Modified: trunk/moon/src/panel.cpp
===================================================================
--- trunk/moon/src/panel.cpp 2007-07-20 22:30:46 UTC (rev 82391)
+++ trunk/moon/src/panel.cpp 2007-07-20 22:44:01 UTC (rev 82392)
@@ -11,6 +11,7 @@
#include <gtk/gtk.h>
+#include "geometry.h"
#include "panel.h"
#include "brush.h"
#include "collection.h"
@@ -51,6 +52,7 @@
{
this->SetValue (Panel::ChildrenProperty, Value (new VisualCollection
()));
background = NULL;
+ mouse_over = NULL;
}
Panel::~Panel ()
@@ -61,6 +63,348 @@
}
}
+
+void
+Panel::UpdateTransform ()
+{
+ VisualCollection *children = GetChildren ();
+ FrameworkElement::UpdateTransform ();
+ Collection::Node *n;
+
+ //printf ("Am the canvas, and the xform is: %g %g\n",
absolute_xform.x0, absolute_xform.y0);
+ n = (Collection::Node *) children->list->First ();
+ while (n != NULL) {
+ UIElement *item = (UIElement *) n->obj;
+
+ item->UpdateTransform ();
+
+ n = (Collection::Node *) n->Next ();
+ }
+}
+
+#define DEBUG_BOUNDS 0
+
+#if DEBUG_BOUNDS
+void space (int n)
+{
+ for (int i = 0; i < n; i++)
+ putchar (' ');
+}
+static int levelb = 0;
+#endif
+
+void
+Panel::ComputeBounds ()
+{
+ VisualCollection *children = GetChildren ();
+ Collection::Node *cn;
+ bool first = true;
+
+#if DEBUG_BOUNDS
+ levelb += 4;
+ space (levelb);
+ printf ("Panel: Enter ComputeBounds\n");
+#endif
+ cn = (Collection::Node *) children->list->First ();
+ for ( ; cn != NULL; cn = (Collection::Node *) cn->Next ()) {
+ UIElement *item = (UIElement *) cn->obj;
+
+ // if the item doesn't take part in layout
+ // calculations, skip it
+ if (!item->GetLayoutVisible ())
+ continue;
+
+ Rect r = item->GetBounds ();
+
+#if DEBUG_BOUNDS
+ space (levelb + 4);
+ printf ("Item (%s) bounds %g %g %g %g\n",
+ dependency_object_get_name (item),r.x, r.y, r.w, r.h);
+#endif
+ if (first) {
+ bounds = r;
+ first = false;
+ }
+ else {
+ bounds = bounds.Union (r);
+ }
+ }
+
+ // If we found nothing.
+ double x1, x2, y1, y2;
+
+ x1 = y1 = 0.0;
+ x2 = framework_element_get_width (this);
+ y2 = framework_element_get_height (this);
+
+ if (x2 != 0.0 && y2 != 0.0) {
+ cairo_matrix_transform_point (&absolute_xform, &x1, &y1);
+ cairo_matrix_transform_point (&absolute_xform, &x2, &y2);
+
+ Rect fw_rect = Rect (x1, y1, x2 - x1, y2 - y1);
+
+ if (first)
+ bounds = fw_rect;
+ else
+ bounds = bounds.Union (fw_rect);
+ }
+
+ /* standard "grow the rectangle by enough to cover our
+ asses because of cairo's floating point rendering"
+ thing */
+ bounds.x -= 1;
+ bounds.y -= 1;
+ bounds.w += 2;
+ bounds.h += 2;
+
+#if DEBUG_BOUNDS
+ space (levelb);
+ printf ("Panel: Leave ComputeBounds (%g %g %g %g)\n", bounds.x,
bounds.y, bounds.w, bounds.h);
+ levelb -= 4;
+#endif
+}
+
+
+static int level = 0;
+
+//#define DEBUG_INVALIDATE 1
+
+void
+Panel::Render (cairo_t *cr, int x, int y, int width, int height)
+{
+ VisualCollection *children = GetChildren ();
+ Collection::Node *cn;
+
+ cairo_save (cr); // for UIElement::ClipProperty
+
+ cairo_set_matrix (cr, &absolute_xform);
+
+ Value *value = GetValue (UIElement::ClipProperty);
+ if (value) {
+ Geometry *geometry = value->AsGeometry ();
+ geometry->Draw (cr);
+ cairo_clip (cr);
+ }
+
+ value = GetValue (Panel::BackgroundProperty);
+ if (value) {
+ double fwidth = framework_element_get_width (this);
+ double fheight = framework_element_get_height (this);
+
+ if (fwidth > 0 && fheight > 0){
+ Brush *background = value->AsBrush ();
+ background->SetupBrush (cr, this);
+
+ // FIXME - UIElement::Opacity may play a role here
+ cairo_rectangle (cr, 0, 0, fwidth, fheight);
+ cairo_fill (cr);
+ }
+ }
+
+ Rect render_rect (x, y, width, height);
+
+ level += 4;
+
+ //
+ // from this point on, we use the identity matrix to set the clipping
+ // path for the children
+ //
+ cairo_identity_matrix (cr);
+ cn = (Collection::Node *) children->z_sorted_list->First ();
+ for ( ; cn != NULL; cn = (Collection::Node *) cn->Next ()) {
+ UIElement *item = (UIElement *) cn->obj;
+
+ if (!item->GetVisible()) {
+#ifdef DEBUG_INVALIDATE
+ printf ("skipping invisible object %s: %p (%s)\n",
item->GetName (), item, item->GetTypeName());
+#endif
+ continue;
+ }
+
+ //space (level);
+ //printf ("%s %g %g %g %g\n", dependency_object_get_name
(item), item->x1, item->y1, item->x2, item->y2);
+
+ if (render_rect.IntersectsWith (item->GetBounds())) {
+ Rect inter =
render_rect.Intersection(item->GetBounds());
+#if CAIRO_CLIP
+#if TIME_CLIP
+ STARTTIMER(clip, "cairo clip setup");
+#endif
+ cairo_save (cr);
+
+ //printf ("Clipping to %g %g %g %g\n", inter.x,
inter.y, inter.w, inter.h);
+ // at the very least we need to clip based on the
expose area.
+ // there's also a UIElement::ClipProperty
+ cairo_rectangle (cr, inter.x-1, inter.y-1, inter.w + 2,
inter.h + 2);
+ cairo_clip (cr);
+#if TIME_CLIP
+ ENDTIMER(clip, "cairo clip setup");
+#endif
+#endif
+ item->DoRender (cr, (int)inter.x-1, (int)inter.y-1,
(int)inter.w + 2, (int)inter.h + 2);
+
+#if CAIRO_CLIP
+#if TIME_CLIP
+ STARTTIMER(endclip, "cairo clip teardown");
+#endif
+ cairo_restore (cr);
+
+#if TIME_CLIP
+ ENDTIMER(endclip, "cairo clip teardown");
+#endif
+#endif
+ }
+#ifdef DEBUG_INVALIDATE
+ else {
+ printf ("skipping object %s: %p (%s)\n",
item->GetName(), item, item->GetTypeName());
+ }
+#endif
+
+ }
+ //printf ("RENDER: LEAVE\n");
+ //draw_grid (cr);
+
+ level -= 4;
+ cairo_restore (cr);
+}
+
+bool
+Panel::InsideObject (cairo_t *cr, double x, double y)
+{
+ /* if we have explicitly set width/height, we check them */
+ if (FrameworkElement::InsideObject (cr, x, y)) {
+ return true;
+ }
+
+ /* otherwise we try to figure out if we're inside one of our child
elements */
+ UIElement *mouseover = FindMouseOver (cr, x, y);
+
+ return mouseover != NULL;
+}
+
+bool
+Panel::CheckOver (cairo_t *cr, UIElement *item, double x, double y)
+{
+ // if the item isn't visible, it's really easy
+ if (!item->GetVisible ())
+ return false;
+
+ // if the item doesn't take part in hit testing, it's also easy
+ if (!item->GetHitTestVisible ())
+ return false;
+
+ // first a quick bounds check
+ if (!item->GetBounds().PointInside (x, y))
+ return false;
+
+ // then, if that passes, a more tailored shape check
+ if (!item->InsideObject (cr, x, y))
+ return false;
+
+ return true;
+}
+
+UIElement *
+Panel::FindMouseOver (cairo_t *cr, double x, double y)
+{
+ VisualCollection *children = GetChildren ();
+ Collection::Node *cn;
+
+ // Walk the list in reverse order, since it's sorted in ascending
z-index order
+ //
+ for (cn = (Collection::Node *) children->z_sorted_list->Last (); cn !=
NULL; cn = (Collection::Node *) cn->Prev ()) {
+ UIElement *item = (UIElement *) cn->obj;
+
+ if (CheckOver (cr, item, x, y)) {
+ // printf (" mouse_over = %s\n",
item->GetName());
+ return item;
+ }
+ }
+
+ return NULL;
+}
+
+void
+Panel::HandleMotion (cairo_t *cr, int state, double x, double y, MouseCursor
*cursor)
+{
+ UIElement *new_over = FindMouseOver (cr, x, y);
+
+ if (new_over != mouse_over) {
+ if (mouse_over)
+ mouse_over->Leave ();
+
+ mouse_over = new_over;
+
+ if (mouse_over)
+ mouse_over->Enter (cr, state, x, y);
+ }
+
+ if (cursor && *cursor == MouseCursorDefault)
+ *cursor = (MouseCursor)GetValue
(UIElement::CursorProperty)->AsInt32();
+
+ if (mouse_over)
+ mouse_over->HandleMotion (cr, state, x, y, cursor);
+
+ if (mouse_over || InsideObject (cr, x, y))
+ FrameworkElement::HandleMotion (cr, state, x, y, NULL);
+}
+
+void
+Panel::HandleButtonPress (cairo_t *cr, int state, double x, double y)
+{
+ // not sure if this is correct, but we don't bother updating
+ // the current mouse_over here (and along with that, emitting
+ // enter/leave events).
+ if (mouse_over) {
+ if (mouse_over->GetBounds().PointInside (x, y)
+ && mouse_over->InsideObject (cr, x, y)) {
+
+ mouse_over->HandleButtonPress (cr, state, x, y);
+ }
+ }
+
+ FrameworkElement::HandleButtonPress (cr, state, x, y);
+}
+
+void
+Panel::HandleButtonRelease (cairo_t *cr, int state, double x, double y)
+{
+ // not sure if this is correct, but we don't bother updating
+ // the current mouse_over here (and along with that, emitting
+ // enter/leave events).
+ if (mouse_over) {
+ if (mouse_over->GetBounds().PointInside (x, y)
+ && mouse_over->InsideObject (cr, x, y)) {
+
+ mouse_over->HandleButtonRelease (cr, state, x, y);
+ }
+ }
+
+ FrameworkElement::HandleButtonRelease (cr, state, x, y);
+}
+
+void
+Panel::Enter (cairo_t *cr, int state, double x, double y)
+{
+ mouse_over = FindMouseOver (cr, x, y);
+
+ if (mouse_over)
+ mouse_over->Enter (cr, state, x, y);
+
+ FrameworkElement::Enter (cr, state, x, y);
+}
+
+void
+Panel::Leave ()
+{
+ if (mouse_over) {
+ mouse_over->Leave ();
+ mouse_over = NULL;
+ }
+
+ FrameworkElement::Leave ();
+}
+
//
// Intercept any changes to the children property and mirror that into our
// own variable
Modified: trunk/moon/src/panel.h
===================================================================
--- trunk/moon/src/panel.h 2007-07-20 22:30:46 UTC (rev 82391)
+++ trunk/moon/src/panel.h 2007-07-20 22:44:01 UTC (rev 82392)
@@ -14,6 +14,11 @@
class Panel : public FrameworkElement {
Brush *background;
+
+ //
+ // Contains the last element where the mouse entered
+ //
+ UIElement *mouse_over;
public:
Panel ();
virtual ~Panel ();
@@ -22,6 +27,22 @@
VisualCollection *GetChildren ();
void SetChildren (VisualCollection *col);
+ virtual void UpdateTransform ();
+ virtual void ComputeBounds ();
+ virtual void Render (cairo_t *cr, int x, int y, int width, int height);
+
+ bool CheckOver (cairo_t *cr, UIElement *item, double x, double y);
+
+ virtual UIElement* FindMouseOver (cairo_t *cr, double x, double y);
+
+ virtual bool InsideObject (cairo_t *cr, double x, double y);
+
+ virtual void HandleMotion (cairo_t *cr, int state, double x, double y,
MouseCursor *cursor);
+ virtual void HandleButtonPress (cairo_t *cr, int state, double x,
double y);
+ virtual void HandleButtonRelease (cairo_t *cr, int state, double x,
double y);
+ virtual void Enter (cairo_t *cr, int state, double x, double y);
+ virtual void Leave ();
+
static DependencyProperty* ChildrenProperty;
static DependencyProperty* BackgroundProperty;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches