comparison gtk/dw.c @ 145:659c1a2bccad

Fixed the calculations in the splitbar widget. Finished all the splitbar functions.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 22 Oct 2002 12:21:37 +0000
parents c68bc269ed58
children b479002e013f
comparison
equal deleted inserted replaced
144:c68bc269ed58 145:659c1a2bccad
6094 6094
6095 if(GTK_IS_HPANED(widget)) 6095 if(GTK_IS_HPANED(widget))
6096 gtk_paned_set_position(GTK_PANED(widget), (int)(event->width * (*percent / 100.0))); 6096 gtk_paned_set_position(GTK_PANED(widget), (int)(event->width * (*percent / 100.0)));
6097 if(GTK_IS_VPANED(widget)) 6097 if(GTK_IS_VPANED(widget))
6098 gtk_paned_set_position(GTK_PANED(widget), (int)(event->height * (*percent / 100.0))); 6098 gtk_paned_set_position(GTK_PANED(widget), (int)(event->height * (*percent / 100.0)));
6099 gtk_object_set_data(GTK_OBJECT(widget), "_dw_waiting", NULL);
6099 return FALSE; 6100 return FALSE;
6100 } 6101 }
6101 6102
6102 #if GTK_MAJOR_VERSION > 1 6103 #if GTK_MAJOR_VERSION > 1
6103 /* Figure out the new percentage */ 6104 /* Figure out the new percentage */
6104 gint _splitbar_accept_position(GtkWidget *widget, gpointer data) 6105 void _splitbar_accept_position(GObject *object, GParamSpec *pspec, gpointer data)
6105 { 6106 {
6107 GtkWidget *widget = (GtkWidget *)data;
6106 float *percent = (float *)gtk_object_get_data(GTK_OBJECT(widget), "_dw_percent"); 6108 float *percent = (float *)gtk_object_get_data(GTK_OBJECT(widget), "_dw_percent");
6107 int size = 0, position = gtk_paned_get_position(GTK_PANED(widget)); 6109 int size = 0, position = gtk_paned_get_position(GTK_PANED(widget));
6108 6110
6109 printf("Accept position\n"); 6111 if(!percent || gtk_object_get_data(GTK_OBJECT(widget), "_dw_waiting"))
6110 if(!percent) 6112 return;
6111 return FALSE;
6112 6113
6113 if(GTK_IS_VPANED(widget)) 6114 if(GTK_IS_VPANED(widget))
6114 size = widget->allocation.height; 6115 size = widget->allocation.height;
6115 else if(GTK_IS_HPANED(widget)) 6116 else if(GTK_IS_HPANED(widget))
6116 size = widget->allocation.width; 6117 size = widget->allocation.width;
6117 6118
6118 if(size > 0) 6119 if(size > 0)
6119 *percent = ((float)(position * 100) / (float)size); 6120 *percent = ((float)(position * 100) / (float)size);
6120 return FALSE;
6121 } 6121 }
6122 #endif 6122 #endif
6123 6123
6124 /* 6124 /*
6125 * Creates a splitbar window (widget) with given parameters. 6125 * Creates a splitbar window (widget) with given parameters.
6144 gtk_paned_add1(GTK_PANED(tmp), topleft); 6144 gtk_paned_add1(GTK_PANED(tmp), topleft);
6145 gtk_paned_add2(GTK_PANED(tmp), bottomright); 6145 gtk_paned_add2(GTK_PANED(tmp), bottomright);
6146 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); 6146 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id);
6147 *percent = 50.0; 6147 *percent = 50.0;
6148 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_percent", (gpointer)percent); 6148 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_percent", (gpointer)percent);
6149 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_waiting", (gpointer)1);
6149 gtk_signal_connect(GTK_OBJECT(tmp), "size-allocate", GTK_SIGNAL_FUNC(_splitbar_size_allocate), NULL); 6150 gtk_signal_connect(GTK_OBJECT(tmp), "size-allocate", GTK_SIGNAL_FUNC(_splitbar_size_allocate), NULL);
6150 #if GTK_MAJOR_VERSION > 1 6151 #if GTK_MAJOR_VERSION > 1
6151 g_signal_connect(G_OBJECT(tmp), "accept-position", (GCallback)_splitbar_accept_position, NULL); 6152 g_signal_connect(G_OBJECT(tmp), "notify::position", (GCallback)_splitbar_accept_position, (gpointer)tmp);
6152 #else 6153 #else
6153 gtk_paned_set_handle_size(GTK_PANED(tmp), 3); 6154 gtk_paned_set_handle_size(GTK_PANED(tmp), 3);
6154 #endif 6155 #endif
6155 gtk_widget_show(tmp); 6156 gtk_widget_show(tmp);
6156 DW_MUTEX_UNLOCK; 6157 DW_MUTEX_UNLOCK;
6162 * Parameters: 6163 * Parameters:
6163 * handle: The handle to the splitbar returned by dw_splitbar_new(). 6164 * handle: The handle to the splitbar returned by dw_splitbar_new().
6164 */ 6165 */
6165 void dw_splitbar_set(HWND handle, float percent) 6166 void dw_splitbar_set(HWND handle, float percent)
6166 { 6167 {
6167 /* We probably need to force a redraw here */
6168 float *mypercent = (float *)dw_window_get_data(handle, "_dw_percent"); 6168 float *mypercent = (float *)dw_window_get_data(handle, "_dw_percent");
6169 int size = 0, position;
6170
6171 if(GTK_IS_VPANED(handle))
6172 size = handle->allocation.height;
6173 else if(GTK_IS_HPANED(handle))
6174 size = handle->allocation.width;
6169 6175
6170 if(mypercent) 6176 if(mypercent)
6171 *mypercent = percent; 6177 *mypercent = percent;
6178
6179 if(size > 10)
6180 {
6181 position = (int)((float)size * (percent / 100.0));
6182
6183 gtk_paned_set_position(GTK_PANED(handle), position);
6184 }
6172 } 6185 }
6173 6186
6174 /* 6187 /*
6175 * Gets the position of a splitbar (pecentage). 6188 * Gets the position of a splitbar (pecentage).
6176 * Parameters: 6189 * Parameters: