1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk1/textctrl.h
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __GTKTEXTCTRLH__
12 #define __GTKTEXTCTRLH__
14 //-----------------------------------------------------------------------------
16 //-----------------------------------------------------------------------------
18 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
21 wxTextCtrl() { Init(); }
22 wxTextCtrl(wxWindow
*parent
,
24 const wxString
&value
= wxEmptyString
,
25 const wxPoint
&pos
= wxDefaultPosition
,
26 const wxSize
&size
= wxDefaultSize
,
28 const wxValidator
& validator
= wxDefaultValidator
,
29 const wxString
&name
= wxTextCtrlNameStr
);
33 bool Create(wxWindow
*parent
,
35 const wxString
&value
= wxEmptyString
,
36 const wxPoint
&pos
= wxDefaultPosition
,
37 const wxSize
&size
= wxDefaultSize
,
39 const wxValidator
& validator
= wxDefaultValidator
,
40 const wxString
&name
= wxTextCtrlNameStr
);
42 // implement base class pure virtuals
43 // ----------------------------------
45 virtual wxString
GetValue() const;
46 virtual void SetValue(const wxString
& value
);
48 virtual int GetLineLength(long lineNo
) const;
49 virtual wxString
GetLineText(long lineNo
) const;
50 virtual int GetNumberOfLines() const;
52 virtual bool IsModified() const;
53 virtual bool IsEditable() const;
55 // If the return values from and to are the same, there is no selection.
56 virtual void GetSelection(long* from
, long* to
) const;
63 virtual void Replace(long from
, long to
, const wxString
& value
);
64 virtual void Remove(long from
, long to
);
66 // sets/clears the dirty flag
67 virtual void MarkDirty();
68 virtual void DiscardEdits();
70 virtual void SetMaxLength(unsigned long len
);
72 // writing text inserts it at the current position, appending always
73 // inserts it at the end
74 virtual void WriteText(const wxString
& text
);
75 virtual void AppendText(const wxString
& text
);
77 // apply text attribute to the range of text (only works with richedit
79 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
81 // translate between the position (which is just an index in the text ctrl
82 // considering all its contents as a single strings) and (x, y) coordinates
83 // which represent column and line.
84 virtual long XYToPosition(long x
, long y
) const;
85 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
87 virtual void ShowPosition(long pos
);
89 // Clipboard operations
98 virtual bool CanUndo() const;
99 virtual bool CanRedo() const;
102 virtual void SetInsertionPoint(long pos
);
103 virtual void SetInsertionPointEnd();
104 virtual long GetInsertionPoint() const;
105 virtual wxTextPos
GetLastPosition() const;
107 virtual void SetSelection(long from
, long to
);
108 virtual void SetEditable(bool editable
);
110 virtual bool Enable( bool enable
= true );
112 // Implementation from now on
113 void OnDropFiles( wxDropFilesEvent
&event
);
114 void OnChar( wxKeyEvent
&event
);
116 void OnCut(wxCommandEvent
& event
);
117 void OnCopy(wxCommandEvent
& event
);
118 void OnPaste(wxCommandEvent
& event
);
119 void OnUndo(wxCommandEvent
& event
);
120 void OnRedo(wxCommandEvent
& event
);
122 void OnUpdateCut(wxUpdateUIEvent
& event
);
123 void OnUpdateCopy(wxUpdateUIEvent
& event
);
124 void OnUpdatePaste(wxUpdateUIEvent
& event
);
125 void OnUpdateUndo(wxUpdateUIEvent
& event
);
126 void OnUpdateRedo(wxUpdateUIEvent
& event
);
128 bool SetFont(const wxFont
& font
);
129 bool SetForegroundColour(const wxColour
& colour
);
130 bool SetBackgroundColour(const wxColour
& colour
);
132 GtkWidget
* GetConnectWidget();
133 bool IsOwnGtkWindow( GdkWindow
*window
);
134 void DoApplyWidgetStyle(GtkRcStyle
*style
);
135 void CalculateScrollbar();
136 void OnInternalIdle();
138 void SetUpdateFont(bool update
) { m_updateFont
= update
; }
139 void UpdateFontIfNeeded();
141 void SetModified() { m_modified
= true; }
143 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
144 // avoid horrible flicker/scrolling back and forth
145 virtual void Freeze();
148 // textctrl specific scrolling
149 virtual bool ScrollLines(int lines
);
150 virtual bool ScrollPages(int pages
);
152 // implementation only from now on
154 // wxGTK-specific: called recursively by Enable,
155 // to give widgets an oppprtunity to correct their colours after they
156 // have been changed by Enable
157 virtual void OnParentEnable( bool enable
) ;
159 // tell the control to ignore next text changed signal
160 void IgnoreNextTextUpdate();
162 // should we ignore the changed signal? always resets the flag
163 bool IgnoreTextUpdate();
165 static wxVisualAttributes
166 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
169 virtual wxSize
DoGetBestSize() const;
171 // common part of all ctors
174 // get the vertical adjustment, if any, NULL otherwise
175 GtkAdjustment
*GetVAdj() const;
177 // scroll the control by the given number of pixels, return true if the
178 // scroll position changed
179 bool DoScroll(GtkAdjustment
*adj
, int diff
);
181 // Widgets that use the style->base colour for the BG colour should
182 // override this and return true.
183 virtual bool UseGTKStyleBase() const { return true; }
186 // change the font for everything in this control
187 void ChangeFontGlobally();
190 GtkWidget
*m_vScrollbar
;
193 bool m_vScrollbarVisible
:1;
195 bool m_ignoreNextUpdate
:1;
197 DECLARE_EVENT_TABLE()
198 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
201 #endif // __GTKTEXTCTRLH__