]> git.saurik.com Git - wxWidgets.git/commitdiff
wxTextEntry::SetMargins(), GetMargins() - implemented on wxMSW and wxGTK (GTK+ 2...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 5 Sep 2009 12:39:12 +0000 (12:39 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 5 Sep 2009 12:39:12 +0000 (12:39 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61834 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

20 files changed:
include/wx/combo.h
include/wx/gtk/combobox.h
include/wx/gtk/textctrl.h
include/wx/gtk/textentry.h
include/wx/msw/textentry.h
include/wx/propgrid/propgriddefs.h
include/wx/richtext/richtextctrl.h
include/wx/textentry.h
interface/wx/combo.h
interface/wx/textentry.h
src/common/combocmn.cpp
src/common/textentrycmn.cpp
src/generic/combog.cpp
src/generic/odcombo.cpp
src/gtk/textctrl.cpp
src/gtk/textentry.cpp
src/msw/combo.cpp
src/msw/textentry.cpp
src/propgrid/editors.cpp
src/propgrid/propgrid.cpp

index a4ae62396ca379277d4ce9ee2d7d138a46fd52dc..9a9ed7883bcb4c4126e5f9387c27722d77bef857 100644 (file)
@@ -86,8 +86,8 @@ enum
     wxCC_IFLAG_CREATED              = 0x0100,
     // Internal use: really put button outside
     wxCC_IFLAG_BUTTON_OUTSIDE       = 0x0200,
-    // Internal use: SetTextIndent has been called
-    wxCC_IFLAG_INDENT_SET           = 0x0400,
+    // Internal use: SetMargins has been succesfully called
+    wxCC_IFLAG_LEFT_MARGIN_SET      = 0x0400,
     // Internal use: Set wxTAB_TRAVERSAL to parent when popup is dismissed
     wxCC_IFLAG_PARENT_TAB_TRAVERSAL = 0x0800,
     // Internal use: Secondary popup window type should be used (if available).
@@ -118,7 +118,8 @@ struct wxComboCtrlFeatures
         BitmapButton        = 0x0002, // Button may be replaced with bitmap
         ButtonSpacing       = 0x0004, // Button can have spacing from the edge
                                       // of the control
-        TextIndent          = 0x0008, // SetTextIndent can be used
+        TextIndent          = 0x0008, // SetMargins can be used to control
+                                      // left margin.
         PaintControl        = 0x0010, // Combo control itself can be custom painted
         PaintWritable       = 0x0020, // A variable-width area in front of writable
                                       // combo control's textctrl can be custom
@@ -302,19 +303,18 @@ public:
                            const wxBitmap& bmpHover = wxNullBitmap,
                            const wxBitmap& bmpDisabled = wxNullBitmap );
 
+#if WXWIN_COMPATIBILITY_2_6
     //
     // This will set the space in pixels between left edge of the control and the
     // text, regardless whether control is read-only (ie. no wxTextCtrl) or not.
     // Platform-specific default can be set with value-1.
     // Remarks
     // * This method may do nothing on some native implementations.
-    void SetTextIndent( int indent );
+    wxDEPRECTED( void SetTextIndent( int indent ) );
 
     // Returns actual indentation in pixels.
-    wxCoord GetTextIndent() const
-    {
-        return m_absIndent;
-    }
+    wxDEPRECTED( wxCoord GetTextIndent() const );
+#endif
 
     // Returns area covered by the text field.
     const wxRect& GetTextRect() const
@@ -385,6 +385,17 @@ public:
     const wxBitmap& GetBitmapHover() const { return m_bmpHover; }
     const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; }
 
+    // Margins functions mirrored from TextEntryBase
+    // (wxComboCtrl does not inherit from wxTextEntry, but may embed a
+    // wxTextCtrl, so we need these). Also note that these functions
+    // have replaced SetTextIndent() in wxWidgets 2.9.1 and later.
+    bool SetMargins(const wxPoint& pt)
+        { return DoSetMargins(pt); }
+    bool SetMargins(wxCoord left, wxCoord top = -1)
+        { return DoSetMargins(wxPoint(left, top)); }
+    wxPoint GetMargins() const
+        { return DoGetMargins(); }
+
     // Return internal flags
     wxUint32 GetInternalFlags() const { return m_iFlags; }
 
@@ -423,7 +434,8 @@ protected:
     // called from wxSizeEvent handler
     virtual void OnResize() = 0;
 
-    // Return native text identation (for pure text, not textctrl)
+    // Return native text identation
+    // (i.e. text margin, for pure text, not textctrl)
     virtual wxCoord GetNativeTextIndent() const;
 
     // Called in syscolourchanged handler and base create
@@ -521,6 +533,10 @@ protected:
     virtual void DoSetToolTip( wxToolTip *tip );
 #endif
 
+    // margins functions
+    virtual bool DoSetMargins(const wxPoint& pt);
+    virtual wxPoint DoGetMargins() const;
+
     // This is used when m_text is hidden (readonly).
     wxString                m_valueString;
 
@@ -572,8 +588,8 @@ protected:
     // selection indicator.
     wxCoord                 m_widthCustomPaint;
 
-    // absolute text indentation, in pixels
-    wxCoord                 m_absIndent;
+    // left margin, in pixels
+    wxCoord                 m_marginLeft;
 
     // side on which the popup is aligned
     int                     m_anchorSide;
index d715d1dae889bf79cd6fcdcd0825173c701e4f6f..39543f8baad99b0a129b9d9976054080d79ee17a 100644 (file)
@@ -135,8 +135,8 @@ protected:
     // custom list stores.
     virtual void GTKCreateComboBoxWidget();
 
-    // return the GtkEntry part of the combobox
-    GtkEntry *GetEntry() const { return m_entry; }
+    virtual GtkEntry *GetEntry() const
+        { return m_entry; }
 
     GtkEntry*   m_entry;
 
index a4371c7c98f5dca3e056eb0282b4c9e99852b581..3da5188a2d5b4e17834c56469e274d9837098a80 100644 (file)
@@ -178,6 +178,7 @@ protected:
 private:
     // overridden wxTextEntry virtual methods
     virtual GtkEditable *GetEditable() const;
+    virtual GtkEntry *GetEntry() const;
     virtual void EnableTextChangedEvents(bool enable);
 
     // change the font for everything in this control
index deab5219c41ef59b79dad2251a4701d3788c1762..0af6c9a652a59de86ac24794b4b359372969f181 100644 (file)
@@ -12,6 +12,7 @@
 #define _WX_GTK_TEXTENTRY_H_
 
 typedef struct _GtkEditable GtkEditable;
+typedef struct _GtkEntry GtkEntry;
 
 // ----------------------------------------------------------------------------
 // wxTextEntry: roughly corresponds to GtkEditable
@@ -55,10 +56,17 @@ public:
 protected:
     virtual wxString DoGetValue() const;
 
+    // margins functions
+    virtual bool DoSetMargins(const wxPoint& pt);
+    virtual wxPoint DoGetMargins() const;
+
 private:
     // implement this to return the associated GtkEntry or another widget
     // implementing GtkEditable
     virtual GtkEditable *GetEditable() const = 0;
+
+    // implement this to return the associated GtkEntry
+    virtual GtkEntry *GetEntry() const = 0;
 };
 
 #endif // _WX_GTK_TEXTENTRY_H_
index ef5c4e201f0bb883e671733e6fa39d309ec36645..ade77243f2ce06ed6f2f70c460fc150007f81654 100644 (file)
@@ -76,6 +76,10 @@ protected:
     };
     virtual void DoSetSelection(long from, long to, int flags = SetSel_Scroll);
 
+    // margins functions
+    virtual bool DoSetMargins(const wxPoint& pt);
+    virtual wxPoint DoGetMargins() const;
+
 private:
     // implement this to return the HWND of the EDIT control
     virtual WXHWND GetEditHWND() const = 0;
index d29af13122cfca3a30f75487a0cee358bac1ab4b..d7180e71c8618cc1c396d5258d4438080c2c50da 100644 (file)
@@ -37,9 +37,6 @@
     // space between vertical line and value editor control
     #define wxPG_XBEFOREWIDGET          1
 
-    // x position adjustment for wxTextCtrl (and like)
-    #define wxPG_TEXTCTRLXADJUST        3
-
     // comment to use bitmap buttons
     #define wxPG_ICON_WIDTH             9
     // 1 if wxRendererNative should be employed
@@ -75,7 +72,9 @@
     #define wxPG_XBEFOREWIDGET          1
 
     // x position adjustment for wxTextCtrl (and like)
-    #define wxPG_TEXTCTRLXADJUST        3
+    // NB: Only define wxPG_TEXTCTRLXADJUST for platforms that do not
+    //     (yet) support wxTextEntry::SetMargins() for the left margin.
+    //#define wxPG_TEXTCTRLXADJUST        3
 
     // comment to use bitmap buttons
     #define wxPG_ICON_WIDTH             9
index a0ecffeacfecbb62ce473290c8a7fb62d063d565..aaef4dac28ebb2f9370e423d63e32cb8da7cc830 100644 (file)
@@ -783,6 +783,7 @@ protected:
 #ifdef __WXGTK20__
     virtual wxWindow *GetEditableWindow() { return this; }
     virtual GtkEditable *GetEditable() const { return NULL; }
+    virtual GtkEntry *GetEntry() const { return NULL; }
 #endif
 
 // Overrides
index cdf6e522a4622b2a321c8d4ab05306d5276d8152..e09014be6ffc8149d09d95276c0c8c48bd28ce2d 100644 (file)
@@ -142,6 +142,20 @@ public:
     virtual wxString GetHint() const;
 
 
+    // margins
+    // -------
+
+    // margins are the empty space between borders of control and the text
+    // itself. When setting margin, use value -1 to indicate that specific
+    // margin should not be changed.
+
+    bool SetMargins(const wxPoint& pt)
+        { return DoSetMargins(pt); }
+    bool SetMargins(wxCoord left, wxCoord top = -1)
+        { return DoSetMargins(wxPoint(left, top)); }
+    wxPoint GetMargins() const
+        { return DoGetMargins(); }
+
 protected:
     // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
     // also used to implement WriteText() in wxMSW
@@ -159,6 +173,10 @@ protected:
     // generation and also by generic hints implementation
     virtual wxWindow *GetEditableWindow() = 0;
 
+    // margins functions
+    virtual bool DoSetMargins(const wxPoint& pt);
+    virtual wxPoint DoGetMargins() const;
+
 
     // class which should be used to temporarily disable text change events
     //
index e5cb5c7dc7d9f0781f771bb87203178d6fcb3acc..12a4192eedc6324e20224b98dadc77c957e84ab8 100644 (file)
@@ -159,7 +159,7 @@ struct wxComboCtrlFeatures
         BitmapButton    = 0x0002, ///< Button may be replaced with bitmap.
         ButtonSpacing   = 0x0004, ///< Button can have spacing from the edge
                                   ///< of the control.
-        TextIndent      = 0x0008, ///< wxComboCtrl::SetTextIndent() can be used.
+        TextIndent      = 0x0008, ///< wxComboCtrl::SetMargins() can be used.
         PaintControl    = 0x0010, ///< Combo control itself can be custom painted.
         PaintWritable   = 0x0020, ///< A variable-width area in front of writable
                                   ///< combo control's textctrl can be custom
@@ -454,6 +454,19 @@ public:
     */
     virtual long GetLastPosition() const;
 
+    /**
+        Returns the margins used by the control. The @c x field of the returned
+        point is the horizontal margin and the @c y field is the vertical one.
+
+        @remarks If given margin cannot be accurately determined, its value
+                will be set to -1.
+
+        @see SetMargins()
+
+        @since 2.9.1
+    */
+    wxPoint GetMargins() const;
+
     /**
         Returns current popup interface that has been set with
         SetPopupControl().
@@ -472,6 +485,8 @@ public:
 
     /**
         Returns actual indentation in pixels.
+
+        @deprecated Use GetMargins() instead.
     */
     wxCoord GetTextIndent() const;
 
@@ -607,6 +622,21 @@ public:
     */
     virtual void SetInsertionPointEnd();
 
+    //@{
+    /**
+        Attempts to set the control margins. When margins are given as wxPoint,
+        x indicates the left and y the top margin. Use -1 to indicate that
+        an existing value should be used.
+
+        @return
+            @true if setting of all requested margins was successful.
+
+        @since 2.9.1
+    */
+    bool SetMargins(const wxPoint& pt);
+    bool SetMargins(wxCoord left, wxCoord top = -1);
+    //@}
+
     /**
         Set side of the control to which the popup will align itself. Valid
         values are @c wxLEFT, @c wxRIGHT and 0. The default value 0 means that
@@ -676,6 +706,8 @@ public:
         This will set the space in pixels between left edge of the control and
         the text, regardless whether control is read-only or not. Value -1 can
         be given to indicate platform default.
+
+        @deprecated Use SetMargins() instead.
     */
     void SetTextIndent(int indent);
 
index bec4b6a9285dac45a7094eefb8b8eaf3ea25f3c7..bdbf7f28e250de388957e111d71c204588d38a78 100644 (file)
@@ -381,6 +381,35 @@ public:
      */
     virtual wxString GetHint() const;
 
+    //@{
+    /**
+        Attempts to set the control margins. When margins are given as wxPoint,
+        x indicates the left and y the top margin. Use -1 to indicate that
+        an existing value should be used.
+
+        @return
+            @true if setting of all requested margins was successful.
+
+        @since 2.9.1
+    */
+    bool SetMargins(const wxPoint& pt);
+    bool SetMargins(wxCoord left, wxCoord top = -1);
+    //@}
+
+    /**
+        Returns the margins used by the control. The @c x field of the returned
+        point is the horizontal margin and the @c y field is the vertical one.
+
+        @remarks If given margin cannot be accurately determined, its value
+                will be set to -1. On some platforms you cannot obtain valid
+                margin values until you have called SetMargins().
+
+        @see SetMargins()
+
+        @since 2.9.1
+    */
+    wxPoint GetMargins() const;
+
     /**
         Sets the new text control value.
 
index 17b6a376639c6a4a1c0dff1728523b20f9aa3180..e51c47e9fce187966366e6e0ba87983c8f6332b0 100644 (file)
 #define TEXTCTRL_TEXT_CENTERED        0 // 1 if text in textctrl is vertically centered
 #define FOCUS_RING                    0 // No focus ring on wxMSW
 
+#if !defined(__WXWINCE__)
+    // 1 if wxTextEntry::SetMargins() can be used to set the left margin
+    #define LEFT_MARGIN_CAN_BE_SET        1
+#else
+    #define LEFT_MARGIN_CAN_BE_SET        0
+#endif
+
 //#undef wxUSE_POPUPWIN
 //#define wxUSE_POPUPWIN 0
 
 #elif defined(__WXGTK__)
 
+#include "wx/gtk/private.h"
+
 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
 //     this bug: If wxDialog is hidden, its position becomes corrupt
 //     between hide and next show, but without internal coordinates being
 #define TEXTCTRL_TEXT_CENTERED        1 // 1 if text in textctrl is vertically centered
 #define FOCUS_RING                    0 // No focus ring on wxGTK
 
+#if GTK_CHECK_VERSION(2,10,0)
+    // 1 if wxTextEntry::SetMargins() can be used to set the left margin
+    #define LEFT_MARGIN_CAN_BE_SET    1
+#else
+    #define LEFT_MARGIN_CAN_BE_SET    0
+#endif
+
 #elif defined(__WXMAC__)
 
 #define USE_TRANSIENT_POPUP           1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
 #undef COMBO_MARGIN
 #define COMBO_MARGIN                  FOCUS_RING
 
+// 1 if wxTextEntry::SetMargins() can be used to set the left margin
+#define LEFT_MARGIN_CAN_BE_SET        0
+
 #else
 
 #define USE_TRANSIENT_POPUP           0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
 #define TEXTCTRL_TEXT_CENTERED        1 // 1 if text in textctrl is vertically centered
 #define FOCUS_RING                    0
 
+// 1 if wxTextEntry::SetMargins() can be used to set the left margin
+#define LEFT_MARGIN_CAN_BE_SET        0
+
 #endif
 
 
@@ -519,7 +541,7 @@ void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo,
         combo->PrepareBackground(dc,rect,0);
 
         dc.DrawText( combo->GetValue(),
-                     rect.x + combo->GetTextIndent(),
+                     rect.x + combo->m_marginLeft,
                      (rect.height-dc.GetCharHeight())/2 + rect.y );
     }
 }
@@ -804,7 +826,7 @@ void wxComboCtrlBase::Init()
 
     m_extLeft = 0;
     m_extRight = 0;
-    m_absIndent = -1;
+    m_marginLeft = -1;
     m_iFlags = 0;
     m_timeCanAcceptClick = 0;
 
@@ -833,7 +855,7 @@ bool wxComboCtrlBase::Create(wxWindow *parent,
 
     // Get colours
     OnThemeChange();
-    m_absIndent = GetNativeTextIndent();
+    m_marginLeft = GetNativeTextIndent();
 
     m_iFlags |= wxCC_IFLAG_CREATED;
 
@@ -953,8 +975,8 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth )
     }
 
     // Defaul indentation
-    if ( m_absIndent < 0 )
-        m_absIndent = GetNativeTextIndent();
+    if ( m_marginLeft < 0 )
+        m_marginLeft = GetNativeTextIndent();
 
     int butWidth = btnWidth;
 
@@ -1058,43 +1080,54 @@ void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust
     if ( !m_text )
         return;
 
-#if !TEXTCTRL_TEXT_CENTERED
-
     wxSize sz = GetClientSize();
 
     int customBorder = m_widthCustomBorder;
     if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
     {
+#if LEFT_MARGIN_CAN_BE_SET
+        // Call SetMargins() on textctrl if LEFT_MARGIN_CAN_BE_SET == 1
+        wxUnusedVar(textCtrlXAdjust);
+        m_text->SetMargins(0);
+        textCtrlXAdjust = 0;
+#endif
+
         // Centre textctrl
+#if !TEXTCTRL_TEXT_CENTERED
         int tcSizeY = m_text->GetBestSize().y;
-        int diff = sz.y - tcSizeY;
-        int y = textCtrlYAdjust + (diff/2);
+        int diff0 = sz.y - tcSizeY;
+        int y = textCtrlYAdjust + (diff0/2);
+#else
+        wxUnusedVar(textCtrlYAdjust);
+        int y = 0;
+#endif
 
         if ( y < customBorder )
             y = customBorder;
 
-        m_text->SetSize( m_tcArea.x + m_widthCustomPaint + m_absIndent + textCtrlXAdjust,
-                         y,
-                         m_tcArea.width - COMBO_MARGIN -
-                         (textCtrlXAdjust + m_widthCustomPaint + m_absIndent),
-                         -1 );
+        int x = m_tcArea.x + m_widthCustomPaint + 
+                m_marginLeft + textCtrlXAdjust;
+
+        m_text->SetSize(x,
+                        y,
+                        m_tcArea.width - m_tcArea.x - x,
+                        /*m_tcArea.width - COMBO_MARGIN -
+                        (textCtrlXAdjust + m_widthCustomPaint +
+                         m_marginLeft),*/
+                        -1 );
 
         // Make sure textctrl doesn't exceed the bottom custom border
         wxSize tsz = m_text->GetSize();
-        diff = (y + tsz.y) - (sz.y - customBorder);
-        if ( diff >= 0 )
+        int diff1 = (y + tsz.y) - (sz.y - customBorder);
+        if ( diff1 >= 0 )
         {
-            tsz.y = tsz.y - diff - 1;
+            tsz.y = tsz.y - diff1 - 1;
             m_text->SetSize(tsz);
         }
     }
     else
-#else // TEXTCTRL_TEXT_CENTERED
-    wxUnusedVar(textCtrlXAdjust);
-    wxUnusedVar(textCtrlYAdjust);
-#endif // !TEXTCTRL_TEXT_CENTERED/TEXTCTRL_TEXT_CENTERED
     {
-        // If it has border, have textctrl will the entire text field.
+        // If it has border, have textctrl fill the entire text field.
         m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
                          m_tcArea.y,
                          m_tcArea.width - m_widthCustomPaint,
@@ -1729,9 +1762,9 @@ void wxComboCtrlBase::OnIdleEvent( wxIdleEvent& WXUNUSED(event) )
 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
 {
     OnThemeChange();
-    // indentation may also have changed
-    if ( !(m_iFlags & wxCC_IFLAG_INDENT_SET) )
-        m_absIndent = GetNativeTextIndent();
+    // left margin may also have changed
+    if ( !(m_iFlags & wxCC_IFLAG_LEFT_MARGIN_SET) )
+        m_marginLeft = GetNativeTextIndent();
     RecalcAndRefresh();
 }
 
@@ -2217,22 +2250,61 @@ void wxComboCtrlBase::SetCustomPaintWidth( int width )
     RecalcAndRefresh();
 }
 
+bool wxComboCtrlBase::DoSetMargins(const wxPoint& margins)
+{
+    // For general sanity's sake, we ignore top margin. Instead
+    // we will always try to center the text vertically.
+    bool res = true;
+
+    if ( margins.x != -1 )
+    {
+        m_marginLeft = margins.x;
+        m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
+    }
+    else
+    {
+        m_marginLeft = GetNativeTextIndent();
+        m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
+    }
+
+    if ( margins.y != -1 )
+    {
+        res = false;
+    }
+
+    RecalcAndRefresh();
+
+    return res;
+}
+
+wxPoint wxComboCtrlBase::DoGetMargins() const
+{
+    return wxPoint(m_marginLeft, -1);
+}
+
+#if WXWIN_COMPATIBILITY_2_6
 void wxComboCtrlBase::SetTextIndent( int indent )
 {
     if ( indent < 0 )
     {
-        m_absIndent = GetNativeTextIndent();
-        m_iFlags &= ~(wxCC_IFLAG_INDENT_SET);
+        m_marginLeft = GetNativeTextIndent();
+        m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
     }
     else
     {
-        m_absIndent = indent;
-        m_iFlags |= wxCC_IFLAG_INDENT_SET;
+        m_marginLeft = indent;
+        m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
     }
 
     RecalcAndRefresh();
 }
 
+wxCoord wxComboCtrlBase::GetTextIndent() const;
+{
+    return m_marginLeft;
+}
+#endif
+
 wxCoord wxComboCtrlBase::GetNativeTextIndent() const
 {
     return DEFAULT_TEXT_INDENT;
index cb81ea0779d33bd4f3d61077ae475936fbdb5824..f7b11237efa7ac13f6e86940e4627f3e19557e0b 100644 (file)
@@ -265,4 +265,18 @@ wxString wxTextEntryBase::GetHint() const
     return m_hintData ? m_hintData->GetHintString() : wxString();
 }
 
+// ----------------------------------------------------------------------------
+// margins support
+// ----------------------------------------------------------------------------
+
+bool wxTextEntryBase::DoSetMargins(const wxPoint& WXUNUSED(pt))
+{
+    return false;
+}
+
+wxPoint wxTextEntryBase::DoGetMargins() const
+{
+    return wxPoint(-1, -1);
+}
+
 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX
index 3c07f3da368041d12b63b04cf909f72d1ea735c1..ef4d47169edd647f1c461c6039bfa848504259ea 100644 (file)
 
 #if defined(__WXUNIVERSAL__)
 
-#define TEXTCTRLXADJUST                 0 // position adjustment for wxTextCtrl, with zero indent
+// position adjustment for wxTextCtrl, to achieve zero left margin
+// meaningless if LEFT_MARGIN_CAN_BE_SET set to 1 in combocmn.cpp
+#define TEXTCTRLXADJUST                 0
+
 #define TEXTCTRLYADJUST                 0
 #define TEXTXADJUST                     0 // how much is read-only text's x adjusted
 #define DEFAULT_DROPBUTTON_WIDTH        19
 
 #elif defined(__WXMSW__)
 
-#define TEXTCTRLXADJUST                 2 // position adjustment for wxTextCtrl, with zero indent
+// position adjustment for wxTextCtrl, to achieve zero left margin
+// meaningless if LEFT_MARGIN_CAN_BE_SET set to 1 in combocmn.cpp
+#define TEXTCTRLXADJUST                 2
+
 #define TEXTCTRLYADJUST                 3
 #define TEXTXADJUST                     0 // how much is read-only text's x adjusted
 #define DEFAULT_DROPBUTTON_WIDTH        17
 
 #elif defined(__WXGTK__)
 
-#define TEXTCTRLXADJUST                 -1 // position adjustment for wxTextCtrl, with zero indent
+// position adjustment for wxTextCtrl, to achieve zero left margin
+// meaningless if LEFT_MARGIN_CAN_BE_SET set to 1 in combocmn.cpp
+#define TEXTCTRLXADJUST                 -1
+
 #define TEXTCTRLYADJUST                 0
 #define TEXTXADJUST                     1 // how much is read-only text's x adjusted
 #define DEFAULT_DROPBUTTON_WIDTH        23
 
 #elif defined(__WXMAC__)
 
-#define TEXTCTRLXADJUST                 0 // position adjustment for wxTextCtrl, with zero indent
+// position adjustment for wxTextCtrl, to achieve zero left margin
+// meaningless if LEFT_MARGIN_CAN_BE_SET set to 1 in combocmn.cpp
+#define TEXTCTRLXADJUST                 0
+
 #define TEXTCTRLYADJUST                 0
 #define TEXTXADJUST                     0 // how much is read-only text's x adjusted
 #define DEFAULT_DROPBUTTON_WIDTH        22
 
 #else
 
-#define TEXTCTRLXADJUST                 0 // position adjustment for wxTextCtrl, with zero indent
+// position adjustment for wxTextCtrl, to achieve zero left margin
+// meaningless if LEFT_MARGIN_CAN_BE_SET set to 1 in combocmn.cpp
+#define TEXTCTRLXADJUST                 0
+
 #define TEXTCTRLYADJUST                 0
 #define TEXTXADJUST                     0 // how much is read-only text's x adjusted
 #define DEFAULT_DROPBUTTON_WIDTH        19
index 8321e400d12be99f383f2a170c5fde1828d0b44b..1d912e19c0a44f17467cc22fb0aa06041f4c591a 100644 (file)
@@ -1085,7 +1085,7 @@ void wxOwnerDrawnComboBox::OnDrawItem( wxDC& dc,
     if ( flags & wxODCB_PAINTING_CONTROL )
     {
         dc.DrawText( GetValue(),
-                     rect.x + GetTextIndent(),
+                     rect.x + GetMargins().x,
                      (rect.height-dc.GetCharHeight())/2 + rect.y );
     }
     else
index 81a1502eb483b3a0e268d98d0b1c3b89cf237278..167cfcb38a8dc2003323ca3f7ce389a83b2b900f 100644 (file)
@@ -818,6 +818,11 @@ GtkEditable *wxTextCtrl::GetEditable() const
     return GTK_EDITABLE(m_text);
 }
 
+GtkEntry *wxTextCtrl::GetEntry() const
+{
+    return GTK_ENTRY(m_text);
+}
+
 // ----------------------------------------------------------------------------
 // flags handling
 // ----------------------------------------------------------------------------
index 1e0bd5238948e32d55f240361ae77608bd5735d8..7b49e1150d3a8a3447a1ca130b65b76d59d4ce90 100644 (file)
@@ -326,4 +326,74 @@ void wxTextEntry::SendMaxLenEvent()
     win->HandleWindowEvent(event);
 }
 
+// ----------------------------------------------------------------------------
+// margins support
+// ----------------------------------------------------------------------------
+
+bool wxTextEntry::DoSetMargins(const wxPoint& margins)
+{
+#if GTK_CHECK_VERSION(2,10,0)
+    GtkEntry* entry = GetEntry();
+
+    if ( !entry )
+        return false;
+
+    const GtkBorder* oldBorder = gtk_entry_get_inner_border(entry);
+    GtkBorder* newBorder;
+
+    if ( oldBorder )
+    {
+        newBorder = gtk_border_copy(oldBorder);
+    }
+    else
+    {
+    #if GTK_CHECK_VERSION(2,14,0)
+        newBorder = gtk_border_new();
+    #else
+        newBorder = new GtkBorder;
+    #endif
+        // Use some reasonable defaults for initial margins
+        newBorder->left = 2;
+        newBorder->right = 2;
+
+        // These numbers seem to let the text remain vertically centered
+        // in common use scenarios when margins.y == -1.
+        newBorder->top = 3;
+        newBorder->bottom = 3;
+    }
+
+    if ( margins.x != -1 )
+        newBorder->left = (gint) margins.x;
+
+    if ( margins.y != -1 )
+        newBorder->top = (gint) margins.y;
+
+    gtk_entry_set_inner_border(entry, newBorder);
+
+    return true;
+#else
+    wxUnusedVar(margins);
+    return false;
+#endif
+}
+
+wxPoint wxTextEntry::DoGetMargins() const
+{
+#if GTK_CHECK_VERSION(2,10,0)
+    GtkEntry* entry = GetEntry();
+
+    if ( !entry )
+        return wxPoint(-1, -1);
+
+    const GtkBorder* border = gtk_entry_get_inner_border(entry);
+
+    if ( !border )
+        return wxPoint(-1, -1);
+
+    return wxPoint((wxCoord) border->left, (wxCoord) border->top);
+#else
+    return wxPoint(-1, -1);
+#endif
+}
+
 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX
index 9ee04ced0af1a27a9e929957a0be4e4a1d421260..f0c621d54df859c0d1453d1099afc8e113db3bae 100644 (file)
 #define NATIVE_TEXT_INDENT_XP       4
 #define NATIVE_TEXT_INDENT_CLASSIC  2
 
-#define TEXTCTRLXADJUST_XP          1
 #define TEXTCTRLYADJUST_XP          3
-#define TEXTCTRLXADJUST_CLASSIC     1
 #define TEXTCTRLYADJUST_CLASSIC     3
 
 #define COMBOBOX_ANIMATION_RESOLUTION   10
@@ -264,19 +262,16 @@ void wxComboCtrl::OnResize()
     //
     // Recalculates button and textctrl areas
 
-    int textCtrlXAdjust;
     int textCtrlYAdjust;
 
 #if wxUSE_UXTHEME
     if ( wxUxThemeEngine::GetIfActive() )
     {
-        textCtrlXAdjust = TEXTCTRLXADJUST_XP;
         textCtrlYAdjust = TEXTCTRLYADJUST_XP;
     }
     else
 #endif
     {
-        textCtrlXAdjust = TEXTCTRLXADJUST_CLASSIC;
         textCtrlYAdjust = TEXTCTRLYADJUST_CLASSIC;
     }
 
@@ -286,7 +281,7 @@ void wxComboCtrl::OnResize()
     CalculateAreas(btnWidth);
 
     // Position textctrl using standard routine
-    PositionTextCtrl(textCtrlXAdjust,textCtrlYAdjust);
+    PositionTextCtrl(0, textCtrlYAdjust);
 }
 
 // Draws non-XP GUI dotted line around the focus area
index 672058b8fd306d4db2797f909bff61c4be599869..eb53b98d0d9785322f306d69613a343c4f570223 100644 (file)
@@ -474,4 +474,44 @@ wxString wxTextEntry::GetHint() const
 
 #endif // wxUSE_UXTHEME
 
+// ----------------------------------------------------------------------------
+// margins support
+// ----------------------------------------------------------------------------
+
+bool wxTextEntry::DoSetMargins(const wxPoint& margins)
+{
+#if !defined(__WXWINCE__)
+    bool res = true;
+
+    if ( margins.x != -1 )
+    {
+        // left margin
+        ::SendMessage(GetEditHwnd(), EM_SETMARGINS,
+                      EC_LEFTMARGIN, MAKELONG(margins.x, 0));
+    }
+
+    if ( margins.y != -1 )
+    {
+        res = false;
+    }
+
+    return res;
+#else
+    return false;
+#endif
+}
+
+wxPoint wxTextEntry::DoGetMargins() const
+{
+#if !defined(__WXWINCE__)
+    LRESULT lResult = ::SendMessage(GetEditHwnd(), EM_GETMARGINS,
+                                    0, 0);
+    int left = LOWORD(lResult);
+    int top = -1;
+    return wxPoint(left, top);
+#else
+    return wxPoint(-1, -1);
+#endif
+}
+
 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX
index 5acd8064d3650fc56209980babbd3c64c4c9055a..a05bed43d0c6c5927bf61ffc58350fe24cba6407 100644 (file)
 
 #include "wx/odcombo.h"
 
-#ifdef __WXMSW__
-    #include "wx/msw/private.h"
-#endif
-
 // -----------------------------------------------------------------------
 
 #if defined(__WXMSW__)
 #define wxPG_CHOICEYADJUST           0
 #endif
 
-#define ODCB_CUST_PAINT_MARGIN               6  // Number added to image width for SetCustomPaintWidth
+// Number added to image width for SetCustomPaintWidth
+#define ODCB_CUST_PAINT_MARGIN               9
 
 // Milliseconds to wait for two mouse-ups after focus inorder
 // to trigger a double-click.
@@ -288,12 +285,7 @@ void wxPGTextCtrlEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl )
     //
     // Fix indentation, just in case (change in font boldness is one good
     // reason).
-#if defined(__WXMSW__) && !defined(__WXWINCE__)
-    ::SendMessage(GetHwndOf(tc),
-                  EM_SETMARGINS,
-                  EC_LEFTMARGIN | EC_RIGHTMARGIN,
-                  MAKELONG(0, 0));
-#endif
+    tc->SetMargins(0);
 }
 
 // Provided so that, for example, ComboBox editor can use the same code
@@ -582,13 +574,16 @@ public:
         return rect.width;
     }
 
-    virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust),
+    virtual void PositionTextCtrl( int textCtrlXAdjust,
                                    int WXUNUSED(textCtrlYAdjust) )
     {
         wxPropertyGrid* pg = GetGrid();
+    #ifdef wxPG_TEXTCTRLXADJUST
+        textCtrlXAdjust = wxPG_TEXTCTRLXADJUST -
+                          (wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1) - 1,
+    #endif
         wxOwnerDrawnComboBox::PositionTextCtrl(
-            wxPG_TEXTCTRLXADJUST -
-            (wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1) - 1,
+            textCtrlXAdjust,
             pg->GetSpacingY() + 2
         );
     }
@@ -877,7 +872,7 @@ wxWindow* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid* propGrid,
                odcbFlags);
 
     cb->SetButtonPosition(si.y,0,wxRIGHT);
-    cb->SetTextIndent(wxPG_XBEFORETEXT-1);
+    cb->SetMargins(wxPG_XBEFORETEXT-1);
 
     wxPGChoiceEditor_SetCustomPaintWidth( propGrid, cb, property->GetCommonValue() );
 
@@ -1598,7 +1593,7 @@ void wxPropertyGrid::CorrectEditorWidgetPosY()
 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
 // fits into that category as well).
 void wxPropertyGrid::FixPosForTextCtrl( wxWindow* ctrl,
-                                        unsigned int forColumn,
+                                        unsigned int WXUNUSED(forColumn),
                                         const wxPoint& offset )
 {
     // Center the control vertically
@@ -1612,10 +1607,14 @@ void wxPropertyGrid::FixPosForTextCtrl( wxWindow* ctrl,
     finalPos.y += y_adj;
     finalPos.height -= (y_adj+sz_dec);
 
-    int textCtrlXAdjust = wxPG_TEXTCTRLXADJUST;
+#ifndef wxPG_TEXTCTRLXADJUST
+    int textCtrlXAdjust = wxPG_XBEFORETEXT - 1;
 
-    if ( forColumn != 1 )
-        textCtrlXAdjust -= 3;  // magic number!
+    wxTextCtrl* tc = static_cast<wxTextCtrl*>(ctrl);
+    tc->SetMargins(0);
+#else
+    int textCtrlXAdjust = wxPG_TEXTCTRLXADJUST;
+#endif
 
     finalPos.x += textCtrlXAdjust;
     finalPos.width -= textCtrlXAdjust;
@@ -1691,13 +1690,6 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
     {
         tc->SetBackgroundColour(m_colSelBack);
         tc->SetForegroundColour(m_colSelFore);
-
-        // Normalize margins
-    #ifdef __WXMSW__
-        ::SendMessage(GetHwndOf(tc), EM_SETMARGINS,
-                      EC_LEFTMARGIN | EC_RIGHTMARGIN,
-                      MAKELONG(3, 0));
-    #endif
     }
 
 #ifdef __WXMSW__
index e520c268a2b1e6f458a78a522a1d8e67efc2d10d..09ada8704b99ef552c032a73c10a4dfa6c338552 100644 (file)
 #include "wx/timer.h"
 #include "wx/dcbuffer.h"
 
-#ifdef __WXMSW__
-    #include "wx/msw/private.h"
-#endif
-
 // Two pics for the expand / collapse buttons.
 // Files are not supplied with this project (since it is
 // recommended to use either custom or native rendering).
@@ -3867,18 +3863,6 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags )
                     if ( (p->m_flags & wxPG_PROP_MODIFIED) && (m_windowStyle & wxPG_BOLD_MODIFIED) )
                         SetCurControlBoldFont();
 
-                    //
-                    // Fix TextCtrl indentation
-                #if defined(__WXMSW__) && !defined(__WXWINCE__)
-                    wxTextCtrl* tc = NULL;
-                    if ( primaryCtrl->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) )
-                        tc = ((wxOwnerDrawnComboBox*)primaryCtrl)->GetTextCtrl();
-                    else
-                        tc = wxDynamicCast(primaryCtrl, wxTextCtrl);
-                    if ( tc )
-                        ::SendMessage(GetHwndOf(tc), EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0, 0));
-                #endif
-
                     // Store x relative to splitter (we'll need it).
                     m_ctrlXAdjust = m_wndEditor->GetPosition().x - splitterX;