Author: spouliot
Date: 2007-09-04 13:57:54 -0400 (Tue, 04 Sep 2007)
New Revision: 85312

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/text.cpp
   trunk/moon/src/text.h
Log:
2007-09-04  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * text.h|cpp: TextBlock actual_[height|width] are already cached 
        because they're expansive to calculate. Make sure we don't compute
        them until they're really required (e.g. when a lot of properties
        changes when loading an XAML file).



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-09-04 17:51:44 UTC (rev 85311)
+++ trunk/moon/src/ChangeLog    2007-09-04 17:57:54 UTC (rev 85312)
@@ -1,3 +1,10 @@
+2007-09-04  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * text.h|cpp: TextBlock actual_[height|width] are already cached 
+       because they're expansive to calculate. Make sure we don't compute
+       them until they're really required (e.g. when a lot of properties
+       changes when loading an XAML file).
+
 2007-09-04  Chris Toshok  <[EMAIL PROTECTED]>
 
        * animation.cpp (KeyFrameAnimation_ResolveKeyFrames): add the

Modified: trunk/moon/src/text.cpp
===================================================================
--- trunk/moon/src/text.cpp     2007-09-04 17:51:44 UTC (rev 85311)
+++ trunk/moon/src/text.cpp     2007-09-04 17:57:54 UTC (rev 85312)
@@ -324,6 +324,7 @@
        
        actual_height = 0.0;
        actual_width = 0.0;
+       dirty_actual_values = true;
        
        /* initialize the font description */
        font = pango_font_description_new ();
@@ -382,7 +383,7 @@
 void 
 TextBlock::ComputeBounds ()
 {
-       bounds = bounding_rect_for_transformed_rect (&absolute_xform, Rect (0, 
0, actual_width, actual_height));
+       bounds = bounding_rect_for_transformed_rect (&absolute_xform, Rect (0, 
0, GetActualWidth (), GetActualHeight ()));
 // no-op       bounds.GrowBy (1);
 }
 
@@ -391,7 +392,7 @@
 {
        Point user_xform_origin = GetRenderTransformOrigin ();
        
-       return Point (user_xform_origin.x * actual_width, user_xform_origin.y * 
actual_height);
+       return Point (user_xform_origin.x * GetActualWidth (), 
user_xform_origin.y * GetActualHeight ());
 }
 
 bool
@@ -424,8 +425,8 @@
 void
 TextBlock::GetSizeForBrush (cairo_t *cr, double *width, double *height)
 {
-       *height = actual_height;
-       *width = actual_width;
+       *height = GetActualHeight ();
+       *width = GetActualWidth ();
 }
 
 void
@@ -450,9 +451,6 @@
                cairo_new_path (cr);
                cairo_restore (cr);
        }
-       
-       text_block_set_actual_height (this, actual_height);
-       text_block_set_actual_width (this, actual_width);
 }
 
 void
@@ -649,22 +647,23 @@
        mango_renderer_layout_path (renderer, layout);
        pango_layout_get_pixel_size (layout, &w, &h);
        
-       actual_height = (double) h;
-       actual_width = (double) w;
-       
-       if (clip && actual_height > clip_height)
-               actual_height = clip_height;
+       if (clip && (h > clip_height))
+               text_block_set_actual_height (this, (double)clip_height);
+       else
+               text_block_set_actual_height (this, (double)h);
+       text_block_set_actual_width (this, (double)w);
+       dirty_actual_values = false;
 }
 
 void
 TextBlock::Paint (cairo_t *cr)
 {
        TextWrapping wrapping = text_block_get_text_wrapping (this);
-       double h = framework_element_get_height (this);
+       double h = GetActualHeight ();
        double w = framework_element_get_width (this);
 
-       if (wrapping == TextWrappingWrapWithOverflow)
-               h = actual_height;
+       if (wrapping != TextWrappingWrapWithOverflow)
+               h = framework_element_get_height (this);
        
        if (w > 0.0 && h > 0.0) {
                cairo_rectangle (cr, 0, 0, w, h);
@@ -722,7 +721,7 @@
        }
        
        if (prop != TextBlock::ActualHeightProperty && prop != 
TextBlock::ActualWidthProperty) {
-               CalcActualWidthHeight (NULL);
+               dirty_actual_values = true;
                UpdateBounds (true);
                Invalidate ();
        }
@@ -734,7 +733,7 @@
 TextBlock::OnSubPropertyChanged (DependencyProperty *prop, DependencyProperty 
*subprop)
 {
        if (prop == TextBlock::ForegroundProperty) {
-               CalcActualWidthHeight (NULL);
+               dirty_actual_values = true;
                Invalidate ();
        } else
                FrameworkElement::OnSubPropertyChanged (prop, subprop);
@@ -743,10 +742,38 @@
 void
 TextBlock::OnCollectionChanged (Collection *col, CollectionChangeType type, 
DependencyObject *obj, DependencyProperty *prop)
 {
-       CalcActualWidthHeight (NULL);
+       dirty_actual_values = true;
        UpdateBounds (true);
 }
 
+Value *
+TextBlock::GetValue (DependencyProperty *property)
+{
+       if (dirty_actual_values && ((property == 
TextBlock::ActualHeightProperty) || (property == 
TextBlock::ActualWidthProperty)))
+               CalcActualWidthHeight (NULL);
+
+       return DependencyObject::GetValue (property);
+}
+
+void
+TextBlock::SetValue (DependencyProperty *property, Value *value)
+{
+       if (value) {
+               if (property == TextBlock::ActualHeightProperty)
+                       actual_height = value->AsDouble ();
+               else if (property == TextBlock::ActualWidthProperty)
+                       actual_width = value->AsDouble ();
+       }
+       return DependencyObject::SetValue (property, value);
+}
+
+void
+TextBlock::SetValue (DependencyProperty *property, Value value)
+{
+       SetValue (property, &value);
+}
+
+
 TextBlock *
 text_block_new (void)
 {

Modified: trunk/moon/src/text.h
===================================================================
--- trunk/moon/src/text.h       2007-09-04 17:51:44 UTC (rev 85311)
+++ trunk/moon/src/text.h       2007-09-04 17:57:54 UTC (rev 85312)
@@ -169,18 +169,37 @@
        virtual void OnSubPropertyChanged (DependencyProperty *prop, 
DependencyProperty *subprop);
        virtual void OnCollectionChanged (Collection *col, CollectionChangeType 
type, DependencyObject *obj, DependencyProperty *prop);
        
+       virtual Value *GetValue (DependencyProperty *property);
+       virtual void SetValue (DependencyProperty *property, Value *value);
+       virtual void SetValue (DependencyProperty *property, Value value);
+
 private:
        PangoFontDescription *font;
        MangoRenderer *renderer;
        PangoLayout *layout;
        Brush *foreground;
        
+       bool dirty_actual_values;
        double actual_height;
        double actual_width;
        
        void CalcActualWidthHeight (cairo_t *cr);
        void Layout (cairo_t *cr);
        void Paint (cairo_t *cr);
+
+       double GetActualWidth ()
+       {
+               if (dirty_actual_values)
+                       CalcActualWidthHeight (NULL);
+               return actual_width;
+       }
+
+       double GetActualHeight ()
+       {
+               if (dirty_actual_values)
+                       CalcActualWidthHeight (NULL);
+               return actual_height;
+       }
 };
 
 TextBlock *text_block_new (void);

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

Reply via email to