comparison ios/dw.m @ 2384:32ebd33be56b

iOS: First building version. Yay! Still lots to do but progress.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 21 Mar 2021 22:48:28 +0000
parents a410d42d9e36
children a126b04b9996
comparison
equal deleted inserted replaced
2383:a410d42d9e36 2384:32ebd33be56b
2449 void API dw_main(void) 2449 void API dw_main(void)
2450 { 2450 {
2451 DWThread = dw_thread_id(); 2451 DWThread = dw_thread_id();
2452 /* Make sure any queued redraws are handled */ 2452 /* Make sure any queued redraws are handled */
2453 _dw_redraw(0, FALSE); 2453 _dw_redraw(0, FALSE);
2454 [DWApp run]; 2454 [[NSRunLoop mainRunLoop] run];
2455 DWThread = (DWTID)-1; 2455 DWThread = (DWTID)-1;
2456 } 2456 }
2457 2457
2458 /* 2458 /*
2459 * Causes running dw_main() to return. 2459 * Causes running dw_main() to return.
2460 */ 2460 */
2461 void API dw_main_quit(void) 2461 void API dw_main_quit(void)
2462 { 2462 {
2463 [DWApp stop:nil]; 2463 /* TODO: Make this work
2464 [[NSRunLoop mainRunLoop] ]; */
2464 } 2465 }
2465 2466
2466 /* 2467 /*
2467 * Runs a message loop for Dynamic Windows, for a period of milliseconds. 2468 * Runs a message loop for Dynamic Windows, for a period of milliseconds.
2468 * Parameters: 2469 * Parameters:
2498 } 2499 }
2499 2500
2500 /* Internal version that doesn't lock the run mutex */ 2501 /* Internal version that doesn't lock the run mutex */
2501 int _dw_main_iteration(NSDate *date) 2502 int _dw_main_iteration(NSDate *date)
2502 { 2503 {
2503 UIEvent *event = [DWApp nextEventMatchingMask:UIEventMaskAny 2504 return [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:date];
2504 untilDate:date
2505 inMode:NSDefaultRunLoopMode
2506 dequeue:YES];
2507 if(event)
2508 {
2509 [DWApp sendEvent:event];
2510 return 1;
2511 }
2512 return 0;
2513 } 2505 }
2514 2506
2515 /* 2507 /*
2516 * Processes a single message iteration and returns. 2508 * Processes a single message iteration and returns.
2517 */ 2509 */
7578 * Returns: 7570 * Returns:
7579 * A malloced buffer with the selected font or NULL on error. 7571 * A malloced buffer with the selected font or NULL on error.
7580 */ 7572 */
7581 char * API dw_font_choose(const char *currfont) 7573 char * API dw_font_choose(const char *currfont)
7582 { 7574 {
7583 /* Create the Font Chooser Dialog class. */ 7575 __block UIFont *font = nil;
7584 static DWFontChoose *fontDlg = nil; 7576 UIFontPickerViewController* picker = [[UIFontPickerViewController alloc] init];
7585 DWDialog *dialog; 7577 /*TODO: Add handler for accepting the font fontPickerViewControllerDidPickFont */
7586 UIFont *font = nil; 7578 /* Wait for them to pick a color */
7587 7579 [picker presentViewController:picker animated:YES completion:nil];
7588 if(currfont) 7580 [picker release];
7589 font = _dw_font_by_name(currfont); 7581
7590
7591 if(fontDlg)
7592 {
7593 dialog = [fontDlg dialog];
7594 /* If someone is already waiting just return */
7595 if(dialog)
7596 {
7597 return NULL;
7598 }
7599 }
7600 else
7601 {
7602 [UIFontManager setFontPanelFactory:[DWFontChoose class]];
7603 fontDlg = (DWFontChoose *)[DWFontManager fontPanel:YES];
7604 }
7605
7606 dialog = dw_dialog_new(fontDlg);
7607 if(font) 7582 if(font)
7608 [DWFontManager setSelectedFont:font isMultiple:NO]; 7583 {
7609 else 7584 NSString *fontname = [font fontName];
7610 [DWFontManager setSelectedFont:[UIFont fontWithName:@"Helvetica" size:9.0] isMultiple:NO];
7611 [fontDlg setDialog:dialog];
7612 [DWFontManager orderFrontFontPanel:DWFontManager];
7613
7614
7615 /* Wait for them to pick a color */
7616 font = (UIFont *)dw_dialog_wait(dialog);
7617 if(font)
7618 {
7619 NSString *fontname = [font displayName];
7620 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]]; 7585 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]];
7621 return strdup([output UTF8String]); 7586 return strdup([output UTF8String]);
7622 } 7587 }
7623 return NULL; 7588 return NULL;
7624 } 7589 }
7634 DWBox *parent = (DWBox *)[object superview]; 7599 DWBox *parent = (DWBox *)[object superview];
7635 7600
7636 /* Some controls are embedded in scrollviews... 7601 /* Some controls are embedded in scrollviews...
7637 * so get the parent of the scrollview in that case. 7602 * so get the parent of the scrollview in that case.
7638 */ 7603 */
7639 if([object isKindOfClass:[NSTableView class]] && [parent isMemberOfClass:[NSClipView class]]) 7604 if([object isKindOfClass:[UITableView class]])
7640 { 7605 {
7641 object = [parent superview]; 7606 object = [parent superview];
7642 parent = (DWBox *)[object superview]; 7607 parent = (DWBox *)[object superview];
7643 } 7608 }
7644 7609
7670 (DWDefaultFont ? DWDefaultFont : [UIFont systemFontOfSize:[UIFont smallSystemFontSize]]); 7635 (DWDefaultFont ? DWDefaultFont : [UIFont systemFontOfSize:[UIFont smallSystemFontSize]]);
7671 7636
7672 if(font) 7637 if(font)
7673 { 7638 {
7674 id object = _text_handle(handle); 7639 id object = _text_handle(handle);
7675 if([object window]) 7640 if([object isMemberOfClass:[DWMLE class]])
7676 {
7677 [object lockFocus];
7678 [font set];
7679 [object unlockFocus];
7680 }
7681 else if([object isMemberOfClass:[DWMLE class]])
7682 { 7641 {
7683 DWMLE *mle = object; 7642 DWMLE *mle = object;
7684 7643
7685 [[mle textStorage] setFont:font]; 7644 [mle setFont:font];
7686 } 7645 }
7687 else if([object isKindOfClass:[UIControl class]]) 7646 else if([object isKindOfClass:[UIControl class]])
7688 { 7647 {
7689 [object setFont:font]; 7648 [object setFont:font];
7690 [[object cell] setFont:font];
7691 } 7649 }
7692 else if([object isMemberOfClass:[DWRender class]]) 7650 else if([object isMemberOfClass:[DWRender class]])
7693 { 7651 {
7694 DWRender *render = object; 7652 DWRender *render = object;
7695 7653
7726 { 7684 {
7727 font = [object font]; 7685 font = [object font];
7728 } 7686 }
7729 if(font) 7687 if(font)
7730 { 7688 {
7731 NSString *fontname = [font displayName]; 7689 NSString *fontname = [font fontName];
7732 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]]; 7690 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]];
7733 return strdup([output UTF8String]); 7691 return strdup([output UTF8String]);
7734 } 7692 }
7735 return NULL; 7693 return NULL;
7736 } 7694 }
7752 7710
7753 /* Handle destroying a top-level window */ 7711 /* Handle destroying a top-level window */
7754 if([ object isKindOfClass:[ UIWindow class ] ]) 7712 if([ object isKindOfClass:[ UIWindow class ] ])
7755 { 7713 {
7756 DWWindow *window = handle; 7714 DWWindow *window = handle;
7757 [window close]; 7715 [window release];
7758 } 7716 }
7759 /* Handle removing menu items from menus */ 7717 /* Handle removing menu items from menus */
7718 #if 0 /* TODO: The menus are technically immutable, so we'd need to recreate it...*/
7760 else if([ object isKindOfClass:[UIMenuItem class]]) 7719 else if([ object isKindOfClass:[UIMenuItem class]])
7761 { 7720 {
7762 DWMenu *menu = [object menu]; 7721 DWMenu *menu = [object menu];
7763 7722
7764 [menu removeItem:object]; 7723 [menu removeItem:object];
7765 } 7724 }
7725 #endif
7766 /* Handle destroying a control or box */ 7726 /* Handle destroying a control or box */
7767 else if([object isKindOfClass:[UIView class]] || [object isKindOfClass:[UIControl class]]) 7727 else if([object isKindOfClass:[UIView class]] || [object isKindOfClass:[UIControl class]])
7768 { 7728 {
7769 DWBox *parent = (DWBox *)[object superview]; 7729 DWBox *parent = (DWBox *)[object superview];
7770 7730
7771 /* Some controls are embedded in scrollviews... 7731 /* Some controls are embedded in scrollviews...
7772 * so get the parent of the scrollview in that case. 7732 * so get the parent of the scrollview in that case.
7773 */ 7733 */
7774 if(([object isKindOfClass:[NSTableView class]] || [object isMemberOfClass:[DWMLE class]]) 7734 if(([object isKindOfClass:[UITableView class]] || [object isMemberOfClass:[DWMLE class]]))
7775 && [parent isMemberOfClass:[NSClipView class]])
7776 { 7735 {
7777 object = [parent superview]; 7736 object = [parent superview];
7778 parent = (DWBox *)[object superview]; 7737 parent = (DWBox *)[object superview];
7779 } 7738 }
7780 7739
7854 retval = strdup([ nsstr UTF8String ]); 7813 retval = strdup([ nsstr UTF8String ]);
7855 } 7814 }
7856 else if([ object isKindOfClass:[ UIControl class ] ]) 7815 else if([ object isKindOfClass:[ UIControl class ] ])
7857 { 7816 {
7858 UIControl *control = object; 7817 UIControl *control = object;
7859 NSString *nsstr = [ control stringValue]; 7818 NSString *nsstr = [control text];
7860 7819
7861 retval = strdup([ nsstr UTF8String ]); 7820 retval = strdup([ nsstr UTF8String ]);
7862 } 7821 }
7863 DW_FUNCTION_RETURN_THIS(retval); 7822 DW_FUNCTION_RETURN_THIS(retval);
7864 } 7823 }
7876 { 7835 {
7877 DW_FUNCTION_INIT; 7836 DW_FUNCTION_INIT;
7878 id object = _text_handle(handle); 7837 id object = _text_handle(handle);
7879 7838
7880 if([ object isKindOfClass:[ UIWindow class ] ] || [ object isKindOfClass:[ UIButton class ] ]) 7839 if([ object isKindOfClass:[ UIWindow class ] ] || [ object isKindOfClass:[ UIButton class ] ])
7881 [object setTitle:[ NSString stringWithUTF8String:text ]]; 7840 [object setTitle:[NSString stringWithUTF8String:text]];
7882 else if([ object isKindOfClass:[ UIControl class ] ]) 7841 else if([ object isKindOfClass:[ UIControl class ] ])
7883 { 7842 {
7884 UIControl *control = object; 7843 UIControl *control = object;
7885 [control setStringValue:[ NSString stringWithUTF8String:text ]]; 7844 [control setText:[NSString stringWithUTF8String:text]];
7886 } 7845 }
7887 else 7846 else
7888 return; 7847 return;
7889 /* If we changed the text... */ 7848 /* If we changed the text... */
7890 Item *item = _box_item(handle); 7849 Item *item = _box_item(handle);
7915 * Sets the text used for a given window's floating bubble help. 7874 * Sets the text used for a given window's floating bubble help.
7916 * Parameters: 7875 * Parameters:
7917 * handle: Handle to the window (widget). 7876 * handle: Handle to the window (widget).
7918 * bubbletext: The text in the floating bubble tooltip. 7877 * bubbletext: The text in the floating bubble tooltip.
7919 */ 7878 */
7920 DW_FUNCTION_DEFINITION(dw_window_set_tooltip, void, HWND handle, const char *bubbletext) 7879 void API dw_window_set_tooltip(HWND handle, const char *bubbletext)
7921 DW_FUNCTION_ADD_PARAM2(handle, bubbletext) 7880 {
7922 DW_FUNCTION_NO_RETURN(dw_window_set_tooltip) 7881 /* Tooltips don't exist on iOS */
7923 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, bubbletext, char *)
7924 {
7925 DW_FUNCTION_INIT;
7926 id object = handle;
7927 if(bubbletext && *bubbletext)
7928 [object setToolTip:[NSString stringWithUTF8String:bubbletext]];
7929 else
7930 [object setToolTip:nil];
7931 DW_FUNCTION_RETURN_NOTHING;
7932 } 7882 }
7933 7883
7934 /* 7884 /*
7935 * Disables given window (widget). 7885 * Disables given window (widget).
7936 * Parameters: 7886 * Parameters:
7945 id object = handle; 7895 id object = handle;
7946 7896
7947 if([object isMemberOfClass:[UIScrollView class]]) 7897 if([object isMemberOfClass:[UIScrollView class]])
7948 { 7898 {
7949 UIScrollView *sv = handle; 7899 UIScrollView *sv = handle;
7950 object = [sv documentView]; 7900 NSArray *subviews = [sv subviews];
7901 object = [subviews firstObject];
7951 } 7902 }
7952 if([object isKindOfClass:[UIControl class]] || [object isKindOfClass:[UIMenuItem class]]) 7903 if([object isKindOfClass:[UIControl class]] || [object isKindOfClass:[UIMenuItem class]])
7953 { 7904 {
7954 [object setEnabled:NO]; 7905 [object setEnabled:NO];
7955 } 7906 }
7976 id object = handle; 7927 id object = handle;
7977 7928
7978 if([object isMemberOfClass:[UIScrollView class]]) 7929 if([object isMemberOfClass:[UIScrollView class]])
7979 { 7930 {
7980 UIScrollView *sv = handle; 7931 UIScrollView *sv = handle;
7981 object = [sv documentView]; 7932 NSArray *subviews = [sv subviews];
7933 object = [subviews firstObject];
7982 } 7934 }
7983 if([object isKindOfClass:[UIControl class]] /* TODO: || [object isKindOfClass:[UIMenuItem class]] */) 7935 if([object isKindOfClass:[UIControl class]] /* TODO: || [object isKindOfClass:[UIMenuItem class]] */)
7984 { 7936 {
7985 [object setEnabled:YES]; 7937 [object setEnabled:YES];
7986 } 7938 }
8114 NSObject *object = handle; 8066 NSObject *object = handle;
8115 UIView *view = handle; 8067 UIView *view = handle;
8116 if([ object isKindOfClass:[ UIWindow class ] ]) 8068 if([ object isKindOfClass:[ UIWindow class ] ])
8117 { 8069 {
8118 UIWindow *window = handle; 8070 UIWindow *window = handle;
8119 view = [window contentView]; 8071 NSArray *subviews = [window subviews];
8072 view = [subviews firstObject];
8120 } 8073 }
8121 return [view viewWithTag:cid]; 8074 return [view viewWithTag:cid];
8122 } 8075 }
8123 8076
8124 /* 8077 /*
8126 * Parameters: 8079 * Parameters:
8127 * handle: The window handle to minimize. 8080 * handle: The window handle to minimize.
8128 */ 8081 */
8129 int API dw_window_minimize(HWND handle) 8082 int API dw_window_minimize(HWND handle)
8130 { 8083 {
8131 UIWindow *window = handle;
8132 [window miniaturize:nil];
8133 return 0; 8084 return 0;
8134 } 8085 }
8135 8086
8136 /* Causes entire window to be invalidated and redrawn. 8087 /* Causes entire window to be invalidated and redrawn.
8137 * Parameters: 8088 * Parameters:
8139 */ 8090 */
8140 void API dw_window_redraw(HWND handle) 8091 void API dw_window_redraw(HWND handle)
8141 { 8092 {
8142 DWWindow *window = handle; 8093 DWWindow *window = handle;
8143 [window setRedraw:YES]; 8094 [window setRedraw:YES];
8144 [[window contentView] showWindow]; 8095 [window setShown:YES];
8145 [window setRedraw:NO]; 8096 [window setRedraw:NO];
8146 } 8097 }
8147 8098
8148 /* 8099 /*
8149 * Makes the window topmost. 8100 * Makes the window topmost.
8150 * Parameters: 8101 * Parameters:
8151 * handle: The window handle to make topmost. 8102 * handle: The window handle to make topmost.
8152 */ 8103 */
8153 int API dw_window_raise(HWND handle) 8104 int API dw_window_raise(HWND handle)
8154 { 8105 {
8155 UIWindow *window = handle;
8156 [window orderFront:nil];
8157 return 0; 8106 return 0;
8158 } 8107 }
8159 8108
8160 /* 8109 /*
8161 * Makes the window bottommost. 8110 * Makes the window bottommost.
8162 * Parameters: 8111 * Parameters:
8163 * handle: The window handle to make bottommost. 8112 * handle: The window handle to make bottommost.
8164 */ 8113 */
8165 int API dw_window_lower(HWND handle) 8114 int API dw_window_lower(HWND handle)
8166 { 8115 {
8167 UIWindow *window = handle;
8168 [window orderBack:nil];
8169 return 0; 8116 return 0;
8170 } 8117 }
8171 8118
8172 /* 8119 /*
8173 * Sets the size of a given window (widget). 8120 * Sets the size of a given window (widget).
8174 * Parameters: 8121 * Parameters:
8175 * handle: Window (widget) handle. 8122 * handle: Window (widget) handle.
8176 * width: New width in pixels. 8123 * width: New width in pixels.
8177 * height: New height in pixels. 8124 * height: New height in pixels.
8178 */ 8125 */
8179 DW_FUNCTION_DEFINITION(dw_window_set_size, void, HWND handle, ULONG width, ULONG height) 8126 void API dw_window_set_size(HWND handle, ULONG width, ULONG height)
8180 DW_FUNCTION_ADD_PARAM3(handle, width, height) 8127 {
8181 DW_FUNCTION_NO_RETURN(dw_window_set_size) 8128 /* On iOS the window usually takes up the full screen */
8182 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, width, ULONG, height, ULONG)
8183 {
8184 DW_FUNCTION_INIT;
8185 NSObject *object = handle;
8186
8187 if([ object isMemberOfClass:[ DWWindow class ] ])
8188 {
8189 DWWindow *window = handle;
8190 Box *thisbox;
8191 CGRect content, frame = NSMakeRect(0, 0, width, height);
8192
8193 /* Convert the external frame size to internal content size */
8194 content = [UIWindow contentRectForFrameRect:frame styleMask:[window styleMask]];
8195
8196 /*
8197 * The following is an attempt to dynamically size a window based on the size of its
8198 * children before realization. Only applicable when width or height is less than one.
8199 */
8200 if((width < 1 || height < 1) && (thisbox = (Box *)[[window contentView] box]))
8201 {
8202 int depth = 0;
8203
8204 /* Calculate space requirements */
8205 _resize_box(thisbox, &depth, (int)width, (int)height, 1);
8206
8207 /* Update components that need auto-sizing */
8208 if(width < 1) content.size.width = thisbox->minwidth;
8209 if(height < 1) content.size.height = thisbox->minheight;
8210 }
8211
8212 /* Finally set the size */
8213 [window setContentSize:content.size];
8214 }
8215 DW_FUNCTION_RETURN_NOTHING;
8216 } 8129 }
8217 8130
8218 /* 8131 /*
8219 * Gets the size the system thinks the widget should be. 8132 * Gets the size the system thinks the widget should be.
8220 * Parameters: 8133 * Parameters:
8224 */ 8137 */
8225 void API dw_window_get_preferred_size(HWND handle, int *width, int *height) 8138 void API dw_window_get_preferred_size(HWND handle, int *width, int *height)
8226 { 8139 {
8227 id object = handle; 8140 id object = handle;
8228 8141
8229 if([object isMemberOfClass:[DWWindow class]]) 8142 if([object isMemberOfClass:[DWBox class]])
8230 {
8231 Box *thisbox;
8232
8233 if((thisbox = (Box *)[[object contentView] box]))
8234 {
8235 int depth = 0;
8236 CGRect frame;
8237
8238 /* Calculate space requirements */
8239 _resize_box(thisbox, &depth, 0, 0, 1);
8240
8241 /* Figure out the border size */
8242 frame = [UIWindow frameRectForContentRect:NSMakeRect(0, 0, thisbox->minwidth, thisbox->minheight) styleMask:[object styleMask]];
8243
8244 /* Return what was requested */
8245 if(width) *width = frame.size.width;
8246 if(height) *height = frame.size.height;
8247 }
8248 }
8249 else if([object isMemberOfClass:[DWBox class]])
8250 { 8143 {
8251 Box *thisbox; 8144 Box *thisbox;
8252 8145
8253 if((thisbox = (Box *)[object box])) 8146 if((thisbox = (Box *)[object box]))
8254 { 8147 {
8278 { 8171 {
8279 dw_window_set_data(handle, "_dw_grav_horz", DW_INT_TO_POINTER(horz)); 8172 dw_window_set_data(handle, "_dw_grav_horz", DW_INT_TO_POINTER(horz));
8280 dw_window_set_data(handle, "_dw_grav_vert", DW_INT_TO_POINTER(vert)); 8173 dw_window_set_data(handle, "_dw_grav_vert", DW_INT_TO_POINTER(vert));
8281 } 8174 }
8282 8175
8283 /* Convert the coordinates based on gravity */
8284 void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height)
8285 {
8286 int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz"));
8287 int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert"));
8288 id object = handle;
8289
8290 /* Do any gravity calculations */
8291 if(horz || (vert & 0xf) != DW_GRAV_BOTTOM)
8292 {
8293 long newx = *x, newy = *y;
8294
8295 /* Handle horizontal center gravity */
8296 if((horz & 0xf) == DW_GRAV_CENTER)
8297 newx += ((dw_screen_width() / 2) - (width / 2));
8298 /* Handle right gravity */
8299 else if((horz & 0xf) == DW_GRAV_RIGHT)
8300 newx = dw_screen_width() - width - *x;
8301 /* Handle vertical center gravity */
8302 if((vert & 0xf) == DW_GRAV_CENTER)
8303 newy += ((dw_screen_height() / 2) - (height / 2));
8304 else if((vert & 0xf) == DW_GRAV_TOP)
8305 newy = dw_screen_height() - height - *y;
8306
8307 /* Save the new values */
8308 *x = newx;
8309 *y = newy;
8310 }
8311 /* Adjust the values to avoid Dock/Menubar if requested */
8312 if((horz | vert) & DW_GRAV_OBSTACLES)
8313 {
8314 CGRect visiblerect = [[object screen] visibleFrame];
8315 CGRect totalrect = [[object screen] frame];
8316
8317 if(horz & DW_GRAV_OBSTACLES)
8318 {
8319 if((horz & 0xf) == DW_GRAV_LEFT)
8320 *x += visiblerect.origin.x;
8321 else if((horz & 0xf) == DW_GRAV_RIGHT)
8322 *x -= (totalrect.origin.x + totalrect.size.width) - (visiblerect.origin.x + visiblerect.size.width);
8323 }
8324 if(vert & DW_GRAV_OBSTACLES)
8325 {
8326 if((vert & 0xf) == DW_GRAV_BOTTOM)
8327 *y += visiblerect.origin.y;
8328 else if((vert & 0xf) == DW_GRAV_TOP)
8329 *y -= (totalrect.origin.y + totalrect.size.height) - (visiblerect.origin.y + visiblerect.size.height);
8330 }
8331 }
8332 }
8333
8334 /* 8176 /*
8335 * Sets the position of a given window (widget). 8177 * Sets the position of a given window (widget).
8336 * Parameters: 8178 * Parameters:
8337 * handle: Window (widget) handle. 8179 * handle: Window (widget) handle.
8338 * x: X location from the bottom left. 8180 * x: X location from the bottom left.
8339 * y: Y location from the bottom left. 8181 * y: Y location from the bottom left.
8340 */ 8182 */
8341 DW_FUNCTION_DEFINITION(dw_window_set_pos, void, HWND handle, LONG x, LONG y) 8183 void API dw_window_set_pos(HWND handle, LONG x, LONG y)
8342 DW_FUNCTION_ADD_PARAM3(handle, x, y) 8184 {
8343 DW_FUNCTION_NO_RETURN(dw_window_set_pos) 8185 /* iOS windows take up the whole screen */
8344 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, x, LONG, y, LONG)
8345 {
8346 DW_FUNCTION_INIT;
8347 NSObject *object = handle;
8348
8349 if([ object isMemberOfClass:[ DWWindow class ] ])
8350 {
8351 DWWindow *window = handle;
8352 CGPoint point;
8353 CGSize size = [[window contentView] frame].size;
8354
8355 /* Can't position an unsized window, so attempt to auto-size */
8356 if(size.width <= 1 || size.height <= 1)
8357 {
8358 /* Determine the contents size */
8359 dw_window_set_size(handle, 0, 0);
8360 }
8361
8362 size = [window frame].size;
8363 _handle_gravity(handle, &x, &y, (unsigned long)size.width, (unsigned long)size.height);
8364
8365 point.x = x;
8366 point.y = y;
8367
8368 [window setFrameOrigin:point];
8369 /* Position set manually... don't auto-position */
8370 [window setShown:YES];
8371 }
8372 DW_FUNCTION_RETURN_NOTHING;
8373 } 8186 }
8374 8187
8375 /* 8188 /*
8376 * Sets the position and size of a given window (widget). 8189 * Sets the position and size of a given window (widget).
8377 * Parameters: 8190 * Parameters:
8381 * width: Width of the widget. 8194 * width: Width of the widget.
8382 * height: Height of the widget. 8195 * height: Height of the widget.
8383 */ 8196 */
8384 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height) 8197 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height)
8385 { 8198 {
8386 dw_window_set_size(handle, width, height);
8387 dw_window_set_pos(handle, x, y);
8388 } 8199 }
8389 8200
8390 /* 8201 /*
8391 * Gets the position and size of a given window (widget). 8202 * Gets the position and size of a given window (widget).
8392 * Parameters: 8203 * Parameters:
8405 UIWindow *window = handle; 8216 UIWindow *window = handle;
8406 CGRect rect = [window frame]; 8217 CGRect rect = [window frame];
8407 if(x) 8218 if(x)
8408 *x = rect.origin.x; 8219 *x = rect.origin.x;
8409 if(y) 8220 if(y)
8410 *y = [[window screen] frame].size.height - rect.origin.y - rect.size.height; 8221 *y = rect.origin.y;
8411 if(width) 8222 if(width)
8412 *width = rect.size.width; 8223 *width = rect.size.width;
8413 if(height) 8224 if(height)
8414 *height = rect.size.height; 8225 *height = rect.size.height;
8415 return; 8226 return;
8433 /* 8244 /*
8434 * Returns the width of the screen. 8245 * Returns the width of the screen.
8435 */ 8246 */
8436 int API dw_screen_width(void) 8247 int API dw_screen_width(void)
8437 { 8248 {
8438 CGRect screenRect = [[NSScreen mainScreen] frame]; 8249 CGRect screenRect = [[UIScreen mainScreen] bounds];
8439 return screenRect.size.width; 8250 return screenRect.size.width;
8440 } 8251 }
8441 8252
8442 /* 8253 /*
8443 * Returns the height of the screen. 8254 * Returns the height of the screen.
8444 */ 8255 */
8445 int API dw_screen_height(void) 8256 int API dw_screen_height(void)
8446 { 8257 {
8447 CGRect screenRect = [[NSScreen mainScreen] frame]; 8258 CGRect screenRect = [[UIScreen mainScreen] bounds];
8448 return screenRect.size.height; 8259 return screenRect.size.height;
8449 } 8260 }
8450 8261
8451 /* This should return the current color depth */ 8262 /* This should return the current color depth */
8452 unsigned long API dw_color_depth_get(void) 8263 unsigned long API dw_color_depth_get(void)
8453 { 8264 {
8454 UIWindowDepth screenDepth = [[NSScreen mainScreen] depth]; 8265 /* iOS always runs in 32bit depth */
8455 return NSBitsPerPixelFromDepth(screenDepth); 8266 return 32;
8456 } 8267 }
8457 8268
8458 /* 8269 /*
8459 * Creates a new system notification if possible. 8270 * Creates a new system notification if possible.
8460 * Parameters: 8271 * Parameters:
8576 * freq: Frequency. 8387 * freq: Frequency.
8577 * dur: Duration. 8388 * dur: Duration.
8578 */ 8389 */
8579 void API dw_beep(int freq, int dur) 8390 void API dw_beep(int freq, int dur)
8580 { 8391 {
8581 NSBeep(); 8392 /* TODO: Don't see a simple way to do this without bundling sounds */
8582 } 8393 }
8583 8394
8584 /* Call this after drawing to the screen to make sure 8395 /* Call this after drawing to the screen to make sure
8585 * anything you have drawn is visible. 8396 * anything you have drawn is visible.
8586 */ 8397 */
8693 { 8504 {
8694 id object = window; 8505 id object = window;
8695 if([object isMemberOfClass:[DWWindow class]]) 8506 if([object isMemberOfClass:[DWWindow class]])
8696 { 8507 {
8697 UIWindow *win = window; 8508 UIWindow *win = window;
8698 object = [win contentView]; 8509 NSArray *subviews = [win subviews];
8510 object = [subviews firstObject];
8699 } 8511 }
8700 else if([object isMemberOfClass:[UIScrollView class]]) 8512 else if([object isMemberOfClass:[UIScrollView class]])
8701 { 8513 {
8702 UIScrollView *sv = window; 8514 UIScrollView *sv = window;
8703 object = [sv documentView]; 8515 NSArray *subviews = [sv subviews];
8516 object = [subviews firstObject];
8704 } 8517 }
8705 WindowData *blah = (WindowData *)[object userdata]; 8518 WindowData *blah = (WindowData *)[object userdata];
8706 8519
8707 if(!blah) 8520 if(!blah)
8708 { 8521 {
8735 { 8548 {
8736 id object = window; 8549 id object = window;
8737 if([object isMemberOfClass:[DWWindow class]]) 8550 if([object isMemberOfClass:[DWWindow class]])
8738 { 8551 {
8739 UIWindow *win = window; 8552 UIWindow *win = window;
8740 object = [win contentView]; 8553 NSArray *subviews = [win subviews];
8554 object = [subviews firstObject];
8741 } 8555 }
8742 else if([object isMemberOfClass:[UIScrollView class]]) 8556 else if([object isMemberOfClass:[UIScrollView class]])
8743 { 8557 {
8744 UIScrollView *sv = window; 8558 UIScrollView *sv = window;
8745 object = [sv documentView]; 8559 NSArray *subviews = [sv subviews];
8560 object = [subviews firstObject];
8746 } 8561 }
8747 WindowData *blah = (WindowData *)[object userdata]; 8562 WindowData *blah = (WindowData *)[object userdata];
8748 8563
8749 if(blah && blah->root && dataname) 8564 if(blah && blah->root && dataname)
8750 { 8565 {
9831 _DWDirtyDrawables = [[NSMutableArray alloc] init]; 9646 _DWDirtyDrawables = [[NSMutableArray alloc] init];
9832 /* Use NSThread to start a dummy thread to initialize the threading subsystem */ 9647 /* Use NSThread to start a dummy thread to initialize the threading subsystem */
9833 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil]; 9648 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil];
9834 [thread start]; 9649 [thread start];
9835 [thread release]; 9650 [thread release];
9836 [UITextField setCellClass:[DWTextFieldCell class]];
9837 if(!_dw_app_id[0]) 9651 if(!_dw_app_id[0])
9838 { 9652 {
9839 /* Generate an Application ID based on the PID if all else fails. */ 9653 /* Generate an Application ID based on the PID if all else fails. */
9840 snprintf(_dw_app_id, _DW_APP_ID_SIZE, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid()); 9654 snprintf(_dw_app_id, _DW_APP_ID_SIZE, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
9841 } 9655 }