#include "wx/log.h"
#include "wx/intl.h"
#include "wx/frame.h"
+ #include "wx/menu.h"
#include "wx/containr.h" // wxSetFocusToChild()
#include "wx/module.h"
#endif //WX_PRECOMP
m_activateInfo = (void*) info;
#endif
+
+ m_menuSystem = NULL;
}
WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
WXLRESULT rc = 0;
bool processed = false;
-#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
switch ( message )
{
+#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
case WM_ACTIVATE:
{
SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo;
}
break;
}
+#endif // __SMARTPHONE__ || __POCKETPC__
+
+ case WM_SYSCOMMAND:
+ // Keep the #ifdef block inside the case to fix a potential MSVC
+ // warning regarding switch statement containing no case or
+ // default labels (or a default only).
+#ifndef __WXUNIVERSAL__
+ // We may need to generate events for the items added to the system
+ // menu if it had been created (and presumably modified).
+ if ( m_menuSystem )
+ {
+ // From MSDN:
+ //
+ // ... the four low-order bits of the wParam parameter are
+ // used internally by the system. To obtain the correct
+ // result when testing the value of wParam, an application
+ // must combine the value 0xFFF0 with the wParam value by
+ // using the bitwise AND operator.
+ unsigned id = wParam & 0xfff0;
+
+ // SC_SIZE is the first of the system-defined commands and we
+ // leave those to DefWindowProc().
+ if ( id < SC_SIZE )
+ {
+ if ( m_menuSystem->MSWCommand(0 /* unused anyhow */, id) )
+ processed = true;
+ }
+ }
+#endif // #ifndef __WXUNIVERSAL__
+ break;
}
-#endif
if ( !processed )
rc = wxTopLevelWindowBase::MSWWindowProc(message, wParam, lParam);
if ( winTop )
{
wxIcon icon = winTop->GetIcon();
- if ( icon.Ok() )
+ if ( icon.IsOk() )
{
::SendMessage(GetHwnd(), WM_SETICON,
(WPARAM)TRUE,
}
#endif // !__WXWINCE__
+ if ( !title.empty() )
+ {
+ ::SetWindowText(GetHwnd(), title.wx_str());
+ }
+
+ SubclassWin(m_hWnd);
+
+#if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
// move the dialog to its initial position without forcing repainting
int x, y, w, h;
(void)MSWGetCreateWindowCoords(pos, size, x, y, w, h);
if ( x == (int)CW_USEDEFAULT )
{
- // centre it on the screen - what else can we do?
- wxSize sizeDpy = wxGetDisplaySize();
-
- x = (sizeDpy.x - w) / 2;
- y = (sizeDpy.y - h) / 2;
- }
-
-#if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
- if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) )
- {
- wxLogLastError(wxT("MoveWindow"));
+ // Let the system position the window, just set its size.
+ ::SetWindowPos(GetHwnd(), 0,
+ 0, 0, w, h,
+ SWP_NOMOVE | SWP_NOZORDER);
}
-#endif
-
- if ( !title.empty() )
+ else // Move the window to the desired location and set its size too.
{
- ::SetWindowText(GetHwnd(), title.wx_str());
+ if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) )
+ {
+ wxLogLastError(wxT("MoveWindow"));
+ }
}
-
- SubclassWin(m_hWnd);
+#endif // !__WXWINCE__
#ifdef __SMARTPHONE__
// Work around title non-display glitch
if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
{
// we have different dialog templates to allows creation of dialogs
- // with & without captions under MSWindows, resizeable or not (but a
- // resizeable dialog always has caption - otherwise it would look too
+ // with & without captions under MSWindows, resizable or not (but a
+ // resizable dialog always has caption - otherwise it would look too
// strange)
// we need 3 additional WORDs for dialog menu, class and title (as we
wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
{
+ delete m_menuSystem;
+
SendDestroyEvent();
#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
{
::ShowWindow(GetHwnd(), nShowCmd);
- m_iconized = nShowCmd == SW_MINIMIZE;
+ // Hiding the window doesn't change its iconized state.
+ if ( nShowCmd != SW_HIDE )
+ {
+ // Otherwise restoring, maximizing or showing the window normally also
+ // makes it not iconized and only minimizing it does make it iconized.
+ m_iconized = nShowCmd == SW_MINIMIZE;
+ }
}
void wxTopLevelWindowMSW::ShowWithoutActivating()
void wxTopLevelWindowMSW::Iconize(bool iconize)
{
+ if ( iconize == m_iconized )
+ {
+ // Do nothing, in particular don't restore non-iconized windows when
+ // Iconize(false) is called as this would wrongly un-maximize them.
+ return;
+ }
+
if ( IsShown() )
{
// change the window state immediately
// finally send an event allowing the window to relayout itself &c
wxSizeEvent event(rect.GetSize(), GetId());
+ event.SetEventObject(this);
HandleWindowEvent(event);
}
else // stop showing full screen
return true;
}
-#ifndef __WXWINCE__
-
-bool wxTopLevelWindowMSW::SetShape(const wxRegion& region)
-{
- wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
- wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
-
- // The empty region signifies that the shape should be removed from the
- // window.
- if ( region.IsEmpty() )
- {
- if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
- {
- wxLogLastError(wxT("SetWindowRgn"));
- return false;
- }
- return true;
- }
-
- // Windows takes ownership of the region, so
- // we'll have to make a copy of the region to give to it.
- DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
- RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
- ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
- HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
- delete[] (char*) rgnData;
-
- // SetWindowRgn expects the region to be in coordinants
- // relative to the window, not the client area. Figure
- // out the offset, if any.
- RECT rect;
- DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
- DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
- ::GetClientRect(GetHwnd(), &rect);
- ::AdjustWindowRectEx(&rect, dwStyle, ::GetMenu(GetHwnd()) != NULL, dwExStyle);
- ::OffsetRgn(hrgn, -rect.left, -rect.top);
-
- // Now call the shape API with the new region.
- if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
- {
- wxLogLastError(wxT("SetWindowRgn"));
- return false;
- }
- return true;
-}
-
-#endif // !__WXWINCE__
-
void wxTopLevelWindowMSW::RequestUserAttention(int flags)
{
// check if we can use FlashWindowEx(): unfortunately a simple test for
}
}
+wxMenu *wxTopLevelWindowMSW::MSWGetSystemMenu() const
+{
+#ifndef __WXUNIVERSAL__
+ if ( !m_menuSystem )
+ {
+ HMENU hmenu = ::GetSystemMenu(GetHwnd(), FALSE);
+ if ( !hmenu )
+ {
+ wxLogLastError(wxT("GetSystemMenu()"));
+ return NULL;
+ }
+
+ wxTopLevelWindowMSW * const
+ self = const_cast<wxTopLevelWindowMSW *>(this);
+
+ self->m_menuSystem = wxMenu::MSWNewFromHMENU(hmenu);
+
+ // We need to somehow associate this menu with this window to ensure
+ // that we get events from it. A natural idea would be to pretend that
+ // it's attached to our menu bar but this wouldn't work if we don't
+ // have any menu bar which is a common case for applications using
+ // custom items in the system menu (they mostly do it exactly because
+ // they don't have any other menus).
+ //
+ // So reuse the invoking window pointer instead, this is not exactly
+ // correct but doesn't seem to have any serious drawbacks.
+ m_menuSystem->SetInvokingWindow(self);
+ }
+#endif // #ifndef __WXUNIVERSAL__
+
+ return m_menuSystem;
+}
+
+// ----------------------------------------------------------------------------
+// Transparency support
// ---------------------------------------------------------------------------
bool wxTopLevelWindowMSW::SetTransparent(wxByte alpha)