1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk1/textctrl.h
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef __GTKTEXTCTRLH__
11 #define __GTKTEXTCTRLH__
13 //-----------------------------------------------------------------------------
15 //-----------------------------------------------------------------------------
17 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
20 wxTextCtrl() { Init(); }
21 wxTextCtrl(wxWindow
*parent
,
23 const wxString
&value
= wxEmptyString
,
24 const wxPoint
&pos
= wxDefaultPosition
,
25 const wxSize
&size
= wxDefaultSize
,
27 const wxValidator
& validator
= wxDefaultValidator
,
28 const wxString
&name
= wxTextCtrlNameStr
);
30 virtual ~wxTextCtrl();
32 bool Create(wxWindow
*parent
,
34 const wxString
&value
= wxEmptyString
,
35 const wxPoint
&pos
= wxDefaultPosition
,
36 const wxSize
&size
= wxDefaultSize
,
38 const wxValidator
& validator
= wxDefaultValidator
,
39 const wxString
&name
= wxTextCtrlNameStr
);
41 // implement base class pure virtuals
42 // ----------------------------------
44 virtual int GetLineLength(long lineNo
) const;
45 virtual wxString
GetLineText(long lineNo
) const;
46 virtual int GetNumberOfLines() const;
48 virtual bool IsModified() const;
49 virtual bool IsEditable() const;
51 // If the return values from and to are the same, there is no selection.
52 virtual void GetSelection(long* from
, long* to
) const;
59 virtual void Replace(long from
, long to
, const wxString
& value
);
60 virtual void Remove(long from
, long to
);
62 // sets/clears the dirty flag
63 virtual void MarkDirty();
64 virtual void DiscardEdits();
66 virtual void SetMaxLength(unsigned long len
);
68 // writing text inserts it at the current position, appending always
69 // inserts it at the end
70 virtual void WriteText(const wxString
& text
);
71 virtual void AppendText(const wxString
& text
);
73 // apply text attribute to the range of text (only works with richedit
75 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
77 // translate between the position (which is just an index in the text ctrl
78 // considering all its contents as a single strings) and (x, y) coordinates
79 // which represent column and line.
80 virtual long XYToPosition(long x
, long y
) const;
81 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
83 virtual void ShowPosition(long pos
);
85 // Clipboard operations
94 virtual bool CanUndo() const;
95 virtual bool CanRedo() const;
98 virtual void SetInsertionPoint(long pos
);
99 virtual void SetInsertionPointEnd();
100 virtual long GetInsertionPoint() const;
101 virtual wxTextPos
GetLastPosition() const;
103 virtual void SetSelection(long from
, long to
);
104 virtual void SetEditable(bool editable
);
106 virtual void DoEnable( bool enable
);
108 // Implementation from now on
109 void OnDropFiles( wxDropFilesEvent
&event
);
110 void OnChar( wxKeyEvent
&event
);
112 void OnCut(wxCommandEvent
& event
);
113 void OnCopy(wxCommandEvent
& event
);
114 void OnPaste(wxCommandEvent
& event
);
115 void OnUndo(wxCommandEvent
& event
);
116 void OnRedo(wxCommandEvent
& event
);
118 void OnUpdateCut(wxUpdateUIEvent
& event
);
119 void OnUpdateCopy(wxUpdateUIEvent
& event
);
120 void OnUpdatePaste(wxUpdateUIEvent
& event
);
121 void OnUpdateUndo(wxUpdateUIEvent
& event
);
122 void OnUpdateRedo(wxUpdateUIEvent
& event
);
124 bool SetFont(const wxFont
& font
);
125 bool SetForegroundColour(const wxColour
& colour
);
126 bool SetBackgroundColour(const wxColour
& colour
);
128 GtkWidget
* GetConnectWidget();
129 bool IsOwnGtkWindow( GdkWindow
*window
);
130 void DoApplyWidgetStyle(GtkRcStyle
*style
);
131 void CalculateScrollbar();
132 void OnInternalIdle();
134 void SetUpdateFont(bool update
) { m_updateFont
= update
; }
135 void UpdateFontIfNeeded();
137 void SetModified() { m_modified
= true; }
139 // textctrl specific scrolling
140 virtual bool ScrollLines(int lines
);
141 virtual bool ScrollPages(int pages
);
143 // implementation only from now on
145 // tell the control to ignore next text changed signal
146 void IgnoreNextTextUpdate();
148 // should we ignore the changed signal? always resets the flag
149 bool IgnoreTextUpdate();
151 static wxVisualAttributes
152 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
155 virtual wxSize
DoGetBestSize() const;
157 // common part of all ctors
160 // overridden wxWindow methods
161 virtual void DoFreeze();
162 virtual void DoThaw();
164 // get the vertical adjustment, if any, NULL otherwise
165 GtkAdjustment
*GetVAdj() const;
167 // scroll the control by the given number of pixels, return true if the
168 // scroll position changed
169 bool DoScroll(GtkAdjustment
*adj
, int diff
);
171 // Widgets that use the style->base colour for the BG colour should
172 // override this and return true.
173 virtual bool UseGTKStyleBase() const { return true; }
175 virtual void DoSetValue(const wxString
&value
, int flags
= 0);
176 virtual wxString
DoGetValue() const;
179 // change the font for everything in this control
180 void ChangeFontGlobally();
183 GtkWidget
*m_vScrollbar
;
186 bool m_vScrollbarVisible
:1;
188 bool m_ignoreNextUpdate
:1;
190 DECLARE_EVENT_TABLE()
191 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
194 #endif // __GTKTEXTCTRLH__