Use ACO_AUTOAPPEND option for text completion in wxMSW.
[wxWidgets.git] / src / msw / textentry.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/textentry.cpp
3 // Purpose: wxTextEntry implementation for wxMSW
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 #ifndef WX_PRECOMP
27 #include "wx/arrstr.h"
28 #include "wx/string.h"
29 #endif // WX_PRECOMP
30
31 #if wxUSE_TEXTCTRL || wxUSE_COMBOBOX
32
33 #include "wx/textentry.h"
34 #include "wx/textcompleter.h"
35 #include "wx/dynlib.h"
36
37 #include "wx/msw/private.h"
38
39 #if wxUSE_UXTHEME
40 #include "wx/msw/uxtheme.h"
41 #endif
42
43 #define GetEditHwnd() ((HWND)(GetEditHWND()))
44
45 // ----------------------------------------------------------------------------
46 // wxIEnumString implements IEnumString interface
47 // ----------------------------------------------------------------------------
48
49 // standard VC6 SDK (WINVER == 0x0400) does not know about IAutoComplete
50 #if wxUSE_OLE && (WINVER >= 0x0500)
51 #define HAS_AUTOCOMPLETE
52 #endif
53
54 #ifdef HAS_AUTOCOMPLETE
55
56 #include "wx/msw/ole/oleutils.h"
57 #include <shldisp.h>
58 #include <shobjidl.h>
59
60 #if defined(__MINGW32__) || defined (__WATCOMC__) || defined(__CYGWIN__)
61 // needed for IID_IAutoComplete, IID_IAutoComplete2 and ACO_AUTOSUGGEST
62 #include <shlguid.h>
63 #endif
64
65 #ifndef ACO_UPDOWNKEYDROPSLIST
66 #define ACO_UPDOWNKEYDROPSLIST 0x20
67 #endif
68
69 #ifndef SHACF_FILESYS_ONLY
70 #define SHACF_FILESYS_ONLY 0x00000010
71 #endif
72
73 DEFINE_GUID(CLSID_AutoComplete,
74 0x00bb2763, 0x6a77, 0x11d0, 0xa5, 0x35, 0x00, 0xc0, 0x4f, 0xd7, 0xd0, 0x62);
75
76 class wxIEnumString : public IEnumString
77 {
78 public:
79 wxIEnumString()
80 {
81 m_index = 0;
82 }
83
84 wxIEnumString(const wxIEnumString& other)
85 : m_strings(other.m_strings),
86 m_index(other.m_index)
87 {
88 }
89
90 DECLARE_IUNKNOWN_METHODS;
91
92 virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt,
93 LPOLESTR *rgelt,
94 ULONG *pceltFetched)
95 {
96 if ( !rgelt || (!pceltFetched && celt > 1) )
97 return E_POINTER;
98
99 ULONG pceltFetchedDummy;
100 if ( !pceltFetched )
101 pceltFetched = &pceltFetchedDummy;
102
103 *pceltFetched = 0;
104
105 for ( const unsigned count = m_strings.size(); celt--; ++m_index )
106 {
107 if ( m_index == count )
108 return S_FALSE;
109
110 const wxWX2WCbuf wcbuf = m_strings[m_index].wc_str();
111 const size_t size = (wcslen(wcbuf) + 1)*sizeof(wchar_t);
112 void *olestr = CoTaskMemAlloc(size);
113 if ( !olestr )
114 return E_OUTOFMEMORY;
115
116 memcpy(olestr, wcbuf, size);
117
118 *rgelt++ = static_cast<LPOLESTR>(olestr);
119
120 ++(*pceltFetched);
121 }
122
123 return S_OK;
124 }
125
126 virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt)
127 {
128 m_index += celt;
129 if ( m_index > m_strings.size() )
130 {
131 m_index = m_strings.size();
132 return S_FALSE;
133 }
134
135 return S_OK;
136 }
137
138 virtual HRESULT STDMETHODCALLTYPE Reset()
139 {
140 m_index = 0;
141
142 return S_OK;
143 }
144
145 virtual HRESULT STDMETHODCALLTYPE Clone(IEnumString **ppEnum)
146 {
147 if ( !ppEnum )
148 return E_POINTER;
149
150 wxIEnumString *e = new wxIEnumString(*this);
151
152 e->AddRef();
153 *ppEnum = e;
154
155 return S_OK;
156 }
157
158 private:
159 // dtor doesn't have to be virtual as we're only ever deleted from our own
160 // Release() and are not meant to be derived form anyhow, but making it
161 // virtual silences gcc warnings; making it private makes it impossible to
162 // (mistakenly) delete us directly instead of calling Release()
163 virtual ~wxIEnumString() { }
164
165
166 wxArrayString m_strings;
167 unsigned m_index;
168
169 friend class wxTextAutoCompleteData;
170
171 wxDECLARE_NO_ASSIGN_CLASS(wxIEnumString);
172 };
173
174 BEGIN_IID_TABLE(wxIEnumString)
175 ADD_IID(Unknown)
176 ADD_IID(EnumString)
177 END_IID_TABLE;
178
179 IMPLEMENT_IUNKNOWN_METHODS(wxIEnumString)
180
181
182 // This class gathers the auto-complete-related we use. It is allocated on
183 // demand by wxTextEntry when AutoComplete() is called.
184 class wxTextAutoCompleteData wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS
185 {
186 public:
187 // The constructor associates us with the given text entry.
188 wxTextAutoCompleteData(wxTextEntry *entry)
189 : m_entry(entry),
190 m_win(entry->GetEditableWindow())
191 {
192 m_autoComplete = NULL;
193 m_autoCompleteDropDown = NULL;
194 m_enumStrings = NULL;
195 m_customCompleter = NULL;
196
197 m_connectedCharEvent = false;
198
199 // Create an object exposing IAutoComplete interface which we'll later
200 // use to get IAutoComplete2 as the latter can't be created directly,
201 // apparently.
202 HRESULT hr = CoCreateInstance
203 (
204 CLSID_AutoComplete,
205 NULL,
206 CLSCTX_INPROC_SERVER,
207 IID_IAutoComplete,
208 reinterpret_cast<void **>(&m_autoComplete)
209 );
210 if ( FAILED(hr) )
211 {
212 wxLogApiError(wxT("CoCreateInstance(CLSID_AutoComplete)"), hr);
213 return;
214 }
215
216 // Create a string enumerator and initialize the completer with it.
217 m_enumStrings = new wxIEnumString;
218 m_enumStrings->AddRef();
219 hr = m_autoComplete->Init(m_entry->GetEditHWND(), m_enumStrings,
220 NULL, NULL);
221 if ( FAILED(hr) )
222 {
223 wxLogApiError(wxT("IAutoComplete::Init"), hr);
224
225 m_enumStrings->Release();
226 m_enumStrings = NULL;
227
228 return;
229 }
230
231 // As explained in DoRefresh(), we need to call IAutoCompleteDropDown::
232 // ResetEnumerator() if we want to be able to change the completions on
233 // the fly. In principle we could live without it, i.e. return true
234 // from IsOk() even if this QueryInterface() fails, but it doesn't look
235 // like this is ever going to have in practice anyhow as the shell-
236 // provided IAutoComplete always implements IAutoCompleteDropDown too.
237 hr = m_autoComplete->QueryInterface
238 (
239 IID_IAutoCompleteDropDown,
240 reinterpret_cast<void **>(&m_autoCompleteDropDown)
241 );
242 if ( FAILED(hr) )
243 {
244 wxLogApiError(wxT("IAutoComplete::QI(IAutoCompleteDropDown)"), hr);
245 return;
246 }
247
248 // Finally set the completion options using IAutoComplete2.
249 IAutoComplete2 *pAutoComplete2 = NULL;
250 hr = m_autoComplete->QueryInterface
251 (
252 IID_IAutoComplete2,
253 reinterpret_cast<void **>(&pAutoComplete2)
254 );
255 if ( SUCCEEDED(hr) )
256 {
257 pAutoComplete2->SetOptions(ACO_AUTOSUGGEST |
258 ACO_AUTOAPPEND |
259 ACO_UPDOWNKEYDROPSLIST);
260 pAutoComplete2->Release();
261 }
262 }
263
264 ~wxTextAutoCompleteData()
265 {
266 delete m_customCompleter;
267
268 if ( m_enumStrings )
269 m_enumStrings->Release();
270 if ( m_autoCompleteDropDown )
271 m_autoCompleteDropDown->Release();
272 if ( m_autoComplete )
273 m_autoComplete->Release();
274 }
275
276 // Must be called after creating this object to verify if initializing it
277 // succeeded.
278 bool IsOk() const
279 {
280 return m_autoComplete && m_autoCompleteDropDown && m_enumStrings;
281 }
282
283 void ChangeStrings(const wxArrayString& strings)
284 {
285 m_enumStrings->m_strings = strings;
286
287 DoRefresh();
288 }
289
290 // Takes ownership of the pointer if it is non-NULL.
291 bool ChangeCustomCompleter(wxTextCompleter *completer)
292 {
293 delete m_customCompleter;
294 m_customCompleter = completer;
295
296 if ( m_customCompleter )
297 {
298 // We postpone connecting to this event until we really need to do
299 // it (however we don't disconnect from it when we don't need it
300 // any more because we don't have wxUNBIND_OR_DISCONNECT_HACK...).
301 if ( !m_connectedCharEvent )
302 {
303 m_connectedCharEvent = true;
304
305 // Use the special wxEVT_AFTER_CHAR and not the usual
306 // wxEVT_CHAR here because we need to have the updated value of
307 // the text control in this handler in order to provide
308 // completions for the correct prefix and unfortunately we
309 // don't have any way to let DefWindowProc() run from our
310 // wxEVT_CHAR handler (as we must also let the other handlers
311 // defined at wx level run first).
312 //
313 // Notice that we can't use wxEVT_COMMAND_TEXT_UPDATED here
314 // neither as, due to our use of ACO_AUTOAPPEND, we get
315 // EN_CHANGE notifications from the control every time
316 // IAutoComplete auto-appends something to it.
317 wxBIND_OR_CONNECT_HACK(m_win, wxEVT_AFTER_CHAR,
318 wxKeyEventHandler,
319 wxTextAutoCompleteData::OnAfterChar,
320 this);
321 }
322
323 UpdateStringsFromCustomCompleter();
324 }
325
326 return true;
327 }
328
329 void DisableCompletion()
330 {
331 // We currently simply reset the list of possible strings as this seems
332 // to effectively disable auto-completion just fine. We could (and
333 // probably should) use IAutoComplete::Enable(FALSE) for this too but
334 // then we'd need to call Enable(TRUE) to turn it on back again later.
335
336 m_enumStrings->m_strings.clear();
337 m_enumStrings->Reset();
338
339 ChangeCustomCompleter(NULL);
340 }
341
342 private:
343 // Must be called after changing wxIEnumString::m_strings to really make
344 // the changes stick.
345 void DoRefresh()
346 {
347 m_enumStrings->Reset();
348
349 // This is completely and utterly not documented and in fact the
350 // current MSDN seems to try to discourage us from using it by saying
351 // that "there is no reason to use this method unless the drop-down
352 // list is currently visible" but actually we absolutely must call it
353 // to force the auto-completer (and not just its drop-down!) to refresh
354 // the list of completions which could have changed now. Without this
355 // call the new choices returned by GetCompletions() that hadn't been
356 // returned by it before are simply silently ignored.
357 m_autoCompleteDropDown->ResetEnumerator();
358 }
359
360 // Update the strings returned by our string enumerator to correspond to
361 // the currently valid choices according to the custom completer.
362 void UpdateStringsFromCustomCompleter()
363 {
364 // As we use ACO_AUTOAPPEND, the selected part of the text is usually
365 // the one appended by us so don't consider it as part of the
366 // user-entered prefix.
367 long from, to;
368 m_entry->GetSelection(&from, &to);
369
370 if ( to == from )
371 from = m_entry->GetLastPosition(); // Take all if no selection.
372
373 const wxString prefix = m_entry->GetRange(0, from);
374
375 // For efficiency we access m_strings directly instead of creating
376 // another wxArrayString, normally this should save us an unnecessary
377 // memory allocation on the subsequent calls.
378 m_enumStrings->m_strings.clear();
379 m_customCompleter->GetCompletions(prefix, m_enumStrings->m_strings);
380
381 DoRefresh();
382 }
383
384 void OnAfterChar(wxKeyEvent& event)
385 {
386 // Notice that we must not refresh the completions when the user
387 // presses Backspace as this would result in adding back the just
388 // erased character(s) because of ACO_AUTOAPPEND option we use.
389 if ( m_customCompleter && event.GetKeyCode() != WXK_BACK )
390 UpdateStringsFromCustomCompleter();
391
392 event.Skip();
393 }
394
395
396 // The text entry we're associated with.
397 wxTextEntry * const m_entry;
398
399 // The window of this text entry.
400 wxWindow * const m_win;
401
402 // The auto-completer object itself.
403 IAutoComplete *m_autoComplete;
404
405 // Its IAutoCompleteDropDown interface needed for ResetEnumerator() call.
406 IAutoCompleteDropDown *m_autoCompleteDropDown;
407
408 // Enumerator for strings currently used for auto-completion.
409 wxIEnumString *m_enumStrings;
410
411 // Custom completer or NULL if none.
412 wxTextCompleter *m_customCompleter;
413
414 // Initially false, set to true after connecting OnTextChanged() handler.
415 bool m_connectedCharEvent;
416
417
418 wxDECLARE_NO_COPY_CLASS(wxTextAutoCompleteData);
419 };
420
421 #endif // HAS_AUTOCOMPLETE
422
423 // ============================================================================
424 // wxTextEntry implementation
425 // ============================================================================
426
427 // ----------------------------------------------------------------------------
428 // initialization and destruction
429 // ----------------------------------------------------------------------------
430
431 wxTextEntry::wxTextEntry()
432 {
433 #ifdef HAS_AUTOCOMPLETE
434 m_autoCompleteData = NULL;
435 #endif // HAS_AUTOCOMPLETE
436 }
437
438 wxTextEntry::~wxTextEntry()
439 {
440 #ifdef HAS_AUTOCOMPLETE
441 delete m_autoCompleteData;
442 #endif // HAS_AUTOCOMPLETE
443 }
444
445 // ----------------------------------------------------------------------------
446 // operations on text
447 // ----------------------------------------------------------------------------
448
449 void wxTextEntry::WriteText(const wxString& text)
450 {
451 ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());
452 }
453
454 wxString wxTextEntry::DoGetValue() const
455 {
456 return wxGetWindowText(GetEditHWND());
457 }
458
459 void wxTextEntry::Remove(long from, long to)
460 {
461 DoSetSelection(from, to, SetSel_NoScroll);
462 WriteText(wxString());
463 }
464
465 // ----------------------------------------------------------------------------
466 // clipboard operations
467 // ----------------------------------------------------------------------------
468
469 void wxTextEntry::Copy()
470 {
471 ::SendMessage(GetEditHwnd(), WM_COPY, 0, 0);
472 }
473
474 void wxTextEntry::Cut()
475 {
476 ::SendMessage(GetEditHwnd(), WM_CUT, 0, 0);
477 }
478
479 void wxTextEntry::Paste()
480 {
481 ::SendMessage(GetEditHwnd(), WM_PASTE, 0, 0);
482 }
483
484 // ----------------------------------------------------------------------------
485 // undo/redo
486 // ----------------------------------------------------------------------------
487
488 void wxTextEntry::Undo()
489 {
490 ::SendMessage(GetEditHwnd(), EM_UNDO, 0, 0);
491 }
492
493 void wxTextEntry::Redo()
494 {
495 // same as Undo, since Undo undoes the undo
496 Undo();
497 return;
498 }
499
500 bool wxTextEntry::CanUndo() const
501 {
502 return ::SendMessage(GetEditHwnd(), EM_CANUNDO, 0, 0) != 0;
503 }
504
505 bool wxTextEntry::CanRedo() const
506 {
507 // see comment in Redo()
508 return CanUndo();
509 }
510
511 // ----------------------------------------------------------------------------
512 // insertion point and selection
513 // ----------------------------------------------------------------------------
514
515 void wxTextEntry::SetInsertionPoint(long pos)
516 {
517 // calling DoSetSelection(-1, -1) would select everything which is not what
518 // we want here
519 if ( pos == -1 )
520 pos = GetLastPosition();
521
522 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
523 // and not just SetSelection() here
524 DoSetSelection(pos, pos);
525 }
526
527 long wxTextEntry::GetInsertionPoint() const
528 {
529 long from;
530 GetSelection(&from, NULL);
531 return from;
532 }
533
534 long wxTextEntry::GetLastPosition() const
535 {
536 return ::SendMessage(GetEditHwnd(), EM_LINELENGTH, 0, 0);
537 }
538
539 void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags))
540 {
541 // if from and to are both -1, it means (in wxWidgets) that all text should
542 // be selected, translate this into Windows convention
543 if ( (from == -1) && (to == -1) )
544 {
545 from = 0;
546 }
547
548 ::SendMessage(GetEditHwnd(), EM_SETSEL, from, to);
549 }
550
551 void wxTextEntry::GetSelection(long *from, long *to) const
552 {
553 DWORD dwStart, dwEnd;
554 ::SendMessage(GetEditHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
555
556 if ( from )
557 *from = dwStart;
558 if ( to )
559 *to = dwEnd;
560 }
561
562 // ----------------------------------------------------------------------------
563 // auto-completion
564 // ----------------------------------------------------------------------------
565
566 #if wxUSE_OLE
567
568 #ifdef HAS_AUTOCOMPLETE
569
570 bool wxTextEntry::DoAutoCompleteFileNames()
571 {
572 typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD);
573 static SHAutoComplete_t s_pfnSHAutoComplete = (SHAutoComplete_t)-1;
574 static wxDynamicLibrary s_dllShlwapi;
575 if ( s_pfnSHAutoComplete == (SHAutoComplete_t)-1 )
576 {
577 if ( !s_dllShlwapi.Load(wxT("shlwapi.dll"), wxDL_VERBATIM | wxDL_QUIET) )
578 {
579 s_pfnSHAutoComplete = NULL;
580 }
581 else
582 {
583 wxDL_INIT_FUNC(s_pfn, SHAutoComplete, s_dllShlwapi);
584 }
585 }
586
587 if ( !s_pfnSHAutoComplete )
588 return false;
589
590 HRESULT hr = (*s_pfnSHAutoComplete)(GetEditHwnd(), SHACF_FILESYS_ONLY);
591 if ( FAILED(hr) )
592 {
593 wxLogApiError(wxT("SHAutoComplete()"), hr);
594
595 return false;
596 }
597
598 // Disable the other kinds of completion now that we use the built-in file
599 // names completion.
600 if ( m_autoCompleteData )
601 m_autoCompleteData->DisableCompletion();
602
603 return true;
604 }
605
606 wxTextAutoCompleteData *wxTextEntry::GetOrCreateCompleter()
607 {
608 if ( !m_autoCompleteData )
609 {
610 wxTextAutoCompleteData * const ac = new wxTextAutoCompleteData(this);
611 if ( ac->IsOk() )
612 m_autoCompleteData = ac;
613 else
614 delete ac;
615 }
616
617 return m_autoCompleteData;
618 }
619
620 bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices)
621 {
622 wxTextAutoCompleteData * const ac = GetOrCreateCompleter();
623 if ( !ac )
624 return false;
625
626 ac->ChangeStrings(choices);
627
628 return true;
629 }
630
631 bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer)
632 {
633 // First deal with the case when we just want to disable auto-completion.
634 if ( !completer )
635 {
636 if ( m_autoCompleteData )
637 m_autoCompleteData->DisableCompletion();
638 //else: Nothing to do, we hadn't used auto-completion even before.
639 }
640 else // Have a valid completer.
641 {
642 wxTextAutoCompleteData * const ac = GetOrCreateCompleter();
643 if ( !ac )
644 {
645 // Delete the custom completer for consistency with the case when
646 // we succeed to avoid memory leaks in user code.
647 delete completer;
648 return false;
649 }
650
651 // This gives ownership of the custom completer to m_autoCompleteData.
652 if ( !ac->ChangeCustomCompleter(completer) )
653 return false;
654 }
655
656 return true;
657 }
658
659 #else // !HAS_AUTOCOMPLETE
660
661 // We still need to define stubs as we declared these overrides in the header.
662
663 bool wxTextEntry::DoAutoCompleteFileNames()
664 {
665 return wxTextEntryBase::DoAutoCompleteFileNames();
666 }
667
668 bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices)
669 {
670 return wxTextEntryBase::DoAutoCompleteStrings(choices);
671 }
672
673 #endif // HAS_AUTOCOMPLETE/!HAS_AUTOCOMPLETE
674
675 #endif // wxUSE_OLE
676
677 // ----------------------------------------------------------------------------
678 // editable state
679 // ----------------------------------------------------------------------------
680
681 bool wxTextEntry::IsEditable() const
682 {
683 return !(::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY);
684 }
685
686 void wxTextEntry::SetEditable(bool editable)
687 {
688 ::SendMessage(GetEditHwnd(), EM_SETREADONLY, !editable, 0);
689 }
690
691 // ----------------------------------------------------------------------------
692 // max length
693 // ----------------------------------------------------------------------------
694
695 void wxTextEntry::SetMaxLength(unsigned long len)
696 {
697 if ( len >= 0xffff )
698 {
699 // this will set it to a platform-dependent maximum (much more
700 // than 64Kb under NT)
701 len = 0;
702 }
703
704 ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0);
705 }
706
707 // ----------------------------------------------------------------------------
708 // hints
709 // ----------------------------------------------------------------------------
710
711 #if wxUSE_UXTHEME
712
713 #ifndef EM_SETCUEBANNER
714 #define EM_SETCUEBANNER 0x1501
715 #define EM_GETCUEBANNER 0x1502
716 #endif
717
718 bool wxTextEntry::SetHint(const wxString& hint)
719 {
720 if ( wxUxThemeEngine::GetIfActive() )
721 {
722 // notice that this message always works with Unicode strings
723 //
724 // we always use TRUE for wParam to show the hint even when the window
725 // has focus, otherwise there would be no way to show the hint for the
726 // initially focused window
727 if ( ::SendMessage(GetEditHwnd(), EM_SETCUEBANNER,
728 TRUE, (LPARAM)(const wchar_t *)hint.wc_str()) )
729 return true;
730 }
731
732 return wxTextEntryBase::SetHint(hint);
733 }
734
735 wxString wxTextEntry::GetHint() const
736 {
737 if ( wxUxThemeEngine::GetIfActive() )
738 {
739 wchar_t buf[256];
740 if ( ::SendMessage(GetEditHwnd(), EM_GETCUEBANNER,
741 (WPARAM)buf, WXSIZEOF(buf)) )
742 return wxString(buf);
743 }
744
745 return wxTextEntryBase::GetHint();
746 }
747
748
749 #endif // wxUSE_UXTHEME
750
751 // ----------------------------------------------------------------------------
752 // margins support
753 // ----------------------------------------------------------------------------
754
755 bool wxTextEntry::DoSetMargins(const wxPoint& margins)
756 {
757 #if !defined(__WXWINCE__)
758 bool res = true;
759
760 if ( margins.x != -1 )
761 {
762 // left margin
763 ::SendMessage(GetEditHwnd(), EM_SETMARGINS,
764 EC_LEFTMARGIN, MAKELONG(margins.x, 0));
765 }
766
767 if ( margins.y != -1 )
768 {
769 res = false;
770 }
771
772 return res;
773 #else
774 return false;
775 #endif
776 }
777
778 wxPoint wxTextEntry::DoGetMargins() const
779 {
780 #if !defined(__WXWINCE__)
781 LRESULT lResult = ::SendMessage(GetEditHwnd(), EM_GETMARGINS,
782 0, 0);
783 int left = LOWORD(lResult);
784 int top = -1;
785 return wxPoint(left, top);
786 #else
787 return wxPoint(-1, -1);
788 #endif
789 }
790
791 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX