]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
Also set GTK text direction to m_wxwindow.
[wxWidgets.git] / src / msw / window.cpp
index 2d079a591868df7edab64df68b8668a6b469101d..bd227b7ed35ab07fe7f42e7a1a19512c9a2903d6 100644 (file)
@@ -28,6 +28,8 @@
 
 #ifndef WX_PRECOMP
     #include "wx/msw/wrapwin.h"
+    #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
+    #include "wx/msw/missing.h"
     #include "wx/accel.h"
     #include "wx/menu.h"
     #include "wx/dc.h"
@@ -48,6 +50,7 @@
     #include "wx/log.h"
     #include "wx/textctrl.h"
     #include "wx/menuitem.h"
+    #include "wx/module.h"
 #endif
 
 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
@@ -55,7 +58,6 @@
 #endif
 
 #include "wx/evtloop.h"
-#include "wx/module.h"
 #include "wx/power.h"
 #include "wx/sysopt.h"
 
     #include <windowsx.h>
 #endif
 
-// include <commctrl.h> "properly"
-#include "wx/msw/wrapcctl.h"
-
-#ifndef __WXWINCE__
+#if !defined __WXWINCE__ && !defined NEED_PBT_H
     #include <pbt.h>
 #endif
 
-#include "wx/msw/missing.h"
-
 #if defined(__WXWINCE__)
     #include "wx/msw/wince/missing.h"
 #ifdef __POCKETPC__
@@ -829,7 +826,7 @@ void wxWindowMSW::MSWUpdateUIState(int action, int state)
     if ( s_needToUpdate == -1 )
     {
         int verMaj, verMin;
-        s_needToUpdate = wxGetOsVersion(&verMaj, &verMin) == wxWINDOWS_NT &&
+        s_needToUpdate = wxGetOsVersion(&verMaj, &verMin) == wxOS_WINDOWS_NT &&
                             verMaj >= 5;
     }
 
@@ -1018,6 +1015,67 @@ bool wxWindowMSW::ScrollPages(int pages)
                             down ? pages : -pages);
 }
 
+// ----------------------------------------------------------------------------
+// RTL support
+// ----------------------------------------------------------------------------
+
+void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir)
+{
+#ifdef __WXWINCE__
+    wxUnusedVar(dir);
+#else
+    const HWND hwnd = GetHwnd();
+    wxCHECK_RET( hwnd, _T("layout direction must be set after window creation") );
+
+    LONG styleOld = ::GetWindowLong(hwnd, GWL_EXSTYLE);
+
+    LONG styleNew = styleOld;
+    switch ( dir )
+    {
+        case wxLayout_LeftToRight:
+            styleNew &= ~WS_EX_LAYOUTRTL;
+            break;
+
+        case wxLayout_RightToLeft:
+            styleNew |= WS_EX_LAYOUTRTL;
+            break;
+
+        default:
+            wxFAIL_MSG(_T("unsupported layout direction"));
+            break;
+    }
+
+    if ( styleNew != styleOld )
+    {
+        ::SetWindowLong(hwnd, GWL_EXSTYLE, styleNew);
+    }
+#endif
+}
+
+wxLayoutDirection wxWindowMSW::GetLayoutDirection() const
+{
+#ifdef __WXWINCE__
+    return wxLayout_Default;
+#else
+    const HWND hwnd = GetHwnd();
+    wxCHECK_MSG( hwnd, wxLayout_Default, _T("invalid window") );
+
+    return ::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL
+                ? wxLayout_RightToLeft
+                : wxLayout_LeftToRight;
+#endif
+}
+
+wxCoord
+wxWindowMSW::AdjustForLayoutDirection(wxCoord x,
+                                      wxCoord WXUNUSED(width),
+                                      wxCoord WXUNUSED(widthTotal)) const
+{
+    // Win32 mirrors the coordinates of RTL windows automatically, so don't
+    // redo it ourselves
+    return x;
+}
+
 // ---------------------------------------------------------------------------
 // subclassing
 // ---------------------------------------------------------------------------
@@ -2119,13 +2177,15 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                         if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown )
                         {
                             // control wants to process Enter itself, don't
-                            // call IsDialogMessage() which would interpret
-                            // it
+                            // call IsDialogMessage() which would consume it
                             return false;
                         }
 
+#if wxUSE_BUTTON
                         // currently active button should get enter press even
-                        // if there is a default button elsewhere
+                        // if there is a default button elsewhere so check if
+                        // this window is a button first
+                        wxWindow *btn = NULL;
                         if ( lDlgCode & DLGC_DEFPUSHBUTTON )
                         {
                             // let IsDialogMessage() handle this for all
@@ -2135,59 +2195,38 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                             if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
                             {
                                 // emulate the button click
-                                wxWindow *
-                                    btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
-                                if ( btn )
-                                    btn->MSWCommand(BN_CLICKED, 0 /* unused */);
+                                btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
                             }
 
                             bProcess = false;
                         }
-                        else // not a button itself
+                        else // not a button itself, do we have default button?
                         {
-#if wxUSE_BUTTON
-                            wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                            wxTopLevelWindow *
+                                tlw = wxDynamicCast(wxGetTopLevelParent(this),
+                                                    wxTopLevelWindow);
                             if ( tlw )
                             {
-                                wxButton *btn = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
-                                if ( btn && btn->IsEnabled() )
-                                {
-                                    // if we do have a default button, do press it
-                                    btn->MSWCommand(BN_CLICKED, 0 /* unused */);
-
-                                    return true;
-                                }
+                                btn = wxDynamicCast(tlw->GetDefaultItem(),
+                                                    wxButton);
                             }
-                            else // no default button
+                        }
+
+                        if ( btn && btn->IsEnabled() )
+                        {
+                            btn->MSWCommand(BN_CLICKED, 0 /* unused */);
+                            return true;
+                        }
+
 #endif // wxUSE_BUTTON
-                            {
+
 #ifdef __WXWINCE__
-                                wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN);
-                                event.SetEventObject(this);
-                                if(GetEventHandler()->ProcessEvent(event))
-                                    return true;
-#endif
-                                // this is a quick and dirty test for a text
-                                // control
-                                if ( !(lDlgCode & DLGC_HASSETSEL) )
-                                {
-                                    // don't process Enter, the control might
-                                    // need it for itself and don't let
-                                    // ::IsDialogMessage() have it as it can
-                                    // eat the Enter events sometimes
-                                    return false;
-                                }
-                                else if (!IsTopLevel())
-                                {
-                                    // if not a top level window, let parent
-                                    // handle it
-                                    return false;
-                                }
-                                //else: treat Enter as TAB: pass to the next
-                                //      control as this is the best thing to do
-                                //      if the text doesn't handle Enter itself
-                            }
-                        }
+                        // map Enter presses into button presses on PDAs
+                        wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN);
+                        event.SetEventObject(this);
+                        if ( GetEventHandler()->ProcessEvent(event) )
+                            return true;
+#endif // __WXWINCE__
                     }
                     break;
 
@@ -4107,12 +4146,11 @@ bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange)
 
 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture)
 {
-    wxWindow *win = wxFindWinFromHandle(hWndGainedCapture);
-
     // notify windows on the capture stack about lost capture
     // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
-    wxWindowBase::NotifyCaptureLost(win);
+    wxWindowBase::NotifyCaptureLost();
 
+    wxWindow *win = wxFindWinFromHandle(hWndGainedCapture);
     wxMouseCaptureChangedEvent event(GetId(), win);
     event.SetEventObject(this);
     return GetEventHandler()->ProcessEvent(event);