Mercurial > dwindows
comparison mac/dw.m @ 666:e426de6e6c7c
Changes to make the resize function more like on the other platforms.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 26 Feb 2011 16:07:04 +0000 |
parents | e6bec2290f3f |
children | 28727d9a835c |
comparison
equal
deleted
inserted
replaced
665:e6bec2290f3f | 666:e426de6e6c7c |
---|---|
118 } | 118 } |
119 case 3: | 119 case 3: |
120 case 4: | 120 case 4: |
121 { | 121 { |
122 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; | 122 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; |
123 int flags = [object pressedMouseButtons]; | 123 int flags = (int)[object pressedMouseButtons]; |
124 NSPoint point = [object mouseLocation]; | 124 NSPoint point = [object mouseLocation]; |
125 int button = 0; | 125 int button = 0; |
126 char *which = "pressed"; | 126 char *which = "pressed"; |
127 | 127 |
128 if(message == 4) | 128 if(message == 4) |
222 */ | 222 */ |
223 | 223 |
224 /* Subclass for a box type */ | 224 /* Subclass for a box type */ |
225 @interface DWBox : NSView <NSWindowDelegate> | 225 @interface DWBox : NSView <NSWindowDelegate> |
226 { | 226 { |
227 Box box; | 227 Box *box; |
228 void *userdata; | 228 void *userdata; |
229 NSColor *bgcolor; | 229 NSColor *bgcolor; |
230 } | 230 } |
231 -(Box)box; | 231 - (id)init; |
232 -(void) dealloc; | |
233 -(Box *)box; | |
232 -(void *)userdata; | 234 -(void *)userdata; |
233 -(void)setBox:(Box)input; | |
234 -(void)setUserdata:(void *)input; | 235 -(void)setUserdata:(void *)input; |
235 -(void)drawRect:(NSRect)rect; | 236 -(void)drawRect:(NSRect)rect; |
236 -(BOOL)isFlipped; | 237 -(BOOL)isFlipped; |
237 -(void)mouseDown:(NSEvent *)theEvent; | 238 -(void)mouseDown:(NSEvent *)theEvent; |
238 -(void)mouseUp:(NSEvent *)theEvent; | 239 -(void)mouseUp:(NSEvent *)theEvent; |
239 -(void)setColor:(unsigned long)input; | 240 -(void)setColor:(unsigned long)input; |
240 @end | 241 @end |
241 | 242 |
242 @implementation DWBox | 243 @implementation DWBox |
243 -(Box)box { return box; } | 244 - (id)init |
245 { | |
246 self = [super init]; | |
247 | |
248 if (self) | |
249 { | |
250 box = calloc(1, sizeof(Box)); | |
251 } | |
252 return self; | |
253 } | |
254 -(void) dealloc | |
255 { | |
256 free(box); | |
257 [super dealloc]; | |
258 } | |
259 -(Box *)box { return box; } | |
244 -(void *)userdata { return userdata; } | 260 -(void *)userdata { return userdata; } |
245 -(void)setBox:(Box)input { box = input; } | |
246 -(void)setUserdata:(void *)input { userdata = input; } | 261 -(void)setUserdata:(void *)input { userdata = input; } |
247 -(void)drawRect:(NSRect)rect | 262 -(void)drawRect:(NSRect)rect |
248 { | 263 { |
249 if(bgcolor) | 264 if(bgcolor) |
250 { | 265 { |
297 [super dealloc]; | 312 [super dealloc]; |
298 } | 313 } |
299 - (void)windowResized:(NSNotification *)notification; | 314 - (void)windowResized:(NSNotification *)notification; |
300 { | 315 { |
301 NSSize size = [self frame].size; | 316 NSSize size = [self frame].size; |
302 _do_resize(&box, size.width, size.height); | 317 _do_resize(box, size.width, size.height); |
303 _event_handler([self window], nil, 1); | 318 _event_handler([self window], nil, 1); |
304 } | 319 } |
305 -(void)windowDidBecomeMain:(id)sender | 320 -(void)windowDidBecomeMain:(id)sender |
306 { | 321 { |
307 if(windowmenu) | 322 if(windowmenu) |
399 id object = [notepage view]; | 414 id object = [notepage view]; |
400 | 415 |
401 if([object isMemberOfClass:[DWBox class]]) | 416 if([object isMemberOfClass:[DWBox class]]) |
402 { | 417 { |
403 DWBox *view = object; | 418 DWBox *view = object; |
404 Box box = [view box]; | 419 Box *box = [view box]; |
405 NSSize size = [view frame].size; | 420 NSSize size = [view frame].size; |
406 _do_resize(&box, size.width, size.height); | 421 _do_resize(box, size.width, size.height); |
407 } | 422 } |
408 } | 423 } |
409 @end | 424 @end |
410 | 425 |
411 /* Subclass for a Notebook page type */ | 426 /* Subclass for a Notebook page type */ |
458 for(object in views) | 473 for(object in views) |
459 { | 474 { |
460 if([object isMemberOfClass:[DWBox class]]) | 475 if([object isMemberOfClass:[DWBox class]]) |
461 { | 476 { |
462 DWBox *view = object; | 477 DWBox *view = object; |
463 Box box = [view box]; | 478 Box *box = [view box]; |
464 NSSize size = [view frame].size; | 479 NSSize size = [view frame].size; |
465 _do_resize(&box, size.width, size.height); | 480 _do_resize(box, size.width, size.height); |
466 } | 481 } |
467 } | 482 } |
468 } | 483 } |
469 @end | 484 @end |
470 | 485 |
835 /* This function will recursively search a box and add up the total height of it */ | 850 /* This function will recursively search a box and add up the total height of it */ |
836 static void _count_size(HWND thisbox, int type, int *xsize, int *xorigsize) | 851 static void _count_size(HWND thisbox, int type, int *xsize, int *xorigsize) |
837 { | 852 { |
838 int size = 0, origsize = 0, z; | 853 int size = 0, origsize = 0, z; |
839 DWBox *box = thisbox; | 854 DWBox *box = thisbox; |
840 Box _tmp = [box box]; | 855 Box *tmp = [box box]; |
841 Box *tmp = &_tmp; | |
842 | 856 |
843 if(!tmp) | 857 if(!tmp) |
844 { | 858 { |
845 *xsize = *xorigsize = 0; | 859 *xsize = *xorigsize = 0; |
846 return; | 860 return; |
914 { | 928 { |
915 if(thisbox->items[z].type == TYPEBOX) | 929 if(thisbox->items[z].type == TYPEBOX) |
916 { | 930 { |
917 int initialx, initialy; | 931 int initialx, initialy; |
918 DWBox *box = thisbox->items[z].hwnd; | 932 DWBox *box = thisbox->items[z].hwnd; |
919 Box _tmp = [box box]; | 933 Box *tmp = [box box]; |
920 Box *tmp = &_tmp; | |
921 | 934 |
922 initialx = x - (*usedx); | 935 initialx = x - (*usedx); |
923 initialy = y - (*usedy); | 936 initialy = y - (*usedy); |
924 | 937 |
925 if(tmp) | 938 if(tmp) |
977 } | 990 } |
978 | 991 |
979 nux = *usedx; nuy = *usedy; | 992 nux = *usedx; nuy = *usedy; |
980 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); | 993 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); |
981 } | 994 } |
982 [box setBox:_tmp]; | |
983 | 995 |
984 (*depth)++; | 996 (*depth)++; |
985 | 997 |
986 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); | 998 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); |
987 | 999 |
990 newx = x - nux; | 1002 newx = x - nux; |
991 newy = y - nuy; | 1003 newy = y - nuy; |
992 | 1004 |
993 tmp->minwidth = thisbox->items[z].width = initialx - newx; | 1005 tmp->minwidth = thisbox->items[z].width = initialx - newx; |
994 tmp->minheight = thisbox->items[z].height = initialy - newy; | 1006 tmp->minheight = thisbox->items[z].height = initialy - newy; |
995 [box setBox:_tmp]; | |
996 } | 1007 } |
997 } | 1008 } |
998 | 1009 |
999 if(pass > 1 && *depth > 0) | 1010 if(pass > 1 && *depth > 0) |
1000 { | 1011 { |
1029 } | 1040 } |
1030 | 1041 |
1031 if(thisbox->items[z].type == TYPEBOX) | 1042 if(thisbox->items[z].type == TYPEBOX) |
1032 { | 1043 { |
1033 DWBox *box = thisbox->items[z].hwnd; | 1044 DWBox *box = thisbox->items[z].hwnd; |
1034 Box _tmp = [box box]; | 1045 Box *tmp = [box box]; |
1035 Box *tmp = &_tmp; | |
1036 | 1046 |
1037 if(tmp) | 1047 if(tmp) |
1038 { | 1048 { |
1039 tmp->parentxratio = thisbox->items[z].xratio; | 1049 tmp->parentxratio = thisbox->items[z].xratio; |
1040 tmp->parentyratio = thisbox->items[z].yratio; | 1050 tmp->parentyratio = thisbox->items[z].yratio; |
1041 } | 1051 } |
1042 [box setBox:_tmp]; | |
1043 } | 1052 } |
1044 } | 1053 } |
1045 else | 1054 else |
1046 { | 1055 { |
1047 thisbox->items[z].xratio = thisbox->xratio; | 1056 thisbox->items[z].xratio = thisbox->xratio; |
1132 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); | 1141 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); |
1133 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ | 1142 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ |
1134 if(thisbox->items[z].type == TYPEBOX) | 1143 if(thisbox->items[z].type == TYPEBOX) |
1135 { | 1144 { |
1136 DWBox *box = thisbox->items[z].hwnd; | 1145 DWBox *box = thisbox->items[z].hwnd; |
1137 Box _tmp = [box box]; | 1146 Box *tmp = [box box]; |
1138 Box *tmp = &_tmp; | |
1139 | 1147 |
1140 if(tmp) | 1148 if(tmp) |
1141 { | 1149 { |
1142 if(*depth > 0) | 1150 if(*depth > 0) |
1143 { | 1151 { |
1160 else | 1168 else |
1161 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/calcval; | 1169 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/calcval; |
1162 tmp->height = thisbox->items[z].height; | 1170 tmp->height = thisbox->items[z].height; |
1163 } | 1171 } |
1164 } | 1172 } |
1165 [box setBox:_tmp]; | |
1166 | 1173 |
1167 (*depth)++; | 1174 (*depth)++; |
1168 | 1175 |
1169 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); | 1176 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); |
1170 | 1177 |
1171 (*depth)--; | 1178 (*depth)--; |
1172 [box setBox:_tmp]; | |
1173 | 1179 |
1174 } | 1180 } |
1175 } | 1181 } |
1176 } | 1182 } |
1177 | 1183 |
1218 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; | 1224 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; |
1219 DWBox *view = [notepage view]; | 1225 DWBox *view = [notepage view]; |
1220 | 1226 |
1221 if(view != nil) | 1227 if(view != nil) |
1222 { | 1228 { |
1223 Box box = [view box]; | 1229 Box *box = [view box]; |
1224 NSSize size = [view frame].size; | 1230 NSSize size = [view frame].size; |
1225 _do_resize(&box, size.width, size.height); | 1231 _do_resize(box, size.width, size.height); |
1226 [view setBox:box]; | |
1227 } | 1232 } |
1228 } | 1233 } |
1229 else if([handle isMemberOfClass:[DWRender class]]) | 1234 else if([handle isMemberOfClass:[DWRender class]]) |
1230 { | 1235 { |
1231 _event_handler(handle, nil, 1); | 1236 _event_handler(handle, nil, 1); |
1275 for(z=0;z<thisbox->count;z++) | 1280 for(z=0;z<thisbox->count;z++) |
1276 { | 1281 { |
1277 if(thisbox->items[z].type == TYPEBOX) | 1282 if(thisbox->items[z].type == TYPEBOX) |
1278 { | 1283 { |
1279 DWBox *box = thisbox->items[z].hwnd; | 1284 DWBox *box = thisbox->items[z].hwnd; |
1280 Box _tmp = [box box]; | 1285 Box *tmp = [box box]; |
1281 Box *tmp = &_tmp; | |
1282 _changebox(tmp, percent, type); | 1286 _changebox(tmp, percent, type); |
1283 [box setBox:_tmp]; | |
1284 } | 1287 } |
1285 else | 1288 else |
1286 { | 1289 { |
1287 if(type == DW_HORZ) | 1290 if(type == DW_HORZ) |
1288 { | 1291 { |
1693 * pad: Number of pixels to pad around the box. | 1696 * pad: Number of pixels to pad around the box. |
1694 */ | 1697 */ |
1695 HWND API dw_box_new(int type, int pad) | 1698 HWND API dw_box_new(int type, int pad) |
1696 { | 1699 { |
1697 DWBox *view = [[DWBox alloc] init]; | 1700 DWBox *view = [[DWBox alloc] init]; |
1698 Box newbox; | 1701 Box *newbox = [view box]; |
1699 memset(&newbox, 0, sizeof(Box)); | 1702 memset(newbox, 0, sizeof(Box)); |
1700 newbox.pad = pad; | 1703 newbox->pad = pad; |
1701 newbox.type = type; | 1704 newbox->type = type; |
1702 [view setBox:newbox]; | |
1703 return view; | 1705 return view; |
1704 } | 1706 } |
1705 | 1707 |
1706 /* | 1708 /* |
1707 * Create a new Group Box to be packed. | 1709 * Create a new Group Box to be packed. |
1731 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 1733 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
1732 { | 1734 { |
1733 NSObject *object = box; | 1735 NSObject *object = box; |
1734 DWBox *view = box; | 1736 DWBox *view = box; |
1735 DWBox *this = item; | 1737 DWBox *this = item; |
1736 Box thisbox; | 1738 Box *thisbox; |
1737 int z; | 1739 int z; |
1738 Item *tmpitem, *thisitem; | 1740 Item *tmpitem, *thisitem; |
1739 | 1741 |
1740 /* Query the objects */ | 1742 /* Query the objects */ |
1741 if([ object isKindOfClass:[ NSWindow class ] ]) | 1743 if([ object isKindOfClass:[ NSWindow class ] ]) |
1743 NSWindow *window = box; | 1745 NSWindow *window = box; |
1744 view = [window contentView]; | 1746 view = [window contentView]; |
1745 } | 1747 } |
1746 | 1748 |
1747 thisbox = [view box]; | 1749 thisbox = [view box]; |
1748 thisitem = thisbox.items; | 1750 thisitem = thisbox->items; |
1749 object = item; | 1751 object = item; |
1750 | 1752 |
1751 /* Duplicate the existing data */ | 1753 /* Duplicate the existing data */ |
1752 tmpitem = malloc(sizeof(Item)*(thisbox.count+1)); | 1754 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
1753 | 1755 |
1754 for(z=0;z<thisbox.count;z++) | 1756 for(z=0;z<thisbox->count;z++) |
1755 { | 1757 { |
1756 tmpitem[z+1] = thisitem[z]; | 1758 tmpitem[z+1] = thisitem[z]; |
1757 } | 1759 } |
1758 | 1760 |
1759 /* Sanity checks */ | 1761 /* Sanity checks */ |
1780 if(vsize) | 1782 if(vsize) |
1781 tmpitem[0].vsize = SIZEEXPAND; | 1783 tmpitem[0].vsize = SIZEEXPAND; |
1782 else | 1784 else |
1783 tmpitem[0].vsize = SIZESTATIC; | 1785 tmpitem[0].vsize = SIZESTATIC; |
1784 | 1786 |
1785 thisbox.items = tmpitem; | 1787 thisbox->items = tmpitem; |
1786 | 1788 |
1787 /* Update the item count */ | 1789 /* Update the item count */ |
1788 thisbox.count++; | 1790 thisbox->count++; |
1789 | 1791 |
1790 /* Add the item to the box */ | 1792 /* Add the item to the box */ |
1791 [view setBox:thisbox]; | |
1792 [view addSubview:this]; | 1793 [view addSubview:this]; |
1793 | 1794 |
1794 /* Free the old data */ | 1795 /* Free the old data */ |
1795 if(thisbox.count) | 1796 if(thisbox->count) |
1796 free(thisitem); | 1797 free(thisitem); |
1797 } | 1798 } |
1798 | 1799 |
1799 /* | 1800 /* |
1800 * Pack windows (widgets) into a box from the start (or top). | 1801 * Pack windows (widgets) into a box from the start (or top). |
1810 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 1811 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
1811 { | 1812 { |
1812 NSObject *object = box; | 1813 NSObject *object = box; |
1813 DWBox *view = box; | 1814 DWBox *view = box; |
1814 DWBox *this = item; | 1815 DWBox *this = item; |
1815 Box thisbox; | 1816 Box *thisbox; |
1816 int z; | 1817 int z; |
1817 Item *tmpitem, *thisitem; | 1818 Item *tmpitem, *thisitem; |
1818 | 1819 |
1819 /* Query the objects */ | 1820 /* Query the objects */ |
1820 if([ object isKindOfClass:[ NSWindow class ] ]) | 1821 if([ object isKindOfClass:[ NSWindow class ] ]) |
1822 NSWindow *window = box; | 1823 NSWindow *window = box; |
1823 view = [window contentView]; | 1824 view = [window contentView]; |
1824 } | 1825 } |
1825 | 1826 |
1826 thisbox = [view box]; | 1827 thisbox = [view box]; |
1827 thisitem = thisbox.items; | 1828 thisitem = thisbox->items; |
1828 object = item; | 1829 object = item; |
1829 | 1830 |
1830 /* Duplicate the existing data */ | 1831 /* Duplicate the existing data */ |
1831 tmpitem = malloc(sizeof(Item)*(thisbox.count+1)); | 1832 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
1832 | 1833 |
1833 for(z=0;z<thisbox.count;z++) | 1834 for(z=0;z<thisbox->count;z++) |
1834 { | 1835 { |
1835 tmpitem[z] = thisitem[z]; | 1836 tmpitem[z] = thisitem[z]; |
1836 } | 1837 } |
1837 | 1838 |
1838 /* Sanity checks */ | 1839 /* Sanity checks */ |
1841 if(hsize && !width) | 1842 if(hsize && !width) |
1842 width = 1; | 1843 width = 1; |
1843 | 1844 |
1844 /* Fill in the item data appropriately */ | 1845 /* Fill in the item data appropriately */ |
1845 if([ object isKindOfClass:[ DWBox class ] ]) | 1846 if([ object isKindOfClass:[ DWBox class ] ]) |
1846 tmpitem[thisbox.count].type = TYPEBOX; | 1847 tmpitem[thisbox->count].type = TYPEBOX; |
1847 else | 1848 else |
1848 tmpitem[thisbox.count].type = TYPEITEM; | 1849 tmpitem[thisbox->count].type = TYPEITEM; |
1849 | 1850 |
1850 tmpitem[thisbox.count].hwnd = item; | 1851 tmpitem[thisbox->count].hwnd = item; |
1851 tmpitem[thisbox.count].origwidth = tmpitem[thisbox.count].width = width; | 1852 tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width; |
1852 tmpitem[thisbox.count].origheight = tmpitem[thisbox.count].height = height; | 1853 tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height; |
1853 tmpitem[thisbox.count].pad = pad; | 1854 tmpitem[thisbox->count].pad = pad; |
1854 if(hsize) | 1855 if(hsize) |
1855 tmpitem[thisbox.count].hsize = SIZEEXPAND; | 1856 tmpitem[thisbox->count].hsize = SIZEEXPAND; |
1856 else | 1857 else |
1857 tmpitem[thisbox.count].hsize = SIZESTATIC; | 1858 tmpitem[thisbox->count].hsize = SIZESTATIC; |
1858 | 1859 |
1859 if(vsize) | 1860 if(vsize) |
1860 tmpitem[thisbox.count].vsize = SIZEEXPAND; | 1861 tmpitem[thisbox->count].vsize = SIZEEXPAND; |
1861 else | 1862 else |
1862 tmpitem[thisbox.count].vsize = SIZESTATIC; | 1863 tmpitem[thisbox->count].vsize = SIZESTATIC; |
1863 | 1864 |
1864 thisbox.items = tmpitem; | 1865 thisbox->items = tmpitem; |
1865 | 1866 |
1866 /* Update the item count */ | 1867 /* Update the item count */ |
1867 thisbox.count++; | 1868 thisbox->count++; |
1868 | 1869 |
1869 /* Add the item to the box */ | 1870 /* Add the item to the box */ |
1870 [view setBox:thisbox]; | |
1871 [view addSubview:this]; | 1871 [view addSubview:this]; |
1872 | 1872 |
1873 /* Free the old data */ | 1873 /* Free the old data */ |
1874 if(thisbox.count) | 1874 if(thisbox->count) |
1875 free(thisitem); | 1875 free(thisitem); |
1876 } | 1876 } |
1877 | 1877 |
1878 /* | 1878 /* |
1879 * Create a new button window (widget) to be packed. | 1879 * Create a new button window (widget) to be packed. |
4175 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) | 4175 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) |
4176 { | 4176 { |
4177 DWNotebook *notebook = handle; | 4177 DWNotebook *notebook = handle; |
4178 NSInteger page = [notebook pageid]; | 4178 NSInteger page = [notebook pageid]; |
4179 DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil]; | 4179 DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil]; |
4180 [notepage setPageid:page]; | 4180 [notepage setPageid:(NSInteger)page]; |
4181 if(front) | 4181 if(front) |
4182 { | 4182 { |
4183 [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; | 4183 [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; |
4184 } | 4184 } |
4185 else | 4185 else |
5890 #endif | 5890 #endif |
5891 | 5891 |
5892 threadfunc = (void (*)(void *))tmp[0]; | 5892 threadfunc = (void (*)(void *))tmp[0]; |
5893 | 5893 |
5894 threadfunc(tmp[1]); | 5894 threadfunc(tmp[1]); |
5895 #if !defined(GARBAGE_COLLECT) | |
5896 [pool release]; | |
5897 #endif | |
5895 free(tmp); | 5898 free(tmp); |
5896 } | 5899 } |
5897 | 5900 |
5898 /* | 5901 /* |
5899 * Allocates a shared memory region with a name. | 5902 * Allocates a shared memory region with a name. |