Mercurial > dwindows
comparison gtk/dw.c @ 195:b023d363fc09
Added scrollbar and timer support on OS/2 and GTK.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 20 Jan 2003 08:49:11 +0000 |
parents | efd4703450fa |
children | 3dc60d60007f |
comparison
equal
deleted
inserted
replaced
194:37bee5b50bcb | 195:b023d363fc09 |
---|---|
2368 DW_MUTEX_UNLOCK; | 2368 DW_MUTEX_UNLOCK; |
2369 return tmp; | 2369 return tmp; |
2370 } | 2370 } |
2371 | 2371 |
2372 /* | 2372 /* |
2373 * Create a new scrollbar window (widget) to be packed. | |
2374 * Parameters: | |
2375 * vertical: TRUE or FALSE if scrollbar is vertical. | |
2376 * increments: Number of increments available. | |
2377 * id: An ID to be used with WinWindowFromID() or 0L. | |
2378 */ | |
2379 HWND dw_scrollbar_new(int vertical, int increments, ULONG id) | |
2380 { | |
2381 GtkWidget *tmp; | |
2382 GtkAdjustment *adjustment; | |
2383 int _locked_by_me = FALSE; | |
2384 | |
2385 DW_MUTEX_LOCK; | |
2386 adjustment = (GtkAdjustment *)gtk_adjustment_new(0, 0, (gfloat)increments, 1, 1, 1); | |
2387 if(vertical) | |
2388 tmp = gtk_vscrollbar_new(adjustment); | |
2389 else | |
2390 tmp = gtk_hscrollbar_new(adjustment); | |
2391 GTK_WIDGET_UNSET_FLAGS(tmp, GTK_CAN_FOCUS); | |
2392 gtk_widget_show(tmp); | |
2393 gtk_object_set_data(GTK_OBJECT(tmp), "adjustment", (gpointer)adjustment); | |
2394 gtk_object_set_data(GTK_OBJECT(adjustment), "scrollbar", (gpointer)tmp); | |
2395 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
2396 DW_MUTEX_UNLOCK; | |
2397 return tmp; | |
2398 | |
2399 /* | |
2373 * Create a new percent bar window (widget) to be packed. | 2400 * Create a new percent bar window (widget) to be packed. |
2374 * Parameters: | 2401 * Parameters: |
2375 * id: An ID to be used with WinWindowFromID() or 0L. | 2402 * id: An ID to be used with WinWindowFromID() or 0L. |
2376 */ | 2403 */ |
2377 HWND dw_percent_new(unsigned long id) | 2404 HWND dw_percent_new(unsigned long id) |
3184 if(adjustment) | 3211 if(adjustment) |
3185 { | 3212 { |
3186 int max = _round_value(adjustment->upper) - 1; | 3213 int max = _round_value(adjustment->upper) - 1; |
3187 | 3214 |
3188 if(GTK_IS_VSCALE(handle)) | 3215 if(GTK_IS_VSCALE(handle)) |
3216 gtk_adjustment_set_value(adjustment, (gfloat)(max - position)); | |
3217 else | |
3218 gtk_adjustment_set_value(adjustment, (gfloat)position); | |
3219 } | |
3220 DW_MUTEX_UNLOCK; | |
3221 } | |
3222 | |
3223 /* | |
3224 * Returns the position of the scrollbar. | |
3225 * Parameters: | |
3226 * handle: Handle to the scrollbar to be queried. | |
3227 */ | |
3228 unsigned int dw_scrollbar_query_pos(HWND handle) | |
3229 { | |
3230 int val = 0, _locked_by_me = FALSE; | |
3231 GtkAdjustment *adjustment; | |
3232 | |
3233 if(!handle) | |
3234 return 0; | |
3235 | |
3236 DW_MUTEX_LOCK; | |
3237 adjustment = (GtkAdjustment *)gtk_object_get_data(GTK_OBJECT(handle), "adjustment"); | |
3238 if(adjustment) | |
3239 { | |
3240 int max = _round_value(adjustment->upper) - 1; | |
3241 int thisval = _round_value(adjustment->value); | |
3242 | |
3243 if(GTK_IS_VSCROLLBAR(handle)) | |
3244 val = max - thisval; | |
3245 else | |
3246 val = thisval; | |
3247 } | |
3248 DW_MUTEX_UNLOCK; | |
3249 return val; | |
3250 } | |
3251 | |
3252 /* | |
3253 * Sets the scrollbar position. | |
3254 * Parameters: | |
3255 * handle: Handle to the scrollbar to be set. | |
3256 * position: Position of the scrollbar withing the range. | |
3257 */ | |
3258 void dw_scrollbar_set_pos(HWND handle, unsigned int position) | |
3259 { | |
3260 int _locked_by_me = FALSE; | |
3261 GtkAdjustment *adjustment; | |
3262 | |
3263 if(!handle) | |
3264 return; | |
3265 | |
3266 DW_MUTEX_LOCK; | |
3267 adjustment = (GtkAdjustment *)gtk_object_get_data(GTK_OBJECT(handle), "adjustment"); | |
3268 if(adjustment) | |
3269 { | |
3270 int max = _round_value(adjustment->upper) - 1; | |
3271 | |
3272 if(GTK_IS_VSCROLLBAR(handle)) | |
3189 gtk_adjustment_set_value(adjustment, (gfloat)(max - position)); | 3273 gtk_adjustment_set_value(adjustment, (gfloat)(max - position)); |
3190 else | 3274 else |
3191 gtk_adjustment_set_value(adjustment, (gfloat)position); | 3275 gtk_adjustment_set_value(adjustment, (gfloat)position); |
3192 } | 3276 } |
3193 DW_MUTEX_UNLOCK; | 3277 DW_MUTEX_UNLOCK; |
6950 DW_MUTEX_UNLOCK; | 7034 DW_MUTEX_UNLOCK; |
6951 return ret; | 7035 return ret; |
6952 } | 7036 } |
6953 | 7037 |
6954 /* | 7038 /* |
7039 * Add a callback to a timer event. | |
7040 * Parameters: | |
7041 * window: Window handle which owns this timer. | |
7042 * interval: Milliseconds to delay between calls. | |
7043 * sigfunc: The pointer to the function to be used as the callback. | |
7044 * data: User data to be passed to the handler function. | |
7045 * Returns: | |
7046 * Timer ID for use with dw_timer_disconnect(), 0 on error. | |
7047 */ | |
7048 int API dw_timer_connect(HWND window, int interval, void *sigfunc, void *data) | |
7049 { | |
7050 int tag, _locked_by_me = FALSE; | |
7051 char buf[100]; | |
7052 | |
7053 if(!window) | |
7054 return 0; | |
7055 | |
7056 DW_MUTEX_LOCK; | |
7057 tag = gtk_timeout_add(interval, (GtkFunction)sigfunc, data); | |
7058 sprintf(buf, "_dw_timer%d", tag); | |
7059 gtk_object_set_data(GTK_OBJECT(window), buf, (gpointer)tag); | |
7060 DW_MUTEX_UNLOCK; | |
7061 return tag; | |
7062 } | |
7063 | |
7064 /* | |
7065 * Removes timer callback. | |
7066 * Parameters: | |
7067 * id: Timer ID returned by dw_timer_connect(). | |
7068 */ | |
7069 void API dw_timer_disconnect(int id) | |
7070 { | |
7071 int _locked_by_me = FALSE; | |
7072 | |
7073 DW_MUTEX_LOCK; | |
7074 gtk_timeout_remove(id); | |
7075 DW_MUTEX_UNLOCK; | |
7076 } | |
7077 | |
7078 /* | |
6955 * Add a callback to a window event. | 7079 * Add a callback to a window event. |
6956 * Parameters: | 7080 * Parameters: |
6957 * window: Window handle of signal to be called back. | 7081 * window: Window handle of signal to be called back. |
6958 * signame: A string pointer identifying which signal to be hooked. | 7082 * signame: A string pointer identifying which signal to be hooked. |
6959 * sigfunc: The pointer to the function to be used as the callback. | 7083 * sigfunc: The pointer to the function to be used as the callback. |