-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathodcombo.cpp
More file actions
3867 lines (3155 loc) · 107 KB
/
odcombo.cpp
File metadata and controls
3867 lines (3155 loc) · 107 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/////////////////////////////////////////////////////////////////////////////
// Name: odcombo.cpp
// Purpose: wxPGOwnerDrawnComboBox and related classes implementation
// Author: Jaakko Salli
// Modified by:
// Created: Jan-25-2005
// RCS-ID: $Id:
// Copyright: (c) 2005 Jaakko Salli
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_COMBOBOX
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/log.h"
#include "wx/button.h"
#include "wx/combobox.h"
#include "wx/textctrl.h"
#include "wx/dcclient.h"
#include "wx/settings.h"
#include "wx/dialog.h"
#endif
#include "wx/dcbuffer.h"
#include "wx/tooltip.h"
#include "wx/timer.h"
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
#include "wx/msw/uxtheme.h"
#endif
#include <wx/propgrid/propgrid.h>
#if !wxPG_USING_WXOWNERDRAWNCOMBOBOX
#include "wx/propgrid/odcombo.h"
//
// THESE GO TO BASE FILE
//
#define BMP_BUTTON_MARGIN 4
//#define DEFAULT_POPUP_HEIGHT -1
#define DEFAULT_POPUP_HEIGHT 300
#define DEFAULT_TEXT_INDENT 3
#if defined(__WXMSW__)
#define ALLOW_FAKE_POPUP 0 // Use only on plats with problems with wxPopupWindow
#define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
//#undef wxUSE_POPUPWIN
//#define wxUSE_POPUPWIN 0
#elif defined(__WXGTK__)
// Fake popup windows cause focus problems on GTK2 (but enable on GTK1.2, just in case)
#if defined(__WXGTK20__)
#define ALLOW_FAKE_POPUP 0 // Use only on plats with problems with wxPopupWindow
#else
#define ALLOW_FAKE_POPUP 1 // Use only on plats with problems with wxPopupWindow
#endif
#define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
#elif defined(__WXMAC__)
#define ALLOW_FAKE_POPUP 1 // Use only on plats with problems with wxPopupWindow
#define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
#else
#define ALLOW_FAKE_POPUP 1 // Use only on plats with problems with wxPopupWindow
#define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
#endif
// Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
// what the wxUSE_POPUPWIN says.
#if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
#undef wxUSE_POPUPWIN
#define wxUSE_POPUPWIN 0
#endif
#if wxUSE_POPUPWIN
#include "wx/popupwin.h"
#else
#undef USE_TRANSIENT_POPUP
#define USE_TRANSIENT_POPUP 0
#endif
// For versions < 2.6.2, don't enable transient popup. There may be
// problems I don't have time to test properly.
#if !wxCHECK_VERSION(2, 6, 2)
#undef USE_TRANSIENT_POPUP
#define USE_TRANSIENT_POPUP 0
#endif
#if USE_TRANSIENT_POPUP
#undef ALLOW_FAKE_POPUP
#define ALLOW_FAKE_POPUP 0
#define wxPGComboPopupWindowBase wxPopupTransientWindow
#define INSTALL_TOPLEV_HANDLER 0
#elif wxUSE_POPUPWIN
#define wxPGComboPopupWindowBase wxPopupWindow
#define INSTALL_TOPLEV_HANDLER 1
#else
#define wxPGComboPopupWindowBase wxDialog
#if !ALLOW_FAKE_POPUP
#define INSTALL_TOPLEV_HANDLER 0 // Doesn't need since can monitor active event
#else
#define INSTALL_TOPLEV_HANDLER 1
#endif
#endif
//
// THESE GO TO GENERIC FILE
//
// Some adjustments to make the generic more bearable
#if defined(__WXUNIVERSAL__)
#define TEXTCTRLXADJUST 0 // position adjustment for wxTextCtrl, with zero indent
#define TEXTCTRLYADJUST 0
#define TEXTXADJUST 0 // how much is read-only text's x adjusted
#define DEFAULT_DROPBUTTON_WIDTH 19
#elif defined(__WXMSW__)
#define TEXTCTRLXADJUST 2 // position adjustment for wxTextCtrl, with zero indent
#define TEXTCTRLYADJUST 3
#define TEXTXADJUST 0 // how much is read-only text's x adjusted
#define DEFAULT_DROPBUTTON_WIDTH 17
#elif defined(__WXGTK__)
#define TEXTCTRLXADJUST -1 // position adjustment for wxTextCtrl, with zero indent
#define TEXTCTRLYADJUST 0
#define TEXTXADJUST 1 // how much is read-only text's x adjusted
#define DEFAULT_DROPBUTTON_WIDTH 23
#elif defined(__WXMAC__)
#define TEXTCTRLXADJUST 0 // position adjustment for wxTextCtrl, with zero indent
#define TEXTCTRLYADJUST 0
#define TEXTXADJUST 0 // how much is read-only text's x adjusted
#define DEFAULT_DROPBUTTON_WIDTH 19
#else
#define TEXTCTRLXADJUST 0 // position adjustment for wxTextCtrl, with zero indent
#define TEXTCTRLYADJUST 0
#define TEXTXADJUST 0 // how much is read-only text's x adjusted
#define DEFAULT_DROPBUTTON_WIDTH 19
#endif
// constants
// ----------------------------------------------------------------------------
// TO BASE
// the margin between the text control and the combo button
static const wxCoord g_comboMargin = 2;
// ----------------------------------------------------------------------------
// wxPGComboFrameEventHandler takes care of hiding the popup when events happen
// in its top level parent.
// ----------------------------------------------------------------------------
#if INSTALL_TOPLEV_HANDLER
//
// This will no longer be necessary after wxTransientPopupWindow
// works well on all platforms.
//
class wxPGComboFrameEventHandler : public wxEvtHandler
{
public:
wxPGComboFrameEventHandler( wxPGComboControlBase* pCb );
~wxPGComboFrameEventHandler();
void OnPopup();
void OnIdle( wxIdleEvent& event );
void OnMouseEvent( wxMouseEvent& event );
void OnActivate( wxActivateEvent& event );
void OnResize( wxSizeEvent& event );
void OnMove( wxMoveEvent& event );
void OnMenuEvent( wxMenuEvent& event );
void OnClose( wxCloseEvent& event );
protected:
wxWindow* m_focusStart;
wxPGComboControlBase* m_combo;
private:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxPGComboFrameEventHandler, wxEvtHandler)
EVT_IDLE(wxPGComboFrameEventHandler::OnIdle)
EVT_LEFT_DOWN(wxPGComboFrameEventHandler::OnMouseEvent)
EVT_RIGHT_DOWN(wxPGComboFrameEventHandler::OnMouseEvent)
EVT_SIZE(wxPGComboFrameEventHandler::OnResize)
EVT_MOVE(wxPGComboFrameEventHandler::OnMove)
EVT_MENU_HIGHLIGHT(wxID_ANY,wxPGComboFrameEventHandler::OnMenuEvent)
EVT_MENU_OPEN(wxPGComboFrameEventHandler::OnMenuEvent)
EVT_ACTIVATE(wxPGComboFrameEventHandler::OnActivate)
EVT_CLOSE(wxPGComboFrameEventHandler::OnClose)
END_EVENT_TABLE()
wxPGComboFrameEventHandler::wxPGComboFrameEventHandler( wxPGComboControlBase* combo )
: wxEvtHandler()
{
m_combo = combo;
}
wxPGComboFrameEventHandler::~wxPGComboFrameEventHandler()
{
}
void wxPGComboFrameEventHandler::OnPopup()
{
m_focusStart = ::wxWindow::FindFocus();
}
void wxPGComboFrameEventHandler::OnIdle( wxIdleEvent& event )
{
wxWindow* winFocused = ::wxWindow::FindFocus();
wxWindow* popup = m_combo->GetPopupControl();
wxWindow* winpopup = m_combo->GetPopupWindow();
if (
winFocused != m_focusStart &&
winFocused != popup &&
winFocused->GetParent() != popup &&
winFocused != winpopup &&
winFocused->GetParent() != winpopup &&
winFocused != m_combo &&
winFocused != m_combo->GetButton() // GTK (atleast) requires this
)
{
m_combo->HidePopup();
}
event.Skip();
}
void wxPGComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event )
{
m_combo->HidePopup();
event.Skip();
}
void wxPGComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event )
{
m_combo->HidePopup();
event.Skip();
}
void wxPGComboFrameEventHandler::OnClose( wxCloseEvent& event )
{
m_combo->HidePopup();
event.Skip();
}
void wxPGComboFrameEventHandler::OnActivate( wxActivateEvent& event )
{
m_combo->HidePopup();
event.Skip();
}
void wxPGComboFrameEventHandler::OnResize( wxSizeEvent& event )
{
m_combo->HidePopup();
event.Skip();
}
void wxPGComboFrameEventHandler::OnMove( wxMoveEvent& event )
{
m_combo->HidePopup();
event.Skip();
}
#endif // INSTALL_TOPLEV_HANDLER
// ----------------------------------------------------------------------------
// wxPGComboPopupWindow is wxPopupWindow customized for
// wxComboControl.
// ----------------------------------------------------------------------------
class wxPGComboPopupWindow : public wxPGComboPopupWindowBase
{
public:
wxPGComboPopupWindow( wxPGComboControlBase *parent, int style = wxBORDER_NONE );
#if USE_TRANSIENT_POPUP
virtual bool ProcessLeftDown(wxMouseEvent& event);
#endif
void OnKeyEvent(wxKeyEvent& event);
void OnMouseEvent( wxMouseEvent& event );
#if !wxUSE_POPUPWIN
void OnActivate( wxActivateEvent& event );
#endif
protected:
#if USE_TRANSIENT_POPUP
virtual void OnDismiss();
#endif
private:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxPGComboPopupWindow, wxPGComboPopupWindowBase)
EVT_MOUSE_EVENTS(wxPGComboPopupWindow::OnMouseEvent)
#if !wxUSE_POPUPWIN
EVT_ACTIVATE(wxPGComboPopupWindow::OnActivate)
#endif
EVT_KEY_DOWN(wxPGComboPopupWindow::OnKeyEvent)
EVT_KEY_UP(wxPGComboPopupWindow::OnKeyEvent)
END_EVENT_TABLE()
wxPGComboPopupWindow::wxPGComboPopupWindow( wxPGComboControlBase *parent,
int style )
#if wxUSE_POPUPWIN
: wxPGComboPopupWindowBase(parent,style)
#else
: wxPGComboPopupWindowBase(parent,
wxID_ANY,
wxEmptyString,
wxPoint(-21,-21),
wxSize(20,20),
style)
#endif
{
}
void wxPGComboPopupWindow::OnKeyEvent( wxKeyEvent& event )
{
// Relay keyboard event to the main child controls
// (just skipping may just cause the popup to close)
wxWindowList children = GetChildren();
wxWindowList::iterator node = children.begin();
wxWindow* child = (wxWindow*)*node;
child->AddPendingEvent(event);
}
void wxPGComboPopupWindow::OnMouseEvent( wxMouseEvent& event )
{
event.Skip();
}
#if !wxUSE_POPUPWIN
void wxPGComboPopupWindow::OnActivate( wxActivateEvent& event )
{
if ( !event.GetActive() )
{
// Tell combo control that we are dismissed.
wxPGComboControl* combo = (wxPGComboControl*) GetParent();
wxASSERT( combo );
wxASSERT( combo->IsKindOf(CLASSINFO(wxPGComboControl)) );
combo->HidePopup();
event.Skip();
}
}
#endif
#if USE_TRANSIENT_POPUP
bool wxPGComboPopupWindow::ProcessLeftDown(wxMouseEvent& event )
{
return wxPGComboPopupWindowBase::ProcessLeftDown(event);
}
#endif
#if USE_TRANSIENT_POPUP
// First thing that happens when a transient popup closes is that this method gets called.
void wxPGComboPopupWindow::OnDismiss()
{
wxPGComboControlBase* combo = (wxPGComboControlBase*) GetParent();
wxASSERT ( combo->IsKindOf(CLASSINFO(wxPGComboControlBase)) );
combo->OnPopupDismiss();
}
#endif
// ----------------------------------------------------------------------------
// wxPGComboPopup methods
//
// ----------------------------------------------------------------------------
wxPGComboPopup::~wxPGComboPopup()
{
}
void wxPGComboPopup::OnPopup()
{
}
void wxPGComboPopup::OnDismiss()
{
}
wxSize wxPGComboPopup::GetAdjustedSize( int minWidth,
int prefHeight,
int WXUNUSED(maxHeight) )
{
return wxSize(minWidth,prefHeight);
}
void wxPGComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect )
{
if ( m_combo->GetWindowStyle() & wxCB_READONLY ) // ie. no textctrl
{
m_combo->DrawFocusBackground(dc,rect,0);
dc.DrawText( GetStringValue(),
rect.x + m_combo->GetTextIndent(),
(rect.height-dc.GetCharHeight())/2 + m_combo->m_widthCustomBorder );
}
}
void wxPGComboPopup::OnComboKeyEvent( wxKeyEvent& event )
{
event.Skip();
}
void wxPGComboPopup::OnComboDoubleClick()
{
}
void wxPGComboPopup::SetStringValue( const wxString& WXUNUSED(value) )
{
}
bool wxPGComboPopup::LazyCreate()
{
return false;
}
void wxPGComboPopup::Dismiss()
{
m_combo->HidePopup();
}
// ----------------------------------------------------------------------------
// wxPGVListBoxComboPopup is a wxVListBox customized to act as a popup control
//
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxPGVListBoxComboPopup, wxVListBox)
EVT_MOTION(wxPGVListBoxComboPopup::OnMouseMove)
EVT_KEY_DOWN(wxPGVListBoxComboPopup::OnKey)
EVT_LEFT_UP(wxPGVListBoxComboPopup::OnLeftClick)
#if wxCHECK_VERSION(2,8,0)
EVT_MOUSE_CAPTURE_LOST(wxPGVListBoxComboPopup::OnMouseCaptureLost)
#endif
END_EVENT_TABLE()
wxPGVListBoxComboPopup::wxPGVListBoxComboPopup(wxPGComboControl* combo)
: wxVListBox(), wxPGComboPopup(combo)
{
//m_callback = callback;
m_widestWidth = 0;
m_avgCharWidth = 0;
m_baseImageWidth = 0;
m_itemHeight = 0;
m_value = -1;
m_itemHover = -1;
m_clientDataItemsType = wxClientData_None;
}
bool wxPGVListBoxComboPopup::Create(wxWindow* parent)
{
if ( !wxVListBox::Create(parent,
wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
wxBORDER_SIMPLE | wxLB_INT_HEIGHT | wxWANTS_CHARS) )
return false;
m_font = m_combo->GetFont();
wxVListBox::SetItemCount(m_strings.GetCount());
// TODO: Move this to SetFont
m_itemHeight = GetCharHeight() + 0;
return true;
}
wxPGVListBoxComboPopup::~wxPGVListBoxComboPopup()
{
Clear();
}
bool wxPGVListBoxComboPopup::LazyCreate()
{
// NB: There is a bug with wxVListBox that can be avoided by creating
// it later (bug causes empty space to be shown if initial selection
// is at the end of a list longer than the control can show at once).
return true;
}
// paint the control itself
void wxPGVListBoxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect )
{
if ( !(m_combo->GetWindowStyle() & wxODCB_STD_CONTROL_PAINT) )
{
int flags = wxPGCC_PAINTING_CONTROL;
if ( m_combo->ShouldDrawFocus() )
flags |= wxPGCC_PAINTING_SELECTED;
m_combo->DrawFocusBackground(dc,rect,0);
if ( m_combo->OnDrawItem(dc,rect,m_value,flags) )
return;
}
wxPGComboPopup::PaintComboControl(dc,rect);
}
void wxPGVListBoxComboPopup::OnDrawItem( wxDC& dc, const wxRect& rect, size_t n) const
{
dc.SetFont(m_font);
bool isHilited = wxVListBox::GetSelection() == (int) n;
// Set correct text colour for selected items
// (must always set the correct colour - atleast GTK may have lost it
// in between calls).
if ( isHilited )
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) );
else
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
if ( !m_combo->OnDrawItem(dc,rect,(int)n,0) )
dc.DrawText( GetString(n), rect.x + 2, rect.y );
}
wxCoord wxPGVListBoxComboPopup::OnMeasureItem(size_t n) const
{
int itemHeight = m_combo->OnMeasureItem(n);
if ( itemHeight < 0 )
itemHeight = m_itemHeight;
return itemHeight;
}
void wxPGVListBoxComboPopup::OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const
{
// we need to render selected and current items differently
if ( IsCurrent(n) )
{
m_combo->DrawFocusBackground( dc, rect, wxCONTROL_ISSUBMENU|wxCONTROL_SELECTED );
}
//else: do nothing for the normal items
}
void wxPGVListBoxComboPopup::DismissWithEvent()
{
int selection = wxVListBox::GetSelection();
Dismiss();
if ( selection != wxNOT_FOUND )
m_stringValue = m_strings[selection];
else
m_stringValue = wxEmptyString;
if ( m_stringValue != m_combo->GetValue() )
m_combo->SetValue(m_stringValue);
m_value = selection;
SendComboBoxEvent(selection);
}
void wxPGVListBoxComboPopup::SendComboBoxEvent( int selection )
{
wxCommandEvent evt(wxEVT_COMMAND_COMBOBOX_SELECTED,m_combo->GetId());
evt.SetEventObject(m_combo);
evt.SetInt(selection);
// Set client data, if any
if ( selection >= 0 && (int)m_clientDatas.GetCount() > selection )
{
void* clientData = m_clientDatas[selection];
if ( m_clientDataItemsType == wxClientData_Object )
evt.SetClientObject((wxClientData*)clientData);
else
evt.SetClientData(clientData);
}
m_combo->GetEventHandler()->AddPendingEvent(evt);
}
// returns true if key was consumed
bool wxPGVListBoxComboPopup::HandleKey( int keycode, bool saturate )
{
int value = m_value;
int itemCount = GetCount();
if ( itemCount == 0 )
return false;
if ( keycode == WXK_DOWN || keycode == WXK_RIGHT )
{
value++;
}
else if ( keycode == WXK_UP || keycode == WXK_LEFT )
{
value--;
}
else if ( keycode == WXK_PAGEDOWN )
{
value+=10;
}
else if ( keycode == WXK_PAGEUP )
{
value-=10;
}
/*
else if ( keycode == WXK_END )
{
value = itemCount-1;
}
else if ( keycode == WXK_HOME )
{
value = 0;
}
*/
else
return false;
if ( saturate )
{
if ( value >= itemCount )
value = itemCount - 1;
else if ( value < 0 )
value = 0;
}
else
{
if ( value >= itemCount )
value -= itemCount;
else if ( value < 0 )
value += itemCount;
}
if ( value == m_value )
// Even if value was same, don't skip the event
// (good for consistency)
return true;
m_value = value;
wxString valStr;
if ( value >= 0 )
m_combo->SetValue(m_strings[value]);
SendComboBoxEvent(m_value);
return true;
}
void wxPGVListBoxComboPopup::OnComboDoubleClick()
{
// Cycle on dclick (disable saturation to allow true cycling).
if ( !::wxGetKeyState(WXK_SHIFT) )
HandleKey(WXK_DOWN,false);
else
HandleKey(WXK_UP,false);
}
void wxPGVListBoxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
{
// Saturated key movement on
if ( !HandleKey(event.GetKeyCode(),true) )
event.Skip();
}
void wxPGVListBoxComboPopup::OnPopup()
{
// *must* set value after size is set (this is because of a vlbox bug)
wxVListBox::SetSelection(m_value);
}
void wxPGVListBoxComboPopup::OnMouseMove(wxMouseEvent& event)
{
// Move selection to cursor if it is inside the popup
int itemHere = GetItemAtPosition(event.GetPosition());
if ( itemHere >= 0 )
wxVListBox::SetSelection(itemHere);
event.Skip();
}
void wxPGVListBoxComboPopup::OnLeftClick(wxMouseEvent& WXUNUSED(event))
{
DismissWithEvent();
}
void wxPGVListBoxComboPopup::OnKey(wxKeyEvent& event)
{
// Select item if ENTER is pressed
if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER )
{
DismissWithEvent();
}
// Hide popup if ESC is pressed
else if ( event.GetKeyCode() == WXK_ESCAPE )
Dismiss();
else
event.Skip();
}
void wxPGVListBoxComboPopup::CheckWidth( int pos )
{
wxCoord x = m_combo->OnMeasureItemWidth(pos);
if ( x < 0 )
{
if ( !m_font.Ok() )
m_font = m_combo->GetFont();
wxCoord y;
m_combo->GetTextExtent(m_strings[pos], &x, &y, 0, 0, &m_font);
x += 4;
}
if ( m_widestWidth < x )
{
m_widestWidth = x;
}
}
void wxPGVListBoxComboPopup::Insert( const wxString& item, int pos )
{
// Need to change selection?
wxString strValue;
if ( !(m_combo->GetWindowStyle() & wxCB_READONLY) &&
m_combo->GetValue() == item )
m_value = pos;
else if ( m_value >= pos )
m_value++;
m_strings.Insert(item,pos);
if ( IsCreated() )
wxVListBox::SetItemCount( wxVListBox::GetItemCount()+1 );
// Calculate width
CheckWidth(pos);
}
int wxPGVListBoxComboPopup::Append(const wxString& item)
{
int pos = (int)m_strings.GetCount();
if ( m_combo->GetWindowStyle() & wxCB_SORT )
{
// Find position
// TODO: Could be optimized with binary search
wxArrayString strings = m_strings;
unsigned int i;
for ( i=0; i<strings.GetCount(); i++ )
{
if ( item.Cmp(strings.Item(i)) < 0 )
{
pos = (int)i;
break;
}
}
}
Insert(item,pos);
return pos;
}
void wxPGVListBoxComboPopup::Clear()
{
wxASSERT(m_combo);
m_strings.Empty();
ClearClientDatas();
if ( IsCreated() )
wxVListBox::SetItemCount(0);
}
void wxPGVListBoxComboPopup::ClearClientDatas()
{
if ( m_clientDataItemsType == wxClientData_Object )
{
size_t i;
for ( i=0; i<m_clientDatas.GetCount(); i++ )
delete (wxClientData*) m_clientDatas[i];
}
m_clientDatas.Empty();
}
void wxPGVListBoxComboPopup::SetItemClientData( wxODCIndex n,
void* clientData,
wxClientDataType clientDataItemsType )
{
// It should be sufficient to update this variable only here
m_clientDataItemsType = clientDataItemsType;
m_clientDatas.SetCount(n+1,NULL);
m_clientDatas[n] = clientData;
}
void* wxPGVListBoxComboPopup::GetItemClientData(wxODCIndex n) const
{
if ( ((wxODCIndex)m_clientDatas.GetCount()) > n )
return m_clientDatas[n];
return NULL;
}
void wxPGVListBoxComboPopup::Delete( wxODCIndex item )
{
// Remove client data, if set
if ( m_clientDatas.GetCount() )
{
if ( m_clientDataItemsType == wxClientData_Object )
delete (wxClientData*) m_clientDatas[item];
m_clientDatas.RemoveAt(item);
}
m_strings.RemoveAt(item);
int sel = GetSelection();
if ( IsCreated() )
wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
if ( (int)item < sel )
SetSelection(sel-1);
else if ( (int)item == sel )
SetSelection(wxNOT_FOUND);
}
int wxPGVListBoxComboPopup::FindString(const wxString& s) const
{
return m_strings.Index(s);
}
wxODCCount wxPGVListBoxComboPopup::GetCount() const
{
return m_strings.GetCount();
}
wxString wxPGVListBoxComboPopup::GetString( int item ) const
{
return m_strings[item];
}
void wxPGVListBoxComboPopup::SetString( int item, const wxString& str )
{
m_strings[item] = str;
}
wxString wxPGVListBoxComboPopup::GetStringValue() const
{
return m_stringValue;
}
void wxPGVListBoxComboPopup::SetSelection( int item )
{
// This seems to be necessary (2.5.3 w/ MingW atleast)
if ( item < -1 || item >= (int)m_strings.GetCount() )
item = -1;
m_value = item;
if ( item >= 0 )
m_stringValue = m_strings[item];
else
m_stringValue = wxEmptyString;
if ( IsCreated() )
wxVListBox::SetSelection(item);
}
int wxPGVListBoxComboPopup::GetSelection() const
{
return m_value;
}
void wxPGVListBoxComboPopup::SetStringValue( const wxString& value )
{
int index = m_strings.Index(value);
m_stringValue = value;
if ( index >= 0 && index < (int)wxVListBox::GetItemCount() )
{
wxVListBox::SetSelection(index);
m_value = index;
}
}
wxSize wxPGVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
{
int height = 250;
if ( m_strings.GetCount() )
{
if ( prefHeight > 0 )
height = prefHeight;
if ( height > maxHeight )
height = maxHeight;
int totalHeight = GetTotalHeight(); // + 3;
if ( height >= totalHeight )
{
height = totalHeight;
}
else
{
// Adjust height to a multiple of the height of the first item
// NB: Calculations that take variable height into account
// are unnecessary.
int fih = GetLineHeight(0);
int shown = height/fih;
height = shown * fih;
}
}
else
height = 50;
// JACS
#if defined(__WXMAC__)
// Set a minimum height since otherwise scrollbars won't draw properly
height = wxMax(50, height);
#endif
// Take scrollbar into account in width calculations
int widestWidth = m_widestWidth + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
return wxSize(minWidth > widestWidth ? minWidth : widestWidth,
height+2);
}
void wxPGVListBoxComboPopup::Populate( int n, const wxString choices[] )
{
int i;
for ( i=0; i<n; i++ )
{