+void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir)
+{
+ if ( dir == wxLayout_Default )
+ dir = wxTheApp->GetLayoutDirection();
+
+ if ( dir != wxLayout_Default )
+ wxTopLevelWindowBase::SetLayoutDirection(dir);
+}
+
+// ----------------------------------------------------------------------------
+// wxTopLevelWindowMSW geometry
+// ----------------------------------------------------------------------------
+
+#ifndef __WXWINCE__
+
+void wxTopLevelWindowMSW::DoGetPosition(int *x, int *y) const
+{
+ if ( IsIconized() )
+ {
+ WINDOWPLACEMENT wp;
+ wp.length = sizeof(WINDOWPLACEMENT);
+ if ( ::GetWindowPlacement(GetHwnd(), &wp) )
+ {
+ RECT& rc = wp.rcNormalPosition;
+
+ // the position returned by GetWindowPlacement() is in workspace
+ // coordinates except for windows with WS_EX_TOOLWINDOW style
+ if ( !HasFlag(wxFRAME_TOOL_WINDOW) )
+ {
+ // we must use the correct display for the translation as the
+ // task bar might be shown on one display but not the other one
+ int n = wxDisplay::GetFromWindow(this);
+ wxDisplay dpy(n == wxNOT_FOUND ? 0 : n);
+ const wxPoint ptOfs = dpy.GetClientArea().GetPosition() -
+ dpy.GetGeometry().GetPosition();
+
+ rc.left += ptOfs.x;
+ rc.top += ptOfs.y;
+ }
+
+ if ( x )
+ *x = rc.left;
+ if ( y )
+ *y = rc.top;
+
+ return;
+ }
+
+ wxLogLastError(wxT("GetWindowPlacement"));
+ }
+ //else: normal case
+
+ wxTopLevelWindowBase::DoGetPosition(x, y);
+}
+
+void wxTopLevelWindowMSW::DoGetSize(int *width, int *height) const
+{
+ if ( IsIconized() )
+ {
+ WINDOWPLACEMENT wp;
+ wp.length = sizeof(WINDOWPLACEMENT);
+ if ( ::GetWindowPlacement(GetHwnd(), &wp) )
+ {
+ const RECT& rc = wp.rcNormalPosition;
+
+ if ( width )
+ *width = rc.right - rc.left;
+ if ( height )
+ *height = rc.bottom - rc.top;
+
+ return;
+ }
+
+ wxLogLastError(wxT("GetWindowPlacement"));
+ }
+ //else: normal case
+
+ wxTopLevelWindowBase::DoGetSize(width, height);
+}
+
+#endif // __WXWINCE__
+
+void
+wxTopLevelWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
+ const wxSize& size,
+ int& x, int& y,
+ int& w, int& h) const
+{
+ // let the system position the window if no explicit position was specified
+ if ( pos.x == wxDefaultCoord )
+ {
+ // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
+ // can just as well set it to CW_USEDEFAULT as well
+ x =
+ y = CW_USEDEFAULT;
+ }
+ else
+ {
+ // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
+ // neither because it is not handled as a special value by Windows then
+ // and so we have to choose some default value for it, even if a
+ // completely arbitrary one
+ static const int DEFAULT_Y = 200;
+
+ x = pos.x;
+ y = pos.y == wxDefaultCoord ? DEFAULT_Y : pos.y;
+ }
+
+ if ( size.x == wxDefaultCoord || size.y == wxDefaultCoord )
+ {
+ // We don't use CW_USEDEFAULT here for several reasons:
+ //
+ // 1. It results in huge frames on modern screens (1000*800 is not
+ // uncommon on my 1280*1024 screen) which is way too big for a half
+ // empty frame of most of wxWidgets samples for example)
+ //
+ // 2. It is buggy for frames with wxFRAME_TOOL_WINDOW style for which
+ // the default is for whatever reason 8*8 which breaks client <->
+ // window size calculations (it would be nice if it didn't, but it
+ // does and the simplest way to fix it seemed to change the broken
+ // default size anyhow)
+ //
+ // 3. There is just no advantage in doing it: with x and y it is
+ // possible that [future versions of] Windows position the new top
+ // level window in some smart way which we can't do, but we can
+ // guess a reasonably good size for a new window just as well
+ // ourselves
+ //
+ // The only exception is for the Windows CE platform where the system
+ // does know better than we how should the windows be sized
+#ifdef _WIN32_WCE
+ w =
+ h = CW_USEDEFAULT;
+#else // !_WIN32_WCE
+ wxSize sizeReal = size;
+ sizeReal.SetDefaults(GetDefaultSize());
+
+ w = sizeReal.x;
+ h = sizeReal.y;
+#endif // _WIN32_WCE/!_WIN32_WCE
+ }
+ else
+ {
+ w = size.x;
+ h = size.y;
+ }
+}
+