1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/gtk1/textctrl.h
3 // Purpose:
4 // Author:      Robert Roebling
5 // Created:     01/02/97
6 // Id:          $Id: textctrl.h 41754 2006-10-08 22:40:14Z VZ $
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:
wxTextCtrl()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 wxString GetValue() const;
46 
47     virtual int GetLineLength(long lineNo) const;
48     virtual wxString GetLineText(long lineNo) const;
49     virtual int GetNumberOfLines() const;
50 
51     virtual bool IsModified() const;
52     virtual bool IsEditable() const;
53 
54     // If the return values from and to are the same, there is no selection.
55     virtual void GetSelection(long* from, long* to) const;
56 
57     // operations
58     // ----------
59 
60     // editing
61     virtual void Clear();
62     virtual void Replace(long from, long to, const wxString& value);
63     virtual void Remove(long from, long to);
64 
65     // sets/clears the dirty flag
66     virtual void MarkDirty();
67     virtual void DiscardEdits();
68 
69     virtual void SetMaxLength(unsigned long len);
70 
71     // writing text inserts it at the current position, appending always
72     // inserts it at the end
73     virtual void WriteText(const wxString& text);
74     virtual void AppendText(const wxString& text);
75 
76     // apply text attribute to the range of text (only works with richedit
77     // controls)
78     virtual bool SetStyle(long start, long end, const wxTextAttr& style);
79 
80     // translate between the position (which is just an index in the text ctrl
81     // considering all its contents as a single strings) and (x, y) coordinates
82     // which represent column and line.
83     virtual long XYToPosition(long x, long y) const;
84     virtual bool PositionToXY(long pos, long *x, long *y) const;
85 
86     virtual void ShowPosition(long pos);
87 
88     // Clipboard operations
89     virtual void Copy();
90     virtual void Cut();
91     virtual void Paste();
92 
93     // Undo/redo
94     virtual void Undo();
95     virtual void Redo();
96 
97     virtual bool CanUndo() const;
98     virtual bool CanRedo() const;
99 
100     // Insertion point
101     virtual void SetInsertionPoint(long pos);
102     virtual void SetInsertionPointEnd();
103     virtual long GetInsertionPoint() const;
104     virtual wxTextPos GetLastPosition() const;
105 
106     virtual void SetSelection(long from, long to);
107     virtual void SetEditable(bool editable);
108 
109     virtual bool Enable( bool enable = true );
110 
111     // Implementation from now on
112     void OnDropFiles( wxDropFilesEvent &event );
113     void OnChar( wxKeyEvent &event );
114 
115     void OnCut(wxCommandEvent& event);
116     void OnCopy(wxCommandEvent& event);
117     void OnPaste(wxCommandEvent& event);
118     void OnUndo(wxCommandEvent& event);
119     void OnRedo(wxCommandEvent& event);
120 
121     void OnUpdateCut(wxUpdateUIEvent& event);
122     void OnUpdateCopy(wxUpdateUIEvent& event);
123     void OnUpdatePaste(wxUpdateUIEvent& event);
124     void OnUpdateUndo(wxUpdateUIEvent& event);
125     void OnUpdateRedo(wxUpdateUIEvent& event);
126 
127     bool SetFont(const wxFont& font);
128     bool SetForegroundColour(const wxColour& colour);
129     bool SetBackgroundColour(const wxColour& colour);
130 
131     GtkWidget* GetConnectWidget();
132     bool IsOwnGtkWindow( GdkWindow *window );
133     void DoApplyWidgetStyle(GtkRcStyle *style);
134     void CalculateScrollbar();
135     void OnInternalIdle();
136 
SetUpdateFont(bool update)137     void SetUpdateFont(bool update) { m_updateFont = update; }
138     void UpdateFontIfNeeded();
139 
SetModified()140     void SetModified() { m_modified = true; }
141 
142     // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
143     // avoid horrible flicker/scrolling back and forth
144     virtual void Freeze();
145     virtual void Thaw();
146 
147     // textctrl specific scrolling
148     virtual bool ScrollLines(int lines);
149     virtual bool ScrollPages(int pages);
150 
151     // implementation only from now on
152 
153     // wxGTK-specific: called recursively by Enable,
154     // to give widgets an oppprtunity to correct their colours after they
155     // have been changed by Enable
156     virtual void OnParentEnable( bool enable ) ;
157 
158     // tell the control to ignore next text changed signal
159     void IgnoreNextTextUpdate();
160 
161     // should we ignore the changed signal? always resets the flag
162     bool IgnoreTextUpdate();
163 
164     static wxVisualAttributes
165     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
166 
167 protected:
168     virtual wxSize DoGetBestSize() const;
169 
170     // common part of all ctors
171     void Init();
172 
173     // get the vertical adjustment, if any, NULL otherwise
174     GtkAdjustment *GetVAdj() const;
175 
176     // scroll the control by the given number of pixels, return true if the
177     // scroll position changed
178     bool DoScroll(GtkAdjustment *adj, int diff);
179 
180     // Widgets that use the style->base colour for the BG colour should
181     // override this and return true.
UseGTKStyleBase()182     virtual bool UseGTKStyleBase() const { return true; }
183 
184     virtual void DoSetValue(const wxString &value, int flags = 0);
185 
186 private:
187     // change the font for everything in this control
188     void ChangeFontGlobally();
189 
190     GtkWidget  *m_text;
191     GtkWidget  *m_vScrollbar;
192 
193     bool        m_modified:1;
194     bool        m_vScrollbarVisible:1;
195     bool        m_updateFont:1;
196     bool        m_ignoreNextUpdate:1;
197 
198     DECLARE_EVENT_TABLE()
199     DECLARE_DYNAMIC_CLASS(wxTextCtrl)
200 };
201 
202 #endif // __GTKTEXTCTRLH__
203 
204