static bool sUMAHasAppearance = false ;
static long sUMAAppearanceVersion = 0 ;
+static long sUMASystemVersion = 0 ;
static bool sUMAHasAquaLayout = false ;
static bool sUMASystemInitialized = false ;
extern int gAGABackgroundColor ;
bool UMAHasAppearance() { return sUMAHasAppearance ; }
long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
+long UMAGetSystemVersion() { return sUMASystemVersion ; }
static bool sUMAHasWindowManager = false ;
static long sUMAWindowManagerAttr = 0 ;
InitCursor();
#endif
+ if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr)
+ sUMASystemVersion = 0x0000 ;
+
long theAppearance ;
if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
{
NavLoad() ;
}
+ long menuMgrAttr ;
+ Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ;
+ if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask )
+ sUMAHasAquaLayout = true ;
+
if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress )
{
FontFamilyID fontId ;
TXNInitTextension(fontDescriptions, noOfFontDescriptions, options );
}
- long menuMgrAttr ;
- Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ;
- if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask )
- sUMAHasAquaLayout = true ;
+
sUMASystemInitialized = true ;
}
// menu manager
-void UMASetMenuTitle( MenuRef menu , StringPtr title )
+MenuRef UMANewMenu( SInt16 id , const wxString& title )
{
-/*
-#if !TARGET_CARBON
- long size = GetHandleSize( (Handle) menu ) ;
- const long headersize = 14 ;
- int oldlen = (**menu).menuData[0] + 1;
- int newlen = title[0] + 1 ;
-
- if ( oldlen < newlen )
- {
- // enlarge before adjusting
- SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
- }
+ wxString str = wxStripMenuCodes( title ) ;
+ MenuRef menu ;
+#if TARGET_CARBON
+ CFStringRef cfs = wxMacCreateCFString( str ) ;
+ CreateNewMenu( id , 0 , &menu ) ;
+ SetMenuTitleWithCFString( menu , cfs ) ;
+ CFRelease( cfs ) ;
+#else
+ Str255 ptitle ;
+ wxMacStringToPascal( str , ptitle ) ;
+ menu = ::NewMenu( id , ptitle ) ;
+#endif
+ return menu ;
+}
- if ( oldlen != newlen )
- memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
+void UMASetMenuTitle( MenuRef menu , const wxString& title )
+{
+ wxString str = wxStripMenuCodes( title ) ;
+#if TARGET_CARBON
+ CFStringRef cfs = wxMacCreateCFString( str ) ;
+ SetMenuTitleWithCFString( menu , cfs ) ;
+ CFRelease( cfs ) ;
+#else
+ Str255 ptitle ;
+ wxMacStringToPascal( str , ptitle ) ;
+ SetMenuTitle( menu , ptitle ) ;
+#endif
+}
- memcpy( (char*) (**menu).menuData , title , newlen ) ;
- if ( oldlen > newlen )
- {
- // shrink after
- SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
- }
+void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title )
+{
+ wxString str = wxStripMenuCodes( title ) ;
+#if TARGET_CARBON
+ CFStringRef cfs = wxMacCreateCFString( str ) ;
+ SetMenuItemTextWithCFString( menu , item , cfs ) ;
+ CFRelease( cfs ) ;
#else
-*/
- SetMenuTitle( menu , title ) ;
-//#endif
+ Str255 ptitle ;
+ wxMacStringToPascal( str , ptitle ) ;
+ SetMenuItemText( menu , item , ptitle ) ;
+#endif
}
+
UInt32 UMAMenuEvent( EventRecord *inEvent )
{
return MenuEvent( inEvent ) ;
}
-void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
+void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
{
- EnableMenuItem( inMenu , inItem ) ;
+ if ( enable )
+ EnableMenuItem( inMenu , inItem ) ;
+ else
+ DisableMenuItem( inMenu , inItem ) ;
}
-void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
+void UMAAppendSubMenuItem( MenuRef menu , const wxString& title , SInt16 id )
{
- DisableMenuItem( inMenu , inItem ) ;
+ MacAppendMenu(menu, "\pA");
+ UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title );
+ SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
}
-void UMAAppendSubMenuItem( MenuRef menu , StringPtr l , SInt16 id )
+void UMAInsertSubMenuItem( MenuRef menu , const wxString& title , MenuItemIndex item , SInt16 id )
{
- Str255 label ;
- memcpy( label , l , l[0]+1 ) ;
- // hardcoded adding of the submenu combination for mac
-
- int theEnd = label[0] + 1;
- if (theEnd > 251)
- theEnd = 251; // mac allows only 255 characters
- label[theEnd++] = '/';
- label[theEnd++] = hMenuCmd;
- label[theEnd++] = '!';
- label[theEnd++] = id ;
- label[theEnd] = 0x00;
- label[0] = theEnd;
- MacAppendMenu(menu, label);
+ MacInsertMenuItem(menu, "\pA" , item);
+ UMASetMenuItemText(menu, item , title );
+ SetMenuItemHierarchicalID( menu , item , id ) ;
}
-void UMAInsertSubMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 id )
+void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
{
- Str255 label ;
- memcpy( label , l , l[0]+1 ) ;
- // hardcoded adding of the submenu combination for mac
+ if ( !entry )
+ return ;
+
+ UInt8 modifiers = 0 ;
+ SInt16 key = entry->GetKeyCode() ;
+ if ( key )
+ {
+ bool explicitCommandKey = false ;
+
+ if ( entry->GetFlags() & wxACCEL_CTRL )
+ {
+ explicitCommandKey = true ;
+ }
+
+ if (entry->GetFlags() & wxACCEL_ALT )
+ {
+ modifiers |= kMenuOptionModifier ;
+ }
- int theEnd = label[0] + 1;
- if (theEnd > 251)
- theEnd = 251; // mac allows only 255 characters
- label[theEnd++] = '/';
- label[theEnd++] = hMenuCmd;
- label[theEnd++] = '!';
- label[theEnd++] = id;
- label[theEnd] = 0x00;
- label[0] = theEnd;
- MacInsertMenuItem(menu, label , item);
+ if (entry->GetFlags() & wxACCEL_SHIFT)
+ {
+ modifiers |= kMenuShiftModifier ;
+ }
+
+ SInt16 glyph = 0 ;
+ SInt16 macKey = key ;
+ if ( key >= WXK_F1 && key <= WXK_F15 )
+ {
+ macKey = kFunctionKeyCharCode ;
+ glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
+ if ( key >= WXK_F13 )
+ glyph += 13 ;
+ if ( !explicitCommandKey )
+ modifiers |= kMenuNoCommandModifier ;
+
+ switch( key )
+ {
+ case WXK_F1 :
+ macKey += ( 0x7a << 8 ) ;
+ break ;
+ case WXK_F2 :
+ macKey += ( 0x78 << 8 ) ;
+ break ;
+ case WXK_F3 :
+ macKey += ( 0x63 << 8 ) ;
+ break ;
+ case WXK_F4 :
+ macKey += ( 0x76 << 8 ) ;
+ break ;
+ case WXK_F5 :
+ macKey += ( 0x60 << 8 ) ;
+ break ;
+ case WXK_F6 :
+ macKey += ( 0x61 << 8 ) ;
+ break ;
+ case WXK_F7 :
+ macKey += ( 0x62 << 8 ) ;
+ break ;
+ case WXK_F8 :
+ macKey += ( 0x64 << 8 ) ;
+ break ;
+ case WXK_F9 :
+ macKey += ( 0x65 << 8 ) ;
+ break ;
+ case WXK_F10 :
+ macKey += ( 0x6D << 8 ) ;
+ break ;
+ case WXK_F11 :
+ macKey += ( 0x67 << 8 ) ;
+ break ;
+ case WXK_F12 :
+ macKey += ( 0x6F << 8 ) ;
+ break ;
+ case WXK_F13 :
+ macKey += ( 0x69 << 8 ) ;
+ break ;
+ case WXK_F14 :
+ macKey += ( 0x6B << 8 ) ;
+ break ;
+ case WXK_F15 :
+ macKey += ( 0x71 << 8 ) ;
+ break ;
+ default :
+ break ;
+ } ;
+ // unfortunately this does not yet trigger the right key ,
+ // for some reason mac justs picks the first function key menu
+ // defined, so we turn this off
+ macKey = 0 ;
+ glyph = 0 ;
+ }
+ else
+ {
+ switch( key )
+ {
+ case WXK_BACK :
+ macKey = kBackspaceCharCode ;
+ glyph = kMenuDeleteLeftGlyph ;
+ break ;
+ case WXK_TAB :
+ macKey = kTabCharCode ;
+ glyph = kMenuTabRightGlyph ;
+ break ;
+ case kEnterCharCode :
+ macKey = kEnterCharCode ;
+ glyph = kMenuEnterGlyph ;
+ break ;
+ case WXK_RETURN :
+ macKey = kReturnCharCode ;
+ glyph = kMenuReturnGlyph ;
+ break ;
+ case WXK_ESCAPE :
+ macKey = kEscapeCharCode ;
+ glyph = kMenuEscapeGlyph ;
+ break ;
+ case WXK_SPACE :
+ macKey = ' ' ;
+ glyph = kMenuSpaceGlyph ;
+ break ;
+ case WXK_DELETE :
+ macKey = kDeleteCharCode ;
+ glyph = kMenuDeleteRightGlyph ;
+ break ;
+ case WXK_CLEAR :
+ macKey = kClearCharCode ;
+ glyph = kMenuClearGlyph ;
+ break ;
+ case WXK_PRIOR : // PAGE UP
+ macKey = kPageUpCharCode ;
+ glyph = kMenuPageUpGlyph ;
+ break ;
+ case WXK_NEXT :
+ macKey = kPageDownCharCode ;
+ glyph = kMenuPageDownGlyph ;
+ break ;
+ case WXK_LEFT :
+ macKey = kLeftArrowCharCode ;
+ glyph = kMenuLeftArrowGlyph ;
+ break ;
+ case WXK_UP :
+ macKey = kUpArrowCharCode ;
+ glyph = kMenuUpArrowGlyph ;
+ break ;
+ case WXK_RIGHT :
+ macKey = kRightArrowCharCode ;
+ glyph = kMenuRightArrowGlyph ;
+ break ;
+ case WXK_DOWN :
+ macKey = kDownArrowCharCode ;
+ glyph = kMenuDownArrowGlyph ;
+ break ;
+ }
+ }
+
+ SetItemCmd( menu, item , macKey );
+ SetMenuItemModifiers(menu, item , modifiers ) ;
+
+ if ( glyph )
+ SetMenuItemKeyGlyph(menu, item , glyph ) ;
+ }
}
-void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers )
+void UMAAppendMenuItem( MenuRef menu , const wxString& title , wxAcceleratorEntry *entry )
{
- Str255 label ;
- memcpy( label , l , l[0]+1 ) ;
- if ( key )
- {
- int pos = label[0] ;
- label[++pos] = '/';
- label[++pos] = toupper( key );
- label[0] = pos ;
- }
- MacAppendMenu( menu , label ) ;
+ MacAppendMenu(menu, "\pA");
+ UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title );
+ UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
}
-void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 key, UInt8 modifiers )
+void UMAInsertMenuItem( MenuRef menu , const wxString& title , MenuItemIndex item , wxAcceleratorEntry *entry )
{
- Str255 label ;
- memcpy( label , l , l[0]+1 ) ;
- if ( key )
- {
- int pos = label[0] ;
- label[++pos] = '/';
- label[++pos] = toupper( key );
- label[0] = pos ;
- }
- MacInsertMenuItem( menu , label , item) ;
+ MacInsertMenuItem( menu , "\p" , item) ;
+ UMASetMenuItemText(menu, item , title );
+ UMASetMenuItemShortcut( menu , item , entry ) ;
}
// quickdraw