]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/textctrl.h
implementation of HotKey, see #12354
[wxWidgets.git] / include / wx / gtk1 / textctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk1/textctrl.h
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __GTKTEXTCTRLH__
12 #define __GTKTEXTCTRLH__
13
14 //-----------------------------------------------------------------------------
15 // wxTextCtrl
16 //-----------------------------------------------------------------------------
17
18 class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
19 {
20 public:
21 wxTextCtrl() { Init(); }
22 wxTextCtrl(wxWindow *parent,
23 wxWindowID id,
24 const wxString &value = wxEmptyString,
25 const wxPoint &pos = wxDefaultPosition,
26 const wxSize &size = wxDefaultSize,
27 long style = 0,
28 const wxValidator& validator = wxDefaultValidator,
29 const wxString &name = wxTextCtrlNameStr);
30
31 virtual ~wxTextCtrl();
32
33 bool Create(wxWindow *parent,
34 wxWindowID id,
35 const wxString &value = wxEmptyString,
36 const wxPoint &pos = wxDefaultPosition,
37 const wxSize &size = wxDefaultSize,
38 long style = 0,
39 const wxValidator& validator = wxDefaultValidator,
40 const wxString &name = wxTextCtrlNameStr);
41
42 // implement base class pure virtuals
43 // ----------------------------------
44
45 virtual int GetLineLength(long lineNo) const;
46 virtual wxString GetLineText(long lineNo) const;
47 virtual int GetNumberOfLines() const;
48
49 virtual bool IsModified() const;
50 virtual bool IsEditable() const;
51
52 // If the return values from and to are the same, there is no selection.
53 virtual void GetSelection(long* from, long* to) const;
54
55 // operations
56 // ----------
57
58 // editing
59 virtual void Clear();
60 virtual void Replace(long from, long to, const wxString& value);
61 virtual void Remove(long from, long to);
62
63 // sets/clears the dirty flag
64 virtual void MarkDirty();
65 virtual void DiscardEdits();
66
67 virtual void SetMaxLength(unsigned long len);
68
69 // writing text inserts it at the current position, appending always
70 // inserts it at the end
71 virtual void WriteText(const wxString& text);
72 virtual void AppendText(const wxString& text);
73
74 // apply text attribute to the range of text (only works with richedit
75 // controls)
76 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
77
78 // translate between the position (which is just an index in the text ctrl
79 // considering all its contents as a single strings) and (x, y) coordinates
80 // which represent column and line.
81 virtual long XYToPosition(long x, long y) const;
82 virtual bool PositionToXY(long pos, long *x, long *y) const;
83
84 virtual void ShowPosition(long pos);
85
86 // Clipboard operations
87 virtual void Copy();
88 virtual void Cut();
89 virtual void Paste();
90
91 // Undo/redo
92 virtual void Undo();
93 virtual void Redo();
94
95 virtual bool CanUndo() const;
96 virtual bool CanRedo() const;
97
98 // Insertion point
99 virtual void SetInsertionPoint(long pos);
100 virtual void SetInsertionPointEnd();
101 virtual long GetInsertionPoint() const;
102 virtual wxTextPos GetLastPosition() const;
103
104 virtual void SetSelection(long from, long to);
105 virtual void SetEditable(bool editable);
106
107 virtual void DoEnable( bool enable );
108
109 // Implementation from now on
110 void OnDropFiles( wxDropFilesEvent &event );
111 void OnChar( wxKeyEvent &event );
112
113 void OnCut(wxCommandEvent& event);
114 void OnCopy(wxCommandEvent& event);
115 void OnPaste(wxCommandEvent& event);
116 void OnUndo(wxCommandEvent& event);
117 void OnRedo(wxCommandEvent& event);
118
119 void OnUpdateCut(wxUpdateUIEvent& event);
120 void OnUpdateCopy(wxUpdateUIEvent& event);
121 void OnUpdatePaste(wxUpdateUIEvent& event);
122 void OnUpdateUndo(wxUpdateUIEvent& event);
123 void OnUpdateRedo(wxUpdateUIEvent& event);
124
125 bool SetFont(const wxFont& font);
126 bool SetForegroundColour(const wxColour& colour);
127 bool SetBackgroundColour(const wxColour& colour);
128
129 GtkWidget* GetConnectWidget();
130 bool IsOwnGtkWindow( GdkWindow *window );
131 void DoApplyWidgetStyle(GtkRcStyle *style);
132 void CalculateScrollbar();
133 void OnInternalIdle();
134
135 void SetUpdateFont(bool update) { m_updateFont = update; }
136 void UpdateFontIfNeeded();
137
138 void SetModified() { m_modified = true; }
139
140 // textctrl specific scrolling
141 virtual bool ScrollLines(int lines);
142 virtual bool ScrollPages(int pages);
143
144 // implementation only from now on
145
146 // wxGTK-specific: called recursively by Enable,
147 // to give widgets an oppprtunity to correct their colours after they
148 // have been changed by Enable
149 virtual void OnEnabled( bool enabled ) ;
150
151 // tell the control to ignore next text changed signal
152 void IgnoreNextTextUpdate();
153
154 // should we ignore the changed signal? always resets the flag
155 bool IgnoreTextUpdate();
156
157 static wxVisualAttributes
158 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
159
160 protected:
161 virtual wxSize DoGetBestSize() const;
162
163 // common part of all ctors
164 void Init();
165
166 // overridden wxWindow methods
167 virtual void DoFreeze();
168 virtual void DoThaw();
169
170 // get the vertical adjustment, if any, NULL otherwise
171 GtkAdjustment *GetVAdj() const;
172
173 // scroll the control by the given number of pixels, return true if the
174 // scroll position changed
175 bool DoScroll(GtkAdjustment *adj, int diff);
176
177 // Widgets that use the style->base colour for the BG colour should
178 // override this and return true.
179 virtual bool UseGTKStyleBase() const { return true; }
180
181 virtual void DoSetValue(const wxString &value, int flags = 0);
182 virtual wxString DoGetValue() const;
183
184 private:
185 // change the font for everything in this control
186 void ChangeFontGlobally();
187
188 GtkWidget *m_text;
189 GtkWidget *m_vScrollbar;
190
191 bool m_modified:1;
192 bool m_vScrollbarVisible:1;
193 bool m_updateFont:1;
194 bool m_ignoreNextUpdate:1;
195
196 DECLARE_EVENT_TABLE()
197 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
198 };
199
200 #endif // __GTKTEXTCTRLH__
201