Mercurial > dwindows
comparison win/dw.c @ 124:edf615d8266e
Use float instead of int for percent on Windows. And a minor safety check
on OS/2.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 20 Oct 2002 01:41:04 +0000 |
parents | 1cad81b7cc4c |
children | 72cb88af4490 |
comparison
equal
deleted
inserted
replaced
123:63f61a702b17 | 124:edf615d8266e |
---|---|
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 int percent = (int)dw_window_get_data(hwnd, "_dw_percent"); | 2306 float *percent = (float *)dw_window_get_data(hwnd, "_dw_percent"); |
2307 int type = (int)dw_window_get_data(hwnd, "_dw_type"); | 2307 int type = (int)dw_window_get_data(hwnd, "_dw_type"); |
2308 | 2308 |
2309 switch (msg) | 2309 switch (msg) |
2310 { | 2310 { |
2311 case WM_ACTIVATE: | 2311 case WM_ACTIVATE: |
2314 | 2314 |
2315 case WM_SIZE: | 2315 case WM_SIZE: |
2316 { | 2316 { |
2317 int x = LOWORD(mp2), y = HIWORD(mp2); | 2317 int x = LOWORD(mp2), y = HIWORD(mp2); |
2318 | 2318 |
2319 if(x > 0 && y > 0) | 2319 if(x > 0 && y > 0 && percent) |
2320 { | 2320 { |
2321 if(type == BOXHORZ) | 2321 if(type == BOXHORZ) |
2322 { | 2322 { |
2323 int newx = x - SPLITBAR_WIDTH, newy = y; | 2323 int newx = x - SPLITBAR_WIDTH, newy = y; |
2324 float ratio = (float)percent/(float)100; | 2324 float ratio = (float)*percent/(float)100.0; |
2325 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); | 2325 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); |
2326 Box *tmp = (Box *)GetWindowLong(handle, GWL_USERDATA); | 2326 Box *tmp = (Box *)GetWindowLong(handle, GWL_USERDATA); |
2327 | 2327 |
2328 newx = (int)((float)newx * ratio); | 2328 newx = (int)((float)newx * ratio); |
2329 | 2329 |
2341 dw_window_set_data(hwnd, "_dw_start", (void *)newx); | 2341 dw_window_set_data(hwnd, "_dw_start", (void *)newx); |
2342 } | 2342 } |
2343 else | 2343 else |
2344 { | 2344 { |
2345 int newx = x, newy = y - SPLITBAR_WIDTH; | 2345 int newx = x, newy = y - SPLITBAR_WIDTH; |
2346 float ratio = (float)(100-percent)/(float)100; | 2346 float ratio = (float)(100.0-*percent)/(float)100.0; |
2347 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); | 2347 HWND handle = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); |
2348 Box *tmp = (Box *)GetWindowLong(handle, GWL_USERDATA); | 2348 Box *tmp = (Box *)GetWindowLong(handle, GWL_USERDATA); |
2349 | 2349 |
2350 newy = (int)((float)newy * ratio); | 2350 newy = (int)((float)newy * ratio); |
2351 | 2351 |
6783 NULL); | 6783 NULL); |
6784 | 6784 |
6785 if(tmp) | 6785 if(tmp) |
6786 { | 6786 { |
6787 HWND tmpbox = dw_box_new(BOXVERT, 0); | 6787 HWND tmpbox = dw_box_new(BOXVERT, 0); |
6788 float *percent = (float *)malloc(sizeof(float)); | |
6788 | 6789 |
6789 dw_box_pack_start(tmpbox, topleft, 1, 1, TRUE, TRUE, 0); | 6790 dw_box_pack_start(tmpbox, topleft, 1, 1, TRUE, TRUE, 0); |
6790 SetParent(tmpbox, tmp); | 6791 SetParent(tmpbox, tmp); |
6791 dw_window_set_data(tmp, "_dw_topleft", (void *)tmpbox); | 6792 dw_window_set_data(tmp, "_dw_topleft", (void *)tmpbox); |
6792 | 6793 |
6793 tmpbox = dw_box_new(BOXVERT, 0); | 6794 tmpbox = dw_box_new(BOXVERT, 0); |
6794 dw_box_pack_start(tmpbox, bottomright, 1, 1, TRUE, TRUE, 0); | 6795 dw_box_pack_start(tmpbox, bottomright, 1, 1, TRUE, TRUE, 0); |
6795 SetParent(tmpbox, tmp); | 6796 SetParent(tmpbox, tmp); |
6796 dw_window_set_data(tmp, "_dw_bottomright", (void *)tmpbox); | 6797 dw_window_set_data(tmp, "_dw_bottomright", (void *)tmpbox); |
6797 dw_window_set_data(tmp, "_dw_percent", (void *)50); | 6798 *percent = 50.0; |
6799 dw_window_set_data(tmp, "_dw_percent", (void *)percent); | |
6798 dw_window_set_data(tmp, "_dw_type", (void *)type); | 6800 dw_window_set_data(tmp, "_dw_type", (void *)type); |
6799 } | 6801 } |
6800 return tmp; | 6802 return tmp; |
6801 } | 6803 } |
6802 | 6804 |
6803 /* | 6805 /* |
6804 * Sets the position of a splitbar (pecentage). | 6806 * Sets the position of a splitbar (pecentage). |
6805 * Parameters: | 6807 * Parameters: |
6806 * handle: The handle to the splitbar returned by dw_splitbar_new(). | 6808 * handle: The handle to the splitbar returned by dw_splitbar_new(). |
6807 */ | 6809 */ |
6808 void dw_splitbar_set(HWND handle, int percent) | 6810 void dw_splitbar_set(HWND handle, float percent) |
6809 { | 6811 { |
6810 /* We probably need to force a redraw here */ | 6812 /* We probably need to force a redraw here */ |
6811 dw_window_set_data(handle, "_dw_percent", (void *)percent); | 6813 float *mypercent = (float *)dw_window_get_data(handle, "_dw_percent"); |
6814 | |
6815 if(mypercent) | |
6816 *mypercent = percent; | |
6812 } | 6817 } |
6813 | 6818 |
6814 /* | 6819 /* |
6815 * Gets the position of a splitbar (pecentage). | 6820 * Gets the position of a splitbar (pecentage). |
6816 * Parameters: | 6821 * Parameters: |
6817 * handle: The handle to the splitbar returned by dw_splitbar_new(). | 6822 * handle: The handle to the splitbar returned by dw_splitbar_new(). |
6818 */ | 6823 */ |
6819 int dw_splitbar_get(HWND handle) | 6824 float dw_splitbar_get(HWND handle) |
6820 { | 6825 { |
6821 return (int)dw_window_get_data(handle, "_dw_percent"); | 6826 float *percent = (float *)dw_window_get_data(handle, "_dw_percent"); |
6822 } | 6827 |
6823 | 6828 if(percent) |
6824 /* | 6829 return *percent; |
6825 * Pack a splitbar (sizer) into the specified box from the start. | 6830 return 0.0; |
6826 * Parameters: | |
6827 * box: Window handle of the box to be packed into. | |
6828 */ | |
6829 void dw_box_pack_splitbar_start(HWND box) | |
6830 { | |
6831 Box *thisbox = (Box *)GetWindowLong(box, GWL_USERDATA); | |
6832 | |
6833 if(thisbox) | |
6834 { | |
6835 HWND tmp = CreateWindow(SplitbarClassName, | |
6836 "", | |
6837 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, | |
6838 0,0,2000,1000, | |
6839 DW_HWND_OBJECT, | |
6840 NULL, | |
6841 DWInstance, | |
6842 NULL); | |
6843 if(thisbox->type == BOXVERT) | |
6844 dw_box_pack_start(box, tmp, 1, SPLITBAR_WIDTH, TRUE, FALSE, 0); | |
6845 else | |
6846 dw_box_pack_start(box, tmp, SPLITBAR_WIDTH, 1, FALSE, TRUE, 0); | |
6847 | |
6848 } | |
6849 } | |
6850 | |
6851 /* | |
6852 * Pack a splitbar (sizer) into the specified box from the end. | |
6853 * Parameters: | |
6854 * box: Window handle of the box to be packed into. | |
6855 */ | |
6856 void dw_box_pack_splitbar_end(HWND box) | |
6857 { | |
6858 Box *thisbox = (Box *)GetWindowLong(box, GWL_USERDATA); | |
6859 | |
6860 if(thisbox) | |
6861 { | |
6862 HWND tmp = CreateWindow(SplitbarClassName, | |
6863 "", | |
6864 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, | |
6865 0,0,2000,1000, | |
6866 DW_HWND_OBJECT, | |
6867 NULL, | |
6868 DWInstance, | |
6869 NULL); | |
6870 if(thisbox->type == BOXVERT) | |
6871 dw_box_pack_end(box, tmp, 1, SPLITBAR_WIDTH, TRUE, FALSE, 0); | |
6872 else | |
6873 dw_box_pack_end(box, tmp, SPLITBAR_WIDTH, 1, FALSE, TRUE, 0); | |
6874 | |
6875 } | |
6876 } | 6831 } |
6877 | 6832 |
6878 /* | 6833 /* |
6879 * Pack windows (widgets) into a box from the end (or bottom). | 6834 * Pack windows (widgets) into a box from the end (or bottom). |
6880 * Parameters: | 6835 * Parameters: |