comparison os2/dw.c @ 846:a75e798ee6ed

Added initial scrollbox implementation for OS/2.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 31 Mar 2011 00:34:37 +0000
parents 53b677d126dc
children 2663f23c88a5
comparison
equal deleted inserted replaced
845:7331b7c9f1c9 846:a75e798ee6ed
35 /* The toolkit headers don't seem to have this */ 35 /* The toolkit headers don't seem to have this */
36 BOOL APIENTRY WinStretchPointer(HPS hps, LONG x, LONG y, LONG cx, LONG cy, HPOINTER hptr, ULONG fs); 36 BOOL APIENTRY WinStretchPointer(HPS hps, LONG x, LONG y, LONG cx, LONG cy, HPOINTER hptr, ULONG fs);
37 37
38 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); 38 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
39 MRESULT EXPENTRY _wndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); 39 MRESULT EXPENTRY _wndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
40 MRESULT EXPENTRY _scrollwndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
40 void _do_resize(Box *thisbox, int x, int y); 41 void _do_resize(Box *thisbox, int x, int y);
41 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y); 42 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y);
42 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height); 43 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height);
43 void _dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname); 44 void _dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname);
44 void _dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname); 45 void _dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname);
45 void _free_menu_data(HWND menu); 46 void _free_menu_data(HWND menu);
46 47
47 char ClassName[] = "dynamicwindows"; 48 char ClassName[] = "dynamicwindows";
48 char SplitbarClassName[] = "dwsplitbar"; 49 char SplitbarClassName[] = "dwsplitbar";
50 char ScrollClassName[] = "dwscroll";
49 char *DefaultFont = "9.WarpSans"; 51 char *DefaultFont = "9.WarpSans";
50 52
51 HAB dwhab = 0; 53 HAB dwhab = 0;
52 HMQ dwhmq = 0; 54 HMQ dwhmq = 0;
53 DWTID _dwtid = 0; 55 DWTID _dwtid = 0;
955 { 957 {
956 int height = _get_height(parent); 958 int height = _get_height(parent);
957 959
958 return WinSetWindowPos(hwnd, behind, x, height - y - cy, cx, cy, fl); 960 return WinSetWindowPos(hwnd, behind, x, height - y - cy, cx, cy, fl);
959 } 961 }
962
963 #define _DW_DEFAULT_SCROLLBAR_WIDTH 16
960 964
961 /* This function calculates how much space the widgets and boxes require 965 /* This function calculates how much space the widgets and boxes require
962 * and does expansion as necessary. 966 * and does expansion as necessary.
963 */ 967 */
964 int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, 968 int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy,
1320 { 1324 {
1321 _MySetWindowPos(handle, thisbox->hwnd, HWND_TOP, currentx + pad, currenty + pad, 1325 _MySetWindowPos(handle, thisbox->hwnd, HWND_TOP, currentx + pad, currenty + pad,
1322 width + vectorx, height + vectory, SWP_MOVE | SWP_SIZE | SWP_ZORDER); 1326 width + vectorx, height + vectory, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1323 _check_resize_notebook(handle); 1327 _check_resize_notebook(handle);
1324 } 1328 }
1329 else if(strncmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0)
1330 {
1331 /* Handle special case of scrollbox */
1332 int cx = width + vectorx;
1333 int cy = height + vectory;
1334 int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0;
1335 HWND box = (HWND)dw_window_get_data(handle, "_dw_resizebox");
1336 HWND client = WinWindowFromID(handle, FID_CLIENT);
1337 HWND vscroll = WinWindowFromID(handle, FID_VERTSCROLL);
1338 HWND hscroll = WinWindowFromID(handle, FID_HORZSCROLL);
1339 Box *thisbox = (Box *)WinQueryWindowPtr(box, QWP_USER);
1340 int origx, origy;
1341 unsigned int hpos = (unsigned int)WinSendMsg(hscroll, SBM_QUERYPOS, 0, 0);
1342 unsigned int vpos = (unsigned int)WinSendMsg(vscroll, SBM_QUERYPOS, 0, 0);
1343
1344 /* Position the scrollbox parts */
1345 WinSetWindowPos(handle, HWND_TOP, currentx + pad, currenty + pad, cx, cy, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1346 WinSetWindowPos(client, HWND_TOP, 0, _DW_DEFAULT_SCROLLBAR_WIDTH, cx - _DW_DEFAULT_SCROLLBAR_WIDTH, cy - _DW_DEFAULT_SCROLLBAR_WIDTH, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1347 WinSetWindowPos(hscroll, HWND_TOP, 0, 0, cx - _DW_DEFAULT_SCROLLBAR_WIDTH, _DW_DEFAULT_SCROLLBAR_WIDTH, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1348 WinSetWindowPos(vscroll, HWND_TOP, cx - _DW_DEFAULT_SCROLLBAR_WIDTH, _DW_DEFAULT_SCROLLBAR_WIDTH, _DW_DEFAULT_SCROLLBAR_WIDTH, cy - _DW_DEFAULT_SCROLLBAR_WIDTH, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1349
1350 origx = cx = cx - _DW_DEFAULT_SCROLLBAR_WIDTH;
1351 origy = cy = cy - _DW_DEFAULT_SCROLLBAR_WIDTH;
1352
1353 /* Get the required space for the box */
1354 _resize_box(thisbox, &depth, cx, cy, &usedx, &usedy, 1, &usedpadx, &usedpady);
1355
1356 if(cx < usedx)
1357 {
1358 cx = usedx;
1359 }
1360 if(cy < usedy)
1361 {
1362 cy = usedy;
1363 }
1364
1365 /* Setup vertical scroller */
1366 WinSendMsg(vscroll, SBM_SETSCROLLBAR, (MPARAM)vpos, MPFROM2SHORT(0, (unsigned short)usedy - origy));
1367 WinSendMsg(vscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT((unsigned short)origy, usedy), 0);
1368 if(vpos > usedy)
1369 {
1370 vpos = usedy;
1371 WinSendMsg(vscroll, SBM_SETPOS, (MPARAM)vpos, 0);
1372 }
1373
1374 /* Setup horizontal scroller */
1375 WinSendMsg(hscroll, SBM_SETSCROLLBAR, (MPARAM)hpos, MPFROM2SHORT(0, (unsigned short)usedx - origx));
1376 WinSendMsg(hscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT((unsigned short)origx, usedx), 0);
1377 if(hpos > usedx)
1378 {
1379 hpos = usedx;
1380 WinSendMsg(hscroll, SBM_SETPOS, (MPARAM)hpos, 0);
1381 }
1382
1383 /* Position the scrolled box */
1384 WinSetWindowPos(box, HWND_TOP, 0, -(cy - origy), cx, cy, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
1385
1386 /* Layout the content of the scrollbox */
1387 _do_resize(thisbox, cx, cy);
1388 }
1325 else if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) 1389 else if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0)
1326 { 1390 {
1327 /* Then try the bottom or right box */ 1391 /* Then try the bottom or right box */
1328 float *percent = (float *)dw_window_get_data(handle, "_dw_percent"); 1392 float *percent = (float *)dw_window_get_data(handle, "_dw_percent");
1329 int type = (int)dw_window_get_data(handle, "_dw_type"); 1393 int type = (int)dw_window_get_data(handle, "_dw_type");
1540 1604
1541 return myfunc(hWnd, msg, mp1, mp2); 1605 return myfunc(hWnd, msg, mp1, mp2);
1542 } 1606 }
1543 1607
1544 return WinDefWindowProc(hWnd, msg, mp1, mp2); 1608 return WinDefWindowProc(hWnd, msg, mp1, mp2);
1609 }
1610
1611 /* This procedure handles scrollbox */
1612 MRESULT EXPENTRY _scrollwndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1613 {
1614 switch(msg)
1615 {
1616 case WM_HSCROLL:
1617 case WM_VSCROLL:
1618 break;
1619 }
1620 return WinDefWindowProc(hWnd, msg, mp1, mp2);
1545 } 1621 }
1546 1622
1547 void _click_default(HWND handle) 1623 void _click_default(HWND handle)
1548 { 1624 {
1549 char tmpbuf[100]; 1625 char tmpbuf[100];
3482 dwhmq = WinCreateMsgQueue(dwhab, 0); 3558 dwhmq = WinCreateMsgQueue(dwhab, 0);
3483 } 3559 }
3484 3560
3485 rc = WinRegisterClass(dwhab, ClassName, _wndproc, CS_SIZEREDRAW | CS_CLIPCHILDREN, 32); 3561 rc = WinRegisterClass(dwhab, ClassName, _wndproc, CS_SIZEREDRAW | CS_CLIPCHILDREN, 32);
3486 rc = WinRegisterClass(dwhab, SplitbarClassName, _splitwndproc, 0L, 32); 3562 rc = WinRegisterClass(dwhab, SplitbarClassName, _splitwndproc, 0L, 32);
3563 rc = WinRegisterClass(dwhab, ScrollClassName, _scrollwndproc, 0L, 32);
3487 3564
3488 /* Get the OS/2 version. */ 3565 /* Get the OS/2 version. */
3489 DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_MS_COUNT,(void *)aulBuffer, 4*sizeof(ULONG)); 3566 DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_MS_COUNT,(void *)aulBuffer, 4*sizeof(ULONG));
3490 3567
3491 desktop = WinQueryDesktopWindow(dwhab, NULLHANDLE); 3568 desktop = WinQueryDesktopWindow(dwhab, NULLHANDLE);
4083 Box *newbox = calloc(1, sizeof(Box)); 4160 Box *newbox = calloc(1, sizeof(Box));
4084 4161
4085 newbox->pad = pad; 4162 newbox->pad = pad;
4086 newbox->type = type; 4163 newbox->type = type;
4087 newbox->count = 0; 4164 newbox->count = 0;
4088 newbox->grouphwnd = NULLHANDLE; 4165 newbox->grouphwnd = NULLHANDLE;
4089 4166
4090 newbox->hwnd = WinCreateWindow(HWND_OBJECT, 4167 newbox->hwnd = WinCreateWindow(HWND_OBJECT,
4091 WC_FRAME, 4168 WC_FRAME,
4092 NULL, 4169 NULL,
4093 WS_VISIBLE | WS_CLIPCHILDREN | 4170 WS_VISIBLE | WS_CLIPCHILDREN |
4112 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). 4189 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
4113 * pad: Number of pixels to pad around the box. 4190 * pad: Number of pixels to pad around the box.
4114 */ 4191 */
4115 HWND API dw_scrollbox_new(int type, int pad) 4192 HWND API dw_scrollbox_new(int type, int pad)
4116 { 4193 {
4117 return dw_box_new(type, pad); 4194 HWND hwndframe, box = dw_box_new(type, pad);
4195 HWND client, tmpbox = dw_box_new(DW_VERT, 0);
4196 WindowData *blah = calloc(sizeof(WindowData), 1);
4197 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0);
4198 hwndframe = WinCreateWindow(HWND_OBJECT, ScrollClassName, "", WS_VISIBLE | WS_CLIPCHILDREN,
4199 0, 0, 2000, 1000, NULLHANDLE, HWND_TOP, 0, NULL, NULL);
4200 WinCreateWindow(hwndframe, WC_SCROLLBAR, "", WS_VISIBLE | SBS_AUTOTRACK | SBS_VERT,
4201 0,0,2000,1000, hwndframe, HWND_TOP, FID_VERTSCROLL, NULL, NULL);
4202 WinCreateWindow(hwndframe, WC_SCROLLBAR, "", WS_VISIBLE | SBS_AUTOTRACK | SBS_HORZ,
4203 0,0,2000,1000, hwndframe, HWND_TOP, FID_HORZSCROLL, NULL, NULL);
4204 client = WinCreateWindow(hwndframe, WC_FRAME, "", WS_VISIBLE | WS_CLIPCHILDREN,
4205 0,0,2000,1000, NULLHANDLE, HWND_TOP, FID_CLIENT, NULL, NULL);
4206 WinSetParent(tmpbox, client, FALSE);
4207 WinSetWindowPtr(hwndframe, QWP_USER, blah);
4208 dw_window_set_data(hwndframe, "_dw_resizebox", (void *)tmpbox);
4209 dw_window_set_data(hwndframe, "_dw_box", (void *)box);
4210 dw_window_set_color(hwndframe, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY);
4211 dw_window_set_color(client, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY);
4212 return hwndframe;
4118 } 4213 }
4119 4214
4120 int API dw_scrollbox_get_pos( HWND handle, int orient ) 4215 int API dw_scrollbox_get_pos( HWND handle, int orient )
4121 { 4216 {
4122 return 0; 4217 return 0;
5671 return; 5766 return;
5672 } 5767 }
5673 5768
5674 if(WinWindowFromID(box, FID_CLIENT)) 5769 if(WinWindowFromID(box, FID_CLIENT))
5675 { 5770 {
5676 box = WinWindowFromID(box, FID_CLIENT); 5771 HWND intbox = (HWND)dw_window_get_data(box, "_dw_box");
5677 hsize = TRUE; 5772 if(intbox)
5678 vsize = TRUE; 5773 {
5774 box = intbox;
5775 }
5776 else
5777 {
5778 box = WinWindowFromID(box, FID_CLIENT);
5779 hsize = vsize = TRUE;
5780 }
5679 } 5781 }
5680 _dw_box_pack_end(box, item, width, height, hsize, vsize, pad, funcname); 5782 _dw_box_pack_end(box, item, width, height, hsize, vsize, pad, funcname);
5681 } 5783 }
5682 5784
5683 void _dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname) 5785 void _dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname)
8994 return; 9096 return;
8995 } 9097 }
8996 9098
8997 if(WinWindowFromID(box, FID_CLIENT)) 9099 if(WinWindowFromID(box, FID_CLIENT))
8998 { 9100 {
8999 box = WinWindowFromID(box, FID_CLIENT); 9101 HWND intbox = (HWND)dw_window_get_data(box, "_dw_box");
9000 hsize = TRUE; 9102 if(intbox)
9001 vsize = TRUE; 9103 {
9104 box = intbox;
9105 }
9106 else
9107 {
9108 box = WinWindowFromID(box, FID_CLIENT);
9109 hsize = vsize = TRUE;
9110 }
9002 } 9111 }
9003 _dw_box_pack_start(box, item, width, height, hsize, vsize, pad, funcname); 9112 _dw_box_pack_start(box, item, width, height, hsize, vsize, pad, funcname);
9004 } 9113 }
9005 9114
9006 void _dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname) 9115 void _dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname)