Author: fejj
Date: 2007-06-19 13:32:31 -0400 (Tue, 19 Jun 2007)
New Revision: 80208

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/text.cpp
   trunk/moon/src/text.h
Log:
2007-06-19  Jeffrey Stedfast  <[EMAIL PROTECTED]>

        * text.cpp (Run::OnPropertyChanged): Always chain up to our parent
        implementation and if one of our properties changed, notify our
        attachees.
        (Inline::OnPropertyChanged): Same.
        (TextBlock::OnPropertyChanged): Keep track of Inlines changes.
        (TextBlock::Draw): Use our foreground brush directly and the same
        for run's foreground brush.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-06-19 17:31:23 UTC (rev 80207)
+++ trunk/moon/src/ChangeLog    2007-06-19 17:32:31 UTC (rev 80208)
@@ -1,3 +1,13 @@
+2007-06-19  Jeffrey Stedfast  <[EMAIL PROTECTED]>
+
+       * text.cpp (Run::OnPropertyChanged): Always chain up to our parent
+       implementation and if one of our properties changed, notify our
+       attachees.
+       (Inline::OnPropertyChanged): Same.
+       (TextBlock::OnPropertyChanged): Keep track of Inlines changes.
+       (TextBlock::Draw): Use our foreground brush directly and the same
+       for run's foreground brush.
+
 2007-06-19  Miguel de Icaza  <[EMAIL PROTECTED]>
 
        * runtime.cpp: Implement collection iterators.

Modified: trunk/moon/src/text.cpp
===================================================================
--- trunk/moon/src/text.cpp     2007-06-19 17:31:23 UTC (rev 80207)
+++ trunk/moon/src/text.cpp     2007-06-19 17:32:31 UTC (rev 80208)
@@ -75,6 +75,18 @@
 }
 
 
+static Brush *
+default_foreground (void)
+{
+       SolidColorBrush *brush = new SolidColorBrush ();
+       Color *color = color_from_str ("black");
+       solid_color_brush_set_color (brush, color);
+       delete color;
+       
+       return (Brush *) brush;
+}
+
+
 // Inline
 
 DependencyProperty *Inline::FontFamilyProperty;
@@ -89,10 +101,10 @@
 void
 Inline::OnPropertyChanged (DependencyProperty *prop)
 {
-       if (prop->type != Type::INLINE) {
-               DependencyObject::OnPropertyChanged (prop);
-               return;
-       }
+       if (prop->type == Type::INLINE)
+               NotifyAttacheesOfPropertyChange (prop);
+       
+       DependencyObject::OnPropertyChanged (prop);
 }
 
 char *
@@ -201,6 +213,8 @@
 {
        layout = NULL;
        
+       foreground = NULL;
+       
        /* initialize the font description */
        font = pango_font_description_new ();
        char *family = inline_get_font_family (this);
@@ -221,6 +235,11 @@
        
        if (layout != NULL)
                g_object_unref (layout);
+       
+       if (foreground != NULL) {
+               foreground->Detach (NULL, this);
+               foreground->unref ();
+       }
 }
 
 void
@@ -228,8 +247,6 @@
 {
        bool font_changed = false;
        
-       // FIXME: need to invalidate our parent TextBlock
-       
        if (prop == Inline::FontFamilyProperty) {
                char *family = inline_get_font_family (this);
                pango_font_description_set_family (font, family);
@@ -250,16 +267,28 @@
                FontWeights weight = inline_get_font_weight (this);
                pango_font_description_set_weight (font, font_weight (weight));
                font_changed = true;
+       } else if (prop == Inline::ForegroundProperty) {
+               if (foreground != NULL) {
+                       foreground->Detach (NULL, this);
+                       foreground->unref ();
+               }
+               
+               if ((foreground = inline_get_foreground (this)) != NULL) {
+                       foreground->Attach (NULL, this);
+                       foreground->ref ();
+               }
        } else if (prop == Run::TextProperty && layout != NULL) {
                char *text = run_get_text (this);
                pango_layout_set_text (layout, text ? text : "", -1);
-       } else {
-               Inline::OnPropertyChanged (prop);
-               return;
        }
        
        if (font_changed && layout != NULL)
                pango_layout_set_font_description (layout, font);
+       
+       if (prop->type == Type::RUN)
+               NotifyAttacheesOfPropertyChange (prop);
+       
+       Inline::OnPropertyChanged (prop);
 }
 
 Run *
@@ -301,14 +330,13 @@
 
 TextBlock::TextBlock ()
 {
-       SolidColorBrush *brush = new SolidColorBrush ();
-       Color *color = color_from_str ("black");
-       solid_color_brush_set_color (brush, color);
-       delete color;
+       Brush *brush = default_foreground ();
        
        foreground = NULL;
        SetValue (TextBlock::ForegroundProperty, Value (brush));
        
+       inlines = NULL;
+       
        layout = NULL;
        
        height = -1;
@@ -335,6 +363,11 @@
        if (layout)
                g_object_unref (layout);
        
+       if (inlines != NULL) {
+               inlines->Detach (NULL, this);
+               inlines->unref ();
+       }
+       
        if (foreground != NULL) {
                foreground->Detach (NULL, this);
                foreground->unref ();
@@ -459,8 +492,6 @@
 TextBlock::Draw (Surface *s, bool render, int *w, int *h)
 {
        int full_width = 0, full_height = 0;
-       Inlines *inlines;
-       Brush *brush;
        char *text;
        
        text = text_block_get_text (this);
@@ -490,8 +521,7 @@
        
        if (text && *text) {
                if (render) {
-                       if ((brush = text_block_get_foreground (this)))
-                               brush->SetupBrush (s->cairo, this);
+                       foreground->SetupBrush (s->cairo, this);
                        pango_cairo_show_layout (s->cairo, layout);
                } else
                        pango_cairo_layout_path (s->cairo, layout);
@@ -499,7 +529,7 @@
                pango_layout_get_pixel_size (layout, &full_width, &full_height);
        }
        
-       if ((inlines = text_block_get_inlines (this))) {
+       if (inlines != NULL) {
                PangoFontDescription *cur_font = font;
                GList *next, *node = inlines->list;
                int width, height, x = 0, y = 0;
@@ -546,8 +576,10 @@
                                }
                                
                                if (render) {
-                                       if ((brush = inline_get_foreground 
(item)))
-                                               brush->SetupBrush (s->cairo, 
this);
+                                       if (run->foreground != NULL)
+                                               run->foreground->SetupBrush 
(s->cairo, this);
+                                       else
+                                               foreground->SetupBrush 
(s->cairo, this);
                                        
                                        pango_cairo_show_layout (s->cairo, 
run->layout);
                                } else
@@ -630,6 +662,16 @@
        } else if (prop == TextBlock::TextProperty && layout != NULL) {
                char *text = text_block_get_text (this);
                pango_layout_set_text (layout, text ? text : "", -1);
+       } else if (prop == TextBlock::InlinesProperty) {
+               if (inlines != NULL) {
+                       inlines->Detach (NULL, this);
+                       inlines->unref ();
+               }
+               
+               if ((inlines = text_block_get_inlines (this)) != NULL) {
+                       inlines->Attach (NULL, this);
+                       inlines->ref ();
+               }
        } else if (prop == TextBlock::ForegroundProperty) {
                if (foreground != NULL) {
                        foreground->Detach (NULL, this);
@@ -651,6 +693,14 @@
        FullInvalidate (false);
 }
 
+void
+TextBlock::OnSubPropertyChanged (DependencyProperty *prop, DependencyProperty 
*subprop)
+{
+       FullInvalidate (false);
+       
+       FrameworkElement::OnSubPropertyChanged (prop, subprop);
+}
+
 TextBlock *
 text_block_new (void)
 {

Modified: trunk/moon/src/text.h
===================================================================
--- trunk/moon/src/text.h       2007-06-19 17:31:23 UTC (rev 80207)
+++ trunk/moon/src/text.h       2007-06-19 17:32:31 UTC (rev 80208)
@@ -113,6 +113,7 @@
        
        PangoFontDescription *font;
        PangoLayout *layout;
+       Brush *foreground;
        
        Run ();
        ~Run ();
@@ -128,6 +129,7 @@
 
 class TextBlock : public FrameworkElement {
        Brush *foreground;
+       Inlines *inlines;
 public:
        static DependencyProperty *ActualHeightProperty;
        static DependencyProperty *ActualWidthProperty;
@@ -157,6 +159,7 @@
        virtual Point getxformorigin ();
        virtual bool inside_object (Surface *s, double x, double y);
        virtual void OnPropertyChanged (DependencyProperty *prop);
+       virtual void OnSubPropertyChanged (DependencyProperty *prop, 
DependencyProperty *subprop);
        
 private:
        PangoFontDescription *font;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to