Mercurial > dwindows
comparison ios/dw.m @ 2383:a410d42d9e36
iOS: Implement classes for encapsulating immutable UIImage and UIMenu so the
handles don't change when we recreate these objects. More conversion to iOS.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 21 Mar 2021 21:48:19 +0000 |
parents | 41a04e6b3e8e |
children | 32ebd33be56b |
comparison
equal
deleted
inserted
replaced
2382:41a04e6b3e8e | 2383:a410d42d9e36 |
---|---|
586 -(void)doBitBlt:(id)param; | 586 -(void)doBitBlt:(id)param; |
587 -(void)doFlush:(id)param; | 587 -(void)doFlush:(id)param; |
588 @end | 588 @end |
589 | 589 |
590 API_AVAILABLE(ios(13.0)) | 590 API_AVAILABLE(ios(13.0)) |
591 @interface DWMenuItem : UIMenuItem | 591 @interface DWMenuItem : UICommand |
592 { | 592 { |
593 int check; | 593 int check; |
594 unsigned long tag; | |
594 } | 595 } |
595 -(void)setCheck:(int)input; | 596 -(void)setCheck:(int)input; |
597 -(void)setTag:(unsigned long)input; | |
596 -(int)check; | 598 -(int)check; |
599 -(unsigned long)tag; | |
597 -(void)dealloc; | 600 -(void)dealloc; |
598 @end | 601 @end |
602 | |
603 API_AVAILABLE(ios(13.0)) | |
604 @interface DWMenu : NSObject | |
605 { | |
606 UIMenu *menu; | |
607 } | |
608 -(void)setMenu:(UIMenu *)input; | |
609 -(UIMenu *)menu; | |
610 -(DWMenuItem *)itemWithTag:(unsigned long)tag; | |
611 -(void)dealloc; | |
612 @end | |
613 | |
599 | 614 |
600 /* So basically to implement our event handlers... | 615 /* So basically to implement our event handlers... |
601 * it looks like we are going to have to subclass | 616 * it looks like we are going to have to subclass |
602 * basically everything. Was hoping to add methods | 617 * basically everything. Was hoping to add methods |
603 * to the superclasses but it looks like you can | 618 * to the superclasses but it looks like you can |
620 -(void)setUserdata:(void *)input; | 635 -(void)setUserdata:(void *)input; |
621 -(void)drawRect:(CGRect)rect; | 636 -(void)drawRect:(CGRect)rect; |
622 -(BOOL)isFlipped; | 637 -(BOOL)isFlipped; |
623 -(void)mouseDown:(UIEvent *)theEvent; | 638 -(void)mouseDown:(UIEvent *)theEvent; |
624 -(void)mouseUp:(UIEvent *)theEvent; | 639 -(void)mouseUp:(UIEvent *)theEvent; |
625 -(UIMenu *)menuForEvent:(UIEvent *)theEvent; | 640 -(DWMenu *)menuForEvent:(UIEvent *)theEvent; |
626 -(void)rightMouseUp:(UIEvent *)theEvent; | 641 -(void)rightMouseUp:(UIEvent *)theEvent; |
627 -(void)otherMouseDown:(UIEvent *)theEvent; | 642 -(void)otherMouseDown:(UIEvent *)theEvent; |
628 -(void)otherMouseUp:(UIEvent *)theEvent; | 643 -(void)otherMouseUp:(UIEvent *)theEvent; |
629 -(void)keyDown:(UIEvent *)theEvent; | 644 -(void)keyDown:(UIEvent *)theEvent; |
630 -(void)setColor:(unsigned long)input; | 645 -(void)setColor:(unsigned long)input; |
667 } | 682 } |
668 } | 683 } |
669 -(BOOL)isFlipped { return YES; } | 684 -(BOOL)isFlipped { return YES; } |
670 -(void)mouseDown:(UIEvent *)theEvent { _event_handler(self, (void *)1, 3); } | 685 -(void)mouseDown:(UIEvent *)theEvent { _event_handler(self, (void *)1, 3); } |
671 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)1, 4); } | 686 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)1, 4); } |
672 -(UIMenu *)menuForEvent:(UIEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } | 687 -(DWMenu *)menuForEvent:(UIEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } |
673 -(void)rightMouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)2, 4); } | 688 -(void)rightMouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)2, 4); } |
674 -(void)otherMouseDown:(UIEvent *)theEvent { _event_handler(self, (void *)3, 3); } | 689 -(void)otherMouseDown:(UIEvent *)theEvent { _event_handler(self, (void *)3, 3); } |
675 -(void)otherMouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)3, 4); } | 690 -(void)otherMouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)3, 4); } |
676 -(void)keyDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 2); } | 691 -(void)keyDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 2); } |
677 -(void)setColor:(unsigned long)input | 692 -(void)setColor:(unsigned long)input |
745 -(void)setSize:(CGSize)input; | 760 -(void)setSize:(CGSize)input; |
746 -(CGSize)size; | 761 -(CGSize)size; |
747 -(UIImage *)cachedDrawingRep; | 762 -(UIImage *)cachedDrawingRep; |
748 -(void)mouseDown:(UIEvent *)theEvent; | 763 -(void)mouseDown:(UIEvent *)theEvent; |
749 -(void)mouseUp:(UIEvent *)theEvent; | 764 -(void)mouseUp:(UIEvent *)theEvent; |
750 -(UIMenu *)menuForEvent:(UIEvent *)theEvent; | 765 -(DWMenu *)menuForEvent:(UIEvent *)theEvent; |
751 -(void)rightMouseUp:(UIEvent *)theEvent; | 766 -(void)rightMouseUp:(UIEvent *)theEvent; |
752 -(void)otherMouseDown:(UIEvent *)theEvent; | 767 -(void)otherMouseDown:(UIEvent *)theEvent; |
753 -(void)otherMouseUp:(UIEvent *)theEvent; | 768 -(void)otherMouseUp:(UIEvent *)theEvent; |
754 -(void)drawRect:(CGRect)rect; | 769 -(void)drawRect:(CGRect)rect; |
755 -(void)keyDown:(UIEvent *)theEvent; | 770 -(void)keyDown:(UIEvent *)theEvent; |
793 { | 808 { |
794 if(![theEvent isMemberOfClass:[UIEvent class]]) | 809 if(![theEvent isMemberOfClass:[UIEvent class]]) |
795 _event_handler(self, theEvent, 3); | 810 _event_handler(self, theEvent, 3); |
796 } | 811 } |
797 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } | 812 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } |
798 -(UIMenu *)menuForEvent:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } | 813 -(DWMenu *)menuForEvent:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } |
799 -(void)rightMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } | 814 -(void)rightMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } |
800 -(void)otherMouseDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); } | 815 -(void)otherMouseDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); } |
801 -(void)otherMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } | 816 -(void)otherMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } |
802 -(void)mouseDragged:(UIEvent *)theEvent { _event_handler(self, theEvent, 5); } | 817 -(void)mouseDragged:(UIEvent *)theEvent { _event_handler(self, theEvent, 5); } |
803 -(void)drawRect:(CGRect)rect { | 818 -(void)drawRect:(CGRect)rect { |
979 @end | 994 @end |
980 | 995 |
981 /* Subclass for a top-level window */ | 996 /* Subclass for a top-level window */ |
982 @interface DWView : DWBox /* <UIWindowDelegate> */ | 997 @interface DWView : DWBox /* <UIWindowDelegate> */ |
983 { | 998 { |
984 UIMenu *windowmenu; | 999 DWMenu *windowmenu; |
985 CGSize oldsize; | 1000 CGSize oldsize; |
986 } | 1001 } |
987 -(BOOL)windowShouldClose:(id)sender; | 1002 -(BOOL)windowShouldClose:(id)sender; |
988 -(void)setMenu:(UIMenu *)input; | 1003 -(void)setMenu:(DWMenu *)input; |
989 -(void)windowDidBecomeMain:(id)sender; | 1004 -(void)windowDidBecomeMain:(id)sender; |
990 -(void)menuHandler:(id)sender; | 1005 -(void)menuHandler:(id)sender; |
991 @end | 1006 @end |
992 | 1007 |
993 @implementation DWView | 1008 @implementation DWView |
1040 } | 1055 } |
1041 -(void)windowDidBecomeMain:(id)sender | 1056 -(void)windowDidBecomeMain:(id)sender |
1042 { | 1057 { |
1043 _event_handler([self window], nil, 13); | 1058 _event_handler([self window], nil, 13); |
1044 } | 1059 } |
1045 -(void)setMenu:(UIMenu *)input { windowmenu = input; [windowmenu retain]; } | 1060 -(void)setMenu:(DWMenu *)input { windowmenu = input; [windowmenu retain]; } |
1046 -(void)menuHandler:(id)sender | 1061 -(void)menuHandler:(id)sender |
1047 { | 1062 { |
1048 [DWObj menuHandler:sender]; | 1063 [DWObj menuHandler:sender]; |
1049 } | 1064 } |
1050 @end | 1065 @end |
1093 @end | 1108 @end |
1094 | 1109 |
1095 /* Subclass for a menu item type */ | 1110 /* Subclass for a menu item type */ |
1096 @implementation DWMenuItem | 1111 @implementation DWMenuItem |
1097 -(void)setCheck:(int)input { check = input; } | 1112 -(void)setCheck:(int)input { check = input; } |
1113 -(void)setTag:(unsigned long)input { tag = input; } | |
1098 -(int)check { return check; } | 1114 -(int)check { return check; } |
1115 -(unsigned long)tag { return tag; } | |
1099 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; } | 1116 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; } |
1117 @end | |
1118 /* | |
1119 * Encapsulate immutable objects in our own containers, | |
1120 * so we can recreate the immutable subobjects as needed. | |
1121 * Currently in this category: DWMenu and DWImage | |
1122 */ | |
1123 @implementation DWMenu | |
1124 -(void)setMenu:(UIMenu *)input { menu = input; } | |
1125 -(UIMenu *)menu { return menu; } | |
1126 -(DWMenuItem *)itemWithTag:(unsigned long)tag | |
1127 { | |
1128 NSArray *children = [menu children]; | |
1129 | |
1130 for(DWMenuItem *menuitem in children) | |
1131 { | |
1132 if([menuitem tag] == tag) | |
1133 return menuitem; | |
1134 } | |
1135 return nil; | |
1136 } | |
1137 -(void)dealloc { [super dealloc]; } | |
1138 @end | |
1139 | |
1140 @interface DWImage : NSObject | |
1141 { | |
1142 UIImage *image; | |
1143 CGImageRef cgimage; | |
1144 } | |
1145 -(void)setImage:(UIImage *)input; | |
1146 -(void)setCGImage:(CGImageRef)input; | |
1147 -(UIImage *)image; | |
1148 -(CGImageRef)cgimage; | |
1149 -(void)dealloc; | |
1150 @end | |
1151 | |
1152 @implementation DWImage | |
1153 -(void)setImage:(UIImage *)input { image = input; } | |
1154 -(void)setCGImage:(CGImageRef)input { cgimage = input; } | |
1155 -(UIImage *)image { return image; } | |
1156 -(CGImageRef)cgimage { return cgimage; } | |
1157 -(void)dealloc { if(cgimage) CGImageRelease(cgimage); if(image) [image release]; [super dealloc]; } | |
1100 @end | 1158 @end |
1101 | 1159 |
1102 /* Subclass for a scrollbox type */ | 1160 /* Subclass for a scrollbox type */ |
1103 @interface DWScrollBox : UIScrollView | 1161 @interface DWScrollBox : UIScrollView |
1104 { | 1162 { |
1188 -(void *)userdata { return userdata; } | 1246 -(void *)userdata { return userdata; } |
1189 -(void)setUserdata:(void *)input { userdata = input; } | 1247 -(void)setUserdata:(void *)input { userdata = input; } |
1190 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 1248 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
1191 @end | 1249 @end |
1192 | 1250 |
1193 | |
1194 /* Subclass for a Notebook control type */ | |
1195 @interface DWNotebook : UISegmentedControl | |
1196 { | |
1197 void *userdata; | |
1198 int pageid; | |
1199 } | |
1200 -(void *)userdata; | |
1201 -(void)setUserdata:(void *)input; | |
1202 -(int)pageid; | |
1203 -(void)setPageid:(int)input; | |
1204 -(void)pageChanged:(id)sender; | |
1205 @end | |
1206 | |
1207 /* Subclass for a Notebook page type */ | 1251 /* Subclass for a Notebook page type */ |
1208 @interface DWNotebookPage : UIView | 1252 @interface DWNotebookPage : UIView |
1209 { | 1253 { |
1210 void *userdata; | 1254 void *userdata; |
1211 int pageid; | 1255 int pageid; |
1214 -(void)setUserdata:(void *)input; | 1258 -(void)setUserdata:(void *)input; |
1215 -(int)pageid; | 1259 -(int)pageid; |
1216 -(void)setPageid:(int)input; | 1260 -(void)setPageid:(int)input; |
1217 @end | 1261 @end |
1218 | 1262 |
1263 /* Subclass for a Notebook control type */ | |
1264 @interface DWNotebook : UISegmentedControl | |
1265 { | |
1266 void *userdata; | |
1267 int pageid; | |
1268 NSMutableArray<DWNotebookPage *> *views; | |
1269 } | |
1270 -(void *)userdata; | |
1271 -(void)setUserdata:(void *)input; | |
1272 -(int)pageid; | |
1273 -(void)setPageid:(int)input; | |
1274 -(NSMutableArray<DWNotebookPage *> *)views; | |
1275 -(void)pageChanged:(id)sender; | |
1276 @end | |
1277 | |
1219 @implementation DWNotebook | 1278 @implementation DWNotebook |
1220 -(void *)userdata { return userdata; } | 1279 -(void *)userdata { return userdata; } |
1221 -(void)setUserdata:(void *)input { userdata = input; } | 1280 -(void)setUserdata:(void *)input { userdata = input; } |
1222 -(int)pageid { return pageid; } | 1281 -(int)pageid { return pageid; } |
1223 -(void)setPageid:(int)input { pageid = input; } | 1282 -(void)setPageid:(int)input { pageid = input; } |
1283 -(NSMutableArray<DWNotebookPage *> *)views { return views; }; | |
1224 -(void)pageChanged:(id)sender | 1284 -(void)pageChanged:(id)sender |
1225 { | 1285 { |
1226 #if 0 /* TODO: Implement page/segment changed handler */ | 1286 #if 0 /* TODO: Implement page/segment changed handler */ |
1227 id object = [notepage view]; | 1287 id object = [notepage view]; |
1228 DWNotebookPage *page = (DWNotebookPage *)notepage; | 1288 DWNotebookPage *page = (DWNotebookPage *)notepage; |
1248 -(void)setPageid:(int)input { pageid = input; } | 1308 -(void)setPageid:(int)input { pageid = input; } |
1249 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } | 1309 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } |
1250 @end | 1310 @end |
1251 | 1311 |
1252 /* Subclass for a splitbar type */ | 1312 /* Subclass for a splitbar type */ |
1253 @interface DWSplitBar : UISplitViewController | 1313 @interface DWSplitBar : UISplitViewController <UISplitViewControllerDelegate> |
1254 { | 1314 { |
1255 void *userdata; | 1315 void *userdata; |
1256 float percent; | 1316 float percent; |
1257 NSInteger Tag; | 1317 NSInteger Tag; |
1258 } | 1318 } |
1408 -(void)setup; | 1468 -(void)setup; |
1409 -(CGSize)getsize; | 1469 -(CGSize)getsize; |
1410 -(void)setForegroundColor:(UIColor *)input; | 1470 -(void)setForegroundColor:(UIColor *)input; |
1411 -(void)doubleClicked:(id)sender; | 1471 -(void)doubleClicked:(id)sender; |
1412 -(void)selectionChanged:(id)sender; | 1472 -(void)selectionChanged:(id)sender; |
1413 -(UIMenu *)menuForEvent:(UIEvent *)event; | 1473 -(DWMenu *)menuForEvent:(UIEvent *)event; |
1414 @end | 1474 @end |
1415 | 1475 |
1416 @implementation DWContainer | 1476 @implementation DWContainer |
1417 -(NSInteger)numberOfRowsInTableView:(UITableView *)aTable | 1477 -(NSInteger)numberOfRowsInTableView:(UITableView *)aTable |
1418 { | 1478 { |
1799 /* Handler for container class */ | 1859 /* Handler for container class */ |
1800 _event_handler(self, (UIEvent *)params, 12); | 1860 _event_handler(self, (UIEvent *)params, 12); |
1801 /* Handler for listbox class */ | 1861 /* Handler for listbox class */ |
1802 _event_handler(self, DW_INT_TO_POINTER((int)[self indexPathForSelectedRow].row), 11); | 1862 _event_handler(self, DW_INT_TO_POINTER((int)[self indexPathForSelectedRow].row), 11); |
1803 } | 1863 } |
1804 -(UIMenu *)menuForEvent:(UIEvent *)event | 1864 -(DWMenu *)menuForEvent:(UIEvent *)event |
1805 { | 1865 { |
1806 #if 0 /* TODO: Fix this */ | 1866 #if 0 /* TODO: Fix this */ |
1807 int row; | 1867 int row; |
1808 CGPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; | 1868 CGPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; |
1809 row = (int)[self rowAtPoint:where]; | 1869 row = (int)[self rowAtPoint:where]; |
3409 * handle: Handle to the spinbutton to be set. | 3469 * handle: Handle to the spinbutton to be set. |
3410 * limit: Number of characters the entryfield will take. | 3470 * limit: Number of characters the entryfield will take. |
3411 */ | 3471 */ |
3412 void API dw_entryfield_set_limit(HWND handle, ULONG limit) | 3472 void API dw_entryfield_set_limit(HWND handle, ULONG limit) |
3413 { | 3473 { |
3474 #if 0 /* TODO: Implment this via textField:shouldChangeCharactersInRange:replacementString: */ | |
3414 DWEntryField *entry = handle; | 3475 DWEntryField *entry = handle; |
3415 DWEntryFieldFormatter *formatter = [[[DWEntryFieldFormatter alloc] init] autorelease]; | 3476 DWEntryFieldFormatter *formatter = [[[DWEntryFieldFormatter alloc] init] autorelease]; |
3416 | 3477 |
3417 [formatter setMaximumLength:(int)limit]; | 3478 [formatter setMaximumLength:(int)limit]; |
3418 [entry setFormatter:formatter]; | 3479 [entry setFormatter:formatter]; |
3480 #endif | |
3419 } | 3481 } |
3420 | 3482 |
3421 /* | 3483 /* |
3422 * Create a new bitmap button window (widget) to be packed. | 3484 * Create a new bitmap button window (widget) to be packed. |
3423 * Parameters: | 3485 * Parameters: |
4692 UIBezierPath* aPath = [UIBezierPath bezierPath]; | 4754 UIBezierPath* aPath = [UIBezierPath bezierPath]; |
4693 UIColor *color = pthread_getspecific(_dw_fg_color_key); | 4755 UIColor *color = pthread_getspecific(_dw_fg_color_key); |
4694 [color set]; | 4756 [color set]; |
4695 | 4757 |
4696 [aPath moveToPoint:CGPointMake(x1 + 0.5, y1 + 0.5)]; | 4758 [aPath moveToPoint:CGPointMake(x1 + 0.5, y1 + 0.5)]; |
4697 [aPath lineToPoint:CGPointMake(x2 + 0.5, y2 + 0.5)]; | 4759 [aPath addLineToPoint:CGPointMake(x2 + 0.5, y2 + 0.5)]; |
4698 [aPath stroke]; | 4760 [aPath stroke]; |
4699 } | 4761 } |
4700 | 4762 |
4701 if(bi) | 4763 if(bi) |
4702 UIGraphicsEndImageContext(); | 4764 UIGraphicsEndImageContext(); |
5885 { | 5947 { |
5886 thistext = [cont getRowTitle:x]; | 5948 thistext = [cont getRowTitle:x]; |
5887 | 5949 |
5888 if(thistext && strcmp(thistext, text) == 0) | 5950 if(thistext && strcmp(thistext, text) == 0) |
5889 { | 5951 { |
5890 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x]; | 5952 NSIndexPath *ip = [NSIndexPath indexPathForRow:(NSUInteger)x inSection:0]; |
5891 | 5953 |
5892 [cont selectRowIndexes:selected byExtendingSelection:YES]; | 5954 [cont selectRowAtIndexPath:ip |
5893 [selected release]; | 5955 animated:NO |
5894 [cont scrollRowToVisible:x]; | 5956 scrollPosition:UITableViewScrollPositionNone]; |
5895 x=count; | 5957 x=count; |
5896 break; | 5958 break; |
5897 } | 5959 } |
5898 } | 5960 } |
5899 DW_LOCAL_POOL_OUT; | 5961 DW_LOCAL_POOL_OUT; |
5921 { | 5983 { |
5922 thisdata = [cont getRowData:x]; | 5984 thisdata = [cont getRowData:x]; |
5923 | 5985 |
5924 if(thisdata == data) | 5986 if(thisdata == data) |
5925 { | 5987 { |
5926 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x]; | 5988 NSIndexPath *ip = [NSIndexPath indexPathForRow:(NSUInteger)x inSection:0]; |
5927 | 5989 |
5928 [cont selectRowIndexes:selected byExtendingSelection:YES]; | 5990 [cont selectRowAtIndexPath:ip |
5929 [selected release]; | 5991 animated:NO |
5930 [cont scrollRowToVisible:x]; | 5992 scrollPosition:UITableViewScrollPositionNone]; |
5931 x=count; | 5993 x=count; |
5932 break; | 5994 break; |
5933 } | 5995 } |
5934 } | 5996 } |
5935 DW_LOCAL_POOL_OUT; | 5997 DW_LOCAL_POOL_OUT; |
6039 { | 6101 { |
6040 if(size.width > 24) | 6102 if(size.width > 24) |
6041 size.width = 24; | 6103 size.width = 24; |
6042 if(size.height > 24) | 6104 if(size.height > 24) |
6043 size.height = 24; | 6105 size.height = 24; |
6106 #if 0 /* TODO: UIImage is immutable, duplicate? */ | |
6044 [image setSize:size]; | 6107 [image setSize:size]; |
6108 #endif | |
6045 } | 6109 } |
6046 } | 6110 } |
6047 } | 6111 } |
6048 | 6112 |
6049 /* Internal version that does not resize the image */ | 6113 /* Internal version that does not resize the image */ |
6145 * topleft: Handle to the window to be top or left. | 6209 * topleft: Handle to the window to be top or left. |
6146 * bottomright: Handle to the window to be bottom or right. | 6210 * bottomright: Handle to the window to be bottom or right. |
6147 * Returns: | 6211 * Returns: |
6148 * A handle to a splitbar window or NULL on failure. | 6212 * A handle to a splitbar window or NULL on failure. |
6149 */ | 6213 */ |
6150 DW_FUNCTION_DEFINITION(dw_splitbar_new, HWND, int type, HWND topleft, HWND bottomright, unsigned long cid) | 6214 DW_FUNCTION_DEFINITION(dw_splitbar_new, HWND, DW_UNUSED(int type), HWND topleft, HWND bottomright, unsigned long cid) |
6151 DW_FUNCTION_ADD_PARAM4(type, topleft, bottomright, cid) | 6215 DW_FUNCTION_ADD_PARAM4(type, topleft, bottomright, cid) |
6152 DW_FUNCTION_RETURN(dw_splitbar_new, HWND) | 6216 DW_FUNCTION_RETURN(dw_splitbar_new, HWND) |
6153 DW_FUNCTION_RESTORE_PARAM4(type, int, topleft, HWND, bottomright, HWND, cid, unsigned long) | 6217 DW_FUNCTION_RESTORE_PARAM4(DW_UNUSED(type), int, topleft, HWND, bottomright, HWND, cid, unsigned long) |
6154 { | 6218 { |
6155 DW_FUNCTION_INIT; | 6219 DW_FUNCTION_INIT; |
6156 id tmpbox = dw_box_new(DW_VERT, 0); | 6220 id tmpbox = dw_box_new(DW_VERT, 0); |
6157 DWSplitBar *split = [[DWSplitBar alloc] init]; | 6221 DWSplitBar *split = [[DWSplitBar alloc] init]; |
6222 UIViewController *vc = [[UIViewController alloc] init]; | |
6158 [split setDelegate:split]; | 6223 [split setDelegate:split]; |
6159 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); | 6224 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); |
6160 [split addSubview:tmpbox]; | 6225 [vc setView:tmpbox]; |
6226 if (@available(iOS 14.0, *)) { | |
6227 [split setViewController:vc forColumn:UISplitViewControllerColumnPrimary]; | |
6228 } else { | |
6229 [split addChildViewController:vc]; | |
6230 } | |
6161 [tmpbox autorelease]; | 6231 [tmpbox autorelease]; |
6162 tmpbox = dw_box_new(DW_VERT, 0); | 6232 tmpbox = dw_box_new(DW_VERT, 0); |
6163 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); | 6233 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); |
6164 [split addSubview:tmpbox]; | 6234 vc = [[UIViewController alloc] init]; |
6235 [vc setView:tmpbox]; | |
6236 if (@available(iOS 14.0, *)) { | |
6237 [split setViewController:vc forColumn:UISplitViewControllerColumnSecondary]; | |
6238 } else { | |
6239 [split addChildViewController:vc]; | |
6240 } | |
6165 [tmpbox autorelease]; | 6241 [tmpbox autorelease]; |
6166 if(type == DW_VERT) | 6242 #if 0 /* TODO: All iOS splitbars are vertical */ |
6167 { | 6243 [split setVertical:(type == DW_VERT ? YES : NO)]; |
6168 [split setVertical:NO]; | 6244 #endif |
6169 } | |
6170 else | |
6171 { | |
6172 [split setVertical:YES]; | |
6173 } | |
6174 /* Set the default percent to 50% split */ | 6245 /* Set the default percent to 50% split */ |
6175 [split setPercent:50.0]; | 6246 [split setPercent:50.0]; |
6176 [split setTag:cid]; | 6247 [split setTag:cid]; |
6177 DW_FUNCTION_RETURN_THIS(split); | 6248 DW_FUNCTION_RETURN_THIS(split); |
6178 } | 6249 } |
6188 DW_FUNCTION_NO_RETURN(dw_splitbar_set) | 6259 DW_FUNCTION_NO_RETURN(dw_splitbar_set) |
6189 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, percent, float) | 6260 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, percent, float) |
6190 { | 6261 { |
6191 DW_FUNCTION_INIT; | 6262 DW_FUNCTION_INIT; |
6192 DWSplitBar *split = handle; | 6263 DWSplitBar *split = handle; |
6193 CGRect rect = [split frame]; | 6264 CGSize size = [split preferredContentSize]; |
6194 float pos; | 6265 float pos; |
6195 /* Calculate the position based on the size */ | 6266 /* Calculate the position based on the size */ |
6196 if([split isVertical]) | 6267 #if 0 /* TODO: iOS split views are always vertical */ |
6197 { | 6268 if(![split isVertical]) |
6198 pos = rect.size.width * (percent / 100.0); | 6269 pos = size.height * (percent / 100.0); |
6199 } | |
6200 else | 6270 else |
6201 { | 6271 #endif |
6202 pos = rect.size.height * (percent / 100.0); | 6272 pos = size.width * (percent / 100.0); |
6203 } | |
6204 if(pos > 0) | 6273 if(pos > 0) |
6205 { | 6274 { |
6206 [split setPosition:pos ofDividerAtIndex:0]; | 6275 if (@available(iOS 14.0, *)) { |
6276 [split setPreferredPrimaryColumnWidth:pos]; | |
6277 } else { | |
6278 /* TODO: Is this possible on earlier versions? */ | |
6279 } | |
6207 } | 6280 } |
6208 else | 6281 else |
6209 { | 6282 { |
6210 /* If we have no size.. wait until the resize | 6283 /* If we have no size.. wait until the resize |
6211 * event when we get an actual size to try | 6284 * event when we get an actual size to try |
6222 * handle: The handle to the splitbar returned by dw_splitbar_new(). | 6295 * handle: The handle to the splitbar returned by dw_splitbar_new(). |
6223 */ | 6296 */ |
6224 float API dw_splitbar_get(HWND handle) | 6297 float API dw_splitbar_get(HWND handle) |
6225 { | 6298 { |
6226 DWSplitBar *split = handle; | 6299 DWSplitBar *split = handle; |
6227 CGRect rect1 = [split frame]; | 6300 float retval = 50.0; |
6228 NSArray *subviews = [split subviews]; | 6301 |
6229 UIView *view = [subviews firstObject]; | 6302 if (@available(iOS 14.0, *)) { |
6230 CGRect rect2 = [view frame]; | 6303 float primary = [split primaryColumnWidth]; |
6231 float pos, total, retval = 0.0; | 6304 float supplementary = [split supplementaryColumnWidth]; |
6232 if([split isVertical]) | 6305 retval = (primary / (primary + supplementary)) * 100.0; |
6233 { | 6306 } else { |
6234 total = rect1.size.width; | 6307 /* TODO: If possible*/ |
6235 pos = rect2.size.width; | |
6236 } | |
6237 else | |
6238 { | |
6239 total = rect1.size.height; | |
6240 pos = rect2.size.height; | |
6241 } | |
6242 if(total > 0) | |
6243 { | |
6244 retval = pos / total; | |
6245 } | 6308 } |
6246 return retval; | 6309 return retval; |
6247 } | 6310 } |
6248 | 6311 |
6249 /* Internal function to convert fontname to UIFont */ | 6312 /* Internal function to convert fontname to UIFont */ |
6597 * id: An ID to be used with dw_window_from_id() or 0L. | 6660 * id: An ID to be used with dw_window_from_id() or 0L. |
6598 */ | 6661 */ |
6599 HWND API dw_calendar_new(ULONG cid) | 6662 HWND API dw_calendar_new(ULONG cid) |
6600 { | 6663 { |
6601 DWCalendar *calendar = [[DWCalendar alloc] init]; | 6664 DWCalendar *calendar = [[DWCalendar alloc] init]; |
6602 [calendar setDatePickerMode:DWDatePickerModeSingle]; | 6665 [calendar setDatePickerMode:UIDatePickerModeDate]; |
6603 [calendar setDatePickerStyle:DWDatePickerStyleClockAndCalendar]; | |
6604 [calendar setDatePickerElements:DWDatePickerElementFlagYearMonthDay]; | |
6605 [calendar setTag:cid]; | 6666 [calendar setTag:cid]; |
6606 [calendar setDateValue:[NSDate date]]; | 6667 [calendar setDate:[NSDate date]]; |
6607 return calendar; | 6668 return calendar; |
6608 } | 6669 } |
6609 | 6670 |
6610 /* | 6671 /* |
6611 * Sets the current date of a calendar. | 6672 * Sets the current date of a calendar. |
6624 | 6685 |
6625 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; | 6686 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; |
6626 dateFormatter.dateFormat = @"yyyy-MM-dd"; | 6687 dateFormatter.dateFormat = @"yyyy-MM-dd"; |
6627 | 6688 |
6628 date = [dateFormatter dateFromString:[NSString stringWithUTF8String:buffer]]; | 6689 date = [dateFormatter dateFromString:[NSString stringWithUTF8String:buffer]]; |
6629 [calendar setDateValue:date]; | 6690 [calendar setDate:date]; |
6630 [date release]; | 6691 [date release]; |
6631 DW_LOCAL_POOL_OUT; | 6692 DW_LOCAL_POOL_OUT; |
6632 } | 6693 } |
6633 | 6694 |
6634 /* | 6695 /* |
6638 */ | 6699 */ |
6639 void dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day) | 6700 void dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day) |
6640 { | 6701 { |
6641 DWCalendar *calendar = handle; | 6702 DWCalendar *calendar = handle; |
6642 DW_LOCAL_POOL_IN; | 6703 DW_LOCAL_POOL_IN; |
6643 NSCalendar *mycalendar = [[NSCalendar alloc] initWithCalendarIdentifier:DWCalendarIdentifierGregorian]; | 6704 NSCalendar *mycalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; |
6644 NSDate *date = [calendar dateValue]; | 6705 NSDate *date = [calendar date]; |
6645 NSDateComponents* components = [mycalendar components:DWCalendarUnitDay|DWCalendarUnitMonth|DWCalendarUnitYear fromDate:date]; | 6706 NSDateComponents* components = [mycalendar components:NSCalendarUnitDay|NSCalendarUnitMonth|NSCalendarUnitYear fromDate:date]; |
6646 *day = (unsigned int)[components day]; | 6707 *day = (unsigned int)[components day]; |
6647 *month = (unsigned int)[components month]; | 6708 *month = (unsigned int)[components month]; |
6648 *year = (unsigned int)[components year]; | 6709 *year = (unsigned int)[components year]; |
6649 [mycalendar release]; | 6710 [mycalendar release]; |
6650 DW_LOCAL_POOL_OUT; | 6711 DW_LOCAL_POOL_OUT; |
6671 dw_html_url(handle, DW_HOME_URL); | 6732 dw_html_url(handle, DW_HOME_URL); |
6672 break; | 6733 break; |
6673 case DW_HTML_SEARCH: | 6734 case DW_HTML_SEARCH: |
6674 break; | 6735 break; |
6675 case DW_HTML_RELOAD: | 6736 case DW_HTML_RELOAD: |
6676 [html reload:html]; | 6737 [html reload]; |
6677 break; | 6738 break; |
6678 case DW_HTML_STOP: | 6739 case DW_HTML_STOP: |
6679 [html stopLoading:html]; | 6740 [html stopLoading]; |
6680 break; | 6741 break; |
6681 case DW_HTML_PRINT: | 6742 case DW_HTML_PRINT: |
6682 break; | 6743 break; |
6683 } | 6744 } |
6684 } | 6745 } |
6764 * x: Pointer to variable to store X coordinate. | 6825 * x: Pointer to variable to store X coordinate. |
6765 * y: Pointer to variable to store Y coordinate. | 6826 * y: Pointer to variable to store Y coordinate. |
6766 */ | 6827 */ |
6767 void API dw_pointer_query_pos(long *x, long *y) | 6828 void API dw_pointer_query_pos(long *x, long *y) |
6768 { | 6829 { |
6769 CGPoint mouseLoc; | |
6770 mouseLoc = [UIEvent mouseLocation]; | |
6771 if(x) | 6830 if(x) |
6772 { | 6831 { |
6773 *x = mouseLoc.x; | 6832 *x = 0; |
6774 } | 6833 } |
6775 if(y) | 6834 if(y) |
6776 { | 6835 { |
6777 *y = [[NSScreen mainScreen] frame].size.height - mouseLoc.y; | 6836 *y = 0; |
6778 } | 6837 } |
6779 } | 6838 } |
6780 | 6839 |
6781 /* | 6840 /* |
6782 * Sets the X and Y coordinates of the mouse pointer. | 6841 * Sets the X and Y coordinates of the mouse pointer. |
6795 * id: An ID to be used for getting the resource from the | 6854 * id: An ID to be used for getting the resource from the |
6796 * resource file. | 6855 * resource file. |
6797 */ | 6856 */ |
6798 HMENUI API dw_menu_new(ULONG cid) | 6857 HMENUI API dw_menu_new(ULONG cid) |
6799 { | 6858 { |
6800 UIMenu *menu = [[UIMenu alloc] init]; | 6859 DWMenu *menu = [[DWMenu alloc] init]; |
6801 [menu setAutoenablesItems:NO]; | |
6802 /* [menu setTag:cid]; Why doesn't this work? */ | 6860 /* [menu setTag:cid]; Why doesn't this work? */ |
6803 return menu; | 6861 return menu; |
6804 } | 6862 } |
6805 | 6863 |
6806 /* | 6864 /* |
6808 * Parameters: | 6866 * Parameters: |
6809 * location: Handle of a window frame to be attached to. | 6867 * location: Handle of a window frame to be attached to. |
6810 */ | 6868 */ |
6811 HMENUI API dw_menubar_new(HWND location) | 6869 HMENUI API dw_menubar_new(HWND location) |
6812 { | 6870 { |
6813 UIWindow *window = location; | 6871 /* TODO: Implement this with UIMenuSystem */ |
6814 UIMenu *windowmenu = _generate_main_menu(); | 6872 return NULL; |
6815 [[window contentView] setMenu:windowmenu]; | |
6816 return (HMENUI)windowmenu; | |
6817 } | 6873 } |
6818 | 6874 |
6819 /* | 6875 /* |
6820 * Destroys a menu created with dw_menubar_new or dw_menu_new. | 6876 * Destroys a menu created with dw_menubar_new or dw_menu_new. |
6821 * Parameters: | 6877 * Parameters: |
6822 * menu: Handle of a menu. | 6878 * menu: Handle of a menu. |
6823 */ | 6879 */ |
6824 void API dw_menu_destroy(HMENUI *menu) | 6880 void API dw_menu_destroy(HMENUI *menu) |
6825 { | 6881 { |
6826 UIMenu *thismenu = *menu; | 6882 DWMenu *thismenu = *menu; |
6827 DW_LOCAL_POOL_IN; | 6883 DW_LOCAL_POOL_IN; |
6828 [thismenu release]; | 6884 [thismenu release]; |
6829 DW_LOCAL_POOL_OUT; | 6885 DW_LOCAL_POOL_OUT; |
6830 } | |
6831 | |
6832 /* Handle deprecation of convertScreenToBase in 10.10 yet still supporting | |
6833 * 10.6 and earlier since convertRectFromScreen was introduced in 10.7. | |
6834 */ | |
6835 CGPoint _windowPointFromScreen(id window, CGPoint p) | |
6836 { | |
6837 SEL crfs = NSSelectorFromString(@"convertRectFromScreen:"); | |
6838 | |
6839 if([window respondsToSelector:crfs]) | |
6840 { | |
6841 CGRect (* icrfs)(id, SEL, CGRect) = (CGRect (*)(id, SEL, CGRect))[window methodForSelector:crfs]; | |
6842 CGRect rect = icrfs(window, crfs, NSMakeRect(p.x, p.y, 1, 1)); | |
6843 return rect.origin; | |
6844 } | |
6845 else | |
6846 { | |
6847 SEL cstb = NSSelectorFromString(@"convertScreenToBase:"); | |
6848 | |
6849 if([window respondsToSelector:cstb]) | |
6850 { | |
6851 CGPoint (* icstb)(id, SEL, CGPoint) = (CGPoint (*)(id, SEL, CGPoint))[window methodForSelector:cstb]; | |
6852 return icstb(window, cstb, p); | |
6853 } | |
6854 } | |
6855 return NSMakePoint(0,0); | |
6856 } | 6886 } |
6857 | 6887 |
6858 /* | 6888 /* |
6859 * Pops up a context menu at given x and y coordinates. | 6889 * Pops up a context menu at given x and y coordinates. |
6860 * Parameters: | 6890 * Parameters: |
6863 * x: X coordinate. | 6893 * x: X coordinate. |
6864 * y: Y coordinate. | 6894 * y: Y coordinate. |
6865 */ | 6895 */ |
6866 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) | 6896 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) |
6867 { | 6897 { |
6868 UIMenu *thismenu = (UIMenu *)*menu; | 6898 #if 0 /* TODO: Figure out how to do this */ |
6899 DWMenu *thismenu = (DWMenu *)*menu; | |
6869 id object = parent; | 6900 id object = parent; |
6870 UIView *view = [object isKindOfClass:[UIWindow class]] ? [object contentView] : parent; | 6901 UIView *view = [object isKindOfClass:[UIWindow class]] ? [object contentView] : parent; |
6871 UIWindow *window = [view window]; | 6902 UIWindow *window = [view window]; |
6872 UIEvent *event = [DWApp currentEvent]; | |
6873 if(!window) | |
6874 window = [event window]; | |
6875 [thismenu autorelease]; | 6903 [thismenu autorelease]; |
6876 CGPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y); | 6904 CGPoint p = CGPointMake(x, y); |
6877 UIEvent* fake = [UIEvent mouseEventWithType:DWEventTypeRightMouseDown | 6905 [UIContextMenuInteraction a |
6878 location:_windowPointFromScreen(window, p) | 6906 #endif |
6879 modifierFlags:0 | |
6880 timestamp:[event timestamp] | |
6881 windowNumber:[window windowNumber] | |
6882 context:[NSGraphicsContext currentContext] | |
6883 eventNumber:1 | |
6884 clickCount:1 | |
6885 pressure:0.0]; | |
6886 [UIMenu popUpContextMenu:thismenu withEvent:fake forView:view]; | |
6887 } | 6907 } |
6888 | 6908 |
6889 char _removetilde(char *dest, const char *src) | 6909 char _removetilde(char *dest, const char *src) |
6890 { | 6910 { |
6891 int z, cur=0; | 6911 int z, cur=0; |
6919 * flags: Extended attributes to set on the menu. | 6939 * flags: Extended attributes to set on the menu. |
6920 * submenu: Handle to an existing menu to be a submenu or NULL. | 6940 * submenu: Handle to an existing menu to be a submenu or NULL. |
6921 */ | 6941 */ |
6922 HWND API dw_menu_append_item(HMENUI menux, const char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux) | 6942 HWND API dw_menu_append_item(HMENUI menux, const char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux) |
6923 { | 6943 { |
6924 UIMenu *menu = menux; | 6944 DWMenu *menu = menux; |
6925 UIMenu *submenu = submenux; | |
6926 DWMenuItem *item = NULL; | 6945 DWMenuItem *item = NULL; |
6927 if(strlen(title) == 0) | 6946 if(strlen(title) == 0) |
6928 { | 6947 { |
6948 #if 0 /* TODO: Not sure if separators exist in iOS */ | |
6929 [menu addItem:[DWMenuItem separatorItem]]; | 6949 [menu addItem:[DWMenuItem separatorItem]]; |
6950 #endif | |
6930 } | 6951 } |
6931 else | 6952 else |
6932 { | 6953 { |
6933 char accel[2]; | 6954 char accel[2]; |
6934 char *newtitle = malloc(strlen(title)+1); | 6955 char *newtitle = malloc(strlen(title)+1); |
6935 NSString *nstr; | 6956 NSString *nstr; |
6936 | 6957 UIMenu *newmenu, *oldmenu = [menu menu]; |
6958 NSArray *newchildren, *oldchildren = [oldmenu children]; | |
6959 | |
6937 accel[0] = _removetilde(newtitle, title); | 6960 accel[0] = _removetilde(newtitle, title); |
6938 accel[1] = 0; | 6961 accel[1] = 0; |
6939 | 6962 |
6940 nstr = [ NSString stringWithUTF8String:newtitle ]; | 6963 nstr = [ NSString stringWithUTF8String:newtitle ]; |
6941 free(newtitle); | 6964 free(newtitle); |
6942 | 6965 |
6943 item = [[[DWMenuItem alloc] initWithTitle:nstr | 6966 item = [[DWMenuItem commandWithTitle:nstr image:nil |
6944 action:@selector(menuHandler:) | 6967 action:@selector(menuHandler:) |
6945 keyEquivalent:[ NSString stringWithUTF8String:accel ]] autorelease]; | 6968 propertyList:nil] autorelease]; |
6946 [menu addItem:item]; | 6969 newchildren = [oldchildren arrayByAddingObjectsFromArray:@[item]]; |
6947 | 6970 if(oldmenu) |
6971 { | |
6972 newmenu = [oldmenu menuByReplacingChildren:newchildren]; | |
6973 [oldmenu release]; | |
6974 } | |
6975 else if(@available(iOS 14.0, *)) | |
6976 newmenu = [UIMenu menuWithChildren:newchildren]; | |
6977 else | |
6978 newmenu = [UIMenu menuWithTitle:@"" children:newchildren]; | |
6979 [menu setMenu:newmenu]; | |
6980 | |
6948 [item setTag:itemid]; | 6981 [item setTag:itemid]; |
6949 if(check) | 6982 if(check) |
6950 { | 6983 { |
6951 [item setCheck:YES]; | 6984 [item setCheck:YES]; |
6952 if(flags & DW_MIS_CHECKED) | 6985 if(flags & DW_MIS_CHECKED) |
6953 { | 6986 { |
6954 [item setState:DWControlStateValueOn]; | 6987 [item setState:UIMenuElementStateOn]; |
6955 } | 6988 } |
6956 } | 6989 } |
6990 #if 0 /* TODO: Disabled items not supported on iOS */ | |
6957 if(flags & DW_MIS_DISABLED) | 6991 if(flags & DW_MIS_DISABLED) |
6958 { | 6992 { |
6959 [item setEnabled:NO]; | 6993 [item setEnabled:NO]; |
6960 } | 6994 } |
6961 | 6995 #endif |
6996 | |
6997 #if 0 /* TODO: iOS may not support submenus... but may be able to cascade... with defered menus */ | |
6962 if(submenux) | 6998 if(submenux) |
6963 { | 6999 { |
7000 DWMenu *submenu = submenux; | |
7001 | |
6964 [submenu setTitle:nstr]; | 7002 [submenu setTitle:nstr]; |
6965 [menu setSubmenu:submenu forItem:item]; | 7003 [menu setSubmenu:submenu forItem:item]; |
6966 } | 7004 } |
7005 #endif | |
6967 return item; | 7006 return item; |
6968 } | 7007 } |
6969 return item; | 7008 return item; |
6970 } | 7009 } |
6971 | 7010 |
6978 * check: TRUE for checked FALSE for not checked. | 7017 * check: TRUE for checked FALSE for not checked. |
6979 */ | 7018 */ |
6980 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) | 7019 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) |
6981 { | 7020 { |
6982 id menu = menux; | 7021 id menu = menux; |
6983 UIMenuItem *menuitem = (UIMenuItem *)[menu itemWithTag:itemid]; | 7022 DWMenuItem *menuitem = [menu itemWithTag:itemid]; |
6984 | 7023 |
6985 if(menuitem != nil) | 7024 if(menuitem != nil) |
6986 { | 7025 { |
6987 if(check) | 7026 if(check) |
6988 { | 7027 { |
6989 [menuitem setState:DWControlStateValueOn]; | 7028 [menuitem setState:UIMenuElementStateOn]; |
6990 } | 7029 } |
6991 else | 7030 else |
6992 { | 7031 { |
6993 [menuitem setState:DWControlStateValueOff]; | 7032 [menuitem setState:UIMenuElementStateOff]; |
6994 } | 7033 } |
6995 } | 7034 } |
6996 } | 7035 } |
6997 | 7036 |
6998 /* | 7037 /* |
7003 * Returns: | 7042 * Returns: |
7004 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure. | 7043 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure. |
7005 */ | 7044 */ |
7006 int API dw_menu_delete_item(HMENUI menux, unsigned long itemid) | 7045 int API dw_menu_delete_item(HMENUI menux, unsigned long itemid) |
7007 { | 7046 { |
7047 #if 0 /* TODO: Remove item from the children array */ | |
7008 id menu = menux; | 7048 id menu = menux; |
7009 UIMenuItem *menuitem = (UIMenuItem *)[menu itemWithTag:itemid]; | 7049 DWMenuItem *menuitem = [menu itemWithTag:itemid]; |
7010 | 7050 |
7011 if(menuitem != nil) | 7051 if(menuitem != nil) |
7012 { | 7052 { |
7013 [menu removeItem:menuitem]; | 7053 [menu removeItem:menuitem]; |
7014 return DW_ERROR_NONE; | 7054 return DW_ERROR_NONE; |
7015 } | 7055 } |
7056 #endif | |
7016 return DW_ERROR_UNKNOWN; | 7057 return DW_ERROR_UNKNOWN; |
7017 } | 7058 } |
7018 | 7059 |
7019 /* | 7060 /* |
7020 * Sets the state of a menu item. | 7061 * Sets the state of a menu item. |
7025 * DW_MIS_CHECKED/DW_MIS_UNCHECKED | 7066 * DW_MIS_CHECKED/DW_MIS_UNCHECKED |
7026 */ | 7067 */ |
7027 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) | 7068 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) |
7028 { | 7069 { |
7029 id menu = menux; | 7070 id menu = menux; |
7030 UIMenuItem *menuitem = (UIMenuItem *)[menu itemWithTag:itemid]; | 7071 DWMenuItem *menuitem = [menu itemWithTag:itemid]; |
7031 | 7072 |
7032 if(menuitem != nil) | 7073 if(menuitem != nil) |
7033 { | 7074 { |
7034 if(state & DW_MIS_CHECKED) | 7075 if(state & DW_MIS_CHECKED) |
7035 { | 7076 { |
7036 [menuitem setState:DWControlStateValueOn]; | 7077 [menuitem setState:UIMenuElementStateOn]; |
7037 } | 7078 } |
7038 else if(state & DW_MIS_UNCHECKED) | 7079 else if(state & DW_MIS_UNCHECKED) |
7039 { | 7080 { |
7040 [menuitem setState:DWControlStateValueOff]; | 7081 [menuitem setState:UIMenuElementStateOff]; |
7041 } | 7082 } |
7083 #if 0 /* TODO: Disabled items not supported on iOS */ | |
7042 if(state & DW_MIS_ENABLED) | 7084 if(state & DW_MIS_ENABLED) |
7043 { | 7085 { |
7044 [menuitem setEnabled:YES]; | 7086 [menuitem setEnabled:YES]; |
7045 } | 7087 } |
7046 else if(state & DW_MIS_DISABLED) | 7088 else if(state & DW_MIS_DISABLED) |
7047 { | 7089 { |
7048 [menuitem setEnabled:NO]; | 7090 [menuitem setEnabled:NO]; |
7049 } | 7091 } |
7092 #endif | |
7050 } | 7093 } |
7051 } | 7094 } |
7052 | 7095 |
7053 /* Gets the notebook page from associated ID */ | 7096 /* Gets the notebook page from associated ID */ |
7054 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid) | 7097 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid) |
7055 { | 7098 { |
7056 NSArray *pages = [notebook tabViewItems]; | 7099 NSArray *pages = [notebook views]; |
7057 for(DWNotebookPage *notepage in pages) | 7100 for(DWNotebookPage *notepage in pages) |
7058 { | 7101 { |
7059 if([notepage pageid] == pageid) | 7102 if([notepage pageid] == pageid) |
7060 { | 7103 { |
7061 return notepage; | 7104 return notepage; |
7071 * resource file. | 7114 * resource file. |
7072 */ | 7115 */ |
7073 HWND API dw_notebook_new(ULONG cid, int top) | 7116 HWND API dw_notebook_new(ULONG cid, int top) |
7074 { | 7117 { |
7075 DWNotebook *notebook = [[DWNotebook alloc] init]; | 7118 DWNotebook *notebook = [[DWNotebook alloc] init]; |
7076 [notebook setDelegate:notebook]; | |
7077 [notebook addTarget:notebook | 7119 [notebook addTarget:notebook |
7078 action:@selector(pageChanged:) | 7120 action:@selector(pageChanged:) |
7079 forControlEvents:UIControlEventValueChanged]; | 7121 forControlEvents:UIControlEventValueChanged]; |
7080 /* [notebook setTag:cid]; Why doesn't this work? */ | 7122 /* [notebook setTag:cid]; Why doesn't this work? */ |
7081 return notebook; | 7123 return notebook; |
7090 */ | 7132 */ |
7091 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) | 7133 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) |
7092 { | 7134 { |
7093 DWNotebook *notebook = handle; | 7135 DWNotebook *notebook = handle; |
7094 NSInteger page = [notebook pageid]; | 7136 NSInteger page = [notebook pageid]; |
7095 DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:[NSString stringWithFormat: @"pageid:%d", (int)page]]; | 7137 DWNotebookPage *notepage = [[DWNotebookPage alloc] init]; |
7138 NSMutableArray<DWNotebookPage *> *views = [notebook views]; | |
7096 [notepage setPageid:(int)page]; | 7139 [notepage setPageid:(int)page]; |
7097 if(front) | 7140 if(front) |
7098 { | 7141 { |
7099 [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; | 7142 [notebook insertSegmentWithTitle:@"" atIndex:(NSInteger)0 animated:NO]; |
7143 [views addObject:notepage]; | |
7100 } | 7144 } |
7101 else | 7145 else |
7102 { | 7146 { |
7103 [notebook addTabViewItem:notepage]; | 7147 [notebook insertSegmentWithTitle:@"" atIndex:[notebook numberOfSegments] animated:NO]; |
7148 [views addObject:notepage]; | |
7104 } | 7149 } |
7105 [notepage autorelease]; | 7150 [notepage autorelease]; |
7106 [notebook setPageid:(int)(page+1)]; | 7151 [notebook setPageid:(int)(page+1)]; |
7107 return (unsigned long)page; | 7152 return (unsigned long)page; |
7108 } | 7153 } |
7119 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 7164 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
7120 DW_LOCAL_POOL_IN; | 7165 DW_LOCAL_POOL_IN; |
7121 | 7166 |
7122 if(notepage != nil) | 7167 if(notepage != nil) |
7123 { | 7168 { |
7124 [notebook removeTabViewItem:notepage]; | 7169 NSMutableArray<DWNotebookPage *> *views = [notebook views]; |
7170 NSUInteger index = [views indexOfObject:notepage]; | |
7171 | |
7172 if(index != NSNotFound) | |
7173 { | |
7174 [notebook removeSegmentAtIndex:index animated:NO]; | |
7175 [views removeObject:notepage]; | |
7176 [notepage release]; | |
7177 } | |
7125 } | 7178 } |
7126 DW_LOCAL_POOL_OUT; | 7179 DW_LOCAL_POOL_OUT; |
7127 } | 7180 } |
7128 | 7181 |
7129 /* | 7182 /* |
7132 * handle: Handle to the notebook widget. | 7185 * handle: Handle to the notebook widget. |
7133 */ | 7186 */ |
7134 unsigned long API dw_notebook_page_get(HWND handle) | 7187 unsigned long API dw_notebook_page_get(HWND handle) |
7135 { | 7188 { |
7136 DWNotebook *notebook = handle; | 7189 DWNotebook *notebook = handle; |
7137 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; | 7190 NSInteger index = [notebook selectedSegmentIndex]; |
7191 NSMutableArray<DWNotebookPage *> *views = [notebook views]; | |
7192 DWNotebookPage *notepage = [views objectAtIndex:index]; | |
7138 return [notepage pageid]; | 7193 return [notepage pageid]; |
7139 } | 7194 } |
7140 | 7195 |
7141 /* | 7196 /* |
7142 * Sets the currently visibale page ID. | 7197 * Sets the currently visibale page ID. |
7144 * handle: Handle to the notebook widget. | 7199 * handle: Handle to the notebook widget. |
7145 * pageid: ID of the page to be made visible. | 7200 * pageid: ID of the page to be made visible. |
7146 */ | 7201 */ |
7147 void API dw_notebook_page_set(HWND handle, unsigned int pageid) | 7202 void API dw_notebook_page_set(HWND handle, unsigned int pageid) |
7148 { | 7203 { |
7204 #if 0 /* TODO: Don't see a method to select a tab */ | |
7149 DWNotebook *notebook = handle; | 7205 DWNotebook *notebook = handle; |
7150 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 7206 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
7151 | 7207 |
7152 if(notepage != nil) | 7208 if(notepage != nil) |
7153 { | 7209 { |
7154 [notebook selectTabViewItem:notepage]; | 7210 NSMutableArray<DWNotebookPage *> *views = [notebook views]; |
7155 } | 7211 NSUInteger index = [views indexOfObject:notepage]; |
7212 | |
7213 if(index != NSNotFound) | |
7214 { | |
7215 [notebook selectTabViewItem:notepage]; | |
7216 } | |
7217 } | |
7218 #endif | |
7156 } | 7219 } |
7157 | 7220 |
7158 /* | 7221 /* |
7159 * Sets the text on the specified notebook tab. | 7222 * Sets the text on the specified notebook tab. |
7160 * Parameters: | 7223 * Parameters: |
7163 * text: Pointer to the text to set. | 7226 * text: Pointer to the text to set. |
7164 */ | 7227 */ |
7165 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, const char *text) | 7228 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, const char *text) |
7166 { | 7229 { |
7167 DWNotebook *notebook = handle; | 7230 DWNotebook *notebook = handle; |
7168 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 7231 |
7169 | 7232 [notebook setTitle:[NSString stringWithUTF8String:text] forSegmentAtIndex:pageid]; |
7170 if(notepage != nil) | |
7171 { | |
7172 [notepage setLabel:[ NSString stringWithUTF8String:text ]]; | |
7173 } | |
7174 } | 7233 } |
7175 | 7234 |
7176 /* | 7235 /* |
7177 * Sets the text on the specified notebook tab status area. | 7236 * Sets the text on the specified notebook tab status area. |
7178 * Parameters: | 7237 * Parameters: |
7192 * pageid: Page ID in the notebook which is being packed. | 7251 * pageid: Page ID in the notebook which is being packed. |
7193 * page: Box handle to be packed. | 7252 * page: Box handle to be packed. |
7194 */ | 7253 */ |
7195 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) | 7254 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) |
7196 { | 7255 { |
7256 #if 0 /* TODO: Haven't implemented the content yet since UISegmentedControl is just the buttons */ | |
7197 DWNotebook *notebook = handle; | 7257 DWNotebook *notebook = handle; |
7198 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 7258 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
7199 | 7259 |
7200 if(notepage != nil) | 7260 if(notepage != nil) |
7201 { | 7261 { |
7204 | 7264 |
7205 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); | 7265 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); |
7206 [notepage setView:box]; | 7266 [notepage setView:box]; |
7207 [box autorelease]; | 7267 [box autorelease]; |
7208 } | 7268 } |
7269 #endif | |
7209 } | 7270 } |
7210 | 7271 |
7211 /* | 7272 /* |
7212 * Create a new Window Frame. | 7273 * Create a new Window Frame. |
7213 * Parameters: | 7274 * Parameters: |
7219 DW_FUNCTION_ADD_PARAM3(hwndOwner, title, flStyle) | 7280 DW_FUNCTION_ADD_PARAM3(hwndOwner, title, flStyle) |
7220 DW_FUNCTION_RETURN(dw_window_new, HWND) | 7281 DW_FUNCTION_RETURN(dw_window_new, HWND) |
7221 DW_FUNCTION_RESTORE_PARAM3(hwndOwner, HWND, title, char *, flStyle, ULONG) | 7282 DW_FUNCTION_RESTORE_PARAM3(hwndOwner, HWND, title, char *, flStyle, ULONG) |
7222 { | 7283 { |
7223 DW_FUNCTION_INIT; | 7284 DW_FUNCTION_INIT; |
7224 CGRect frame = NSMakeRect(1,1,1,1); | 7285 DWWindow *window = [[DWWindow alloc] init]; |
7225 DWWindow *window = [[DWWindow alloc] | 7286 |
7226 initWithContentRect:frame | 7287 /* TODO: Handle style flags */ |
7227 styleMask:(flStyle) | 7288 if(@available(iOS 13.0, *)) { |
7228 backing:NSBackingStoreBuffered | 7289 [window setLargeContentTitle:[NSString stringWithUTF8String:title]]; |
7229 defer:false]; | |
7230 | |
7231 [window setTitle:[ NSString stringWithUTF8String:title ]]; | |
7232 | |
7233 DWView *view = [[DWView alloc] init]; | |
7234 | |
7235 [window setContentView:view]; | |
7236 [window setDelegate:view]; | |
7237 [window setAutorecalculatesKeyViewLoop:YES]; | |
7238 [window setAcceptsMouseMovedEvents:YES]; | |
7239 [window setReleasedWhenClosed:YES]; | |
7240 [view autorelease]; | |
7241 | |
7242 /* Enable full screen mode on resizeable windows */ | |
7243 if(flStyle & DW_FCF_SIZEBORDER) | |
7244 { | |
7245 [window setCollectionBehavior:UIWindowCollectionBehaviorFullScreenPrimary]; | |
7246 } | |
7247 | |
7248 /* If it isn't a toplevel window... */ | |
7249 if(hwndOwner) | |
7250 { | |
7251 id object = hwndOwner; | |
7252 | |
7253 /* Check to see if the parent is an MDI window */ | |
7254 if([object isMemberOfClass:[DWMDI class]]) | |
7255 { | |
7256 /* Set the window level to be floating */ | |
7257 [window setLevel:NSFloatingWindowLevel]; | |
7258 [window setHidesOnDeactivate:YES]; | |
7259 } | |
7260 } | 7290 } |
7261 DW_FUNCTION_RETURN_THIS(window); | 7291 DW_FUNCTION_RETURN_THIS(window); |
7262 } | 7292 } |
7263 | 7293 |
7264 /* | 7294 /* |
7288 * handle: Handle to widget for which to change. | 7318 * handle: Handle to widget for which to change. |
7289 * cursortype: ID of the pointer you want. | 7319 * cursortype: ID of the pointer you want. |
7290 */ | 7320 */ |
7291 void API dw_window_set_pointer(HWND handle, int pointertype) | 7321 void API dw_window_set_pointer(HWND handle, int pointertype) |
7292 { | 7322 { |
7293 id object = handle; | 7323 /* TODO: Only might be possible on Catalyst */ |
7294 | |
7295 if([ object isKindOfClass:[ UIView class ] ]) | |
7296 { | |
7297 UIView *view = handle; | |
7298 | |
7299 if(pointertype == DW_POINTER_DEFAULT) | |
7300 { | |
7301 [view discardCursorRects]; | |
7302 } | |
7303 else if(pointertype == DW_POINTER_ARROW) | |
7304 { | |
7305 CGRect rect = [view frame]; | |
7306 NSCursor *cursor = [NSCursor arrowCursor]; | |
7307 | |
7308 [view addCursorRect:rect cursor:cursor]; | |
7309 } | |
7310 /* No cursor for DW_POINTER_CLOCK? */ | |
7311 } | |
7312 } | 7324 } |
7313 | 7325 |
7314 /* | 7326 /* |
7315 * Makes the window visible. | 7327 * Makes the window visible. |
7316 * Parameters: | 7328 * Parameters: |
7321 NSObject *object = handle; | 7333 NSObject *object = handle; |
7322 | 7334 |
7323 if([ object isMemberOfClass:[ DWWindow class ] ]) | 7335 if([ object isMemberOfClass:[ DWWindow class ] ]) |
7324 { | 7336 { |
7325 DWWindow *window = handle; | 7337 DWWindow *window = handle; |
7326 CGRect rect = [[window contentView] frame]; | 7338 CGRect rect = [window frame]; |
7327 id defaultitem = [window initialFirstResponder]; | 7339 |
7328 | |
7329 if([window isMiniaturized]) | |
7330 { | |
7331 [window deminiaturize:nil]; | |
7332 } | |
7333 /* If we haven't been sized by a call.. */ | 7340 /* If we haven't been sized by a call.. */ |
7334 if(rect.size.width <= 1 || rect.size.height <= 1) | 7341 if(rect.size.width <= 1 || rect.size.height <= 1) |
7335 { | 7342 { |
7336 /* Determine the contents size */ | 7343 /* Determine the contents size */ |
7337 dw_window_set_size(handle, 0, 0); | 7344 dw_window_set_size(handle, 0, 0); |
7338 } | 7345 } |
7339 /* If the position was not set... generate a default | |
7340 * default one in a similar pattern to SHELLPOSITION. | |
7341 */ | |
7342 if(![window shown]) | 7346 if(![window shown]) |
7343 { | |
7344 static int defaultx = 0, defaulty = 0; | |
7345 int cx = dw_screen_width(), cy = dw_screen_height(); | |
7346 int maxx = cx / 4, maxy = cy / 4; | |
7347 CGPoint point; | |
7348 | |
7349 rect = [window frame]; | |
7350 | |
7351 defaultx += 20; | |
7352 defaulty += 20; | |
7353 if(defaultx > maxx) | |
7354 defaultx = 20; | |
7355 if(defaulty > maxy) | |
7356 defaulty = 20; | |
7357 | |
7358 point.x = defaultx; | |
7359 /* Take into account menu bar and inverted Y */ | |
7360 point.y = cy - defaulty - (int)rect.size.height - 22; | |
7361 | |
7362 [window setFrameOrigin:point]; | |
7363 [window setShown:YES]; | 7347 [window setShown:YES]; |
7364 } | |
7365 [[window contentView] showWindow]; | |
7366 [window makeKeyAndOrderFront:nil]; | |
7367 | |
7368 if(!([window styleMask] & DWWindowStyleMaskResizable)) | |
7369 { | |
7370 /* Fix incorrect repeat in displaying textured windows */ | |
7371 [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge]; | |
7372 [window setContentBorderThickness:0.0 forEdge:NSMinYEdge]; | |
7373 } | |
7374 if(defaultitem) | |
7375 { | |
7376 /* If there is a default item set, make it first responder */ | |
7377 [window makeFirstResponder:defaultitem]; | |
7378 } | |
7379 } | 7348 } |
7380 return 0; | 7349 return 0; |
7381 } | 7350 } |
7382 | 7351 |
7383 /* | 7352 /* |
7391 | 7360 |
7392 if([ object isKindOfClass:[ UIWindow class ] ]) | 7361 if([ object isKindOfClass:[ UIWindow class ] ]) |
7393 { | 7362 { |
7394 UIWindow *window = handle; | 7363 UIWindow *window = handle; |
7395 | 7364 |
7396 [window orderOut:nil]; | 7365 [window setHidden:YES]; |
7397 } | 7366 } |
7398 return 0; | 7367 return 0; |
7399 } | 7368 } |
7400 | 7369 |
7401 /* | 7370 /* |
7414 UIColor *bg = NULL; | 7383 UIColor *bg = NULL; |
7415 | 7384 |
7416 /* Get the UIColor for non-default colors */ | 7385 /* Get the UIColor for non-default colors */ |
7417 if(fore != DW_CLR_DEFAULT) | 7386 if(fore != DW_CLR_DEFAULT) |
7418 { | 7387 { |
7419 fg = [UIColor colorWithDeviceRed: DW_RED_VALUE(_fore)/255.0 green: DW_GREEN_VALUE(_fore)/255.0 blue: DW_BLUE_VALUE(_fore)/255.0 alpha: 1]; | 7388 fg = [UIColor colorWithRed: DW_RED_VALUE(_fore)/255.0 green: DW_GREEN_VALUE(_fore)/255.0 blue: DW_BLUE_VALUE(_fore)/255.0 alpha: 1]; |
7420 } | 7389 } |
7421 if(back != DW_CLR_DEFAULT) | 7390 if(back != DW_CLR_DEFAULT) |
7422 { | 7391 { |
7423 bg = [UIColor colorWithDeviceRed: DW_RED_VALUE(_back)/255.0 green: DW_GREEN_VALUE(_back)/255.0 blue: DW_BLUE_VALUE(_back)/255.0 alpha: 1]; | 7392 bg = [UIColor colorWithRed: DW_RED_VALUE(_back)/255.0 green: DW_GREEN_VALUE(_back)/255.0 blue: DW_BLUE_VALUE(_back)/255.0 alpha: 1]; |
7424 } | 7393 } |
7425 | 7394 |
7426 /* Get the textfield from the spinbutton */ | 7395 /* Get the textfield from the spinbutton */ |
7427 if([object isMemberOfClass:[DWSpinButton class]]) | 7396 if([object isMemberOfClass:[DWSpinButton class]]) |
7428 { | 7397 { |
7429 object = [object textfield]; | 7398 object = [object textfield]; |
7430 } | 7399 } |
7431 /* Get the cell on classes using NSCell */ | 7400 /* Get the cell on classes using NSCell */ |
7432 if([object isKindOfClass:[UITextField class]]) | 7401 if([object isKindOfClass:[UITextField class]]) |
7433 { | 7402 { |
7434 id cell = [object cell]; | 7403 [object setTextColor:(fg ? fg : [UIColor labelColor])]; |
7435 | |
7436 [object setTextColor:(fg ? fg : [UIColor controlTextColor])]; | |
7437 [cell setTextColor:(fg ? fg : [UIColor controlTextColor])]; | |
7438 } | 7404 } |
7439 if([object isMemberOfClass:[DWButton class]]) | 7405 if([object isMemberOfClass:[DWButton class]]) |
7440 { | 7406 { |
7441 [object setTitleColor:(fg ? fg : [UIColor controlTextColor])]; | 7407 [object setTextColor:(fg ? fg : [UIColor labelColor])]; |
7442 } | 7408 } |
7443 if([object isKindOfClass:[UITextField class]] || [object isKindOfClass:[UIButton class]]) | 7409 if([object isKindOfClass:[UITextField class]] || [object isKindOfClass:[UIButton class]]) |
7444 { | 7410 { |
7445 id cell = [object cell]; | 7411 [object setBackgroundColor:(bg ? bg : [UIColor systemBackgroundColor])]; |
7446 | |
7447 [cell setBackgroundColor:(bg ? bg : [UIColor controlColor])]; | |
7448 } | 7412 } |
7449 else if([object isMemberOfClass:[DWBox class]]) | 7413 else if([object isMemberOfClass:[DWBox class]]) |
7450 { | 7414 { |
7451 DWBox *box = object; | 7415 DWBox *box = object; |
7452 | 7416 |
7453 [box setColor:_back]; | 7417 [box setColor:_back]; |
7454 } | 7418 } |
7455 else if([object isKindOfClass:[NSTableView class]]) | 7419 else if([object isKindOfClass:[UITableView class]]) |
7456 { | 7420 { |
7457 DWContainer *cont = handle; | 7421 DWContainer *cont = handle; |
7458 | 7422 |
7459 [cont setBackgroundColor:(bg ? bg : [UIColor controlBackgroundColor])]; | 7423 [cont setBackgroundColor:(bg ? bg : [UIColor systemBackgroundColor])]; |
7460 [cont setForegroundColor:(fg ? fg : [UIColor controlTextColor])]; | 7424 [cont setForegroundColor:(fg ? fg : [UIColor labelColor])]; |
7461 } | 7425 } |
7462 else if([object isMemberOfClass:[DWMLE class]]) | 7426 else if([object isMemberOfClass:[DWMLE class]]) |
7463 { | 7427 { |
7464 DWMLE *mle = handle; | 7428 DWMLE *mle = handle; |
7465 [mle setBackgroundColor:(bg ? bg : [UIColor controlBackgroundColor])]; | 7429 [mle setBackgroundColor:(bg ? bg : [UIColor systemBackgroundColor])]; |
7466 NSTextStorage *ts = [mle textStorage]; | 7430 [mle setTextColor:(fg ? fg : [UIColor labelColor])]; |
7467 [ts setForegroundColor:(fg ? fg : [UIColor controlTextColor])]; | |
7468 } | 7431 } |
7469 return 0; | 7432 return 0; |
7470 } | 7433 } |
7471 | 7434 |
7472 /* | 7435 /* |
7489 */ | 7452 */ |
7490 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) | 7453 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) |
7491 { | 7454 { |
7492 id object = _text_handle(handle); | 7455 id object = _text_handle(handle); |
7493 | 7456 |
7494 if([object isMemberOfClass:[DWWindow class]]) | 7457 if([object isKindOfClass:[UILabel class]]) |
7495 { | |
7496 DWWindow *window = object; | |
7497 SEL sssm = NSSelectorFromString(@"setStyleMask"); | |
7498 | |
7499 if([window respondsToSelector:sssm]) | |
7500 { | |
7501 DWIMP issm = (DWIMP)[window methodForSelector:sssm]; | |
7502 int currentstyle = (int)[window styleMask]; | |
7503 int tmp; | |
7504 | |
7505 tmp = currentstyle | (int)mask; | |
7506 tmp ^= mask; | |
7507 tmp |= style; | |
7508 | |
7509 issm(window, sssm, tmp); | |
7510 } | |
7511 } | |
7512 else if([object isKindOfClass:[UILabel class]]) | |
7513 { | 7458 { |
7514 UILabel *label = object; | 7459 UILabel *label = object; |
7515 | 7460 |
7516 [label setTextAlignment:(style & 0xF)]; | 7461 [label setTextAlignment:(style & 0xF)]; |
7517 #if 0 /* TODO: Implement vertical centering */ | 7462 #if 0 /* TODO: Implement vertical centering */ |
7526 [label setLineBreakMode:NSLineBreakByWordWrapping]; | 7471 [label setLineBreakMode:NSLineBreakByWordWrapping]; |
7527 else | 7472 else |
7528 [label setLineBreakMode:NSLineBreakByTruncatingTail]; | 7473 [label setLineBreakMode:NSLineBreakByTruncatingTail]; |
7529 } | 7474 } |
7530 } | 7475 } |
7476 #if 0 /* TODO: See if we can change alignment... */ | |
7531 else if([object isMemberOfClass:[UITextView class]]) | 7477 else if([object isMemberOfClass:[UITextView class]]) |
7532 { | 7478 { |
7533 UITextView *tv = handle; | 7479 UITextView *tv = handle; |
7534 [tv setAlignment:(style & mask)]; | 7480 [tv setAlignment:(style & mask)]; |
7535 } | 7481 } |
7536 else if([object isMemberOfClass:[DWButton class]]) | 7482 #endif |
7537 { | |
7538 DWButton *button = handle; | |
7539 | |
7540 if(mask & DW_BS_NOBORDER) | |
7541 { | |
7542 if(style & DW_BS_NOBORDER) | |
7543 [button setBordered:NO]; | |
7544 else | |
7545 [button setBordered:YES]; | |
7546 } | |
7547 } | |
7548 else if([object isMemberOfClass:[DWMenuItem class]]) | 7483 else if([object isMemberOfClass:[DWMenuItem class]]) |
7549 { | 7484 { |
7550 if(mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED)) | 7485 if(mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED)) |
7551 { | 7486 { |
7552 if(style & DW_MIS_CHECKED) | 7487 if(style & DW_MIS_CHECKED) |
7553 [object setState:DWControlStateValueOn]; | 7488 [object setState:UIMenuElementStateOn]; |
7554 else if(style & DW_MIS_UNCHECKED) | 7489 else if(style & DW_MIS_UNCHECKED) |
7555 [object setState:DWControlStateValueOff]; | 7490 [object setState:UIMenuElementStateOff]; |
7556 } | 7491 } |
7557 if(mask & (DW_MIS_ENABLED | DW_MIS_DISABLED)) | 7492 if(mask & (DW_MIS_ENABLED | DW_MIS_DISABLED)) |
7558 { | 7493 { |
7559 if(style & DW_MIS_ENABLED) | 7494 if(style & DW_MIS_ENABLED) |
7560 [object setEnabled:YES]; | 7495 [object setEnabled:YES]; |
7573 */ | 7508 */ |
7574 void API dw_window_set_focus(HWND handle) | 7509 void API dw_window_set_focus(HWND handle) |
7575 { | 7510 { |
7576 id object = handle; | 7511 id object = handle; |
7577 | 7512 |
7578 [[object window] makeFirstResponder:object]; | 7513 [object becomeFirstResponder]; |
7579 } | 7514 } |
7580 | 7515 |
7581 /* | 7516 /* |
7582 * Sets the default focus item for a window/dialog. | 7517 * Sets the default focus item for a window/dialog. |
7583 * Parameters: | 7518 * Parameters: |
7591 DWWindow *window = handle; | 7526 DWWindow *window = handle; |
7592 id object = defaultitem; | 7527 id object = defaultitem; |
7593 | 7528 |
7594 if([window isKindOfClass:[UIWindow class]] && [object isKindOfClass:[UIControl class]]) | 7529 if([window isKindOfClass:[UIWindow class]] && [object isKindOfClass:[UIControl class]]) |
7595 { | 7530 { |
7596 [window setInitialFirstResponder:defaultitem]; | 7531 [object becomeFirstResponder]; |
7597 } | 7532 } |
7598 } | 7533 } |
7599 | 7534 |
7600 /* | 7535 /* |
7601 * Sets window to click the default dialog item when an ENTER is pressed. | 7536 * Sets window to click the default dialog item when an ENTER is pressed. |
7603 * window: Window (widget) to look for the ENTER press. | 7538 * window: Window (widget) to look for the ENTER press. |
7604 * next: Window (widget) to move to next (or click) | 7539 * next: Window (widget) to move to next (or click) |
7605 */ | 7540 */ |
7606 void API dw_window_click_default(HWND handle, HWND next) | 7541 void API dw_window_click_default(HWND handle, HWND next) |
7607 { | 7542 { |
7608 id object = handle; | 7543 /* TODO: Figure out how to do this if we should */ |
7609 id control = next; | |
7610 | |
7611 if([object isMemberOfClass:[DWWindow class]]) | |
7612 { | |
7613 if([control isMemberOfClass:[DWButton class]]) | |
7614 { | |
7615 UIWindow *window = object; | |
7616 | |
7617 [window setDefaultButtonCell:[control cell]]; | |
7618 } | |
7619 } | |
7620 else | |
7621 { | |
7622 if([control isMemberOfClass:[DWSpinButton class]]) | |
7623 { | |
7624 control = [control textfield]; | |
7625 } | |
7626 [object setClickDefault:control]; | |
7627 } | |
7628 } | 7544 } |
7629 | 7545 |
7630 /* | 7546 /* |
7631 * Captures the mouse input to this window. | 7547 * Captures the mouse input to this window. |
7632 * Parameters: | 7548 * Parameters: |
7651 * handle: The window handle to destroy. | 7567 * handle: The window handle to destroy. |
7652 * newparent: The window's new parent window. | 7568 * newparent: The window's new parent window. |
7653 */ | 7569 */ |
7654 void API dw_window_reparent(HWND handle, HWND newparent) | 7570 void API dw_window_reparent(HWND handle, HWND newparent) |
7655 { | 7571 { |
7656 id object = handle; | 7572 /* TODO: Not sure if we should even bother with this */ |
7657 | |
7658 if([object isMemberOfClass:[DWWindow class]]) | |
7659 { | |
7660 /* We can't actually reparent on MacOS but if the | |
7661 * new parent is an MDI window, change to be a | |
7662 * floating window... otherwise set it to normal. | |
7663 */ | |
7664 UIWindow *window = handle; | |
7665 | |
7666 /* If it isn't a toplevel window... */ | |
7667 if(newparent) | |
7668 { | |
7669 object = newparent; | |
7670 | |
7671 /* Check to see if the parent is an MDI window */ | |
7672 if([object isMemberOfClass:[DWMDI class]]) | |
7673 { | |
7674 /* Set the window level to be floating */ | |
7675 [window setLevel:NSFloatingWindowLevel]; | |
7676 [window setHidesOnDeactivate:YES]; | |
7677 return; | |
7678 } | |
7679 } | |
7680 /* Set the window back to a normal window */ | |
7681 [window setLevel:NSNormalWindowLevel]; | |
7682 [window setHidesOnDeactivate:NO]; | |
7683 } | |
7684 } | 7573 } |
7685 | 7574 |
7686 /* Allows the user to choose a font using the system's font chooser dialog. | 7575 /* Allows the user to choose a font using the system's font chooser dialog. |
7687 * Parameters: | 7576 * Parameters: |
7688 * currfont: current font | 7577 * currfont: current font |
7868 [window close]; | 7757 [window close]; |
7869 } | 7758 } |
7870 /* Handle removing menu items from menus */ | 7759 /* Handle removing menu items from menus */ |
7871 else if([ object isKindOfClass:[UIMenuItem class]]) | 7760 else if([ object isKindOfClass:[UIMenuItem class]]) |
7872 { | 7761 { |
7873 UIMenu *menu = [object menu]; | 7762 DWMenu *menu = [object menu]; |
7874 | 7763 |
7875 [menu removeItem:object]; | 7764 [menu removeItem:object]; |
7876 } | 7765 } |
7877 /* Handle destroying a control or box */ | 7766 /* Handle destroying a control or box */ |
7878 else if([object isKindOfClass:[UIView class]] || [object isKindOfClass:[UIControl class]]) | 7767 else if([object isKindOfClass:[UIView class]] || [object isKindOfClass:[UIControl class]]) |
8089 if([object isMemberOfClass:[UIScrollView class]]) | 7978 if([object isMemberOfClass:[UIScrollView class]]) |
8090 { | 7979 { |
8091 UIScrollView *sv = handle; | 7980 UIScrollView *sv = handle; |
8092 object = [sv documentView]; | 7981 object = [sv documentView]; |
8093 } | 7982 } |
8094 if([object isKindOfClass:[UIControl class]] || [object isKindOfClass:[UIMenuItem class]]) | 7983 if([object isKindOfClass:[UIControl class]] /* TODO: || [object isKindOfClass:[UIMenuItem class]] */) |
8095 { | 7984 { |
8096 [object setEnabled:YES]; | 7985 [object setEnabled:YES]; |
8097 } | 7986 } |
8098 if([object isKindOfClass:[UITextView class]]) | 7987 if([object isKindOfClass:[UITextView class]]) |
8099 { | 7988 { |