comparison mac/dw.m @ 1419:8827e9b14b40

Initial support for automatic window redrawing on Mac. Added support for automatic sizes for ranged widgets and image buttons.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 02 Dec 2011 23:50:01 +0000
parents 461240f946d0
children fabf23bdc7fb
comparison
equal deleted inserted replaced
1418:461240f946d0 1419:8827e9b14b40
148 /* Some internal prototypes */ 148 /* Some internal prototypes */
149 static void _do_resize(Box *thisbox, int x, int y); 149 static void _do_resize(Box *thisbox, int x, int y);
150 void _handle_resize_events(Box *thisbox); 150 void _handle_resize_events(Box *thisbox);
151 int _remove_userdata(UserData **root, char *varname, int all); 151 int _remove_userdata(UserData **root, char *varname, int all);
152 int _dw_main_iteration(NSDate *date); 152 int _dw_main_iteration(NSDate *date);
153
154 /* Internal function to queue a window redraw */
155 void _dw_redraw(id window)
156 {
157 static id lastwindow = nil;
158
159 if(lastwindow != window && lastwindow != nil)
160 {
161 dw_window_redraw(lastwindow);
162 }
163 lastwindow = window;
164 }
153 165
154 SignalHandler *_get_handler(HWND window, int messageid) 166 SignalHandler *_get_handler(HWND window, int messageid)
155 { 167 {
156 SignalHandler *tmp = Root; 168 SignalHandler *tmp = Root;
157 169
195 { 15, DW_SIGNAL_SWITCH_PAGE }, 207 { 15, DW_SIGNAL_SWITCH_PAGE },
196 { 16, DW_SIGNAL_TREE_EXPAND }, 208 { 16, DW_SIGNAL_TREE_EXPAND },
197 { 17, DW_SIGNAL_COLUMN_CLICK } 209 { 17, DW_SIGNAL_COLUMN_CLICK }
198 }; 210 };
199 211
200 int _event_handler(id object, NSEvent *event, int message) 212 int _event_handler1(id object, NSEvent *event, int message)
201 { 213 {
202 SignalHandler *handler = _get_handler(object, message); 214 SignalHandler *handler = _get_handler(object, message);
203 /* NSLog(@"Event handler - type %d\n", message); */ 215 /* NSLog(@"Event handler - type %d\n", message); */
204 216
205 if(handler) 217 if(handler)
435 return clickcolumnfunc(handler->window, column_num, handler->data); 447 return clickcolumnfunc(handler->window, column_num, handler->data);
436 } 448 }
437 } 449 }
438 } 450 }
439 return -1; 451 return -1;
452 }
453
454 /* Sub function to handle redraws */
455 int _event_handler(id object, NSEvent *event, int message)
456 {
457 int ret = _event_handler1(object, event, message);
458 _dw_redraw(nil);
459 return ret;
440 } 460 }
441 461
442 /* Subclass for the Timer type */ 462 /* Subclass for the Timer type */
443 @interface DWTimerHandler : NSObject { } 463 @interface DWTimerHandler : NSObject { }
444 -(void)runTimer:(id)sender; 464 -(void)runTimer:(id)sender;
1304 @interface DWScrollbar : NSScroller 1324 @interface DWScrollbar : NSScroller
1305 { 1325 {
1306 void *userdata; 1326 void *userdata;
1307 double range; 1327 double range;
1308 double visible; 1328 double visible;
1329 int vertical;
1309 } 1330 }
1310 -(void *)userdata; 1331 -(void *)userdata;
1311 -(void)setUserdata:(void *)input; 1332 -(void)setUserdata:(void *)input;
1312 -(float)range; 1333 -(float)range;
1313 -(float)visible; 1334 -(float)visible;
1335 -(int)vertical;
1336 -(void)setVertical:(int)value;
1314 -(void)setRange:(double)input1 andVisible:(double)input2; 1337 -(void)setRange:(double)input1 andVisible:(double)input2;
1315 -(void)scrollerChanged:(id)sender; 1338 -(void)scrollerChanged:(id)sender;
1316 @end 1339 @end
1317 1340
1318 @implementation DWScrollbar 1341 @implementation DWScrollbar
1319 -(void *)userdata { return userdata; } 1342 -(void *)userdata { return userdata; }
1320 -(void)setUserdata:(void *)input { userdata = input; } 1343 -(void)setUserdata:(void *)input { userdata = input; }
1321 -(float)range { return range; } 1344 -(float)range { return range; }
1322 -(float)visible { return visible; } 1345 -(float)visible { return visible; }
1346 -(int)vertical { return vertical; }
1347 -(void)setVertical:(int)value { vertical = value; }
1323 -(void)setRange:(double)input1 andVisible:(double)input2 { range = input1; visible = input2; } 1348 -(void)setRange:(double)input1 andVisible:(double)input2 { range = input1; visible = input2; }
1324 -(void)scrollerChanged:(id)sender 1349 -(void)scrollerChanged:(id)sender
1325 { 1350 {
1326 double max = (range - visible); 1351 double max = (range - visible);
1327 double result = ([self doubleValue] * max); 1352 double result = ([self doubleValue] * max);
3525 if([object isMemberOfClass:[ DWSpinButton class]]) 3550 if([object isMemberOfClass:[ DWSpinButton class]])
3526 object = [object textfield]; 3551 object = [object textfield];
3527 /* Handle all the different button types */ 3552 /* Handle all the different button types */
3528 if([ object isKindOfClass:[ NSButton class ] ]) 3553 if([ object isKindOfClass:[ NSButton class ] ])
3529 { 3554 {
3530 nsstr = [object title]; 3555 NSImage *image = [object image];
3531 3556
3532 switch([object buttonType]) 3557 if(image)
3533 { 3558 {
3534 case NSSwitchButton: 3559 /* Image button */
3535 case NSRadioButton: 3560 NSSize size = [image size];
3536 extrawidth = 24; 3561 thiswidth = (int)size.width;
3537 extraheight = 4; 3562 thisheight = (int)size.height;
3538 break; 3563 }
3539 default: 3564 else
3540 if([object isBordered]) 3565 {
3541 { 3566 /* Text button */
3542 extrawidth = 30; 3567 nsstr = [object title];
3543 extraheight = 8; 3568
3544 } 3569 switch([object buttonType])
3545 else 3570 {
3546 { 3571 case NSSwitchButton:
3547 extrawidth = 8; 3572 case NSRadioButton:
3573 extrawidth = 24;
3548 extraheight = 4; 3574 extraheight = 4;
3549 } 3575 break;
3550 break; 3576 default:
3577 if([object isBordered])
3578 {
3579 extrawidth = 30;
3580 extraheight = 8;
3581 }
3582 else
3583 {
3584 extrawidth = 8;
3585 extraheight = 4;
3586 }
3587 break;
3588 }
3551 } 3589 }
3552 } 3590 }
3553 /* If the control is an entryfield set width to 150 */ 3591 /* If the control is an entryfield set width to 150 */
3554 else if([object isKindOfClass:[ NSTextField class ]] && [object isEditable]) 3592 else if([object isKindOfClass:[ NSTextField class ]] && [object isEditable])
3555 { 3593 {
3563 thisheight = (int)[font boundingRectForFont].size.height; 3601 thisheight = (int)[font boundingRectForFont].size.height;
3564 /* Spinbuttons don't need to be as wide */ 3602 /* Spinbuttons don't need to be as wide */
3565 if([object isMemberOfClass:[ DWComboBox class]]) 3603 if([object isMemberOfClass:[ DWComboBox class]])
3566 extraheight = 4; 3604 extraheight = 4;
3567 } 3605 }
3606 /* Handle the ranged widgets */
3607 else if([ object isMemberOfClass:[DWScrollbar class] ] ||
3608 [ object isMemberOfClass:[DWPercent class] ] ||
3609 [ object isMemberOfClass:[DWSlider class] ])
3610 {
3611 if([ object isMemberOfClass:[DWScrollbar class] ] && [object vertical])
3612 {
3613 thiswidth = 14;
3614 thisheight = 100;
3615 }
3616 else
3617 {
3618 thiswidth = 100;
3619 thisheight = 14;
3620 }
3621 }
3568 else if([ object isKindOfClass:[ NSControl class ] ]) 3622 else if([ object isKindOfClass:[ NSControl class ] ])
3569 nsstr = [object stringValue]; 3623 nsstr = [object stringValue];
3570 3624
3571 /* Handle static text fields */ 3625 /* Handle static text fields */
3572 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable]) 3626 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable])
3707 /* Save the parent box so radio 3761 /* Save the parent box so radio
3708 * buttons can use it later. 3762 * buttons can use it later.
3709 */ 3763 */
3710 [button setParent:view]; 3764 [button setParent:view];
3711 } 3765 }
3766 /* Queue a redraw on the top-level window */
3767 _dw_redraw([object window]);
3712 3768
3713 /* Free the old data */ 3769 /* Free the old data */
3714 if(thisbox->count) 3770 if(thisbox->count)
3715 free(thisitem); 3771 free(thisitem);
3716 DW_MUTEX_UNLOCK; 3772 DW_MUTEX_UNLOCK;
4059 { 4115 {
4060 DWScrollbar *scrollbar; 4116 DWScrollbar *scrollbar;
4061 if(vertical) 4117 if(vertical)
4062 { 4118 {
4063 scrollbar = [[DWScrollbar alloc] init]; 4119 scrollbar = [[DWScrollbar alloc] init];
4120 [scrollbar setVertical:YES];
4064 } 4121 }
4065 else 4122 else
4066 { 4123 {
4067 scrollbar = [[DWScrollbar alloc] initWithFrame:NSMakeRect(0,0,100,5)]; 4124 scrollbar = [[DWScrollbar alloc] initWithFrame:NSMakeRect(0,0,100,5)];
4068 } 4125 }
8100 Item *item = _box_item(handle); 8157 Item *item = _box_item(handle);
8101 8158
8102 /* Check to see if any of the sizes need to be recalculated */ 8159 /* Check to see if any of the sizes need to be recalculated */
8103 if(item && (item->origwidth == -1 || item->origheight == -1)) 8160 if(item && (item->origwidth == -1 || item->origheight == -1))
8104 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 8161 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
8162 /* Queue a redraw on the top-level window */
8163 _dw_redraw([object window]);
8105 return DW_ERROR_NONE; 8164 return DW_ERROR_NONE;
8106 } 8165 }
8107 return DW_ERROR_UNKNOWN; 8166 return DW_ERROR_UNKNOWN;
8108 } 8167 }
8109 8168
8279 Item *item = _box_item(handle); 8338 Item *item = _box_item(handle);
8280 8339
8281 /* Check to see if any of the sizes need to be recalculated */ 8340 /* Check to see if any of the sizes need to be recalculated */
8282 if(item && (item->origwidth == -1 || item->origheight == -1)) 8341 if(item && (item->origwidth == -1 || item->origheight == -1))
8283 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 8342 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
8343 /* Queue a redraw on the top-level window */
8344 _dw_redraw([object window]);
8284 } 8345 }
8285 8346
8286 /* 8347 /*
8287 * Sets the text used for a given window's floating bubble help. 8348 * Sets the text used for a given window's floating bubble help.
8288 * Parameters: 8349 * Parameters: