1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/textctrl.h
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GTK_TEXTCTRL_H_
12 #define _WX_GTK_TEXTCTRL_H_
14 typedef struct _GtkTextMark GtkTextMark
;
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
20 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
23 wxTextCtrl() { Init(); }
24 wxTextCtrl(wxWindow
*parent
,
26 const wxString
&value
= wxEmptyString
,
27 const wxPoint
&pos
= wxDefaultPosition
,
28 const wxSize
&size
= wxDefaultSize
,
30 const wxValidator
& validator
= wxDefaultValidator
,
31 const wxString
&name
= wxTextCtrlNameStr
);
33 virtual ~wxTextCtrl();
35 bool Create(wxWindow
*parent
,
37 const wxString
&value
= wxEmptyString
,
38 const wxPoint
&pos
= wxDefaultPosition
,
39 const wxSize
&size
= wxDefaultSize
,
41 const wxValidator
& validator
= wxDefaultValidator
,
42 const wxString
&name
= wxTextCtrlNameStr
);
44 // implement base class pure virtuals
45 // ----------------------------------
47 virtual void WriteText(const wxString
& text
);
48 virtual wxString
GetValue() const;
49 virtual bool IsEmpty() const;
51 virtual int GetLineLength(long lineNo
) const;
52 virtual wxString
GetLineText(long lineNo
) const;
53 virtual int GetNumberOfLines() const;
55 virtual bool IsModified() const;
56 virtual bool IsEditable() const;
58 virtual void GetSelection(long* from
, long* to
) const;
60 virtual void Remove(long from
, long to
);
62 virtual void MarkDirty();
63 virtual void DiscardEdits();
65 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
66 virtual bool GetStyle(long position
, wxTextAttr
& style
);
68 // translate between the position (which is just an index in the text ctrl
69 // considering all its contents as a single strings) and (x, y) coordinates
70 // which represent column and line.
71 virtual long XYToPosition(long x
, long y
) const;
72 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
74 virtual void ShowPosition(long pos
);
76 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
77 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
79 wxTextCoord
*row
) const
81 return wxTextCtrlBase::HitTest(pt
, col
, row
);
84 // Clipboard operations
90 virtual void SetInsertionPoint(long pos
);
91 virtual long GetInsertionPoint() const;
92 virtual wxTextPos
GetLastPosition() const;
94 virtual void SetSelection(long from
, long to
);
95 virtual void SetEditable(bool editable
);
97 // Overridden wxWindow methods
98 virtual void SetWindowStyleFlag( long style
);
99 virtual bool Enable( bool enable
= true );
101 // Implementation from now on
102 void OnDropFiles( wxDropFilesEvent
&event
);
103 void OnChar( wxKeyEvent
&event
);
105 void OnCut(wxCommandEvent
& event
);
106 void OnCopy(wxCommandEvent
& event
);
107 void OnPaste(wxCommandEvent
& event
);
108 void OnUndo(wxCommandEvent
& event
);
109 void OnRedo(wxCommandEvent
& event
);
111 void OnUpdateCut(wxUpdateUIEvent
& event
);
112 void OnUpdateCopy(wxUpdateUIEvent
& event
);
113 void OnUpdatePaste(wxUpdateUIEvent
& event
);
114 void OnUpdateUndo(wxUpdateUIEvent
& event
);
115 void OnUpdateRedo(wxUpdateUIEvent
& event
);
117 bool SetFont(const wxFont
& font
);
118 bool SetForegroundColour(const wxColour
& colour
);
119 bool SetBackgroundColour(const wxColour
& colour
);
121 GtkWidget
* GetConnectWidget();
123 void SetUpdateFont(bool WXUNUSED(update
)) { }
125 // implementation only from now on
127 // tell the control to ignore next text changed signal
128 void IgnoreNextTextUpdate(int n
= 1) { m_countUpdatesToIgnore
= n
; }
130 // should we ignore the changed signal? always resets the flag
131 bool IgnoreTextUpdate();
133 // call this to indicate that the control is about to be changed
134 // programmatically and so m_modified flag shouldn't be set
135 void DontMarkDirtyOnNextChange() { m_dontMarkDirty
= true; }
137 // should we mark the control as dirty? always resets the flag
138 bool MarkDirtyOnChange();
140 // always let GTK have mouse release events for multiline controls
141 virtual bool GTKProcessEvent(wxEvent
& event
) const;
144 static wxVisualAttributes
145 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
148 // overridden wxWindow virtual methods
149 virtual wxSize
DoGetBestSize() const;
150 virtual void DoApplyWidgetStyle(GtkRcStyle
*style
);
151 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
153 virtual wxSize
DoGetSizeFromTextSize(int xlen
, int ylen
= -1) const;
155 virtual void DoFreeze();
156 virtual void DoThaw();
158 // Widgets that use the style->base colour for the BG colour should
159 // override this and return true.
160 virtual bool UseGTKStyleBase() const { return true; }
162 virtual void DoSetValue(const wxString
&value
, int flags
= 0);
164 // Override this to use either GtkEntry or GtkTextView IME depending on the
165 // kind of control we are.
166 virtual int GTKIMFilterKeypress(GdkEventKey
* event
) const;
168 virtual wxPoint
DoPositionToCoords(long pos
) const;
170 // wrappers hiding the differences between functions doing the same thing
171 // for GtkTextView and GtkEntry (all of them use current window style to
172 // set the given characteristic)
173 void GTKSetEditable();
174 void GTKSetVisibility();
175 void GTKSetActivatesDefault();
176 void GTKSetWrapMode();
177 void GTKSetJustification();
182 // overridden wxTextEntry virtual methods
183 virtual GtkEditable
*GetEditable() const;
184 virtual GtkEntry
*GetEntry() const;
185 virtual void EnableTextChangedEvents(bool enable
);
187 // change the font for everything in this control
188 void ChangeFontGlobally();
190 // get the encoding which is used in this control: this looks at our font
191 // and default style but not the current style (i.e. the style for the
192 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
194 wxFontEncoding
GetTextEncoding() const;
196 // returns either m_text or m_buffer depending on whether the control is
197 // single- or multi-line; convenient for the GTK+ functions which work with
199 void *GetTextObject() const
201 return IsMultiLine() ? static_cast<void *>(m_buffer
)
202 : static_cast<void *>(m_text
);
206 // the widget used for single line controls
210 bool m_dontMarkDirty
:1;
212 int m_countUpdatesToIgnore
;
214 // Our text buffer. Convenient, and holds the buffer while using
215 // a dummy one when frozen
216 GtkTextBuffer
*m_buffer
;
218 GtkTextMark
* m_showPositionOnThaw
;
219 GSList
* m_anonymousMarkList
;
222 void OnUrlMouseEvent(wxMouseEvent
&);
224 DECLARE_EVENT_TABLE()
225 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
228 #endif // _WX_GTK_TEXTCTRL_H_