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 int GetLineLength(long lineNo
) const;
46 virtual wxString
GetLineText(long lineNo
) const;
47 virtual int GetNumberOfLines() const;
49 virtual bool IsModified() const;
50 virtual bool IsEditable() const;
52 // If the return values from and to are the same, there is no selection.
53 virtual void GetSelection(long* from
, long* to
) const;
60 virtual void Replace(long from
, long to
, const wxString
& value
);
61 virtual void Remove(long from
, long to
);
63 // sets/clears the dirty flag
64 virtual void MarkDirty();
65 virtual void DiscardEdits();
67 virtual void SetMaxLength(unsigned long len
);
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
);
74 // apply text attribute to the range of text (only works with richedit
76 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
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;
84 virtual void ShowPosition(long pos
);
86 // Clipboard operations
95 virtual bool CanUndo() const;
96 virtual bool CanRedo() const;
99 virtual void SetInsertionPoint(long pos
);
100 virtual void SetInsertionPointEnd();
101 virtual long GetInsertionPoint() const;
102 virtual wxTextPos
GetLastPosition() const;
104 virtual void SetSelection(long from
, long to
);
105 virtual void SetEditable(bool editable
);
107 virtual void DoEnable( bool enable
);
109 // Implementation from now on
110 void OnDropFiles( wxDropFilesEvent
&event
);
111 void OnChar( wxKeyEvent
&event
);
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
);
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
);
125 bool SetFont(const wxFont
& font
);
126 bool SetForegroundColour(const wxColour
& colour
);
127 bool SetBackgroundColour(const wxColour
& colour
);
129 GtkWidget
* GetConnectWidget();
130 bool IsOwnGtkWindow( GdkWindow
*window
);
131 void DoApplyWidgetStyle(GtkRcStyle
*style
);
132 void CalculateScrollbar();
133 void OnInternalIdle();
135 void SetUpdateFont(bool update
) { m_updateFont
= update
; }
136 void UpdateFontIfNeeded();
138 void SetModified() { m_modified
= true; }
140 // textctrl specific scrolling
141 virtual bool ScrollLines(int lines
);
142 virtual bool ScrollPages(int pages
);
144 // implementation only from now on
146 // tell the control to ignore next text changed signal
147 void IgnoreNextTextUpdate();
149 // should we ignore the changed signal? always resets the flag
150 bool IgnoreTextUpdate();
152 static wxVisualAttributes
153 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
156 virtual wxSize
DoGetBestSize() const;
158 // common part of all ctors
161 // overridden wxWindow methods
162 virtual void DoFreeze();
163 virtual void DoThaw();
165 // get the vertical adjustment, if any, NULL otherwise
166 GtkAdjustment
*GetVAdj() const;
168 // scroll the control by the given number of pixels, return true if the
169 // scroll position changed
170 bool DoScroll(GtkAdjustment
*adj
, int diff
);
172 // Widgets that use the style->base colour for the BG colour should
173 // override this and return true.
174 virtual bool UseGTKStyleBase() const { return true; }
176 virtual void DoSetValue(const wxString
&value
, int flags
= 0);
177 virtual wxString
DoGetValue() const;
180 // change the font for everything in this control
181 void ChangeFontGlobally();
184 GtkWidget
*m_vScrollbar
;
187 bool m_vScrollbarVisible
:1;
189 bool m_ignoreNextUpdate
:1;
191 DECLARE_EVENT_TABLE()
192 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
195 #endif // __GTKTEXTCTRLH__