Mercurial > dwindows
comparison mac/dw.m @ 651:270580896dac
Filling in more class types.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 22 Feb 2011 19:41:02 +0000 |
parents | 55b677d460e9 |
children | ef0f484c6c4b |
comparison
equal
deleted
inserted
replaced
650:55b677d460e9 | 651:270580896dac |
---|---|
103 -(void *)userdata; | 103 -(void *)userdata; |
104 -(void)setUserdata:(void *)input; | 104 -(void)setUserdata:(void *)input; |
105 @end | 105 @end |
106 | 106 |
107 @implementation DWPercent | 107 @implementation DWPercent |
108 -(void *)userdata { return userdata; } | |
109 -(void)setUserdata:(void *)input { userdata = input; } | |
110 @end | |
111 | |
112 /* Subclass for a entryfield type */ | |
113 @interface DWEntryField : NSTextField | |
114 { | |
115 void *userdata; | |
116 } | |
117 -(void *)userdata; | |
118 -(void)setUserdata:(void *)input; | |
119 @end | |
120 | |
121 @implementation DWEntryField | |
122 -(void *)userdata { return userdata; } | |
123 -(void)setUserdata:(void *)input { userdata = input; } | |
124 @end | |
125 | |
126 /* Subclass for a entryfield password type */ | |
127 @interface DWEntryFieldPassword : NSSecureTextField | |
128 { | |
129 void *userdata; | |
130 } | |
131 -(void *)userdata; | |
132 -(void)setUserdata:(void *)input; | |
133 @end | |
134 | |
135 @implementation DWEntryFieldPassword | |
108 -(void *)userdata { return userdata; } | 136 -(void *)userdata { return userdata; } |
109 -(void)setUserdata:(void *)input { userdata = input; } | 137 -(void)setUserdata:(void *)input { userdata = input; } |
110 @end | 138 @end |
111 | 139 |
112 NSApplication *DWApp; | 140 NSApplication *DWApp; |
884 * the file path on success. | 912 * the file path on success. |
885 * | 913 * |
886 */ | 914 */ |
887 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) | 915 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) |
888 { | 916 { |
889 NSLog(@"dw_file_browse() unimplemented\n"); | 917 if(flags == DW_FILE_OPEN) |
918 { | |
919 /* Create the File Open Dialog class. */ | |
920 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; | |
921 | |
922 /* Enable the selection of files in the dialog. */ | |
923 [openDlg setCanChooseFiles:YES]; | |
924 [openDlg setCanChooseDirectories:NO]; | |
925 | |
926 /* Disable multiple selection */ | |
927 [openDlg setAllowsMultipleSelection:NO]; | |
928 | |
929 /* Display the dialog. If the OK button was pressed, | |
930 * process the files. | |
931 */ | |
932 if([openDlg runModal] == NSOKButton) | |
933 { | |
934 /* Get an array containing the full filenames of all | |
935 * files and directories selected. | |
936 */ | |
937 NSArray* files = [openDlg filenames]; | |
938 NSString* fileName = [files objectAtIndex:0]; | |
939 return strdup([ fileName UTF8String ]); | |
940 } | |
941 } | |
942 else | |
943 { | |
944 /* Create the File Save Dialog class. */ | |
945 NSSavePanel* saveDlg = [NSSavePanel savePanel]; | |
946 | |
947 /* Enable the selection of files in the dialog. */ | |
948 [saveDlg setCanCreateDirectories:YES]; | |
949 | |
950 /* Display the dialog. If the OK button was pressed, | |
951 * process the files. | |
952 */ | |
953 if([saveDlg runModal] == NSFileHandlingPanelOKButton) | |
954 { | |
955 /* Get an array containing the full filenames of all | |
956 * files and directories selected. | |
957 */ | |
958 NSString* fileName = [saveDlg filename]; | |
959 return strdup([ fileName UTF8String ]); | |
960 } | |
961 } | |
962 | |
890 return NULL; | 963 return NULL; |
891 } | 964 } |
892 | 965 |
893 /* | 966 /* |
894 * Gets the contents of the default clipboard as text. | 967 * Gets the contents of the default clipboard as text. |
898 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not | 971 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not |
899 * be converted to text. | 972 * be converted to text. |
900 */ | 973 */ |
901 char *dw_clipboard_get_text() | 974 char *dw_clipboard_get_text() |
902 { | 975 { |
903 NSLog(@"dw_clipboard_get_text() unimplemented\n"); | 976 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; |
977 NSString *str = [pasteboard stringForType:NSStringPboardType]; | |
978 if(str != nil) | |
979 { | |
980 return strdup([ str UTF8String ]); | |
981 } | |
904 return NULL; | 982 return NULL; |
905 } | 983 } |
906 | 984 |
907 /* | 985 /* |
908 * Sets the contents of the default clipboard to the supplied text. | 986 * Sets the contents of the default clipboard to the supplied text. |
909 * Parameters: | 987 * Parameters: |
910 * Text. | 988 * Text. |
911 */ | 989 */ |
912 void dw_clipboard_set_text( char *str, int len ) | 990 void dw_clipboard_set_text( char *str, int len) |
913 { | 991 { |
914 NSLog(@"dw_clipboard_set_text() unimplemented\n"); | 992 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; |
915 return; | 993 |
994 [pasteboard clearContents]; | |
995 | |
996 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; | |
916 } | 997 } |
917 | 998 |
918 | 999 |
919 /* | 1000 /* |
920 * Allocates and initializes a dialog struct. | 1001 * Allocates and initializes a dialog struct. |
1164 * text: The default text to be in the entryfield widget. | 1245 * text: The default text to be in the entryfield widget. |
1165 * id: An ID to be used with dw_window_from_id() or 0L. | 1246 * id: An ID to be used with dw_window_from_id() or 0L. |
1166 */ | 1247 */ |
1167 HWND API dw_entryfield_new(char *text, ULONG id) | 1248 HWND API dw_entryfield_new(char *text, ULONG id) |
1168 { | 1249 { |
1169 NSTextField *entry = [[NSTextField alloc] init]; | 1250 DWEntryField *entry = [[DWEntryField alloc] init]; |
1170 [entry setStringValue:[ NSString stringWithUTF8String:text ]]; | 1251 [entry setStringValue:[ NSString stringWithUTF8String:text ]]; |
1171 [entry setTag:id]; | 1252 [entry setTag:id]; |
1172 return entry; | 1253 return entry; |
1173 } | 1254 } |
1174 | 1255 |
1178 * text: The default text to be in the entryfield widget. | 1259 * text: The default text to be in the entryfield widget. |
1179 * id: An ID to be used with dw_window_from_id() or 0L. | 1260 * id: An ID to be used with dw_window_from_id() or 0L. |
1180 */ | 1261 */ |
1181 HWND API dw_entryfield_password_new(char *text, ULONG id) | 1262 HWND API dw_entryfield_password_new(char *text, ULONG id) |
1182 { | 1263 { |
1183 NSSecureTextField *entry = [[NSSecureTextField alloc] init]; | 1264 DWEntryFieldPassword *entry = [[DWEntryFieldPassword alloc] init]; |
1184 [entry setStringValue:[ NSString stringWithUTF8String:text ]]; | 1265 [entry setStringValue:[ NSString stringWithUTF8String:text ]]; |
1185 [entry setTag:id]; | 1266 [entry setTag:id]; |
1186 return entry; | 1267 return entry; |
1187 } | 1268 } |
1188 | 1269 |
2673 */ | 2754 */ |
2674 HWND API dw_html_new(unsigned long id) | 2755 HWND API dw_html_new(unsigned long id) |
2675 { | 2756 { |
2676 WebView *web = [[WebView alloc] init]; | 2757 WebView *web = [[WebView alloc] init]; |
2677 return web; | 2758 return web; |
2678 } | |
2679 | |
2680 /* | |
2681 * Call a function from the window (widget)'s context. | |
2682 * Parameters: | |
2683 * handle: Window handle of the widget. | |
2684 * function: Function pointer to be called. | |
2685 * data: Pointer to the data to be passed to the function. | |
2686 */ | |
2687 void API dw_window_function(HWND handle, void *function, void *data) | |
2688 { | |
2689 NSLog(@"dw_window_function() unimplemented\n"); | |
2690 } | 2759 } |
2691 | 2760 |
2692 /* | 2761 /* |
2693 * Returns the current X and Y coordinates of the mouse pointer. | 2762 * Returns the current X and Y coordinates of the mouse pointer. |
2694 * Parameters: | 2763 * Parameters: |
2985 | 3054 |
2986 return (HWND)window; | 3055 return (HWND)window; |
2987 } | 3056 } |
2988 | 3057 |
2989 /* | 3058 /* |
3059 * Call a function from the window (widget)'s context. | |
3060 * Parameters: | |
3061 * handle: Window handle of the widget. | |
3062 * function: Function pointer to be called. | |
3063 * data: Pointer to the data to be passed to the function. | |
3064 */ | |
3065 void API dw_window_function(HWND handle, void *function, void *data) | |
3066 { | |
3067 void (* windowfunc)(void *); | |
3068 | |
3069 windowfunc = function; | |
3070 | |
3071 if(windowfunc) | |
3072 windowfunc(data); | |
3073 } | |
3074 | |
3075 | |
3076 /* | |
2990 * Changes the appearance of the mouse pointer. | 3077 * Changes the appearance of the mouse pointer. |
2991 * Parameters: | 3078 * Parameters: |
2992 * handle: Handle to widget for which to change. | 3079 * handle: Handle to widget for which to change. |
2993 * cursortype: ID of the pointer you want. | 3080 * cursortype: ID of the pointer you want. |
2994 */ | 3081 */ |
3498 * freq: Frequency. | 3585 * freq: Frequency. |
3499 * dur: Duration. | 3586 * dur: Duration. |
3500 */ | 3587 */ |
3501 void API dw_beep(int freq, int dur) | 3588 void API dw_beep(int freq, int dur) |
3502 { | 3589 { |
3503 NSLog(@"dw_beep() unimplemented\n"); | 3590 NSBeep(); |
3504 } | 3591 } |
3505 | 3592 |
3506 /* Call this after drawing to the screen to make sure | 3593 /* Call this after drawing to the screen to make sure |
3507 * anything you have drawn is visible. | 3594 * anything you have drawn is visible. |
3508 */ | 3595 */ |
3509 void API dw_flush(void) | 3596 void API dw_flush(void) |
3510 { | 3597 { |
3598 } | |
3599 | |
3600 /* Functions for managing the user data lists that are associated with | |
3601 * a given window handle. Used in dw_window_set_data() and | |
3602 * dw_window_get_data(). | |
3603 */ | |
3604 UserData *_find_userdata(UserData **root, char *varname) | |
3605 { | |
3606 UserData *tmp = *root; | |
3607 | |
3608 while(tmp) | |
3609 { | |
3610 if(strcasecmp(tmp->varname, varname) == 0) | |
3611 return tmp; | |
3612 tmp = tmp->next; | |
3613 } | |
3614 return NULL; | |
3615 } | |
3616 | |
3617 int _new_userdata(UserData **root, char *varname, void *data) | |
3618 { | |
3619 UserData *new = _find_userdata(root, varname); | |
3620 | |
3621 if(new) | |
3622 { | |
3623 new->data = data; | |
3624 return TRUE; | |
3625 } | |
3626 else | |
3627 { | |
3628 new = malloc(sizeof(UserData)); | |
3629 if(new) | |
3630 { | |
3631 new->varname = strdup(varname); | |
3632 new->data = data; | |
3633 | |
3634 new->next = NULL; | |
3635 | |
3636 if (!*root) | |
3637 *root = new; | |
3638 else | |
3639 { | |
3640 UserData *prev = NULL, *tmp = *root; | |
3641 while(tmp) | |
3642 { | |
3643 prev = tmp; | |
3644 tmp = tmp->next; | |
3645 } | |
3646 if(prev) | |
3647 prev->next = new; | |
3648 else | |
3649 *root = new; | |
3650 } | |
3651 return TRUE; | |
3652 } | |
3653 } | |
3654 return FALSE; | |
3655 } | |
3656 | |
3657 int _remove_userdata(UserData **root, char *varname, int all) | |
3658 { | |
3659 UserData *prev = NULL, *tmp = *root; | |
3660 | |
3661 while(tmp) | |
3662 { | |
3663 if(all || strcasecmp(tmp->varname, varname) == 0) | |
3664 { | |
3665 if(!prev) | |
3666 { | |
3667 *root = tmp->next; | |
3668 free(tmp->varname); | |
3669 free(tmp); | |
3670 if(!all) | |
3671 return 0; | |
3672 tmp = *root; | |
3673 } | |
3674 else | |
3675 { | |
3676 /* If all is true we should | |
3677 * never get here. | |
3678 */ | |
3679 prev->next = tmp->next; | |
3680 free(tmp->varname); | |
3681 free(tmp); | |
3682 return 0; | |
3683 } | |
3684 } | |
3685 else | |
3686 { | |
3687 prev = tmp; | |
3688 tmp = tmp->next; | |
3689 } | |
3690 } | |
3691 return 0; | |
3511 } | 3692 } |
3512 | 3693 |
3513 /* | 3694 /* |
3514 * Add a named user data item to a window handle. | 3695 * Add a named user data item to a window handle. |
3515 * Parameters: | 3696 * Parameters: |
3517 * dataname: A string pointer identifying which signal to be hooked. | 3698 * dataname: A string pointer identifying which signal to be hooked. |
3518 * data: User data to be passed to the handler function. | 3699 * data: User data to be passed to the handler function. |
3519 */ | 3700 */ |
3520 void dw_window_set_data(HWND window, char *dataname, void *data) | 3701 void dw_window_set_data(HWND window, char *dataname, void *data) |
3521 { | 3702 { |
3522 NSLog(@"dw_window_set_data() unimplemented\n"); | 3703 id object = window; |
3704 WindowData *blah = (WindowData *)[object userdata]; | |
3705 | |
3706 if(!blah) | |
3707 { | |
3708 if(!dataname) | |
3709 return; | |
3710 | |
3711 blah = calloc(1, sizeof(WindowData)); | |
3712 [object setUserdata:blah]; | |
3713 } | |
3714 | |
3715 if(data) | |
3716 _new_userdata(&(blah->root), dataname, data); | |
3717 else | |
3718 { | |
3719 if(dataname) | |
3720 _remove_userdata(&(blah->root), dataname, FALSE); | |
3721 else | |
3722 _remove_userdata(&(blah->root), NULL, TRUE); | |
3723 } | |
3523 } | 3724 } |
3524 | 3725 |
3525 /* | 3726 /* |
3526 * Gets a named user data item to a window handle. | 3727 * Gets a named user data item to a window handle. |
3527 * Parameters: | 3728 * Parameters: |
3529 * dataname: A string pointer identifying which signal to be hooked. | 3730 * dataname: A string pointer identifying which signal to be hooked. |
3530 * data: User data to be passed to the handler function. | 3731 * data: User data to be passed to the handler function. |
3531 */ | 3732 */ |
3532 void *dw_window_get_data(HWND window, char *dataname) | 3733 void *dw_window_get_data(HWND window, char *dataname) |
3533 { | 3734 { |
3534 NSLog(@"dw_window_get_data() unimplemented\n"); | 3735 id object = window; |
3736 WindowData *blah = (WindowData *)[object userdata]; | |
3737 | |
3738 if(blah && blah->root && dataname) | |
3739 { | |
3740 UserData *ud = _find_userdata(&(blah->root), dataname); | |
3741 if(ud) | |
3742 return ud->data; | |
3743 } | |
3535 return NULL; | 3744 return NULL; |
3536 } | 3745 } |
3537 | 3746 |
3538 /* | 3747 /* |
3539 * Add a callback to a timer event. | 3748 * Add a callback to a timer event. |
4516 dw_box_pack_start(window, box, 0, 0, TRUE, TRUE, 0); | 4725 dw_box_pack_start(window, box, 0, 0, TRUE, TRUE, 0); |
4517 dw_window_show(window); | 4726 dw_window_show(window); |
4518 dw_window_set_pos_size(window, 400, 400, 500, 500); | 4727 dw_window_set_pos_size(window, 400, 400, 500, 500); |
4519 dw_window_get_pos_size(window, &x, &y, &width, &height); | 4728 dw_window_get_pos_size(window, &x, &y, &width, &height); |
4520 dw_messagebox("Dynamic Windows Information", DW_MB_OK | DW_MB_INFORMATION, "%d %d %d %d %d %d %d\n", (int)x, (int)y, (int)width, (int)height, (int)dw_screen_width(), (int)dw_screen_height(), (int)dw_color_depth_get()); | 4729 dw_messagebox("Dynamic Windows Information", DW_MB_OK | DW_MB_INFORMATION, "%d %d %d %d %d %d %d\n", (int)x, (int)y, (int)width, (int)height, (int)dw_screen_width(), (int)dw_screen_height(), (int)dw_color_depth_get()); |
4730 dw_messagebox("File selection", DW_MB_OK | DW_MB_INFORMATION, "%s", dw_file_browse("Choose file", "", "", DW_FILE_OPEN)); | |
4521 dw_main(); | 4731 dw_main(); |
4522 | 4732 |
4523 return 0; | 4733 return 0; |
4524 } | 4734 } |
4525 #endif | 4735 #endif |