Mercurial > dwindows
comparison mac/dw.m @ 1802:aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
Remove NSTexturedBackgroundWindowMask from style in dw_window_new.
Add Copyright notice to winmain.c.
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 27 Sep 2012 05:09:10 +0000 |
parents | 9304241b7b33 |
children | 2bcdc3cfffa7 |
comparison
equal
deleted
inserted
replaced
1801:889f8d47761c | 1802:aedf5903db0a |
---|---|
160 /* Internal function to queue a window redraw */ | 160 /* Internal function to queue a window redraw */ |
161 void _dw_redraw(id window, int skip) | 161 void _dw_redraw(id window, int skip) |
162 { | 162 { |
163 static id lastwindow = nil; | 163 static id lastwindow = nil; |
164 id redraw = lastwindow; | 164 id redraw = lastwindow; |
165 | 165 |
166 if(skip && window == nil) | 166 if(skip && window == nil) |
167 return; | 167 return; |
168 | 168 |
169 lastwindow = window; | 169 lastwindow = window; |
170 if(redraw != lastwindow && redraw != nil) | 170 if(redraw != lastwindow && redraw != nil) |
284 /* Button press and release event */ | 284 /* Button press and release event */ |
285 case 3: | 285 case 3: |
286 case 4: | 286 case 4: |
287 { | 287 { |
288 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; | 288 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; |
289 NSPoint p = [NSEvent mouseLocation]; | 289 NSPoint p = [NSEvent mouseLocation]; |
290 int button = 1; | 290 int button = 1; |
291 | 291 |
292 if([event isMemberOfClass:[NSEvent class]]) | 292 if([event isMemberOfClass:[NSEvent class]]) |
293 { | 293 { |
294 id view = [[[event window] contentView] superview]; | 294 id view = [[[event window] contentView] superview]; |
295 NSEventType type = [event type]; | 295 NSEventType type = [event type]; |
296 | 296 |
297 p = [view convertPoint:[event locationInWindow] toView:object]; | 297 p = [view convertPoint:[event locationInWindow] toView:object]; |
298 | 298 |
299 if(type == NSRightMouseDown || type == NSRightMouseUp) | 299 if(type == NSRightMouseDown || type == NSRightMouseUp) |
300 { | 300 { |
301 button = 2; | 301 button = 2; |
319 id view = [[[event window] contentView] superview]; | 319 id view = [[[event window] contentView] superview]; |
320 NSPoint p = [view convertPoint:[event locationInWindow] toView:object]; | 320 NSPoint p = [view convertPoint:[event locationInWindow] toView:object]; |
321 SEL spmb = NSSelectorFromString(@"pressedMouseButtons"); | 321 SEL spmb = NSSelectorFromString(@"pressedMouseButtons"); |
322 IMP ipmb = [[NSEvent class] respondsToSelector:spmb] ? [[NSEvent class] methodForSelector:spmb] : 0; | 322 IMP ipmb = [[NSEvent class] respondsToSelector:spmb] ? [[NSEvent class] methodForSelector:spmb] : 0; |
323 int buttonmask = ipmb ? (int)ipmb([NSEvent class], spmb) : (1 << [event buttonNumber]); | 323 int buttonmask = ipmb ? (int)ipmb([NSEvent class], spmb) : (1 << [event buttonNumber]); |
324 | 324 |
325 return motionfunc(object, (int)p.x, (int)p.y, buttonmask, handler->data); | 325 return motionfunc(object, (int)p.x, (int)p.y, buttonmask, handler->data); |
326 } | 326 } |
327 /* Window close event */ | 327 /* Window close event */ |
328 case 6: | 328 case 6: |
329 { | 329 { |
532 -(void)menuHandler:(id)param; | 532 -(void)menuHandler:(id)param; |
533 -(void)doBitBlt:(id)param; | 533 -(void)doBitBlt:(id)param; |
534 -(void)doFlush:(id)param; | 534 -(void)doFlush:(id)param; |
535 @end | 535 @end |
536 | 536 |
537 @interface DWMenuItem : NSMenuItem | 537 @interface DWMenuItem : NSMenuItem |
538 { | 538 { |
539 int check; | 539 int check; |
540 } | 540 } |
541 -(void)setCheck:(int)input; | 541 -(void)setCheck:(int)input; |
542 -(int)check; | 542 -(int)check; |
543 -(void)dealloc; | 543 -(void)dealloc; |
558 if([item check]) | 558 if([item check]) |
559 { | 559 { |
560 if([item state] == NSOnState) | 560 if([item state] == NSOnState) |
561 [item setState:NSOffState]; | 561 [item setState:NSOffState]; |
562 else | 562 else |
563 [item setState:NSOnState]; | 563 [item setState:NSOnState]; |
564 } | 564 } |
565 _event_handler(param, nil, 8); | 565 _event_handler(param, nil, 8); |
566 } | 566 } |
567 -(void)doBitBlt:(id)param | 567 -(void)doBitBlt:(id)param |
568 { | 568 { |
603 image = [image initWithSize:[rep size]]; | 603 image = [image initWithSize:[rep size]]; |
604 [image addRepresentation:rep]; | 604 [image addRepresentation:rep]; |
605 } | 605 } |
606 if(bltinfo->srcwidth != -1) | 606 if(bltinfo->srcwidth != -1) |
607 { | 607 { |
608 [image drawInRect:NSMakeRect(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height) | 608 [image drawInRect:NSMakeRect(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height) |
609 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->srcwidth, bltinfo->srcheight) | 609 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->srcwidth, bltinfo->srcheight) |
610 operation:NSCompositeSourceOver fraction:1.0]; | 610 operation:NSCompositeSourceOver fraction:1.0]; |
611 } | 611 } |
612 else | 612 else |
613 { | 613 { |
614 [image drawAtPoint:NSMakePoint(bltinfo->xdest, bltinfo->ydest) | 614 [image drawAtPoint:NSMakePoint(bltinfo->xdest, bltinfo->ydest) |
615 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height) | 615 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height) |
616 operation:NSCompositeSourceOver fraction:1.0]; | 616 operation:NSCompositeSourceOver fraction:1.0]; |
617 } | 617 } |
618 [bltsrc release]; | 618 [bltsrc release]; |
619 [image release]; | 619 [image release]; |
849 -(void)setUserdata:(void *)input { userdata = input; } | 849 -(void)setUserdata:(void *)input { userdata = input; } |
850 -(void)setFont:(NSFont *)input { [font release]; font = input; [font retain]; } | 850 -(void)setFont:(NSFont *)input { [font release]; font = input; [font retain]; } |
851 -(NSFont *)font { return font; } | 851 -(NSFont *)font { return font; } |
852 -(void)setSize:(NSSize)input { size = input; } | 852 -(void)setSize:(NSSize)input { size = input; } |
853 -(NSSize)size { return size; } | 853 -(NSSize)size { return size; } |
854 -(void)mouseDown:(NSEvent *)theEvent | 854 -(void)mouseDown:(NSEvent *)theEvent |
855 { | 855 { |
856 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & NSControlKeyMask)) | 856 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & NSControlKeyMask)) |
857 _event_handler(self, theEvent, 3); | 857 _event_handler(self, theEvent, 3); |
858 } | 858 } |
859 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 859 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
860 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } | 860 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } |
861 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 861 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
862 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } | 862 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } |
942 [DWApp setMainMenu:DWMainMenu]; | 942 [DWApp setMainMenu:DWMainMenu]; |
943 } | 943 } |
944 _event_handler([self window], nil, 13); | 944 _event_handler([self window], nil, 13); |
945 } | 945 } |
946 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } | 946 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } |
947 -(void)menuHandler:(id)sender | 947 -(void)menuHandler:(id)sender |
948 { | 948 { |
949 id menu = [sender menu]; | 949 id menu = [sender menu]; |
950 | 950 |
951 /* Find the highest menu for this item */ | 951 /* Find the highest menu for this item */ |
952 while([menu supermenu]) | 952 while([menu supermenu]) |
1168 } else | 1168 } else |
1169 { | 1169 { |
1170 [super keyUp:theEvent]; | 1170 [super keyUp:theEvent]; |
1171 } | 1171 } |
1172 } | 1172 } |
1173 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent | 1173 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent |
1174 { | 1174 { |
1175 if(([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) | 1175 if(([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) |
1176 { | 1176 { |
1177 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"]) | 1177 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"]) |
1178 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self]; | 1178 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self]; |
1179 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"]) | 1179 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"]) |
1180 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self]; | 1180 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self]; |
1232 else | 1232 else |
1233 { | 1233 { |
1234 [super keyUp:theEvent]; | 1234 [super keyUp:theEvent]; |
1235 } | 1235 } |
1236 } | 1236 } |
1237 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent | 1237 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent |
1238 { | 1238 { |
1239 if(([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) | 1239 if(([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) |
1240 { | 1240 { |
1241 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"]) | 1241 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"]) |
1242 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self]; | 1242 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self]; |
1243 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"]) | 1243 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"]) |
1244 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self]; | 1244 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self]; |
1321 -(void)setDialog:(DWDialog *)input; | 1321 -(void)setDialog:(DWDialog *)input; |
1322 -(DWDialog *)dialog; | 1322 -(DWDialog *)dialog; |
1323 @end | 1323 @end |
1324 | 1324 |
1325 @implementation DWColorChoose | 1325 @implementation DWColorChoose |
1326 -(void)changeColor:(id)sender | 1326 -(void)changeColor:(id)sender |
1327 { | 1327 { |
1328 if(!dialog) | 1328 if(!dialog) |
1329 [self close]; | 1329 [self close]; |
1330 else | 1330 else |
1331 pickedcolor = [self color]; | 1331 pickedcolor = [self color]; |
1332 } | 1332 } |
1333 -(BOOL)windowShouldClose:(id)window | 1333 -(BOOL)windowShouldClose:(id)window |
1334 { | 1334 { |
1335 if(dialog) | 1335 if(dialog) |
1336 { | 1336 { |
1337 DWDialog *d = dialog; | 1337 DWDialog *d = dialog; |
1338 dialog = nil; | 1338 dialog = nil; |
1339 dw_dialog_dismiss(d, pickedcolor); | 1339 dw_dialog_dismiss(d, pickedcolor); |
1340 } | 1340 } |
1341 [self close]; | 1341 [self close]; |
1342 return NO; | 1342 return NO; |
1343 } | 1343 } |
1344 -(void)setDialog:(DWDialog *)input { dialog = input; } | 1344 -(void)setDialog:(DWDialog *)input { dialog = input; } |
1345 -(DWDialog *)dialog { return dialog; } | 1345 -(DWDialog *)dialog { return dialog; } |
1346 @end | 1346 @end |
1347 | 1347 |
1526 -(void)setScrollview:(id)input { scrollview = input; } | 1526 -(void)setScrollview:(id)input { scrollview = input; } |
1527 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } | 1527 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } |
1528 @end | 1528 @end |
1529 | 1529 |
1530 /* Subclass NSTextFieldCell for displaying image and text */ | 1530 /* Subclass NSTextFieldCell for displaying image and text */ |
1531 @interface DWImageAndTextCell : NSTextFieldCell | 1531 @interface DWImageAndTextCell : NSTextFieldCell |
1532 { | 1532 { |
1533 @private | 1533 @private |
1534 NSImage *image; | 1534 NSImage *image; |
1535 } | 1535 } |
1536 -(void)setImage:(NSImage *)anImage; | 1536 -(void)setImage:(NSImage *)anImage; |
1538 -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView; | 1538 -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView; |
1539 -(NSSize)cellSize; | 1539 -(NSSize)cellSize; |
1540 @end | 1540 @end |
1541 | 1541 |
1542 @implementation DWImageAndTextCell | 1542 @implementation DWImageAndTextCell |
1543 -(void)dealloc | 1543 -(void)dealloc |
1544 { | 1544 { |
1545 [image release]; | 1545 [image release]; |
1546 image = nil; | 1546 image = nil; |
1547 [super dealloc]; | 1547 [super dealloc]; |
1548 } | 1548 } |
1549 -copyWithZone:(NSZone *)zone | 1549 -copyWithZone:(NSZone *)zone |
1550 { | 1550 { |
1551 DWImageAndTextCell *cell = (DWImageAndTextCell *)[super copyWithZone:zone]; | 1551 DWImageAndTextCell *cell = (DWImageAndTextCell *)[super copyWithZone:zone]; |
1552 cell->image = [image retain]; | 1552 cell->image = [image retain]; |
1553 return cell; | 1553 return cell; |
1554 } | 1554 } |
1555 -(void)setImage:(NSImage *)anImage | 1555 -(void)setImage:(NSImage *)anImage |
1556 { | 1556 { |
1557 if(anImage != image) | 1557 if(anImage != image) |
1558 { | 1558 { |
1559 [image release]; | 1559 [image release]; |
1560 image = [anImage retain]; | 1560 image = [anImage retain]; |
1561 } | 1561 } |
1562 } | 1562 } |
1563 -(NSImage *)image | 1563 -(NSImage *)image |
1564 { | 1564 { |
1565 return [[image retain] autorelease]; | 1565 return [[image retain] autorelease]; |
1566 } | 1566 } |
1567 -(NSRect)imageFrameForCellFrame:(NSRect)cellFrame | 1567 -(NSRect)imageFrameForCellFrame:(NSRect)cellFrame |
1568 { | 1568 { |
1569 if(image != nil) | 1569 if(image != nil) |
1570 { | 1570 { |
1571 NSRect imageFrame; | 1571 NSRect imageFrame; |
1572 imageFrame.size = [image size]; | 1572 imageFrame.size = [image size]; |
1573 imageFrame.origin = cellFrame.origin; | 1573 imageFrame.origin = cellFrame.origin; |
1574 imageFrame.origin.x += 3; | 1574 imageFrame.origin.x += 3; |
1576 return imageFrame; | 1576 return imageFrame; |
1577 } | 1577 } |
1578 else | 1578 else |
1579 return NSZeroRect; | 1579 return NSZeroRect; |
1580 } | 1580 } |
1581 -(void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent | 1581 -(void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent |
1582 { | 1582 { |
1583 NSRect textFrame, imageFrame; | 1583 NSRect textFrame, imageFrame; |
1584 NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge); | 1584 NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge); |
1585 [super editWithFrame: textFrame inView: controlView editor:textObj delegate:anObject event: theEvent]; | 1585 [super editWithFrame: textFrame inView: controlView editor:textObj delegate:anObject event: theEvent]; |
1586 } | 1586 } |
1587 -(void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength | 1587 -(void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength |
1588 { | 1588 { |
1589 NSRect textFrame, imageFrame; | 1589 NSRect textFrame, imageFrame; |
1590 NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge); | 1590 NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge); |
1591 [super selectWithFrame: textFrame inView: controlView editor:textObj delegate:anObject start:selStart length:selLength]; | 1591 [super selectWithFrame: textFrame inView: controlView editor:textObj delegate:anObject start:selStart length:selLength]; |
1592 } | 1592 } |
1593 -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView | 1593 -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView |
1594 { | 1594 { |
1595 if(image != nil) | 1595 if(image != nil) |
1596 { | 1596 { |
1597 NSSize imageSize; | 1597 NSSize imageSize; |
1598 NSRect imageFrame; | 1598 NSRect imageFrame; |
1599 SEL sdir = NSSelectorFromString(@"drawInRect:fromRect:operation:fraction:respectFlipped:hints:"); | 1599 SEL sdir = NSSelectorFromString(@"drawInRect:fromRect:operation:fraction:respectFlipped:hints:"); |
1600 | 1600 |
1601 imageSize = [image size]; | 1601 imageSize = [image size]; |
1602 NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge); | 1602 NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge); |
1603 if ([self drawsBackground]) | 1603 if ([self drawsBackground]) |
1604 { | 1604 { |
1605 [[self backgroundColor] set]; | 1605 [[self backgroundColor] set]; |
1606 NSRectFill(imageFrame); | 1606 NSRectFill(imageFrame); |
1607 } | 1607 } |
1608 imageFrame.origin.x += 3; | 1608 imageFrame.origin.x += 3; |
1609 imageFrame.size = imageSize; | 1609 imageFrame.size = imageSize; |
1610 | 1610 |
1611 /* New method for 10.6 and later */ | 1611 /* New method for 10.6 and later */ |
1612 if([image respondsToSelector:sdir]) | 1612 if([image respondsToSelector:sdir]) |
1613 { | 1613 { |
1614 IMP idir = [image methodForSelector:sdir]; | 1614 IMP idir = [image methodForSelector:sdir]; |
1615 | 1615 |
1616 imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2); | 1616 imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2); |
1617 | 1617 |
1618 idir(image, sdir, imageFrame, NSZeroRect, NSCompositeSourceOver, 1.0, YES, nil); | 1618 idir(image, sdir, imageFrame, NSZeroRect, NSCompositeSourceOver, 1.0, YES, nil); |
1619 } | 1619 } |
1620 else | 1620 else |
1621 { | 1621 { |
1622 /* Old method for 10.5 */ | 1622 /* Old method for 10.5 */ |
1623 SEL sctp = NSSelectorFromString(@"compositeToPoint:operation:"); | 1623 SEL sctp = NSSelectorFromString(@"compositeToPoint:operation:"); |
1624 | 1624 |
1625 if ([controlView isFlipped]) | 1625 if ([controlView isFlipped]) |
1626 imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2); | 1626 imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2); |
1627 else | 1627 else |
1628 imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2); | 1628 imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2); |
1629 | 1629 |
1630 if([image respondsToSelector:sctp]) | 1630 if([image respondsToSelector:sctp]) |
1631 { | 1631 { |
1632 IMP ictp = [image methodForSelector:sctp]; | 1632 IMP ictp = [image methodForSelector:sctp]; |
1633 | 1633 |
1634 ictp(image, sctp, imageFrame.origin, NSCompositeSourceOver); | 1634 ictp(image, sctp, imageFrame.origin, NSCompositeSourceOver); |
1635 } | 1635 } |
1636 } | 1636 } |
1637 } | 1637 } |
1638 [super drawWithFrame:cellFrame inView:controlView]; | 1638 [super drawWithFrame:cellFrame inView:controlView]; |
1639 } | 1639 } |
1640 -(NSSize)cellSize | 1640 -(NSSize)cellSize |
1641 { | 1641 { |
1642 NSSize cellSize = [super cellSize]; | 1642 NSSize cellSize = [super cellSize]; |
1643 cellSize.width += (image ? [image size].width : 0) + 3; | 1643 cellSize.width += (image ? [image size].width : 0) + 3; |
1644 return cellSize; | 1644 return cellSize; |
1645 } | 1645 } |
1750 { | 1750 { |
1751 NSColor *oldodd = oddcolor; | 1751 NSColor *oldodd = oddcolor; |
1752 NSColor *oldeven = evencolor; | 1752 NSColor *oldeven = evencolor; |
1753 unsigned long _odd = _get_color(oddcol); | 1753 unsigned long _odd = _get_color(oddcol); |
1754 unsigned long _even = _get_color(evencol); | 1754 unsigned long _even = _get_color(evencol); |
1755 | 1755 |
1756 /* Get the NSColor for non-default colors */ | 1756 /* Get the NSColor for non-default colors */ |
1757 if(oddcol != DW_RGB_TRANSPARENT) | 1757 if(oddcol != DW_RGB_TRANSPARENT) |
1758 oddcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_odd)/255.0 green: DW_GREEN_VALUE(_odd)/255.0 blue: DW_BLUE_VALUE(_odd)/255.0 alpha: 1] retain]; | 1758 oddcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_odd)/255.0 green: DW_GREEN_VALUE(_odd)/255.0 blue: DW_BLUE_VALUE(_odd)/255.0 alpha: 1] retain]; |
1759 else | 1759 else |
1760 oddcolor = NULL; | 1760 oddcolor = NULL; |
1815 return 0; | 1815 return 0; |
1816 } | 1816 } |
1817 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row | 1817 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
1818 { | 1818 { |
1819 DWImageAndTextCell *bcell = cell; | 1819 DWImageAndTextCell *bcell = cell; |
1820 | 1820 |
1821 /* Handle drawing image and text if necessary */ | 1821 /* Handle drawing image and text if necessary */ |
1822 if([cell isMemberOfClass:[DWImageAndTextCell class]]) | 1822 if([cell isMemberOfClass:[DWImageAndTextCell class]]) |
1823 { | 1823 { |
1824 int index = (int)(row * [tvcols count]); | 1824 int index = (int)(row * [tvcols count]); |
1825 DWImageAndTextCell *browsercell = [data objectAtIndex:index]; | 1825 DWImageAndTextCell *browsercell = [data objectAtIndex:index]; |
1899 | 1899 |
1900 if(![[NSPointerArray class] respondsToSelector:swopa]) | 1900 if(![[NSPointerArray class] respondsToSelector:swopa]) |
1901 swopa = NSSelectorFromString(@"weakObjectsPointerArray"); | 1901 swopa = NSSelectorFromString(@"weakObjectsPointerArray"); |
1902 if(![[NSPointerArray class] respondsToSelector:swopa]) | 1902 if(![[NSPointerArray class] respondsToSelector:swopa]) |
1903 return; | 1903 return; |
1904 | 1904 |
1905 IMP iwopa = [[NSPointerArray class] methodForSelector:swopa]; | 1905 IMP iwopa = [[NSPointerArray class] methodForSelector:swopa]; |
1906 | 1906 |
1907 titles = iwopa([NSPointerArray class], swopa); | 1907 titles = iwopa([NSPointerArray class], swopa); |
1908 [titles retain]; | 1908 [titles retain]; |
1909 tvcols = [[[NSMutableArray alloc] init] retain]; | 1909 tvcols = [[[NSMutableArray alloc] init] retain]; |
1910 data = [[[NSMutableArray alloc] init] retain]; | 1910 data = [[[NSMutableArray alloc] init] retain]; |
1911 types = [[[NSMutableArray alloc] init] retain]; | 1911 types = [[[NSMutableArray alloc] init] retain]; |
1913 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self]; | 1913 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self]; |
1914 } | 1914 } |
1915 -(NSSize)getsize | 1915 -(NSSize)getsize |
1916 { | 1916 { |
1917 int cwidth = 0, cheight = 0; | 1917 int cwidth = 0, cheight = 0; |
1918 | 1918 |
1919 if(tvcols) | 1919 if(tvcols) |
1920 { | 1920 { |
1921 int z; | 1921 int z; |
1922 int colcount = (int)[tvcols count]; | 1922 int colcount = (int)[tvcols count]; |
1923 int rowcount = (int)[self numberOfRowsInTableView:self]; | 1923 int rowcount = (int)[self numberOfRowsInTableView:self]; |
1924 | 1924 |
1925 for(z=0;z<colcount;z++) | 1925 for(z=0;z<colcount;z++) |
1926 { | 1926 { |
1927 NSTableColumn *column = [tvcols objectAtIndex:z]; | 1927 NSTableColumn *column = [tvcols objectAtIndex:z]; |
1928 int width = [column width]; | 1928 int width = [column width]; |
1929 | 1929 |
1930 if(rowcount > 0) | 1930 if(rowcount > 0) |
1931 { | 1931 { |
1932 int x; | 1932 int x; |
1933 | 1933 |
1934 for(x=0;x<rowcount;x++) | 1934 for(x=0;x<rowcount;x++) |
1935 { | 1935 { |
1936 NSCell *cell = [self preparedCellAtColumn:z row:x]; | 1936 NSCell *cell = [self preparedCellAtColumn:z row:x]; |
1937 int thiswidth = [cell cellSize].width; | 1937 int thiswidth = [cell cellSize].width; |
1938 | 1938 |
1939 /* If on the first column... add up the heights */ | 1939 /* If on the first column... add up the heights */ |
1940 if(z == 0) | 1940 if(z == 0) |
1941 cheight += [cell cellSize].height; | 1941 cheight += [cell cellSize].height; |
1942 | 1942 |
1943 /* Check the image inside the cell to get its width */ | 1943 /* Check the image inside the cell to get its width */ |
1944 if([cell isMemberOfClass:[NSImageCell class]]) | 1944 if([cell isMemberOfClass:[NSImageCell class]]) |
1945 { | 1945 { |
1946 int index = (int)(x * [tvcols count]) + z; | 1946 int index = (int)(x * [tvcols count]) + z; |
1947 NSImage *image = [data objectAtIndex:index]; | 1947 NSImage *image = [data objectAtIndex:index]; |
1948 if([image isMemberOfClass:[NSImage class]]) | 1948 if([image isMemberOfClass:[NSImage class]]) |
1949 { | 1949 { |
1950 thiswidth = [image size].width; | 1950 thiswidth = [image size].width; |
1951 } | 1951 } |
1952 } | 1952 } |
1953 | 1953 |
1954 if(thiswidth > width) | 1954 if(thiswidth > width) |
1955 { | 1955 { |
1956 width = thiswidth; | 1956 width = thiswidth; |
1957 } | 1957 } |
1958 } | 1958 } |
2615 * These will be used to find the widest or | 2615 * These will be used to find the widest or |
2616 * tallest items in a box. | 2616 * tallest items in a box. |
2617 */ | 2617 */ |
2618 int uymax = 0, uxmax = 0; | 2618 int uymax = 0, uxmax = 0; |
2619 int upymax = 0, upxmax = 0; | 2619 int upymax = 0, upxmax = 0; |
2620 | 2620 |
2621 /* Reset the box sizes */ | 2621 /* Reset the box sizes */ |
2622 thisbox->minwidth = thisbox->minheight = thisbox->usedpadx = thisbox->usedpady = thisbox->pad * 2; | 2622 thisbox->minwidth = thisbox->minheight = thisbox->usedpadx = thisbox->usedpady = thisbox->pad * 2; |
2623 | 2623 |
2624 /* Handle special groupbox case */ | 2624 /* Handle special groupbox case */ |
2625 if(thisbox->grouphwnd) | 2625 if(thisbox->grouphwnd) |
2641 titleRect = [groupbox titleRect]; | 2641 titleRect = [groupbox titleRect]; |
2642 | 2642 |
2643 thisbox->grouppadx = borderSize.width; | 2643 thisbox->grouppadx = borderSize.width; |
2644 thisbox->grouppady = borderSize.height + titleRect.size.height; | 2644 thisbox->grouppady = borderSize.height + titleRect.size.height; |
2645 } | 2645 } |
2646 | 2646 |
2647 thisbox->minwidth += thisbox->grouppadx; | 2647 thisbox->minwidth += thisbox->grouppadx; |
2648 thisbox->usedpadx += thisbox->grouppadx; | 2648 thisbox->usedpadx += thisbox->grouppadx; |
2649 thisbox->minheight += thisbox->grouppady; | 2649 thisbox->minheight += thisbox->grouppady; |
2650 thisbox->usedpady += thisbox->grouppady; | 2650 thisbox->usedpady += thisbox->grouppady; |
2651 } | 2651 } |
2652 | 2652 |
2653 /* Count up all the space for all items in the box */ | 2653 /* Count up all the space for all items in the box */ |
2654 for(z=0;z<thisbox->count;z++) | 2654 for(z=0;z<thisbox->count;z++) |
2655 { | 2655 { |
2656 int itempad, itemwidth, itemheight; | 2656 int itempad, itemwidth, itemheight; |
2657 | 2657 |
2658 if(thisbox->items[z].type == TYPEBOX) | 2658 if(thisbox->items[z].type == TYPEBOX) |
2659 { | 2659 { |
2660 id box = thisbox->items[z].hwnd; | 2660 id box = thisbox->items[z].hwnd; |
2661 Box *tmp = [box box]; | 2661 Box *tmp = [box box]; |
2662 | 2662 |
2689 * be used used repeatedly in the next section. | 2689 * be used used repeatedly in the next section. |
2690 */ | 2690 */ |
2691 itempad = thisbox->items[z].pad * 2; | 2691 itempad = thisbox->items[z].pad * 2; |
2692 itemwidth = thisbox->items[z].width + itempad; | 2692 itemwidth = thisbox->items[z].width + itempad; |
2693 itemheight = thisbox->items[z].height + itempad; | 2693 itemheight = thisbox->items[z].height + itempad; |
2694 | 2694 |
2695 /* Calculate the totals and maximums */ | 2695 /* Calculate the totals and maximums */ |
2696 if(thisbox->type == DW_VERT) | 2696 if(thisbox->type == DW_VERT) |
2697 { | 2697 { |
2698 if(itemwidth > uxmax) | 2698 if(itemwidth > uxmax) |
2699 uxmax = itemwidth; | 2699 uxmax = itemwidth; |
2700 | 2700 |
2701 if(thisbox->items[z].hsize != SIZEEXPAND) | 2701 if(thisbox->items[z].hsize != SIZEEXPAND) |
2702 { | 2702 { |
2703 if(itemwidth > upxmax) | 2703 if(itemwidth > upxmax) |
2704 upxmax = itemwidth; | 2704 upxmax = itemwidth; |
2705 } | 2705 } |
2756 if(thisbox->items[z].hsize == SIZEEXPAND) | 2756 if(thisbox->items[z].hsize == SIZEEXPAND) |
2757 { | 2757 { |
2758 if(thisbox->type == DW_HORZ) | 2758 if(thisbox->type == DW_HORZ) |
2759 { | 2759 { |
2760 int expandablex = thisbox->minwidth - thisbox->usedpadx; | 2760 int expandablex = thisbox->minwidth - thisbox->usedpadx; |
2761 | 2761 |
2762 if(expandablex) | 2762 if(expandablex) |
2763 width = (int)(((float)width / (float)expandablex) * (float)(x - thisbox->usedpadx)); | 2763 width = (int)(((float)width / (float)expandablex) * (float)(x - thisbox->usedpadx)); |
2764 } | 2764 } |
2765 else | 2765 else |
2766 width = x - (itempad + thispad + thisbox->grouppadx); | 2766 width = x - (itempad + thispad + thisbox->grouppadx); |
2768 if(thisbox->items[z].vsize == SIZEEXPAND) | 2768 if(thisbox->items[z].vsize == SIZEEXPAND) |
2769 { | 2769 { |
2770 if(thisbox->type == DW_VERT) | 2770 if(thisbox->type == DW_VERT) |
2771 { | 2771 { |
2772 int expandabley = thisbox->minheight - thisbox->usedpady; | 2772 int expandabley = thisbox->minheight - thisbox->usedpady; |
2773 | 2773 |
2774 if(expandabley) | 2774 if(expandabley) |
2775 height = (int)(((float)height / (float)expandabley) * (float)(y - thisbox->usedpady)); | 2775 height = (int)(((float)height / (float)expandabley) * (float)(y - thisbox->usedpady)); |
2776 } | 2776 } |
2777 else | 2777 else |
2778 height = y - (itempad + thispad + thisbox->grouppady); | 2778 height = y - (itempad + thispad + thisbox->grouppady); |
2779 } | 2779 } |
2780 | 2780 |
2781 /* If the calculated size is valid... */ | 2781 /* If the calculated size is valid... */ |
2782 if(height > 0 && width > 0) | 2782 if(height > 0 && width > 0) |
2783 { | 2783 { |
2784 int pad = thisbox->items[z].pad; | 2784 int pad = thisbox->items[z].pad; |
2785 NSView *handle = thisbox->items[z].hwnd; | 2785 NSView *handle = thisbox->items[z].hwnd; |
2786 NSPoint point; | 2786 NSPoint point; |
2787 NSSize size; | 2787 NSSize size; |
2788 | 2788 |
2789 point.x = currentx + pad; | 2789 point.x = currentx + pad; |
2790 point.y = currenty + pad; | 2790 point.y = currenty + pad; |
2791 size.width = width; | 2791 size.width = width; |
2792 size.height = height; | 2792 size.height = height; |
2793 [handle setFrameOrigin:point]; | 2793 [handle setFrameOrigin:point]; |
2875 else if([window redraw]) | 2875 else if([window redraw]) |
2876 { | 2876 { |
2877 [split splitViewDidResizeSubviews:nil]; | 2877 [split splitViewDidResizeSubviews:nil]; |
2878 } | 2878 } |
2879 } | 2879 } |
2880 | 2880 |
2881 /* Advance the current position in the box */ | 2881 /* Advance the current position in the box */ |
2882 if(thisbox->type == DW_HORZ) | 2882 if(thisbox->type == DW_HORZ) |
2883 currentx += width + (pad * 2); | 2883 currentx += width + (pad * 2); |
2884 if(thisbox->type == DW_VERT) | 2884 if(thisbox->type == DW_VERT) |
2885 currenty += height + (pad * 2); | 2885 currenty += height + (pad * 2); |
2893 if(x > 0 && y > 0) | 2893 if(x > 0 && y > 0) |
2894 { | 2894 { |
2895 if(thisbox) | 2895 if(thisbox) |
2896 { | 2896 { |
2897 int depth = 0; | 2897 int depth = 0; |
2898 | 2898 |
2899 /* Calculate space requirements */ | 2899 /* Calculate space requirements */ |
2900 _resize_box(thisbox, &depth, x, y, 1); | 2900 _resize_box(thisbox, &depth, x, y, 1); |
2901 | 2901 |
2902 /* Finally place all the boxes and controls */ | 2902 /* Finally place all the boxes and controls */ |
2903 _resize_box(thisbox, &depth, x, y, 2); | 2903 _resize_box(thisbox, &depth, x, y, 2); |
2904 } | 2904 } |
2905 } | 2905 } |
2906 } | 2906 } |
3113 return _user_dir; | 3113 return _user_dir; |
3114 } | 3114 } |
3115 | 3115 |
3116 /* | 3116 /* |
3117 * Returns a pointer to a static buffer which containes the | 3117 * Returns a pointer to a static buffer which containes the |
3118 * private application data directory. | 3118 * private application data directory. |
3119 */ | 3119 */ |
3120 char * API dw_app_dir(void) | 3120 char * API dw_app_dir(void) |
3121 { | 3121 { |
3122 return _dw_bundle_path; | 3122 return _dw_bundle_path; |
3123 } | 3123 } |
3134 char outbuf[1025] = {0}; | 3134 char outbuf[1025] = {0}; |
3135 | 3135 |
3136 va_start(args, format); | 3136 va_start(args, format); |
3137 vsnprintf(outbuf, 1024, format, args); | 3137 vsnprintf(outbuf, 1024, format, args); |
3138 va_end(args); | 3138 va_end(args); |
3139 | 3139 |
3140 NSLog(@"%s", outbuf); | 3140 NSLog(@"%s", outbuf); |
3141 } | 3141 } |
3142 | 3142 |
3143 /* | 3143 /* |
3144 * Displays a Message Box with given text and title.. | 3144 * Displays a Message Box with given text and title.. |
3145 * Parameters: | 3145 * Parameters: |
3146 * title: The title of the message box. | 3146 * title: The title of the message box. |
3147 * flags: flags to indicate buttons and icon | 3147 * flags: flags to indicate buttons and icon |
3236 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) | 3236 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) |
3237 { | 3237 { |
3238 char temp[PATH_MAX+1]; | 3238 char temp[PATH_MAX+1]; |
3239 char *file = NULL, *path = NULL; | 3239 char *file = NULL, *path = NULL; |
3240 DW_LOCAL_POOL_IN; | 3240 DW_LOCAL_POOL_IN; |
3241 | 3241 |
3242 /* Figure out path information... | 3242 /* Figure out path information... |
3243 * These functions are only support in Snow Leopard and later... | 3243 * These functions are only support in Snow Leopard and later... |
3244 */ | 3244 */ |
3245 if(defpath && *defpath && DWOSMinor > 5) | 3245 if(defpath && *defpath && DWOSMinor > 5) |
3246 { | 3246 { |
3247 struct stat buf; | 3247 struct stat buf; |
3248 | 3248 |
3249 /* Get an absolute path */ | 3249 /* Get an absolute path */ |
3250 if(!realpath(defpath, temp)) | 3250 if(!realpath(defpath, temp)) |
3251 strcpy(temp, defpath); | 3251 strcpy(temp, defpath); |
3252 | 3252 |
3253 /* Check if the defpath exists */ | 3253 /* Check if the defpath exists */ |
3254 if(stat(temp, &buf) == 0) | 3254 if(stat(temp, &buf) == 0) |
3255 { | 3255 { |
3256 /* Can be a directory or file */ | 3256 /* Can be a directory or file */ |
3257 if(buf.st_mode & S_IFDIR) | 3257 if(buf.st_mode & S_IFDIR) |
3261 } | 3261 } |
3262 /* If it wasn't a directory... check if there is a path */ | 3262 /* If it wasn't a directory... check if there is a path */ |
3263 if(!path && strchr(temp, '/')) | 3263 if(!path && strchr(temp, '/')) |
3264 { | 3264 { |
3265 unsigned long x = strlen(temp) - 1; | 3265 unsigned long x = strlen(temp) - 1; |
3266 | 3266 |
3267 /* Trim off the filename */ | 3267 /* Trim off the filename */ |
3268 while(x > 0 && temp[x] != '/') | 3268 while(x > 0 && temp[x] != '/') |
3269 { | 3269 { |
3270 x--; | 3270 x--; |
3271 } | 3271 } |
3283 } | 3283 } |
3284 } | 3284 } |
3285 } | 3285 } |
3286 } | 3286 } |
3287 } | 3287 } |
3288 | 3288 |
3289 if(flags == DW_FILE_OPEN || flags == DW_DIRECTORY_OPEN) | 3289 if(flags == DW_FILE_OPEN || flags == DW_DIRECTORY_OPEN) |
3290 { | 3290 { |
3291 /* Create the File Open Dialog class. */ | 3291 /* Create the File Open Dialog class. */ |
3292 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; | 3292 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; |
3293 | 3293 |
3294 if(path) | 3294 if(path) |
3295 { | 3295 { |
3296 SEL ssdu = NSSelectorFromString(@"setDirectoryURL"); | 3296 SEL ssdu = NSSelectorFromString(@"setDirectoryURL"); |
3297 | 3297 |
3298 if([openDlg respondsToSelector:ssdu]) | 3298 if([openDlg respondsToSelector:ssdu]) |
3299 { | 3299 { |
3300 IMP isdu = [openDlg methodForSelector:ssdu]; | 3300 IMP isdu = [openDlg methodForSelector:ssdu]; |
3301 isdu(openDlg, ssdu, [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]); | 3301 isdu(openDlg, ssdu, [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]); |
3302 } | 3302 } |
3311 else | 3311 else |
3312 { | 3312 { |
3313 [openDlg setCanChooseFiles:NO]; | 3313 [openDlg setCanChooseFiles:NO]; |
3314 [openDlg setCanChooseDirectories:YES]; | 3314 [openDlg setCanChooseDirectories:YES]; |
3315 } | 3315 } |
3316 | 3316 |
3317 /* Handle file types */ | 3317 /* Handle file types */ |
3318 if(ext && *ext) | 3318 if(ext && *ext) |
3319 { | 3319 { |
3320 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease]; | 3320 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease]; |
3321 [openDlg setAllowedFileTypes:fileTypes]; | 3321 [openDlg setAllowedFileTypes:fileTypes]; |
3344 } | 3344 } |
3345 else | 3345 else |
3346 { | 3346 { |
3347 /* Create the File Save Dialog class. */ | 3347 /* Create the File Save Dialog class. */ |
3348 NSSavePanel* saveDlg = [NSSavePanel savePanel]; | 3348 NSSavePanel* saveDlg = [NSSavePanel savePanel]; |
3349 | 3349 |
3350 if(path) | 3350 if(path) |
3351 { | 3351 { |
3352 SEL ssdu = NSSelectorFromString(@"setDirectoryURL"); | 3352 SEL ssdu = NSSelectorFromString(@"setDirectoryURL"); |
3353 | 3353 |
3354 if([saveDlg respondsToSelector:ssdu]) | 3354 if([saveDlg respondsToSelector:ssdu]) |
3355 { | 3355 { |
3356 IMP isdu = [saveDlg methodForSelector:ssdu]; | 3356 IMP isdu = [saveDlg methodForSelector:ssdu]; |
3357 isdu(saveDlg, ssdu, [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]); | 3357 isdu(saveDlg, ssdu, [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]]); |
3358 } | 3358 } |
3359 } | 3359 } |
3360 if(file) | 3360 if(file) |
3361 { | 3361 { |
3362 SEL ssnfsv = NSSelectorFromString(@"setNameFieldStringValue"); | 3362 SEL ssnfsv = NSSelectorFromString(@"setNameFieldStringValue"); |
3363 | 3363 |
3364 if([saveDlg respondsToSelector:ssnfsv]) | 3364 if([saveDlg respondsToSelector:ssnfsv]) |
3365 { | 3365 { |
3366 IMP isnfsv = [saveDlg methodForSelector:ssnfsv]; | 3366 IMP isnfsv = [saveDlg methodForSelector:ssnfsv]; |
3367 isnfsv(saveDlg, ssnfsv, [NSString stringWithUTF8String:file]); | 3367 isnfsv(saveDlg, ssnfsv, [NSString stringWithUTF8String:file]); |
3368 } | 3368 } |
3375 if(ext && *ext) | 3375 if(ext && *ext) |
3376 { | 3376 { |
3377 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease]; | 3377 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease]; |
3378 [saveDlg setAllowedFileTypes:fileTypes]; | 3378 [saveDlg setAllowedFileTypes:fileTypes]; |
3379 } | 3379 } |
3380 | 3380 |
3381 /* Display the dialog. If the OK button was pressed, | 3381 /* Display the dialog. If the OK button was pressed, |
3382 * process the files. | 3382 * process the files. |
3383 */ | 3383 */ |
3384 if([saveDlg runModal] == NSFileHandlingPanelOKButton) | 3384 if([saveDlg runModal] == NSFileHandlingPanelOKButton) |
3385 { | 3385 { |
3425 */ | 3425 */ |
3426 void dw_clipboard_set_text( char *str, int len) | 3426 void dw_clipboard_set_text( char *str, int len) |
3427 { | 3427 { |
3428 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; | 3428 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; |
3429 SEL scc = NSSelectorFromString(@"clearContents"); | 3429 SEL scc = NSSelectorFromString(@"clearContents"); |
3430 | 3430 |
3431 if([pasteboard respondsToSelector:scc]) | 3431 if([pasteboard respondsToSelector:scc]) |
3432 { | 3432 { |
3433 IMP icc = [pasteboard methodForSelector:scc]; | 3433 IMP icc = [pasteboard methodForSelector:scc]; |
3434 icc(pasteboard, scc); | 3434 icc(pasteboard, scc); |
3435 } | 3435 } |
3618 } | 3618 } |
3619 if([object isMemberOfClass:[ NSBox class]]) | 3619 if([object isMemberOfClass:[ NSBox class]]) |
3620 { | 3620 { |
3621 NSBox *box = object; | 3621 NSBox *box = object; |
3622 id content = [box contentView]; | 3622 id content = [box contentView]; |
3623 | 3623 |
3624 if([content isMemberOfClass:[ DWText class]]) | 3624 if([content isMemberOfClass:[ DWText class]]) |
3625 { | 3625 { |
3626 object = content; | 3626 object = content; |
3627 } | 3627 } |
3628 } | 3628 } |
3629 return object; | 3629 return object; |
3630 } | 3630 } |
3631 | 3631 |
3632 /* Internal function to calculate the widget's required size.. | 3632 /* Internal function to calculate the widget's required size.. |
3633 * These are the general rules for widget sizes: | 3633 * These are the general rules for widget sizes: |
3634 * | 3634 * |
3635 * Render/Unspecified: 1x1 | 3635 * Render/Unspecified: 1x1 |
3636 * Scrolled(Container,Tree,MLE): Guessed size clamped to min and max in dw.h | 3636 * Scrolled(Container,Tree,MLE): Guessed size clamped to min and max in dw.h |
3637 * Entryfield/Combobox/Spinbutton: 150x(maxfontheight) | 3637 * Entryfield/Combobox/Spinbutton: 150x(maxfontheight) |
3638 * Spinbutton: 50x(maxfontheight) | 3638 * Spinbutton: 50x(maxfontheight) |
3639 * Text/Status: (textwidth)x(textheight) | 3639 * Text/Status: (textwidth)x(textheight) |
3643 void _control_size(id handle, int *width, int *height) | 3643 void _control_size(id handle, int *width, int *height) |
3644 { | 3644 { |
3645 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; | 3645 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; |
3646 NSString *nsstr = nil; | 3646 NSString *nsstr = nil; |
3647 id object = _text_handle(handle); | 3647 id object = _text_handle(handle); |
3648 | 3648 |
3649 /* Handle all the different button types */ | 3649 /* Handle all the different button types */ |
3650 if([ object isKindOfClass:[ NSButton class ] ]) | 3650 if([ object isKindOfClass:[ NSButton class ] ]) |
3651 { | 3651 { |
3652 switch([object buttonType]) | 3652 switch([object buttonType]) |
3653 { | 3653 { |
3658 nsstr = [object title]; | 3658 nsstr = [object title]; |
3659 break; | 3659 break; |
3660 default: | 3660 default: |
3661 { | 3661 { |
3662 NSImage *image = [object image]; | 3662 NSImage *image = [object image]; |
3663 | 3663 |
3664 if(image) | 3664 if(image) |
3665 { | 3665 { |
3666 /* Image button */ | 3666 /* Image button */ |
3667 NSSize size = [image size]; | 3667 NSSize size = [image size]; |
3668 thiswidth = (int)size.width; | 3668 thiswidth = (int)size.width; |
3675 } | 3675 } |
3676 else | 3676 else |
3677 { | 3677 { |
3678 /* Text button */ | 3678 /* Text button */ |
3679 nsstr = [object title]; | 3679 nsstr = [object title]; |
3680 | 3680 |
3681 if([object isBordered]) | 3681 if([object isBordered]) |
3682 { | 3682 { |
3683 extrawidth = 30; | 3683 extrawidth = 30; |
3684 extraheight = 8; | 3684 extraheight = 8; |
3685 } | 3685 } |
3695 } | 3695 } |
3696 /* If the control is an entryfield set width to 150 */ | 3696 /* If the control is an entryfield set width to 150 */ |
3697 else if([object isKindOfClass:[ NSTextField class ]]) | 3697 else if([object isKindOfClass:[ NSTextField class ]]) |
3698 { | 3698 { |
3699 NSFont *font = [object font]; | 3699 NSFont *font = [object font]; |
3700 | 3700 |
3701 if([object isEditable]) | 3701 if([object isEditable]) |
3702 { | 3702 { |
3703 /* Spinbuttons don't need to be as wide */ | 3703 /* Spinbuttons don't need to be as wide */ |
3704 if([object isMemberOfClass:[ DWSpinButton class]]) | 3704 if([object isMemberOfClass:[ DWSpinButton class]]) |
3705 thiswidth = 50; | 3705 thiswidth = 50; |
3709 if([object isMemberOfClass:[ DWComboBox class]]) | 3709 if([object isMemberOfClass:[ DWComboBox class]]) |
3710 extraheight = 4; | 3710 extraheight = 4; |
3711 } | 3711 } |
3712 else | 3712 else |
3713 nsstr = [object stringValue]; | 3713 nsstr = [object stringValue]; |
3714 | 3714 |
3715 if(font) | 3715 if(font) |
3716 thisheight = (int)[font boundingRectForFont].size.height; | 3716 thisheight = (int)[font boundingRectForFont].size.height; |
3717 } | 3717 } |
3718 /* Handle the ranged widgets */ | 3718 /* Handle the ranged widgets */ |
3719 else if([ object isMemberOfClass:[DWPercent class] ] || | 3719 else if([ object isMemberOfClass:[DWPercent class] ] || |
3738 } | 3738 } |
3739 /* Handle bitmap size */ | 3739 /* Handle bitmap size */ |
3740 else if([ object isMemberOfClass:[NSImageView class] ]) | 3740 else if([ object isMemberOfClass:[NSImageView class] ]) |
3741 { | 3741 { |
3742 NSImage *image = [object image]; | 3742 NSImage *image = [object image]; |
3743 | 3743 |
3744 if(image) | 3744 if(image) |
3745 { | 3745 { |
3746 NSSize size = [image size]; | 3746 NSSize size = [image size]; |
3747 thiswidth = (int)size.width; | 3747 thiswidth = (int)size.width; |
3748 thisheight = (int)size.height; | 3748 thisheight = (int)size.height; |
3750 } | 3750 } |
3751 /* Handle calendar */ | 3751 /* Handle calendar */ |
3752 else if([ object isMemberOfClass:[DWCalendar class] ]) | 3752 else if([ object isMemberOfClass:[DWCalendar class] ]) |
3753 { | 3753 { |
3754 NSCell *cell = [object cell]; | 3754 NSCell *cell = [object cell]; |
3755 | 3755 |
3756 if(cell) | 3756 if(cell) |
3757 { | 3757 { |
3758 NSSize size = [cell cellSize]; | 3758 NSSize size = [cell cellSize]; |
3759 | 3759 |
3760 thiswidth = size.width; | 3760 thiswidth = size.width; |
3761 thisheight = size.height; | 3761 thisheight = size.height; |
3762 } | 3762 } |
3763 } | 3763 } |
3764 /* MLE and Container */ | 3764 /* MLE and Container */ |
3765 else if([ object isMemberOfClass:[DWMLE class] ] || | 3765 else if([ object isMemberOfClass:[DWMLE class] ] || |
3766 [ object isMemberOfClass:[DWContainer class] ]) | 3766 [ object isMemberOfClass:[DWContainer class] ]) |
3767 { | 3767 { |
3768 NSSize size; | 3768 NSSize size; |
3769 | 3769 |
3770 if([ object isMemberOfClass:[DWMLE class] ]) | 3770 if([ object isMemberOfClass:[DWMLE class] ]) |
3771 { | 3771 { |
3772 NSScrollView *sv = [object scrollview]; | 3772 NSScrollView *sv = [object scrollview]; |
3773 NSSize frame = [sv frame].size; | 3773 NSSize frame = [sv frame].size; |
3774 BOOL hscroll = [sv hasHorizontalScroller]; | 3774 BOOL hscroll = [sv hasHorizontalScroller]; |
3775 | 3775 |
3776 /* Make sure word wrap is off for the first part */ | 3776 /* Make sure word wrap is off for the first part */ |
3777 if(!hscroll) | 3777 if(!hscroll) |
3778 { | 3778 { |
3779 [[object textContainer] setWidthTracksTextView:NO]; | 3779 [[object textContainer] setWidthTracksTextView:NO]; |
3780 [[object textContainer] setContainerSize:[object maxSize]]; | 3780 [[object textContainer] setContainerSize:[object maxSize]]; |
3789 /* Re-enable word wrapping if it was on */ | 3789 /* Re-enable word wrapping if it was on */ |
3790 if(!hscroll) | 3790 if(!hscroll) |
3791 { | 3791 { |
3792 [[object textContainer] setWidthTracksTextView:YES]; | 3792 [[object textContainer] setWidthTracksTextView:YES]; |
3793 [sv setHasHorizontalScroller:NO]; | 3793 [sv setHasHorizontalScroller:NO]; |
3794 | 3794 |
3795 /* If the un wrapped it is beyond the bounds... */ | 3795 /* If the un wrapped it is beyond the bounds... */ |
3796 if(size.width > _DW_SCROLLED_MAX_WIDTH) | 3796 if(size.width > _DW_SCROLLED_MAX_WIDTH) |
3797 { | 3797 { |
3798 NSSize max = [object maxSize]; | 3798 NSSize max = [object maxSize]; |
3799 | 3799 |
3800 /* Set the max size to the limit */ | 3800 /* Set the max size to the limit */ |
3801 [object setMaxSize:NSMakeSize(_DW_SCROLLED_MAX_WIDTH, max.height)]; | 3801 [object setMaxSize:NSMakeSize(_DW_SCROLLED_MAX_WIDTH, max.height)]; |
3802 /* Recalculate the size */ | 3802 /* Recalculate the size */ |
3803 [object sizeToFit]; | 3803 [object sizeToFit]; |
3804 size = [object bounds].size; | 3804 size = [object bounds].size; |
3812 if(hscroll && size.width > _DW_SCROLLED_MAX_WIDTH) | 3812 if(hscroll && size.width > _DW_SCROLLED_MAX_WIDTH) |
3813 size.height += 16.0; | 3813 size.height += 16.0; |
3814 } | 3814 } |
3815 else | 3815 else |
3816 size = [object getsize]; | 3816 size = [object getsize]; |
3817 | 3817 |
3818 thiswidth = size.width; | 3818 thiswidth = size.width; |
3819 thisheight = size.height; | 3819 thisheight = size.height; |
3820 | 3820 |
3821 if(thiswidth < _DW_SCROLLED_MIN_WIDTH) | 3821 if(thiswidth < _DW_SCROLLED_MIN_WIDTH) |
3822 thiswidth = _DW_SCROLLED_MIN_WIDTH; | 3822 thiswidth = _DW_SCROLLED_MIN_WIDTH; |
3823 if(thiswidth > _DW_SCROLLED_MAX_WIDTH) | 3823 if(thiswidth > _DW_SCROLLED_MAX_WIDTH) |
3824 thiswidth = _DW_SCROLLED_MAX_WIDTH; | 3824 thiswidth = _DW_SCROLLED_MAX_WIDTH; |
3825 if(thisheight < _DW_SCROLLED_MIN_HEIGHT) | 3825 if(thisheight < _DW_SCROLLED_MIN_HEIGHT) |
3830 /* Tree */ | 3830 /* Tree */ |
3831 else if([ object isMemberOfClass:[DWTree class] ]) | 3831 else if([ object isMemberOfClass:[DWTree class] ]) |
3832 { | 3832 { |
3833 thiswidth = (int)((_DW_SCROLLED_MAX_WIDTH + _DW_SCROLLED_MIN_WIDTH)/2); | 3833 thiswidth = (int)((_DW_SCROLLED_MAX_WIDTH + _DW_SCROLLED_MIN_WIDTH)/2); |
3834 thisheight = (int)((_DW_SCROLLED_MAX_HEIGHT + _DW_SCROLLED_MIN_HEIGHT)/2); | 3834 thisheight = (int)((_DW_SCROLLED_MAX_HEIGHT + _DW_SCROLLED_MIN_HEIGHT)/2); |
3835 } | 3835 } |
3836 /* Any other control type */ | 3836 /* Any other control type */ |
3837 else if([ object isKindOfClass:[ NSControl class ] ]) | 3837 else if([ object isKindOfClass:[ NSControl class ] ]) |
3838 nsstr = [object stringValue]; | 3838 nsstr = [object stringValue]; |
3839 | 3839 |
3840 /* If we have a string... | 3840 /* If we have a string... |
3841 * calculate the size with the current font. | 3841 * calculate the size with the current font. |
3842 */ | 3842 */ |
3843 if(nsstr && [nsstr length]) | 3843 if(nsstr && [nsstr length]) |
3844 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight); | 3844 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight); |
3845 | 3845 |
3846 /* Handle static text fields */ | 3846 /* Handle static text fields */ |
3847 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable]) | 3847 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable]) |
3848 { | 3848 { |
3849 id border = handle; | 3849 id border = handle; |
3850 | 3850 |
3851 extrawidth = 10; | 3851 extrawidth = 10; |
3852 | 3852 |
3853 /* Handle status bar field */ | 3853 /* Handle status bar field */ |
3854 if([border isMemberOfClass:[ NSBox class ] ]) | 3854 if([border isMemberOfClass:[ NSBox class ] ]) |
3855 { | 3855 { |
3856 extrawidth += 2; | 3856 extrawidth += 2; |
3857 extraheight = 8; | 3857 extraheight = 8; |
3858 } | 3858 } |
3859 } | 3859 } |
3860 | 3860 |
3861 /* Set the requested sizes */ | 3861 /* Set the requested sizes */ |
3862 if(width) | 3862 if(width) |
3863 *width = thiswidth + extrawidth; | 3863 *width = thiswidth + extrawidth; |
3864 if(height) | 3864 if(height) |
3865 *height = thisheight + extraheight; | 3865 *height = thisheight + extraheight; |
3953 tmpitem[index].origwidth = tmpitem[index].width = width; | 3953 tmpitem[index].origwidth = tmpitem[index].width = width; |
3954 tmpitem[index].origheight = tmpitem[index].height = height; | 3954 tmpitem[index].origheight = tmpitem[index].height = height; |
3955 tmpitem[index].pad = pad; | 3955 tmpitem[index].pad = pad; |
3956 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC; | 3956 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC; |
3957 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC; | 3957 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC; |
3958 | 3958 |
3959 /* If either of the parameters are -1 ... calculate the size */ | 3959 /* If either of the parameters are -1 ... calculate the size */ |
3960 if(width == -1 || height == -1) | 3960 if(width == -1 || height == -1) |
3961 _control_size(object, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); | 3961 _control_size(object, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); |
3962 | 3962 |
3963 thisbox->items = tmpitem; | 3963 thisbox->items = tmpitem; |
4001 { | 4001 { |
4002 int _locked_by_me = FALSE; | 4002 int _locked_by_me = FALSE; |
4003 DW_LOCAL_POOL_IN; | 4003 DW_LOCAL_POOL_IN; |
4004 DW_MUTEX_LOCK; | 4004 DW_MUTEX_LOCK; |
4005 id object = handle; | 4005 id object = handle; |
4006 | 4006 |
4007 if([object isKindOfClass:[NSView class]] || [object isKindOfClass:[NSControl class]]) | 4007 if([object isKindOfClass:[NSView class]] || [object isKindOfClass:[NSControl class]]) |
4008 { | 4008 { |
4009 DWBox *parent = (DWBox *)[object superview]; | 4009 DWBox *parent = (DWBox *)[object superview]; |
4010 | 4010 |
4011 /* Some controls are embedded in scrollviews... | 4011 /* Some controls are embedded in scrollviews... |
4012 * so get the parent of the scrollview in that case. | 4012 * so get the parent of the scrollview in that case. |
4013 */ | 4013 */ |
4014 if(([object isKindOfClass:[NSTableView class]] || [object isMemberOfClass:[DWMLE class]]) | 4014 if(([object isKindOfClass:[NSTableView class]] || [object isMemberOfClass:[DWMLE class]]) |
4015 && [parent isMemberOfClass:[NSClipView class]]) | 4015 && [parent isMemberOfClass:[NSClipView class]]) |
4016 { | 4016 { |
4017 object = [parent superview]; | 4017 object = [parent superview]; |
4018 parent = (DWBox *)[object superview]; | 4018 parent = (DWBox *)[object superview]; |
4019 } | 4019 } |
4020 | 4020 |
4021 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) | 4021 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) |
4022 { | 4022 { |
4023 id window = [object window]; | 4023 id window = [object window]; |
4024 Box *thisbox = [parent box]; | 4024 Box *thisbox = [parent box]; |
4025 int z, index = -1; | 4025 int z, index = -1; |
4026 Item *tmpitem = NULL, *thisitem = thisbox->items; | 4026 Item *tmpitem = NULL, *thisitem = thisbox->items; |
4027 | 4027 |
4028 if(!thisitem) | 4028 if(!thisitem) |
4029 thisbox->count = 0; | 4029 thisbox->count = 0; |
4030 | 4030 |
4031 for(z=0;z<thisbox->count;z++) | 4031 for(z=0;z<thisbox->count;z++) |
4032 { | 4032 { |
4033 if(thisitem[z].hwnd == object) | 4033 if(thisitem[z].hwnd == object) |
4034 index = z; | 4034 index = z; |
4035 } | 4035 } |
4036 | 4036 |
4037 if(index == -1) | 4037 if(index == -1) |
4038 { | 4038 { |
4039 DW_MUTEX_UNLOCK; | 4039 DW_MUTEX_UNLOCK; |
4040 DW_LOCAL_POOL_OUT; | 4040 DW_LOCAL_POOL_OUT; |
4041 return DW_ERROR_GENERAL; | 4041 return DW_ERROR_GENERAL; |
4042 } | 4042 } |
4043 | 4043 |
4044 [object retain]; | 4044 [object retain]; |
4045 [object removeFromSuperview]; | 4045 [object removeFromSuperview]; |
4046 | 4046 |
4047 if(thisbox->count > 1) | 4047 if(thisbox->count > 1) |
4048 { | 4048 { |
4049 tmpitem = calloc(sizeof(Item), (thisbox->count-1)); | 4049 tmpitem = calloc(sizeof(Item), (thisbox->count-1)); |
4050 | 4050 |
4051 /* Copy all but the current entry to the new list */ | 4051 /* Copy all but the current entry to the new list */ |
4052 for(z=0;z<index;z++) | 4052 for(z=0;z<index;z++) |
4053 { | 4053 { |
4054 tmpitem[z] = thisitem[z]; | 4054 tmpitem[z] = thisitem[z]; |
4055 } | 4055 } |
4056 for(z=index+1;z<thisbox->count;z++) | 4056 for(z=index+1;z<thisbox->count;z++) |
4057 { | 4057 { |
4058 tmpitem[z-1] = thisitem[z]; | 4058 tmpitem[z-1] = thisitem[z]; |
4059 } | 4059 } |
4060 } | 4060 } |
4061 | 4061 |
4062 thisbox->items = tmpitem; | 4062 thisbox->items = tmpitem; |
4063 if(thisitem) | 4063 if(thisitem) |
4064 free(thisitem); | 4064 free(thisitem); |
4065 if(tmpitem) | 4065 if(tmpitem) |
4066 thisbox->count--; | 4066 thisbox->count--; |
4088 int _locked_by_me = FALSE; | 4088 int _locked_by_me = FALSE; |
4089 DW_LOCAL_POOL_IN; | 4089 DW_LOCAL_POOL_IN; |
4090 DW_MUTEX_LOCK; | 4090 DW_MUTEX_LOCK; |
4091 DWBox *parent = (DWBox *)box; | 4091 DWBox *parent = (DWBox *)box; |
4092 id object = nil; | 4092 id object = nil; |
4093 | 4093 |
4094 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) | 4094 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) |
4095 { | 4095 { |
4096 id window = [parent window]; | 4096 id window = [parent window]; |
4097 Box *thisbox = [parent box]; | 4097 Box *thisbox = [parent box]; |
4098 | 4098 |
4099 if(thisbox && index > -1 && index < thisbox->count) | 4099 if(thisbox && index > -1 && index < thisbox->count) |
4100 { | 4100 { |
4101 int z; | 4101 int z; |
4102 Item *tmpitem = NULL, *thisitem = thisbox->items; | 4102 Item *tmpitem = NULL, *thisitem = thisbox->items; |
4103 | 4103 |
4104 object = thisitem[index].hwnd; | 4104 object = thisitem[index].hwnd; |
4105 | 4105 |
4106 if(object) | 4106 if(object) |
4107 { | 4107 { |
4108 [object retain]; | 4108 [object retain]; |
4109 [object removeFromSuperview]; | 4109 [object removeFromSuperview]; |
4110 } | 4110 } |
4111 | 4111 |
4112 if(thisbox->count > 1) | 4112 if(thisbox->count > 1) |
4113 { | 4113 { |
4114 tmpitem = calloc(sizeof(Item), (thisbox->count-1)); | 4114 tmpitem = calloc(sizeof(Item), (thisbox->count-1)); |
4115 | 4115 |
4116 /* Copy all but the current entry to the new list */ | 4116 /* Copy all but the current entry to the new list */ |
4117 for(z=0;thisitem && z<index;z++) | 4117 for(z=0;thisitem && z<index;z++) |
4118 { | 4118 { |
4119 tmpitem[z] = thisitem[z]; | 4119 tmpitem[z] = thisitem[z]; |
4120 } | 4120 } |
4121 for(z=index+1;z<thisbox->count;z++) | 4121 for(z=index+1;z<thisbox->count;z++) |
4122 { | 4122 { |
4123 tmpitem[z-1] = thisitem[z]; | 4123 tmpitem[z-1] = thisitem[z]; |
4124 } | 4124 } |
4125 } | 4125 } |
4126 | 4126 |
4127 thisbox->items = tmpitem; | 4127 thisbox->items = tmpitem; |
4128 if(thisitem) | 4128 if(thisitem) |
4129 free(thisitem); | 4129 free(thisitem); |
4130 if(tmpitem) | 4130 if(tmpitem) |
4131 thisbox->count--; | 4131 thisbox->count--; |
4132 else | 4132 else |
4133 thisbox->count = 0; | 4133 thisbox->count = 0; |
4134 | 4134 |
4135 /* Queue a redraw on the top-level window */ | 4135 /* Queue a redraw on the top-level window */ |
4136 _dw_redraw(window, TRUE); | 4136 _dw_redraw(window, TRUE); |
4137 } | 4137 } |
4138 } | 4138 } |
4139 DW_MUTEX_UNLOCK; | 4139 DW_MUTEX_UNLOCK; |
5300 */ | 5300 */ |
5301 void API dw_mle_set_word_wrap(HWND handle, int state) | 5301 void API dw_mle_set_word_wrap(HWND handle, int state) |
5302 { | 5302 { |
5303 DWMLE *mle = handle; | 5303 DWMLE *mle = handle; |
5304 NSScrollView *sv = [mle scrollview]; | 5304 NSScrollView *sv = [mle scrollview]; |
5305 | 5305 |
5306 if(state) | 5306 if(state) |
5307 { | 5307 { |
5308 [[mle textContainer] setWidthTracksTextView:YES]; | 5308 [[mle textContainer] setWidthTracksTextView:YES]; |
5309 [sv setHasHorizontalScroller:NO]; | 5309 [sv setHasHorizontalScroller:NO]; |
5310 } | 5310 } |
5400 */ | 5400 */ |
5401 HWND API dw_status_text_new(char *text, ULONG cid) | 5401 HWND API dw_status_text_new(char *text, ULONG cid) |
5402 { | 5402 { |
5403 NSBox *border = [[NSBox alloc] init]; | 5403 NSBox *border = [[NSBox alloc] init]; |
5404 NSTextField *textfield = dw_text_new(text, cid); | 5404 NSTextField *textfield = dw_text_new(text, cid); |
5405 | 5405 |
5406 [border setBorderType:NSGrooveBorder]; | 5406 [border setBorderType:NSGrooveBorder]; |
5407 //[border setBorderType:NSLineBorder]; | 5407 //[border setBorderType:NSLineBorder]; |
5408 [border setTitlePosition:NSNoTitle]; | 5408 [border setTitlePosition:NSNoTitle]; |
5409 [border setContentView:textfield]; | 5409 [border setContentView:textfield]; |
5410 [border setContentViewMargins:NSMakeSize(1.5,1.5)]; | 5410 [border setContentViewMargins:NSMakeSize(1.5,1.5)]; |
5523 [colorDlg setTarget:colorDlg]; | 5523 [colorDlg setTarget:colorDlg]; |
5524 [colorDlg setAction:@selector(changeColor:)]; | 5524 [colorDlg setAction:@selector(changeColor:)]; |
5525 } | 5525 } |
5526 else | 5526 else |
5527 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; | 5527 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; |
5528 | 5528 |
5529 /* If someone is already waiting just return */ | 5529 /* If someone is already waiting just return */ |
5530 if([colorDlg dialog]) | 5530 if([colorDlg dialog]) |
5531 { | 5531 { |
5532 DW_LOCAL_POOL_OUT; | 5532 DW_LOCAL_POOL_OUT; |
5533 return value; | 5533 return value; |
5534 } | 5534 } |
5535 | 5535 |
5536 unsigned long tempcol = _get_color(value); | 5536 unsigned long tempcol = _get_color(value); |
5537 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(tempcol)/255.0 green: DW_GREEN_VALUE(tempcol)/255.0 blue: DW_BLUE_VALUE(tempcol)/255.0 alpha: 1] retain]; | 5537 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(tempcol)/255.0 green: DW_GREEN_VALUE(tempcol)/255.0 blue: DW_BLUE_VALUE(tempcol)/255.0 alpha: 1] retain]; |
5538 [colorDlg setColor:color]; | 5538 [colorDlg setColor:color]; |
5539 | 5539 |
5540 dialog = dw_dialog_new(colorDlg); | 5540 dialog = dw_dialog_new(colorDlg); |
5541 [colorDlg setDialog:dialog]; | 5541 [colorDlg setDialog:dialog]; |
5542 [colorDlg makeKeyAndOrderFront:nil]; | 5542 [colorDlg makeKeyAndOrderFront:nil]; |
5543 | 5543 |
5544 /* Wait for them to pick a color */ | 5544 /* Wait for them to pick a color */ |
5740 { | 5740 { |
5741 id object = handle; | 5741 id object = handle; |
5742 NSString *nstr; | 5742 NSString *nstr; |
5743 NSFont *font = nil; | 5743 NSFont *font = nil; |
5744 DW_LOCAL_POOL_IN; | 5744 DW_LOCAL_POOL_IN; |
5745 | 5745 |
5746 nstr = [NSString stringWithUTF8String:text]; | 5746 nstr = [NSString stringWithUTF8String:text]; |
5747 | 5747 |
5748 /* Check the pixmap for associated object or font */ | 5748 /* Check the pixmap for associated object or font */ |
5749 if(pixmap) | 5749 if(pixmap) |
5750 { | 5750 { |
5751 object = pixmap->handle; | 5751 object = pixmap->handle; |
5752 font = pixmap->font; | 5752 font = pixmap->font; |
5921 { | 5921 { |
5922 int _locked_by_me = FALSE; | 5922 int _locked_by_me = FALSE; |
5923 DW_LOCAL_POOL_IN; | 5923 DW_LOCAL_POOL_IN; |
5924 DW_MUTEX_LOCK; | 5924 DW_MUTEX_LOCK; |
5925 id image = handle; | 5925 id image = handle; |
5926 | 5926 |
5927 if(pixmap) | 5927 if(pixmap) |
5928 { | 5928 { |
5929 image = (id)pixmap->image; | 5929 image = (id)pixmap->image; |
5930 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES); | 5930 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES); |
5931 [NSGraphicsContext saveGraphicsState]; | 5931 [NSGraphicsContext saveGraphicsState]; |
5956 double a1 = atan2((y1-yorigin), (x1-xorigin)); | 5956 double a1 = atan2((y1-yorigin), (x1-xorigin)); |
5957 double a2 = atan2((y2-yorigin), (x2-xorigin)); | 5957 double a2 = atan2((y2-yorigin), (x2-xorigin)); |
5958 double dx = xorigin - x1; | 5958 double dx = xorigin - x1; |
5959 double dy = yorigin - y1; | 5959 double dy = yorigin - y1; |
5960 double r = sqrt(dx*dx + dy*dy); | 5960 double r = sqrt(dx*dx + dy*dy); |
5961 | 5961 |
5962 /* Convert to degrees */ | 5962 /* Convert to degrees */ |
5963 a1 *= (180.0 / M_PI); | 5963 a1 *= (180.0 / M_PI); |
5964 a2 *= (180.0 / M_PI); | 5964 a2 *= (180.0 / M_PI); |
5965 | 5965 |
5966 /* Prepare to draw */ | 5966 /* Prepare to draw */ |
5967 [aPath appendBezierPathWithArcWithCenter:NSMakePoint(xorigin, yorigin) | 5967 [aPath appendBezierPathWithArcWithCenter:NSMakePoint(xorigin, yorigin) |
5968 radius:r startAngle:a1 endAngle:a2]; | 5968 radius:r startAngle:a1 endAngle:a2]; |
5969 } | 5969 } |
5970 /* If the fill flag is passed */ | 5970 /* If the fill flag is passed */ |
6109 int _locked_by_me = FALSE; | 6109 int _locked_by_me = FALSE; |
6110 DW_MUTEX_LOCK; | 6110 DW_MUTEX_LOCK; |
6111 DWTree *tree = handle; | 6111 DWTree *tree = handle; |
6112 NSMutableArray *array = (NSMutableArray *)item; | 6112 NSMutableArray *array = (NSMutableArray *)item; |
6113 DW_LOCAL_POOL_IN; | 6113 DW_LOCAL_POOL_IN; |
6114 | 6114 |
6115 if(title) | 6115 if(title) |
6116 { | 6116 { |
6117 NSString *oldstr = [array objectAtIndex:1]; | 6117 NSString *oldstr = [array objectAtIndex:1]; |
6118 NSString *nstr = [[NSString stringWithUTF8String:title] retain]; | 6118 NSString *nstr = [[NSString stringWithUTF8String:title] retain]; |
6119 [array replaceObjectAtIndex:1 withObject:nstr]; | 6119 [array replaceObjectAtIndex:1 withObject:nstr]; |
6420 object = [ NSString stringWithUTF8String:str ]; | 6420 object = [ NSString stringWithUTF8String:str ]; |
6421 } | 6421 } |
6422 else | 6422 else |
6423 { | 6423 { |
6424 char textbuffer[101] = {0}; | 6424 char textbuffer[101] = {0}; |
6425 | 6425 |
6426 if(type & DW_CFA_ULONG) | 6426 if(type & DW_CFA_ULONG) |
6427 { | 6427 { |
6428 ULONG tmp = *((ULONG *)data); | 6428 ULONG tmp = *((ULONG *)data); |
6429 | 6429 |
6430 snprintf(textbuffer, 100, "%lu", tmp); | 6430 snprintf(textbuffer, 100, "%lu", tmp); |
6431 } | 6431 } |
6432 else if(type & DW_CFA_DATE) | 6432 else if(type & DW_CFA_DATE) |
6433 { | 6433 { |
6434 struct tm curtm; | 6434 struct tm curtm; |
6435 CDATE cdate = *((CDATE *)data); | 6435 CDATE cdate = *((CDATE *)data); |
6436 | 6436 |
6437 memset( &curtm, 0, sizeof(curtm) ); | 6437 memset( &curtm, 0, sizeof(curtm) ); |
6438 curtm.tm_mday = cdate.day; | 6438 curtm.tm_mday = cdate.day; |
6439 curtm.tm_mon = cdate.month - 1; | 6439 curtm.tm_mon = cdate.month - 1; |
6440 curtm.tm_year = cdate.year - 1900; | 6440 curtm.tm_year = cdate.year - 1900; |
6441 | 6441 |
6442 strftime(textbuffer, 100, "%x", &curtm); | 6442 strftime(textbuffer, 100, "%x", &curtm); |
6443 } | 6443 } |
6444 else if(type & DW_CFA_TIME) | 6444 else if(type & DW_CFA_TIME) |
6445 { | 6445 { |
6446 struct tm curtm; | 6446 struct tm curtm; |
6447 CTIME ctime = *((CTIME *)data); | 6447 CTIME ctime = *((CTIME *)data); |
6448 | 6448 |
6449 memset( &curtm, 0, sizeof(curtm) ); | 6449 memset( &curtm, 0, sizeof(curtm) ); |
6450 curtm.tm_hour = ctime.hours; | 6450 curtm.tm_hour = ctime.hours; |
6451 curtm.tm_min = ctime.minutes; | 6451 curtm.tm_min = ctime.minutes; |
6452 curtm.tm_sec = ctime.seconds; | 6452 curtm.tm_sec = ctime.seconds; |
6453 | 6453 |
6454 strftime(textbuffer, 100, "%X", &curtm); | 6454 strftime(textbuffer, 100, "%X", &curtm); |
6455 } | 6455 } |
6456 if(textbuffer[0]) | 6456 if(textbuffer[0]) |
6457 object = [ NSString stringWithUTF8String:textbuffer ]; | 6457 object = [ NSString stringWithUTF8String:textbuffer ]; |
6458 } | 6458 } |
6600 void API dw_container_set_stripe(HWND handle, unsigned long oddcolor, unsigned long evencolor) | 6600 void API dw_container_set_stripe(HWND handle, unsigned long oddcolor, unsigned long evencolor) |
6601 { | 6601 { |
6602 int _locked_by_me = FALSE; | 6602 int _locked_by_me = FALSE; |
6603 DW_MUTEX_LOCK; | 6603 DW_MUTEX_LOCK; |
6604 DWContainer *cont = handle; | 6604 DWContainer *cont = handle; |
6605 [cont setRowBgOdd:(oddcolor == DW_CLR_DEFAULT ? DW_RGB(230,230,230) : oddcolor) | 6605 [cont setRowBgOdd:(oddcolor == DW_CLR_DEFAULT ? DW_RGB(230,230,230) : oddcolor) |
6606 andEven:(evencolor == DW_CLR_DEFAULT ? DW_RGB_TRANSPARENT : evencolor)]; | 6606 andEven:(evencolor == DW_CLR_DEFAULT ? DW_RGB_TRANSPARENT : evencolor)]; |
6607 DW_MUTEX_UNLOCK; | 6607 DW_MUTEX_UNLOCK; |
6608 } | 6608 } |
6609 | 6609 |
6610 /* | 6610 /* |
6958 { | 6958 { |
6959 if(size.width > 24) | 6959 if(size.width > 24) |
6960 size.width = 24; | 6960 size.width = 24; |
6961 if(size.height > 24) | 6961 if(size.height > 24) |
6962 size.height = 24; | 6962 size.height = 24; |
6963 [image setSize:size]; | 6963 [image setSize:size]; |
6964 } | 6964 } |
6965 } | 6965 } |
6966 } | 6966 } |
6967 | 6967 |
6968 /* Internal version that does not resize the image */ | 6968 /* Internal version that does not resize the image */ |
7166 NSFont *_dw_font_by_name(char *fontname) | 7166 NSFont *_dw_font_by_name(char *fontname) |
7167 { | 7167 { |
7168 char *fontcopy = strdup(fontname); | 7168 char *fontcopy = strdup(fontname); |
7169 char *name = strchr(fontcopy, '.'); | 7169 char *name = strchr(fontcopy, '.'); |
7170 NSFont *font = nil; | 7170 NSFont *font = nil; |
7171 | 7171 |
7172 if(name) | 7172 if(name) |
7173 { | 7173 { |
7174 int size = atoi(fontcopy); | 7174 int size = atoi(fontcopy); |
7175 *name = 0; | 7175 *name = 0; |
7176 name++; | 7176 name++; |
7392 | 7392 |
7393 NSBundle *bundle = [NSBundle mainBundle]; | 7393 NSBundle *bundle = [NSBundle mainBundle]; |
7394 NSString *respath = [bundle resourcePath]; | 7394 NSString *respath = [bundle resourcePath]; |
7395 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid]; | 7395 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid]; |
7396 NSImage *temp = [[NSImage alloc] initWithContentsOfFile:filepath]; | 7396 NSImage *temp = [[NSImage alloc] initWithContentsOfFile:filepath]; |
7397 | 7397 |
7398 if(temp) | 7398 if(temp) |
7399 { | 7399 { |
7400 NSSize size = [temp size]; | 7400 NSSize size = [temp size]; |
7401 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] | 7401 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] |
7402 initWithBitmapDataPlanes:NULL | 7402 initWithBitmapDataPlanes:NULL |
7436 int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname) | 7436 int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname) |
7437 { | 7437 { |
7438 if(pixmap) | 7438 if(pixmap) |
7439 { | 7439 { |
7440 NSFont *font = _dw_font_by_name(fontname); | 7440 NSFont *font = _dw_font_by_name(fontname); |
7441 | 7441 |
7442 if(font) | 7442 if(font) |
7443 { | 7443 { |
7444 DW_LOCAL_POOL_IN; | 7444 DW_LOCAL_POOL_IN; |
7445 NSFont *oldfont = pixmap->font; | 7445 NSFont *oldfont = pixmap->font; |
7446 [font retain]; | 7446 [font retain]; |
7514 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight) | 7514 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight) |
7515 { | 7515 { |
7516 DWBitBlt *bltinfo = calloc(1, sizeof(DWBitBlt)); | 7516 DWBitBlt *bltinfo = calloc(1, sizeof(DWBitBlt)); |
7517 NSValue* bi; | 7517 NSValue* bi; |
7518 DW_LOCAL_POOL_IN; | 7518 DW_LOCAL_POOL_IN; |
7519 | 7519 |
7520 bi = [NSValue valueWithPointer:bltinfo]; | 7520 bi = [NSValue valueWithPointer:bltinfo]; |
7521 | 7521 |
7522 /* Sanity checks */ | 7522 /* Sanity checks */ |
7523 if((!dest && !destp) || (!src && !srcp) || | 7523 if((!dest && !destp) || (!src && !srcp) || |
7524 ((srcwidth == -1 || srcheight == -1) && srcwidth != srcheight)) | 7524 ((srcwidth == -1 || srcheight == -1) && srcwidth != srcheight)) |
7525 { | 7525 { |
7526 DW_LOCAL_POOL_OUT; | 7526 DW_LOCAL_POOL_OUT; |
7527 return DW_ERROR_GENERAL; | 7527 return DW_ERROR_GENERAL; |
7528 } | 7528 } |
7529 | 7529 |
7530 /* Fill in the information */ | 7530 /* Fill in the information */ |
7531 bltinfo->dest = dest; | 7531 bltinfo->dest = dest; |
7532 bltinfo->src = src; | 7532 bltinfo->src = src; |
7533 bltinfo->xdest = xdest; | 7533 bltinfo->xdest = xdest; |
7534 bltinfo->ydest = ydest; | 7534 bltinfo->ydest = ydest; |
7860 | 7860 |
7861 item = [[[DWMenuItem alloc] initWithTitle:nstr | 7861 item = [[[DWMenuItem alloc] initWithTitle:nstr |
7862 action:@selector(menuHandler:) | 7862 action:@selector(menuHandler:) |
7863 keyEquivalent:[ NSString stringWithUTF8String:accel ]] autorelease]; | 7863 keyEquivalent:[ NSString stringWithUTF8String:accel ]] autorelease]; |
7864 [menu addItem:item]; | 7864 [menu addItem:item]; |
7865 | 7865 |
7866 [item setTag:itemid]; | 7866 [item setTag:itemid]; |
7867 if(check) | 7867 if(check) |
7868 { | 7868 { |
7869 [item setCheck:YES]; | 7869 [item setCheck:YES]; |
7870 if(flags & DW_MIS_CHECKED) | 7870 if(flags & DW_MIS_CHECKED) |
7916 /* | 7916 /* |
7917 * Deletes the menu item specified. | 7917 * Deletes the menu item specified. |
7918 * Parameters: | 7918 * Parameters: |
7919 * menu: The handle to the menu in which the item was appended. | 7919 * menu: The handle to the menu in which the item was appended. |
7920 * id: Menuitem id. | 7920 * id: Menuitem id. |
7921 * Returns: | 7921 * Returns: |
7922 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure. | 7922 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure. |
7923 */ | 7923 */ |
7924 int API dw_menu_delete_item(HMENUI menux, unsigned long itemid) | 7924 int API dw_menu_delete_item(HMENUI menux, unsigned long itemid) |
7925 { | 7925 { |
7926 id menu = menux; | 7926 id menu = menux; |
7927 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; | 7927 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; |
7928 | 7928 |
7929 if(menuitem != nil) | 7929 if(menuitem != nil) |
7930 { | 7930 { |
7931 [menu removeItem:menuitem]; | 7931 [menu removeItem:menuitem]; |
7932 return DW_ERROR_NONE; | 7932 return DW_ERROR_NONE; |
7933 } | 7933 } |
8138 int _locked_by_me = FALSE; | 8138 int _locked_by_me = FALSE; |
8139 DW_MUTEX_LOCK; | 8139 DW_MUTEX_LOCK; |
8140 NSRect frame = NSMakeRect(1,1,1,1); | 8140 NSRect frame = NSMakeRect(1,1,1,1); |
8141 DWWindow *window = [[DWWindow alloc] | 8141 DWWindow *window = [[DWWindow alloc] |
8142 initWithContentRect:frame | 8142 initWithContentRect:frame |
8143 styleMask:(flStyle | NSTexturedBackgroundWindowMask) | 8143 styleMask:(flStyle) |
8144 backing:NSBackingStoreBuffered | 8144 backing:NSBackingStoreBuffered |
8145 defer:false]; | 8145 defer:false]; |
8146 | 8146 |
8147 [window setTitle:[ NSString stringWithUTF8String:title ]]; | 8147 [window setTitle:[ NSString stringWithUTF8String:title ]]; |
8148 | 8148 |
8151 [window setContentView:view]; | 8151 [window setContentView:view]; |
8152 [window setDelegate:view]; | 8152 [window setDelegate:view]; |
8153 [window setAutorecalculatesKeyViewLoop:YES]; | 8153 [window setAutorecalculatesKeyViewLoop:YES]; |
8154 [window setAcceptsMouseMovedEvents:YES]; | 8154 [window setAcceptsMouseMovedEvents:YES]; |
8155 [view release]; | 8155 [view release]; |
8156 | 8156 |
8157 /* Enable full screen mode on resizeable windows */ | 8157 /* Enable full screen mode on resizeable windows */ |
8158 if(flStyle & DW_FCF_SIZEBORDER) | 8158 if(flStyle & DW_FCF_SIZEBORDER) |
8159 { | 8159 { |
8160 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; | 8160 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; |
8161 } | 8161 } |
8250 if(rect.size.width <= 1 || rect.size.height <= 1) | 8250 if(rect.size.width <= 1 || rect.size.height <= 1) |
8251 { | 8251 { |
8252 /* Determine the contents size */ | 8252 /* Determine the contents size */ |
8253 dw_window_set_size(handle, 0, 0); | 8253 dw_window_set_size(handle, 0, 0); |
8254 } | 8254 } |
8255 /* If the position was not set... generate a default | 8255 /* If the position was not set... generate a default |
8256 * default one in a similar pattern to SHELLPOSITION. | 8256 * default one in a similar pattern to SHELLPOSITION. |
8257 */ | 8257 */ |
8258 if(![window shown]) | 8258 if(![window shown]) |
8259 { | 8259 { |
8260 static int defaultx = 0, defaulty = 0; | 8260 static int defaultx = 0, defaulty = 0; |
8261 int cx = dw_screen_width(), cy = dw_screen_height(); | 8261 int cx = dw_screen_width(), cy = dw_screen_height(); |
8262 int maxx = cx / 4, maxy = cy / 4; | 8262 int maxx = cx / 4, maxy = cy / 4; |
8263 NSPoint point; | 8263 NSPoint point; |
8264 | 8264 |
8265 rect = [window frame]; | 8265 rect = [window frame]; |
8266 | 8266 |
8267 defaultx += 20; | 8267 defaultx += 20; |
8268 defaulty += 20; | 8268 defaulty += 20; |
8269 if(defaultx > maxx) | 8269 if(defaultx > maxx) |
8270 defaultx = 20; | 8270 defaultx = 20; |
8271 if(defaulty > maxy) | 8271 if(defaulty > maxy) |
8272 defaulty = 20; | 8272 defaulty = 20; |
8273 | 8273 |
8274 point.x = defaultx; | 8274 point.x = defaultx; |
8275 /* Take into account menu bar and inverted Y */ | 8275 /* Take into account menu bar and inverted Y */ |
8276 point.y = cy - defaulty - (int)rect.size.height - 22; | 8276 point.y = cy - defaulty - (int)rect.size.height - 22; |
8277 | 8277 |
8278 [window setFrameOrigin:point]; | 8278 [window setFrameOrigin:point]; |
8279 [window setShown:YES]; | 8279 [window setShown:YES]; |
8280 } | 8280 } |
8281 [[window contentView] showWindow]; | 8281 [[window contentView] showWindow]; |
8282 [window makeKeyAndOrderFront:nil]; | 8282 [window makeKeyAndOrderFront:nil]; |
8283 | 8283 |
8284 if(!([window styleMask] & NSResizableWindowMask)) | 8284 if(!([window styleMask] & NSResizableWindowMask)) |
8285 { | 8285 { |
8286 /* Fix incorrect repeat in displaying textured windows */ | 8286 /* Fix incorrect repeat in displaying textured windows */ |
8287 [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge]; | 8287 [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge]; |
8288 [window setContentBorderThickness:0.0 forEdge:NSMinYEdge]; | 8288 [window setContentBorderThickness:0.0 forEdge:NSMinYEdge]; |
8425 | 8425 |
8426 if([object isMemberOfClass:[DWWindow class]]) | 8426 if([object isMemberOfClass:[DWWindow class]]) |
8427 { | 8427 { |
8428 DWWindow *window = object; | 8428 DWWindow *window = object; |
8429 SEL sssm = NSSelectorFromString(@"setStyleMask"); | 8429 SEL sssm = NSSelectorFromString(@"setStyleMask"); |
8430 | 8430 |
8431 if([window respondsToSelector:sssm]) | 8431 if([window respondsToSelector:sssm]) |
8432 { | 8432 { |
8433 IMP issm = [window methodForSelector:sssm]; | 8433 IMP issm = [window methodForSelector:sssm]; |
8434 int currentstyle = (int)[window styleMask]; | 8434 int currentstyle = (int)[window styleMask]; |
8435 int tmp; | 8435 int tmp; |
8436 | 8436 |
8437 tmp = currentstyle | (int)mask; | 8437 tmp = currentstyle | (int)mask; |
8438 tmp ^= mask; | 8438 tmp ^= mask; |
8439 tmp |= style; | 8439 tmp |= style; |
8440 | 8440 |
8441 issm(window, sssm, tmp); | 8441 issm(window, sssm, tmp); |
8442 } | 8442 } |
8443 } | 8443 } |
8444 else if([object isKindOfClass:[NSTextField class]]) | 8444 else if([object isKindOfClass:[NSTextField class]]) |
8445 { | 8445 { |
8500 * This is for use after showing the window/dialog. | 8500 * This is for use after showing the window/dialog. |
8501 */ | 8501 */ |
8502 void API dw_window_set_focus(HWND handle) | 8502 void API dw_window_set_focus(HWND handle) |
8503 { | 8503 { |
8504 id object = handle; | 8504 id object = handle; |
8505 | 8505 |
8506 [[object window] makeFirstResponder:object]; | 8506 [[object window] makeFirstResponder:object]; |
8507 } | 8507 } |
8508 | 8508 |
8509 /* | 8509 /* |
8510 * Sets the default focus item for a window/dialog. | 8510 * Sets the default focus item for a window/dialog. |
8679 { | 8679 { |
8680 /* Find the item within the box it is packed into */ | 8680 /* Find the item within the box it is packed into */ |
8681 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[DWGroupBox class]] || [object isKindOfClass:[NSControl class]]) | 8681 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[DWGroupBox class]] || [object isKindOfClass:[NSControl class]]) |
8682 { | 8682 { |
8683 DWBox *parent = (DWBox *)[object superview]; | 8683 DWBox *parent = (DWBox *)[object superview]; |
8684 | 8684 |
8685 /* Some controls are embedded in scrollviews... | 8685 /* Some controls are embedded in scrollviews... |
8686 * so get the parent of the scrollview in that case. | 8686 * so get the parent of the scrollview in that case. |
8687 */ | 8687 */ |
8688 if([object isKindOfClass:[NSTableView class]] && [parent isMemberOfClass:[NSClipView class]]) | 8688 if([object isKindOfClass:[NSTableView class]] && [parent isMemberOfClass:[NSClipView class]]) |
8689 { | 8689 { |
8690 object = [parent superview]; | 8690 object = [parent superview]; |
8691 parent = (DWBox *)[object superview]; | 8691 parent = (DWBox *)[object superview]; |
8692 } | 8692 } |
8693 | 8693 |
8694 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) | 8694 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) |
8695 { | 8695 { |
8696 Box *thisbox = [parent box]; | 8696 Box *thisbox = [parent box]; |
8697 Item *thisitem = thisbox->items; | 8697 Item *thisitem = thisbox->items; |
8698 int z; | 8698 int z; |
8699 | 8699 |
8700 for(z=0;z<thisbox->count;z++) | 8700 for(z=0;z<thisbox->count;z++) |
8701 { | 8701 { |
8702 if(thisitem[z].hwnd == object) | 8702 if(thisitem[z].hwnd == object) |
8703 return &thisitem[z]; | 8703 return &thisitem[z]; |
8704 } | 8704 } |
8743 } | 8743 } |
8744 else | 8744 else |
8745 return DW_ERROR_UNKNOWN; | 8745 return DW_ERROR_UNKNOWN; |
8746 /* If we changed the text... */ | 8746 /* If we changed the text... */ |
8747 Item *item = _box_item(handle); | 8747 Item *item = _box_item(handle); |
8748 | 8748 |
8749 /* Check to see if any of the sizes need to be recalculated */ | 8749 /* Check to see if any of the sizes need to be recalculated */ |
8750 if(item && (item->origwidth == -1 || item->origheight == -1)) | 8750 if(item && (item->origwidth == -1 || item->origheight == -1)) |
8751 { | 8751 { |
8752 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 8752 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); |
8753 /* Queue a redraw on the top-level window */ | 8753 /* Queue a redraw on the top-level window */ |
8754 _dw_redraw([object window], TRUE); | 8754 _dw_redraw([object window], TRUE); |
8755 } | 8755 } |
8756 return DW_ERROR_NONE; | 8756 return DW_ERROR_NONE; |
8757 } | 8757 } |
8805 } | 8805 } |
8806 /* Handle removing menu items from menus */ | 8806 /* Handle removing menu items from menus */ |
8807 else if([ object isKindOfClass:[NSMenuItem class]]) | 8807 else if([ object isKindOfClass:[NSMenuItem class]]) |
8808 { | 8808 { |
8809 NSMenu *menu = [object menu]; | 8809 NSMenu *menu = [object menu]; |
8810 | 8810 |
8811 [menu removeItem:object]; | 8811 [menu removeItem:object]; |
8812 } | 8812 } |
8813 /* Handle destroying a control or box */ | 8813 /* Handle destroying a control or box */ |
8814 else if([object isKindOfClass:[NSView class]] || [object isKindOfClass:[NSControl class]]) | 8814 else if([object isKindOfClass:[NSView class]] || [object isKindOfClass:[NSControl class]]) |
8815 { | 8815 { |
8832 int z, index = -1; | 8832 int z, index = -1; |
8833 Item *tmpitem = NULL, *thisitem = thisbox->items; | 8833 Item *tmpitem = NULL, *thisitem = thisbox->items; |
8834 | 8834 |
8835 if(!thisitem) | 8835 if(!thisitem) |
8836 thisbox->count = 0; | 8836 thisbox->count = 0; |
8837 | 8837 |
8838 for(z=0;z<thisbox->count;z++) | 8838 for(z=0;z<thisbox->count;z++) |
8839 { | 8839 { |
8840 if(thisitem[z].hwnd == object) | 8840 if(thisitem[z].hwnd == object) |
8841 index = z; | 8841 index = z; |
8842 } | 8842 } |
8851 [object removeFromSuperview]; | 8851 [object removeFromSuperview]; |
8852 | 8852 |
8853 if(thisbox->count > 1) | 8853 if(thisbox->count > 1) |
8854 { | 8854 { |
8855 tmpitem = calloc(sizeof(Item), (thisbox->count-1)); | 8855 tmpitem = calloc(sizeof(Item), (thisbox->count-1)); |
8856 | 8856 |
8857 /* Copy all but the current entry to the new list */ | 8857 /* Copy all but the current entry to the new list */ |
8858 for(z=0;z<index;z++) | 8858 for(z=0;z<index;z++) |
8859 { | 8859 { |
8860 tmpitem[z] = thisitem[z]; | 8860 tmpitem[z] = thisitem[z]; |
8861 } | 8861 } |
8862 for(z=index+1;z<thisbox->count;z++) | 8862 for(z=index+1;z<thisbox->count;z++) |
8863 { | 8863 { |
8864 tmpitem[z-1] = thisitem[z]; | 8864 tmpitem[z-1] = thisitem[z]; |
8865 } | 8865 } |
8866 } | 8866 } |
8867 | 8867 |
8868 thisbox->items = tmpitem; | 8868 thisbox->items = tmpitem; |
8869 if(thisitem) | 8869 if(thisitem) |
8870 free(thisitem); | 8870 free(thisitem); |
8871 if(tmpitem) | 8871 if(tmpitem) |
8872 thisbox->count--; | 8872 thisbox->count--; |
8873 else | 8873 else |
8874 thisbox->count = 0; | 8874 thisbox->count = 0; |
8875 | 8875 |
8876 /* Queue a redraw on the top-level window */ | 8876 /* Queue a redraw on the top-level window */ |
8877 _dw_redraw(window, TRUE); | 8877 _dw_redraw(window, TRUE); |
8878 } | 8878 } |
8879 } | 8879 } |
8880 DW_MUTEX_UNLOCK; | 8880 DW_MUTEX_UNLOCK; |
8934 } | 8934 } |
8935 else | 8935 else |
8936 return; | 8936 return; |
8937 /* If we changed the text... */ | 8937 /* If we changed the text... */ |
8938 Item *item = _box_item(handle); | 8938 Item *item = _box_item(handle); |
8939 | 8939 |
8940 /* Check to see if any of the sizes need to be recalculated */ | 8940 /* Check to see if any of the sizes need to be recalculated */ |
8941 if(item && (item->origwidth == -1 || item->origheight == -1)) | 8941 if(item && (item->origwidth == -1 || item->origheight == -1)) |
8942 { | 8942 { |
8943 int newwidth, newheight; | 8943 int newwidth, newheight; |
8944 | 8944 |
8945 _control_size(handle, &newwidth, &newheight); | 8945 _control_size(handle, &newwidth, &newheight); |
8946 | 8946 |
8947 /* Only update the item and redraw the window if it changed */ | 8947 /* Only update the item and redraw the window if it changed */ |
8948 if((item->origwidth == -1 && item->width != newwidth) || | 8948 if((item->origwidth == -1 && item->width != newwidth) || |
8949 (item->origheight == -1 && item->height != newheight)) | 8949 (item->origheight == -1 && item->height != newheight)) |
8950 { | 8950 { |
8951 if(item->origwidth == -1) | 8951 if(item->origwidth == -1) |
9044 { | 9044 { |
9045 DW_LOCAL_POOL_IN; | 9045 DW_LOCAL_POOL_IN; |
9046 NSImageView *iv = handle; | 9046 NSImageView *iv = handle; |
9047 NSData *thisdata = [NSData dataWithBytes:data length:len]; | 9047 NSData *thisdata = [NSData dataWithBytes:data length:len]; |
9048 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata]; | 9048 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata]; |
9049 | 9049 |
9050 if(pixmap) | 9050 if(pixmap) |
9051 { | 9051 { |
9052 [iv setImage:pixmap]; | 9052 [iv setImage:pixmap]; |
9053 } | 9053 } |
9054 [pixmap release]; | 9054 [pixmap release]; |
9055 /* If we changed the text... */ | 9055 /* If we changed the text... */ |
9056 Item *item = _box_item(handle); | 9056 Item *item = _box_item(handle); |
9057 | 9057 |
9058 /* Check to see if any of the sizes need to be recalculated */ | 9058 /* Check to see if any of the sizes need to be recalculated */ |
9059 if(item && (item->origwidth == -1 || item->origheight == -1)) | 9059 if(item && (item->origwidth == -1 || item->origheight == -1)) |
9060 { | 9060 { |
9061 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 9061 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); |
9062 /* Queue a redraw on the top-level window */ | 9062 /* Queue a redraw on the top-level window */ |
9063 _dw_redraw([iv window], TRUE); | 9063 _dw_redraw([iv window], TRUE); |
9064 } | 9064 } |
9065 DW_LOCAL_POOL_OUT; | 9065 DW_LOCAL_POOL_OUT; |
9066 } | 9066 } |
9081 */ | 9081 */ |
9082 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename) | 9082 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename) |
9083 { | 9083 { |
9084 NSObject *object = handle; | 9084 NSObject *object = handle; |
9085 DW_LOCAL_POOL_IN; | 9085 DW_LOCAL_POOL_IN; |
9086 | 9086 |
9087 if([ object isKindOfClass:[ NSImageView class ] ]) | 9087 if([ object isKindOfClass:[ NSImageView class ] ]) |
9088 { | 9088 { |
9089 NSImageView *iv = handle; | 9089 NSImageView *iv = handle; |
9090 NSImage *bitmap = nil; | 9090 NSImage *bitmap = nil; |
9091 | 9091 |
9202 if([ object isMemberOfClass:[ DWWindow class ] ]) | 9202 if([ object isMemberOfClass:[ DWWindow class ] ]) |
9203 { | 9203 { |
9204 DWWindow *window = handle; | 9204 DWWindow *window = handle; |
9205 Box *thisbox; | 9205 Box *thisbox; |
9206 NSRect content, frame = NSMakeRect(0, 0, width, height); | 9206 NSRect content, frame = NSMakeRect(0, 0, width, height); |
9207 | 9207 |
9208 /* Convert the external frame size to internal content size */ | 9208 /* Convert the external frame size to internal content size */ |
9209 content = [NSWindow contentRectForFrameRect:frame styleMask:[window styleMask]]; | 9209 content = [NSWindow contentRectForFrameRect:frame styleMask:[window styleMask]]; |
9210 | 9210 |
9211 /* | 9211 /* |
9212 * The following is an attempt to dynamically size a window based on the size of its | 9212 * The following is an attempt to dynamically size a window based on the size of its |
9213 * children before realization. Only applicable when width or height is less than one. | 9213 * children before realization. Only applicable when width or height is less than one. |
9214 */ | 9214 */ |
9215 if((width < 1 || height < 1) && (thisbox = [[window contentView] box])) | 9215 if((width < 1 || height < 1) && (thisbox = [[window contentView] box])) |
9216 { | 9216 { |
9217 int depth = 0; | 9217 int depth = 0; |
9218 | 9218 |
9219 /* Calculate space requirements */ | 9219 /* Calculate space requirements */ |
9220 _resize_box(thisbox, &depth, (int)width, (int)height, 1); | 9220 _resize_box(thisbox, &depth, (int)width, (int)height, 1); |
9221 | 9221 |
9222 /* Update components that need auto-sizing */ | 9222 /* Update components that need auto-sizing */ |
9223 if(width < 1) content.size.width = thisbox->minwidth; | 9223 if(width < 1) content.size.width = thisbox->minwidth; |
9224 if(height < 1) content.size.height = thisbox->minheight; | 9224 if(height < 1) content.size.height = thisbox->minheight; |
9225 } | 9225 } |
9226 | 9226 |
9227 /* Finally set the size */ | 9227 /* Finally set the size */ |
9228 [window setContentSize:content.size]; | 9228 [window setContentSize:content.size]; |
9229 } | 9229 } |
9230 DW_MUTEX_UNLOCK; | 9230 DW_MUTEX_UNLOCK; |
9231 } | 9231 } |
9238 * height: Height in pixels of the item or NULL if not needed. | 9238 * height: Height in pixels of the item or NULL if not needed. |
9239 */ | 9239 */ |
9240 void API dw_window_get_preferred_size(HWND handle, int *width, int *height) | 9240 void API dw_window_get_preferred_size(HWND handle, int *width, int *height) |
9241 { | 9241 { |
9242 id object = handle; | 9242 id object = handle; |
9243 | 9243 |
9244 if([object isMemberOfClass:[DWWindow class]]) | 9244 if([object isMemberOfClass:[DWWindow class]]) |
9245 { | 9245 { |
9246 Box *thisbox; | 9246 Box *thisbox; |
9247 | 9247 |
9248 if((thisbox = [[object contentView] box])) | 9248 if((thisbox = [[object contentView] box])) |
9249 { | 9249 { |
9250 int depth = 0; | 9250 int depth = 0; |
9251 NSRect frame; | 9251 NSRect frame; |
9252 | 9252 |
9253 /* Calculate space requirements */ | 9253 /* Calculate space requirements */ |
9254 _resize_box(thisbox, &depth, 0, 0, 1); | 9254 _resize_box(thisbox, &depth, 0, 0, 1); |
9255 | 9255 |
9256 /* Figure out the border size */ | 9256 /* Figure out the border size */ |
9257 frame = [NSWindow frameRectForContentRect:NSMakeRect(0, 0, thisbox->minwidth, thisbox->minheight) styleMask:[object styleMask]]; | 9257 frame = [NSWindow frameRectForContentRect:NSMakeRect(0, 0, thisbox->minwidth, thisbox->minheight) styleMask:[object styleMask]]; |
9258 | 9258 |
9259 /* Return what was requested */ | 9259 /* Return what was requested */ |
9260 if(width) *width = frame.size.width; | 9260 if(width) *width = frame.size.width; |
9261 if(height) *height = frame.size.height; | 9261 if(height) *height = frame.size.height; |
9262 } | 9262 } |
9263 } | 9263 } |
9264 else if([object isMemberOfClass:[DWBox class]]) | 9264 else if([object isMemberOfClass:[DWBox class]]) |
9265 { | 9265 { |
9266 Box *thisbox; | 9266 Box *thisbox; |
9267 | 9267 |
9268 if((thisbox = [object box])) | 9268 if((thisbox = [object box])) |
9269 { | 9269 { |
9270 int depth = 0; | 9270 int depth = 0; |
9271 | 9271 |
9272 /* Calculate space requirements */ | 9272 /* Calculate space requirements */ |
9273 _resize_box(thisbox, &depth, 0, 0, 1); | 9273 _resize_box(thisbox, &depth, 0, 0, 1); |
9274 | 9274 |
9275 /* Return what was requested */ | 9275 /* Return what was requested */ |
9276 if(width) *width = thisbox->minwidth; | 9276 if(width) *width = thisbox->minwidth; |
9277 if(height) *height = thisbox->minheight; | 9277 if(height) *height = thisbox->minheight; |
9278 } | 9278 } |
9279 } | 9279 } |
9299 void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height) | 9299 void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height) |
9300 { | 9300 { |
9301 int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz")); | 9301 int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz")); |
9302 int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert")); | 9302 int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert")); |
9303 id object = handle; | 9303 id object = handle; |
9304 | 9304 |
9305 /* Do any gravity calculations */ | 9305 /* Do any gravity calculations */ |
9306 if(horz || (vert & 0xf) != DW_GRAV_BOTTOM) | 9306 if(horz || (vert & 0xf) != DW_GRAV_BOTTOM) |
9307 { | 9307 { |
9308 long newx = *x, newy = *y; | 9308 long newx = *x, newy = *y; |
9309 | 9309 |
9310 /* Handle horizontal center gravity */ | 9310 /* Handle horizontal center gravity */ |
9311 if((horz & 0xf) == DW_GRAV_CENTER) | 9311 if((horz & 0xf) == DW_GRAV_CENTER) |
9312 newx += ((dw_screen_width() / 2) - (width / 2)); | 9312 newx += ((dw_screen_width() / 2) - (width / 2)); |
9313 /* Handle right gravity */ | 9313 /* Handle right gravity */ |
9314 else if((horz & 0xf) == DW_GRAV_RIGHT) | 9314 else if((horz & 0xf) == DW_GRAV_RIGHT) |
9316 /* Handle vertical center gravity */ | 9316 /* Handle vertical center gravity */ |
9317 if((vert & 0xf) == DW_GRAV_CENTER) | 9317 if((vert & 0xf) == DW_GRAV_CENTER) |
9318 newy += ((dw_screen_height() / 2) - (height / 2)); | 9318 newy += ((dw_screen_height() / 2) - (height / 2)); |
9319 else if((vert & 0xf) == DW_GRAV_TOP) | 9319 else if((vert & 0xf) == DW_GRAV_TOP) |
9320 newy = dw_screen_height() - height - *y; | 9320 newy = dw_screen_height() - height - *y; |
9321 | 9321 |
9322 /* Save the new values */ | 9322 /* Save the new values */ |
9323 *x = newx; | 9323 *x = newx; |
9324 *y = newy; | 9324 *y = newy; |
9325 } | 9325 } |
9326 /* Adjust the values to avoid Dock/Menubar if requested */ | 9326 /* Adjust the values to avoid Dock/Menubar if requested */ |
9327 if((horz | vert) & DW_GRAV_OBSTACLES) | 9327 if((horz | vert) & DW_GRAV_OBSTACLES) |
9328 { | 9328 { |
9329 NSRect visiblerect = [[object screen] visibleFrame]; | 9329 NSRect visiblerect = [[object screen] visibleFrame]; |
9330 NSRect totalrect = [[object screen] frame]; | 9330 NSRect totalrect = [[object screen] frame]; |
9331 | 9331 |
9332 if(horz & DW_GRAV_OBSTACLES) | 9332 if(horz & DW_GRAV_OBSTACLES) |
9333 { | 9333 { |
9334 if((horz & 0xf) == DW_GRAV_LEFT) | 9334 if((horz & 0xf) == DW_GRAV_LEFT) |
9335 *x += visiblerect.origin.x; | 9335 *x += visiblerect.origin.x; |
9336 else if((horz & 0xf) == DW_GRAV_RIGHT) | 9336 else if((horz & 0xf) == DW_GRAV_RIGHT) |
9356 void API dw_window_set_pos(HWND handle, LONG x, LONG y) | 9356 void API dw_window_set_pos(HWND handle, LONG x, LONG y) |
9357 { | 9357 { |
9358 int _locked_by_me = FALSE; | 9358 int _locked_by_me = FALSE; |
9359 DW_MUTEX_LOCK; | 9359 DW_MUTEX_LOCK; |
9360 NSObject *object = handle; | 9360 NSObject *object = handle; |
9361 | 9361 |
9362 if([ object isMemberOfClass:[ DWWindow class ] ]) | 9362 if([ object isMemberOfClass:[ DWWindow class ] ]) |
9363 { | 9363 { |
9364 DWWindow *window = handle; | 9364 DWWindow *window = handle; |
9365 NSPoint point; | 9365 NSPoint point; |
9366 NSSize size = [[window contentView] frame].size; | 9366 NSSize size = [[window contentView] frame].size; |
9372 dw_window_set_size(handle, 0, 0); | 9372 dw_window_set_size(handle, 0, 0); |
9373 } | 9373 } |
9374 | 9374 |
9375 size = [window frame].size; | 9375 size = [window frame].size; |
9376 _handle_gravity(handle, &x, &y, (unsigned long)size.width, (unsigned long)size.height); | 9376 _handle_gravity(handle, &x, &y, (unsigned long)size.width, (unsigned long)size.height); |
9377 | 9377 |
9378 point.x = x; | 9378 point.x = x; |
9379 point.y = y; | 9379 point.y = y; |
9380 | 9380 |
9381 [window setFrameOrigin:point]; | 9381 [window setFrameOrigin:point]; |
9382 /* Position set manually... don't auto-position */ | 9382 /* Position set manually... don't auto-position */ |
9383 [window setShown:YES]; | 9383 [window setShown:YES]; |
9384 } | 9384 } |
9385 DW_MUTEX_UNLOCK; | 9385 DW_MUTEX_UNLOCK; |
9555 if (!*root) | 9555 if (!*root) |
9556 *root = new; | 9556 *root = new; |
9557 else | 9557 else |
9558 { | 9558 { |
9559 UserData *prev = *root, *tmp = prev->next; | 9559 UserData *prev = *root, *tmp = prev->next; |
9560 | 9560 |
9561 while(tmp) | 9561 while(tmp) |
9562 { | 9562 { |
9563 prev = tmp; | 9563 prev = tmp; |
9564 tmp = tmp->next; | 9564 tmp = tmp->next; |
9565 } | 9565 } |
10116 * eve: The handle to the event returned by dw_event_new(). | 10116 * eve: The handle to the event returned by dw_event_new(). |
10117 */ | 10117 */ |
10118 int dw_event_wait(HEV eve, unsigned long timeout) | 10118 int dw_event_wait(HEV eve, unsigned long timeout) |
10119 { | 10119 { |
10120 int rc; | 10120 int rc; |
10121 | 10121 |
10122 if(!eve) | 10122 if(!eve) |
10123 return DW_ERROR_NON_INIT; | 10123 return DW_ERROR_NON_INIT; |
10124 | 10124 |
10125 pthread_mutex_lock (&(eve->mutex)); | 10125 pthread_mutex_lock (&(eve->mutex)); |
10126 | 10126 |
10127 if(eve->posted) | 10127 if(eve->posted) |
10128 { | 10128 { |
10129 pthread_mutex_unlock (&(eve->mutex)); | 10129 pthread_mutex_unlock (&(eve->mutex)); |
10130 return DW_ERROR_NONE; | 10130 return DW_ERROR_NONE; |
10131 } | 10131 } |
10132 | 10132 |
10133 if(timeout != -1) | 10133 if(timeout != -1) |
10134 { | 10134 { |
10135 struct timeval now; | 10135 struct timeval now; |
10136 struct timespec timeo; | 10136 struct timespec timeo; |
10137 | 10137 |
10138 gettimeofday(&now, 0); | 10138 gettimeofday(&now, 0); |
10139 timeo.tv_sec = now.tv_sec + (timeout / 1000); | 10139 timeo.tv_sec = now.tv_sec + (timeout / 1000); |
10140 timeo.tv_nsec = now.tv_usec * 1000; | 10140 timeo.tv_nsec = now.tv_usec * 1000; |
10141 rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo); | 10141 rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo); |
10142 } | 10142 } |
10591 * False if there is already a message loop running. | 10591 * False if there is already a message loop running. |
10592 */ | 10592 */ |
10593 int API dw_init(int newthread, int argc, char *argv[]) | 10593 int API dw_init(int newthread, int argc, char *argv[]) |
10594 { | 10594 { |
10595 char *lang = getenv("LANG"); | 10595 char *lang = getenv("LANG"); |
10596 | 10596 |
10597 /* Correct the startup path if run from a bundle */ | 10597 /* Correct the startup path if run from a bundle */ |
10598 if(argc > 0 && argv[0]) | 10598 if(argc > 0 && argv[0]) |
10599 { | 10599 { |
10600 char *pathcopy = strdup(argv[0]); | 10600 char *pathcopy = strdup(argv[0]); |
10601 char *app = strstr(pathcopy, ".app/"); | 10601 char *app = strstr(pathcopy, ".app/"); |
10602 | 10602 |
10603 if(app) | 10603 if(app) |
10604 { | 10604 { |
10605 char pathbuf[PATH_MAX+1] = { 0 }; | 10605 char pathbuf[PATH_MAX+1] = { 0 }; |
10606 size_t len = (size_t)(app - pathcopy); | 10606 size_t len = (size_t)(app - pathcopy); |
10607 | 10607 |
10608 if(len > 0) | 10608 if(len > 0) |
10609 strncpy(_dw_bundle_path, pathcopy, len + 4); | 10609 strncpy(_dw_bundle_path, pathcopy, len + 4); |
10610 *app = 0; | 10610 *app = 0; |
10611 | 10611 |
10612 getcwd(pathbuf, PATH_MAX); | 10612 getcwd(pathbuf, PATH_MAX); |
10624 } | 10624 } |
10625 } | 10625 } |
10626 if(pathcopy) | 10626 if(pathcopy) |
10627 free(pathcopy); | 10627 free(pathcopy); |
10628 } | 10628 } |
10629 | 10629 |
10630 /* Just in case we can't obtain a path */ | 10630 /* Just in case we can't obtain a path */ |
10631 if(!_dw_bundle_path[0]) | 10631 if(!_dw_bundle_path[0]) |
10632 getcwd(_dw_bundle_path, PATH_MAX); | 10632 getcwd(_dw_bundle_path, PATH_MAX); |
10633 | 10633 |
10634 /* Get the operating system version */ | 10634 /* Get the operating system version */ |
10635 NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString]; | 10635 NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString]; |
10636 const char *versionstr = [version UTF8String]; | 10636 const char *versionstr = [version UTF8String]; |
10637 sscanf(versionstr, "Version %d.%d.%d", &DWOSMajor, &DWOSMinor, &DWOSBuild); | 10637 sscanf(versionstr, "Version %d.%d.%d", &DWOSMajor, &DWOSMinor, &DWOSBuild); |
10638 /* Set the locale... if it is UTF-8 pass it | 10638 /* Set the locale... if it is UTF-8 pass it |
10639 * directly, otherwise specify UTF-8 explicitly. | 10639 * directly, otherwise specify UTF-8 explicitly. |
10640 */ | 10640 */ |
10641 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8"); | 10641 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8"); |
10642 /* Create the application object */ | 10642 /* Create the application object */ |
10643 DWApp = [NSApplication sharedApplication]; | 10643 DWApp = [NSApplication sharedApplication]; |
10895 NSURL *myurl = [NSURL URLWithString:[NSString stringWithUTF8String:url]]; | 10895 NSURL *myurl = [NSURL URLWithString:[NSString stringWithUTF8String:url]]; |
10896 [[NSWorkspace sharedWorkspace] openURL:myurl]; | 10896 [[NSWorkspace sharedWorkspace] openURL:myurl]; |
10897 return DW_ERROR_NONE; | 10897 return DW_ERROR_NONE; |
10898 } | 10898 } |
10899 | 10899 |
10900 typedef struct _dwprint | 10900 typedef struct _dwprint |
10901 { | 10901 { |
10902 NSPrintInfo *pi; | 10902 NSPrintInfo *pi; |
10903 int (*drawfunc)(HPRINT, HPIXMAP, int, void *); | 10903 int (*drawfunc)(HPRINT, HPIXMAP, int, void *); |
10904 void *drawdata; | 10904 void *drawdata; |
10905 unsigned long flags; | 10905 unsigned long flags; |
10920 { | 10920 { |
10921 DWPrint *print; | 10921 DWPrint *print; |
10922 NSPrintPanel *panel; | 10922 NSPrintPanel *panel; |
10923 PMPrintSettings settings; | 10923 PMPrintSettings settings; |
10924 NSPrintInfo *pi; | 10924 NSPrintInfo *pi; |
10925 | 10925 |
10926 if(!drawfunc || !(print = calloc(1, sizeof(DWPrint)))) | 10926 if(!drawfunc || !(print = calloc(1, sizeof(DWPrint)))) |
10927 { | 10927 { |
10928 return NULL; | 10928 return NULL; |
10929 } | 10929 } |
10930 | 10930 |
10931 if(!jobname) | 10931 if(!jobname) |
10932 jobname = "Dynamic Windows Print Job"; | 10932 jobname = "Dynamic Windows Print Job"; |
10933 | 10933 |
10934 print->drawfunc = drawfunc; | 10934 print->drawfunc = drawfunc; |
10935 print->drawdata = drawdata; | 10935 print->drawdata = drawdata; |
10936 print->flags = flags; | 10936 print->flags = flags; |
10937 | 10937 |
10938 /* Get the page range */ | 10938 /* Get the page range */ |
10939 pi = [NSPrintInfo sharedPrintInfo]; | 10939 pi = [NSPrintInfo sharedPrintInfo]; |
10940 [pi setHorizontalPagination:NSFitPagination]; | 10940 [pi setHorizontalPagination:NSFitPagination]; |
10941 [pi setHorizontallyCentered:YES]; | 10941 [pi setHorizontallyCentered:YES]; |
10942 [pi setVerticalPagination:NSFitPagination]; | 10942 [pi setVerticalPagination:NSFitPagination]; |
10943 [pi setVerticallyCentered:YES]; | 10943 [pi setVerticallyCentered:YES]; |
10944 [pi setOrientation:NSPortraitOrientation]; | 10944 [pi setOrientation:NSPortraitOrientation]; |
10945 [pi setLeftMargin:0.0]; | 10945 [pi setLeftMargin:0.0]; |
10946 [pi setRightMargin:0.0]; | 10946 [pi setRightMargin:0.0]; |
10947 [pi setTopMargin:0.0]; | 10947 [pi setTopMargin:0.0]; |
10948 [pi setBottomMargin:0.0]; | 10948 [pi setBottomMargin:0.0]; |
10949 | 10949 |
10950 settings = [pi PMPrintSettings]; | 10950 settings = [pi PMPrintSettings]; |
10951 PMSetPageRange(settings, 1, pages); | 10951 PMSetPageRange(settings, 1, pages); |
10952 PMSetFirstPage(settings, 1, true); | 10952 PMSetFirstPage(settings, 1, true); |
10953 PMSetLastPage(settings, pages, true); | 10953 PMSetLastPage(settings, pages, true); |
10954 PMPrintSettingsSetJobName(settings, (CFStringRef)[NSString stringWithUTF8String:jobname]); | 10954 PMPrintSettingsSetJobName(settings, (CFStringRef)[NSString stringWithUTF8String:jobname]); |
10955 [pi updateFromPMPrintSettings]; | 10955 [pi updateFromPMPrintSettings]; |
10956 | 10956 |
10957 /* Create and show the print panel */ | 10957 /* Create and show the print panel */ |
10958 panel = [NSPrintPanel printPanel]; | 10958 panel = [NSPrintPanel printPanel]; |
10959 if(!panel || [panel runModalWithPrintInfo:pi] == NSCancelButton) | 10959 if(!panel || [panel runModalWithPrintInfo:pi] == NSCancelButton) |
10960 { | 10960 { |
10961 free(print); | 10961 free(print); |
10962 return NULL; | 10962 return NULL; |
10963 } | 10963 } |
10964 /* Put the print info from the panel into the operation */ | 10964 /* Put the print info from the panel into the operation */ |
10965 print->pi = pi; | 10965 print->pi = pi; |
10966 | 10966 |
10967 return print; | 10967 return print; |
10968 } | 10968 } |
10969 | 10969 |
10970 /* | 10970 /* |
10971 * Runs the print job, causing the draw page callbacks to fire. | 10971 * Runs the print job, causing the draw page callbacks to fire. |
10972 * Parameters: | 10972 * Parameters: |
10973 * print: Handle to the print object returned by dw_print_new(). | 10973 * print: Handle to the print object returned by dw_print_new(). |
10974 * flags: Flags to run the print job. | 10974 * flags: Flags to run the print job. |
10975 * Returns: | 10975 * Returns: |
10986 NSImageView *iv; | 10986 NSImageView *iv; |
10987 NSSize size; | 10987 NSSize size; |
10988 PMPrintSettings settings; | 10988 PMPrintSettings settings; |
10989 int x, result = DW_ERROR_UNKNOWN; | 10989 int x, result = DW_ERROR_UNKNOWN; |
10990 UInt32 start, end; | 10990 UInt32 start, end; |
10991 | 10991 |
10992 if(!p) | 10992 if(!p) |
10993 return result; | 10993 return result; |
10994 | 10994 |
10995 DW_LOCAL_POOL_IN; | 10995 DW_LOCAL_POOL_IN; |
10996 | 10996 |
10997 /* Figure out the printer/paper size */ | 10997 /* Figure out the printer/paper size */ |
10998 pi = p->pi; | 10998 pi = p->pi; |
10999 size = [pi paperSize]; | 10999 size = [pi paperSize]; |
11000 | 11000 |
11001 /* Get the page range */ | 11001 /* Get the page range */ |
11006 PMGetLastPage(settings, &end); | 11006 PMGetLastPage(settings, &end); |
11007 PMSetPageRange(settings, 1, 1); | 11007 PMSetPageRange(settings, 1, 1); |
11008 PMSetFirstPage(settings, 1, true); | 11008 PMSetFirstPage(settings, 1, true); |
11009 PMSetLastPage(settings, 1, true); | 11009 PMSetLastPage(settings, 1, true); |
11010 [pi updateFromPMPrintSettings]; | 11010 [pi updateFromPMPrintSettings]; |
11011 | 11011 |
11012 /* Create an image view to print and a pixmap to draw into */ | 11012 /* Create an image view to print and a pixmap to draw into */ |
11013 iv = [[NSImageView alloc] init]; | 11013 iv = [[NSImageView alloc] init]; |
11014 pixmap = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8); | 11014 pixmap = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8); |
11015 rep = pixmap->image; | 11015 rep = pixmap->image; |
11016 pixmap2 = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8); | 11016 pixmap2 = dw_pixmap_new(iv, (int)size.width, (int)size.height, 8); |
11017 rep2 = pixmap2->image; | 11017 rep2 = pixmap2->image; |
11018 | 11018 |
11019 /* Create an image with the data from the pixmap | 11019 /* Create an image with the data from the pixmap |
11020 * to go into the image view. | 11020 * to go into the image view. |
11021 */ | 11021 */ |
11022 image = [[NSImage alloc] initWithSize:[rep size]]; | 11022 image = [[NSImage alloc] initWithSize:[rep size]]; |
11023 flipped = [[NSImage alloc] initWithSize:[rep size]]; | 11023 flipped = [[NSImage alloc] initWithSize:[rep size]]; |
11024 [image addRepresentation:rep]; | 11024 [image addRepresentation:rep]; |
11025 [flipped addRepresentation:rep2]; | 11025 [flipped addRepresentation:rep2]; |
11026 [iv setImage:flipped]; | 11026 [iv setImage:flipped]; |
11027 [iv setImageScaling:NSScaleProportionally]; | 11027 [iv setImageScaling:NSScaleProportionally]; |
11028 [iv setFrameOrigin:NSMakePoint(0,0)]; | 11028 [iv setFrameOrigin:NSMakePoint(0,0)]; |
11029 [iv setFrameSize:size]; | 11029 [iv setFrameSize:size]; |
11030 | 11030 |
11031 /* Create the print operation using the image view and | 11031 /* Create the print operation using the image view and |
11032 * print info obtained from the panel in the last call. | 11032 * print info obtained from the panel in the last call. |
11033 */ | 11033 */ |
11034 po = [NSPrintOperation printOperationWithView:iv printInfo:pi]; | 11034 po = [NSPrintOperation printOperationWithView:iv printInfo:pi]; |
11035 [po setShowsPrintPanel:NO]; | 11035 [po setShowsPrintPanel:NO]; |
11036 | 11036 |
11037 /* Cycle through each page */ | 11037 /* Cycle through each page */ |
11038 for(x=start; x<end && p->drawfunc; x++) | 11038 for(x=start; x<end && p->drawfunc; x++) |
11039 { | 11039 { |
11040 /* Call the application's draw function */ | 11040 /* Call the application's draw function */ |
11041 p->drawfunc(print, pixmap, x, p->drawdata); | 11041 p->drawfunc(print, pixmap, x, p->drawdata); |
11074 * print: Handle to the print object returned by dw_print_new(). | 11074 * print: Handle to the print object returned by dw_print_new(). |
11075 */ | 11075 */ |
11076 void API dw_print_cancel(HPRINT print) | 11076 void API dw_print_cancel(HPRINT print) |
11077 { | 11077 { |
11078 DWPrint *p = print; | 11078 DWPrint *p = print; |
11079 | 11079 |
11080 if(p) | 11080 if(p) |
11081 p->drawfunc = NULL; | 11081 p->drawfunc = NULL; |
11082 } | 11082 } |
11083 | 11083 |
11084 /* | 11084 /* |