]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/combobxc.cpp
Include wx/icon.h according to precompiled headers of wx/wx.h (with other minor clean...
[wxWidgets.git] / src / mac / carbon / combobxc.cpp
CommitLineData
46cc7c4e 1/////////////////////////////////////////////////////////////////////////////
3c24dad6
SC
2// Name: src/mac/carbon/combobxc.cpp
3// Purpose: wxComboBox class using HIView ComboBox
46cc7c4e
SC
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
46cc7c4e
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
46cc7c4e 14#include "wx/combobox.h"
f1e01716
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/button.h"
3b3dc801 18 #include "wx/menu.h"
f1e01716
WS
19#endif
20
46cc7c4e 21#include "wx/mac/uma.h"
c829d62b 22#if TARGET_API_MAC_OSX
46cc7c4e 23#ifndef __HIVIEW__
7d8268a1 24 #include <HIToolbox/HIView.h>
46cc7c4e 25#endif
c829d62b 26#endif
46cc7c4e 27
46cc7c4e 28IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
46cc7c4e 29
c829d62b 30#if TARGET_API_MAC_OSX
46cc7c4e 31#define USE_HICOMBOBOX 1 //use hi combobox define
c829d62b
SC
32#else
33#define USE_HICOMBOBOX 0
34#endif
46cc7c4e 35
3c24dad6 36static int nextPopUpMenuId = 1000;
150e31d2 37MenuHandle NewUniqueMenu()
46cc7c4e 38{
3c24dad6
SC
39 MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" );
40 nextPopUpMenuId++;
41 return handle;
46cc7c4e
SC
42}
43
21fd5529
SC
44#if USE_HICOMBOBOX
45static const EventTypeSpec eventList[] =
46{
47 { kEventClassTextField , kEventTextAccepted } ,
3c24dad6 48};
21fd5529
SC
49
50static pascal OSStatus wxMacComboBoxEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
51{
3c24dad6
SC
52 OSStatus result = eventNotHandledErr;
53 wxComboBox* cb = (wxComboBox*) data;
150e31d2 54
3c24dad6 55 wxMacCarbonEvent cEvent( event );
21fd5529
SC
56
57 switch( cEvent.GetClass() )
58 {
59 case kEventClassTextField :
60 switch( cEvent.GetKind() )
61 {
62 case kEventTextAccepted :
63 {
64 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, cb->GetId() );
65 event.SetInt( cb->GetSelection() );
66 event.SetString( cb->GetStringSelection() );
67 event.SetEventObject( cb );
68 cb->GetEventHandler()->ProcessEvent( event );
69 }
3c24dad6 70 break;
21fd5529 71 default :
3c24dad6 72 break;
21fd5529 73 }
3c24dad6 74 break;
21fd5529 75 default :
3c24dad6 76 break;
21fd5529 77 }
150e31d2 78
21fd5529 79
3c24dad6 80 return result;
21fd5529
SC
81}
82
83DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacComboBoxEventHandler )
84
85#endif
46cc7c4e
SC
86
87// ----------------------------------------------------------------------------
88// constants
89// ----------------------------------------------------------------------------
90
91// the margin between the text control and the choice
92static const wxCoord MARGIN = 2;
93#if TARGET_API_MAC_OSX
94static const int POPUPWIDTH = 24;
95#else
96static const int POPUPWIDTH = 18;
97#endif
98static const int POPUPHEIGHT = 23;
99
100// ----------------------------------------------------------------------------
101// wxComboBoxText: text control forwards events to combobox
102// ----------------------------------------------------------------------------
103
104class wxComboBoxText : public wxTextCtrl
105{
106public:
107 wxComboBoxText( wxComboBox * cb )
108 : wxTextCtrl( cb , 1 )
109 {
110 m_cb = cb;
111 }
112
113protected:
114 void OnChar( wxKeyEvent& event )
115 {
116 if ( event.GetKeyCode() == WXK_RETURN )
117 {
118 wxString value = GetValue();
119
120 if ( m_cb->GetCount() == 0 )
121 {
122 // make Enter generate "selected" event if there is only one item
123 // in the combobox - without it, it's impossible to select it at
124 // all!
125 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, m_cb->GetId() );
126 event.SetInt( 0 );
127 event.SetString( value );
128 event.SetEventObject( m_cb );
129 m_cb->GetEventHandler()->ProcessEvent( event );
130 }
131 else
132 {
133 // add the item to the list if it's not there yet
134 if ( m_cb->FindString(value) == wxNOT_FOUND )
135 {
136 m_cb->Append(value);
137 m_cb->SetStringSelection(value);
138
139 // and generate the selected event for it
140 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, m_cb->GetId() );
141 event.SetInt( m_cb->GetCount() - 1 );
142 event.SetString( value );
143 event.SetEventObject( m_cb );
144 m_cb->GetEventHandler()->ProcessEvent( event );
145 }
146
147 // This will invoke the dialog default action, such
148 // as the clicking the default button.
149
150 wxWindow *parent = GetParent();
151 while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
3c24dad6 152 parent = parent->GetParent();
46cc7c4e
SC
153 }
154 if ( parent && parent->GetDefaultItem() )
155 {
156 wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
157 wxButton);
158 if ( def && def->IsEnabled() )
159 {
160 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
161 event.SetEventObject(def);
162 def->Command(event);
3c24dad6 163 return;
3dee36ae 164 }
46cc7c4e
SC
165 }
166
167 return;
168 }
169 }
150e31d2 170
46cc7c4e
SC
171 event.Skip();
172 }
173private:
174 wxComboBox *m_cb;
175
176 DECLARE_EVENT_TABLE()
177};
178
179BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl)
180 EVT_CHAR( wxComboBoxText::OnChar)
181END_EVENT_TABLE()
182
183class wxComboBoxChoice : public wxChoice
184{
185public:
186 wxComboBoxChoice(wxComboBox *cb, int style)
187 : wxChoice( cb , 1 )
188 {
189 m_cb = cb;
190 }
191
192protected:
193 void OnChoice( wxCommandEvent& e )
194 {
195 wxString s = e.GetString();
196
197 m_cb->DelegateChoice( s );
198 wxCommandEvent event2(wxEVT_COMMAND_COMBOBOX_SELECTED, m_cb->GetId() );
199 event2.SetInt(m_cb->GetSelection());
200 event2.SetEventObject(m_cb);
201 event2.SetString(m_cb->GetStringSelection());
202 m_cb->ProcessCommand(event2);
203 }
204 virtual wxSize DoGetBestSize() const
205 {
3c24dad6
SC
206 wxSize sz = wxChoice::DoGetBestSize();
207 sz.x = POPUPWIDTH;
208 return sz;
150e31d2 209 }
46cc7c4e
SC
210
211private:
212 wxComboBox *m_cb;
213
214 DECLARE_EVENT_TABLE()
215};
216
217BEGIN_EVENT_TABLE(wxComboBoxChoice, wxChoice)
3dee36ae 218 EVT_CHOICE(wxID_ANY, wxComboBoxChoice::OnChoice)
46cc7c4e
SC
219END_EVENT_TABLE()
220
221wxComboBox::~wxComboBox()
222{
223 // delete client objects
224 FreeData();
225
226 // delete the controls now, don't leave them alive even though they would
227 // still be eventually deleted by our parent - but it will be too late, the
228 // user code expects them to be gone now
229 if (m_text != NULL) {
230 delete m_text;
231 m_text = NULL;
232 }
233 if (m_choice != NULL) {
234 delete m_choice;
235 m_choice = NULL;
236 }
237}
238
239
240// ----------------------------------------------------------------------------
241// geometry
242// ----------------------------------------------------------------------------
243
244wxSize wxComboBox::DoGetBestSize() const
245{
246#if USE_HICOMBOBOX
7d8268a1 247 return wxControl::DoGetBestSize();
46cc7c4e
SC
248#else
249 wxSize size = m_choice->GetBestSize();
150e31d2 250
46cc7c4e
SC
251 if ( m_text != NULL )
252 {
253 wxSize sizeText = m_text->GetBestSize();
150e31d2 254
46cc7c4e
SC
255 size.x = POPUPWIDTH + sizeText.x + MARGIN;
256 }
257
258 return size;
259#endif
260}
261
262void wxComboBox::DoMoveWindow(int x, int y, int width, int height) {
263#if USE_HICOMBOBOX
7d8268a1 264 wxControl::DoMoveWindow(x, y, width, height);
46cc7c4e
SC
265#else
266 height = POPUPHEIGHT;
150e31d2 267
46cc7c4e
SC
268 wxControl::DoMoveWindow(x, y, width, height);
269
270 if ( m_text == NULL )
271 {
272 // we might not be fully constructed yet, therefore watch out...
273 if ( m_choice )
3dee36ae 274 m_choice->SetSize(0, 0 , width, wxDefaultCoord);
46cc7c4e
SC
275 }
276 else
277 {
278 wxCoord wText = width - POPUPWIDTH - MARGIN;
279 m_text->SetSize(0, 0, wText, height);
3dee36ae 280 m_choice->SetSize(0 + wText + MARGIN, 0, POPUPWIDTH, wxDefaultCoord);
46cc7c4e 281 }
150e31d2 282#endif
46cc7c4e
SC
283}
284
285
286
287// ----------------------------------------------------------------------------
288// operations forwarded to the subcontrols
289// ----------------------------------------------------------------------------
290
291bool wxComboBox::Enable(bool enable)
292{
293 if ( !wxControl::Enable(enable) )
7d8268a1 294 return false;
46cc7c4e 295
7d8268a1 296 return true;
46cc7c4e
SC
297}
298
299bool wxComboBox::Show(bool show)
300{
301 if ( !wxControl::Show(show) )
7d8268a1 302 return false;
46cc7c4e 303
7d8268a1 304 return true;
46cc7c4e
SC
305}
306
307void wxComboBox::SetFocus()
308{
309#if USE_HICOMBOBOX
7d8268a1 310 wxControl::SetFocus();
46cc7c4e
SC
311#else
312 if ( m_text != NULL) {
313 m_text->SetFocus();
314 }
315#endif
316}
317
318
319void wxComboBox::DelegateTextChanged( const wxString& value )
320{
321 SetStringSelection( value );
322}
323
324
325void wxComboBox::DelegateChoice( const wxString& value )
326{
327 SetStringSelection( value );
328}
329
330
331bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
332 const wxString& value,
333 const wxPoint& pos,
334 const wxSize& size,
335 const wxArrayString& choices,
336 long style,
337 const wxValidator& validator,
338 const wxString& name)
339{
340 wxCArrayString chs( choices );
341
342 return Create( parent, id, value, pos, size, chs.GetCount(),
343 chs.GetStrings(), style, validator, name );
344}
345
346
347bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
348 const wxString& value,
349 const wxPoint& pos,
350 const wxSize& size,
351 int n, const wxString choices[],
352 long style,
353 const wxValidator& validator,
354 const wxString& name)
355{
356 m_text = NULL;
357 m_choice = NULL;
358#if USE_HICOMBOBOX
3c24dad6 359 m_macIsUserPane = false;
46cc7c4e
SC
360#endif
361 if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
362 wxDefaultValidator, name) )
363 {
7d8268a1 364 return false;
46cc7c4e
SC
365 }
366#if USE_HICOMBOBOX
3c24dad6 367 Rect bounds = wxMacGetBoundsForControl( this , pos , size );
46cc7c4e 368 HIRect hiRect;
150e31d2 369
46cc7c4e
SC
370 hiRect.origin.x = 20; //bounds.left;
371 hiRect.origin.y = 25; //bounds.top;
372 hiRect.size.width = 120;// bounds.right - bounds.left;
150e31d2
JS
373 hiRect.size.height = 24;
374
46cc7c4e
SC
375 //For some reason, this code causes the combo box not to be displayed at all.
376 //hiRect.origin.x = bounds.left;
377 //hiRect.origin.y = bounds.top;
378 //hiRect.size.width = bounds.right - bounds.left;
379 //hiRect.size.height = bounds.bottom - bounds.top;
380 //printf("left = %d, right = %d, top = %d, bottom = %d\n", bounds.left, bounds.right, bounds.top, bounds.bottom);
7d8268a1 381 //printf("x = %d, y = %d, width = %d, height = %d\n", hibounds.origin.x, hibounds.origin.y, hibounds.size.width, hibounds.size.height);
3c24dad6
SC
382 m_peer = new wxMacControl(this);
383 verify_noerr( HIComboBoxCreate( &hiRect, CFSTR(""), NULL, NULL, kHIComboBoxStandardAttributes, m_peer->GetControlRefAddr() ) );
150e31d2 384
46cc7c4e 385
3c24dad6
SC
386 m_peer->SetMinimum( 0 );
387 m_peer->SetMaximum( 100);
46cc7c4e 388 if ( n > 0 )
3c24dad6 389 m_peer->SetValue( 1 );
150e31d2 390
3c24dad6 391 MacPostControlCreate(pos,size);
150e31d2 392
3c24dad6 393 for ( int i = 0; i < n; i++ )
46cc7c4e
SC
394 {
395 DoAppend( choices[ i ] );
396 }
150e31d2 397
3c24dad6 398 HIViewSetVisible( m_peer->GetControlRef(), true );
46cc7c4e 399 SetSelection(0);
3c24dad6
SC
400 EventHandlerRef comboEventHandler;
401 InstallControlEventHandler( m_peer->GetControlRef(), GetwxMacComboBoxEventHandlerUPP(),
150e31d2 402 GetEventTypeCount(eventList), eventList, this,
21fd5529 403 (EventHandlerRef *)&comboEventHandler);
46cc7c4e
SC
404#else
405 m_choice = new wxComboBoxChoice(this, style );
406
407 m_choice = new wxComboBoxChoice(this, style );
3c24dad6 408 m_choice->SetSizeHints( wxSize( POPUPWIDTH , POPUPHEIGHT ) );
150e31d2 409
46cc7c4e
SC
410 wxSize csize = size;
411 if ( style & wxCB_READONLY )
412 {
413 m_text = NULL;
414 }
415 else
416 {
417 m_text = new wxComboBoxText(this);
3dee36ae 418 if ( size.y == wxDefaultCoord ) {
3c24dad6 419 csize.y = m_text->GetSize().y;
46cc7c4e
SC
420 }
421 }
150e31d2 422
46cc7c4e 423 DoSetSize(pos.x, pos.y, csize.x, csize.y);
150e31d2 424
3c24dad6 425 for ( int i = 0; i < n; i++ )
46cc7c4e
SC
426 {
427 m_choice->DoAppend( choices[ i ] );
428 }
429 SetBestSize(csize); // Needed because it is a wxControlWithItems
430#endif
431
7d8268a1 432 return true;
46cc7c4e
SC
433}
434
435wxString wxComboBox::GetValue() const
436{
437#if USE_HICOMBOBOX
438 CFStringRef myString;
3c24dad6 439 HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)GetSelection(), &myString );
46cc7c4e
SC
440 return wxMacCFStringHolder( myString, m_font.GetEncoding() ).AsString();
441#else
442 wxString result;
150e31d2 443
46cc7c4e
SC
444 if ( m_text == NULL )
445 {
446 result = m_choice->GetString( m_choice->GetSelection() );
447 }
448 else
449 {
450 result = m_text->GetValue();
451 }
150e31d2 452
46cc7c4e
SC
453 return result;
454#endif
455}
456
457void wxComboBox::SetValue(const wxString& value)
458{
459#if USE_HICOMBOBOX
150e31d2 460
46cc7c4e
SC
461#else
462 int s = FindString (value);
463 if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) )
464 {
3c24dad6 465 m_choice->Append(value);
46cc7c4e 466 }
3c24dad6 467 SetStringSelection( value );
46cc7c4e
SC
468#endif
469}
470
471// Clipboard operations
472void wxComboBox::Copy()
473{
474 if ( m_text != NULL )
475 {
476 m_text->Copy();
477 }
478}
479
480void wxComboBox::Cut()
481{
482 if ( m_text != NULL )
483 {
484 m_text->Cut();
485 }
486}
487
488void wxComboBox::Paste()
489{
490 if ( m_text != NULL )
491 {
492 m_text->Paste();
493 }
494}
495
496void wxComboBox::SetEditable(bool editable)
497{
498 if ( ( m_text == NULL ) && editable )
499 {
500 m_text = new wxComboBoxText( this );
501 }
502 else if ( ( m_text != NULL ) && !editable )
503 {
504 delete m_text;
505 m_text = NULL;
506 }
507
508 int currentX, currentY;
509 GetPosition( &currentX, &currentY );
150e31d2 510
46cc7c4e
SC
511 int currentW, currentH;
512 GetSize( &currentW, &currentH );
513
514 DoMoveWindow( currentX, currentY, currentW, currentH );
515}
516
517void wxComboBox::SetInsertionPoint(long pos)
518{
519 // TODO
520}
521
522void wxComboBox::SetInsertionPointEnd()
523{
524 // TODO
525}
526
527long wxComboBox::GetInsertionPoint() const
528{
529 // TODO
530 return 0;
531}
532
7d8268a1 533wxTextPos wxComboBox::GetLastPosition() const
46cc7c4e
SC
534{
535 // TODO
536 return 0;
537}
538
539void wxComboBox::Replace(long from, long to, const wxString& value)
540{
541 // TODO
542}
543
544void wxComboBox::Remove(long from, long to)
545{
546 // TODO
547}
548
549void wxComboBox::SetSelection(long from, long to)
550{
551 // TODO
552}
553
150e31d2 554int wxComboBox::DoAppend(const wxString& item)
46cc7c4e
SC
555{
556#if USE_HICOMBOBOX
557 CFIndex outIndex;
3c24dad6
SC
558 HIComboBoxAppendTextItem( m_peer->GetControlRef(), wxMacCFStringHolder( item, m_font.GetEncoding() ), &outIndex );
559 //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
46cc7c4e
SC
560 return (int) outIndex;
561#else
3c24dad6 562 return m_choice->DoAppend( item );
46cc7c4e
SC
563#endif
564}
565
aa61d352 566int wxComboBox::DoInsert(const wxString& item, unsigned int pos)
46cc7c4e
SC
567{
568#if USE_HICOMBOBOX
3c24dad6 569 HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) );
150e31d2 570
3c24dad6 571 //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
150e31d2 572
46cc7c4e
SC
573 return pos;
574#else
3c24dad6 575 return m_choice->DoInsert( item , pos );
46cc7c4e
SC
576#endif
577}
578
aa61d352 579void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
46cc7c4e
SC
580{
581#if USE_HICOMBOBOX
582 return; //TODO
583#else
3c24dad6 584 return m_choice->DoSetItemClientData( n , clientData );
46cc7c4e
SC
585#endif
586}
587
aa61d352 588void* wxComboBox::DoGetItemClientData(unsigned int n) const
46cc7c4e
SC
589{
590#if USE_HICOMBOBOX
591 return NULL; //TODO
592#else
3c24dad6 593 return m_choice->DoGetItemClientData( n );
46cc7c4e
SC
594#endif
595}
596
aa61d352 597void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
46cc7c4e
SC
598{
599#if USE_HICOMBOBOX
600 return; //TODO
601#else
3c24dad6 602 return m_choice->DoSetItemClientObject( n , clientData );
46cc7c4e
SC
603#endif
604}
605
aa61d352 606wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const
46cc7c4e
SC
607{
608#if USE_HICOMBOBOX
609 return NULL;
610#else
3c24dad6 611 return m_choice->DoGetItemClientObject( n );
46cc7c4e
SC
612#endif
613}
614
615void wxComboBox::FreeData()
616{
aa61d352 617 if (HasClientObjectData())
46cc7c4e 618 {
aa61d352
VZ
619 unsigned int count = GetCount();
620 for ( unsigned int n = 0; n < count; n++ )
46cc7c4e
SC
621 {
622 SetClientObject( n, NULL );
623 }
624 }
625}
626
aa61d352 627unsigned int wxComboBox::GetCount() const {
46cc7c4e 628#if USE_HICOMBOBOX
3c24dad6 629 return (unsigned int) HIComboBoxGetItemCount( m_peer->GetControlRef() );
46cc7c4e 630#else
3c24dad6 631 return m_choice->GetCount();
46cc7c4e
SC
632#endif
633}
634
aa61d352 635void wxComboBox::Delete(unsigned int n)
46cc7c4e
SC
636{
637#if USE_HICOMBOBOX
3c24dad6 638 HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex)n );
46cc7c4e
SC
639#else
640 // force client object deletion
641 if( HasClientObjectData() )
642 SetClientObject( n, NULL );
643 m_choice->Delete( n );
644#endif
645}
646
647void wxComboBox::Clear()
648{
b310cebd 649 FreeData();
46cc7c4e 650#if USE_HICOMBOBOX
3c24dad6
SC
651 for ( CFIndex i = GetCount() - 1; i >= 0; ++ i )
652 verify_noerr( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), i ) );
21fd5529 653 m_peer->SetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag,CFSTR(""));
46cc7c4e 654#else
46cc7c4e
SC
655 m_choice->Clear();
656#endif
657}
658
659int wxComboBox::GetSelection() const
660{
661#if USE_HICOMBOBOX
3c24dad6 662 return FindString( GetStringSelection() );
46cc7c4e
SC
663#else
664 return m_choice->GetSelection();
665#endif
666}
667
668void wxComboBox::SetSelection(int n)
669{
670#if USE_HICOMBOBOX
3c24dad6 671 SetControl32BitValue( m_peer->GetControlRef() , n + 1 );
46cc7c4e
SC
672#else
673 m_choice->SetSelection( n );
150e31d2 674
46cc7c4e
SC
675 if ( m_text != NULL )
676 {
aa61d352 677 m_text->SetValue(GetString(n));
46cc7c4e
SC
678 }
679#endif
680}
681
11e62fe6 682int wxComboBox::FindString(const wxString& s, bool bCase) const
46cc7c4e
SC
683{
684#if USE_HICOMBOBOX
aa61d352 685 for( unsigned int i = 0 ; i < GetCount() ; i++ )
46cc7c4e 686 {
aa61d352 687 if (GetString(i).IsSameAs(s, bCase) )
46cc7c4e
SC
688 return i ;
689 }
3c24dad6 690 return wxNOT_FOUND;
46cc7c4e 691#else
11e62fe6 692 return m_choice->FindString( s, bCase );
46cc7c4e
SC
693#endif
694}
695
aa61d352 696wxString wxComboBox::GetString(unsigned int n) const
46cc7c4e
SC
697{
698#if USE_HICOMBOBOX
699 CFStringRef itemText;
3c24dad6 700 HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)n, &itemText );
46cc7c4e
SC
701 return wxMacCFStringHolder(itemText).AsString();
702#else
703 return m_choice->GetString( n );
704#endif
705}
706
707wxString wxComboBox::GetStringSelection() const
708{
b310cebd 709#if USE_HICOMBOBOX
3c24dad6 710 return wxMacCFStringHolder(m_peer->GetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag)).AsString();
b310cebd 711#else
46cc7c4e 712 int sel = GetSelection ();
aa61d352
VZ
713 if (sel != wxNOT_FOUND)
714 return wxString(this->GetString((unsigned int)sel));
46cc7c4e
SC
715 else
716 return wxEmptyString;
b310cebd 717#endif
46cc7c4e
SC
718}
719
aa61d352 720void wxComboBox::SetString(unsigned int n, const wxString& s)
46cc7c4e
SC
721{
722#if USE_HICOMBOBOX
3c24dad6 723 verify_noerr ( HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex) n,
b310cebd 724 wxMacCFStringHolder(s, m_font.GetEncoding()) ) );
3c24dad6 725 verify_noerr ( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex) n + 1 ) );
46cc7c4e 726#else
3c24dad6 727 m_choice->SetString( n , s );
46cc7c4e
SC
728#endif
729}
730
150e31d2
JS
731bool wxComboBox::IsEditable() const
732{
733#if USE_HICOMBOBOX
7d8268a1
WS
734 // TODO
735 return !HasFlag(wxCB_READONLY);
150e31d2 736#else
7d8268a1 737 return m_text != NULL && !HasFlag(wxCB_READONLY);
150e31d2
JS
738#endif
739}
740
741void wxComboBox::Undo()
742{
743#if USE_HICOMBOBOX
7d8268a1 744 // TODO
150e31d2
JS
745#else
746 if (m_text != NULL)
747 m_text->Undo();
748#endif
749}
750
751void wxComboBox::Redo()
752{
753#if USE_HICOMBOBOX
7d8268a1 754 // TODO
150e31d2
JS
755#else
756 if (m_text != NULL)
757 m_text->Redo();
758#endif
759}
760
761void wxComboBox::SelectAll()
762{
763#if USE_HICOMBOBOX
7d8268a1 764 // TODO
150e31d2
JS
765#else
766 if (m_text != NULL)
767 m_text->SelectAll();
768#endif
769}
770
771bool wxComboBox::CanCopy() const
772{
773#if USE_HICOMBOBOX
7d8268a1
WS
774 // TODO
775 return false;
150e31d2
JS
776#else
777 if (m_text != NULL)
778 return m_text->CanCopy();
779 else
780 return false;
781#endif
782}
783
784bool wxComboBox::CanCut() const
785{
786#if USE_HICOMBOBOX
7d8268a1
WS
787 // TODO
788 return false;
150e31d2
JS
789#else
790 if (m_text != NULL)
791 return m_text->CanCut();
792 else
793 return false;
794#endif
795}
796
797bool wxComboBox::CanPaste() const
798{
799#if USE_HICOMBOBOX
7d8268a1
WS
800 // TODO
801 return false;
150e31d2
JS
802#else
803 if (m_text != NULL)
804 return m_text->CanPaste();
805 else
806 return false;
807#endif
808}
809
810bool wxComboBox::CanUndo() const
811{
812#if USE_HICOMBOBOX
7d8268a1
WS
813 // TODO
814 return false;
150e31d2
JS
815#else
816 if (m_text != NULL)
817 return m_text->CanUndo();
818 else
819 return false;
820#endif
821}
822
823bool wxComboBox::CanRedo() const
824{
825#if USE_HICOMBOBOX
7d8268a1
WS
826 // TODO
827 return false;
150e31d2
JS
828#else
829 if (m_text != NULL)
830 return m_text->CanRedo();
831 else
832 return false;
833#endif
834}
46cc7c4e 835
150e31d2 836wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
46cc7c4e 837{
46cc7c4e
SC
838 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
839 event.SetInt(GetSelection());
840 event.SetEventObject(this);
841 event.SetString(GetStringSelection());
842 ProcessCommand(event);
3c24dad6 843 return noErr;
46cc7c4e 844}