]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxWindow::GetWindowBorderSize()
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 25 Nov 2006 14:52:52 +0000 (14:52 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 25 Nov 2006 14:52:52 +0000 (14:52 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43639 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/window.tex
include/wx/window.h
src/common/wincmn.cpp

index 0df9ac310d74ffc834dc4d70d12eee32718db537..cc3f221ea84b4518db7af3059c6d24b9cac762e5 100644 (file)
@@ -1373,6 +1373,14 @@ that size.
 \helpref{GetClientSize}{wxwindowgetclientsize}
 
 
+\membersection{wxWindow::GetWindowBorderSize}\label{wxwindowgetwindowbordersize}
+
+\constfunc{wxSize}{GetWindowBorderSize}{\void}
+
+Returns the size of the left/right and top/bottom borders of this window in x
+and y components of the result respectively.
+
+
 \membersection{wxWindow::GetWindowStyleFlag}\label{wxwindowgetwindowstyleflag}
 
 \constfunc{long}{GetWindowStyleFlag}{\void}
index 5a098ee0f31f4ea9d850f2e1ec7b6c6658ad423c..acff5abc8e9a37a9c26493e1ceaf242a6d46bba5 100644 (file)
@@ -473,6 +473,11 @@ public:
         return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) );
     }
 
+    // return the size of the left/right and top/bottom borders in x and y
+    // components of the result respectively
+    virtual wxSize GetWindowBorderSize() const;
+
+
     // window state
     // ------------
 
index d597dd9c2208e2f0516f344183bfe046e4683cf7..5a5ca178914f6a72d8c19a007a1d8bb8c2fabd54 100644 (file)
@@ -587,6 +587,76 @@ wxSize wxWindowBase::DoGetBestSize() const
     return best;
 }
 
+// helper of GetWindowBorderSize(): as many ports don't implement support for
+// wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
+// fallbacks in this case
+static wxGetMetricOrDefault(wxSystemMetric what)
+{
+    int rc = wxSystemSettings::GetMetric(what);
+    if ( rc == -1 )
+    {
+        switch ( what )
+        {
+            case wxSYS_BORDER_X:
+            case wxSYS_BORDER_Y:
+                // 2D border is by default 1 pixel wide
+                rc = 1;
+                break;
+
+            case wxSYS_EDGE_X:
+            case wxSYS_EDGE_Y:
+                // 3D borders are by default 2 pixels
+                rc = 2;
+                break;
+
+            default:
+                wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
+                rc = 0;
+        }
+    }
+
+    return rc;
+}
+
+wxSize wxWindowBase::GetWindowBorderSize() const
+{
+    wxSize size;
+
+    switch ( GetBorder() )
+    {
+        case wxBORDER_NONE:
+            // nothing to do, size is already (0, 0)
+            break;
+
+        case wxBORDER_SIMPLE:
+        case wxBORDER_STATIC:
+            size.x = wxGetMetricOrDefault(wxSYS_BORDER_X);
+            size.y = wxGetMetricOrDefault(wxSYS_BORDER_Y);
+            break;
+
+        case wxBORDER_SUNKEN:
+        case wxBORDER_RAISED:
+            size.x = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X),
+                           wxGetMetricOrDefault(wxSYS_BORDER_X));
+            size.y = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y),
+                           wxGetMetricOrDefault(wxSYS_BORDER_Y));
+            break;
+
+        case wxBORDER_DOUBLE:
+            size.x = wxGetMetricOrDefault(wxSYS_EDGE_X) +
+                        wxGetMetricOrDefault(wxSYS_BORDER_X);
+            size.y = wxGetMetricOrDefault(wxSYS_EDGE_Y) +
+                        wxGetMetricOrDefault(wxSYS_BORDER_Y);
+            break;
+
+        default:
+            wxFAIL_MSG(_T("Unknown border style."));
+            break;
+    }
+
+    // we have borders on both sides
+    return size*2;
+}
 
 wxSize wxWindowBase::GetEffectiveMinSize() const
 {