X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c6b938377211da1987c8b6e44134fb0f32c84df..404b319a85dadd7decf7a5a5331020520031a41c:/src/msw/toplevel.cpp diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 85c221a45b..a4610c3c20 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -63,6 +63,15 @@ #define ICON_SMALL 0 #endif +// ---------------------------------------------------------------------------- +// globals +// ---------------------------------------------------------------------------- + +#if wxUSE_MENUS || wxUSE_MENUS_NATIVE + extern wxMenu *wxCurrentPopupMenu; +#endif // wxUSE_MENUS || wxUSE_MENUS_NATIVE + + // ---------------------------------------------------------------------------- // stubs for missing functions under MicroWindows // ---------------------------------------------------------------------------- @@ -414,6 +423,38 @@ WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WX #endif // #ifndef __WXUNIVERSAL__ } break; + +#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) +#if wxUSE_MENUS + case WM_INITMENUPOPUP: + processed = HandleMenuPopup(wxEVT_MENU_OPEN, (WXHMENU)wParam); + break; + + case WM_MENUSELECT: + { + WXWORD item, flags; + WXHMENU hmenu; + UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); + + processed = HandleMenuSelect(item, flags, hmenu); + } + break; + + case WM_EXITMENULOOP: + // Under Windows 98 and 2000 and later we're going to get + // WM_UNINITMENUPOPUP which will be used to generate this event + // with more information (notably the menu that was closed) so we + // only need this one under old Windows systems where the newer + // event is never sent. + if ( wxGetWinVersion() < wxWinVersion_98 ) + processed = HandleExitMenuLoop(wParam); + break; + + case WM_UNINITMENUPOPUP: + processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam); + break; +#endif // wxUSE_MENUS +#endif // !__WXMICROWIN__ } if ( !processed ) @@ -473,7 +514,7 @@ bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, if ( !title.empty() ) { - ::SetWindowText(GetHwnd(), title.wx_str()); + ::SetWindowText(GetHwnd(), title.t_str()); } SubclassWin(m_hWnd); @@ -523,7 +564,7 @@ bool wxTopLevelWindowMSW::CreateFrame(const wxString& title, #endif return MSWCreate(MSWGetRegisteredClassName(), - title.wx_str(), pos, sz, flags, exflags); + title.t_str(), pos, sz, flags, exflags); } bool wxTopLevelWindowMSW::Create(wxWindow *parent, @@ -709,9 +750,21 @@ bool wxTopLevelWindowMSW::Show(bool show) } else if ( m_iconized ) { - // iconize and show + // We were iconized while we were hidden, so now we need to show + // the window in iconized state. nShowCmd = SW_MINIMIZE; } + else if ( ::IsIconic(GetHwnd()) ) + { + // We were restored while we were hidden, so now we need to show + // the window in its normal state. + // + // As below, don't activate some kinds of windows. + if ( HasFlag(wxFRAME_TOOL_WINDOW) || !IsEnabled() ) + nShowCmd = SW_SHOWNOACTIVATE; + else + nShowCmd = SW_RESTORE; + } else // just show { // we shouldn't use SW_SHOW which also activates the window for @@ -823,9 +876,9 @@ void wxTopLevelWindowMSW::Iconize(bool iconize) } else // hidden { - // iconizing the window shouldn't show it so just remember that we need - // to become iconized when shown later - m_iconized = true; + // iconizing the window shouldn't show it so just update the internal + // state (otherwise it's done by DoShowWindow() itself) + m_iconized = iconize; } } @@ -1335,32 +1388,6 @@ bool wxTopLevelWindowMSW::CanSetTransparent() return (os_type == wxOS_WINDOWS_NT && ver_major >= 5); } -void wxTopLevelWindowMSW::DoEnable(bool enable) -{ - wxTopLevelWindowBase::DoEnable(enable); - - // Enabling or disabling a window may change its appearance. Unfortunately, - // in at least some situation, toplevel windows don't repaint themselves, - // so we have to issue explicit refresh to avoid rendering artifacts. - // - // TODO: find out just what exactly is wrong here - //Refresh(); - - // JS: From observing other application behaviour, such as VS 2010, controls such - // as text fields and comboboxes do not indicate a disabled state when the parent - // is disabled due to a modal dialog being shown. Therefore I have changed these - // controls' behaviour to only indicate a disabled state when IsThisEnabled returns false, - // i.e. the application has specifically disabled each control. Since the colour - // no longer changes when the top-level window is disabled, this means we can avoid - // doing a refresh that causes a distracting flicker in some controls. - // Windows should probably be sending a paint event to each child control just in - // case the state change requires a refresh, but this would cause flicker so perhaps - // it's as well that it doesn't. - // The result of this change is to remove the flicker and also remove the distraction - // of individual controls greying-out due to a dialog being shown, which I think was - // the wrong behaviour. -} - void wxTopLevelWindowMSW::DoFreeze() { // do nothing: freezing toplevel window causes paint and mouse events @@ -1442,6 +1469,80 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) } } +#if wxUSE_MENUS + +bool +wxTopLevelWindowMSW::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu)) +{ + // sign extend to int from unsigned short we get from Windows + int item = (signed short)nItem; + + // WM_MENUSELECT is generated for both normal items and menus, including + // the top level menus of the menu bar, which can't be represented using + // any valid identifier in wxMenuEvent so use an otherwise unused value for + // them + if ( flags & (MF_POPUP | MF_SEPARATOR) ) + item = wxID_NONE; + + wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); + event.SetEventObject(this); + + if ( HandleWindowEvent(event) ) + return true; + + // by default, i.e. if the event wasn't handled above, clear the status bar + // text when an item which can't have any associated help string in wx API + // is selected + if ( item == wxID_NONE ) + DoGiveHelp(wxEmptyString, true); + + return false; +} + +bool +wxTopLevelWindowMSW::DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup) +{ + wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu); + event.SetEventObject(menu); + + return HandleWindowEvent(event); +} + +bool wxTopLevelWindowMSW::HandleExitMenuLoop(WXWORD isPopup) +{ + return DoSendMenuOpenCloseEvent(wxEVT_MENU_CLOSE, + isPopup ? wxCurrentPopupMenu : NULL, + isPopup != 0); +} + +bool wxTopLevelWindowMSW::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu) +{ + bool isPopup = false; + wxMenu* menu = NULL; + if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu ) + { + menu = wxCurrentPopupMenu; + isPopup = true; + } + else + { + menu = MSWFindMenuFromHMENU(hMenu); + } + + + return DoSendMenuOpenCloseEvent(evtType, menu, isPopup); +} + +wxMenu* wxTopLevelWindowMSW::MSWFindMenuFromHMENU(WXHMENU WXUNUSED(hMenu)) +{ + // We don't have any menus at this level. + return NULL; +} + +#endif // wxUSE_MENUS + + + // the DialogProc for all wxWidgets dialogs LONG APIENTRY _EXPORT wxDlgProc(HWND hDlg,