Mercurial > dwindows
comparison os2/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 | d946e329670c |
children | b955228477b3 |
comparison
equal
deleted
inserted
replaced
194:37bee5b50bcb | 195:b023d363fc09 |
---|---|
56 typedef struct _sighandler | 56 typedef struct _sighandler |
57 { | 57 { |
58 struct _sighandler *next; | 58 struct _sighandler *next; |
59 ULONG message; | 59 ULONG message; |
60 HWND window; | 60 HWND window; |
61 int id; | |
61 void *signalfunction; | 62 void *signalfunction; |
62 void *data; | 63 void *data; |
63 | 64 |
64 } SignalHandler; | 65 } SignalHandler; |
65 | 66 |
93 { SLN_SLIDERTRACK, "value_changed" } | 94 { SLN_SLIDERTRACK, "value_changed" } |
94 }; | 95 }; |
95 | 96 |
96 /* This function adds a signal handler callback into the linked list. | 97 /* This function adds a signal handler callback into the linked list. |
97 */ | 98 */ |
98 void _new_signal(ULONG message, HWND window, void *signalfunction, void *data) | 99 void _new_signal(ULONG message, HWND window, int id, void *signalfunction, void *data) |
99 { | 100 { |
100 SignalHandler *new = malloc(sizeof(SignalHandler)); | 101 SignalHandler *new = malloc(sizeof(SignalHandler)); |
101 | 102 |
102 if(message == WM_COMMAND) | 103 if(message == WM_COMMAND) |
103 dw_signal_disconnect_by_window(window); | 104 dw_signal_disconnect_by_window(window); |
104 | 105 |
105 new->message = message; | 106 new->message = message; |
106 new->window = window; | 107 new->window = window; |
108 new->id = id; | |
107 new->signalfunction = signalfunction; | 109 new->signalfunction = signalfunction; |
108 new->data = data; | 110 new->data = data; |
109 new->next = NULL; | 111 new->next = NULL; |
110 | 112 |
111 if (!Root) | 113 if (!Root) |
1886 { | 1888 { |
1887 result = setfocusfunc(tmp->window, tmp->data); | 1889 result = setfocusfunc(tmp->window, tmp->data); |
1888 tmp = NULL; | 1890 tmp = NULL; |
1889 } | 1891 } |
1890 } | 1892 } |
1893 } | |
1894 break; | |
1895 case WM_TIMER: | |
1896 { | |
1897 int (* API timerfunc)(void *) = (int (* API)(void *))tmp->signalfunction; | |
1898 if(tmp->id == (int)mp1) | |
1899 { | |
1900 if(!timerfunc(tmp->data)) | |
1901 dw_timer_disconnect(tmp->id); | |
1902 tmp = NULL; | |
1903 } | |
1904 result = 0; | |
1891 } | 1905 } |
1892 break; | 1906 break; |
1893 case WM_SIZE: | 1907 case WM_SIZE: |
1894 { | 1908 { |
1895 int (* API sizefunc)(HWND, int, int, void *) = (int (* API)(HWND, int, int, void *))tmp->signalfunction; | 1909 int (* API sizefunc)(HWND, int, int, void *) = (int (* API)(HWND, int, int, void *))tmp->signalfunction; |
4260 WinSetWindowPtr(tmp, QWP_USER, blah); | 4274 WinSetWindowPtr(tmp, QWP_USER, blah); |
4261 return tmp; | 4275 return tmp; |
4262 } | 4276 } |
4263 | 4277 |
4264 /* | 4278 /* |
4279 * Create a new scrollbar window (widget) to be packed. | |
4280 * Parameters: | |
4281 * vertical: TRUE or FALSE if scrollbar is vertical. | |
4282 * increments: Number of increments available. | |
4283 * id: An ID to be used with WinWindowFromID() or 0L. | |
4284 */ | |
4285 HWND API dw_scrollbar_new(int vertical, int increments, ULONG id) | |
4286 { | |
4287 HWND tmp; | |
4288 | |
4289 tmp = WinCreateWindow(HWND_OBJECT, | |
4290 WC_SCROLLBAR, | |
4291 "", | |
4292 WS_VISIBLE | SBS_AUTOTRACK | | |
4293 (vertical ? SBS_VERT : SBS_HORZ), | |
4294 0,0,2000,1000, | |
4295 NULLHANDLE, | |
4296 HWND_TOP, | |
4297 id, | |
4298 NULL, | |
4299 NULL); | |
4300 return tmp; | |
4301 } | |
4302 | |
4303 /* | |
4265 * Create a new percent bar window (widget) to be packed. | 4304 * Create a new percent bar window (widget) to be packed. |
4266 * Parameters: | 4305 * Parameters: |
4267 * id: An ID to be used with WinWindowFromID() or 0L. | 4306 * id: An ID to be used with WinWindowFromID() or 0L. |
4268 */ | 4307 */ |
4269 HWND API dw_percent_new(ULONG id) | 4308 HWND API dw_percent_new(ULONG id) |
5204 */ | 5243 */ |
5205 void API dw_slider_set_pos(HWND handle, unsigned int position) | 5244 void API dw_slider_set_pos(HWND handle, unsigned int position) |
5206 { | 5245 { |
5207 dw_window_set_data(handle, "_dw_slider_value", (void *)position); | 5246 dw_window_set_data(handle, "_dw_slider_value", (void *)position); |
5208 WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), (MPARAM)position); | 5247 WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), (MPARAM)position); |
5248 } | |
5249 | |
5250 /* | |
5251 * Returns the position of the scrollbar. | |
5252 * Parameters: | |
5253 * handle: Handle to the scrollbar to be queried. | |
5254 */ | |
5255 unsigned int API dw_scrollbar_query_pos(HWND handle) | |
5256 { | |
5257 return (unsigned int)WinSendMsg(handle, SBM_QUERYPOS, 0, 0); | |
5258 } | |
5259 | |
5260 /* | |
5261 * Sets the scrollbar position. | |
5262 * Parameters: | |
5263 * handle: Handle to the scrollbar to be set. | |
5264 * position: Position of the scrollbar withing the range. | |
5265 */ | |
5266 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) | |
5267 { | |
5268 dw_window_set_data(handle, "_dw_scrollbar_value", (void *)position); | |
5269 WinSendMsg(handle, SBM_SETPOS, (MPARAM)position, 0); | |
5270 } | |
5271 | |
5272 /* | |
5273 * Sets the scrollbar range. | |
5274 * Parameters: | |
5275 * handle: Handle to the scrollbar to be set. | |
5276 * range: Maximum range value. | |
5277 */ | |
5278 void API dw_scrollbar_set_range(HWND handle, unsigned int range) | |
5279 { | |
5280 unsigned int pos = (unsigned int)dw_window_get_data(handle, "_dw_scrollbar_value"); | |
5281 WinSendMsg(handle, SBM_SETSCROLLBAR, (MPARAM)pos, MPFROM2SHORT(0, (unsigned short)range)); | |
5209 } | 5282 } |
5210 | 5283 |
5211 /* | 5284 /* |
5212 * Sets the spinbutton value. | 5285 * Sets the spinbutton value. |
5213 * Parameters: | 5286 * Parameters: |
7561 } | 7634 } |
7562 return NULL; | 7635 return NULL; |
7563 } | 7636 } |
7564 | 7637 |
7565 /* | 7638 /* |
7566 * Add a callback to a window event. | 7639 * Add a callback to a timer event. |
7567 * Parameters: | 7640 * Parameters: |
7568 * window: Window handle of signal to be called back. | 7641 * window: Window handle which owns this timer. |
7569 * signame: A string pointer identifying which signal to be hooked. | 7642 * interval: Milliseconds to delay between calls. |
7570 * sigfunc: The pointer to the function to be used as the callback. | 7643 * sigfunc: The pointer to the function to be used as the callback. |
7571 * data: User data to be passed to the handler function. | 7644 * data: User data to be passed to the handler function. |
7572 */ | 7645 * Returns: |
7573 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) | 7646 * Timer ID for use with dw_timer_disconnect(), 0 on error. |
7574 { | 7647 */ |
7575 ULONG message = 0L; | 7648 int API dw_timer_connect(HWND window, int interval, void *sigfunc, void *data) |
7576 | 7649 { |
7577 if(strcmp(signame, "lose-focus") == 0) | 7650 static int timerid = 0; |
7578 { | 7651 |
7579 char tmpbuf[100]; | 7652 if(window && sigfunc) |
7580 | 7653 { |
7581 WinQueryClassName(window, 99, tmpbuf); | 7654 timerid++; |
7582 | 7655 |
7583 if(strncmp(tmpbuf, "#2", 3) == 0) | 7656 if(timerid >= TID_USERMAX) |
7584 { | 7657 timerid = 1; |
7585 HENUM henum = WinBeginEnumWindows(window); | 7658 |
7586 HWND child = WinGetNextWindow(henum); | 7659 _new_signal(WM_TIMER, window, timerid, sigfunc, data); |
7587 WinEndEnumWindows(henum); | 7660 return WinStartTimer(dwhab, window, timerid, interval); |
7588 if(child) | 7661 } |
7589 window = child; | 7662 return 0; |
7590 } | 7663 } |
7591 } | 7664 |
7592 if(window && signame && sigfunc) | 7665 /* |
7593 { | 7666 * Removes timer callback. |
7594 if((message = _findsigmessage(signame)) != 0) | 7667 * Parameters: |
7595 _new_signal(message, window, sigfunc, data); | 7668 * id: Timer ID returned by dw_timer_connect(). |
7596 } | 7669 */ |
7597 } | 7670 void API dw_timer_disconnect(int id) |
7598 | |
7599 /* | |
7600 * Removes callbacks for a given window with given name. | |
7601 * Parameters: | |
7602 * window: Window handle of callback to be removed. | |
7603 */ | |
7604 void API dw_signal_disconnect_by_name(HWND window, char *signame) | |
7605 { | 7671 { |
7606 SignalHandler *prev = NULL, *tmp = Root; | 7672 SignalHandler *prev = NULL, *tmp = Root; |
7607 ULONG message; | 7673 |
7608 | 7674 /* 0 is an invalid timer ID */ |
7609 if(!window || !signame || (message = _findsigmessage(signame)) == 0) | 7675 if(!id) |
7610 return; | 7676 return; |
7611 | 7677 |
7612 while(tmp) | 7678 while(tmp) |
7613 { | 7679 { |
7614 if(tmp->window == window && tmp->message == message) | 7680 if(tmp->id == id) |
7615 { | 7681 { |
7682 WinStopTimer(dwhab, tmp->window, id); | |
7616 if(prev) | 7683 if(prev) |
7617 { | 7684 { |
7618 prev->next = tmp->next; | 7685 prev->next = tmp->next; |
7619 free(tmp); | 7686 free(tmp); |
7620 tmp = prev->next; | 7687 tmp = prev->next; |
7633 } | 7700 } |
7634 } | 7701 } |
7635 } | 7702 } |
7636 | 7703 |
7637 /* | 7704 /* |
7638 * Removes all callbacks for a given window. | 7705 * Add a callback to a window event. |
7706 * Parameters: | |
7707 * window: Window handle of signal to be called back. | |
7708 * signame: A string pointer identifying which signal to be hooked. | |
7709 * sigfunc: The pointer to the function to be used as the callback. | |
7710 * data: User data to be passed to the handler function. | |
7711 */ | |
7712 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) | |
7713 { | |
7714 ULONG message = 0L; | |
7715 | |
7716 if(strcmp(signame, "lose-focus") == 0) | |
7717 { | |
7718 char tmpbuf[100]; | |
7719 | |
7720 WinQueryClassName(window, 99, tmpbuf); | |
7721 | |
7722 if(strncmp(tmpbuf, "#2", 3) == 0) | |
7723 { | |
7724 HENUM henum = WinBeginEnumWindows(window); | |
7725 HWND child = WinGetNextWindow(henum); | |
7726 WinEndEnumWindows(henum); | |
7727 if(child) | |
7728 window = child; | |
7729 } | |
7730 } | |
7731 if(window && signame && sigfunc) | |
7732 { | |
7733 if((message = _findsigmessage(signame)) != 0) | |
7734 _new_signal(message, window, 0, sigfunc, data); | |
7735 } | |
7736 } | |
7737 | |
7738 /* | |
7739 * Removes callbacks for a given window with given name. | |
7639 * Parameters: | 7740 * Parameters: |
7640 * window: Window handle of callback to be removed. | 7741 * window: Window handle of callback to be removed. |
7641 */ | 7742 */ |
7642 void API dw_signal_disconnect_by_window(HWND window) | 7743 void API dw_signal_disconnect_by_name(HWND window, char *signame) |
7643 { | 7744 { |
7644 SignalHandler *prev = NULL, *tmp = Root; | 7745 SignalHandler *prev = NULL, *tmp = Root; |
7746 ULONG message; | |
7747 | |
7748 if(!window || !signame || (message = _findsigmessage(signame)) == 0) | |
7749 return; | |
7645 | 7750 |
7646 while(tmp) | 7751 while(tmp) |
7647 { | 7752 { |
7648 if(tmp->window == window) | 7753 if(tmp->window == window && tmp->message == message) |
7649 { | 7754 { |
7650 if(prev) | 7755 if(prev) |
7651 { | 7756 { |
7652 prev->next = tmp->next; | 7757 prev->next = tmp->next; |
7653 free(tmp); | 7758 free(tmp); |
7667 } | 7772 } |
7668 } | 7773 } |
7669 } | 7774 } |
7670 | 7775 |
7671 /* | 7776 /* |
7672 * Removes all callbacks for a given window with specified data. | 7777 * Removes all callbacks for a given window. |
7673 * Parameters: | 7778 * Parameters: |
7674 * window: Window handle of callback to be removed. | 7779 * window: Window handle of callback to be removed. |
7675 * data: Pointer to the data to be compared against. | 7780 */ |
7676 */ | 7781 void API dw_signal_disconnect_by_window(HWND window) |
7677 void API dw_signal_disconnect_by_data(HWND window, void *data) | |
7678 { | 7782 { |
7679 SignalHandler *prev = NULL, *tmp = Root; | 7783 SignalHandler *prev = NULL, *tmp = Root; |
7680 | 7784 |
7681 while(tmp) | 7785 while(tmp) |
7682 { | 7786 { |
7683 if(tmp->window == window && tmp->data == data) | 7787 if(tmp->window == window) |
7684 { | 7788 { |
7685 if(prev) | 7789 if(prev) |
7686 { | 7790 { |
7687 prev->next = tmp->next; | 7791 prev->next = tmp->next; |
7688 free(tmp); | 7792 free(tmp); |
7701 tmp = tmp->next; | 7805 tmp = tmp->next; |
7702 } | 7806 } |
7703 } | 7807 } |
7704 } | 7808 } |
7705 | 7809 |
7810 /* | |
7811 * Removes all callbacks for a given window with specified data. | |
7812 * Parameters: | |
7813 * window: Window handle of callback to be removed. | |
7814 * data: Pointer to the data to be compared against. | |
7815 */ | |
7816 void API dw_signal_disconnect_by_data(HWND window, void *data) | |
7817 { | |
7818 SignalHandler *prev = NULL, *tmp = Root; | |
7819 | |
7820 while(tmp) | |
7821 { | |
7822 if(tmp->window == window && tmp->data == data) | |
7823 { | |
7824 if(prev) | |
7825 { | |
7826 prev->next = tmp->next; | |
7827 free(tmp); | |
7828 tmp = prev->next; | |
7829 } | |
7830 else | |
7831 { | |
7832 Root = tmp->next; | |
7833 free(tmp); | |
7834 tmp = Root; | |
7835 } | |
7836 } | |
7837 else | |
7838 { | |
7839 prev = tmp; | |
7840 tmp = tmp->next; | |
7841 } | |
7842 } | |
7843 } | |
7844 | |
7845 |