1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/textctrl.h
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_GTK_TEXTCTRL_H_
11 #define _WX_GTK_TEXTCTRL_H_
13 typedef struct _GtkTextMark GtkTextMark
;
15 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
19 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
22 wxTextCtrl() { Init(); }
23 wxTextCtrl(wxWindow
*parent
,
25 const wxString
&value
= wxEmptyString
,
26 const wxPoint
&pos
= wxDefaultPosition
,
27 const wxSize
&size
= wxDefaultSize
,
29 const wxValidator
& validator
= wxDefaultValidator
,
30 const wxString
&name
= wxTextCtrlNameStr
);
32 virtual ~wxTextCtrl();
34 bool Create(wxWindow
*parent
,
36 const wxString
&value
= wxEmptyString
,
37 const wxPoint
&pos
= wxDefaultPosition
,
38 const wxSize
&size
= wxDefaultSize
,
40 const wxValidator
& validator
= wxDefaultValidator
,
41 const wxString
&name
= wxTextCtrlNameStr
);
43 // implement base class pure virtuals
44 // ----------------------------------
46 virtual void WriteText(const wxString
& text
);
47 virtual wxString
GetValue() const;
48 virtual bool IsEmpty() const;
50 virtual int GetLineLength(long lineNo
) const;
51 virtual wxString
GetLineText(long lineNo
) const;
52 virtual int GetNumberOfLines() const;
54 virtual bool IsModified() const;
55 virtual bool IsEditable() const;
57 virtual void GetSelection(long* from
, long* to
) const;
59 virtual void Remove(long from
, long to
);
61 virtual void MarkDirty();
62 virtual void DiscardEdits();
64 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
65 virtual bool GetStyle(long position
, wxTextAttr
& style
);
67 // translate between the position (which is just an index in the text ctrl
68 // considering all its contents as a single strings) and (x, y) coordinates
69 // which represent column and line.
70 virtual long XYToPosition(long x
, long y
) const;
71 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
73 virtual void ShowPosition(long pos
);
75 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
76 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
78 wxTextCoord
*row
) const
80 return wxTextCtrlBase::HitTest(pt
, col
, row
);
83 // Clipboard operations
89 virtual void SetInsertionPoint(long pos
);
90 virtual long GetInsertionPoint() const;
91 virtual wxTextPos
GetLastPosition() const;
93 virtual void SetSelection(long from
, long to
);
94 virtual void SetEditable(bool editable
);
96 // Overridden wxWindow methods
97 virtual void SetWindowStyleFlag( long style
);
98 virtual bool Enable( bool enable
= true );
100 // Implementation from now on
101 void OnDropFiles( wxDropFilesEvent
&event
);
102 void OnChar( wxKeyEvent
&event
);
104 void OnCut(wxCommandEvent
& event
);
105 void OnCopy(wxCommandEvent
& event
);
106 void OnPaste(wxCommandEvent
& event
);
107 void OnUndo(wxCommandEvent
& event
);
108 void OnRedo(wxCommandEvent
& event
);
110 void OnUpdateCut(wxUpdateUIEvent
& event
);
111 void OnUpdateCopy(wxUpdateUIEvent
& event
);
112 void OnUpdatePaste(wxUpdateUIEvent
& event
);
113 void OnUpdateUndo(wxUpdateUIEvent
& event
);
114 void OnUpdateRedo(wxUpdateUIEvent
& event
);
116 bool SetFont(const wxFont
& font
);
117 bool SetForegroundColour(const wxColour
& colour
);
118 bool SetBackgroundColour(const wxColour
& colour
);
120 GtkWidget
* GetConnectWidget();
122 void SetUpdateFont(bool WXUNUSED(update
)) { }
124 // implementation only from now on
126 // tell the control to ignore next text changed signal
127 void IgnoreNextTextUpdate(int n
= 1) { m_countUpdatesToIgnore
= n
; }
129 // should we ignore the changed signal? always resets the flag
130 bool IgnoreTextUpdate();
132 // call this to indicate that the control is about to be changed
133 // programmatically and so m_modified flag shouldn't be set
134 void DontMarkDirtyOnNextChange() { m_dontMarkDirty
= true; }
136 // should we mark the control as dirty? always resets the flag
137 bool MarkDirtyOnChange();
139 // always let GTK have mouse release events for multiline controls
140 virtual bool GTKProcessEvent(wxEvent
& event
) const;
143 static wxVisualAttributes
144 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
147 // overridden wxWindow virtual methods
148 virtual wxSize
DoGetBestSize() const;
149 virtual void DoApplyWidgetStyle(GtkRcStyle
*style
);
150 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
152 virtual wxSize
DoGetSizeFromTextSize(int xlen
, int ylen
= -1) const;
154 virtual void DoFreeze();
155 virtual void DoThaw();
157 // Widgets that use the style->base colour for the BG colour should
158 // override this and return true.
159 virtual bool UseGTKStyleBase() const { return true; }
161 virtual void DoSetValue(const wxString
&value
, int flags
= 0);
163 // Override this to use either GtkEntry or GtkTextView IME depending on the
164 // kind of control we are.
165 virtual int GTKIMFilterKeypress(GdkEventKey
* event
) const;
167 virtual wxPoint
DoPositionToCoords(long pos
) const;
169 // wrappers hiding the differences between functions doing the same thing
170 // for GtkTextView and GtkEntry (all of them use current window style to
171 // set the given characteristic)
172 void GTKSetEditable();
173 void GTKSetVisibility();
174 void GTKSetActivatesDefault();
175 void GTKSetWrapMode();
176 void GTKSetJustification();
181 // overridden wxTextEntry virtual methods
182 virtual GtkEditable
*GetEditable() const;
183 virtual GtkEntry
*GetEntry() const;
184 virtual void EnableTextChangedEvents(bool enable
);
186 // change the font for everything in this control
187 void ChangeFontGlobally();
189 // get the encoding which is used in this control: this looks at our font
190 // and default style but not the current style (i.e. the style for the
191 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
193 wxFontEncoding
GetTextEncoding() const;
195 // returns either m_text or m_buffer depending on whether the control is
196 // single- or multi-line; convenient for the GTK+ functions which work with
198 void *GetTextObject() const
200 return IsMultiLine() ? static_cast<void *>(m_buffer
)
201 : static_cast<void *>(m_text
);
205 // the widget used for single line controls
209 bool m_dontMarkDirty
:1;
211 int m_countUpdatesToIgnore
;
213 // Our text buffer. Convenient, and holds the buffer while using
214 // a dummy one when frozen
215 GtkTextBuffer
*m_buffer
;
217 GtkTextMark
* m_showPositionOnThaw
;
218 GSList
* m_anonymousMarkList
;
221 void OnUrlMouseEvent(wxMouseEvent
&);
223 DECLARE_EVENT_TABLE()
224 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
227 #endif // _WX_GTK_TEXTCTRL_H_