]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
added WX_DECLARE_OBJARRAY_WITH_DECL
[wxWidgets.git] / src / msw / window.cpp
index abdcc7dac160cf78ba010f5a96d22b91d637bbcf..a451b9a33aea963eca7fb22feec9218a3e0e927d 100644 (file)
@@ -29,8 +29,7 @@
 #endif
 
 #ifndef WX_PRECOMP
-    #include <windows.h>
-    #include "wx/msw/winundef.h"
+    #include "wx/msw/wrapwin.h"
     #include "wx/window.h"
     #include "wx/accel.h"
     #include "wx/setup.h"
@@ -230,7 +229,25 @@ static inline void wxBringWindowToTop(HWND hwnd)
 #ifdef __WXUNIVERSAL__
     IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW, wxWindowBase)
 #else // __WXMSW__
+#if wxUSE_EXTENDED_RTTI
+IMPLEMENT_DYNAMIC_CLASS_XTI(wxWindow, wxWindowBase,"wx/window.h")
+
+WX_BEGIN_PROPERTIES_TABLE(wxWindow)
+       WX_READONLY_PROPERTY( Parent,wxWindow*, GetParent,  )
+       WX_PROPERTY( Id,wxWindowID, SetId, GetId, -1 )
+       WX_PROPERTY_SET_BY_REF( Title,wxString, SetTitle, GetTitle, wxT("") )
+       WX_PROPERTY_SET_BY_REF( Label,wxString, SetLabel, GetLabel, wxT("") )
+       WX_PROPERTY_SET_BY_REF( Position,wxPoint, SetPosition , GetPosition, wxDefaultPosition )
+       WX_PROPERTY_SET_BY_REF( Size,wxSize, SetSize, GetSize, wxDefaultSize )
+WX_END_PROPERTIES_TABLE()
+
+WX_BEGIN_HANDLERS_TABLE(wxWindow)
+WX_END_HANDLERS_TABLE()
+
+WX_CONSTRUCTOR_DUMMY(wxWindow)
+#else
     IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
+#endif
 #endif // __WXUNIVERSAL__/__WXMSW__
 
 BEGIN_EVENT_TABLE(wxWindowMSW, wxWindowBase)
@@ -748,13 +765,15 @@ inline int GetScrollPosition(HWND hWnd, int wOrient)
 #ifdef __WXMICROWIN__
     return ::GetScrollPosWX(hWnd, wOrient);
 #else
-    SCROLLINFO scrollInfo;
+    WinStruct<SCROLLINFO> scrollInfo;
+    scrollInfo.cbSize = sizeof(SCROLLINFO);
     scrollInfo.fMask = SIF_POS;
     if ( !::GetScrollInfo(hWnd,
-                                  wOrient,
-                                  &scrollInfo) )
+                          wOrient,
+                          &scrollInfo) )
     {
-        wxLogLastError(_T("GetScrollInfo"));
+        // Not neccessarily an error, if there are no scrollbars yet.
+        // wxLogLastError(_T("GetScrollInfo"));
     }
     return scrollInfo.nPos;
 //    return ::GetScrollPos(hWnd, wOrient);
@@ -781,13 +800,15 @@ int wxWindowMSW::GetScrollRange(int orient) const
     ::GetScrollRange(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
                      &minPos, &maxPos);
 #endif
-    SCROLLINFO scrollInfo;
+    WinStruct<SCROLLINFO> scrollInfo;
     scrollInfo.fMask = SIF_RANGE;
     if ( !::GetScrollInfo(hWnd,
-                                  orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
-                                  &scrollInfo) )
+                          orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
+                          &scrollInfo) )
     {
-        wxLogLastError(_T("GetScrollInfo"));
+        // Most of the time this is not really an error, since the return
+        // value can also be zero when there is no scrollbar yet.
+        // wxLogLastError(_T("GetScrollInfo"));
     }
     maxPos = scrollInfo.nMax;
 
@@ -931,7 +952,7 @@ void wxWindowMSW::SubclassWin(WXHWND hWnd)
 
     // we don't need to subclass the window of our own class (in the Windows
     // sense of the word)
-    if ( !wxCheckWindowWndProc(hWnd, (WXFARPROC)wxWndProc) )
+       if ( !wxCheckWindowWndProc(hWnd, (WXFARPROC)wxWndProc) )
     {
         ::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc);
     }
@@ -977,6 +998,28 @@ bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc)
     // 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.
+
+       // On WinCE (at least), the wndproc comparison doesn't work,
+       // so have to use something like this.
+#ifdef __WXWINCE__
+       extern const wxChar *wxCanvasClassName;
+       extern const wxChar *wxCanvasClassNameNR;
+       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 ||
+               str == wxMDIFrameClassName ||
+               str == wxMDIFrameClassNameNoRedraw ||
+               str == wxMDIChildFrameClassName ||
+               str == wxMDIChildFrameClassNameNoRedraw ||
+               str == _T("wxTLWHiddenParent"))
+               return TRUE; // Effectively means don't subclass
+       else
+               return FALSE;
+#else
     WNDCLASS cls;
     if ( !::GetClassInfo(wxGetInstance(), wxGetWindowClass(hWnd), &cls) )
     {
@@ -986,6 +1029,7 @@ bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc)
     }
 
     return wndProc == (WXFARPROC)cls.lpfnWndProc;
+#endif
 }
 
 // ----------------------------------------------------------------------------
@@ -1987,7 +2031,10 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                       node;
                       node = node->GetNext() )
                 {
-                    if ( node->GetData()->AcceptsFocus() )
+                    wxWindow * const win = node->GetData();
+                    if ( win->AcceptsFocus() &&
+                            !(::GetWindowLong(GetHwndOf(win), GWL_EXSTYLE) &
+                                WS_EX_CONTROLPARENT) )
                     {
                         // it shouldn't hang...
                         canSafelyCallIsDlgMsg = TRUE;
@@ -1996,7 +2043,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                     }
                 }
             }
-#endif
+#endif // !__WXWINCE__
 
             if ( canSafelyCallIsDlgMsg )
             {
@@ -2300,8 +2347,19 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             break;
 
         case WM_PAINT:
-            processed = HandlePaint();
-            break;
+            {
+                if ( wParam )
+                {
+                    // cast to wxWindow is needed for wxUniv
+                    wxPaintDCEx dc((wxWindow *)this, (WXHDC)wParam);
+                    processed = HandlePaint();
+                }
+                else
+                {
+                    processed = HandlePaint();
+                }
+                break;
+            }
 
         case WM_CLOSE:
 #ifdef __WXUNIVERSAL__
@@ -2955,18 +3013,37 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass,
     // do create the window
     wxWindowCreationHook hook(this);
 
-    m_hWnd = (WXHWND)::CreateWindowEx
-                       (
-                            extendedStyle,
-                            className,
-                            title ? title : wxEmptyString,
-                            style,
-                            x, y, w, h,
-                            (HWND)MSWGetParent(),
-                            (HMENU)controlId,
-                            wxGetInstance(),
-                            NULL                        // no extra data
-                       );
+#ifdef __WXWINCE__
+    if (extendedStyle == 0)
+    {
+        m_hWnd = (WXHWND)::CreateWindow
+            (
+            className,
+            title ? title : wxEmptyString,
+            style,
+            x, y, w, h,
+            (HWND)MSWGetParent(),
+            (HMENU)controlId,
+            wxGetInstance(),
+            NULL                        // no extra data
+            );
+    }
+    else
+#endif
+    {
+        m_hWnd = (WXHWND)::CreateWindowEx
+            (
+            extendedStyle,
+            className,
+            title ? title : wxEmptyString,
+            style,
+            x, y, w, h,
+            (HWND)MSWGetParent(),
+            (HMENU)controlId,
+            wxGetInstance(),
+            NULL                        // no extra data
+            );
+    }
 
     if ( !m_hWnd )
     {
@@ -3338,9 +3415,7 @@ bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
 
         // and now get the file name
         ::DragQueryFile(hFilesInfo, wIndex,
-                        files[wIndex].GetWriteBuf(len), len);
-
-        files[wIndex].UngetWriteBuf();
+                        wxStringBuffer(files[wIndex], len), len);
     }
     DragFinish (hFilesInfo);
 
@@ -3477,20 +3552,21 @@ bool wxWindowMSW::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
 
 #endif // USE_OWNER_DRAWN
 
-#if wxUSE_CONTROLS
+#if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__) 
 
 #if wxUSE_OWNER_DRAWN
-    wxWindow *item = FindItem(id);
-    if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
-        return ((wxControl *)item)->MSWOnDraw(itemStruct);
-#elif !defined(__WXUNIVERSAL__)
+    wxControl *item = wxDynamicCast(FindItem(id), wxControl);
+#else // !wxUSE_OWNER_DRAWN
     // we may still have owner-drawn buttons internally because we have to make
     // them owner-drawn to support colour change
-    wxWindow *item = FindItem(id);
-    if ( item && item->IsKindOf(CLASSINFO(wxButton)) )
-        return ((wxButton *)item)->MSWOnDraw(itemStruct);
+    wxControl *item = wxDynamicCast(FindItem(id), wxButton);
 #endif // USE_OWNER_DRAWN
 
+    if ( item )
+    {
+        return item->MSWOnDraw(itemStruct);
+    }
+
 #endif // wxUSE_CONTROLS
 
     return FALSE;
@@ -3498,7 +3574,7 @@ bool wxWindowMSW::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
 
 bool wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
 {
-#if wxUSE_OWNER_DRAWN
+#if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
     // is it a menu item?
     MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
     if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU )
@@ -3511,12 +3587,13 @@ bool wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
                                         &pMeasureStruct->itemHeight);
     }
 
-    wxWindow *item = FindItem(id);
-    if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
+    wxControl *item = wxDynamicCast(FindItem(id), wxControl);
+    if ( item )
     {
-        return ((wxControl *)item)->MSWOnMeasure(itemStruct);
+        return item->MSWOnMeasure(itemStruct);
     }
-#endif  // owner-drawn menus
+#endif // wxUSE_OWNER_DRAWN
+
     return FALSE;
 }
 
@@ -4645,7 +4722,8 @@ bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam,
                                                               : SB_VERT,
                                   &scrollInfo) )
             {
-                wxLogLastError(_T("GetScrollInfo"));
+                // Not neccessarily an error, if there are no scrollbars yet.
+                // wxLogLastError(_T("GetScrollInfo"));
             }
 
             event.SetPosition(scrollInfo.nTrackPos);