# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1306992225 0 # Node ID 48f43c9755334aa291482f328e5d6769a93be21b # Parent b3674ea2909f3f8feb3899e0d4611a24bfba0faf Added dw_font_choose() on the Mac for 2.1. diff -r b3674ea2909f -r 48f43c975533 dw.h --- a/dw.h Wed Jun 01 23:07:27 2011 +0000 +++ b/dw.h Thu Jun 02 05:23:45 2011 +0000 @@ -1617,6 +1617,7 @@ void API dw_color_foreground_set(unsigned long value); void API dw_color_background_set(unsigned long value); unsigned long API dw_color_choose(unsigned long value); +char * API dw_font_choose(char *currfont); void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y); void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2); void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height); diff -r b3674ea2909f -r 48f43c975533 mac/dw.m --- a/mac/dw.m Wed Jun 01 23:07:27 2011 +0000 +++ b/mac/dw.m Thu Jun 02 05:23:45 2011 +0000 @@ -1110,6 +1110,31 @@ -(DWDialog *)dialog { return dialog; } @end +/* Subclass for a font chooser type */ +@interface DWFontChoose : NSFontPanel +{ + DWDialog *dialog; + NSFontManager *fontManager; +} +-(void)setDialog:(DWDialog *)input; +-(void)setFontManager:(NSFontManager *)input; +-(DWDialog *)dialog; +@end + +@implementation DWFontChoose +-(BOOL)windowShouldClose:(id)window +{ + DWDialog *d = dialog; dialog = nil; + NSFont *pickedfont = [fontManager selectedFont]; + dw_dialog_dismiss(d, pickedfont); + [window orderOut:nil]; + return NO; +} +-(void)setDialog:(DWDialog *)input { dialog = input; } +-(void)setFontManager:(NSFontManager *)input { fontManager = input; } +-(DWDialog *)dialog { return dialog; } +@end + /* Subclass for a splitbar type */ @interface DWSplitBar : NSSplitView #ifdef BUILDING_FOR_SNOW_LEOPARD @@ -7205,6 +7230,60 @@ return font; } +/* Allows the user to choose a color using the system's color chooser dialog. + * Parameters: + * value: current color + * Returns: + * The selected color or the current color if cancelled. + */ +char * API dw_font_choose(char *currfont) +{ + /* Create the Color Chooser Dialog class. */ + static DWFontChoose *fontDlg = nil; + static NSFontManager *fontManager = nil; + DWDialog *dialog; + NSFont *font = nil; + + if(currfont) + font = _dw_font_by_name(currfont); + + if(fontDlg) + { + dialog = [fontDlg dialog]; + /* If someone is already waiting just return */ + if(dialog) + { + return NULL; + } + } + else + { + [NSFontManager setFontPanelFactory:[DWFontChoose class]]; + fontManager = [NSFontManager sharedFontManager]; + fontDlg = (DWFontChoose *)[fontManager fontPanel:YES]; + } + + dialog = dw_dialog_new(fontDlg); + if(font) + [fontManager setSelectedFont:font isMultiple:NO]; + else + [fontManager setSelectedFont:[NSFont fontWithName:@"Helvetica" size:9.0] isMultiple:NO]; + [fontDlg setDialog:dialog]; + [fontDlg setFontManager:fontManager]; + [fontManager orderFrontFontPanel:fontManager]; + + + /* Wait for them to pick a color */ + font = (NSFont *)dw_dialog_wait(dialog); + if(font) + { + NSString *fontname = [font displayName]; + NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]]; + return strdup([output UTF8String]); + } + return NULL; +} + /* * Sets the font used by a specified window (widget) handle. * Parameters: