Mercurial > dwindows
comparison win/dw.c @ 197:f3718165f0b2
Implemented scrollbars and timers on Windows, and added scrollbar to the
example application.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 20 Jan 2003 11:08:43 +0000 |
parents | 37bee5b50bcb |
children | 446dd8cea477 |
comparison
equal
deleted
inserted
replaced
196:3dc60d60007f | 197:f3718165f0b2 |
---|---|
65 typedef struct _sighandler | 65 typedef struct _sighandler |
66 { | 66 { |
67 struct _sighandler *next; | 67 struct _sighandler *next; |
68 ULONG message; | 68 ULONG message; |
69 HWND window; | 69 HWND window; |
70 int id; | |
70 void *signalfunction; | 71 void *signalfunction; |
71 void *data; | 72 void *data; |
72 | 73 |
73 } SignalHandler; | 74 } SignalHandler; |
74 | 75 |
264 return dwVersion; | 265 return dwVersion; |
265 } | 266 } |
266 | 267 |
267 /* This function adds a signal handler callback into the linked list. | 268 /* This function adds a signal handler callback into the linked list. |
268 */ | 269 */ |
269 void _new_signal(ULONG message, HWND window, void *signalfunction, void *data) | 270 void _new_signal(ULONG message, HWND window, int id, void *signalfunction, void *data) |
270 { | 271 { |
271 SignalHandler *new = malloc(sizeof(SignalHandler)); | 272 SignalHandler *new = malloc(sizeof(SignalHandler)); |
272 | 273 |
273 if(message == WM_COMMAND) | 274 if(message == WM_COMMAND) |
274 dw_signal_disconnect_by_window(window); | 275 dw_signal_disconnect_by_window(window); |
275 | 276 |
276 new->message = message; | 277 new->message = message; |
277 new->window = window; | 278 new->window = window; |
279 new->id = id; | |
278 new->signalfunction = signalfunction; | 280 new->signalfunction = signalfunction; |
279 new->data = data; | 281 new->data = data; |
280 new->next = NULL; | 282 new->next = NULL; |
281 | 283 |
282 if (!Root) | 284 if (!Root) |
1223 { | 1225 { |
1224 if(tmp->message == msg || msg == WM_COMMAND || msg == WM_NOTIFY || tmp->message == WM_USER+1) | 1226 if(tmp->message == msg || msg == WM_COMMAND || msg == WM_NOTIFY || tmp->message == WM_USER+1) |
1225 { | 1227 { |
1226 switch(msg) | 1228 switch(msg) |
1227 { | 1229 { |
1230 case WM_TIMER: | |
1231 { | |
1232 int (*timerfunc)(void *) = tmp->signalfunction; | |
1233 if(tmp->id == (int)mp1) | |
1234 { | |
1235 if(!timerfunc(tmp->data)) | |
1236 dw_timer_disconnect(tmp->id); | |
1237 tmp = NULL; | |
1238 } | |
1239 result = 0; | |
1240 } | |
1241 break; | |
1228 case WM_SETFOCUS: | 1242 case WM_SETFOCUS: |
1229 { | 1243 { |
1230 int (*setfocusfunc)(HWND, void *) = (int (*)(HWND, void *))tmp->signalfunction; | 1244 int (*setfocusfunc)(HWND, void *) = (int (*)(HWND, void *))tmp->signalfunction; |
1231 | 1245 |
1232 if(hWnd == tmp->window) | 1246 if(hWnd == tmp->window) |
4164 SendMessage(tmp, TBM_SETRANGE, (WPARAM)FALSE, (LPARAM)MAKELONG(0, increments-1)); | 4178 SendMessage(tmp, TBM_SETRANGE, (WPARAM)FALSE, (LPARAM)MAKELONG(0, increments-1)); |
4165 return tmp; | 4179 return tmp; |
4166 } | 4180 } |
4167 | 4181 |
4168 /* | 4182 /* |
4183 * Create a new scrollbar window (widget) to be packed. | |
4184 * Parameters: | |
4185 * vertical: TRUE or FALSE if scrollbar is vertical. | |
4186 * increments: Number of increments available. | |
4187 * id: An ID to be used with WinWindowFromID() or 0L. | |
4188 */ | |
4189 HWND API dw_scrollbar_new(int vertical, int increments, ULONG id) | |
4190 { | |
4191 HWND tmp = CreateWindow("SCROLLBAR", | |
4192 "", | |
4193 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | | |
4194 (vertical ? SBS_VERT : SBS_HORZ), | |
4195 0,0,2000,1000, | |
4196 DW_HWND_OBJECT, | |
4197 (HMENU)id, | |
4198 DWInstance, | |
4199 NULL); | |
4200 return tmp; | |
4201 } | |
4202 | |
4203 /* | |
4169 * Create a new percent bar window (widget) to be packed. | 4204 * Create a new percent bar window (widget) to be packed. |
4170 * Parameters: | 4205 * Parameters: |
4171 * id: An ID to be used with WinWindowFromID() or 0L. | 4206 * id: An ID to be used with WinWindowFromID() or 0L. |
4172 */ | 4207 */ |
4173 HWND API dw_percent_new(ULONG id) | 4208 HWND API dw_percent_new(ULONG id) |
5272 else | 5307 else |
5273 SendMessage(handle, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)position); | 5308 SendMessage(handle, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)position); |
5274 } | 5309 } |
5275 | 5310 |
5276 /* | 5311 /* |
5312 * Returns the position of the scrollbar. | |
5313 * Parameters: | |
5314 * handle: Handle to the scrollbar to be queried. | |
5315 */ | |
5316 unsigned int API dw_scrollbar_query_pos(HWND handle) | |
5317 { | |
5318 return (unsigned int)SendMessage(handle, SBM_GETPOS, 0, 0); | |
5319 } | |
5320 | |
5321 /* | |
5322 * Sets the scrollbar position. | |
5323 * Parameters: | |
5324 * handle: Handle to the scrollbar to be set. | |
5325 * position: Position of the scrollbar withing the range. | |
5326 */ | |
5327 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) | |
5328 { | |
5329 dw_window_set_data(handle, "_dw_scrollbar_value", (void *)position); | |
5330 SendMessage(handle, SBM_SETPOS, (WPARAM)position, (LPARAM)TRUE); | |
5331 } | |
5332 | |
5333 /* | |
5334 * Sets the scrollbar range. | |
5335 * Parameters: | |
5336 * handle: Handle to the scrollbar to be set. | |
5337 * range: Maximum range value. | |
5338 */ | |
5339 void API dw_scrollbar_set_range(HWND handle, unsigned int range) | |
5340 { | |
5341 SendMessage(handle, SBM_SETRANGE, 0, (LPARAM)range); | |
5342 } | |
5343 | |
5344 /* | |
5277 * Sets the spinbutton value. | 5345 * Sets the spinbutton value. |
5278 * Parameters: | 5346 * Parameters: |
5279 * handle: Handle to the spinbutton to be set. | 5347 * handle: Handle to the spinbutton to be set. |
5280 * position: Current value of the spinbutton. | 5348 * position: Current value of the spinbutton. |
5281 */ | 5349 */ |
7310 } | 7378 } |
7311 return NULL; | 7379 return NULL; |
7312 } | 7380 } |
7313 | 7381 |
7314 /* | 7382 /* |
7383 * Add a callback to a timer event. | |
7384 * Parameters: | |
7385 * window: Window handle which owns this timer. | |
7386 * interval: Milliseconds to delay between calls. | |
7387 * sigfunc: The pointer to the function to be used as the callback. | |
7388 * data: User data to be passed to the handler function. | |
7389 * Returns: | |
7390 * Timer ID for use with dw_timer_disconnect(), 0 on error. | |
7391 */ | |
7392 int API dw_timer_connect(HWND window, int interval, void *sigfunc, void *data) | |
7393 { | |
7394 static int timerid = 0; | |
7395 | |
7396 if(window && sigfunc) | |
7397 { | |
7398 timerid++; | |
7399 | |
7400 if(timerid < 1) | |
7401 timerid = 1; | |
7402 | |
7403 _new_signal(WM_TIMER, window, timerid, sigfunc, data); | |
7404 return SetTimer(window, timerid, interval, NULL); | |
7405 } | |
7406 return 0; | |
7407 } | |
7408 | |
7409 /* | |
7410 * Removes timer callback. | |
7411 * Parameters: | |
7412 * id: Timer ID returned by dw_timer_connect(). | |
7413 */ | |
7414 void API dw_timer_disconnect(int id) | |
7415 { | |
7416 SignalHandler *prev = NULL, *tmp = Root; | |
7417 | |
7418 /* 0 is an invalid timer ID */ | |
7419 if(!id) | |
7420 return; | |
7421 | |
7422 while(tmp) | |
7423 { | |
7424 if(tmp->id == id) | |
7425 { | |
7426 KillTimer(tmp->window, id); | |
7427 if(prev) | |
7428 { | |
7429 prev->next = tmp->next; | |
7430 free(tmp); | |
7431 tmp = prev->next; | |
7432 } | |
7433 else | |
7434 { | |
7435 Root = tmp->next; | |
7436 free(tmp); | |
7437 tmp = Root; | |
7438 } | |
7439 } | |
7440 else | |
7441 { | |
7442 prev = tmp; | |
7443 tmp = tmp->next; | |
7444 } | |
7445 } | |
7446 } | |
7447 | |
7448 /* | |
7315 * Add a callback to a window event. | 7449 * Add a callback to a window event. |
7316 * Parameters: | 7450 * Parameters: |
7317 * window: Window handle of signal to be called back. | 7451 * window: Window handle of signal to be called back. |
7318 * signame: A string pointer identifying which signal to be hooked. | 7452 * signame: A string pointer identifying which signal to be hooked. |
7319 * sigfunc: The pointer to the function to be used as the callback. | 7453 * sigfunc: The pointer to the function to be used as the callback. |
7327 { | 7461 { |
7328 if(stricmp(signame, "set-focus") == 0) | 7462 if(stricmp(signame, "set-focus") == 0) |
7329 window = _normalize_handle(window); | 7463 window = _normalize_handle(window); |
7330 | 7464 |
7331 if((message = _findsigmessage(signame)) != 0) | 7465 if((message = _findsigmessage(signame)) != 0) |
7332 _new_signal(message, window, sigfunc, data); | 7466 _new_signal(message, window, 0, sigfunc, data); |
7333 } | 7467 } |
7334 } | 7468 } |
7335 | 7469 |
7336 /* | 7470 /* |
7337 * Removes callbacks for a given window with given name. | 7471 * Removes callbacks for a given window with given name. |