comparison win/dw.c @ 118:c170181668b7

Initial new splitbar code on Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 19 Oct 2002 03:41:36 +0000
parents 1e406d67b178
children 1cad81b7cc4c
comparison
equal deleted inserted replaced
117:d785ee5adf02 118:c170181668b7
2301 } 2301 }
2302 2302
2303 /* This handles any activity on the splitbars (sizers) */ 2303 /* This handles any activity on the splitbars (sizers) */
2304 BOOL CALLBACK _splitwndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) 2304 BOOL CALLBACK _splitwndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2)
2305 { 2305 {
2306 HWND hwndFrame = 0; 2306 int percent = (int)dw_window_get_data(hwnd, "_dw_percent");
2307 Box *thisbox = 0; 2307 int type = (int)dw_window_get_data(hwnd, "_dw_type");
2308
2309 hwndFrame = GetParent(hwnd);
2310 if(hwndFrame)
2311 thisbox = (Box *)GetWindowLong(hwndFrame, GWL_USERDATA);
2312 2308
2313 switch (msg) 2309 switch (msg)
2314 { 2310 {
2315 case WM_ACTIVATE: 2311 case WM_ACTIVATE:
2316 case WM_SETFOCUS: 2312 case WM_SETFOCUS:
2317 return FALSE; 2313 return FALSE;
2318 2314
2315 case WM_SIZE:
2316 {
2317 int x = LOWORD(mp2), y = HIWORD(mp2);
2318
2319 if(x > 0 && y > 0)
2320 {
2321 if(type == BOXHORZ)
2322 {
2323 int newx = x - SPLITBAR_WIDTH, newy = y;
2324 float ratio = (float)percent/(float)100;
2325 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_topleft");
2326 Box *tmp = (Box *)GetWindowLong(handle, GWL_USERDATA);
2327
2328 newx = (int)((float)newx * ratio);
2329
2330 SetWindowPos(handle, (HWND)NULL, 0, 0, newx, y, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
2331 _do_resize(tmp, newx, y);
2332
2333 handle = (HWND)dw_window_get_data(hwnd, "_dw_bottomright");
2334 tmp = (Box *)GetWindowLong(handle, GWL_USERDATA);
2335
2336 newx = x - newx - SPLITBAR_WIDTH;
2337
2338 SetWindowPos(handle, (HWND)NULL, x - newx, 0, newx, y, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
2339 _do_resize(tmp, newx, y);
2340
2341 dw_window_set_data(hwnd, "_dw_start", (void *)newx);
2342 }
2343 else
2344 {
2345 int newx = x, newy = y - SPLITBAR_WIDTH;
2346 float ratio = (float)(100-percent)/(float)100;
2347 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_bottomright");
2348 Box *tmp = (Box *)GetWindowLong(handle, GWL_USERDATA);
2349
2350 newy = (int)((float)newy * ratio);
2351
2352 SetWindowPos(handle, (HWND)NULL, 0, y - newy, x, newy, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
2353 _do_resize(tmp, x, newy);
2354
2355 handle = (HWND)dw_window_get_data(hwnd, "_dw_topleft");
2356 tmp = (Box *)GetWindowLong(handle, GWL_USERDATA);
2357
2358 newy = y - newy - SPLITBAR_WIDTH;
2359
2360 SetWindowPos(handle, (HWND)NULL, 0, 0, x, newy, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
2361 _do_resize(tmp, x, newy);
2362
2363 dw_window_set_data(hwnd, "_dw_start", (void *)newy);
2364 }
2365 }
2366 }
2367 break;
2319 case WM_PAINT: 2368 case WM_PAINT:
2320 { 2369 {
2321 HDC hdcPaint; 2370 HDC hdcPaint;
2322 PAINTSTRUCT ps; 2371 PAINTSTRUCT ps;
2323 POINT ptlStart[SPLITBAR_WIDTH]; 2372 POINT ptlStart[SPLITBAR_WIDTH];
2324 POINT ptlEnd[SPLITBAR_WIDTH]; 2373 POINT ptlEnd[SPLITBAR_WIDTH];
2325 RECT rcPaint; 2374 RECT rcPaint;
2326 USHORT i; 2375 USHORT i;
2376 int start = (int)dw_window_get_data(hwnd, "_dw_start");
2327 2377
2328 hdcPaint = BeginPaint(hwnd, &ps); 2378 hdcPaint = BeginPaint(hwnd, &ps);
2329 GetWindowRect(hwnd, &rcPaint); 2379 GetWindowRect(hwnd, &rcPaint);
2330 2380
2331 if(thisbox->type == BOXHORZ) 2381 if(type == BOXHORZ)
2332 { 2382 {
2333 for(i = 0; i < SPLITBAR_WIDTH; i++) 2383 for(i = 0; i < SPLITBAR_WIDTH; i++)
2334 { 2384 {
2335 ptlStart[i].x = i; 2385 ptlStart[i].x = i + start - 1;
2336 ptlStart[i].y = 0; 2386 ptlStart[i].y = 0;
2337 2387
2338 ptlEnd[i].x = i; 2388 ptlEnd[i].x = i + start - 1;
2339 ptlEnd[i].y = rcPaint.bottom - rcPaint.top; 2389 ptlEnd[i].y = rcPaint.bottom - rcPaint.top;
2340 } 2390 }
2341 } 2391 }
2342 else 2392 else
2343 { 2393 {
2344 for(i = 0; i < SPLITBAR_WIDTH; i++) 2394 for(i = 0; i < SPLITBAR_WIDTH; i++)
2345 { 2395 {
2346 ptlStart[i].x = 0; 2396 ptlStart[i].x = 0;
2347 ptlStart[i].y = i; 2397 ptlStart[i].y = i + start;
2348 2398
2349 ptlEnd[i].x = rcPaint.right - rcPaint.left; 2399 ptlEnd[i].x = rcPaint.right - rcPaint.left;
2350 ptlEnd[i].y = i; 2400 ptlEnd[i].y = i + start;
2351 } 2401 }
2352 } 2402 }
2353 2403
2354 for(i = 0; i < SPLITBAR_WIDTH; i++) 2404 for(i = 0; i < SPLITBAR_WIDTH; i++)
2355 { 2405 {
2366 EndPaint(hwnd, &ps); 2416 EndPaint(hwnd, &ps);
2367 } 2417 }
2368 return FALSE; 2418 return FALSE;
2369 case WM_MOUSEMOVE: 2419 case WM_MOUSEMOVE:
2370 { 2420 {
2371 if(thisbox->type == BOXHORZ) 2421 if(type == BOXHORZ)
2372 SetCursor(LoadCursor(NULL, IDC_SIZEWE)); 2422 SetCursor(LoadCursor(NULL, IDC_SIZEWE));
2373 else 2423 else
2374 SetCursor(LoadCursor(NULL, IDC_SIZENS)); 2424 SetCursor(LoadCursor(NULL, IDC_SIZENS));
2375 } 2425 }
2376 return FALSE; 2426 return FALSE;
6711 { 6761 {
6712 exit(exitcode); 6762 exit(exitcode);
6713 } 6763 }
6714 6764
6715 /* 6765 /*
6766 * Creates a splitbar window (widget) with given parameters.
6767 * Parameters:
6768 * type: Value can be BOXVERT or BOXHORZ.
6769 * topleft: Handle to the window to be top or left.
6770 * bottomright: Handle to the window to be bottom or right.
6771 * Returns:
6772 * A handle to a splitbar window or NULL on failure.
6773 */
6774 HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright)
6775 {
6776 HWND tmp = CreateWindow(SplitbarClassName,
6777 "",
6778 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
6779 0,0,2000,1000,
6780 DW_HWND_OBJECT,
6781 NULL,
6782 DWInstance,
6783 NULL);
6784
6785 if(tmp)
6786 {
6787 HWND tmpbox = dw_box_new(BOXVERT, 0);
6788
6789 dw_box_pack_start(tmpbox, topleft, 1, 1, TRUE, TRUE, 0);
6790 SetParent(tmpbox, tmp);
6791 dw_window_set_data(tmp, "_dw_topleft", (void *)tmpbox);
6792
6793 tmpbox = dw_box_new(BOXVERT, 0);
6794 dw_box_pack_start(tmpbox, bottomright, 1, 1, TRUE, TRUE, 0);
6795 SetParent(tmpbox, tmp);
6796 dw_window_set_data(tmp, "_dw_bottomright", (void *)tmpbox);
6797 dw_window_set_data(tmp, "_dw_percent", (void *)50);
6798 dw_window_set_data(tmp, "_dw_type", (void *)type);
6799 }
6800 return tmp;
6801 }
6802
6803 /*
6804 * Sets the position of a splitbar (pecentage).
6805 * Parameters:
6806 * handle: The handle to the splitbar returned by dw_splitbar_new().
6807 */
6808 void dw_splitbar_set(HWND handle, int percent)
6809 {
6810 /* We probably need to force a redraw here */
6811 dw_window_set_data(handle, "_dw_percent", (void *)percent);
6812 }
6813
6814 /*
6815 * Gets the position of a splitbar (pecentage).
6816 * Parameters:
6817 * handle: The handle to the splitbar returned by dw_splitbar_new().
6818 */
6819 int dw_splitbar_get(HWND handle)
6820 {
6821 return (int)dw_window_get_data(handle, "_dw_percent");
6822 }
6823
6824 /*
6716 * Pack a splitbar (sizer) into the specified box from the start. 6825 * Pack a splitbar (sizer) into the specified box from the start.
6717 * Parameters: 6826 * Parameters:
6718 * box: Window handle of the box to be packed into. 6827 * box: Window handle of the box to be packed into.
6719 */ 6828 */
6720 void dw_box_pack_splitbar_start(HWND box) 6829 void dw_box_pack_splitbar_start(HWND box)
7156 * data: User data to be passed to the handler function. 7265 * data: User data to be passed to the handler function.
7157 */ 7266 */
7158 void dw_window_set_data(HWND window, char *dataname, void *data) 7267 void dw_window_set_data(HWND window, char *dataname, void *data)
7159 { 7268 {
7160 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(window, GWL_USERDATA); 7269 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(window, GWL_USERDATA);
7270
7271 if(!cinfo)
7272 {
7273 cinfo = calloc(1, sizeof(ColorInfo));
7274 SetWindowLong(window, GWL_USERDATA, (LONG)cinfo);
7275 }
7161 7276
7162 if(cinfo) 7277 if(cinfo)
7163 { 7278 {
7164 if(data) 7279 if(data)
7165 new_userdata(&(cinfo->root), dataname, data); 7280 new_userdata(&(cinfo->root), dataname, data);