Mercurial > dwindows
comparison mac/dw.m @ 1050:48f43c975533
Added dw_font_choose() on the Mac for 2.1.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 02 Jun 2011 05:23:45 +0000 |
parents | 70bad8a91370 |
children | 6919854298fd |
comparison
equal
deleted
inserted
replaced
1049:b3674ea2909f | 1050:48f43c975533 |
---|---|
1105 | 1105 |
1106 @implementation DWColorChoose | 1106 @implementation DWColorChoose |
1107 -(void)changeColor:(id)sender { pickedcolor = [self color]; } | 1107 -(void)changeColor:(id)sender { pickedcolor = [self color]; } |
1108 -(BOOL)windowShouldClose:(id)window { DWDialog *d = dialog; dialog = nil; dw_dialog_dismiss(d, pickedcolor); [window orderOut:nil]; return NO; } | 1108 -(BOOL)windowShouldClose:(id)window { DWDialog *d = dialog; dialog = nil; dw_dialog_dismiss(d, pickedcolor); [window orderOut:nil]; return NO; } |
1109 -(void)setDialog:(DWDialog *)input { dialog = input; } | 1109 -(void)setDialog:(DWDialog *)input { dialog = input; } |
1110 -(DWDialog *)dialog { return dialog; } | |
1111 @end | |
1112 | |
1113 /* Subclass for a font chooser type */ | |
1114 @interface DWFontChoose : NSFontPanel | |
1115 { | |
1116 DWDialog *dialog; | |
1117 NSFontManager *fontManager; | |
1118 } | |
1119 -(void)setDialog:(DWDialog *)input; | |
1120 -(void)setFontManager:(NSFontManager *)input; | |
1121 -(DWDialog *)dialog; | |
1122 @end | |
1123 | |
1124 @implementation DWFontChoose | |
1125 -(BOOL)windowShouldClose:(id)window | |
1126 { | |
1127 DWDialog *d = dialog; dialog = nil; | |
1128 NSFont *pickedfont = [fontManager selectedFont]; | |
1129 dw_dialog_dismiss(d, pickedfont); | |
1130 [window orderOut:nil]; | |
1131 return NO; | |
1132 } | |
1133 -(void)setDialog:(DWDialog *)input { dialog = input; } | |
1134 -(void)setFontManager:(NSFontManager *)input { fontManager = input; } | |
1110 -(DWDialog *)dialog { return dialog; } | 1135 -(DWDialog *)dialog { return dialog; } |
1111 @end | 1136 @end |
1112 | 1137 |
1113 /* Subclass for a splitbar type */ | 1138 /* Subclass for a splitbar type */ |
1114 @interface DWSplitBar : NSSplitView | 1139 @interface DWSplitBar : NSSplitView |
7203 } | 7228 } |
7204 free(fontcopy); | 7229 free(fontcopy); |
7205 return font; | 7230 return font; |
7206 } | 7231 } |
7207 | 7232 |
7233 /* Allows the user to choose a color using the system's color chooser dialog. | |
7234 * Parameters: | |
7235 * value: current color | |
7236 * Returns: | |
7237 * The selected color or the current color if cancelled. | |
7238 */ | |
7239 char * API dw_font_choose(char *currfont) | |
7240 { | |
7241 /* Create the Color Chooser Dialog class. */ | |
7242 static DWFontChoose *fontDlg = nil; | |
7243 static NSFontManager *fontManager = nil; | |
7244 DWDialog *dialog; | |
7245 NSFont *font = nil; | |
7246 | |
7247 if(currfont) | |
7248 font = _dw_font_by_name(currfont); | |
7249 | |
7250 if(fontDlg) | |
7251 { | |
7252 dialog = [fontDlg dialog]; | |
7253 /* If someone is already waiting just return */ | |
7254 if(dialog) | |
7255 { | |
7256 return NULL; | |
7257 } | |
7258 } | |
7259 else | |
7260 { | |
7261 [NSFontManager setFontPanelFactory:[DWFontChoose class]]; | |
7262 fontManager = [NSFontManager sharedFontManager]; | |
7263 fontDlg = (DWFontChoose *)[fontManager fontPanel:YES]; | |
7264 } | |
7265 | |
7266 dialog = dw_dialog_new(fontDlg); | |
7267 if(font) | |
7268 [fontManager setSelectedFont:font isMultiple:NO]; | |
7269 else | |
7270 [fontManager setSelectedFont:[NSFont fontWithName:@"Helvetica" size:9.0] isMultiple:NO]; | |
7271 [fontDlg setDialog:dialog]; | |
7272 [fontDlg setFontManager:fontManager]; | |
7273 [fontManager orderFrontFontPanel:fontManager]; | |
7274 | |
7275 | |
7276 /* Wait for them to pick a color */ | |
7277 font = (NSFont *)dw_dialog_wait(dialog); | |
7278 if(font) | |
7279 { | |
7280 NSString *fontname = [font displayName]; | |
7281 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]]; | |
7282 return strdup([output UTF8String]); | |
7283 } | |
7284 return NULL; | |
7285 } | |
7286 | |
7208 /* | 7287 /* |
7209 * Sets the font used by a specified window (widget) handle. | 7288 * Sets the font used by a specified window (widget) handle. |
7210 * Parameters: | 7289 * Parameters: |
7211 * handle: The window (widget) handle. | 7290 * handle: The window (widget) handle. |
7212 * fontname: Name and size of the font in the form "size.fontname" | 7291 * fontname: Name and size of the font in the form "size.fontname" |