]> git.saurik.com Git - wxWidgets.git/blob - src/common/textentrycmn.cpp
refactor wxMSW code to extract parts common to wxTextCtrl and wxComboBox into wxTextEntry
[wxWidgets.git] / src / common / textentrycmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/textentrycmn.cpp
3 // Purpose: wxTextEntryBase implementation
4 // Author: Vadim Zeitlin
5 // Created: 2007-09-26
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_TEXTCTRL || wxUSE_COMBOBOX
27
28 #ifndef WX_PRECOMP
29 #endif //WX_PRECOMP
30
31 #include "wx/textentry.h"
32 #include "wx/clipbrd.h"
33
34 // ============================================================================
35 // wxTextEntryBase implementation
36 // ============================================================================
37
38 wxString wxTextEntryBase::GetRange(long from, long to) const
39 {
40 wxString sel;
41 if ( from < to )
42 {
43 sel = GetValue().substr(from, to - from);
44 }
45
46 return sel;
47 }
48
49 void wxTextEntryBase::AppendText(const wxString& text)
50 {
51 SetInsertionPointEnd();
52 WriteText(text);
53 }
54
55 void wxTextEntryBase::DoSetValue(const wxString& value, int flags)
56 {
57 EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent));
58
59 SelectAll();
60 WriteText(value);
61 }
62
63 void wxTextEntryBase::Replace(long from, long to, const wxString& value)
64 {
65 {
66 EventsSuppressor noevents(this);
67 Remove(from, to);
68 }
69
70 WriteText(value);
71 }
72
73 bool wxTextEntryBase::HasSelection() const
74 {
75 long from, to;
76 GetSelection(&from, &to);
77
78 return from < to;
79 }
80
81 wxString wxTextEntryBase::GetStringSelection() const
82 {
83 long from, to;
84 GetSelection(&from, &to);
85
86 return GetRange(from, to);
87 }
88
89 bool wxTextEntryBase::CanCopy() const
90 {
91 return HasSelection();
92 }
93
94 bool wxTextEntryBase::CanCut() const
95 {
96 return CanCopy() && IsEditable();
97 }
98
99 bool wxTextEntryBase::CanPaste() const
100 {
101 if ( IsEditable() )
102 {
103 #if wxUSE_CLIPBOARD
104 // check if there is any text on the clipboard
105 if ( wxTheClipboard->IsSupported(wxDF_TEXT) )
106 return true;
107 #endif // wxUSE_CLIPBOARD
108 }
109
110 return false;
111 }
112
113 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX