diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2009-12-12 18:06:49 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2009-12-12 18:06:49 +0000 |
| commit | 0d99b353a4785d932c56901a6bce5672bccd2bf9 (patch) | |
| tree | f5d1e7a978a9a0085e5df01036cef8ffe274e071 /src | |
| parent | a85efbce2612dde7942d3d2c3ad3b3d844b27427 (diff) | |
Sorted Xcode source files (somewhat). Added Manolos patches to fix the Sys_Menu widget pointer.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6962 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Sys_Menu_Bar.cxx | 89 | ||||
| -rw-r--r-- | src/Fl_cocoa.mm | 74 |
2 files changed, 88 insertions, 75 deletions
diff --git a/src/Fl_Sys_Menu_Bar.cxx b/src/Fl_Sys_Menu_Bar.cxx index da0451582..59ca6d4f8 100644 --- a/src/Fl_Sys_Menu_Bar.cxx +++ b/src/Fl_Sys_Menu_Bar.cxx @@ -77,7 +77,7 @@ typedef const Fl_Menu_Item *pFl_Menu_Item; */ #ifndef __APPLE_COCOA__ - static void catMenuText( const char *src, char *dst ) +static void catMenuText( const char *src, char *dst ) { char c; while ( *dst ) @@ -103,7 +103,7 @@ static void catMenuFont( const Fl_Menu_Item *m, char *dst ) return; while ( *dst ) dst++; - + if ( m->labelfont_ & FL_BOLD ) strcat( dst, "<B" ); if ( m->labelfont_ & FL_ITALIC ) @@ -112,28 +112,28 @@ static void catMenuFont( const Fl_Menu_Item *m, char *dst ) // strcat( dst, "<U" ); if ( m->labeltype_ == FL_EMBOSSED_LABEL ) - strcat( dst, "<U" ); + strcat( dst, "<U" ); else if ( m->labeltype_ == FL_ENGRAVED_LABEL ) - strcat( dst, "<O" ); + strcat( dst, "<O" ); else if ( m->labeltype_ == FL_SHADOW_LABEL ) - strcat( dst, "<S" ); + strcat( dst, "<S" ); //else if ( m->labeltype_ == FL_SYMBOL_LABEL ) - ; // not supported + ; // not supported } /** * append a marker to identify the menu shortcut * <B, I, U, O, and S -enum { - kMenuNoModifiers = 0, - kMenuShiftModifier = (1 << 0), - kMenuOptionModifier = (1 << 1), - kMenuControlModifier = (1 << 2), - kMenuNoCommandModifier = (1 << 3) -}; -*/ + enum { + kMenuNoModifiers = 0, + kMenuShiftModifier = (1 << 0), + kMenuOptionModifier = (1 << 1), + kMenuControlModifier = (1 << 2), + kMenuNoCommandModifier = (1 << 3) + }; + */ #endif - + static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m ) { if ( !m->shortcut_ ) @@ -190,15 +190,15 @@ static void setMenuFlags( MenuHandle mh, int miCnt, const Fl_Menu_Item *m ) if ( m->flags & FL_MENU_TOGGLE ) { #ifdef __APPLE_COCOA__ - void *menuItem = MACMenuOrItemOperation("itemAtIndex", mh, miCnt); - MACMenuOrItemOperation("setState", menuItem, m->flags & FL_MENU_VALUE ); + void *menuItem = MACMenuOrItemOperation("itemAtIndex", mh, miCnt); + MACMenuOrItemOperation("setState", menuItem, m->flags & FL_MENU_VALUE ); #else - SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x12 : 0 ); + SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x12 : 0 ); #endif } else if ( m->flags & FL_MENU_RADIO ) { #ifndef __APPLE_COCOA__ - SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x13 : 0 ); + SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x13 : 0 ); #endif } } @@ -222,20 +222,20 @@ static void createSubMenu( void * mh, pFl_Menu_Item &mm ) menuItem = MACMenuOrItemOperation("itemAtIndex", mh, cnt); MACMenuOrItemOperation("setSubmenu", menuItem, submenu); if ( mm->flags & FL_MENU_INACTIVE ) { - MACMenuOrItemOperation("setEnabled", menuItem, 0); + MACMenuOrItemOperation("setEnabled", menuItem, 0); } mm++; while ( mm->text ) { - MACMenuOrItemOperation("addNewItem", submenu, mm->text, mm->callback_, mm->user_data_, &miCnt); + MACMenuOrItemOperation("addNewItem", submenu, mm, &miCnt); setMenuFlags( submenu, miCnt, mm ); setMenuShortcut( submenu, miCnt, mm ); - if ( mm->flags & FL_MENU_INACTIVE ) { - void *item = MACMenuOrItemOperation("itemAtIndex", submenu, miCnt); - MACMenuOrItemOperation("setEnabled", item, 0); - } - flags = mm->flags; + if ( mm->flags & FL_MENU_INACTIVE ) { + void *item = MACMenuOrItemOperation("itemAtIndex", submenu, miCnt); + MACMenuOrItemOperation("setEnabled", item, 0); + } + flags = mm->flags; if ( mm->flags & FL_SUBMENU ) { createSubMenu( submenu, mm ); @@ -246,12 +246,12 @@ static void createSubMenu( void * mh, pFl_Menu_Item &mm ) createSubMenu( submenu, smm ); } if ( flags & FL_MENU_DIVIDER ) { - MACMenuOrItemOperation("addSeparatorItem", submenu); - } + MACMenuOrItemOperation("addSeparatorItem", submenu); + } mm++; } } - + /** * create a system menu bar using the given list of menu structs @@ -266,16 +266,15 @@ void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m) fl_open_display(); Fl_Menu_Bar::menu( m ); fl_sys_menu_bar = this; - - + + const Fl_Menu_Item *mm = m; for (;;) { if ( !mm || !mm->text ) break; char visible = mm->visible() ? 1 : 0; - MACMenuOrItemOperation("addNewItem", MACmainMenu(), mm->text, NULL, NULL, NULL); - + MACMenuOrItemOperation("addNewItem", MACmainMenu(), mm, NULL); if ( mm->flags & FL_SUBMENU ) createSubMenu( MACmainMenu(), mm ); else if ( mm->flags & FL_SUBMENU_POINTER ) { @@ -283,7 +282,7 @@ void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m) createSubMenu( MACmainMenu(), smm ); } if ( visible ) { -// InsertMenu( mh, 0 ); + // InsertMenu( mh, 0 ); } mm++; } @@ -395,17 +394,17 @@ void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m) #endif //__APPLE_COCOA__ /* -const Fl_Menu_Item* Fl_Sys_Menu_Bar::picked(const Fl_Menu_Item* v) { - Fl_menu_Item *ret = Fl_Menu_Bar::picked( v ); - - if ( m->flags & FL_MENU_TOGGLE ) - { - SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x12 : 0 ); - } - - return ret; -} -*/ + const Fl_Menu_Item* Fl_Sys_Menu_Bar::picked(const Fl_Menu_Item* v) { + Fl_menu_Item *ret = Fl_Menu_Bar::picked( v ); + + if ( m->flags & FL_MENU_TOGGLE ) + { + SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x12 : 0 ); + } + + return ret; + } + */ void Fl_Sys_Menu_Bar::draw() { } diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 4b869cc1d..40c1b99b5 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -123,6 +123,7 @@ static int got_events = 0; static Fl_Window* resize_from_system; static NSView *viewWithLockedFocus = nil; static SInt32 MACsystemVersion; +void *MACMenuOrItemOperation(const char *operation, ...); #if CONSOLIDATE_MOTION static Fl_Window* send_motion; @@ -2824,27 +2825,33 @@ static void createAppleMenu(void) } @interface FLMenuItem : NSMenuItem { - Fl_Callback *cb; - void *data; + const Fl_Menu_Item *item; } -- (FLMenuItem*) putData:(Fl_Callback*)callback pter:(void*)d; -- (void) doCallback:(id)obj; -- (void*)getItemData; -@end +- (void) setFlMenuItem:(const Fl_Menu_Item*)flItem; +- (void) doCallback:(id)unused; +- (void) directCallback:(id)unused; +- (Fl_Menu_Item*)getFlMenuItem;@end @implementation FLMenuItem -- (FLMenuItem*) putData:(Fl_Callback*)callback pter:(void*)d +- (void) setFlMenuItem:(const Fl_Menu_Item*)flItem { - cb = callback; - data = d; - return self; + item = flItem; } -- (void) doCallback:(id)obj +- (void) doCallback:(id)unused { - if (cb) cb((Fl_Widget*)obj, data); + if(item) { + fl_sys_menu_bar->picked(item); + if ( item->flags & FL_MENU_TOGGLE ) {// update the menu toggle symbol + [(NSMenuItem*)unused setState:(item->value() ? NSOnState : NSOffState)]; + } + } } -- (void*)getItemData +- (void) directCallback:(id)unused { - return data; + if( item && item->callback() ) item->do_callback(NULL); +} +- (const Fl_Menu_Item*)getFlMenuItem +{ + return item; } @end @@ -2873,16 +2880,26 @@ void *MACcreateMenu(const char *name) return (void *)mymenu; } -void MACsetAboutMenu( Fl_Callback *cb, void *data ) -// attaches a callback to the "About myprog" item of the application menu +void fl_mac_set_about( Fl_Menu_Item *flItem ) +/** + * Mac OS: attaches an Fl_Menu_Item to the "About myprog" item of the system application menu. + * \note Only the shortcut_, callback_ and user_data_ fields of the Fl_Menu_Item* \p flItem are used. + * + * \author Manolo Gouy + * + * \param[in] flItem is a const Fl_Menu_Item* + */ { fl_open_display(); CFStringRef cfname = CFStringCreateCopy(NULL, (CFStringRef)[[appleMenu itemAtIndex:0] title]); [appleMenu removeItemAtIndex:0]; FLMenuItem *item = [[FLMenuItem alloc] autorelease]; - [item initWithTitle:(NSString*)cfname action:@selector(doCallback:) keyEquivalent:@""]; - [item putData:cb pter:data]; - [appleMenu insertItem:item atIndex:0]; + [item initWithTitle:(NSString*)cfname action:@selector(directCallback:) keyEquivalent:@""]; + if(flItem->shortcut()) { + MACMenuOrItemOperation("setKeyEquivalent", item, flItem->shortcut() & 0xff); + MACMenuOrItemOperation("setKeyEquivalentModifierMask", item, flItem->shortcut() ); + } + [item setFlMenuItem:flItem]; [appleMenu insertItem:item atIndex:0]; CFRelease(cfname); [item setTarget:item]; } @@ -2991,27 +3008,24 @@ void *MACMenuOrItemOperation(const char *operation, ...) value = va_arg(ap, int); [menu removeItem:[menu itemAtIndex:value]]; } - else if(strcmp(operation, "getItemData") == 0) {//arguments: NSMenu*, int. Returns the item's data - //items can have a callback and a data pointer attached to them. This returns the data pointer - menu = va_arg(ap, NSMenu*); + else if(strcmp(operation, "getFlMenuItem") == 0) {//arguments: NSMenu*, int. Returns the item's Fl_Menu_Item* menu = va_arg(ap, NSMenu*); value = va_arg(ap, int); - retval = [(FLMenuItem *)[menu itemAtIndex:value] getItemData]; + retval = [(FLMenuItem *)[menu itemAtIndex:value] getFlMenuItem]; } else if(strcmp(operation, "addNewItem") == 0) { - //arguments: NSMenu *menu, const char *name, Fl_Callback *cb, void *data, int *prank - //creates a new menu item named 'name' at the end of 'menu' - //attaches callback 'cb' and data pointer 'data' to it + //arguments: NSMenu *menu, const Fl_Menu_Item* flItem, int *prank + //creates a new menu item at the end of 'menu' + //attaches the Fl_Menu_Item *flItem to it //upon return, puts the rank of the new item in *prank unless prank is NULL menu = va_arg(ap, NSMenu*); - char *name = remove_ampersand(va_arg(ap, const char*)); - Fl_Callback *cb = va_arg(ap, Fl_Callback*); - pter = va_arg(ap, void *); + const Fl_Menu_Item *flItem = va_arg(ap, const Fl_Menu_Item*); + char *name = remove_ampersand(flItem->label()); int *prank = va_arg(ap, int*); CFStringRef cfname = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8); free(name); FLMenuItem *item = [FLMenuItem alloc]; [item initWithTitle:(NSString*)cfname action:@selector(doCallback:) keyEquivalent:@""]; - [item putData:cb pter:pter]; + [item setFlMenuItem:flItem]; [menu addItem:item]; CFRelease(cfname); [item setTarget:item]; |
