resizing problems...



Hello all!

I have some problems with the resizing behaviour of gtk. I have made a
widget (derived from vbox) which holds a drawing area and a horizontal
scrollbar. the widget draws a waveform into the drawing area so the height
of the wave is always the height of the da. if the length of the waveform
gets bigger than the width of the da i want to turn on the scrollbar and if
the  length gets smaller i want to turn it off. in the function
_size_allocate() i determine wether to turn the scrollbar on/off and do a
gtk_widget_show/hide(). now, the problem is, as soon as i do a hide/show the
whole window resizes to its default size (i have made a
gtk_widget_set_usize()). how can i prevent this??? most of my widget is
derived scrolled_window and there it does function... please enlighten me...

here are the relevant source parts:

static void
wave_size_request( GtkWidget *widget, GtkRequisition *requisition )
{
  Wave *wave;
  
  g_return_if_fail( widget != NULL );
  g_return_if_fail( IS_WAVE( widget ) );
  g_return_if_fail( requisition != NULL );
	  
  wave = WAVE( widget );
	      
  requisition->width  = MINIMUM_WAVE_WIDTH;
  requisition->height = MINIMUM_WAVE_HEIGHT;
		  
  if( GTK_WIDGET_VISIBLE( wave->hscrollbar ) )
  {
    gtk_widget_size_request( wave->hscrollbar, &wave->hscrollbar->requisition );
    requisition->height = MAX( requisition->height,
                               wave->hscrollbar->requisition.height );
  }
}
  
static void
wave_size_allocate( GtkWidget *widget, GtkAllocation *allocation )
{
  GtkAllocation a;
  Wave *wave;
  gint x, y, w, h;
  gboolean scr_vis;
	  
  g_return_if_fail( widget != NULL );
  g_return_if_fail( IS_WAVE( widget ) );
  g_return_if_fail( allocation != NULL );
	  
  wave = WAVE( widget );

  widget->allocation = *allocation;
		      
  x = allocation->x;
  y = allocation->y;
  w = allocation->width;
  h = allocation->height;
	        
  scr_vis = FALSE;
  if( GTK_WIDGET_VISIBLE( wave->graph) )
  {
    a.x = x;
    a.y = y;
    a.width = w;
    a.height = h;
 
    if( a.width < wave->length )
    {
      scr_vis = TRUE;
      a.height -= wave->hscrollbar->allocation.height;
      a.height -= 5;
    }
			          
    gtk_widget_size_allocate( wave->graph, &a );
  }
  
  if( scr_vis )
  {
    a.x = 0;
    a.y = h - wave->hscrollbar->requisition.height - 1;
    a.width = w;
    a.height = wave->hscrollbar->requisition.height;
    a.x += x;
    a.y += y;
    gtk_widget_size_allocate( wave->hscrollbar, &a );
    if( !GTK_WIDGET_VISIBLE( wave->hscrollbar ) )
      gtk_widget_show( wave->hscrollbar );
    else if( GTK_WIDGET_VISIBLE( wave->hscrollbar ) )
      gtk_widget_hide( wave->hscrollbar );
			        
    wave->width  = wave->graph->allocation.width;
    wave->height = wave->graph->allocation.height;
				      
}

            ciao Philipp

---------------[ Linux now!!! ]---------------
Linux - Why use Windows, since there is a door?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]