comparison mac/dw.m @ 916:44a0f9a2e8f9

Experimental change, pulling the resize event handling out of the resizer code on Mac. Wait until sizing is complete then take another pass through the window and generate any required events.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 22 Apr 2011 03:59:29 +0000
parents 361d80388dc9
children 8567c9ac089d
comparison
equal deleted inserted replaced
915:361d80388dc9 916:44a0f9a2e8f9
103 103
104 SignalHandler *Root = NULL; 104 SignalHandler *Root = NULL;
105 105
106 /* Some internal prototypes */ 106 /* Some internal prototypes */
107 static void _do_resize(Box *thisbox, int x, int y); 107 static void _do_resize(Box *thisbox, int x, int y);
108 void _handle_resize_events(Box *thisbox);
108 int _remove_userdata(UserData **root, char *varname, int all); 109 int _remove_userdata(UserData **root, char *varname, int all);
109 int _dw_main_iteration(NSDate *date); 110 int _dw_main_iteration(NSDate *date);
110 111
111 SignalHandler *_get_handler(HWND window, int messageid) 112 SignalHandler *_get_handler(HWND window, int messageid)
112 { 113 {
623 #ifdef BUILDING_FOR_SNOW_LEOPARD 624 #ifdef BUILDING_FOR_SNOW_LEOPARD
624 <NSWindowDelegate> 625 <NSWindowDelegate>
625 #endif 626 #endif
626 { 627 {
627 NSMenu *windowmenu; 628 NSMenu *windowmenu;
629 NSSize oldsize;
628 } 630 }
629 -(BOOL)windowShouldClose:(id)sender; 631 -(BOOL)windowShouldClose:(id)sender;
630 -(void)setMenu:(NSMenu *)input; 632 -(void)setMenu:(NSMenu *)input;
631 -(void)windowDidBecomeMain:(id)sender; 633 -(void)windowDidBecomeMain:(id)sender;
632 -(void)menuHandler:(id)sender; 634 -(void)menuHandler:(id)sender;
655 [super dealloc]; 657 [super dealloc];
656 } 658 }
657 - (void)windowResized:(NSNotification *)notification; 659 - (void)windowResized:(NSNotification *)notification;
658 { 660 {
659 NSSize size = [self frame].size; 661 NSSize size = [self frame].size;
660 _do_resize(box, size.width, size.height); 662
661 _do_resize(box, size.width, size.height); 663 if(oldsize.width != size.width || oldsize.height != size.height)
662 _event_handler([self window], nil, 1); 664 {
665 _do_resize(box, size.width, size.height);
666 _do_resize(box, size.width, size.height);
667 _event_handler([self window], nil, 1);
668 oldsize.width = size.width;
669 oldsize.height = size.height;
670 _handle_resize_events(box);
671 }
663 } 672 }
664 -(void)windowDidBecomeMain:(id)sender 673 -(void)windowDidBecomeMain:(id)sender
665 { 674 {
666 if(windowmenu) 675 if(windowmenu)
667 { 676 {
938 { 947 {
939 DWBox *view = object; 948 DWBox *view = object;
940 Box *box = [view box]; 949 Box *box = [view box];
941 NSSize size = [view frame].size; 950 NSSize size = [view frame].size;
942 _do_resize(box, size.width, size.height); 951 _do_resize(box, size.width, size.height);
952 _handle_resize_events(box);
943 } 953 }
944 _event_handler(self, (void *)[page pageid], 15); 954 _event_handler(self, (void *)[page pageid], 15);
945 } 955 }
946 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 956 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
947 @end 957 @end
1000 { 1010 {
1001 DWBox *view = object; 1011 DWBox *view = object;
1002 Box *box = [view box]; 1012 Box *box = [view box];
1003 NSSize size = [view frame].size; 1013 NSSize size = [view frame].size;
1004 _do_resize(box, size.width, size.height); 1014 _do_resize(box, size.width, size.height);
1015 _handle_resize_events(box);
1005 } 1016 }
1006 } 1017 }
1007 } 1018 }
1008 -(void *)userdata { return userdata; } 1019 -(void *)userdata { return userdata; }
1009 -(void)setUserdata:(void *)input { userdata = input; } 1020 -(void)setUserdata:(void *)input { userdata = input; }
1899 } 1910 }
1900 return 0L; 1911 return 0L;
1901 } 1912 }
1902 1913
1903 unsigned long _foreground = 0xAAAAAA, _background = 0; 1914 unsigned long _foreground = 0xAAAAAA, _background = 0;
1915
1916 void _handle_resize_events(Box *thisbox)
1917 {
1918 int z;
1919
1920 for(z=0;z<thisbox->count;z++)
1921 {
1922 id handle = thisbox->items[z].hwnd;
1923
1924 if(thisbox->items[z].type == TYPEBOX)
1925 {
1926 Box *tmp = [handle box];
1927
1928 if(tmp)
1929 {
1930 _handle_resize_events(tmp);
1931 }
1932 }
1933 else
1934 {
1935 if([handle isMemberOfClass:[DWRender class]])
1936 {
1937 DWRender *render = (DWRender *)handle;
1938 NSSize oldsize = [render size];
1939 NSSize newsize = [render frame].size;
1940 NSWindow *window = [render window];
1941
1942 if([window preferredBackingLocation] != NSWindowBackingLocationVideoMemory)
1943 {
1944 [window setPreferredBackingLocation:NSWindowBackingLocationVideoMemory];
1945 }
1946
1947 /* Eliminate duplicate configure requests */
1948 if(oldsize.width != newsize.width || oldsize.height != newsize.height)
1949 {
1950 if(newsize.width > 0 && newsize.height > 0)
1951 {
1952 [render setSize:newsize];
1953 _event_handler(handle, nil, 1);
1954 }
1955 }
1956 }
1957 /* Special handling for notebook controls */
1958 else if([handle isMemberOfClass:[DWNotebook class]])
1959 {
1960 DWNotebook *notebook = (DWNotebook *)handle;
1961 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem];
1962 id view = [notepage view];
1963
1964 if(view != nil)
1965 {
1966 Box *box = [view box];
1967 _handle_resize_events(box);
1968 }
1969 }
1970 /* Handle laying out scrollviews... if required space is less
1971 * than available space, then expand. Otherwise use required space.
1972 */
1973 else if([handle isMemberOfClass:[DWScrollBox class]])
1974 {
1975 DWScrollBox *scrollbox = (DWScrollBox *)handle;
1976 DWBox *contentbox = [scrollbox documentView];
1977 Box *thisbox = [contentbox box];
1978
1979 /* Get the required space for the box */
1980 _handle_resize_events(thisbox);
1981 }
1982 }
1983 }
1984 }
1904 1985
1905 /* Default border is 5.0 according to the documentation */ 1986 /* Default border is 5.0 according to the documentation */
1906 #define _DW_GROUPBOX_BORDER 5 1987 #define _DW_GROUPBOX_BORDER 5
1907 1988
1908 /* This function calculates how much space the widgets and boxes require 1989 /* This function calculates how much space the widgets and boxes require
2248 if(view != nil) 2329 if(view != nil)
2249 { 2330 {
2250 Box *box = [view box]; 2331 Box *box = [view box];
2251 NSSize size = [view frame].size; 2332 NSSize size = [view frame].size;
2252 _do_resize(box, size.width, size.height); 2333 _do_resize(box, size.width, size.height);
2334 _handle_resize_events(box);
2253 } 2335 }
2254 } 2336 }
2255 /* Handle laying out scrollviews... if required space is less 2337 /* Handle laying out scrollviews... if required space is less
2256 * than available space, then expand. Otherwise use required space. 2338 * than available space, then expand. Otherwise use required space.
2257 */ 2339 */
2287 NSStepper *stepper = [spinbutton stepper]; 2369 NSStepper *stepper = [spinbutton stepper];
2288 [textfield setFrameOrigin:NSMakePoint(0,0)]; 2370 [textfield setFrameOrigin:NSMakePoint(0,0)];
2289 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)]; 2371 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)];
2290 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)]; 2372 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)];
2291 [stepper setFrameSize:NSMakeSize(20,size.height)]; 2373 [stepper setFrameSize:NSMakeSize(20,size.height)];
2292 }
2293 else if([handle isMemberOfClass:[DWRender class]])
2294 {
2295 DWRender *render = (DWRender *)handle;
2296 NSSize oldsize = [render size];
2297 NSSize newsize = [render frame].size;
2298 NSWindow *window = [render window];
2299
2300 if([window preferredBackingLocation] != NSWindowBackingLocationVideoMemory)
2301 {
2302 [window setPreferredBackingLocation:NSWindowBackingLocationVideoMemory];
2303 }
2304
2305 /* Eliminate duplicate configure requests */
2306 if(oldsize.width != newsize.width || oldsize.height != newsize.height)
2307 {
2308 [render setSize:newsize];
2309 _event_handler(handle, nil, 1);
2310 }
2311 } 2374 }
2312 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) 2375 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20)
2313 { 2376 {
2314 DWSplitBar *split = (DWSplitBar *)handle; 2377 DWSplitBar *split = (DWSplitBar *)handle;
2315 float percent = [split percent]; 2378 float percent = [split percent];