X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d66d050088ee2012542a2d2607b5329ff5f3a491..1a27a87d531c408a4ccd9bf871bab32384a7d617:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 7a81ded775..199c04357e 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -183,12 +183,6 @@ extern wxMenu *wxCurrentPopupMenu; #endif -#ifdef __WXWINCE__ -extern wxChar *wxCanvasClassName; -#else -extern const wxChar *wxCanvasClassName; -#endif - // true if we had already created the std colour map, used by // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT) static bool gs_hasStdCmap = false; @@ -589,6 +583,12 @@ wxWindowMSW::~wxWindowMSW() } +/* static */ +const wxChar *wxWindowMSW::MSWGetRegisteredClassName() +{ + return wxApp::GetRegisteredClassName(_T("wxWindow"), COLOR_BTNFACE); +} + // real construction (Init() must have been called before!) bool wxWindowMSW::Create(wxWindow *parent, wxWindowID id, @@ -621,7 +621,8 @@ bool wxWindowMSW::Create(wxWindow *parent, msflags |= WS_VISIBLE; } - if ( !MSWCreate(wxCanvasClassName, NULL, pos, size, msflags, exstyle) ) + if ( !MSWCreate(MSWGetRegisteredClassName(), + NULL, pos, size, msflags, exstyle) ) return false; InheritAttributes(); @@ -962,6 +963,9 @@ void wxWindowMSW::MSWUpdateUIState(int action, int state) // scrolling stuff // --------------------------------------------------------------------------- +namespace +{ + inline int GetScrollPosition(HWND hWnd, int wOrient) { #ifdef __WXMICROWIN__ @@ -977,12 +981,19 @@ inline int GetScrollPosition(HWND hWnd, int wOrient) #endif } +inline UINT WXOrientToSB(int orient) +{ + return orient == wxHORIZONTAL ? SB_HORZ : SB_VERT; +} + +} // anonymous namespace + int wxWindowMSW::GetScrollPos(int orient) const { HWND hWnd = GetHwnd(); wxCHECK_MSG( hWnd, 0, _T("no HWND in GetScrollPos") ); - return GetScrollPosition(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT); + return GetScrollPosition(hWnd, WXOrientToSB(orient)); } // This now returns the whole range, not just the number @@ -993,15 +1004,9 @@ int wxWindowMSW::GetScrollRange(int orient) const HWND hWnd = GetHwnd(); if ( !hWnd ) return 0; -#if 0 - ::GetScrollRange(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT, - &minPos, &maxPos); -#endif WinStruct scrollInfo; scrollInfo.fMask = SIF_RANGE; - if ( !::GetScrollInfo(hWnd, - orient == wxHORIZONTAL ? SB_HORZ : SB_VERT, - &scrollInfo) ) + if ( !::GetScrollInfo(hWnd, WXOrientToSB(orient), &scrollInfo) ) { // Most of the time this is not really an error, since the return // value can also be zero when there is no scrollbar yet. @@ -1034,8 +1039,7 @@ void wxWindowMSW::SetScrollPos(int orient, int pos, bool refresh) info.fMask |= SIF_DISABLENOSCROLL; } - ::SetScrollInfo(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT, - &info, refresh); + ::SetScrollInfo(hWnd, WXOrientToSB(orient), &info, refresh); } // New function that will replace some of the above. @@ -1045,28 +1049,37 @@ void wxWindowMSW::SetScrollbar(int orient, int range, bool refresh) { + // We have to set the variables here to make them valid in events + // triggered by ::SetScrollInfo() + *(orient == wxHORIZONTAL ? &m_xThumbSize : &m_yThumbSize) = pageSize; + + HWND hwnd = GetHwnd(); + if ( !hwnd ) + return; + WinStruct info; - info.nPage = pageSize; - info.nMin = 0; // range is nMax - nMin + 1 - info.nMax = range - 1; // as both nMax and nMax are inclusive - info.nPos = pos; + if ( range != -1 ) + { + info.nPage = pageSize; + info.nMin = 0; // range is nMax - nMin + 1 + info.nMax = range - 1; // as both nMax and nMax are inclusive + info.nPos = pos; + + // enable the scrollbar if it had been disabled before by specifying + // SIF_DISABLENOSCROLL below: as we can't know whether this had been + // done or not just do it always + ::EnableScrollBar(hwnd, WXOrientToSB(orient), ESB_ENABLE_BOTH); + } + //else: leave all the fields to be 0 + info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - if ( HasFlag(wxALWAYS_SHOW_SB) ) + if ( HasFlag(wxALWAYS_SHOW_SB) || range == -1 ) { // disable scrollbar instead of removing it then info.fMask |= SIF_DISABLENOSCROLL; } - HWND hWnd = GetHwnd(); - if ( hWnd ) - { - // We have to set the variables here to make them valid in events - // triggered by ::SetScrollInfo() - *(orient == wxHORIZONTAL ? &m_xThumbSize : &m_yThumbSize) = pageSize; - - ::SetScrollInfo(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT, - &info, refresh); - } + ::SetScrollInfo(hwnd, WXOrientToSB(orient), &info, refresh); } void wxWindowMSW::ScrollWindow(int dx, int dy, const wxRect *prect) @@ -1276,36 +1289,12 @@ void wxWindowMSW::DissociateHandle() bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC WXUNUSED(wndProc)) { -// TODO: This list of window class names should be factored out so they can be -// managed in one place and then accessed from here and other places, such as -// wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses() + const wxString str(wxGetWindowClass(hWnd)); -#ifdef __WXWINCE__ - extern wxChar *wxCanvasClassName; - extern wxChar *wxCanvasClassNameNR; -#else - extern const wxChar *wxCanvasClassName; - extern const wxChar *wxCanvasClassNameNR; -#endif - extern const wxChar *wxMDIFrameClassName; - extern const wxChar *wxMDIFrameClassNameNoRedraw; - extern const wxChar *wxMDIChildFrameClassName; - extern const wxChar *wxMDIChildFrameClassNameNoRedraw; - wxString str(wxGetWindowClass(hWnd)); - if (str == wxCanvasClassName || - str == wxCanvasClassNameNR || -#if wxUSE_GLCANVAS - str == _T("wxGLCanvasClass") || - str == _T("wxGLCanvasClassNR") || -#endif // wxUSE_GLCANVAS - str == wxMDIFrameClassName || - str == wxMDIFrameClassNameNoRedraw || - str == wxMDIChildFrameClassName || - str == wxMDIChildFrameClassNameNoRedraw || - str == _T("wxTLWHiddenParent")) - return true; // Effectively means don't subclass - else - return false; + // TODO: get rid of wxTLWHiddenParent special case (currently it's not + // registered by wxApp but using ad hoc code in msw/toplevel.cpp); + // there is also a hidden window class used by sockets &c + return wxApp::IsRegisteredClassName(str) || str == _T("wxTLWHiddenParent"); } // ---------------------------------------------------------------------------- @@ -1987,6 +1976,11 @@ void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height) #if USE_DEFERRED_SIZING m_pendingPosition = wxPoint(x, y); m_pendingSize = wxSize(width, height); + } + else // window was moved immediately, without deferring it + { + m_pendingPosition = wxDefaultPosition; + m_pendingSize = wxDefaultSize; #endif // USE_DEFERRED_SIZING } } @@ -3418,12 +3412,12 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l rc.result = MSWDefWindowProc(message, wParam, lParam); processed = true; - // now alter the client size making room for drawing a themed border - NCCALCSIZE_PARAMS *csparam = NULL; + // now alter the client size making room for drawing a + // themed border RECT *rect; if ( wParam ) { - csparam = (NCCALCSIZE_PARAMS *)lParam; + NCCALCSIZE_PARAMS *csparam = (NCCALCSIZE_PARAMS *)lParam; rect = &csparam->rgrc[0]; } else @@ -3680,6 +3674,11 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass, // especially for wxTLWs wxCHECK_MSG( !m_hWnd, true, "window can't be recreated" ); + // this can happen if this function is called using the return value of + // wxApp::GetRegisteredClassName() which failed + wxCHECK_MSG( wclass, false, "failed to register window class?" ); + + // choose the position/size for the new window int x, y, w, h; (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h); @@ -3694,7 +3693,7 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass, wxString className(wclass); if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) { - className += wxT("NR"); + className += wxApp::GetNoRedrawClassSuffix(); } // do create the window @@ -3845,8 +3844,7 @@ bool wxWindowMSW::HandleTooltipNotify(WXUINT code, // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have // to copy the string we have into the buffer static wxChar buf[513]; - wxStrncpy(buf, ttip.c_str(), WXSIZEOF(buf) - 1); - buf[WXSIZEOF(buf) - 1] = _T('\0'); + wxStrlcpy(buf, ttip.c_str(), WXSIZEOF(buf)); ttText->lpszText = buf; } @@ -4102,7 +4100,6 @@ bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam) ::DragQueryFile(hFilesInfo, wIndex, wxStringBuffer(files[wIndex], len), len); } - DragFinish (hFilesInfo); wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files); event.SetEventObject(this); @@ -4112,6 +4109,8 @@ bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam) event.m_pos.x = dropPoint.x; event.m_pos.y = dropPoint.y; + DragFinish(hFilesInfo); + return HandleWindowEvent(event); #endif } @@ -4262,13 +4261,14 @@ bool wxWindowMSW::HandlePower(WXWPARAM WXUNUSED_IN_WINCE(wParam), bool wxWindowMSW::IsDoubleBuffered() const { - const wxWindowMSW *wnd = this; - do + for ( const wxWindowMSW *win = this; win; win = win->GetParent() ) { - if ( wxHasWindowExStyle(wnd, WS_EX_COMPOSITED) ) + if ( wxHasWindowExStyle(win, WS_EX_COMPOSITED) ) return true; - wnd = wnd->GetParent(); - } while ( wnd && !wnd->IsTopLevel() ); + + if ( win->IsTopLevel() ) + break; + } return false; } @@ -5300,20 +5300,16 @@ bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags) static bool s_initDone = false; if ( !s_initDone ) { - wxLogNull noLog; - - wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM); + // see comment in wxApp::GetComCtl32Version() explaining the + // use of wxLoadedDLL + wxLoadedDLL dllComCtl32(_T("comctl32.dll")); if ( dllComCtl32.IsLoaded() ) { s_pfn_TrackMouseEvent = (_TrackMouseEvent_t) - dllComCtl32.GetSymbol(_T("_TrackMouseEvent")); + dllComCtl32.RawGetSymbol(_T("_TrackMouseEvent")); } s_initDone = true; - - // notice that it's ok to unload comctl32.dll here as it won't - // be really unloaded, being still in use because we link to it - // statically too } if ( s_pfn_TrackMouseEvent ) @@ -5799,8 +5795,7 @@ bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam, scrollInfo.fMask = SIF_TRACKPOS; if ( !::GetScrollInfo(GetHwnd(), - orientation == wxHORIZONTAL ? SB_HORZ - : SB_VERT, + WXOrientToSB(orientation), &scrollInfo) ) { // Not necessarily an error, if there are no scrollbars yet.