void Enable( bool enable ) { MenuItemIndex i = FindMenuItemIndex() ; if ( i > 0 ) { if ( GetWXPeer()->GetId() == wxApp::s_macPreferencesMenuItemId) { if ( enable ) EnableMenuCommand( NULL , kHICommandPreferences ) ; else DisableMenuCommand( NULL , kHICommandPreferences ) ; } else if ( GetWXPeer()->GetId() == wxApp::s_macExitMenuItemId) { if ( enable ) EnableMenuCommand( NULL , kHICommandQuit ) ; else DisableMenuCommand( NULL , kHICommandQuit ) ; } if ( enable ) EnableMenuItem(m_parentMenuRef , i); else DisableMenuItem(m_parentMenuRef , i); if ( GetWXPeer()->IsSubMenu() ) { UMAEnableMenuItem( GetWXPeer()->GetSubMenu()->GetHMenu() , 0 , enable ) ; } } }
OSStatus TextViewSpellingSupport( HIViewRef textView, Boolean on ) { OSStatus status = noErr; TXNCommandEventSupportOptions options = 0; TXNObject txnObj = HITextViewGetTXNObject(textView); // Got TXNObject? require( txnObj != NULL, EXIT ); // Get existing option settings... status = TXNGetCommandEventSupport( txnObj, &options ); require_noerr( status, EXIT ); // add or subtract spelling support as requested // (and enable/disable menu items appropriately) if( on ) { options |= kTXNSupportSpellCheckCommandProcessing; options |= kTXNSupportSpellCheckCommandUpdating; EnableMenuCommand(NULL, kHICommandShowSpellingPanel); EnableMenuCommand(NULL, kToggleAutoSpellcheckCommand); verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), CFSTR("SpellSupportEnable") )); } else { if( options & kTXNSupportSpellCheckCommandProcessing ) options ^= kTXNSupportSpellCheckCommandProcessing; if( options & kTXNSupportSpellCheckCommandUpdating ) options ^= kTXNSupportSpellCheckCommandUpdating; DisableMenuCommand(NULL, kHICommandShowSpellingPanel); DisableMenuCommand(NULL, kToggleAutoSpellcheckCommand); verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), CFSTR("SpellSupportDisable") )); } // Set auto spell check state accordingly status = TextViewSpellCheckAsYouType(textView, on); verify_noerr( status ); // reset modified options status = TXNSetCommandEventSupport(txnObj, options); verify_noerr( status ); HIViewSetNeedsDisplay( textView, true ); EXIT: ; return status; }
// Event handling for window focus acquired events pascal OSStatus WindowFocusAcquired(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { #pragma unused (nextHandler, userData) WindowRef window; OSStatus status = noErr; GetEventParameter(theEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); require_noerr( status, CantGetEventParameter); if ( window != NULL ) { HIViewRef textView; status = GetTextViewFromWindow(window, textView); if ( status == noErr ) { UniChar mark; // For checking menu items // Handle font panel menu item and palette if ( TextViewIsFontPanelSupportEnabled(textView) ) { EnableMenuCommand(NULL, kHICommandShowHideFontPanel); if ( ! FPIsFontPanelVisible() ) verify_noerr( FPShowHideFontPanel() ); } else { DisableMenuCommand(NULL, kHICommandShowHideFontPanel); if ( FPIsFontPanelVisible() ) verify_noerr( FPShowHideFontPanel() ); } // Handle spelling menu items if ( TextViewIsSpellingSupportEnabled(textView) ) { EnableMenuCommand(NULL, kHICommandShowSpellingPanel); EnableMenuCommand(NULL, kToggleAutoSpellcheckCommand); MyShowSpellCheckPanel(); } else { DisableMenuCommand(NULL, kHICommandShowSpellingPanel); DisableMenuCommand(NULL, kToggleAutoSpellcheckCommand); } // Auto-spellcheck menu item mark = ( TXNGetSpellCheckAsYouType(HITextViewGetTXNObject(textView)) ) ? kMenuCheckmarkGlyph : kMenuNullGlyph; verify_noerr( SetMenuCommandMark(NULL, kToggleAutoSpellcheckCommand, mark) ); } } CantGetEventParameter: return status; }
EXPORT(sqInt) primitiveEnableMenuCommand(void) { MenuCommand commandID; MenuHandle menuHandle; sqInt menuHandleOop; sqInt anInteger; sqInt _return_value; menuHandleOop = interpreterProxy->stackValue(1); anInteger = interpreterProxy->stackValue(0); if (interpreterProxy->failed()) { return null; } menuHandle = ((MenuHandle) (interpreterProxy->positive64BitValueOf(menuHandleOop))); commandID = ((MenuCommand) (interpreterProxy->positive64BitValueOf(anInteger))); if (!(ioCheckMenuHandle(menuHandle))) { _return_value = interpreterProxy->success(0); if (interpreterProxy->failed()) { return null; } interpreterProxy->popthenPush(3, _return_value); return null; } #if TARGET_API_MAC_CARBON EnableMenuCommand(menuHandle,commandID); #endif; return null; }
void wxMenuItem::UpdateItemStatus() { if ( !m_parentMenu ) return ; if ( IsSeparator() ) return ; #if TARGET_CARBON if ( UMAGetSystemVersion() >= 0x1000 && GetId() == wxApp::s_macPreferencesMenuItemId) { if ( !IsEnabled() ) DisableMenuCommand( NULL , kHICommandPreferences ) ; else EnableMenuCommand( NULL , kHICommandPreferences ) ; } if ( UMAGetSystemVersion() >= 0x1000 && GetId() == wxApp::s_macExitMenuItemId) { if ( !IsEnabled() ) DisableMenuCommand( NULL , kHICommandQuit ) ; else EnableMenuCommand( NULL , kHICommandQuit ) ; } #endif { MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ; MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ; if ( mhandle == NULL || index == 0) return ; UMAEnableMenuItem( mhandle , index , m_isEnabled ) ; if ( IsCheckable() && IsChecked() ) ::SetItemMark( mhandle , index , 0x12 ) ; // checkmark else ::SetItemMark( mhandle , index , 0 ) ; // no mark UMASetMenuItemText( mhandle , index , wxStripMenuCodes(m_text) , wxFont::GetDefaultEncoding() ) ; wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( m_text ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ; delete entry ; } }
/***************************************************** * * main (argc, argv) * * Purpose: main program entry point * * Notes: You might want to change this to something more verbose * * Inputs: argc - the number of elements in the argv array * argv - an array of pointers to the parameters to this application * * Returns: int - error code (0 == no error) */ int main(int argc, char* argv[]) { OSStatus status; // Can we run this particular demo application? long response; status = Gestalt(gestaltSystemVersion, &response); Boolean ok = ((noErr == status) && (response >= 0x00001030)); if (!ok) { DialogRef theAlert; CreateStandardAlert(kAlertStopAlert, CFSTR("Mac OS X 10.3 (minimum) is required for this application"), NULL, NULL, &theAlert); RunStandardAlert(theAlert, NULL, NULL); ExitToShell(); } // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. status = CreateNibReference(CFSTR("main"), &gIBNibRef); require_noerr(status, CantGetNibRef); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. status = SetMenuBarFromNib(gIBNibRef, CFSTR("MenuBar")); require_noerr(status, CantSetMenuBar); // Adding a Font menu MenuRef fontMenu = GetMenuRef(3); require(fontMenu != NULL, CantSetMenuBar); status = CreateStandardFontMenu(fontMenu, 0, 0, 0, NULL); require_noerr(status, CantSetMenuBar); // Enabling Preferences menu item EnableMenuCommand(NULL, kHICommandPreferences); // Let's react to User's commands. Install_AppleEventHandlers(); EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; InstallEventHandler(GetApplicationEventTarget(), Handle_CommandProcess, 1, &eventTypeCP, NULL, NULL); EventTypeSpec eventTypeCUS = {kEventClassCommand, kEventCommandUpdateStatus}; InstallEventHandler(GetApplicationEventTarget(), Handle_CommandUpdateStatus, 1, &eventTypeCUS, NULL, NULL); EventTypeSpec eventTypeAA = {kEventClassApplication, kEventAppActivated}; InstallEventHandler(GetApplicationEventTarget(), Handle_AppActivated, 1, &eventTypeAA, NULL, NULL); // Call the event loop RunApplicationEventLoop(); CantSetMenuBar: CantGetNibRef: return status; } // main
OSStatus DoOpenDocument(void) { OSStatus err = noErr; NavDialogCreationOptions dialogOptions; OurDialogData *dialogDataP = NULL; static NavEventUPP gNavEventProc = NULL; // event proc for our Nav Dialogs if(!gNavEventProc){ gNavEventProc = NewNavEventUPP(NavEventProc); if(!gNavEventProc) err = memFullErr; } // while our open dialog is up we'll disable our Open command, else // we might end up with more than one open dialog. Yuk DisableMenuCommand(NULL, kHICommandOpen); dialogDataP = (OurDialogData *)calloc(1, sizeof(OurDialogData)); if(!dialogDataP) err = memFullErr; if (!err && ( err = NavGetDefaultDialogCreationOptions( &dialogOptions )) == noErr ) { dialogOptions.preferenceKey = kOpenPrefKey; dialogOptions.modality = kWindowModalityAppModal; // make it modal if ((err = NavCreateGetFileDialog( &dialogOptions, NULL, //openListH, gNavEventProc, NULL, // no custom previews NULL, // filter proc is NULL dialogDataP, &dialogDataP->dialogRef )) == noErr) { if (( err = NavDialogRun( dialogDataP->dialogRef )) != noErr){ if ( dialogDataP->dialogRef != NULL ){ NavDialogDispose( dialogDataP->dialogRef ); dialogDataP->dialogRef = NULL; free(dialogDataP); } } } if(err == userCanceledErr){ err = noErr; } EnableMenuCommand(NULL, kHICommandOpen); } return err; }
bool AquaGui::createMenu() { MenuRef rApplicationMenu; MenuItemIndex outIndex[1]; /* Enable 'Prefereces...' */ EnableMenuCommand(NULL, kHICommandPreferences); GetIndMenuItemWithCommandID(NULL, kHICommandPreferences, 1, &rApplicationMenu, outIndex); /* Enable 'About' */ InsertMenuItemTextWithCFString(rApplicationMenu, CFSTR("About gnash"), (short) 0, 0, kHICommandAbout); return true; }
OSStatus TextViewFontPanelSupport( HIViewRef textView, Boolean on ) { OSStatus status = noErr; TXNCommandEventSupportOptions options = 0; TXNObject txnObj = HITextViewGetTXNObject(textView); // Got TXNObject? require( txnObj != NULL, EXIT ); // Get existing option settings... status = TXNGetCommandEventSupport( txnObj, &options ); require_noerr( status, EXIT ); // Add or subract font command support as requested, // (and enable/disable menu items appropriately) if( on ) { options |= kTXNSupportFontCommandProcessing; options |= kTXNSupportFontCommandUpdating; EnableMenuCommand(NULL, kHICommandShowHideFontPanel); if ( ! FPIsFontPanelVisible() ) verify_noerr( FPShowHideFontPanel() ); verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), CFSTR("FontPanelEnable") )); } else { if( options & kTXNSupportFontCommandProcessing ) options ^= kTXNSupportFontCommandProcessing; if( options & kTXNSupportFontCommandUpdating ) options ^= kTXNSupportFontCommandUpdating; DisableMenuCommand(NULL, kHICommandShowHideFontPanel); if ( FPIsFontPanelVisible() ) verify_noerr( FPShowHideFontPanel() ); verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), CFSTR("FontPanelDisable") )); } // reset modified options status = TXNSetCommandEventSupport(txnObj, options ); verify_noerr( status ); EXIT: ; return status; }
void wxMenuBar::MacInstallMenuBar() { if ( s_macInstalledMenuBar == this ) return ; m_rootMenu->GetPeer()->MakeRoot(); // hide items in the apple menu that don't exist in the wx menubar int menuid = 0; wxMenuItem* appleItem = NULL; wxMenuItem* wxItem = NULL; menuid = wxApp::s_macAboutMenuItemId; appleItem = m_appleMenu->FindItem(menuid); wxItem = FindItem(menuid); if ( appleItem != NULL ) { if ( wxItem == NULL ) appleItem->GetPeer()->Hide(); else appleItem->SetItemLabel(wxItem->GetItemLabel()); } menuid = wxApp::s_macPreferencesMenuItemId; appleItem = m_appleMenu->FindItem(menuid); wxItem = FindItem(menuid); if ( appleItem != NULL ) { if ( wxItem == NULL ) appleItem->GetPeer()->Hide(); else appleItem->SetItemLabel(wxItem->GetItemLabel()); } #if 0 // if we have a mac help menu, clean it up before adding new items MenuHandle helpMenuHandle ; MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenuDontCreate( &helpMenuHandle , &firstUserHelpMenuItem) == noErr ) { for ( int i = CountMenuItems( helpMenuHandle ) ; i >= firstUserHelpMenuItem ; --i ) DeleteMenuItem( helpMenuHandle , i ) ; } else { helpMenuHandle = NULL ; } if ( wxApp::s_macPreferencesMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ; if ( item == NULL || !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandPreferences ) ; else EnableMenuCommand( NULL , kHICommandPreferences ) ; } // Unlike preferences which may or may not exist, the Quit item should be always // enabled unless it is added by the application and then disabled, otherwise // a program would be required to add an item with wxID_EXIT in order to get the // Quit menu item to be enabled, which seems a bit burdensome. if ( wxApp::s_macExitMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macExitMenuItemId , NULL ) ; if ( item != NULL && !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandQuit ) ; else EnableMenuCommand( NULL , kHICommandQuit ) ; } wxString strippedHelpMenuTitle = wxStripMenuCodes( wxApp::s_macHelpMenuTitleName ) ; wxString strippedTranslatedHelpMenuTitle = wxStripMenuCodes( wxString( _("&Help") ) ) ; wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst(); for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext()) { wxMenuItemList::compatibility_iterator node; wxMenuItem *item; wxMenu* menu = menuIter->GetData() , *subMenu = NULL ; wxString strippedMenuTitle = wxStripMenuCodes(m_titles[i]); if ( strippedMenuTitle == wxT("?") || strippedMenuTitle == strippedHelpMenuTitle || strippedMenuTitle == strippedTranslatedHelpMenuTitle ) { for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; if (subMenu) { UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding() ); MenuItemIndex position = CountMenuItems(mh); ::SetMenuItemHierarchicalMenu(mh, position, MAC_WXHMENU(subMenu->GetHMenu())); } else { if ( item->GetId() != wxApp::s_macAboutMenuItemId ) { // we have found a user help menu and an item other than the about item, // so we can create the mac help menu now, if we haven't created it yet if ( helpMenuHandle == NULL ) { if ( UMAGetHelpMenu( &helpMenuHandle , &firstUserHelpMenuItem) != noErr ) { helpMenuHandle = NULL ; break ; } } } if ( item->IsSeparator() ) { if ( helpMenuHandle ) AppendMenuItemTextWithCFString( helpMenuHandle, CFSTR(""), kMenuItemAttrSeparator, 0,NULL); } else { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { // this will be taken care of below } else { if ( helpMenuHandle ) { UMAAppendMenuItem(helpMenuHandle, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), entry); SetMenuItemCommandID( helpMenuHandle , CountMenuItems(helpMenuHandle) , wxIdToMacCommand ( item->GetId() ) ) ; SetMenuItemRefCon( helpMenuHandle , CountMenuItems(helpMenuHandle) , (URefCon) item ) ; } } delete entry ; } } } } else if ( ( m_titles[i] == wxT("Window") || m_titles[i] == wxT("&Window") ) && GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) { CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; } MenuRef wm = (MenuRef)MacGetWindowMenuHMenu(); if ( wm == NULL ) break; // get the insertion point in the standard menu MenuItemIndex winListStart; GetIndMenuItemWithCommandID(wm, kHICommandWindowListSeparator, 1, NULL, &winListStart); // add a separator so that the standard items and the custom items // aren't mixed together, but only if this is the first run OSStatus err = GetIndMenuItemWithCommandID(wm, 'WXWM', 1, NULL, NULL); if ( err == menuItemNotFoundErr ) { InsertMenuItemTextWithCFString( wm, CFSTR(""), winListStart-1, kMenuItemAttrSeparator, 'WXWM'); } wxInsertMenuItemsInMenu(menu, wm, winListStart); } else { UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], GetFont().GetEncoding() ) ; menu->MacBeforeDisplay(false) ; ::InsertMenu(MAC_WXHMENU(GetMenu(i)->GetHMenu()), 0); } } // take care of the about menu item wherever it is { wxMenu* aboutMenu ; wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; if ( aboutMenuItem ) { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( aboutMenuItem->GetItemLabel() ) ; UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetItemLabel() ) , wxFont::GetDefaultEncoding() ); UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; delete entry; } } if ( GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ; } ::DrawMenuBar() ; #endif s_macInstalledMenuBar = this; }
bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow ) { int menuid = item ? item->GetId() : 0; wxUpdateUIEvent event(menuid); event.SetEventObject( this ); bool processed = false; // Try the menu's event handler { wxEvtHandler *handler = GetEventHandler(); if ( handler ) processed = handler->ProcessEvent(event); } // Try the window the menu was popped up from // (and up through the hierarchy) if ( !processed ) { wxWindow *win = GetWindow(); if ( win ) processed = win->HandleWindowEvent(event); } if ( !processed && senderWindow != NULL) { processed = senderWindow->HandleWindowEvent(event); } if ( processed ) { // if anything changed, update the changed attribute if (event.GetSetText()) SetLabel(menuid, event.GetText()); if (event.GetSetChecked()) Check(menuid, event.GetChecked()); if (event.GetSetEnabled()) Enable(menuid, event.GetEnabled()); } else { #if wxOSX_USE_CARBON // these two items are also managed by the Carbon Menu Manager, therefore we must // always reset them ourselves UInt32 cmd = 0; if ( menuid == wxApp::s_macExitMenuItemId ) { cmd = kHICommandQuit; } else if (menuid == wxApp::s_macPreferencesMenuItemId ) { cmd = kHICommandPreferences; } if ( cmd != 0 ) { if ( !item->IsEnabled() || wxDialog::OSXHasModalDialogsOpen() ) DisableMenuCommand( NULL , cmd ) ; else EnableMenuCommand( NULL , cmd ) ; } #endif } return processed; }
/*** ENABLE MENU COMMAND ***/ void EnableCommand( MenuRef menu, MenuCommand command, Boolean enable ) { if( enable ) EnableMenuCommand( menu, command ); else DisableMenuCommand( menu, command ); }
void wxMenuBar::MacInstallMenuBar() { if ( s_macInstalledMenuBar == this ) return ; MenuBarHandle menubar = NULL ; #if TARGET_API_MAC_OSX menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ; #else menubar = NewHandleClear( 12 ) ; (*menubar)[3] = 0x0a ; #endif ::SetMenuBar( menubar ) ; DisposeMenuBar( menubar ) ; MenuHandle appleMenu = NULL ; verify_noerr( CreateNewMenu( kwxMacAppleMenuId , 0 , &appleMenu ) ) ; verify_noerr( SetMenuTitleWithCFString( appleMenu , CFSTR( "\x14" ) ) ); // Add About/Preferences separator only on OS X // KH/RN: Separator is always present on 10.3 but not on 10.2 // However, the change from 10.2 to 10.3 suggests it is preferred #if TARGET_API_MAC_OSX InsertMenuItemTextWithCFString( appleMenu, CFSTR(""), 0, kMenuItemAttrSeparator, 0); #endif InsertMenuItemTextWithCFString( appleMenu, CFSTR("About..."), 0, 0, 0); MacInsertMenu( appleMenu , 0 ) ; // clean-up the help menu before adding new items static MenuHandle mh = NULL ; if ( mh != NULL ) { MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr ) { for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i ) DeleteMenuItem( mh , i ) ; } else { mh = NULL ; } } #if TARGET_CARBON if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ; if ( item == NULL || !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandPreferences ) ; else EnableMenuCommand( NULL , kHICommandPreferences ) ; } // Unlike preferences which may or may not exist, the Quit item should be always // enabled unless it is added by the application and then disabled, otherwise // a program would be required to add an item with wxID_EXIT in order to get the // Quit menu item to be enabled, which seems a bit burdensome. if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macExitMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macExitMenuItemId , NULL ) ; if ( item != NULL && !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandQuit ) ; else EnableMenuCommand( NULL , kHICommandQuit ) ; } #endif wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst(); for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext()) { wxMenuItemList::compatibility_iterator node; wxMenuItem *item; wxMenu* menu = menuIter->GetData() , *subMenu = NULL ; if ( m_titles[i] == wxT("?") || m_titles[i] == wxT("&?") || m_titles[i] == wxApp::s_macHelpMenuTitleName ) { for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; if (subMenu) { // we don't support hierarchical menus in the help menu yet } else { if ( item->GetId() != wxApp::s_macAboutMenuItemId ) { if ( mh == NULL ) { MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr ) { mh = NULL ; break ; } } } if ( item->IsSeparator() ) { if ( mh ) AppendMenuItemTextWithCFString( mh, CFSTR(""), kMenuItemAttrSeparator, 0,NULL); } else { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetText() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { // this will be taken care of below } else { if ( mh ) { UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding(), entry); SetMenuItemCommandID( mh , CountMenuItems(mh) , wxIdToMacCommand ( item->GetId() ) ) ; SetMenuItemRefCon( mh , CountMenuItems(mh) , (URefCon) item ) ; } } delete entry ; } } } } else { UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], m_font.GetEncoding() ) ; menu->MacBeforeDisplay(false) ; ::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0); } } // take care of the about menu item wherever it is { wxMenu* aboutMenu ; wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; if ( aboutMenuItem ) { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( aboutMenuItem->GetText() ) ; UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetText() ) , wxFont::GetDefaultEncoding() ); UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; } } if ( GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ; } ::DrawMenuBar() ; s_macInstalledMenuBar = this; }
// // Main window procedure // LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { int width, height, heightsb; HIMAGELIST hImgList; RECT rect; HDWP hdwp; NMHDR *nmhdr; TCHAR msgstr[MAX_PATH+200]; switch(msg) { case WM_CREATE: g_hwndTextView = CreateTextView(hwnd); g_hwndStatusbar = CreateStatusBar(hwnd); TextView_SetContextMenu(g_hwndTextView, GetSubMenu(LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(IDR_MENU2)), 0)); // load the image list hImgList = ImageList_LoadImage( GetModuleHandle(0), MAKEINTRESOURCE(IDB_BITMAP1), 16, 0, RGB(255,0,255), IMAGE_BITMAP, LR_LOADTRANSPARENT|LR_CREATEDIBSECTION ); TextView_SetImageList(g_hwndTextView, hImgList); // highlight specific lines with image-index "1" //TextView_SetLineImage(g_hwndTextView, 16, 1); //TextView_SetLineImage(g_hwndTextView, 5, 1); //TextView_SetLineImage(g_hwndTextView, 36, 1); //TextView_SetLineImage(g_hwndTextView, 11, 1); // tell windows that we can handle drag+drop'd files DragAcceptFiles(hwnd, TRUE); return 0; case WM_DROPFILES: HandleDropFiles(hwnd, (HDROP)wParam); return 0; case WM_DESTROY: SaveFileData(g_szFileName, hwnd); PostQuitMessage(0); DeleteObject(g_hFont); return 0; //case WM_NCCALCSIZE: // return NcCalcSize(hwnd, wParam, lParam); case WM_INITMENU: CheckMenuCommand((HMENU)wParam, IDM_VIEW_LINENUMBERS, g_fLineNumbers); CheckMenuCommand((HMENU)wParam, IDM_VIEW_LONGLINES, g_fLongLines); CheckMenuCommand((HMENU)wParam, IDM_VIEW_SAVEEXIT, g_fSaveOnExit); CheckMenuCommand((HMENU)wParam, IDM_VIEW_STATUSBAR, g_fShowStatusbar); //CheckMenuCommand((HMENU)wParam, IDM_VIEW_SEARCHBAR, g_hwndSearchBar ? TRUE : FALSE); EnableMenuCommand((HMENU)wParam, IDM_EDIT_UNDO, TextView_CanUndo(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_REDO, TextView_CanRedo(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_PASTE, IsClipboardFormatAvailable(CF_TEXT)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_COPY, TextView_GetSelSize(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_CUT, TextView_GetSelSize(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_DELETE, TextView_GetSelSize(g_hwndTextView)); return 0; //case WM_USER: // wsprintf(msgstr, _T("%s\n\nThis file has been modified outside of Neatpad.") // _T("Do you wish to reload it?"), g_szFileName); // MessageBox(hwnd, msgstr, _T("Neatpad"), MB_ICONQUESTION|MB_YESNO); // // return 0; case WM_ENABLE: // keep the modeless find/replace dialog in the same enabled state as the main window EnableWindow(g_hwndSearchDlg, (BOOL)wParam); return 0; case WM_MENUSELECT: StatusBarMenuSelect(hwnd, g_hwndStatusbar, wParam, lParam); return 0; case WM_NOTIFY: nmhdr = (NMHDR *)lParam; if(nmhdr->hwndFrom == g_hwndTextView) return TextViewNotifyHandler(hwnd, nmhdr); else return NotifyHandler(hwnd, nmhdr); case WM_COMMAND: return CommandHandler(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); case WM_SETFOCUS: SetFocus(g_hwndTextView); return 0; case WM_CLOSE: // does the file need saving? if(TextView_CanUndo(g_hwndTextView)) { UINT r; wsprintf(msgstr, _T("Do you want to save changes to\r\n%s?"), g_szFileName); r = MessageBox(hwnd, msgstr, APP_TITLE, MB_YESNOCANCEL | MB_ICONQUESTION); if(r == IDCANCEL) return 0; } DestroyWindow(hwnd); return 0; case WM_SIZE: // resize the TextView and StatusBar to fit within the main window's client area width = (short)LOWORD(lParam); height = (short)HIWORD(lParam); GetWindowRect(g_hwndStatusbar, &rect); heightsb = rect.bottom-rect.top; hdwp = BeginDeferWindowPos(3); if(g_fShowStatusbar) { DeferWindowPos(hdwp, g_hwndStatusbar, 0, 0, height - heightsb, width, heightsb, SWP_SHOWWINDOW); // MoveWindow(g_hwndStatusbar, 0, height - heightsb, width, heightsb, TRUE); height -= heightsb; } DeferWindowPos(hdwp, g_hwndTextView, 0, 0, 0, width, height, SWP_SHOWWINDOW); //MoveWindow(g_hwndTextView, 0, 0, width, height, TRUE); EndDeferWindowPos(hdwp); SetStatusBarParts(g_hwndStatusbar); return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); }
void TkMacOSXInitMenus( Tcl_Interp *interp) { OSStatus err; EventHandlerUPP menuEventHandlerUPP; const EventTypeSpec menuEventTypes[] = { {kEventClassMenu, kEventMenuEnableItems}, }; gInterp = interp; if (TkMacOSXUseMenuID(kAppleMenu) != TCL_OK) { Tcl_Panic("Menu ID %d is already in use!", kAppleMenu); } err = ChkErr(CreateNewMenu, kAppleMenu, kMenuAttrDoNotUseUserCommandKeys, &tkAppleMenu); if (err != noErr) { Tcl_Panic("CreateNewMenu failed !"); } SetMenuTitle(tkAppleMenu, "\p\024"); InsertMenu(tkAppleMenu, 0); AppendMenu(tkAppleMenu, "\pAbout Tcl & Tk\xc9"); AppendMenu(tkAppleMenu, "\p(-"); if (TkMacOSXUseMenuID(kFileMenu) != TCL_OK) { Tcl_Panic("Menu ID %d is already in use!", kFileMenu); } err = ChkErr(CreateNewMenu, kFileMenu, kMenuAttrDoNotUseUserCommandKeys, &tkFileMenu); if (err != noErr) { Tcl_Panic("CreateNewMenu failed !"); } SetMenuTitle(tkFileMenu, "\pFile"); InsertMenu(tkFileMenu, 0); InsertMenuItem(tkFileMenu, "\pSource\xc9", kSourceItem - 1); InsertMenuItem(tkFileMenu, "\pRun Widget Demo", kDemoItem - 1); InsertMenuItem(tkFileMenu, "\pClose/W", kCloseItem - 1); DisableMenuItem(tkFileMenu, kDemoItem); menuEventHandlerUPP = NewEventHandlerUPP(MenuEventHandlerProc); ChkErr(InstallEventHandler, GetMenuEventTarget(tkFileMenu), menuEventHandlerUPP, GetEventTypeCount(menuEventTypes), menuEventTypes, NULL, &menuEventHandlerRef); DisposeEventHandlerUPP(menuEventHandlerUPP); if (TkMacOSXUseMenuID(kEditMenu) != TCL_OK) { Tcl_Panic("Menu ID %d is already in use!", kEditMenu); } err = ChkErr(CreateNewMenu, kEditMenu, kMenuAttrDoNotUseUserCommandKeys, &tkEditMenu); if (err != noErr) { Tcl_Panic("CreateNewMenu failed !"); } SetMenuTitle(tkEditMenu, "\pEdit"); InsertMenu(tkEditMenu, 0); AppendMenu(tkEditMenu, "\pCut/X"); AppendMenu(tkEditMenu, "\pCopy/C"); AppendMenu(tkEditMenu, "\pPaste/V"); AppendMenu(tkEditMenu, "\pClear"); if (TkMacOSXUseMenuID(kHMHelpMenuID) != TCL_OK) { Tcl_Panic("Help menu ID %s is already in use!", kHMHelpMenuID); } /* * Workaround a Carbon bug with kHICommandPreferences: the first call to * IsMenuKeyEvent returns false for the preferences menu item key shorcut * event (even if the corresponding menu item is dynamically enabled by a * kEventCommandUpdateStatus handler), unless the kHICommandPreferences * menu item has previously been enabled manually. [Bug 1481503] */ EnableMenuCommand(NULL, kHICommandPreferences); DrawMenuBar(); return; }
static pascal void NavEventProc( NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void* callBackUD ) { OurDialogData *dialogDataP = (OurDialogData*)callBackUD; OSStatus err = noErr; switch( callBackSelector ) { case kNavCBUserAction: { NavReplyRecord reply; NavUserAction userAction = 0; if ((err = NavDialogGetReply( callBackParms->context, &reply )) == noErr ) { OSStatus tempErr; userAction = NavDialogGetUserAction( callBackParms->context ); switch( userAction ) { case kNavUserActionOpen: { long count = 0; short index; err = AECountItems( &reply.selection, &count ); for ( index = 1; index <= count; index++ ) { AEKeyword keyWord; AEDesc theDesc; if (( err = AEGetNthDesc( &reply.selection, index, typeWildCard, &keyWord, &theDesc )) == noErr ) { FSRef fileRef; GetFSRefFromAEDesc(&theDesc, &fileRef); (void)doTheFile( fileRef ); AEDisposeDesc( &theDesc ); } } EnableMenuCommand(NULL, kHICommandOpen); } break; case kNavUserActionCancel: //.. break; case kNavUserActionNewFolder: //.. break; } tempErr = NavDisposeReply( &reply ); if(!err) err = tempErr; } break; } case kNavCBTerminate: if( dialogDataP != NULL ) { if(dialogDataP->dialogRef) NavDialogDispose(dialogDataP->dialogRef ); dialogDataP->dialogRef = NULL; free(dialogDataP); } break; } }