From d7fd2d77a0ccbe637c03867c88a70147aa443d70 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 11 Jul 2002 04:11:41 +0000 Subject: reenabled and improved support for Fl_Sys_Menu_Bar which is a subclass of Fl_Menu_Bar and allows restricted access to the Apple typical top menu bar. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2503 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Sys_Menu_Bar.cxx | 26 +++++++++++-------- src/Fl_mac.cxx | 67 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/Fl_Sys_Menu_Bar.cxx b/src/Fl_Sys_Menu_Bar.cxx index f75981c53..14f94e201 100644 --- a/src/Fl_Sys_Menu_Bar.cxx +++ b/src/Fl_Sys_Menu_Bar.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Sys_Menu_Bar.cxx,v 1.1.2.4 2002/04/11 11:52:41 easysw Exp $" +// "$Id: Fl_Sys_Menu_Bar.cxx,v 1.1.2.5 2002/07/11 04:11:41 matthiaswm Exp $" // // MacOS system menu bar widget for the Fast Light Tool Kit (FLTK). // @@ -117,21 +117,26 @@ enum { ÊÊÊÊkMenuNoCommandModifierÊÊ= (1 << 3) }; */ -static void setShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m ) +static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m ) { if ( !m->shortcut_ ) return; + if ( m->flags & FL_SUBMENU ) + return; + if ( m->flags & FL_SUBMENU_POINTER ) + return; char key = m->shortcut_ & 0xff; if ( !isalnum( key ) ) return; - char mod = m->shortcut_ & 0xff00; long macMod = kMenuNoModifiers; - if ( mod & FL_SHIFT ) macMod |= kMenuShiftModifier; - if ( mod & FL_CTRL ) macMod |= kMenuOptionModifier; - if ( !(mod & FL_ALT) ) macMod |= kMenuNoCommandModifier; + if ( m->shortcut_ & FL_SHIFT || isupper(key) ) macMod |= kMenuShiftModifier; + if ( m->shortcut_ & FL_ALT ) macMod |= kMenuOptionModifier; + if ( m->shortcut_ & FL_META ) macMod |= kMenuControlModifier; + if ( !(m->shortcut_ & FL_CTRL) ) macMod |= kMenuNoCommandModifier; - SetItemCmd( mh, miCnt, key ); + //SetMenuItemKeyGlyph( mh, miCnt, key ); + SetItemCmd( mh, miCnt, toupper(key) ); SetMenuItemModifiers( mh, miCnt, macMod ); } @@ -144,7 +149,7 @@ static void catMenuShortcut( const Fl_Menu_Item *m, char *dst ) return; while ( *dst ) dst++; - if ( m->shortcut_ & FL_ALT ) + if ( m->shortcut_ & FL_CTRL ) { sprintf( dst, "/%c", toupper( c ) ); } @@ -184,7 +189,7 @@ static void createSubMenu( MenuHandle mh, int &cnt, pFl_Menu_Item &mm ) MenuHandle smh; buf[1] = 0; catMenuFont( mm, buf+1 ); - catMenuShortcut( mm, buf+1 ); + //catMenuShortcut( mm, buf+1 ); catMenuText( mm->text, buf+1 ); catMenuFlags( mm, buf+1 ); if ( mm->flags & (FL_SUBMENU | FL_SUBMENU_POINTER) ) @@ -199,6 +204,7 @@ static void createSubMenu( MenuHandle mh, int &cnt, pFl_Menu_Item &mm ) AppendMenu( mh, (unsigned char*)buf ); // insert Appearanc manager functions here! setMenuFlags( mh, miCnt, mm ); + setMenuShortcut( mh, miCnt, mm ); SetMenuItemRefCon( mh, miCnt, (UInt32)mm ); miCnt++; if ( mm->flags & FL_MENU_DIVIDER ) @@ -310,5 +316,5 @@ int Fl_Menu_Bar::handle(int event) { */ // -// End of "$Id: Fl_Sys_Menu_Bar.cxx,v 1.1.2.4 2002/04/11 11:52:41 easysw Exp $". +// End of "$Id: Fl_Sys_Menu_Bar.cxx,v 1.1.2.5 2002/07/11 04:11:41 matthiaswm Exp $". // diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx index 7ecac1410..fc8983c8d 100644 --- a/src/Fl_mac.cxx +++ b/src/Fl_mac.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_mac.cxx,v 1.1.2.30 2002/07/11 01:10:15 matthiaswm Exp $" +// "$Id: Fl_mac.cxx,v 1.1.2.31 2002/07/11 04:11:41 matthiaswm Exp $" // // MacOS specific code for the Fast Light Tool Kit (FLTK). // @@ -300,6 +300,54 @@ static void HandleDataReady(fd_set& r, fd_set& w, fd_set& x) } } + +/** + * handle Apple Menu items (can be created using the Fl_Sys_Menu_Bar + * returns eventNotHandledErr if the menu item could not be handled + */ +OSStatus HandleMenu( HICommand *cmd ) +{ + OSStatus ret = eventNotHandledErr; + // attributes, commandIDm menu.menuRef, menu.menuItemIndex + UInt32 ref; + OSErr rrc = GetMenuItemRefCon( cmd->menu.menuRef, cmd->menu.menuItemIndex, &ref ); + //printf( "%d, %08x, %08x, %d, %d, %8x\n", rrc, cmd->attributes, cmd->commandID, cmd->menu.menuRef, cmd->menu.menuItemIndex, rrc ); + if ( rrc==noErr && ref ) + { + Fl_Menu_Item *m = (Fl_Menu_Item*)ref; + //printf( "Menu: %s\n", m->label() ); + fl_sys_menu_bar->picked( m ); + if ( m->flags & FL_MENU_TOGGLE ) // update the menu toggle symbol + SetItemMark( cmd->menu.menuRef, cmd->menu.menuItemIndex, (m->flags & FL_MENU_VALUE ) ? 0x12 : 0 ); + if ( m->flags & FL_MENU_RADIO ) // update all radio buttons in this menu + { + Fl_Menu_Item *j = m; + int i = cmd->menu.menuItemIndex; + for (;;) + { + if ( j->flags & FL_MENU_DIVIDER ) + break; + j++; i++; + if ( !j->text || !j->radio() ) + break; + SetItemMark( cmd->menu.menuRef, i, ( j->flags & FL_MENU_VALUE ) ? 0x13 : 0 ); + } + j = m-1; i = cmd->menu.menuItemIndex-1; + for ( ; i>0; j--, i-- ) + { + if ( !j->text || j->flags&FL_MENU_DIVIDER || !j->radio() ) + break; + SetItemMark( cmd->menu.menuRef, i, ( j->flags & FL_MENU_VALUE ) ? 0x13 : 0 ); + } + SetItemMark( cmd->menu.menuRef, cmd->menu.menuItemIndex, ( m->flags & FL_MENU_VALUE ) ? 0x13 : 0 ); + } + ret = noErr; // done handling this event + } + HiliteMenu(0); + return ret; +} + + /** * We can make every event pass through this function * - mouse events need to be manipulated to use a mouse focus window @@ -309,6 +357,7 @@ static void HandleDataReady(fd_set& r, fd_set& w, fd_set& x) static pascal OSStatus carbonDispatchHandler( EventHandlerCallRef nextHandler, EventRef event, void *userData ) { OSStatus ret = eventNotHandledErr; + HICommand cmd; fl_lock_function(); @@ -329,6 +378,15 @@ static pascal OSStatus carbonDispatchHandler( EventHandlerCallRef nextHandler, E break; } break; + case kEventClassCommand: + switch (GetEventKind( event ) ) + { + case kEventCommandProcess: + GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &cmd ); + ret = HandleMenu( &cmd ); + break; + } + break; case kEventClassFLTK: switch ( GetEventKind( event ) ) { @@ -493,7 +551,10 @@ static double do_queued_events( double time = 0.0 ) { kEventClassMouse, kEventMouseDragged }, { kEventClassFLTK, kEventFLTKBreakLoop }, { kEventClassFLTK, kEventFLTKDataReady } }; - ret = InstallEventHandler( target, dispatchHandler, 16, dispatchEvents, 0, 0L ); + ret = InstallEventHandler( target, dispatchHandler, GetEventTypeCount(dispatchEvents), dispatchEvents, 0, 0L ); + static EventTypeSpec appEvents[] = { + { kEventClassCommand, kEventCommandProcess } }; + ret = InstallApplicationEventHandler( dispatchHandler, GetEventTypeCount(appEvents), appEvents, 0, 0L ); ret = InstallEventLoopTimer( GetMainEventLoop(), 0, 0, NewEventLoopTimerUPP( timerProcCB ), 0, &timer ); } @@ -1683,6 +1744,6 @@ void Fl::paste(Fl_Widget &receiver, int clipboard) { // -// End of "$Id: Fl_mac.cxx,v 1.1.2.30 2002/07/11 01:10:15 matthiaswm Exp $". +// End of "$Id: Fl_mac.cxx,v 1.1.2.31 2002/07/11 04:11:41 matthiaswm Exp $". // -- cgit v1.2.3