]>
Commit | Line | Data |
---|---|---|
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 | #include "wx/window.h" | |
30 | #include "wx/dataobj.h" | |
31 | #endif //WX_PRECOMP | |
32 | ||
33 | #include "wx/textentry.h" | |
34 | #include "wx/clipbrd.h" | |
35 | ||
36 | // ============================================================================ | |
37 | // wxTextEntryBase implementation | |
38 | // ============================================================================ | |
39 | ||
40 | wxString wxTextEntryBase::GetRange(long from, long to) const | |
41 | { | |
42 | wxString sel; | |
43 | wxString value = GetValue(); | |
44 | ||
45 | if ( from < to && (long)value.length() >= to ) | |
46 | { | |
47 | sel = value.substr(from, to - from); | |
48 | } | |
49 | ||
50 | return sel; | |
51 | } | |
52 | ||
53 | void wxTextEntryBase::AppendText(const wxString& text) | |
54 | { | |
55 | SetInsertionPointEnd(); | |
56 | WriteText(text); | |
57 | } | |
58 | ||
59 | void wxTextEntryBase::DoSetValue(const wxString& value, int flags) | |
60 | { | |
61 | EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent)); | |
62 | ||
63 | SelectAll(); | |
64 | WriteText(value); | |
65 | ||
66 | SetInsertionPoint(0); | |
67 | } | |
68 | ||
69 | void wxTextEntryBase::Replace(long from, long to, const wxString& value) | |
70 | { | |
71 | { | |
72 | EventsSuppressor noevents(this); | |
73 | Remove(from, to); | |
74 | } | |
75 | ||
76 | WriteText(value); | |
77 | } | |
78 | ||
79 | bool wxTextEntryBase::HasSelection() const | |
80 | { | |
81 | long from, to; | |
82 | GetSelection(&from, &to); | |
83 | ||
84 | return from < to; | |
85 | } | |
86 | ||
87 | void wxTextEntryBase::RemoveSelection() | |
88 | { | |
89 | long from, to; | |
90 | GetSelection(& from, & to); | |
91 | if (from != -1 && to != -1) | |
92 | Remove(from, to); | |
93 | } | |
94 | ||
95 | wxString wxTextEntryBase::GetStringSelection() const | |
96 | { | |
97 | long from, to; | |
98 | GetSelection(&from, &to); | |
99 | ||
100 | return GetRange(from, to); | |
101 | } | |
102 | ||
103 | bool wxTextEntryBase::CanCopy() const | |
104 | { | |
105 | return HasSelection(); | |
106 | } | |
107 | ||
108 | bool wxTextEntryBase::CanCut() const | |
109 | { | |
110 | return CanCopy() && IsEditable(); | |
111 | } | |
112 | ||
113 | bool wxTextEntryBase::CanPaste() const | |
114 | { | |
115 | if ( IsEditable() ) | |
116 | { | |
117 | #if wxUSE_CLIPBOARD | |
118 | // check if there is any text on the clipboard | |
119 | if ( wxTheClipboard->IsSupported(wxDF_TEXT) | |
120 | #if wxUSE_UNICODE | |
121 | || wxTheClipboard->IsSupported(wxDF_UNICODETEXT) | |
122 | #endif // wxUSE_UNICODE | |
123 | ) | |
124 | { | |
125 | return true; | |
126 | } | |
127 | #endif // wxUSE_CLIPBOARD | |
128 | } | |
129 | ||
130 | return false; | |
131 | } | |
132 | ||
133 | #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX |