Mercurial > dwindows
comparison mac/dw.m @ 653:36c6669422d2
Continuing to add types... looking to almost be usable. :)
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 23 Feb 2011 15:40:46 +0000 |
parents | ef0f484c6c4b |
children | 80e253df49fd |
comparison
equal
deleted
inserted
replaced
652:ef0f484c6c4b | 653:36c6669422d2 |
---|---|
52 SignalHandler *handler = _get_handler(object, message); | 52 SignalHandler *handler = _get_handler(object, message); |
53 NSLog(@"Event handler\n"); | 53 NSLog(@"Event handler\n"); |
54 | 54 |
55 if(handler) | 55 if(handler) |
56 { | 56 { |
57 if(message == 3 || message == 4) | 57 switch(message) |
58 { | 58 { |
59 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; | 59 case 3: |
60 int flags = [object pressedMouseButtons]; | 60 case 4: |
61 NSPoint point = [object mouseLocation]; | 61 { |
62 int button = 0; | 62 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; |
63 char *which = "pressed"; | 63 int flags = [object pressedMouseButtons]; |
64 NSPoint point = [object mouseLocation]; | |
65 int button = 0; | |
66 char *which = "pressed"; | |
64 | 67 |
65 if(message == 4) | 68 if(message == 4) |
69 { | |
70 which = "released"; | |
71 } | |
72 | |
73 if(flags & 1) | |
74 { | |
75 button = 1; | |
76 } | |
77 else if(flags & (1 << 1)) | |
78 { | |
79 button = 2; | |
80 } | |
81 else if(flags & (1 << 2)) | |
82 { | |
83 button = 3; | |
84 } | |
85 | |
86 NSLog(@"Button %s x:%d y:%d button:%d\n", which, (int)point.x, (int)point.y, (int)button); | |
87 return buttonfunc(object, point.x, point.y, button, handler->data); | |
88 } | |
89 case 6: | |
66 { | 90 { |
67 which = "released"; | 91 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
92 NSLog(@"Close\n"); | |
93 return closefunc(object, handler->data); | |
68 } | 94 } |
95 case 7: | |
96 { | |
97 DWExpose exp; | |
98 int (* API exposefunc)(HWND, DWExpose *, void *) = (int (* API)(HWND, DWExpose *, void *))handler->signalfunction; | |
99 NSRect rect = [object frame]; | |
69 | 100 |
70 if(flags & 1) | 101 exp.x = rect.origin.x; |
102 exp.y = rect.origin.y; | |
103 exp.width = rect.size.width; | |
104 exp.height = rect.size.height; | |
105 return exposefunc(object, &exp, handler->data); | |
106 } | |
107 case 8: | |
71 { | 108 { |
72 button = 1; | 109 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
110 | |
111 NSLog(@"Clicked\n"); | |
112 return clickfunc(object, handler->data); | |
73 } | 113 } |
74 else if(flags & (1 << 1)) | |
75 { | |
76 button = 2; | |
77 } | |
78 else if(flags & (1 << 2)) | |
79 { | |
80 button = 3; | |
81 } | |
82 | |
83 NSLog(@"Button %s x:%d y:%d button:%d\n", which, (int)point.x, (int)point.y, (int)button); | |
84 return buttonfunc(object, point.x, point.y, button, handler->data); | |
85 } | 114 } |
86 else if(message == 7) | 115 } |
87 { | 116 return -1; |
88 DWExpose exp; | |
89 int (* API exposefunc)(HWND, DWExpose *, void *) = (int (* API)(HWND, DWExpose *, void *))handler->signalfunction; | |
90 NSRect rect = [object frame]; | |
91 | |
92 exp.x = rect.origin.x; | |
93 exp.y = rect.origin.y; | |
94 exp.width = rect.size.width; | |
95 exp.height = rect.size.height; | |
96 return exposefunc(object, &exp, handler->data); | |
97 } | |
98 else if(message == 8) | |
99 { | |
100 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; | |
101 | |
102 NSLog(@"Clicked\n"); | |
103 return clickfunc(object, handler->data); | |
104 } | |
105 } | |
106 return 0; | |
107 } | 117 } |
108 | 118 |
109 /* So basically to implement our event handlers... | 119 /* So basically to implement our event handlers... |
110 * it looks like we are going to have to subclass | 120 * it looks like we are going to have to subclass |
111 * basically everything. Was hoping to add methods | 121 * basically everything. Was hoping to add methods |
149 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 159 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
150 @end | 160 @end |
151 | 161 |
152 /* Subclass for a top-level window */ | 162 /* Subclass for a top-level window */ |
153 @interface DWView : DWBox { } | 163 @interface DWView : DWBox { } |
164 -(BOOL)windowShouldClose:(id)sender; | |
154 @end | 165 @end |
155 | 166 |
156 @implementation DWView | 167 @implementation DWView |
157 -(void)windowWillClose:(NSNotification *)note | 168 -(BOOL)windowShouldClose:(id)sender |
158 { | 169 { |
159 [[NSApplication sharedApplication] terminate:self]; | 170 if(_event_handler(self, nil, 6) == FALSE) |
171 return NO; | |
172 return YES; | |
160 } | 173 } |
161 - (void)viewDidMoveToWindow | 174 - (void)viewDidMoveToWindow |
162 { | 175 { |
163 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]]; | 176 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]]; |
164 } | 177 } |
320 NSSize size = [view frame].size; | 333 NSSize size = [view frame].size; |
321 _do_resize(&box, size.width, size.height); | 334 _do_resize(&box, size.width, size.height); |
322 } | 335 } |
323 } | 336 } |
324 } | 337 } |
338 @end | |
339 | |
340 /* Subclass for a slider type */ | |
341 @interface DWSlider : NSSlider | |
342 { | |
343 void *userdata; | |
344 } | |
345 -(void *)userdata; | |
346 -(void)setUserdata:(void *)input; | |
347 @end | |
348 | |
349 @implementation DWSlider | |
350 -(void *)userdata { return userdata; } | |
351 -(void)setUserdata:(void *)input { userdata = input; } | |
352 @end | |
353 | |
354 /* Subclass for a slider type */ | |
355 @interface DWScrollbar : NSScroller | |
356 { | |
357 void *userdata; | |
358 float range; | |
359 float visible; | |
360 } | |
361 -(void *)userdata; | |
362 -(void)setUserdata:(void *)input; | |
363 -(float)range; | |
364 -(float)visible; | |
365 -(void)setRange:(float)input1 andVisible:(float)input2; | |
366 @end | |
367 | |
368 @implementation DWScrollbar | |
369 -(void *)userdata { return userdata; } | |
370 -(void)setUserdata:(void *)input { userdata = input; } | |
371 -(float)range { return range; } | |
372 -(float)visible { return visible; } | |
373 -(void)setRange:(float)input1 andVisible:(float)input2 { range = input1; visible = input2; } | |
374 @end | |
375 | |
376 /* Subclass for a render area type */ | |
377 @interface DWRender : NSView | |
378 { | |
379 void *userdata; | |
380 } | |
381 -(void *)userdata; | |
382 -(void)setUserdata:(void *)input; | |
383 -(void)drawRect:(NSRect)rect; | |
384 -(BOOL)isFlipped; | |
385 @end | |
386 | |
387 @implementation DWRender | |
388 -(void *)userdata { return userdata; } | |
389 -(void)setUserdata:(void *)input { userdata = input; } | |
390 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } | |
391 -(BOOL)isFlipped { return YES; } | |
392 @end | |
393 | |
394 /* Subclass for a MLE type */ | |
395 @interface DWMLE : NSTextView | |
396 { | |
397 void *userdata; | |
398 } | |
399 -(void *)userdata; | |
400 -(void)setUserdata:(void *)input; | |
401 @end | |
402 | |
403 @implementation DWMLE | |
404 -(void *)userdata { return userdata; } | |
405 -(void)setUserdata:(void *)input { userdata = input; } | |
325 @end | 406 @end |
326 | 407 |
327 NSApplication *DWApp; | 408 NSApplication *DWApp; |
328 NSRunLoop *DWRunLoop; | 409 NSRunLoop *DWRunLoop; |
329 #if !defined(GARBAGE_COLLECT) | 410 #if !defined(GARBAGE_COLLECT) |
1442 * id: An ID to be used with dw_window_from_id() or 0L. | 1523 * id: An ID to be used with dw_window_from_id() or 0L. |
1443 */ | 1524 */ |
1444 HWND API dw_button_new(char *text, ULONG id) | 1525 HWND API dw_button_new(char *text, ULONG id) |
1445 { | 1526 { |
1446 DWButton *button = [[DWButton alloc] init]; | 1527 DWButton *button = [[DWButton alloc] init]; |
1447 [button setTitle:[ NSString stringWithUTF8String:text ]]; | 1528 if(text && *text) |
1529 { | |
1530 [button setTitle:[ NSString stringWithUTF8String:text ]]; | |
1531 } | |
1448 [button setButtonType:NSMomentaryPushInButton]; | 1532 [button setButtonType:NSMomentaryPushInButton]; |
1449 [button setBezelStyle:NSThickerSquareBezelStyle]; | 1533 [button setBezelStyle:NSThickerSquareBezelStyle]; |
1450 [button setTarget:button]; | 1534 [button setTarget:button]; |
1451 [button setAction:@selector(buttonClicked:)]; | 1535 [button setAction:@selector(buttonClicked:)]; |
1452 /*[button setGradientType:NSGradientConvexWeak];*/ | 1536 /*[button setGradientType:NSGradientConvexWeak];*/ |
1514 * DW pick the appropriate file extension. | 1598 * DW pick the appropriate file extension. |
1515 * (BMP on OS/2 or Windows, XPM on Unix) | 1599 * (BMP on OS/2 or Windows, XPM on Unix) |
1516 */ | 1600 */ |
1517 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) | 1601 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) |
1518 { | 1602 { |
1519 NSLog(@"dw_bitmapbutton_new_from_file() unimplemented\n"); | 1603 NSImage *image = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; |
1520 return HWND_DESKTOP; | 1604 DWButton *button = dw_button_new("", id); |
1605 [button setImage:image]; | |
1606 return button; | |
1521 } | 1607 } |
1522 | 1608 |
1523 /* | 1609 /* |
1524 * Create a new bitmap button window (widget) to be packed from data. | 1610 * Create a new bitmap button window (widget) to be packed from data. |
1525 * Parameters: | 1611 * Parameters: |
1529 * (BMP or ICO on OS/2 or Windows, XPM on Unix) | 1615 * (BMP or ICO on OS/2 or Windows, XPM on Unix) |
1530 * len: length of str | 1616 * len: length of str |
1531 */ | 1617 */ |
1532 HWND API dw_bitmapbutton_new_from_data(char *text, unsigned long id, char *data, int len) | 1618 HWND API dw_bitmapbutton_new_from_data(char *text, unsigned long id, char *data, int len) |
1533 { | 1619 { |
1534 NSLog(@"dw_bitmapbutton_new_from_data() unimplemented\n"); | 1620 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; |
1535 return HWND_DESKTOP; | 1621 NSImage *image = [[NSImage alloc] initWithData:thisdata]; |
1622 DWButton *button = dw_button_new("", id); | |
1623 [button setImage:image]; | |
1624 return button; | |
1536 } | 1625 } |
1537 | 1626 |
1538 /* | 1627 /* |
1539 * Create a new spinbutton window (widget) to be packed. | 1628 * Create a new spinbutton window (widget) to be packed. |
1540 * Parameters: | 1629 * Parameters: |
1601 * increments: Number of increments available. | 1690 * increments: Number of increments available. |
1602 * id: An ID to be used with dw_window_from_id() or 0L. | 1691 * id: An ID to be used with dw_window_from_id() or 0L. |
1603 */ | 1692 */ |
1604 HWND API dw_slider_new(int vertical, int increments, ULONG id) | 1693 HWND API dw_slider_new(int vertical, int increments, ULONG id) |
1605 { | 1694 { |
1606 NSLog(@"dw_slider_new() unimplemented\n"); | 1695 DWSlider *slider = [[DWSlider alloc] init]; |
1607 return HWND_DESKTOP; | 1696 [slider setMaxValue:(double)increments]; |
1697 [slider setMinValue:0]; | |
1698 return slider; | |
1608 } | 1699 } |
1609 | 1700 |
1610 /* | 1701 /* |
1611 * Returns the position of the slider. | 1702 * Returns the position of the slider. |
1612 * Parameters: | 1703 * Parameters: |
1613 * handle: Handle to the slider to be queried. | 1704 * handle: Handle to the slider to be queried. |
1614 */ | 1705 */ |
1615 unsigned int API dw_slider_get_pos(HWND handle) | 1706 unsigned int API dw_slider_get_pos(HWND handle) |
1616 { | 1707 { |
1617 NSLog(@"dw_slider_get_pos() unimplemented\n"); | 1708 DWSlider *slider = handle; |
1618 return 0; | 1709 double val = [slider doubleValue]; |
1710 return (int)val; | |
1619 } | 1711 } |
1620 | 1712 |
1621 /* | 1713 /* |
1622 * Sets the slider position. | 1714 * Sets the slider position. |
1623 * Parameters: | 1715 * Parameters: |
1624 * handle: Handle to the slider to be set. | 1716 * handle: Handle to the slider to be set. |
1625 * position: Position of the slider withing the range. | 1717 * position: Position of the slider withing the range. |
1626 */ | 1718 */ |
1627 void API dw_slider_set_pos(HWND handle, unsigned int position) | 1719 void API dw_slider_set_pos(HWND handle, unsigned int position) |
1628 { | 1720 { |
1629 NSLog(@"dw_slider_set_pos() unimplemented\n"); | 1721 DWSlider *slider = handle; |
1722 [slider setDoubleValue:(double)position]; | |
1630 } | 1723 } |
1631 | 1724 |
1632 /* | 1725 /* |
1633 * Create a new scrollbar window (widget) to be packed. | 1726 * Create a new scrollbar window (widget) to be packed. |
1634 * Parameters: | 1727 * Parameters: |
1636 * increments: Number of increments available. | 1729 * increments: Number of increments available. |
1637 * id: An ID to be used with dw_window_from_id() or 0L. | 1730 * id: An ID to be used with dw_window_from_id() or 0L. |
1638 */ | 1731 */ |
1639 HWND API dw_scrollbar_new(int vertical, ULONG id) | 1732 HWND API dw_scrollbar_new(int vertical, ULONG id) |
1640 { | 1733 { |
1641 NSLog(@"dw_scrollbar_new() unimplemented\n"); | 1734 DWScrollbar *scrollbar = [[DWScrollbar alloc] init]; |
1642 return HWND_DESKTOP; | 1735 return scrollbar; |
1643 } | 1736 } |
1644 | 1737 |
1645 /* | 1738 /* |
1646 * Returns the position of the scrollbar. | 1739 * Returns the position of the scrollbar. |
1647 * Parameters: | 1740 * Parameters: |
1648 * handle: Handle to the scrollbar to be queried. | 1741 * handle: Handle to the scrollbar to be queried. |
1649 */ | 1742 */ |
1650 unsigned int API dw_scrollbar_get_pos(HWND handle) | 1743 unsigned int API dw_scrollbar_get_pos(HWND handle) |
1651 { | 1744 { |
1652 NSLog(@"dw_scrollbar_get_pos() unimplemented\n"); | 1745 DWScrollbar *scrollbar = handle; |
1653 return 0; | 1746 float range = [scrollbar range]; |
1747 float fresult = [scrollbar doubleValue] * range; | |
1748 return (int)fresult; | |
1654 } | 1749 } |
1655 | 1750 |
1656 /* | 1751 /* |
1657 * Sets the scrollbar position. | 1752 * Sets the scrollbar position. |
1658 * Parameters: | 1753 * Parameters: |
1659 * handle: Handle to the scrollbar to be set. | 1754 * handle: Handle to the scrollbar to be set. |
1660 * position: Position of the scrollbar withing the range. | 1755 * position: Position of the scrollbar withing the range. |
1661 */ | 1756 */ |
1662 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) | 1757 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) |
1663 { | 1758 { |
1664 NSLog(@"dw_scrollbar_set_pos() unimplemented\n"); | 1759 DWScrollbar *scrollbar = handle; |
1760 double range = (double)[scrollbar range]; | |
1761 double newpos = (double)position/range; | |
1762 [scrollbar setDoubleValue:newpos]; | |
1665 } | 1763 } |
1666 | 1764 |
1667 /* | 1765 /* |
1668 * Sets the scrollbar range. | 1766 * Sets the scrollbar range. |
1669 * Parameters: | 1767 * Parameters: |
1671 * range: Maximum range value. | 1769 * range: Maximum range value. |
1672 * visible: Visible area relative to the range. | 1770 * visible: Visible area relative to the range. |
1673 */ | 1771 */ |
1674 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) | 1772 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) |
1675 { | 1773 { |
1676 NSLog(@"dw_scrollbar_set_range() unimplemented\n"); | 1774 DWScrollbar *scrollbar = handle; |
1775 float knob = (float)visible/(float)range; | |
1776 [scrollbar setRange:(float)range andVisible:(float)visible]; | |
1777 [scrollbar setKnobProportion:knob]; | |
1677 } | 1778 } |
1678 | 1779 |
1679 /* | 1780 /* |
1680 * Create a new percent bar window (widget) to be packed. | 1781 * Create a new percent bar window (widget) to be packed. |
1681 * Parameters: | 1782 * Parameters: |
1906 * Parameters: | 2007 * Parameters: |
1907 * id: An ID to be used with dw_window_from_id() or 0L. | 2008 * id: An ID to be used with dw_window_from_id() or 0L. |
1908 */ | 2009 */ |
1909 HWND API dw_mle_new(ULONG id) | 2010 HWND API dw_mle_new(ULONG id) |
1910 { | 2011 { |
1911 NSLog(@"dw_mle_new() unimplemented\n"); | 2012 DWMLE *mle = [[DWMLE alloc] init]; |
1912 return HWND_DESKTOP; | 2013 return mle; |
1913 } | 2014 } |
1914 | 2015 |
1915 /* | 2016 /* |
1916 * Adds text to an MLE box and returns the current point. | 2017 * Adds text to an MLE box and returns the current point. |
1917 * Parameters: | 2018 * Parameters: |
1919 * buffer: Text buffer to be imported. | 2020 * buffer: Text buffer to be imported. |
1920 * startpoint: Point to start entering text. | 2021 * startpoint: Point to start entering text. |
1921 */ | 2022 */ |
1922 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint) | 2023 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint) |
1923 { | 2024 { |
1924 NSLog(@"dw_mle_import() unimplemented\n"); | 2025 DWMLE *mle = handle; |
1925 return 0; | 2026 [mle insertText:[ NSString stringWithUTF8String:buffer ]]; |
2027 return strlen(buffer) + startpoint; | |
1926 } | 2028 } |
1927 | 2029 |
1928 /* | 2030 /* |
1929 * Grabs text from an MLE box. | 2031 * Grabs text from an MLE box. |
1930 * Parameters: | 2032 * Parameters: |
1989 * handle: Handle to the MLE. | 2091 * handle: Handle to the MLE. |
1990 * state: TRUE if it can be edited, FALSE for readonly. | 2092 * state: TRUE if it can be edited, FALSE for readonly. |
1991 */ | 2093 */ |
1992 void API dw_mle_set_editable(HWND handle, int state) | 2094 void API dw_mle_set_editable(HWND handle, int state) |
1993 { | 2095 { |
1994 NSLog(@"dw_mle_set_editable() unimplemented\n"); | 2096 DWMLE *mle = handle; |
2097 if(state) | |
2098 { | |
2099 [mle setEditable:YES]; | |
2100 } | |
2101 else | |
2102 { | |
2103 [mle setEditable:NO]; | |
2104 } | |
1995 } | 2105 } |
1996 | 2106 |
1997 /* | 2107 /* |
1998 * Sets the word wrap state of an MLE box. | 2108 * Sets the word wrap state of an MLE box. |
1999 * Parameters: | 2109 * Parameters: |
2056 * text: The text to be display by the static text widget. | 2166 * text: The text to be display by the static text widget. |
2057 * id: An ID to be used with dw_window_from_id() or 0L. | 2167 * id: An ID to be used with dw_window_from_id() or 0L. |
2058 */ | 2168 */ |
2059 HWND API dw_status_text_new(char *text, ULONG id) | 2169 HWND API dw_status_text_new(char *text, ULONG id) |
2060 { | 2170 { |
2061 NSLog(@"dw_status_text_new() unimplemented\n"); | 2171 NSTextField *textfield = dw_text_new(text, id); |
2062 return HWND_DESKTOP; | 2172 [textfield setBordered:YES]; |
2173 [textfield setBezeled:YES]; | |
2174 [textfield setBezelStyle:NSRecessedBezelStyle]; | |
2175 return textfield; | |
2063 } | 2176 } |
2064 | 2177 |
2065 /* | 2178 /* |
2066 * Create a new static text window (widget) to be packed. | 2179 * Create a new static text window (widget) to be packed. |
2067 * Parameters: | 2180 * Parameters: |
2068 * text: The text to be display by the static text widget. | 2181 * text: The text to be display by the static text widget. |
2069 * id: An ID to be used with dw_window_from_id() or 0L. | 2182 * id: An ID to be used with dw_window_from_id() or 0L. |
2070 */ | 2183 */ |
2071 HWND API dw_text_new(char *text, ULONG id) | 2184 HWND API dw_text_new(char *text, ULONG id) |
2072 { | 2185 { |
2073 NSLog(@"dw_text_new() unimplemented\n"); | 2186 NSTextField *textfield = [[NSTextField alloc] init]; |
2074 return HWND_DESKTOP; | 2187 [textfield setEditable:NO]; |
2188 [textfield setSelectable:NO]; | |
2189 [textfield setBordered:NO]; | |
2190 [textfield setDrawsBackground:NO]; | |
2191 [textfield setStringValue:[ NSString stringWithUTF8String:text ]]; | |
2192 return textfield; | |
2075 } | 2193 } |
2076 | 2194 |
2077 /* | 2195 /* |
2078 * Creates a rendering context widget (window) to be packed. | 2196 * Creates a rendering context widget (window) to be packed. |
2079 * Parameters: | 2197 * Parameters: |
2081 * Returns: | 2199 * Returns: |
2082 * A handle to the widget or NULL on failure. | 2200 * A handle to the widget or NULL on failure. |
2083 */ | 2201 */ |
2084 HWND API dw_render_new(unsigned long id) | 2202 HWND API dw_render_new(unsigned long id) |
2085 { | 2203 { |
2086 NSLog(@"dw_render_new() unimplemented\n"); | 2204 DWRender *render = [[DWRender alloc] init]; |
2087 return HWND_DESKTOP; | 2205 return render; |
2088 } | 2206 } |
2089 | 2207 |
2090 /* Sets the current foreground drawing color. | 2208 /* Sets the current foreground drawing color. |
2091 * Parameters: | 2209 * Parameters: |
2092 * red: red value. | 2210 * red: red value. |
2138 * x: X coordinate. | 2256 * x: X coordinate. |
2139 * y: Y coordinate. | 2257 * y: Y coordinate. |
2140 */ | 2258 */ |
2141 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) | 2259 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) |
2142 { | 2260 { |
2143 NSLog(@"dw_draw_point() unimplemented\n"); | 2261 NSRect rect = NSMakeRect(x, y, x, y); |
2262 [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set]; | |
2263 NSRectFill(rect); | |
2144 } | 2264 } |
2145 | 2265 |
2146 /* Draw a line on a window (preferably a render window). | 2266 /* Draw a line on a window (preferably a render window). |
2147 * Parameters: | 2267 * Parameters: |
2148 * handle: Handle to the window. | 2268 * handle: Handle to the window. |
2208 * width: Width of rectangle. | 2328 * width: Width of rectangle. |
2209 * height: Height of rectangle. | 2329 * height: Height of rectangle. |
2210 */ | 2330 */ |
2211 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) | 2331 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) |
2212 { | 2332 { |
2213 NSLog(@"dw_draw_rect() unimplemented\n"); | 2333 NSRect rect = NSMakeRect(x, y, x + width, y + height); |
2334 [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set]; | |
2335 NSRectFill(rect); | |
2214 } | 2336 } |
2215 | 2337 |
2216 /* | 2338 /* |
2217 * Create a tree object to be packed. | 2339 * Create a tree object to be packed. |
2218 * Parameters: | 2340 * Parameters: |
2794 * Parameters: | 2916 * Parameters: |
2795 * id: An ID to be used with dw_window_from_id() or 0L. | 2917 * id: An ID to be used with dw_window_from_id() or 0L. |
2796 */ | 2918 */ |
2797 HWND API dw_bitmap_new(ULONG id) | 2919 HWND API dw_bitmap_new(ULONG id) |
2798 { | 2920 { |
2799 NSLog(@"dw_bitmap_new() unimplemented\n"); | 2921 NSImageView *bitmap = [[NSImageView alloc] init]; |
2800 return HWND_DESKTOP; | 2922 [bitmap setImageFrameStyle:NSImageFrameNone]; |
2923 [bitmap setEditable:NO]; | |
2924 return bitmap; | |
2801 } | 2925 } |
2802 | 2926 |
2803 /* | 2927 /* |
2804 * Creates a pixmap with given parameters. | 2928 * Creates a pixmap with given parameters. |
2805 * Parameters: | 2929 * Parameters: |
2810 * Returns: | 2934 * Returns: |
2811 * A handle to a pixmap or NULL on failure. | 2935 * A handle to a pixmap or NULL on failure. |
2812 */ | 2936 */ |
2813 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) | 2937 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) |
2814 { | 2938 { |
2815 NSLog(@"dw_pixmap_new() unimplemented\n"); | 2939 NSSize size = { (float)width, (float)height }; |
2816 return HWND_DESKTOP; | 2940 NSImage *pixmap = [[NSImage alloc] initWithSize:size]; |
2941 return (HPIXMAP)pixmap; | |
2817 } | 2942 } |
2818 | 2943 |
2819 /* | 2944 /* |
2820 * Creates a pixmap from a file. | 2945 * Creates a pixmap from a file. |
2821 * Parameters: | 2946 * Parameters: |
2826 * Returns: | 2951 * Returns: |
2827 * A handle to a pixmap or NULL on failure. | 2952 * A handle to a pixmap or NULL on failure. |
2828 */ | 2953 */ |
2829 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) | 2954 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) |
2830 { | 2955 { |
2831 NSLog(@"dw_pixmap_new_from_file() unimplemented\n"); | 2956 NSImage *pixmap = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; |
2832 return HWND_DESKTOP; | 2957 return (HPIXMAP)pixmap; |
2833 } | 2958 } |
2834 | 2959 |
2835 /* | 2960 /* |
2836 * Creates a pixmap from memory. | 2961 * Creates a pixmap from memory. |
2837 * Parameters: | 2962 * Parameters: |
2842 * Returns: | 2967 * Returns: |
2843 * A handle to a pixmap or NULL on failure. | 2968 * A handle to a pixmap or NULL on failure. |
2844 */ | 2969 */ |
2845 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len) | 2970 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len) |
2846 { | 2971 { |
2847 NSLog(@"dw_pixmap_new_from_data() unimplemented\n"); | 2972 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; |
2848 return HWND_DESKTOP; | 2973 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata]; |
2974 return (HPIXMAP)pixmap; | |
2849 } | 2975 } |
2850 | 2976 |
2851 /* | 2977 /* |
2852 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds | 2978 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds |
2853 */ | 2979 */ |
2876 * pixmap: Handle to a pixmap returned by | 3002 * pixmap: Handle to a pixmap returned by |
2877 * dw_pixmap_new.. | 3003 * dw_pixmap_new.. |
2878 */ | 3004 */ |
2879 void API dw_pixmap_destroy(HPIXMAP pixmap) | 3005 void API dw_pixmap_destroy(HPIXMAP pixmap) |
2880 { | 3006 { |
2881 NSLog(@"dw_pixmap_destroy() unimplemented\n"); | 3007 NSImage *image = (NSImage *)pixmap; |
3008 [image dealloc]; | |
2882 } | 3009 } |
2883 | 3010 |
2884 /* | 3011 /* |
2885 * Copies from one item to another. | 3012 * Copies from one item to another. |
2886 * Parameters: | 3013 * Parameters: |
3324 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) | 3451 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) |
3325 { | 3452 { |
3326 NSRect frame = NSMakeRect(1,1,1,1); | 3453 NSRect frame = NSMakeRect(1,1,1,1); |
3327 NSWindow *window = [[NSWindow alloc] | 3454 NSWindow *window = [[NSWindow alloc] |
3328 initWithContentRect:frame | 3455 initWithContentRect:frame |
3329 styleMask:flStyle | 3456 styleMask:(flStyle | NSTexturedBackgroundWindowMask) |
3330 backing:NSBackingStoreBuffered | 3457 backing:NSBackingStoreBuffered |
3331 defer:false]; | 3458 defer:false]; |
3332 | 3459 |
3333 [window setTitle:[ NSString stringWithUTF8String:title ]]; | 3460 [window setTitle:[ NSString stringWithUTF8String:title ]]; |
3334 | 3461 |
3409 * fore: Foreground color in DW_RGB format or a default color index. | 3536 * fore: Foreground color in DW_RGB format or a default color index. |
3410 * back: Background color in DW_RGB format or a default color index. | 3537 * back: Background color in DW_RGB format or a default color index. |
3411 */ | 3538 */ |
3412 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) | 3539 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) |
3413 { | 3540 { |
3414 NSLog(@"dw_window_set_color() unimplemented\n"); | 3541 id object = handle; |
3415 return -1; | 3542 |
3543 if([object isMemberOfClass:[NSTextFieldCell class]]) | |
3544 { | |
3545 NSTextFieldCell *text = object; | |
3546 [text setTextColor:[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]]; | |
3547 } | |
3548 return 0; | |
3416 } | 3549 } |
3417 | 3550 |
3418 /* | 3551 /* |
3419 * Sets the font used by a specified window (widget) handle. | 3552 * Sets the font used by a specified window (widget) handle. |
3420 * Parameters: | 3553 * Parameters: |
3421 * handle: The window (widget) handle. | 3554 * handle: The window (widget) handle. |
3422 * border: Size of the window border in pixels. | 3555 * border: Size of the window border in pixels. |
3423 */ | 3556 */ |
3424 int API dw_window_set_border(HWND handle, int border) | 3557 int API dw_window_set_border(HWND handle, int border) |
3425 { | 3558 { |
3426 NSLog(@"dw_window_set_border() unimplemented\n"); | |
3427 return 0; | 3559 return 0; |
3428 } | 3560 } |
3429 | 3561 |
3430 /* | 3562 /* |
3431 * Sets the style of a given window (widget). | 3563 * Sets the style of a given window (widget). |
3434 * width: New width in pixels. | 3566 * width: New width in pixels. |
3435 * height: New height in pixels. | 3567 * height: New height in pixels. |
3436 */ | 3568 */ |
3437 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) | 3569 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) |
3438 { | 3570 { |
3439 NSLog(@"dw_window_set_style() unimplemented\n"); | 3571 id object = handle; |
3572 | |
3573 if([object isMemberOfClass:[NSWindow class]]) | |
3574 { | |
3575 NSWindow *window = object; | |
3576 int currentstyle = [window styleMask]; | |
3577 int tmp; | |
3578 | |
3579 tmp = currentstyle | mask; | |
3580 tmp ^= mask; | |
3581 tmp |= style; | |
3582 | |
3583 [window setStyleMask:tmp]; | |
3584 } | |
3440 } | 3585 } |
3441 | 3586 |
3442 /* | 3587 /* |
3443 * Sets the default focus item for a window/dialog. | 3588 * Sets the default focus item for a window/dialog. |
3444 * Parameters: | 3589 * Parameters: |