Mercurial > dwindows
comparison os2/dw.c @ 125:0d2cbd9d4028
Finished the OS/2 splitbar support.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 20 Oct 2002 03:11:49 +0000 |
parents | edf615d8266e |
children | c5c3ccb84ac7 |
comparison
equal
deleted
inserted
replaced
124:edf615d8266e | 125:0d2cbd9d4028 |
---|---|
685 if(thisbox) | 685 if(thisbox) |
686 { | 686 { |
687 if(_focus_check_box_back(thisbox, handle, 1, 0) == 0) | 687 if(_focus_check_box_back(thisbox, handle, 1, 0) == 0) |
688 _focus_check_box_back(thisbox, handle, 2, 0); | 688 _focus_check_box_back(thisbox, handle, 2, 0); |
689 } | 689 } |
690 } | |
691 | |
692 /* ResetWindow: | |
693 * Resizes window to the exact same size to trigger | |
694 * recalculation of frame. | |
695 */ | |
696 void _ResetWindow(HWND hwndFrame) | |
697 { | |
698 SWP swp; | |
699 | |
700 WinQueryWindowPos(hwndFrame, &swp); | |
701 WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, swp.cx, swp.cy-1, SWP_SIZE); | |
702 WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, swp.cx, swp.cy, SWP_SIZE); | |
703 } | 690 } |
704 | 691 |
705 /* This function will recursively search a box and add up the total height of it */ | 692 /* This function will recursively search a box and add up the total height of it */ |
706 void _count_size(HWND box, int type, int *xsize, int *xorigsize) | 693 void _count_size(HWND box, int type, int *xsize, int *xorigsize) |
707 { | 694 { |
2301 } | 2288 } |
2302 } | 2289 } |
2303 } | 2290 } |
2304 } | 2291 } |
2305 | 2292 |
2293 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y) | |
2294 { | |
2295 if(type == BOXHORZ) | |
2296 { | |
2297 int newx = x - SPLITBAR_WIDTH, newy = y; | |
2298 float ratio = (float)percent/(float)100.0; | |
2299 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); | |
2300 Box *tmp = WinQueryWindowPtr(handle, QWP_USER); | |
2301 | |
2302 newx = (int)((float)newx * ratio); | |
2303 | |
2304 WinSetWindowPos(handle, NULLHANDLE, 0, 0, newx, y, SWP_MOVE | SWP_SIZE | SWP_SHOW); | |
2305 _do_resize(tmp, newx, y); | |
2306 | |
2307 dw_window_set_data(hwnd, "_dw_start", (void *)newx); | |
2308 | |
2309 handle = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); | |
2310 tmp = WinQueryWindowPtr(handle, QWP_USER); | |
2311 | |
2312 newx = x - newx - SPLITBAR_WIDTH; | |
2313 | |
2314 WinSetWindowPos(handle, NULLHANDLE, x - newx, 0, newx, y, SWP_MOVE | SWP_SIZE | SWP_SHOW); | |
2315 _do_resize(tmp, newx, y); | |
2316 } | |
2317 else | |
2318 { | |
2319 int newx = x, newy = y - SPLITBAR_WIDTH; | |
2320 float ratio = (float)percent/(float)100.0; | |
2321 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); | |
2322 Box *tmp = WinQueryWindowPtr(handle, QWP_USER); | |
2323 | |
2324 newy = (int)((float)newy * ratio); | |
2325 | |
2326 WinSetWindowPos(handle, NULLHANDLE, 0, y - newy, x, newy, SWP_MOVE | SWP_SIZE | SWP_SHOW); | |
2327 _do_resize(tmp, x, newy); | |
2328 | |
2329 handle = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); | |
2330 tmp = WinQueryWindowPtr(handle, QWP_USER); | |
2331 | |
2332 newy = y - newy - SPLITBAR_WIDTH; | |
2333 | |
2334 WinSetWindowPos(handle, NULLHANDLE, 0, 0, x, newy, SWP_MOVE | SWP_SIZE | SWP_SHOW); | |
2335 _do_resize(tmp, x, newy); | |
2336 | |
2337 dw_window_set_data(hwnd, "_dw_start", (void *)newy); | |
2338 } | |
2339 } | |
2340 | |
2341 | |
2306 /* This handles any activity on the splitbars (sizers) */ | 2342 /* This handles any activity on the splitbars (sizers) */ |
2307 MRESULT EXPENTRY _splitwndproc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 2343 MRESULT EXPENTRY _splitwndproc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) |
2308 { | 2344 { |
2309 float *percent = (float *)dw_window_get_data(hwnd, "_dw_percent"); | 2345 float *percent = (float *)dw_window_get_data(hwnd, "_dw_percent"); |
2310 int type = (int)dw_window_get_data(hwnd, "_dw_type"); | 2346 int type = (int)dw_window_get_data(hwnd, "_dw_type"); |
2347 int start = (int)dw_window_get_data(hwnd, "_dw_start"); | |
2311 | 2348 |
2312 switch (msg) | 2349 switch (msg) |
2313 { | 2350 { |
2314 case WM_ACTIVATE: | 2351 case WM_ACTIVATE: |
2315 case WM_SETFOCUS: | 2352 case WM_SETFOCUS: |
2318 case WM_SIZE: | 2355 case WM_SIZE: |
2319 { | 2356 { |
2320 int x = SHORT1FROMMP(mp2), y = SHORT2FROMMP(mp2); | 2357 int x = SHORT1FROMMP(mp2), y = SHORT2FROMMP(mp2); |
2321 | 2358 |
2322 if(x > 0 && y > 0 && percent) | 2359 if(x > 0 && y > 0 && percent) |
2323 { | 2360 _handle_splitbar_resize(hwnd, *percent, type, x, y); |
2324 if(type == BOXHORZ) | |
2325 { | |
2326 int newx = x - SPLITBAR_WIDTH, newy = y; | |
2327 float ratio = (float)*percent/(float)100.0; | |
2328 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); | |
2329 Box *tmp = WinQueryWindowPtr(handle, QWP_USER); | |
2330 | |
2331 newx = (int)((float)newx * ratio); | |
2332 | |
2333 WinSetWindowPos(handle, NULLHANDLE, 0, 0, newx, y, SWP_MOVE | SWP_SIZE | SWP_SHOW); | |
2334 _do_resize(tmp, newx, y); | |
2335 | |
2336 handle = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); | |
2337 tmp = WinQueryWindowPtr(handle, QWP_USER); | |
2338 | |
2339 newx = x - newx - SPLITBAR_WIDTH; | |
2340 | |
2341 WinSetWindowPos(handle, NULLHANDLE, x - newx, 0, newx, y, SWP_MOVE | SWP_SIZE | SWP_SHOW); | |
2342 _do_resize(tmp, newx, y); | |
2343 | |
2344 dw_window_set_data(hwnd, "_dw_start", (void *)newx); | |
2345 } | |
2346 else | |
2347 { | |
2348 int newx = x, newy = y - SPLITBAR_WIDTH; | |
2349 float ratio = (float)*percent/(float)100.0; | |
2350 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); | |
2351 Box *tmp = WinQueryWindowPtr(handle, QWP_USER); | |
2352 | |
2353 newy = (int)((float)newy * ratio); | |
2354 | |
2355 WinSetWindowPos(handle, NULLHANDLE, 0, y - newy, x, newy, SWP_MOVE | SWP_SIZE | SWP_SHOW); | |
2356 _do_resize(tmp, x, newy); | |
2357 | |
2358 handle = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); | |
2359 tmp = WinQueryWindowPtr(handle, QWP_USER); | |
2360 | |
2361 newy = y - newy - SPLITBAR_WIDTH; | |
2362 | |
2363 WinSetWindowPos(handle, NULLHANDLE, 0, 0, x, newy, SWP_MOVE | SWP_SIZE | SWP_SHOW); | |
2364 _do_resize(tmp, x, newy); | |
2365 | |
2366 dw_window_set_data(hwnd, "_dw_start", (void *)newy); | |
2367 } | |
2368 } | |
2369 } | 2361 } |
2370 break; | 2362 break; |
2371 case WM_PAINT: | 2363 case WM_PAINT: |
2372 { | 2364 { |
2373 HPS hpsPaint; | 2365 HPS hpsPaint; |
2374 RECTL rclPaint; | 2366 RECTL rclPaint; |
2375 POINTL ptlStart[SPLITBAR_WIDTH]; | 2367 POINTL ptlStart[SPLITBAR_WIDTH]; |
2376 POINTL ptlEnd[SPLITBAR_WIDTH]; | 2368 POINTL ptlEnd[SPLITBAR_WIDTH]; |
2377 USHORT i; | 2369 USHORT i; |
2378 int start = (int)dw_window_get_data(hwnd, "_dw_start"); | |
2379 | 2370 |
2380 hpsPaint = WinBeginPaint(hwnd, 0, 0); | 2371 hpsPaint = WinBeginPaint(hwnd, 0, 0); |
2381 WinQueryWindowRect(hwnd, &rclPaint); | 2372 WinQueryWindowRect(hwnd, &rclPaint); |
2382 | 2373 |
2383 if(type == BOXHORZ) | 2374 if(type == BOXHORZ) |
2427 FALSE)); | 2418 FALSE)); |
2428 } | 2419 } |
2429 return MRFROMSHORT(FALSE); | 2420 return MRFROMSHORT(FALSE); |
2430 case WM_BUTTON1DOWN: | 2421 case WM_BUTTON1DOWN: |
2431 { | 2422 { |
2432 #if 0 | |
2433 APIRET rc; | 2423 APIRET rc; |
2434 RECTL rclFrame; | 2424 RECTL rclFrame; |
2435 RECTL rclBounds; | 2425 RECTL rclBounds; |
2436 RECTL rclStart; | |
2437 USHORT startSize, orig, actual; | |
2438 | 2426 |
2439 WinQueryWindowRect(hwnd, &rclFrame); | 2427 WinQueryWindowRect(hwnd, &rclFrame); |
2440 WinQueryWindowRect(hwnd, &rclStart); | 2428 WinQueryWindowRect(hwnd, &rclBounds); |
2441 | 2429 |
2442 WinQueryWindowRect(hwndFrame, &rclBounds); | 2430 WinMapWindowPoints(hwnd, HWND_DESKTOP, |
2443 | |
2444 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, | |
2445 (PPOINTL)&rclBounds, 2); | 2431 (PPOINTL)&rclBounds, 2); |
2446 WinMapWindowPoints(hwnd, HWND_DESKTOP, | 2432 |
2447 (PPOINTL)&rclStart, 2); | 2433 |
2448 | 2434 if(type == BOXHORZ) |
2449 { | 2435 { |
2450 int z, pastsplitbar = FALSE, found = FALSE; | 2436 rclFrame.xLeft = start; |
2451 orig = actual = 0; | 2437 rclFrame.xRight = start + SPLITBAR_WIDTH; |
2452 | 2438 } |
2453 for(z=0;z<thisbox->count;z++) | 2439 else |
2440 { | |
2441 rclFrame.yBottom = start; | |
2442 rclFrame.yTop = start + SPLITBAR_WIDTH; | |
2443 } | |
2444 | |
2445 if(percent) | |
2446 { | |
2447 rc = _TrackRectangle(hwnd, &rclFrame, &rclBounds); | |
2448 | |
2449 if(rc == TRUE) | |
2454 { | 2450 { |
2455 if(thisbox->items[z].hwnd == hwnd) | 2451 int width = (rclBounds.xRight - rclBounds.xLeft); |
2456 pastsplitbar = TRUE; | 2452 int height = (rclBounds.yTop - rclBounds.yBottom); |
2457 else | 2453 |
2454 if(type == BOXHORZ) | |
2458 { | 2455 { |
2459 if(thisbox->type == BOXHORZ) | 2456 start = rclFrame.xLeft - rclBounds.xLeft; |
2460 { | 2457 *percent = ((float)start / (float)(rclBounds.xRight - rclBounds.xLeft - SPLITBAR_WIDTH)) * 100.0; |
2461 int tmpwidth, tmporigwidth; | |
2462 | |
2463 if(thisbox->items[z].type == TYPEBOX) | |
2464 _count_size(thisbox->items[z].hwnd, BOXHORZ, &tmpwidth, &tmporigwidth); | |
2465 else | |
2466 { | |
2467 tmpwidth = thisbox->items[z].width; | |
2468 tmporigwidth = thisbox->items[z].origwidth; | |
2469 } | |
2470 | |
2471 if(thisbox->items[z].hsize != SIZESTATIC && tmpwidth > actual && tmporigwidth) | |
2472 { | |
2473 found = pastsplitbar; | |
2474 orig = tmporigwidth; | |
2475 actual = tmpwidth; | |
2476 } | |
2477 } | |
2478 else | |
2479 { | |
2480 int tmpheight, tmporigheight; | |
2481 | |
2482 if(thisbox->items[z].type == TYPEBOX) | |
2483 _count_size(thisbox->items[z].hwnd, BOXVERT, &tmpheight, &tmporigheight); | |
2484 else | |
2485 { | |
2486 tmpheight = thisbox->items[z].height; | |
2487 tmporigheight = thisbox->items[z].origheight; | |
2488 } | |
2489 | |
2490 if(thisbox->items[z].vsize != SIZESTATIC && tmpheight > actual && tmporigheight) | |
2491 { | |
2492 found = pastsplitbar; | |
2493 orig = tmporigheight; | |
2494 actual = tmpheight; | |
2495 } | |
2496 } | |
2497 } | |
2498 } | |
2499 | |
2500 /* If we couldn't determine a valid scale... then abort */ | |
2501 if(!orig || !actual) | |
2502 return MRFROMSHORT(FALSE); | |
2503 | |
2504 if(thisbox->type == BOXHORZ) | |
2505 { | |
2506 if(found) | |
2507 startSize = (rclStart.xLeft - rclBounds.xLeft) | |
2508 * (((float)actual)/((float)orig)); | |
2509 else | |
2510 startSize = (rclStart.xLeft - rclBounds.xLeft) | |
2511 * (((float)orig)/((float)actual)); | |
2512 } | |
2513 else | |
2514 { | |
2515 if(found) | |
2516 startSize = (rclStart.yBottom - rclBounds.yBottom) | |
2517 * (((float)actual)/((float)orig)); | |
2518 else | |
2519 startSize = (rclStart.yBottom - rclBounds.yBottom) | |
2520 * (((float)orig)/((float)actual)); | |
2521 } | |
2522 } | |
2523 | |
2524 rc = _TrackRectangle(hwnd, &rclFrame, &rclBounds); | |
2525 | |
2526 if(rc == TRUE) | |
2527 { | |
2528 USHORT usNewRB; | |
2529 USHORT percent; | |
2530 int z; | |
2531 | |
2532 if(thisbox->type == BOXHORZ) | |
2533 { | |
2534 usNewRB = rclFrame.xLeft | |
2535 - rclBounds.xLeft; | |
2536 } | |
2537 else | |
2538 { | |
2539 usNewRB = rclFrame.yBottom | |
2540 - rclBounds.yBottom; | |
2541 } | |
2542 | |
2543 /* We don't want the item to disappear completely */ | |
2544 if(!usNewRB) | |
2545 usNewRB++; | |
2546 | |
2547 if(!startSize) | |
2548 startSize++; | |
2549 | |
2550 percent = (usNewRB*100)/startSize; | |
2551 | |
2552 for(z=0;z<thisbox->count;z++) | |
2553 { | |
2554 if(thisbox->items[z].type == TYPEBOX) | |
2555 { | |
2556 Box *tmp = WinQueryWindowPtr(thisbox->items[z].hwnd, QWP_USER); | |
2557 | |
2558 if(tmp) | |
2559 _changebox(tmp, percent, thisbox->type); | |
2560 } | 2458 } |
2561 else | 2459 else |
2562 { | 2460 { |
2563 if(thisbox->items[z].hwnd == hwnd) | 2461 start = rclFrame.yBottom - rclBounds.yBottom; |
2564 percent = (startSize*100)/usNewRB; | 2462 *percent = 100.0 - (((float)start / (float)(rclBounds.yTop - rclBounds.yBottom - SPLITBAR_WIDTH)) * 100.0); |
2565 | |
2566 if(thisbox->type == BOXHORZ) | |
2567 { | |
2568 if(thisbox->items[z].hsize == SIZEEXPAND) | |
2569 thisbox->items[z].width = (int)(((float)thisbox->items[z].origwidth) * (((float)percent)/((float)100.0))); | |
2570 } | |
2571 else | |
2572 { | |
2573 if(thisbox->items[z].vsize == SIZEEXPAND) | |
2574 thisbox->items[z].height = (int)(((float)thisbox->items[z].origheight) * (((float)percent)/((float)100.0))); | |
2575 } | |
2576 } | 2463 } |
2464 _handle_splitbar_resize(hwnd, *percent, type, width, height); | |
2577 } | 2465 } |
2578 | |
2579 _ResetWindow(WinQueryWindow(hwnd, QW_OWNER)); | |
2580 } | 2466 } |
2581 #endif | |
2582 } | 2467 } |
2583 return MRFROMSHORT(FALSE); | 2468 return MRFROMSHORT(FALSE); |
2584 } | 2469 } |
2585 return WinDefWindowProc(hwnd, msg, mp1, mp2); | 2470 return WinDefWindowProc(hwnd, msg, mp1, mp2); |
2586 } | 2471 } |
6742 */ | 6627 */ |
6743 void dw_splitbar_set(HWND handle, float percent) | 6628 void dw_splitbar_set(HWND handle, float percent) |
6744 { | 6629 { |
6745 /* We probably need to force a redraw here */ | 6630 /* We probably need to force a redraw here */ |
6746 float *mypercent = (float *)dw_window_get_data(handle, "_dw_percent"); | 6631 float *mypercent = (float *)dw_window_get_data(handle, "_dw_percent"); |
6632 int type = (int)dw_window_get_data(handle, "_dw_type"); | |
6633 int width, height; | |
6747 | 6634 |
6748 if(mypercent) | 6635 if(mypercent) |
6749 *mypercent = percent; | 6636 *mypercent = percent; |
6637 | |
6638 dw_window_get_pos_size(handle, NULL, NULL, &width, &height); | |
6639 | |
6640 _handle_splitbar_resize(handle, percent, type, width, height); | |
6750 } | 6641 } |
6751 | 6642 |
6752 /* | 6643 /* |
6753 * Gets the position of a splitbar (pecentage). | 6644 * Gets the position of a splitbar (pecentage). |
6754 * Parameters: | 6645 * Parameters: |