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
);
31 virtual ~wxTextCtrl();
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
) { DoSetValue(value
, SetValue_SendEvent
); }
48 virtual void ChangeValue(const wxString
&value
) { DoSetValue(value
); }
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 // If the return values from and to are the same, there is no selection.
58 virtual void GetSelection(long* from
, long* to
) const;
65 virtual void Replace(long from
, long to
, const wxString
& value
);
66 virtual void Remove(long from
, long to
);
68 // sets/clears the dirty flag
69 virtual void MarkDirty();
70 virtual void DiscardEdits();
72 virtual void SetMaxLength(unsigned long len
);
74 // writing text inserts it at the current position, appending always
75 // inserts it at the end
76 virtual void WriteText(const wxString
& text
);
77 virtual void AppendText(const wxString
& text
);
79 // apply text attribute to the range of text (only works with richedit
81 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
83 // translate between the position (which is just an index in the text ctrl
84 // considering all its contents as a single strings) and (x, y) coordinates
85 // which represent column and line.
86 virtual long XYToPosition(long x
, long y
) const;
87 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
89 virtual void ShowPosition(long pos
);
91 // Clipboard operations
100 virtual bool CanUndo() const;
101 virtual bool CanRedo() const;
104 virtual void SetInsertionPoint(long pos
);
105 virtual void SetInsertionPointEnd();
106 virtual long GetInsertionPoint() const;
107 virtual wxTextPos
GetLastPosition() const;
109 virtual void SetSelection(long from
, long to
);
110 virtual void SetEditable(bool editable
);
112 virtual bool Enable( bool enable
= true );
114 // Implementation from now on
115 void OnDropFiles( wxDropFilesEvent
&event
);
116 void OnChar( wxKeyEvent
&event
);
118 void OnCut(wxCommandEvent
& event
);
119 void OnCopy(wxCommandEvent
& event
);
120 void OnPaste(wxCommandEvent
& event
);
121 void OnUndo(wxCommandEvent
& event
);
122 void OnRedo(wxCommandEvent
& event
);
124 void OnUpdateCut(wxUpdateUIEvent
& event
);
125 void OnUpdateCopy(wxUpdateUIEvent
& event
);
126 void OnUpdatePaste(wxUpdateUIEvent
& event
);
127 void OnUpdateUndo(wxUpdateUIEvent
& event
);
128 void OnUpdateRedo(wxUpdateUIEvent
& event
);
130 bool SetFont(const wxFont
& font
);
131 bool SetForegroundColour(const wxColour
& colour
);
132 bool SetBackgroundColour(const wxColour
& colour
);
134 GtkWidget
* GetConnectWidget();
135 bool IsOwnGtkWindow( GdkWindow
*window
);
136 void DoApplyWidgetStyle(GtkRcStyle
*style
);
137 void CalculateScrollbar();
138 void OnInternalIdle();
140 void SetUpdateFont(bool update
) { m_updateFont
= update
; }
141 void UpdateFontIfNeeded();
143 void SetModified() { m_modified
= true; }
145 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
146 // avoid horrible flicker/scrolling back and forth
147 virtual void Freeze();
150 // textctrl specific scrolling
151 virtual bool ScrollLines(int lines
);
152 virtual bool ScrollPages(int pages
);
154 // implementation only from now on
156 // wxGTK-specific: called recursively by Enable,
157 // to give widgets an oppprtunity to correct their colours after they
158 // have been changed by Enable
159 virtual void OnParentEnable( bool enable
) ;
161 // tell the control to ignore next text changed signal
162 void IgnoreNextTextUpdate();
164 // should we ignore the changed signal? always resets the flag
165 bool IgnoreTextUpdate();
167 static wxVisualAttributes
168 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
171 virtual wxSize
DoGetBestSize() const;
173 // common part of all ctors
176 // get the vertical adjustment, if any, NULL otherwise
177 GtkAdjustment
*GetVAdj() const;
179 // scroll the control by the given number of pixels, return true if the
180 // scroll position changed
181 bool DoScroll(GtkAdjustment
*adj
, int diff
);
183 // Widgets that use the style->base colour for the BG colour should
184 // override this and return true.
185 virtual bool UseGTKStyleBase() const { return true; }
187 void DoSetValue(const wxString
&value
, int flags
= 0);
190 // change the font for everything in this control
191 void ChangeFontGlobally();
194 GtkWidget
*m_vScrollbar
;
197 bool m_vScrollbarVisible
:1;
199 bool m_ignoreNextUpdate
:1;
201 DECLARE_EVENT_TABLE()
202 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
205 #endif // __GTKTEXTCTRLH__