Ask Your Question

Revision history [back]

Factoring?

// a couple of suitable typedefs...

        static void 
        cvImageWidget_get_preferred_dimension (GtkWidget *widget, gint *minimal, gint *natural,
                                               GtkWindowDimensionFn_t win_get_dim,
                                               CvImageWidgetDimMember image_dim_member
                                               gint default_min) 
        { 
          g_return_if_fail (widget != NULL); 
          g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); 
          CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); 

          if(image_widget->original_image != NULL) { 
            *minimal = (image_widget->flags & CV_WINDOW_AUTOSIZE) != CV_WINDOW_AUTOSIZE ? 
              (*win_get_dim)(gtk_widget_get_window(widget)) : image_widget->original_image->*image_dim_member; 
          } 
          else { 
            *minimal = default_min; 
          } 

          if(image_widget->scaled_image != NULL) { 
            *natural = *minimal_width < image_widget->scaled_image->*image_dim_member ? 
              image_widget->scaled_image->*image_dim_member : *minimal; 
          } 
          else { 
            *natural = *minimal; 
          } 
        } 

static void 
        cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) 
        {
            cvImageWidget_get_preferred_dimension( widget, minimal_width, natural_width,
                                                   gdk_window_get_width, &CvImageWidget::cols,
                                                   320 );
        }

static void 
        cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) 
        {
            cvImageWidget_get_preferred_dimension( widget, minimal_height, natural_height,
                                                   gdk_window_get_height, &CvImageWidget::rows,
                                                   240 );
        }