+ pos = posNew;
+ }
+
+ return pos != posStart;
+}
+
+bool wxWindowMSW::ScrollLines(int lines)
+{
+ bool down = lines > 0;
+
+ return ScrollVertically(GetHwnd(),
+ down ? SB_LINEDOWN : SB_LINEUP,
+ down ? lines : -lines);
+}
+
+bool wxWindowMSW::ScrollPages(int pages)
+{
+ bool down = pages > 0;
+
+ return ScrollVertically(GetHwnd(),
+ down ? SB_PAGEDOWN : SB_PAGEUP,
+ down ? pages : -pages);
+}
+
+// ---------------------------------------------------------------------------
+// subclassing
+// ---------------------------------------------------------------------------
+
+void wxWindowMSW::SubclassWin(WXHWND hWnd)
+{
+ wxASSERT_MSG( !m_oldWndProc, wxT("subclassing window twice?") );
+
+ HWND hwnd = (HWND)hWnd;
+ wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in SubclassWin") );
+
+ wxAssociateWinWithHandle(hwnd, this);
+
+ m_oldWndProc = (WXFARPROC)::GetWindowLong((HWND)hWnd, GWL_WNDPROC);
+
+ // we don't need to subclass the window of our own class (in the Windows
+ // sense of the word)
+ if ( !wxCheckWindowWndProc(hWnd, (WXFARPROC)wxWndProc) )
+ {
+ ::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc);
+ }
+ else
+ {
+ // don't bother restoring it neither
+ m_oldWndProc = NULL;
+ }
+}
+
+void wxWindowMSW::UnsubclassWin()
+{
+ wxRemoveHandleAssociation(this);
+
+ // Restore old Window proc
+ HWND hwnd = GetHwnd();
+ if ( hwnd )
+ {
+ m_hWnd = 0;
+
+ wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in UnsubclassWin") );
+
+ if ( m_oldWndProc )
+ {
+ if ( !wxCheckWindowWndProc((WXHWND)hwnd, m_oldWndProc) )
+ {
+ ::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) m_oldWndProc);
+ }
+
+ m_oldWndProc = NULL;
+ }
+ }
+}
+
+bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc)
+{
+#if wxUSE_UNICODE_MSLU
+ // VS: We can't use GetWindowLong(hwnd, GWL_WNDPROC) together with unicows.dll
+ // because it doesn't return pointer to the real wnd proc but rather a handle
+ // of a fake proc that does Unicode<->ANSI translation.
+ //
+ // The hack bellow works, because WNDCLASS contains original window handler
+ // rather that the unicows fake one. This may not be on purpose, though; if
+ // it stops working with future versions of unicows.dll, we can override
+ // unicows hooks by setting Unicows_{Set,Get}WindowLong and
+ // Unicows_RegisterClass to our own versions that keep track of
+ // fake<->real wnd proc mapping.
+ //
+ // FIXME: Doesn't handle wnd procs set by SetWindowLong, only these set
+ // with RegisterClass!!
+
+ if ( wxUsingUnicowsDll() )
+ {
+ static wxChar buffer[512];
+ WNDCLASS cls;
+
+ ::GetClassName((HWND)hWnd, buffer, 512);
+ ::GetClassInfo(wxGetInstance(), buffer, &cls);
+ return wndProc == (WXFARPROC)cls.lpfnWndProc;
+ }
+ else
+#endif
+ {
+ return wndProc == (WXFARPROC)::GetWindowLong((HWND)hWnd, GWL_WNDPROC);
+ }
+}
+
+// ----------------------------------------------------------------------------
+// Style handling
+// ----------------------------------------------------------------------------
+
+void wxWindowMSW::SetWindowStyleFlag(long flags)
+{
+ long flagsOld = GetWindowStyleFlag();
+ if ( flags == flagsOld )
+ return;
+
+ // update the internal variable
+ wxWindowBase::SetWindowStyleFlag(flags);
+
+ // now update the Windows style as well if needed - and if the window had
+ // been already created
+ if ( !GetHwnd() )
+ return;
+
+ WXDWORD exstyle, exstyleOld;
+ long style = MSWGetStyle(flags, &exstyle),
+ styleOld = MSWGetStyle(flagsOld, &exstyleOld);
+
+ if ( style != styleOld )
+ {
+ // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
+ // this function so instead of simply setting the style to the new
+ // value we clear the bits which were set in styleOld but are set in
+ // the new one and set the ones which were not set before
+ long styleReal = ::GetWindowLong(GetHwnd(), GWL_STYLE);
+ styleReal &= ~styleOld;
+ styleReal |= style;
+
+ ::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal);
+ }
+
+ // and the extended style
+ if ( exstyle != exstyleOld )
+ {
+ long exstyleReal = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
+ exstyleReal &= ~exstyleOld;
+ exstyleReal |= exstyle;
+
+ ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyleReal);
+
+ // we must call SetWindowPos() to flash the cached extended style and
+ // also to make the change to wxSTAY_ON_TOP style take effect: just
+ // setting the style simply doesn't work
+ if ( !::SetWindowPos(GetHwnd(),
+ exstyleReal & WS_EX_TOPMOST ? HWND_TOPMOST
+ : HWND_NOTOPMOST,
+ 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE) )
+ {
+ wxLogLastError(_T("SetWindowPos"));
+ }
+ }
+}
+
+WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
+{
+ // translate the style
+ WXDWORD style = WS_CHILD;
+
+ if ( flags & wxCLIP_CHILDREN )
+ style |= WS_CLIPCHILDREN;
+
+ if ( flags & wxCLIP_SIBLINGS )
+ style |= WS_CLIPSIBLINGS;
+
+ wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
+ if ( border != wxBORDER_NONE && border != wxBORDER_DEFAULT )
+ style |= WS_BORDER;
+
+ // now deal with ext style if the caller wants it
+ if ( exstyle )
+ {
+ *exstyle = 0;
+
+ if ( flags & wxTRANSPARENT_WINDOW )
+ *exstyle |= WS_EX_TRANSPARENT;
+
+ switch ( flags & wxBORDER_MASK )
+ {
+ default:
+ wxFAIL_MSG( _T("unknown border style") );
+ // fall through
+
+ case wxBORDER_NONE:
+ case wxBORDER_SIMPLE:
+ case wxBORDER_DEFAULT:
+ break;
+
+ case wxBORDER_STATIC:
+ *exstyle |= WS_EX_STATICEDGE;
+ break;
+
+ case wxBORDER_RAISED:
+ *exstyle |= WS_EX_WINDOWEDGE;
+ break;
+
+ case wxBORDER_SUNKEN:
+ *exstyle |= WS_EX_CLIENTEDGE;
+ break;
+
+ case wxBORDER_DOUBLE:
+ *exstyle |= WS_EX_DLGMODALFRAME;
+ break;
+ }
+ }
+
+ return style;
+}
+
+// Make a Windows extended style from the given wxWindows window style
+WXDWORD wxWindowMSW::MakeExtendedStyle(long style, bool eliminateBorders)
+{
+ WXDWORD exStyle = 0;
+ if ( style & wxTRANSPARENT_WINDOW )
+ exStyle |= WS_EX_TRANSPARENT;
+
+ if ( !eliminateBorders )
+ {
+ if ( style & wxSUNKEN_BORDER )
+ exStyle |= WS_EX_CLIENTEDGE;
+ if ( style & wxDOUBLE_BORDER )
+ exStyle |= WS_EX_DLGMODALFRAME;
+#if defined(__WIN95__)
+ if ( style & wxRAISED_BORDER )
+ // It seems that WS_EX_WINDOWEDGE doesn't work, but WS_EX_DLGMODALFRAME does
+ exStyle |= WS_EX_DLGMODALFRAME; /* WS_EX_WINDOWEDGE */;
+ if ( style & wxSTATIC_BORDER )
+ exStyle |= WS_EX_STATICEDGE;
+#endif
+ }
+
+ return exStyle;
+}
+
+// Determines whether native 3D effects or CTL3D should be used,
+// applying a default border style if required, and returning an extended
+// style to pass to CreateWindowEx.
+WXDWORD wxWindowMSW::Determine3DEffects(WXDWORD defaultBorderStyle,
+ bool *want3D) const
+{
+ // If matches certain criteria, then assume no 3D effects
+ // unless specifically requested (dealt with in MakeExtendedStyle)
+ if ( !GetParent()
+#if wxUSE_CONTROLS
+ || !IsKindOf(CLASSINFO(wxControl))
+#endif // wxUSE_CONTROLS
+ || (m_windowStyle & wxNO_BORDER) )
+ {
+ *want3D = FALSE;
+ return MakeExtendedStyle(m_windowStyle);
+ }
+
+ // Determine whether we should be using 3D effects or not.
+ bool nativeBorder = FALSE; // by default, we don't want a Win95 effect
+
+ // 1) App can specify global 3D effects
+ *want3D = wxTheApp->GetAuto3D();
+
+ // 2) If the parent is being drawn with user colours, or simple border specified,
+ // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
+ if ( GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER) )
+ *want3D = FALSE;
+
+ // 3) Control can override this global setting by defining
+ // a border style, e.g. wxSUNKEN_BORDER
+ if ( m_windowStyle & wxSUNKEN_BORDER )
+ *want3D = TRUE;
+
+ // 4) If it's a special border, CTL3D can't cope so we want a native border
+ if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
+ (m_windowStyle & wxSTATIC_BORDER) )
+ {
+ *want3D = TRUE;
+ nativeBorder = TRUE;
+ }
+
+ // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
+ // effects from extended style
+#if wxUSE_CTL3D
+ if ( *want3D )
+ nativeBorder = FALSE;
+#endif
+
+ DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder);
+
+ // If we want 3D, but haven't specified a border here,
+ // apply the default border style specified.
+ // TODO what about non-Win95 WIN32? Does it have borders?
+#if defined(__WIN95__) && !wxUSE_CTL3D
+ if ( defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER ) ||
+ (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) ))
+ exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE;
+#endif
+
+ return exStyle;
+}
+
+#if WXWIN_COMPATIBILITY
+// If nothing defined for this, try the parent.
+// E.g. we may be a button loaded from a resource, with no callback function
+// defined.
+void wxWindowMSW::OnCommand(wxWindow& win, wxCommandEvent& event)
+{
+ if ( GetEventHandler()->ProcessEvent(event) )
+ return;
+ if ( m_parent )
+ m_parent->GetEventHandler()->OnCommand(win, event);
+}
+#endif // WXWIN_COMPATIBILITY_2
+
+#if WXWIN_COMPATIBILITY
+wxObject* wxWindowMSW::GetChild(int number) const
+{
+ // Return a pointer to the Nth object in the Panel
+ wxNode *node = GetChildren().First();
+ int n = number;
+ while (node && n--)
+ node = node->Next();
+ if ( node )
+ {
+ wxObject *obj = (wxObject *)node->Data();
+ return(obj);
+ }
+ else
+ return NULL;
+}
+#endif // WXWIN_COMPATIBILITY
+
+// Setup background and foreground colours correctly
+void wxWindowMSW::SetupColours()
+{
+ if ( GetParent() )
+ SetBackgroundColour(GetParent()->GetBackgroundColour());
+}
+
+bool wxWindowMSW::IsMouseInWindow() const
+{
+ // get the mouse position
+ POINT pt;
+ ::GetCursorPos(&pt);
+
+ // find the window which currently has the cursor and go up the window
+ // chain until we find this window - or exhaust it
+ HWND hwnd = ::WindowFromPoint(pt);
+ while ( hwnd && (hwnd != GetHwnd()) )
+ hwnd = ::GetParent(hwnd);
+
+ return hwnd != NULL;
+}
+
+void wxWindowMSW::OnIdle(wxIdleEvent& WXUNUSED(event))
+{
+ // Check if we need to send a LEAVE event
+ if ( m_mouseInWindow )
+ {
+ // note that we should generate the leave event whether the window has
+ // or doesn't have mouse capture
+ if ( !IsMouseInWindow() )
+ {
+ // Generate a LEAVE event
+ m_mouseInWindow = FALSE;
+
+ // Unfortunately the mouse button and keyboard state may have
+ // changed by the time the OnIdle function is called, so 'state'
+ // may be meaningless.
+ int state = 0;
+ if ( wxIsShiftDown() )
+ state |= MK_SHIFT;
+ if ( wxIsCtrlDown() )
+ state |= MK_CONTROL;
+ if ( GetKeyState( VK_LBUTTON ) )
+ state |= MK_LBUTTON;
+ if ( GetKeyState( VK_MBUTTON ) )
+ state |= MK_MBUTTON;
+ if ( GetKeyState( VK_RBUTTON ) )
+ state |= MK_RBUTTON;
+
+ POINT pt;
+ if ( !::GetCursorPos(&pt) )
+ {
+ wxLogLastError(_T("GetCursorPos"));
+ }
+
+ // we need to have client coordinates here for symmetry with
+ // wxEVT_ENTER_WINDOW
+ RECT rect = wxGetWindowRect(GetHwnd());
+ pt.x -= rect.left;
+ pt.y -= rect.top;
+
+ wxMouseEvent event2(wxEVT_LEAVE_WINDOW);
+ InitMouseEvent(event2, pt.x, pt.y, state);
+
+ (void)GetEventHandler()->ProcessEvent(event2);
+ }
+ }
+
+ UpdateWindowUI();
+}
+
+// Set this window to be the child of 'parent'.
+bool wxWindowMSW::Reparent(wxWindowBase *parent)
+{
+ if ( !wxWindowBase::Reparent(parent) )
+ return FALSE;
+
+ HWND hWndChild = GetHwnd();
+ HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
+
+ ::SetParent(hWndChild, hWndParent);
+
+ return TRUE;
+}
+
+void wxWindowMSW::Clear()
+{
+ wxClientDC dc((wxWindow *)this);
+ wxBrush brush(GetBackgroundColour(), wxSOLID);
+ dc.SetBackground(brush);
+ dc.Clear();
+}
+
+static inline void SendSetRedraw(HWND hwnd, bool on)
+{
+#ifndef __WXMICROWIN__
+ ::SendMessage(hwnd, WM_SETREDRAW, (WPARAM)on, 0);
+#endif
+}
+
+void wxWindowMSW::Freeze()
+{
+ SendSetRedraw(GetHwnd(), FALSE);
+}
+
+void wxWindowMSW::Thaw()
+{
+ SendSetRedraw(GetHwnd(), TRUE);
+
+ // we need to refresh everything or otherwise he invalidated area is not
+ // repainted
+ Refresh();
+}
+
+void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect)
+{
+ HWND hWnd = GetHwnd();
+ if ( hWnd )
+ {
+ if ( rect )
+ {
+ RECT mswRect;
+ mswRect.left = rect->x;
+ mswRect.top = rect->y;
+ mswRect.right = rect->x + rect->width;
+ mswRect.bottom = rect->y + rect->height;
+
+ ::InvalidateRect(hWnd, &mswRect, eraseBack);
+ }
+ else
+ ::InvalidateRect(hWnd, NULL, eraseBack);
+ }
+}
+
+void wxWindowMSW::Update()
+{
+ if ( !::UpdateWindow(GetHwnd()) )
+ {
+ wxLogLastError(_T("UpdateWindow"));
+ }
+
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+ // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
+ // handler needs to be really drawn right now
+ (void)::GdiFlush();
+#endif // __WIN32__
+}
+
+// ---------------------------------------------------------------------------
+// drag and drop
+// ---------------------------------------------------------------------------
+
+#if wxUSE_DRAG_AND_DROP
+
+void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget)
+{
+ if ( m_dropTarget != 0 ) {
+ m_dropTarget->Revoke(m_hWnd);
+ delete m_dropTarget;
+ }
+
+ m_dropTarget = pDropTarget;
+ if ( m_dropTarget != 0 )
+ m_dropTarget->Register(m_hWnd);
+}
+
+#endif // wxUSE_DRAG_AND_DROP
+
+// old style file-manager drag&drop support: we retain the old-style
+// DragAcceptFiles in parallel with SetDropTarget.
+void wxWindowMSW::DragAcceptFiles(bool accept)
+{
+ HWND hWnd = GetHwnd();
+ if ( hWnd )
+ ::DragAcceptFiles(hWnd, (BOOL)accept);
+}
+
+// ----------------------------------------------------------------------------
+// tooltips
+// ----------------------------------------------------------------------------
+
+#if wxUSE_TOOLTIPS
+
+void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip)
+{
+ wxWindowBase::DoSetToolTip(tooltip);
+
+ if ( m_tooltip )
+ m_tooltip->SetWindow(this);
+}
+
+#endif // wxUSE_TOOLTIPS
+
+// ---------------------------------------------------------------------------
+// moving and resizing
+// ---------------------------------------------------------------------------
+
+// Get total size
+void wxWindowMSW::DoGetSize(int *x, int *y) const
+{
+ RECT rect = wxGetWindowRect(GetHwnd());
+
+ if ( x )
+ *x = rect.right - rect.left;
+ if ( y )
+ *y = rect.bottom - rect.top;
+}
+
+// Get size *available for subwindows* i.e. excluding menu bar etc.
+void wxWindowMSW::DoGetClientSize(int *x, int *y) const
+{
+ RECT rect = wxGetClientRect(GetHwnd());
+
+ if ( x )
+ *x = rect.right;
+ if ( y )
+ *y = rect.bottom;
+}
+
+void wxWindowMSW::DoGetPosition(int *x, int *y) const
+{
+ RECT rect = wxGetWindowRect(GetHwnd());
+
+ POINT point;
+ point.x = rect.left;
+ point.y = rect.top;
+
+ // we do the adjustments with respect to the parent only for the "real"
+ // children, not for the dialogs/frames
+ if ( !IsTopLevel() )
+ {
+ HWND hParentWnd = 0;
+ wxWindow *parent = GetParent();
+ if ( parent )
+ hParentWnd = GetWinHwnd(parent);
+
+ // Since we now have the absolute screen coords, if there's a parent we
+ // must subtract its top left corner
+ if ( hParentWnd )
+ {
+ ::ScreenToClient(hParentWnd, &point);
+ }
+
+ if ( parent )
+ {
+ // We may be faking the client origin. So a window that's really at (0,
+ // 30) may appear (to wxWin apps) to be at (0, 0).
+ wxPoint pt(parent->GetClientAreaOrigin());
+ point.x -= pt.x;
+ point.y -= pt.y;
+ }
+ }
+
+ if ( x )
+ *x = point.x;
+ if ( y )
+ *y = point.y;
+}
+
+void wxWindowMSW::DoScreenToClient(int *x, int *y) const
+{
+ POINT pt;
+ if ( x )
+ pt.x = *x;
+ if ( y )
+ pt.y = *y;
+
+ ::ScreenToClient(GetHwnd(), &pt);
+
+ if ( x )
+ *x = pt.x;
+ if ( y )
+ *y = pt.y;
+}
+
+void wxWindowMSW::DoClientToScreen(int *x, int *y) const
+{
+ POINT pt;
+ if ( x )
+ pt.x = *x;
+ if ( y )
+ pt.y = *y;
+
+ ::ClientToScreen(GetHwnd(), &pt);
+
+ if ( x )
+ *x = pt.x;
+ if ( y )
+ *y = pt.y;
+}
+
+void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height)
+{
+ // TODO: is this consistent with other platforms?
+ // Still, negative width or height shouldn't be allowed
+ if (width < 0)
+ width = 0;
+ if (height < 0)
+ height = 0;
+ if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) )
+ {
+ wxLogLastError(wxT("MoveWindow"));
+ }
+}
+
+// set the size of the window: if the dimensions are positive, just use them,
+// but if any of them is equal to -1, it means that we must find the value for
+// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
+// which case -1 is a valid value for x and y)
+//
+// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
+// the width/height to best suit our contents, otherwise we reuse the current
+// width/height
+void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+{
+ // get the current size and position...
+ int currentX, currentY;
+ GetPosition(¤tX, ¤tY);
+ int currentW,currentH;
+ GetSize(¤tW, ¤tH);
+
+ // ... and don't do anything (avoiding flicker) if it's already ok
+ if ( x == currentX && y == currentY &&
+ width == currentW && height == currentH )
+ {
+ return;
+ }
+
+ if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
+ x = currentX;
+ if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
+ y = currentY;
+
+ AdjustForParentClientOrigin(x, y, sizeFlags);
+
+ wxSize size(-1, -1);
+ if ( width == -1 )
+ {
+ if ( sizeFlags & wxSIZE_AUTO_WIDTH )
+ {
+ size = DoGetBestSize();
+ width = size.x;
+ }
+ else
+ {
+ // just take the current one
+ width = currentW;
+ }
+ }
+
+ if ( height == -1 )
+ {
+ if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
+ {
+ if ( size.x == -1 )
+ {
+ size = DoGetBestSize();
+ }
+ //else: already called DoGetBestSize() above
+
+ height = size.y;
+ }
+ else
+ {
+ // just take the current one
+ height = currentH;
+ }
+ }
+
+ DoMoveWindow(x, y, width, height);
+}
+
+void wxWindowMSW::DoSetClientSize(int width, int height)
+{
+ // setting the client size is less obvious than it it could have been
+ // because in the result of changing the total size the window scrollbar
+ // may [dis]appear and/or its menubar may [un]wrap and so the client size
+ // will not be correct as the difference between the total and client size
+ // changes - so we keep changing it until we get it right
+ //
+ // normally this loop shouldn't take more than 3 iterations (usually 1 but
+ // if scrollbars [dis]appear as the result of the first call, then 2 and it
+ // may become 3 if the window had 0 size originally and so we didn't
+ // calculate the scrollbar correction correctly during the first iteration)
+ // but just to be on the safe side we check for it instead of making it an
+ // "infinite" loop (i.e. leaving break inside as the only way to get out)
+ for ( int i = 0; i < 4; i++ )
+ {
+ RECT rectClient;
+ ::GetClientRect(GetHwnd(), &rectClient);
+
+ // if the size is already ok, stop here (rectClient.left = top = 0)
+ if ( (rectClient.right == width || width == -1) &&
+ (rectClient.bottom == height || height == -1) )
+ {
+ break;
+ }
+
+ int widthClient = width,
+ heightClient = height;
+
+ // Find the difference between the entire window (title bar and all)
+ // and the client area; add this to the new client size to move the
+ // window
+ RECT rectWin;
+ ::GetWindowRect(GetHwnd(), &rectWin);
+
+ widthClient += rectWin.right - rectWin.left - rectClient.right;
+ heightClient += rectWin.bottom - rectWin.top - rectClient.bottom;
+
+ POINT point;
+ point.x = rectWin.left;
+ point.y = rectWin.top;
+
+ // MoveWindow positions the child windows relative to the parent, so
+ // adjust if necessary
+ if ( !IsTopLevel() )
+ {
+ wxWindow *parent = GetParent();
+ if ( parent )
+ {
+ ::ScreenToClient(GetHwndOf(parent), &point);
+ }
+ }
+
+ DoMoveWindow(point.x, point.y, widthClient, heightClient);
+ }
+}
+
+// For implementation purposes - sometimes decorations make the client area
+// smaller
+wxPoint wxWindowMSW::GetClientAreaOrigin() const
+{
+ return wxPoint(0, 0);
+}
+
+// ---------------------------------------------------------------------------
+// text metrics
+// ---------------------------------------------------------------------------
+
+int wxWindowMSW::GetCharHeight() const
+{
+ return wxGetTextMetrics(this).tmHeight;
+}
+
+int wxWindowMSW::GetCharWidth() const
+{
+ // +1 is needed because Windows apparently adds it when calculating the
+ // dialog units size in pixels
+#if wxDIALOG_UNIT_COMPATIBILITY
+ return wxGetTextMetrics(this).tmAveCharWidth;
+#else
+ return wxGetTextMetrics(this).tmAveCharWidth + 1;
+#endif
+}
+
+void wxWindowMSW::GetTextExtent(const wxString& string,
+ int *x, int *y,
+ int *descent, int *externalLeading,
+ const wxFont *theFont) const
+{
+ const wxFont *fontToUse = theFont;
+ if ( !fontToUse )
+ fontToUse = &m_font;
+
+ HWND hWnd = GetHwnd();
+ HDC dc = ::GetDC(hWnd);
+
+ HFONT fnt = 0;
+ HFONT hfontOld = 0;
+ if ( fontToUse && fontToUse->Ok() )
+ {
+ fnt = (HFONT)((wxFont *)fontToUse)->GetResourceHandle(); // const_cast
+ if ( fnt )
+ hfontOld = (HFONT)SelectObject(dc,fnt);
+ }
+
+ SIZE sizeRect;
+ TEXTMETRIC tm;
+ GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect);
+ GetTextMetrics(dc, &tm);
+
+ if ( fontToUse && fnt && hfontOld )
+ SelectObject(dc, hfontOld);
+
+ ReleaseDC(hWnd, dc);
+
+ if ( x )
+ *x = sizeRect.cx;
+ if ( y )
+ *y = sizeRect.cy;
+ if ( descent )
+ *descent = tm.tmDescent;
+ if ( externalLeading )
+ *externalLeading = tm.tmExternalLeading;