1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/textctrl.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/textctrl.h"
32 #include "wx/settings.h"
39 #include "wx/module.h"
43 #include "wx/clipbrd.h"
46 #include "wx/textfile.h"
52 #include "wx/palmos/missing.h"
54 #endif // wxUSE_RICHEDIT
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
62 // this module initializes RichEdit DLL(s) if needed
63 class wxRichEditModule
: public wxModule
66 virtual bool OnInit();
67 virtual void OnExit();
69 // load the richedit DLL of at least of required version
70 static bool Load(int version
= 1);
73 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
74 static HINSTANCE ms_hRichEdit
[2];
76 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
79 HINSTANCE
wxRichEditModule::ms_hRichEdit
[2] = { NULL
, NULL
};
81 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
83 #endif // wxUSE_RICHEDIT
85 // ----------------------------------------------------------------------------
86 // event tables and other macros
87 // ----------------------------------------------------------------------------
89 #if wxUSE_EXTENDED_RTTI
90 WX_DEFINE_FLAGS( wxTextCtrlStyle
)
92 wxBEGIN_FLAGS( wxTextCtrlStyle
)
93 // new style border flags, we put them first to
94 // use them for streaming out
95 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
96 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
97 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
98 wxFLAGS_MEMBER(wxBORDER_RAISED
)
99 wxFLAGS_MEMBER(wxBORDER_STATIC
)
100 wxFLAGS_MEMBER(wxBORDER_NONE
)
102 // old style border flags
103 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
104 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
105 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
106 wxFLAGS_MEMBER(wxRAISED_BORDER
)
107 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
108 wxFLAGS_MEMBER(wxBORDER
)
110 // standard window styles
111 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
112 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
113 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
114 wxFLAGS_MEMBER(wxWANTS_CHARS
)
115 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
116 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
117 wxFLAGS_MEMBER(wxVSCROLL
)
118 wxFLAGS_MEMBER(wxHSCROLL
)
120 wxFLAGS_MEMBER(wxTE_PROCESS_ENTER
)
121 wxFLAGS_MEMBER(wxTE_PROCESS_TAB
)
122 wxFLAGS_MEMBER(wxTE_MULTILINE
)
123 wxFLAGS_MEMBER(wxTE_PASSWORD
)
124 wxFLAGS_MEMBER(wxTE_READONLY
)
125 wxFLAGS_MEMBER(wxHSCROLL
)
126 wxFLAGS_MEMBER(wxTE_RICH
)
127 wxFLAGS_MEMBER(wxTE_RICH2
)
128 wxFLAGS_MEMBER(wxTE_AUTO_URL
)
129 wxFLAGS_MEMBER(wxTE_NOHIDESEL
)
130 wxFLAGS_MEMBER(wxTE_LEFT
)
131 wxFLAGS_MEMBER(wxTE_CENTRE
)
132 wxFLAGS_MEMBER(wxTE_RIGHT
)
133 wxFLAGS_MEMBER(wxTE_DONTWRAP
)
134 wxFLAGS_MEMBER(wxTE_CHARWRAP
)
135 wxFLAGS_MEMBER(wxTE_WORDWRAP
)
137 wxEND_FLAGS( wxTextCtrlStyle
)
139 IMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl
, wxControl
,"wx/textctrl.h")
141 wxBEGIN_PROPERTIES_TABLE(wxTextCtrl
)
142 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
143 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
145 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
146 wxPROPERTY( Value
, wxString
, SetValue
, GetValue
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
147 wxPROPERTY_FLAGS( WindowStyle
, wxTextCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
148 wxEND_PROPERTIES_TABLE()
150 wxBEGIN_HANDLERS_TABLE(wxTextCtrl
)
151 wxEND_HANDLERS_TABLE()
153 wxCONSTRUCTOR_6( wxTextCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
155 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
)
159 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
160 EVT_CHAR(wxTextCtrl::OnChar
)
161 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
164 EVT_RIGHT_UP(wxTextCtrl::OnRightClick
)
167 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
168 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
169 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
170 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
171 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
172 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
173 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
175 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
176 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
177 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
178 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
179 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
180 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
181 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
183 EVT_SET_FOCUS(wxTextCtrl::OnSetFocus
)
186 // ============================================================================
188 // ============================================================================
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void wxTextCtrl::Init()
198 wxTextCtrl::~wxTextCtrl()
202 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
203 const wxString
& value
,
207 const wxValidator
& validator
,
208 const wxString
& name
)
213 // ----------------------------------------------------------------------------
214 // set/get the controls text
215 // ----------------------------------------------------------------------------
217 wxString
wxTextCtrl::GetValue() const
223 wxString
wxTextCtrl::GetRange(long from
, long to
) const
229 void wxTextCtrl::DoSetValue(const wxString
& value
, int flags
)
233 void wxTextCtrl::WriteText(const wxString
& value
)
237 void wxTextCtrl::DoWriteText(const wxString
& text
, int flags
)
241 void wxTextCtrl::AppendText(const wxString
& text
)
245 void wxTextCtrl::Clear()
249 // ----------------------------------------------------------------------------
250 // Clipboard operations
251 // ----------------------------------------------------------------------------
253 void wxTextCtrl::Copy()
257 void wxTextCtrl::Cut()
261 void wxTextCtrl::Paste()
265 bool wxTextCtrl::CanCopy() const
270 bool wxTextCtrl::CanCut() const
275 bool wxTextCtrl::CanPaste() const
280 // ----------------------------------------------------------------------------
282 // ----------------------------------------------------------------------------
284 void wxTextCtrl::SetEditable(bool editable
)
288 void wxTextCtrl::SetInsertionPoint(long pos
)
292 void wxTextCtrl::SetInsertionPointEnd()
296 long wxTextCtrl::GetInsertionPoint() const
301 wxTextPos
wxTextCtrl::GetLastPosition() const
306 // If the return values from and to are the same, there is no
308 void wxTextCtrl::GetSelection(long* from
, long* to
) const
312 bool wxTextCtrl::IsEditable() const
317 // ----------------------------------------------------------------------------
319 // ----------------------------------------------------------------------------
321 void wxTextCtrl::SetSelection(long from
, long to
)
325 void wxTextCtrl::DoSetSelection(long from
, long to
, int flags
)
329 // ----------------------------------------------------------------------------
330 // Working with files
331 // ----------------------------------------------------------------------------
333 bool wxTextCtrl::DoLoadFile(const wxString
& file
, int fileType
)
338 // ----------------------------------------------------------------------------
340 // ----------------------------------------------------------------------------
342 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
346 void wxTextCtrl::Remove(long from
, long to
)
350 bool wxTextCtrl::IsModified() const
355 void wxTextCtrl::MarkDirty()
359 void wxTextCtrl::DiscardEdits()
363 int wxTextCtrl::GetNumberOfLines() const
368 // ----------------------------------------------------------------------------
369 // Positions <-> coords
370 // ----------------------------------------------------------------------------
372 long wxTextCtrl::XYToPosition(long x
, long y
) const
377 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
382 wxTextCtrlHitTestResult
383 wxTextCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
385 return wxTE_HT_UNKNOWN
;
388 // ----------------------------------------------------------------------------
390 // ----------------------------------------------------------------------------
392 void wxTextCtrl::ShowPosition(long pos
)
396 long wxTextCtrl::GetLengthOfLineContainingPos(long pos
) const
401 int wxTextCtrl::GetLineLength(long lineNo
) const
406 wxString
wxTextCtrl::GetLineText(long lineNo
) const
413 void wxTextCtrl::SetMaxLength(unsigned long len
)
417 // ----------------------------------------------------------------------------
419 // ----------------------------------------------------------------------------
421 void wxTextCtrl::Undo()
425 void wxTextCtrl::Redo()
429 bool wxTextCtrl::CanUndo() const
434 bool wxTextCtrl::CanRedo() const
439 // ----------------------------------------------------------------------------
440 // caret handling (Windows only)
441 // ----------------------------------------------------------------------------
443 bool wxTextCtrl::ShowNativeCaret(bool show
)
448 // ----------------------------------------------------------------------------
449 // implemenation details
450 // ----------------------------------------------------------------------------
452 void wxTextCtrl::Command(wxCommandEvent
& event
)
456 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
460 // ----------------------------------------------------------------------------
461 // kbd input processing
462 // ----------------------------------------------------------------------------
464 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
468 // ----------------------------------------------------------------------------
469 // text control event processing
470 // ----------------------------------------------------------------------------
472 bool wxTextCtrl::SendUpdateEvent()
477 bool wxTextCtrl::AdjustSpaceLimit()
482 wxSize
wxTextCtrl::DoGetBestSize() const
487 // ----------------------------------------------------------------------------
488 // standard handlers for standard edit menu events
489 // ----------------------------------------------------------------------------
491 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
495 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
499 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
503 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
507 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
511 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
515 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
519 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
523 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
527 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
531 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
535 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
539 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
543 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
547 void wxTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
551 wxVisualAttributes
wxTextCtrl::GetDefaultAttributes() const
553 wxVisualAttributes attrs
;
554 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
555 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
556 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
); //white
560 bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent
& rEvent
)
564 bool wxTextCtrl::CanApplyThemeBorder() const
568 bool wxTextCtrl::IsEmpty() const
572 bool wxTextCtrl::AcceptsFocusFromKeyboard() const
576 void wxTextCtrl::AdoptAttributesFromHWND()
579 void wxTextCtrl::SetWindowStyleFlag(long lStyle
)
583 // the rest of the file only deals with the rich edit controls
586 // ----------------------------------------------------------------------------
587 // EN_LINK processing
588 // ----------------------------------------------------------------------------
590 bool wxTextCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
595 // ----------------------------------------------------------------------------
596 // colour setting for the rich edit controls
597 // ----------------------------------------------------------------------------
599 bool wxTextCtrl::SetBackgroundColour(const wxColour
& colour
)
604 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
609 // ----------------------------------------------------------------------------
611 // ----------------------------------------------------------------------------
613 bool wxRichEditModule::OnInit()
618 void wxRichEditModule::OnExit()
623 bool wxRichEditModule::Load(int version
)
628 #endif // wxUSE_RICHEDIT
630 // ----------------------------------------------------------------------------
631 // styling support for rich edit controls
632 // ----------------------------------------------------------------------------
636 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
641 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
646 bool wxTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
651 #endif // wxUSE_RICHEDIT
653 #endif // wxUSE_TEXTCTRL