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"
48 #include "wx/palmos/private.h"
49 #include "wx/palmos/winundef.h"
55 #include "wx/palmos/missing.h"
57 #endif // wxUSE_RICHEDIT
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
65 // this module initializes RichEdit DLL(s) if needed
66 class wxRichEditModule
: public wxModule
69 virtual bool OnInit();
70 virtual void OnExit();
72 // load the richedit DLL of at least of required version
73 static bool Load(int version
= 1);
76 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
77 static HINSTANCE ms_hRichEdit
[2];
79 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
82 HINSTANCE
wxRichEditModule::ms_hRichEdit
[2] = { NULL
, NULL
};
84 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
86 #endif // wxUSE_RICHEDIT
88 // ----------------------------------------------------------------------------
89 // event tables and other macros
90 // ----------------------------------------------------------------------------
92 #if wxUSE_EXTENDED_RTTI
93 WX_DEFINE_FLAGS( wxTextCtrlStyle
)
95 wxBEGIN_FLAGS( wxTextCtrlStyle
)
96 // new style border flags, we put them first to
97 // use them for streaming out
98 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
99 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
100 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
101 wxFLAGS_MEMBER(wxBORDER_RAISED
)
102 wxFLAGS_MEMBER(wxBORDER_STATIC
)
103 wxFLAGS_MEMBER(wxBORDER_NONE
)
105 // old style border flags
106 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
107 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
108 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
109 wxFLAGS_MEMBER(wxRAISED_BORDER
)
110 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
111 wxFLAGS_MEMBER(wxBORDER
)
113 // standard window styles
114 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
115 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
116 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
117 wxFLAGS_MEMBER(wxWANTS_CHARS
)
118 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
119 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
120 wxFLAGS_MEMBER(wxVSCROLL
)
121 wxFLAGS_MEMBER(wxHSCROLL
)
123 wxFLAGS_MEMBER(wxTE_PROCESS_ENTER
)
124 wxFLAGS_MEMBER(wxTE_PROCESS_TAB
)
125 wxFLAGS_MEMBER(wxTE_MULTILINE
)
126 wxFLAGS_MEMBER(wxTE_PASSWORD
)
127 wxFLAGS_MEMBER(wxTE_READONLY
)
128 wxFLAGS_MEMBER(wxHSCROLL
)
129 wxFLAGS_MEMBER(wxTE_RICH
)
130 wxFLAGS_MEMBER(wxTE_RICH2
)
131 wxFLAGS_MEMBER(wxTE_AUTO_URL
)
132 wxFLAGS_MEMBER(wxTE_NOHIDESEL
)
133 wxFLAGS_MEMBER(wxTE_LEFT
)
134 wxFLAGS_MEMBER(wxTE_CENTRE
)
135 wxFLAGS_MEMBER(wxTE_RIGHT
)
136 wxFLAGS_MEMBER(wxTE_DONTWRAP
)
137 wxFLAGS_MEMBER(wxTE_CHARWRAP
)
138 wxFLAGS_MEMBER(wxTE_WORDWRAP
)
140 wxEND_FLAGS( wxTextCtrlStyle
)
142 IMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl
, wxControl
,"wx/textctrl.h")
144 wxBEGIN_PROPERTIES_TABLE(wxTextCtrl
)
145 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
146 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
148 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
149 wxPROPERTY( Value
, wxString
, SetValue
, GetValue
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
150 wxPROPERTY_FLAGS( WindowStyle
, wxTextCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
151 wxEND_PROPERTIES_TABLE()
153 wxBEGIN_HANDLERS_TABLE(wxTextCtrl
)
154 wxEND_HANDLERS_TABLE()
156 wxCONSTRUCTOR_6( wxTextCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
158 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
)
162 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
163 EVT_CHAR(wxTextCtrl::OnChar
)
164 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
167 EVT_RIGHT_UP(wxTextCtrl::OnRightClick
)
170 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
171 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
172 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
173 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
174 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
175 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
176 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
178 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
179 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
180 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
181 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
182 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
183 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
184 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
186 EVT_SET_FOCUS(wxTextCtrl::OnSetFocus
)
189 // ============================================================================
191 // ============================================================================
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
197 void wxTextCtrl::Init()
201 wxTextCtrl::~wxTextCtrl()
205 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
206 const wxString
& value
,
210 const wxValidator
& validator
,
211 const wxString
& name
)
216 WXDWORD
wxTextCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
221 // ----------------------------------------------------------------------------
222 // set/get the controls text
223 // ----------------------------------------------------------------------------
225 wxString
wxTextCtrl::GetValue() const
232 void wxTextCtrl::DoSetValue(const wxString
& value
, int flags
)
236 void wxTextCtrl::WriteText(const wxString
& value
)
240 void wxTextCtrl::DoWriteText(const wxString
& value
, bool selectionOnly
)
244 void wxTextCtrl::AppendText(const wxString
& text
)
248 void wxTextCtrl::Clear()
252 // ----------------------------------------------------------------------------
253 // Clipboard operations
254 // ----------------------------------------------------------------------------
256 void wxTextCtrl::Copy()
260 void wxTextCtrl::Cut()
264 void wxTextCtrl::Paste()
268 bool wxTextCtrl::HasSelection() const
273 bool wxTextCtrl::CanCopy() const
278 bool wxTextCtrl::CanCut() const
283 bool wxTextCtrl::CanPaste() const
288 // ----------------------------------------------------------------------------
290 // ----------------------------------------------------------------------------
292 void wxTextCtrl::SetEditable(bool editable
)
296 void wxTextCtrl::SetInsertionPoint(long pos
)
300 void wxTextCtrl::SetInsertionPointEnd()
304 long wxTextCtrl::GetInsertionPoint() const
309 wxTextPos
wxTextCtrl::GetLastPosition() const
314 // If the return values from and to are the same, there is no
316 void wxTextCtrl::GetSelection(long* from
, long* to
) const
320 bool wxTextCtrl::IsEditable() const
325 // ----------------------------------------------------------------------------
327 // ----------------------------------------------------------------------------
329 void wxTextCtrl::SetSelection(long from
, long to
)
333 void wxTextCtrl::DoSetSelection(long from
, long to
, bool scrollCaret
)
337 // ----------------------------------------------------------------------------
338 // Working with files
339 // ----------------------------------------------------------------------------
341 bool wxTextCtrl::DoLoadFile(const wxString
& file
, int fileType
)
346 // ----------------------------------------------------------------------------
348 // ----------------------------------------------------------------------------
350 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
354 void wxTextCtrl::Remove(long from
, long to
)
358 bool wxTextCtrl::IsModified() const
363 void wxTextCtrl::MarkDirty()
367 void wxTextCtrl::DiscardEdits()
371 int wxTextCtrl::GetNumberOfLines() const
376 // ----------------------------------------------------------------------------
377 // Positions <-> coords
378 // ----------------------------------------------------------------------------
380 long wxTextCtrl::XYToPosition(long x
, long y
) const
385 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
390 wxTextCtrlHitTestResult
391 wxTextCtrl::HitTest(const wxPoint
& pt
, wxTextCoord
*col
, wxTextCoord
*row
) const
393 return wxTE_HT_UNKNOWN
;
396 // ----------------------------------------------------------------------------
398 // ----------------------------------------------------------------------------
400 void wxTextCtrl::ShowPosition(long pos
)
404 long wxTextCtrl::GetLengthOfLineContainingPos(long pos
) const
409 int wxTextCtrl::GetLineLength(long lineNo
) const
414 wxString
wxTextCtrl::GetLineText(long lineNo
) const
421 void wxTextCtrl::SetMaxLength(unsigned long len
)
425 // ----------------------------------------------------------------------------
427 // ----------------------------------------------------------------------------
429 void wxTextCtrl::Undo()
433 void wxTextCtrl::Redo()
437 bool wxTextCtrl::CanUndo() const
441 bool wxTextCtrl::CanRedo() const
445 // ----------------------------------------------------------------------------
446 // caret handling (Windows only)
447 // ----------------------------------------------------------------------------
449 bool wxTextCtrl::ShowNativeCaret(bool show
)
454 // ----------------------------------------------------------------------------
455 // implemenation details
456 // ----------------------------------------------------------------------------
458 void wxTextCtrl::Command(wxCommandEvent
& event
)
462 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
466 // ----------------------------------------------------------------------------
467 // kbd input processing
468 // ----------------------------------------------------------------------------
470 bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG
* pMsg
)
475 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
479 WXLRESULT
wxTextCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
484 // ----------------------------------------------------------------------------
485 // text control event processing
486 // ----------------------------------------------------------------------------
488 bool wxTextCtrl::SendUpdateEvent()
493 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
498 bool wxTextCtrl::AdjustSpaceLimit()
503 bool wxTextCtrl::AcceptsFocus() const
508 wxSize
wxTextCtrl::DoGetBestSize() const
513 // ----------------------------------------------------------------------------
514 // standard handlers for standard edit menu events
515 // ----------------------------------------------------------------------------
517 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
521 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
525 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
529 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
533 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
537 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
541 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
545 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
549 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
553 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
557 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
561 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
565 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
569 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
573 void wxTextCtrl::OnRightClick(wxMouseEvent
& event
)
577 void wxTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
581 // the rest of the file only deals with the rich edit controls
584 // ----------------------------------------------------------------------------
585 // EN_LINK processing
586 // ----------------------------------------------------------------------------
588 bool wxTextCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
593 // ----------------------------------------------------------------------------
594 // colour setting for the rich edit controls
595 // ----------------------------------------------------------------------------
597 bool wxTextCtrl::SetBackgroundColour(const wxColour
& colour
)
602 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
607 // ----------------------------------------------------------------------------
608 // styling support for rich edit controls
609 // ----------------------------------------------------------------------------
613 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
618 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
623 bool wxTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
630 // ----------------------------------------------------------------------------
632 // ----------------------------------------------------------------------------
634 bool wxRichEditModule::OnInit()
639 void wxRichEditModule::OnExit()
644 bool wxRichEditModule::Load(int version
)
649 #endif // wxUSE_RICHEDIT
651 #endif // wxUSE_TEXTCTRL