Mercurial > dwindows
comparison mac/dw.m @ 661:eee90a788876
Added missing functions needed to build HandyFTP.
Fixed render area rendering fonts upside down.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 25 Feb 2011 03:45:44 +0000 |
parents | 2784e7ee8bcb |
children | d7badd5606ca |
comparison
equal
deleted
inserted
replaced
660:2784e7ee8bcb | 661:eee90a788876 |
---|---|
82 } | 82 } |
83 | 83 |
84 int _event_handler(id object, NSEvent *event, int message) | 84 int _event_handler(id object, NSEvent *event, int message) |
85 { | 85 { |
86 SignalHandler *handler = _get_handler(object, message); | 86 SignalHandler *handler = _get_handler(object, message); |
87 NSLog(@"Event handler - type %d\n", message); | 87 /*NSLog(@"Event handler - type %d\n", message);*/ |
88 | 88 |
89 if(handler) | 89 if(handler) |
90 { | 90 { |
91 switch(message) | 91 switch(message) |
92 { | 92 { |
147 return buttonfunc(object, point.x, point.y, button, handler->data); | 147 return buttonfunc(object, point.x, point.y, button, handler->data); |
148 } | 148 } |
149 case 6: | 149 case 6: |
150 { | 150 { |
151 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; | 151 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
152 NSLog(@"Close\n"); | |
153 return closefunc(object, handler->data); | 152 return closefunc(object, handler->data); |
154 } | 153 } |
155 case 7: | 154 case 7: |
156 { | 155 { |
157 DWExpose exp; | 156 DWExpose exp; |
161 exp.x = rect.origin.x; | 160 exp.x = rect.origin.x; |
162 exp.y = rect.origin.y; | 161 exp.y = rect.origin.y; |
163 exp.width = rect.size.width; | 162 exp.width = rect.size.width; |
164 exp.height = rect.size.height; | 163 exp.height = rect.size.height; |
165 int result = exposefunc(object, &exp, handler->data); | 164 int result = exposefunc(object, &exp, handler->data); |
166 NSGraphicsContext *gc = [[object window] graphicsContext]; | 165 [[object window] flushWindow]; |
167 [gc flushGraphics]; | |
168 return result; | 166 return result; |
169 } | 167 } |
170 case 8: | 168 case 8: |
171 { | 169 { |
172 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; | 170 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
173 | 171 |
174 NSLog(@"Clicked\n"); | |
175 return clickfunc(object, handler->data); | 172 return clickfunc(object, handler->data); |
176 } | 173 } |
177 case 10: | 174 case 10: |
178 { | 175 { |
179 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction; | 176 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction; |
212 NSMenu *DWMainMenu; | 209 NSMenu *DWMainMenu; |
213 DWTimerHandler *DWHandler; | 210 DWTimerHandler *DWHandler; |
214 #if !defined(GARBAGE_COLLECT) | 211 #if !defined(GARBAGE_COLLECT) |
215 NSAutoreleasePool *pool; | 212 NSAutoreleasePool *pool; |
216 #endif | 213 #endif |
214 HWND _DWLastDrawable; | |
217 | 215 |
218 /* So basically to implement our event handlers... | 216 /* So basically to implement our event handlers... |
219 * it looks like we are going to have to subclass | 217 * it looks like we are going to have to subclass |
220 * basically everything. Was hoping to add methods | 218 * basically everything. Was hoping to add methods |
221 * to the superclasses but it looks like you can | 219 * to the superclasses but it looks like you can |
514 void *userdata; | 512 void *userdata; |
515 } | 513 } |
516 -(void *)userdata; | 514 -(void *)userdata; |
517 -(void)setUserdata:(void *)input; | 515 -(void)setUserdata:(void *)input; |
518 -(void)drawRect:(NSRect)rect; | 516 -(void)drawRect:(NSRect)rect; |
519 -(BOOL)isFlipped; | |
520 -(void)mouseDown:(NSEvent *)theEvent; | 517 -(void)mouseDown:(NSEvent *)theEvent; |
521 -(void)mouseUp:(NSEvent *)theEvent; | 518 -(void)mouseUp:(NSEvent *)theEvent; |
522 @end | 519 @end |
523 | 520 |
524 @implementation DWRender | 521 @implementation DWRender |
525 -(void *)userdata { return userdata; } | 522 -(void *)userdata { return userdata; } |
526 -(void)setUserdata:(void *)input { userdata = input; } | 523 -(void)setUserdata:(void *)input { userdata = input; } |
527 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } | 524 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } |
528 -(BOOL)isFlipped { return YES; } | |
529 -(void)mouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } | 525 -(void)mouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } |
530 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 526 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
531 @end | 527 @end |
532 | 528 |
533 /* Subclass for a MLE type */ | 529 /* Subclass for a MLE type */ |
1147 (*depth)++; | 1143 (*depth)++; |
1148 | 1144 |
1149 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); | 1145 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); |
1150 | 1146 |
1151 (*depth)--; | 1147 (*depth)--; |
1148 [box setBox:_tmp]; | |
1152 | 1149 |
1153 } | 1150 } |
1154 } | 1151 } |
1155 } | 1152 } |
1156 | 1153 |
1200 if(view != nil) | 1197 if(view != nil) |
1201 { | 1198 { |
1202 Box box = [view box]; | 1199 Box box = [view box]; |
1203 NSSize size = [view frame].size; | 1200 NSSize size = [view frame].size; |
1204 _do_resize(&box, size.width, size.height); | 1201 _do_resize(&box, size.width, size.height); |
1202 [view setBox:box]; | |
1205 } | 1203 } |
1206 } | 1204 } |
1207 else if([handle isMemberOfClass:[DWRender class]]) | 1205 else if([handle isMemberOfClass:[DWRender class]]) |
1208 { | 1206 { |
1209 _event_handler(handle, nil, 1); | 1207 _event_handler(handle, nil, 1); |
1208 } | |
1209 else if([handle isMemberOfClass:[WebView class]]) | |
1210 { | |
1211 NSLog(@"x: %d y: %d width: %d height: %d", (int)point.x, (int)point.y, (int)size.width, (int)size.height); | |
1210 } | 1212 } |
1211 | 1213 |
1212 if(thisbox->type == DW_HORZ) | 1214 if(thisbox->type == DW_HORZ) |
1213 currentx += width + vectorx + (pad * 2); | 1215 currentx += width + vectorx + (pad * 2); |
1214 if(thisbox->type == DW_VERT) | 1216 if(thisbox->type == DW_VERT) |
1357 #if !defined(GARBAGE_COLLECT) | 1359 #if !defined(GARBAGE_COLLECT) |
1358 pool = [[NSAutoreleasePool alloc] init]; | 1360 pool = [[NSAutoreleasePool alloc] init]; |
1359 #endif | 1361 #endif |
1360 DWMainMenu = _generate_main_menu(); | 1362 DWMainMenu = _generate_main_menu(); |
1361 [DWApp setMainMenu:DWMainMenu]; | 1363 [DWApp setMainMenu:DWMainMenu]; |
1362 DWObject *test = [[DWObject alloc] init]; | 1364 /*DWObject *test = [[DWObject alloc] init]; |
1363 NSThread *thread = [[ NSThread alloc] initWithTarget:test selector:@selector(uselessThread:) object:nil]; | 1365 NSThread *thread = [[ NSThread alloc] initWithTarget:test selector:@selector(uselessThread:) object:nil]; |
1364 [thread start]; | 1366 [thread start];*/ |
1365 return 0; | 1367 return 0; |
1366 } | 1368 } |
1367 | 1369 |
1368 /* | 1370 /* |
1369 * Runs a message loop for Dynamic Windows. | 1371 * Runs a message loop for Dynamic Windows. |
2719 [image lockFocus]; | 2721 [image lockFocus]; |
2720 } | 2722 } |
2721 else | 2723 else |
2722 { | 2724 { |
2723 [image lockFocusIfCanDraw]; | 2725 [image lockFocusIfCanDraw]; |
2726 _DWLastDrawable = handle; | |
2724 } | 2727 } |
2725 NSRect rect = NSMakeRect(x, y, x, y); | 2728 NSRect rect = NSMakeRect(x, y, x, y); |
2726 [[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]; | 2729 [[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]; |
2727 NSRectFill(rect); | 2730 NSRectFill(rect); |
2728 [image unlockFocus]; | 2731 [image unlockFocus]; |
2746 [image lockFocus]; | 2749 [image lockFocus]; |
2747 } | 2750 } |
2748 else | 2751 else |
2749 { | 2752 { |
2750 [image lockFocusIfCanDraw]; | 2753 [image lockFocusIfCanDraw]; |
2754 _DWLastDrawable = handle; | |
2751 } | 2755 } |
2752 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 2756 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
2753 [aPath setLineWidth: 1.0]; | 2757 [aPath setLineWidth: 0.5]; |
2754 | 2758 |
2755 [aPath moveToPoint:NSMakePoint(x1, y1)]; | 2759 [aPath moveToPoint:NSMakePoint(x1, y1)]; |
2756 [aPath lineToPoint:NSMakePoint(x2, y2)]; | 2760 [aPath lineToPoint:NSMakePoint(x2, y2)]; |
2757 [aPath stroke]; | 2761 [aPath stroke]; |
2758 | 2762 |
2778 [image lockFocusIfCanDraw]; | 2782 [image lockFocusIfCanDraw]; |
2779 NSDictionary *dict = [[NSDictionary alloc] init]; | 2783 NSDictionary *dict = [[NSDictionary alloc] init]; |
2780 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; | 2784 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; |
2781 [image unlockFocus]; | 2785 [image unlockFocus]; |
2782 } | 2786 } |
2787 _DWLastDrawable = handle; | |
2783 } | 2788 } |
2784 if(pixmap) | 2789 if(pixmap) |
2785 { | 2790 { |
2786 image = (id)pixmap->handle; | 2791 image = (id)pixmap->handle; |
2787 [image lockFocus]; | 2792 [image lockFocus]; |
2800 * height Pointer to a variable to be filled in with the height. | 2805 * height Pointer to a variable to be filled in with the height. |
2801 */ | 2806 */ |
2802 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) | 2807 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) |
2803 { | 2808 { |
2804 id image = handle; | 2809 id image = handle; |
2810 NSString *nstr = [ NSString stringWithUTF8String:text ]; | |
2805 if(pixmap) | 2811 if(pixmap) |
2806 { | 2812 { |
2807 image = (id)pixmap->handle; | 2813 image = (id)pixmap->handle; |
2808 } | 2814 [image lockFocus]; |
2809 NSLog(@"dw_font_text_extents_get() unimplemented\n"); | 2815 } |
2816 else | |
2817 { | |
2818 [image lockFocusIfCanDraw]; | |
2819 } | |
2820 NSDictionary *dict = [[NSDictionary alloc] init]; | |
2821 NSSize size = [nstr sizeWithAttributes:dict]; | |
2822 if(width) | |
2823 { | |
2824 *width = size.width; | |
2825 } | |
2826 if(height) | |
2827 { | |
2828 *height = size.height; | |
2829 } | |
2830 [image unlockFocus]; | |
2810 } | 2831 } |
2811 | 2832 |
2812 /* Draw a polygon on a window (preferably a render window). | 2833 /* Draw a polygon on a window (preferably a render window). |
2813 * Parameters: | 2834 * Parameters: |
2814 * handle: Handle to the window. | 2835 * handle: Handle to the window. |
2829 [image lockFocus]; | 2850 [image lockFocus]; |
2830 } | 2851 } |
2831 else | 2852 else |
2832 { | 2853 { |
2833 [image lockFocusIfCanDraw]; | 2854 [image lockFocusIfCanDraw]; |
2855 _DWLastDrawable = handle; | |
2834 } | 2856 } |
2835 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 2857 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
2836 [aPath setLineWidth: 1.0]; | 2858 [aPath setLineWidth: 0.5]; |
2837 | 2859 |
2838 [aPath moveToPoint:NSMakePoint(*x, *y)]; | 2860 [aPath moveToPoint:NSMakePoint(*x, *y)]; |
2839 for(z=1;z<npoints;z++) | 2861 for(z=1;z<npoints;z++) |
2840 { | 2862 { |
2841 [aPath lineToPoint:NSMakePoint(x[z], y[z])]; | 2863 [aPath lineToPoint:NSMakePoint(x[z], y[z])]; |
2868 [image lockFocus]; | 2890 [image lockFocus]; |
2869 } | 2891 } |
2870 else | 2892 else |
2871 { | 2893 { |
2872 [image lockFocusIfCanDraw]; | 2894 [image lockFocusIfCanDraw]; |
2895 _DWLastDrawable = handle; | |
2873 } | 2896 } |
2874 NSRect rect = NSMakeRect(x, y, x + width, y + height); | 2897 NSRect rect = NSMakeRect(x, y, x + width, y + height); |
2875 [[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]; | 2898 [[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]; |
2876 NSRectFill(rect); | 2899 NSRectFill(rect); |
2877 [image unlockFocus]; | 2900 [image unlockFocus]; |
3686 [bltdest lockFocus]; | 3709 [bltdest lockFocus]; |
3687 } | 3710 } |
3688 else | 3711 else |
3689 { | 3712 { |
3690 [bltdest lockFocusIfCanDraw]; | 3713 [bltdest lockFocusIfCanDraw]; |
3714 _DWLastDrawable = dest; | |
3691 } | 3715 } |
3692 if(srcp) | 3716 if(srcp) |
3693 { | 3717 { |
3694 bltsrc = (id)srcp->handle; | 3718 bltsrc = (id)srcp->handle; |
3695 NSImage *image = bltsrc; | 3719 NSImage *image = bltsrc; |
4220 DWView *view = [[DWView alloc] init]; | 4244 DWView *view = [[DWView alloc] init]; |
4221 | 4245 |
4222 [window setContentView:view]; | 4246 [window setContentView:view]; |
4223 [window setDelegate:view]; | 4247 [window setDelegate:view]; |
4224 [window makeKeyAndOrderFront:nil]; | 4248 [window makeKeyAndOrderFront:nil]; |
4249 [window setAllowsConcurrentViewDrawing:NO]; | |
4225 | 4250 |
4226 return (HWND)window; | 4251 return (HWND)window; |
4227 } | 4252 } |
4228 | 4253 |
4229 /* | 4254 /* |
4585 * handle: Handle to the window. | 4610 * handle: Handle to the window. |
4586 * id: An ID to be used to specify the icon. | 4611 * id: An ID to be used to specify the icon. |
4587 */ | 4612 */ |
4588 void API dw_window_set_icon(HWND handle, ULONG id) | 4613 void API dw_window_set_icon(HWND handle, ULONG id) |
4589 { | 4614 { |
4590 NSLog(@"dw_window_set_icon() unimplemented\n"); | 4615 /* This isn't needed, it is loaded from the bundle */ |
4591 } | 4616 } |
4592 | 4617 |
4593 /* | 4618 /* |
4594 * Gets the child window handle with specified ID. | 4619 * Gets the child window handle with specified ID. |
4595 * Parameters: | 4620 * Parameters: |
4829 /* Call this after drawing to the screen to make sure | 4854 /* Call this after drawing to the screen to make sure |
4830 * anything you have drawn is visible. | 4855 * anything you have drawn is visible. |
4831 */ | 4856 */ |
4832 void API dw_flush(void) | 4857 void API dw_flush(void) |
4833 { | 4858 { |
4859 if(_DWLastDrawable) | |
4860 { | |
4861 id object = _DWLastDrawable; | |
4862 NSWindow *window = [object window]; | |
4863 [window flushWindow]; | |
4864 } | |
4834 } | 4865 } |
4835 | 4866 |
4836 /* Functions for managing the user data lists that are associated with | 4867 /* Functions for managing the user data lists that are associated with |
4837 * a given window handle. Used in dw_window_set_data() and | 4868 * a given window handle. Used in dw_window_set_data() and |
4838 * dw_window_get_data(). | 4869 * dw_window_get_data(). |
5941 DWTID dw_thread_id(void) | 5972 DWTID dw_thread_id(void) |
5942 { | 5973 { |
5943 return (DWTID)pthread_self(); | 5974 return (DWTID)pthread_self(); |
5944 } | 5975 } |
5945 | 5976 |
5977 /* | |
5978 * Execute and external program in a seperate session. | |
5979 * Parameters: | |
5980 * program: Program name with optional path. | |
5981 * type: Either DW_EXEC_CON or DW_EXEC_GUI. | |
5982 * params: An array of pointers to string arguements. | |
5983 * Returns: | |
5984 * -1 on error. | |
5985 */ | |
5986 int dw_exec(char *program, int type, char **params) | |
5987 { | |
5988 int ret = -1; | |
5989 | |
5990 if((ret = fork()) == 0) | |
5991 { | |
5992 int i; | |
5993 | |
5994 for (i = 3; i < 256; i++) | |
5995 close(i); | |
5996 setsid(); | |
5997 if(type == DW_EXEC_GUI) | |
5998 { | |
5999 execvp(program, params); | |
6000 } | |
6001 else if(type == DW_EXEC_CON) | |
6002 { | |
6003 char **tmpargs; | |
6004 | |
6005 if(!params) | |
6006 { | |
6007 tmpargs = malloc(sizeof(char *)); | |
6008 tmpargs[0] = NULL; | |
6009 } | |
6010 else | |
6011 { | |
6012 int z = 0; | |
6013 | |
6014 while(params[z]) | |
6015 { | |
6016 z++; | |
6017 } | |
6018 tmpargs = malloc(sizeof(char *)*(z+3)); | |
6019 z=0; | |
6020 tmpargs[0] = "xterm"; | |
6021 tmpargs[1] = "-e"; | |
6022 while(params[z]) | |
6023 { | |
6024 tmpargs[z+2] = params[z]; | |
6025 z++; | |
6026 } | |
6027 tmpargs[z+2] = NULL; | |
6028 } | |
6029 execvp("xterm", tmpargs); | |
6030 free(tmpargs); | |
6031 } | |
6032 /* If we got here exec failed */ | |
6033 _exit(-1); | |
6034 } | |
6035 return ret; | |
6036 } | |
6037 | |
6038 /* | |
6039 * Loads a web browser pointed at the given URL. | |
6040 * Parameters: | |
6041 * url: Uniform resource locator. | |
6042 */ | |
6043 int dw_browse(char *url) | |
6044 { | |
6045 /* Is there a way to find the webbrowser in Unix? */ | |
6046 char *execargs[3], *browser = "netscape", *tmp; | |
6047 | |
6048 tmp = getenv( "DW_BROWSER" ); | |
6049 if(tmp) browser = tmp; | |
6050 execargs[0] = browser; | |
6051 execargs[1] = url; | |
6052 execargs[2] = NULL; | |
6053 | |
6054 return dw_exec(browser, DW_EXEC_GUI, execargs); | |
6055 } | |
6056 | |
5946 #ifdef DWTEST | 6057 #ifdef DWTEST |
5947 int main(int argc, char *argv[]) | 6058 int main(int argc, char *argv[]) |
5948 { | 6059 { |
5949 HWND window, box, vbox, hbox, button, text, checkbox, html; | 6060 HWND window, box, vbox, hbox, button, text, checkbox, html; |
5950 LONG x, y; | 6061 LONG x, y; |