OSDN Git Service

Mac: 'Window' menu is implemented.
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Sat, 26 Apr 2014 02:37:59 +0000 (02:37 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Sat, 26 Apr 2014 02:37:59 +0000 (02:37 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@535 a2be9bc6-48de-4e38-9406-05402d4bc13c

wxSources/MyApp.cpp
wxSources/MyApp.h
wxSources/menu.mm [new file with mode: 0644]
xcode-build/Molby.xcodeproj/project.pbxproj

index f70dce8..23b37e4 100755 (executable)
@@ -94,6 +94,7 @@ BEGIN_EVENT_TABLE(MyApp, wxApp)
        EVT_MENU(myMenuID_EmptyConsoleWindow, MyApp::OnEmptyConsoleWindow)
        EVT_MENU(myMenuID_ViewGlobalParameters, MyApp::OnViewGlobalParameters)
        EVT_MENU(myMenuID_ViewParameterFilesList, MyApp::OnViewParameterFilesList)
+       EVT_MENU(myMenuID_BringAllWindowsToFront, MyApp::OnBringAllWindowsToFront)
 #if defined(__WXMAC__)
        EVT_ACTIVATE(MyApp::OnActivate)
 #endif
@@ -355,14 +356,15 @@ bool MyApp::OnInit(void)
 wxMenuBar *
 MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit_menu)
 {
-       
        //// Make a menubar
        wxMenu *file_menu = new wxMenu;
+       wxMenu *file_history_menu = NULL;
 
        file_menu->Append(wxID_NEW, _T("&New...\tCtrl-N"));
        file_menu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
        if (out_file_history_menu != NULL) {
-               *out_file_history_menu = new wxMenu;
+               file_history_menu = new wxMenu;
+               *out_file_history_menu = file_history_menu;
                file_menu->AppendSubMenu(*out_file_history_menu, _T("Open Recent"));
                m_docManager->FileHistoryAddFilesToMenu(*out_file_history_menu);
                m_docManager->FileHistoryUseMenu(*out_file_history_menu);  //  Should be removed when menu is discarded
@@ -475,6 +477,14 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit
        menu_bar->Append(view_menu, _T("View"));
        menu_bar->Append(md_menu, _T("MM/MD"));
        menu_bar->Append(script_menu, _T("&Script"));
+       
+#if defined(__WXMAC__)
+       wxMenu *window_menu = new wxMenu;
+       window_menu->Append(myMenuID_BringAllWindowsToFront, _T("Bring All to Front"));
+       window_menu->AppendSeparator();
+       menu_bar->Append(window_menu, _T("Window"));
+#endif
+       
        menu_bar->Append(help_menu, _T("&Help"));
        
        UpdateScriptMenu(menu_bar);
@@ -723,6 +733,25 @@ MyApp::OnViewParameterFilesList(wxCommandEvent &event)
        parameterFilesFrame->Raise();
 }
 
+void
+MyApp::OnBringAllWindowsToFront(wxCommandEvent &event)
+{
+       int size = 0, n;
+       wxWindowList::iterator iter;
+       wxTopLevelWindow **wins;
+       size = wxTopLevelWindows.size();
+       if (size > 0) {
+               wins = (wxTopLevelWindow **)calloc(sizeof(wxTopLevelWindow *), size);
+               for (iter = wxTopLevelWindows.begin(), n = 0; iter != wxTopLevelWindows.end(); ++iter, ++n) {
+                       wins[n] = (wxTopLevelWindow *)(*iter);
+               }
+               for (n = 0; n < size; n++) {
+                       if (wins[n]->IsShown())
+                               wins[n]->Raise();
+               }
+       }
+}
+
 int
 MyApp::LookupScriptMenu(const char *title)
 {
@@ -1333,7 +1362,7 @@ MyApp::CallSubProcess(const char *cmdline, const char *procname, int (*callback)
                                        MyAppCallback_setConsoleColor(0);
                                        MyAppCallback_showScriptMessage("%s", buf);
                                }
-                       }
+                       } else break;
                }
                while (m_process != NULL && (m_process->IsErrorAvailable())) {
                        err = m_process->GetErrorStream();
@@ -1352,7 +1381,7 @@ MyApp::CallSubProcess(const char *cmdline, const char *procname, int (*callback)
                                        MyAppCallback_showScriptMessage("\n%s", buf);
                                        MyAppCallback_setConsoleColor(0); 
                                }
-                       }
+                       } else break;
                }
                if (m_processTerminated) {
                        //  OnEndProcess has been called
index c8db617..0ee7e2d 100755 (executable)
@@ -99,6 +99,7 @@ enum {
        myMenuID_StopMDRun = 202,
        myMenuID_ViewGlobalParameters = 205,
        myMenuID_ViewParameterFilesList = 206,
+       myMenuID_BringAllWindowsToFront = 207,
        myMenuID_ExecuteScript = 300,
        myMenuID_OpenConsoleWindow = 301,
        myMenuID_EmptyConsoleWindow = 302,
@@ -165,7 +166,8 @@ class MyApp: public wxApp
        void OnEmptyConsoleWindow(wxCommandEvent &event);
        void OnViewGlobalParameters(wxCommandEvent &event);
        void OnViewParameterFilesList(wxCommandEvent &event);
-
+       void OnBringAllWindowsToFront(wxCommandEvent &event);
+       
        void OnEndProcess(wxProcessEvent &event);
        int CallSubProcess(const char *cmdline, const char *procname, int (*callback)(void *) = NULL, void *callback_data = NULL, FILE *fpout = NULL, FILE *fperr = NULL);
 
diff --git a/wxSources/menu.mm b/wxSources/menu.mm
new file mode 100644 (file)
index 0000000..d29b049
--- /dev/null
@@ -0,0 +1,264 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        src/osx/cocoa/menu.mm
+// Purpose:     wxMenu, wxMenuBar, wxMenuItem
+// Author:      Stefan Csomor
+// Modified by:
+// Created:     1998-01-01
+// Copyright:   (c) Stefan Csomor
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// headers & declarations
+// ============================================================================
+
+// wxWidgets headers
+// -----------------
+
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+#include "wx/log.h"
+#include "wx/app.h"
+#include "wx/utils.h"
+#include "wx/frame.h"
+#include "wx/menuitem.h"
+#endif
+
+#include "wx/menu.h"
+
+#include "wx/osx/private.h"
+
+// other standard headers
+// ----------------------
+#include <string.h>
+
+@implementation wxNSMenu
+
+- (id) initWithTitle:(NSString*) title
+{
+    self = [super initWithTitle:title];
+    impl = NULL;
+    return self;
+}
+
+- (void)setImplementation: (wxMenuImpl *) theImplementation
+{
+    impl = theImplementation;
+}
+
+- (wxMenuImpl*) implementation
+{
+    return impl;
+}
+
+@end
+
+// this is more compatible, as it is also called for command-key shortcuts
+// and under 10.4, we are not getting a 'close' event however...
+#define wxOSX_USE_NEEDSUPDATE_HOOK 1
+
+@interface wxNSMenuController : NSObject wxOSX_10_6_AND_LATER(<NSMenuDelegate>)
+{
+}
+
+#if wxOSX_USE_NEEDSUPDATE_HOOK
+- (void)menuNeedsUpdate:(NSMenu*)smenu;
+#else
+- (void)menuWillOpen:(NSMenu *)menu;
+#endif
+- (void)menuDidClose:(NSMenu *)menu;
+- (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item;
+
+@end
+
+@implementation wxNSMenuController
+
+- (id) init
+{
+    self = [super init];
+    return self;
+}
+
+#if wxOSX_USE_NEEDSUPDATE_HOOK
+- (void)menuNeedsUpdate:(NSMenu*)smenu
+{
+    wxNSMenu* menu = (wxNSMenu*) smenu;
+    wxMenuImpl* menuimpl = [menu implementation];
+    if ( menuimpl )
+    {
+        wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer();
+        if ( wxpeer )
+            wxpeer->HandleMenuOpened();
+    }
+}
+#else
+- (void)menuWillOpen:(NSMenu *)smenu
+{
+    wxNSMenu* menu = (wxNSMenu*) smenu;
+    wxMenuImpl* menuimpl = [menu implementation];
+    if ( menuimpl )
+    {
+        wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer();
+        if ( wxpeer )
+            wxpeer->HandleMenuOpened();
+    }
+}
+#endif
+
+- (void)menuDidClose:(NSMenu *)smenu
+{
+    wxNSMenu* menu = (wxNSMenu*) smenu;
+    wxMenuImpl* menuimpl = [menu implementation];
+    if ( menuimpl )
+    {
+        wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer();
+        if ( wxpeer )
+            wxpeer->HandleMenuClosed();
+    }
+}
+
+- (void)menu:(NSMenu *)smenu willHighlightItem:(NSMenuItem *)item
+{
+    wxNSMenu* menu = (wxNSMenu*) smenu;
+    wxMenuImpl* menuimpl = [menu implementation];
+    if ( menuimpl )
+    {
+        wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer();
+        if ( [ item isKindOfClass:[wxNSMenuItem class] ] )
+        {
+            wxMenuItemImpl* menuitemimpl = (wxMenuItemImpl*) [ (wxNSMenuItem*) item implementation ];
+            if ( wxpeer && menuitemimpl )
+            {
+                wxpeer->HandleMenuItemHighlighted( menuitemimpl->GetWXPeer() );
+            }
+        }
+    }
+}
+
+@end
+
+@interface NSApplication(MissingAppleMenuCall)
+- (void)setAppleMenu:(NSMenu *)menu;
+@end
+
+class wxMenuCocoaImpl : public wxMenuImpl
+{
+public :
+    wxMenuCocoaImpl( wxMenu* peer , wxNSMenu* menu) : wxMenuImpl(peer), m_osxMenu(menu)
+    {
+        static wxNSMenuController* controller = NULL;
+        if ( controller == NULL )
+        {
+            controller = [[wxNSMenuController alloc] init];
+        }
+        [menu setDelegate:controller];
+        [m_osxMenu setImplementation:this];
+        // gc aware
+        if ( m_osxMenu )
+            CFRetain(m_osxMenu);
+        [m_osxMenu release];
+    }
+
+    virtual ~wxMenuCocoaImpl();
+
+    virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos)
+    {
+        NSMenuItem* nsmenuitem = (NSMenuItem*) pItem->GetPeer()->GetHMenuItem();
+        // make sure a call of SetSubMenu is also reflected (occurring after Create)
+        // update the native menu item accordingly
+        
+        if ( pItem->IsSubMenu() )
+        {
+            wxMenu* wxsubmenu = pItem->GetSubMenu();
+            WXHMENU nssubmenu = wxsubmenu->GetHMenu();
+            if ( [nsmenuitem submenu] != nssubmenu )
+            {
+                wxsubmenu->GetPeer()->SetTitle( pItem->GetItemLabelText() );
+                [nsmenuitem setSubmenu:nssubmenu];
+            }
+        }
+        
+        if ( pos == (size_t) -1 )
+            [m_osxMenu addItem:nsmenuitem ];
+        else
+            [m_osxMenu insertItem:nsmenuitem atIndex:pos];
+    }
+
+    virtual void Remove( wxMenuItem *pItem )
+    {
+        [m_osxMenu removeItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem()];
+    }
+
+    virtual void MakeRoot()
+    {
+        [NSApp setMainMenu:m_osxMenu];
+        [NSApp setAppleMenu:[[m_osxMenu itemAtIndex:0] submenu]];
+               {
+                       //  2014.4.26. Toshi Nagata
+                       //  Enable "Window" menu
+                       static NSMutableArray *sWindowsMenus = nil;
+                       if (sWindowsMenus == nil) {
+                               sWindowsMenus = [[NSMutableArray array] retain];
+                       }
+                       id windowsMenu = [m_osxMenu itemWithTitle:@"Window"];
+                       if (windowsMenu && ![sWindowsMenus containsObject:windowsMenu]) {
+                               [NSApp setWindowsMenu:[windowsMenu submenu]];
+                               [sWindowsMenus addObject:windowsMenu];
+                       }
+                       //  End Toshi Nagata
+               }
+    }
+
+    virtual void Enable( bool WXUNUSED(enable) )
+    {
+    }
+
+    virtual void SetTitle( const wxString& text )
+    {
+        wxCFStringRef cfText(text);
+        [m_osxMenu setTitle:cfText.AsNSString()];
+    }
+
+    virtual void PopUp( wxWindow *win, int x, int y )
+    {
+        win->ScreenToClient( &x , &y ) ;
+        NSView *view = win->GetPeer()->GetWXWidget();
+        NSRect frame = [view frame];
+        frame.origin.x = x;
+        frame.origin.y = y;
+        frame.size.width = 1;
+        frame.size.height = 1;
+        NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
+        [popUpButtonCell setAutoenablesItems:NO];
+        [popUpButtonCell setAltersStateOfSelectedItem:NO];
+        [popUpButtonCell setMenu:m_osxMenu];
+        [popUpButtonCell selectItem:nil];
+        [popUpButtonCell performClickWithFrame:frame inView:view];
+        [popUpButtonCell release];
+    }
+
+    WXHMENU GetHMenu() { return m_osxMenu; }
+
+    static wxMenuImpl* Create( wxMenu* peer, const wxString& title );
+    static wxMenuImpl* CreateRootMenu( wxMenu* peer );
+protected :
+    wxNSMenu* m_osxMenu;
+} ;
+
+wxMenuCocoaImpl::~wxMenuCocoaImpl()
+{
+    [m_osxMenu setDelegate:nil];
+    [m_osxMenu setImplementation:nil];
+    // gc aware
+    if ( m_osxMenu )
+        CFRelease(m_osxMenu);
+}
+
+wxMenuImpl* wxMenuImpl::Create( wxMenu* peer, const wxString& title )
+{
+    wxCFStringRef cfText( title );
+    wxNSMenu* menu = [[wxNSMenu alloc] initWithTitle:cfText.AsNSString()];
+    wxMenuImpl* c = new wxMenuCocoaImpl( peer, menu );
+    return c;
+}
index ee48310..bbe1c0a 100644 (file)
@@ -7,6 +7,7 @@
        objects = {
 
 /* Begin PBXBuildFile section */
+               E4196C66190B2FA500183E62 /* menu.mm in Sources */ = {isa = PBXBuildFile; fileRef = E4196C65190B2FA500183E62 /* menu.mm */; };
                E420BDEF1885746700A2B983 /* ConsoleFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E420BDE81885746700A2B983 /* ConsoleFrame.cpp */; };
                E420BDF01885746700A2B983 /* filedlg.mm in Sources */ = {isa = PBXBuildFile; fileRef = E420BDEA1885746700A2B983 /* filedlg.mm */; };
                E420BDF11885746700A2B983 /* GlobalParameterFilesFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E420BDEB1885746700A2B983 /* GlobalParameterFilesFrame.cpp */; };
@@ -95,6 +96,7 @@
 
 /* Begin PBXFileReference section */
                8D1107320486CEB800E47090 /* Molby.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Molby.app; sourceTree = BUILT_PRODUCTS_DIR; };
+               E4196C65190B2FA500183E62 /* menu.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = menu.mm; sourceTree = "<group>"; };
                E420BDE81885746700A2B983 /* ConsoleFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConsoleFrame.cpp; sourceTree = "<group>"; };
                E420BDE91885746700A2B983 /* ConsoleFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConsoleFrame.h; sourceTree = "<group>"; };
                E420BDEA1885746700A2B983 /* filedlg.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = filedlg.mm; sourceTree = "<group>"; };
                                E420BDF31885749000A2B983 /* listctrl_private.h */,
                                E420BDF41885749000A2B983 /* listctrl.cpp */,
                                E4653CB018A0CC7D0022377B /* textctrl_addition.mm */,
+                               E4196C65190B2FA500183E62 /* menu.mm */,
                                E420BDF51885749000A2B983 /* MoleculeView.cpp */,
                                E420BDF61885749000A2B983 /* MoleculeView.h */,
                                E420BDF71885749000A2B983 /* MyApp.cpp */,
                                E420BE23188574F600A2B983 /* RubyDialogFrame.cpp in Sources */,
                                E420BE24188574F600A2B983 /* wxKillAddition.cpp in Sources */,
                                E4653CB118A0CC7D0022377B /* textctrl_addition.mm in Sources */,
+                               E4196C66190B2FA500183E62 /* menu.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };