comparison os2/dw.c @ 94:7c3eef54c98c

Popup menu handler fix for GTK, and fixed sliders/percent widgets not being accurate after a resize. Also removed a limitation in the click default code.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 09 May 2002 06:31:48 +0000
parents 98cce029a611
children 24cf41bb75ff
comparison
equal deleted inserted replaced
93:98cce029a611 94:7c3eef54c98c
25 #include "dw.h" 25 #include "dw.h"
26 26
27 #define QWP_USER 0 27 #define QWP_USER 0
28 28
29 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); 29 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
30 void _do_resize(Box *thisbox, int x, int y);
30 31
31 char ClassName[] = "dynamicwindows"; 32 char ClassName[] = "dynamicwindows";
32 char SplitbarClassName[] = "dwsplitbar"; 33 char SplitbarClassName[] = "dwsplitbar";
33 char DefaultFont[] = "9.WarpSans"; 34 char DefaultFont[] = "9.WarpSans";
34 35
829 830
830 if(rc) 831 if(rc)
831 *rclTrack = track.rclTrack; 832 *rclTrack = track.rclTrack;
832 833
833 return rc; 834 return rc;
835 }
836
837 void _check_resize_notebook(HWND hwnd)
838 {
839 char tmpbuf[100];
840
841 WinQueryClassName(hwnd, 99, tmpbuf);
842
843 /* If we have a notebook we resize the page again. */
844 if(strncmp(tmpbuf, "#40", 4)==0)
845 {
846 unsigned long x, y, width, height;
847 ULONG page = (ULONG)WinSendMsg(hwnd, BKM_QUERYPAGEID, 0, MPFROM2SHORT(BKA_FIRST, BKA_MAJOR));
848
849 while(page)
850 {
851 HWND pagehwnd = (HWND)WinSendMsg(hwnd, BKM_QUERYPAGEWINDOWHWND, MPFROMLONG(page), 0);
852 RECTL rc;
853
854 Box *pagebox = (Box *)WinQueryWindowPtr(pagehwnd, QWP_USER);
855 if(pagebox)
856 {
857 dw_window_get_pos_size(hwnd, &x, &y, &width, &height);
858
859 rc.xLeft = x;
860 rc.yBottom = y;
861 rc.xRight = x + width;
862 rc.yTop = y + height;
863
864 WinSendMsg(hwnd, BKM_CALCPAGERECT, (MPARAM)&rc, (MPARAM)TRUE);
865
866 _do_resize(pagebox, rc.xRight - rc.xLeft, rc.yTop - rc.yBottom);
867 }
868 page = (ULONG)WinSendMsg(hwnd, BKM_QUERYPAGEID, page, MPFROM2SHORT(BKA_NEXT, BKA_MAJOR));
869 }
870
871 }
834 } 872 }
835 873
836 /* This function calculates how much space the widgets and boxes require 874 /* This function calculates how much space the widgets and boxes require
837 * and does expansion as necessary. 875 * and does expansion as necessary.
838 */ 876 */
1178 { 1216 {
1179 /* Entryfields on OS/2 have a thick border that isn't on Windows and GTK */ 1217 /* Entryfields on OS/2 have a thick border that isn't on Windows and GTK */
1180 WinSetWindowPos(handle, HWND_TOP, (currentx + pad) + 3, (currenty + pad) + 3, 1218 WinSetWindowPos(handle, HWND_TOP, (currentx + pad) + 3, (currenty + pad) + 3,
1181 (width + vectorx) - 6, (height + vectory) - 6, SWP_MOVE | SWP_SIZE | SWP_ZORDER); 1219 (width + vectorx) - 6, (height + vectory) - 6, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1182 } 1220 }
1221 else if(strncmp(tmpbuf, "#40", 5)==0)
1222 {
1223 WinSetWindowPos(handle, HWND_TOP, currentx + pad, currenty + pad,
1224 width + vectorx, height + vectory, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1225 _check_resize_notebook(handle);
1226 }
1183 else 1227 else
1184 { 1228 {
1185 WinSetWindowPos(handle, HWND_TOP, currentx + pad, currenty + pad, 1229 WinSetWindowPos(handle, HWND_TOP, currentx + pad, currenty + pad,
1186 width + vectorx, height + vectory, SWP_MOVE | SWP_SIZE | SWP_ZORDER); 1230 width + vectorx, height + vectory, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1187 if(thisbox->items[z].type == TYPEBOX) 1231 if(thisbox->items[z].type == TYPEBOX)
1484 _shift_focus(hWnd); 1528 _shift_focus(hWnd);
1485 return FALSE; 1529 return FALSE;
1486 } 1530 }
1487 else if(SHORT1FROMMP(mp2) == '\r' && blah && blah->clickdefault) 1531 else if(SHORT1FROMMP(mp2) == '\r' && blah && blah->clickdefault)
1488 _click_default(blah->clickdefault); 1532 _click_default(blah->clickdefault);
1489 1533 /* When you hit escape we get this value and the
1534 * window hangs for reasons unknown. (in an MLE)
1535 */
1536 else if(SHORT1FROMMP(mp2) == 283)
1537 return TRUE;
1538
1539 break;
1540 case WM_SIZE:
1541 {
1542 char tmpbuf[100];
1543
1544 WinQueryClassName(hWnd, 99, tmpbuf);
1545
1546 /* If it's a slider... make sure it shows the correct value */
1547 if(strncmp(tmpbuf, "#38", 4)==0)
1548 WinPostMsg(hWnd, WM_USER+7, 0, 0);
1549 }
1550 break;
1551 case WM_USER+7:
1552 {
1553 int pos = (int)dw_window_get_data(hWnd, "_dw_slider_value");
1554 WinSendMsg(hWnd, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), (MPARAM)pos);
1555 }
1556 break;
1557 }
1558
1559 if(oldproc)
1560 return oldproc(hWnd, msg, mp1, mp2);
1561
1562 return WinDefWindowProc(hWnd, msg, mp1, mp2);
1563 }
1564
1565 int _dw_int_pos(HWND hwnd)
1566 {
1567 int pos = (int)dw_window_get_data(hwnd, "_dw_percent_value");
1568 int range = dw_percent_query_range(hwnd);
1569 float fpos = (float)pos;
1570 float frange = (float)range;
1571 float fnew = (fpos/1000.0)*frange;
1572 return (int)fnew;
1573 }
1574
1575 void _dw_int_set(HWND hwnd, int pos)
1576 {
1577 int inew, range = dw_percent_query_range(hwnd);
1578 float fpos = (float)pos;
1579 float frange = (float)range;
1580 float fnew = (fpos/frange)*1000.0;
1581 inew = (int)fnew;
1582 dw_window_set_data(hwnd, "_dw_percent_value", (void *)inew);
1583 }
1584
1585 /* Handle size changes in the percent class */
1586 MRESULT EXPENTRY _percentproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1587 {
1588 WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER);
1589 PFNWP oldproc = 0;
1590
1591 if(blah)
1592 oldproc = blah->oldproc;
1593
1594 switch(msg)
1595 {
1596 case WM_SIZE:
1597 WinPostMsg(hWnd, WM_USER+7, 0, 0);
1598 break;
1599 case WM_USER+7:
1600 WinSendMsg(hWnd, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), (MPARAM)_dw_int_pos(hWnd));
1490 break; 1601 break;
1491 } 1602 }
1492 1603
1493 if(oldproc) 1604 if(oldproc)
1494 return oldproc(hWnd, msg, mp1, mp2); 1605 return oldproc(hWnd, msg, mp1, mp2);
1958 static int lastvalue = -1; 2069 static int lastvalue = -1;
1959 static HWND lasthwnd = NULLHANDLE; 2070 static HWND lasthwnd = NULLHANDLE;
1960 int ulValue = (int)WinSendMsg(tmp->window, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), 0); 2071 int ulValue = (int)WinSendMsg(tmp->window, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), 0);
1961 if(lastvalue != ulValue || lasthwnd != tmp->window) 2072 if(lastvalue != ulValue || lasthwnd != tmp->window)
1962 { 2073 {
2074 dw_window_set_data(tmp->window, "_dw_slider_value", (void *)ulValue);
1963 result = valuechangedfunc(tmp->window, ulValue, tmp->data); 2075 result = valuechangedfunc(tmp->window, ulValue, tmp->data);
1964 lastvalue = ulValue; 2076 lastvalue = ulValue;
1965 lasthwnd = tmp->window; 2077 lasthwnd = tmp->window;
1966 } 2078 }
1967 tmp = NULL; 2079 tmp = NULL;
2099 if(mybox->count == 1 && mybox->items[0].type == TYPEBOX) 2211 if(mybox->count == 1 && mybox->items[0].type == TYPEBOX)
2100 { 2212 {
2101 mybox = (Box *)WinQueryWindowPtr(mybox->items[0].hwnd, QWP_USER); 2213 mybox = (Box *)WinQueryWindowPtr(mybox->items[0].hwnd, QWP_USER);
2102 2214
2103 for(z=0;z<mybox->count;z++) 2215 for(z=0;z<mybox->count;z++)
2104 { 2216 _check_resize_notebook(mybox->items[z].hwnd);
2105 char tmpbuf[100];
2106
2107 WinQueryClassName(mybox->items[z].hwnd, 99, tmpbuf);
2108
2109 /* If we have a notebook we resize the page again. */
2110 if(strncmp(tmpbuf, "#40", 4)==0)
2111 {
2112 unsigned long x, y, width, height;
2113 int page = dw_notebook_page_query(mybox->items[z].hwnd);
2114 HWND pagehwnd = (HWND)WinSendMsg(mybox->items[z].hwnd, BKM_QUERYPAGEWINDOWHWND, MPFROMLONG(page), 0);
2115 RECTL rc;
2116
2117 Box *pagebox = (Box *)WinQueryWindowPtr(pagehwnd, QWP_USER);
2118 if(pagebox)
2119 {
2120 dw_window_get_pos_size(mybox->items[z].hwnd, &x, &y, &width, &height);
2121
2122 rc.xLeft = x;
2123 rc.yBottom = y;
2124 rc.xRight = x + width;
2125 rc.yTop = y + height;
2126
2127 WinSendMsg(mybox->items[z].hwnd, BKM_CALCPAGERECT, (MPARAM)&rc, (MPARAM)TRUE);
2128
2129 _do_resize(pagebox, rc.xRight - rc.xLeft, rc.yTop - rc.yBottom);
2130 }
2131
2132 }
2133 }
2134 2217
2135 } 2218 }
2136 2219
2137 WinShowWindow(hWnd, TRUE); 2220 WinShowWindow(hWnd, TRUE);
2138 } 2221 }
4037 blah->oldproc = WinSubclassWindow(tmp, _entryproc); 4120 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
4038 WinSetWindowPtr(tmp, QWP_USER, blah); 4121 WinSetWindowPtr(tmp, QWP_USER, blah);
4039 return tmp; 4122 return tmp;
4040 } 4123 }
4041 4124
4125
4042 /* 4126 /*
4043 * Create a new slider window (widget) to be packed. 4127 * Create a new slider window (widget) to be packed.
4044 * Parameters: 4128 * Parameters:
4045 * vertical: TRUE or FALSE if slider is vertical. 4129 * vertical: TRUE or FALSE if slider is vertical.
4046 * increments: Number of increments available. 4130 * increments: Number of increments available.
4060 HWND_TOP, 4144 HWND_TOP,
4061 id, 4145 id,
4062 &sldcData, 4146 &sldcData,
4063 NULL); 4147 NULL);
4064 4148
4149
4065 blah->oldproc = WinSubclassWindow(tmp, _entryproc); 4150 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
4066 WinSetWindowPtr(tmp, QWP_USER, blah); 4151 WinSetWindowPtr(tmp, QWP_USER, blah);
4067 return tmp; 4152 return tmp;
4068 } 4153 }
4069 4154
4072 * Parameters: 4157 * Parameters:
4073 * id: An ID to be used with WinWindowFromID() or 0L. 4158 * id: An ID to be used with WinWindowFromID() or 0L.
4074 */ 4159 */
4075 HWND dw_percent_new(ULONG id) 4160 HWND dw_percent_new(ULONG id)
4076 { 4161 {
4162 WindowData *blah = calloc(1, sizeof(WindowData));
4077 HWND tmp = WinCreateWindow(HWND_OBJECT, 4163 HWND tmp = WinCreateWindow(HWND_OBJECT,
4078 WC_SLIDER, 4164 WC_SLIDER,
4079 "", 4165 "",
4080 WS_VISIBLE | SLS_READONLY 4166 WS_VISIBLE | SLS_READONLY
4081 | SLS_RIBBONSTRIP, 4167 | SLS_RIBBONSTRIP,
4084 HWND_TOP, 4170 HWND_TOP,
4085 id, 4171 id,
4086 NULL, 4172 NULL,
4087 NULL); 4173 NULL);
4088 dw_window_disable(tmp); 4174 dw_window_disable(tmp);
4175 blah->oldproc = WinSubclassWindow(tmp, _percentproc);
4176 WinSetWindowPtr(tmp, QWP_USER, blah);
4089 return tmp; 4177 return tmp;
4090 } 4178 }
4091 4179
4092 /* 4180 /*
4093 * Create a new checkbox window (widget) to be packed. 4181 * Create a new checkbox window (widget) to be packed.
4942 * handle: Handle to the percent bar to be set. 5030 * handle: Handle to the percent bar to be set.
4943 * position: Position of the percent bar withing the range. 5031 * position: Position of the percent bar withing the range.
4944 */ 5032 */
4945 void dw_percent_set_pos(HWND handle, unsigned int position) 5033 void dw_percent_set_pos(HWND handle, unsigned int position)
4946 { 5034 {
5035 _dw_int_set(handle, position);
4947 WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), (MPARAM)position); 5036 WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), (MPARAM)position);
4948 } 5037 }
4949 5038
4950 /* 5039 /*
4951 * Returns the position of the slider. 5040 * Returns the position of the slider.
4963 * handle: Handle to the slider to be set. 5052 * handle: Handle to the slider to be set.
4964 * position: Position of the slider withing the range. 5053 * position: Position of the slider withing the range.
4965 */ 5054 */
4966 void dw_slider_set_pos(HWND handle, unsigned int position) 5055 void dw_slider_set_pos(HWND handle, unsigned int position)
4967 { 5056 {
5057 dw_window_set_data(handle, "_dw_slider_value", (void *)position);
4968 WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), (MPARAM)position); 5058 WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), (MPARAM)position);
4969 } 5059 }
4970 5060
4971 /* 5061 /*
4972 * Sets the spinbutton value. 5062 * Sets the spinbutton value.
6838 * next: Window (widget) to move to next (or click) 6928 * next: Window (widget) to move to next (or click)
6839 */ 6929 */
6840 void dw_window_click_default(HWND window, HWND next) 6930 void dw_window_click_default(HWND window, HWND next)
6841 { 6931 {
6842 WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER); 6932 WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER);
6843 char tmpbuf[100]; 6933
6844 6934 if(blah)
6845 WinQueryClassName(window, 99, tmpbuf);
6846
6847 /* These are the window classes which can
6848 * obtain input focus.
6849 */
6850 if(strncmp(tmpbuf, "#6", 3) == 0 && blah)
6851 blah->clickdefault = next; 6935 blah->clickdefault = next;
6852 } 6936 }
6853 6937
6854 /* 6938 /*
6855 * Returns some information about the current operating environment. 6939 * Returns some information about the current operating environment.