]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/combobxc.cpp
Implement LIST_KEY_DOWN support, and move new functions into wxABI_VERSION.
[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
6c20e8f8
VZ
150 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
151 if ( tlw && tlw->GetDefaultItem() )
46cc7c4e 152 {
6c20e8f8 153 wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
46cc7c4e
SC
154 if ( def && def->IsEnabled() )
155 {
156 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
157 event.SetEventObject(def);
158 def->Command(event);
3c24dad6 159 return;
3dee36ae 160 }
46cc7c4e
SC
161 }
162
163 return;
164 }
165 }
150e31d2 166
46cc7c4e
SC
167 event.Skip();
168 }
169private:
170 wxComboBox *m_cb;
171
172 DECLARE_EVENT_TABLE()
173};
174
175BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl)
176 EVT_CHAR( wxComboBoxText::OnChar)
177END_EVENT_TABLE()
178
179class wxComboBoxChoice : public wxChoice
180{
181public:
182 wxComboBoxChoice(wxComboBox *cb, int style)
183 : wxChoice( cb , 1 )
184 {
185 m_cb = cb;
186 }
187
188protected:
189 void OnChoice( wxCommandEvent& e )
190 {
191 wxString s = e.GetString();
192
193 m_cb->DelegateChoice( s );
194 wxCommandEvent event2(wxEVT_COMMAND_COMBOBOX_SELECTED, m_cb->GetId() );
195 event2.SetInt(m_cb->GetSelection());
196 event2.SetEventObject(m_cb);
197 event2.SetString(m_cb->GetStringSelection());
198 m_cb->ProcessCommand(event2);
199 }
200 virtual wxSize DoGetBestSize() const
201 {
3c24dad6
SC
202 wxSize sz = wxChoice::DoGetBestSize();
203 sz.x = POPUPWIDTH;
204 return sz;
150e31d2 205 }
46cc7c4e
SC
206
207private:
208 wxComboBox *m_cb;
209
210 DECLARE_EVENT_TABLE()
211};
212
213BEGIN_EVENT_TABLE(wxComboBoxChoice, wxChoice)
3dee36ae 214 EVT_CHOICE(wxID_ANY, wxComboBoxChoice::OnChoice)
46cc7c4e
SC
215END_EVENT_TABLE()
216
217wxComboBox::~wxComboBox()
218{
219 // delete client objects
220 FreeData();
221
222 // delete the controls now, don't leave them alive even though they would
223 // still be eventually deleted by our parent - but it will be too late, the
224 // user code expects them to be gone now
225 if (m_text != NULL) {
226 delete m_text;
227 m_text = NULL;
228 }
229 if (m_choice != NULL) {
230 delete m_choice;
231 m_choice = NULL;
232 }
233}
234
235
236// ----------------------------------------------------------------------------
237// geometry
238// ----------------------------------------------------------------------------
239
240wxSize wxComboBox::DoGetBestSize() const
241{
242#if USE_HICOMBOBOX
7d8268a1 243 return wxControl::DoGetBestSize();
46cc7c4e
SC
244#else
245 wxSize size = m_choice->GetBestSize();
150e31d2 246
46cc7c4e
SC
247 if ( m_text != NULL )
248 {
249 wxSize sizeText = m_text->GetBestSize();
150e31d2 250
46cc7c4e
SC
251 size.x = POPUPWIDTH + sizeText.x + MARGIN;
252 }
253
254 return size;
255#endif
256}
257
258void wxComboBox::DoMoveWindow(int x, int y, int width, int height) {
259#if USE_HICOMBOBOX
7d8268a1 260 wxControl::DoMoveWindow(x, y, width, height);
46cc7c4e
SC
261#else
262 height = POPUPHEIGHT;
150e31d2 263
46cc7c4e
SC
264 wxControl::DoMoveWindow(x, y, width, height);
265
266 if ( m_text == NULL )
267 {
268 // we might not be fully constructed yet, therefore watch out...
269 if ( m_choice )
3dee36ae 270 m_choice->SetSize(0, 0 , width, wxDefaultCoord);
46cc7c4e
SC
271 }
272 else
273 {
274 wxCoord wText = width - POPUPWIDTH - MARGIN;
275 m_text->SetSize(0, 0, wText, height);
3dee36ae 276 m_choice->SetSize(0 + wText + MARGIN, 0, POPUPWIDTH, wxDefaultCoord);
46cc7c4e 277 }
150e31d2 278#endif
46cc7c4e
SC
279}
280
281
282
283// ----------------------------------------------------------------------------
284// operations forwarded to the subcontrols
285// ----------------------------------------------------------------------------
286
287bool wxComboBox::Enable(bool enable)
288{
289 if ( !wxControl::Enable(enable) )
7d8268a1 290 return false;
46cc7c4e 291
7d8268a1 292 return true;
46cc7c4e
SC
293}
294
295bool wxComboBox::Show(bool show)
296{
297 if ( !wxControl::Show(show) )
7d8268a1 298 return false;
46cc7c4e 299
7d8268a1 300 return true;
46cc7c4e
SC
301}
302
303void wxComboBox::SetFocus()
304{
305#if USE_HICOMBOBOX
7d8268a1 306 wxControl::SetFocus();
46cc7c4e
SC
307#else
308 if ( m_text != NULL) {
309 m_text->SetFocus();
310 }
311#endif
312}
313
314
315void wxComboBox::DelegateTextChanged( const wxString& value )
316{
317 SetStringSelection( value );
318}
319
320
321void wxComboBox::DelegateChoice( const wxString& value )
322{
323 SetStringSelection( value );
324}
325
326
327bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
328 const wxString& value,
329 const wxPoint& pos,
330 const wxSize& size,
331 const wxArrayString& choices,
332 long style,
333 const wxValidator& validator,
334 const wxString& name)
335{
336 wxCArrayString chs( choices );
337
338 return Create( parent, id, value, pos, size, chs.GetCount(),
339 chs.GetStrings(), style, validator, name );
340}
341
342
343bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
344 const wxString& value,
345 const wxPoint& pos,
346 const wxSize& size,
347 int n, const wxString choices[],
348 long style,
349 const wxValidator& validator,
350 const wxString& name)
351{
352 m_text = NULL;
353 m_choice = NULL;
354#if USE_HICOMBOBOX
3c24dad6 355 m_macIsUserPane = false;
46cc7c4e
SC
356#endif
357 if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
358 wxDefaultValidator, name) )
359 {
7d8268a1 360 return false;
46cc7c4e
SC
361 }
362#if USE_HICOMBOBOX
3c24dad6 363 Rect bounds = wxMacGetBoundsForControl( this , pos , size );
46cc7c4e 364 HIRect hiRect;
150e31d2 365
46cc7c4e
SC
366 hiRect.origin.x = 20; //bounds.left;
367 hiRect.origin.y = 25; //bounds.top;
368 hiRect.size.width = 120;// bounds.right - bounds.left;
150e31d2
JS
369 hiRect.size.height = 24;
370
46cc7c4e
SC
371 //For some reason, this code causes the combo box not to be displayed at all.
372 //hiRect.origin.x = bounds.left;
373 //hiRect.origin.y = bounds.top;
374 //hiRect.size.width = bounds.right - bounds.left;
375 //hiRect.size.height = bounds.bottom - bounds.top;
376 //printf("left = %d, right = %d, top = %d, bottom = %d\n", bounds.left, bounds.right, bounds.top, bounds.bottom);
7d8268a1 377 //printf("x = %d, y = %d, width = %d, height = %d\n", hibounds.origin.x, hibounds.origin.y, hibounds.size.width, hibounds.size.height);
3c24dad6
SC
378 m_peer = new wxMacControl(this);
379 verify_noerr( HIComboBoxCreate( &hiRect, CFSTR(""), NULL, NULL, kHIComboBoxStandardAttributes, m_peer->GetControlRefAddr() ) );
150e31d2 380
46cc7c4e 381
3c24dad6
SC
382 m_peer->SetMinimum( 0 );
383 m_peer->SetMaximum( 100);
46cc7c4e 384 if ( n > 0 )
3c24dad6 385 m_peer->SetValue( 1 );
150e31d2 386
3c24dad6 387 MacPostControlCreate(pos,size);
150e31d2 388
3c24dad6 389 for ( int i = 0; i < n; i++ )
46cc7c4e
SC
390 {
391 DoAppend( choices[ i ] );
392 }
150e31d2 393
3c24dad6 394 HIViewSetVisible( m_peer->GetControlRef(), true );
46cc7c4e 395 SetSelection(0);
3c24dad6
SC
396 EventHandlerRef comboEventHandler;
397 InstallControlEventHandler( m_peer->GetControlRef(), GetwxMacComboBoxEventHandlerUPP(),
150e31d2 398 GetEventTypeCount(eventList), eventList, this,
21fd5529 399 (EventHandlerRef *)&comboEventHandler);
46cc7c4e
SC
400#else
401 m_choice = new wxComboBoxChoice(this, style );
cecf69f3 402 m_choice->SetMinSize( wxSize( POPUPWIDTH , POPUPHEIGHT ) );
150e31d2 403
46cc7c4e
SC
404 wxSize csize = size;
405 if ( style & wxCB_READONLY )
406 {
407 m_text = NULL;
408 }
409 else
410 {
411 m_text = new wxComboBoxText(this);
3dee36ae 412 if ( size.y == wxDefaultCoord ) {
3c24dad6 413 csize.y = m_text->GetSize().y;
46cc7c4e
SC
414 }
415 }
150e31d2 416
46cc7c4e 417 DoSetSize(pos.x, pos.y, csize.x, csize.y);
150e31d2 418
3c24dad6 419 for ( int i = 0; i < n; i++ )
46cc7c4e
SC
420 {
421 m_choice->DoAppend( choices[ i ] );
422 }
170acdc9 423 SetInitialSize(csize); // Needed because it is a wxControlWithItems
46cc7c4e
SC
424#endif
425
7d8268a1 426 return true;
46cc7c4e
SC
427}
428
429wxString wxComboBox::GetValue() const
430{
431#if USE_HICOMBOBOX
432 CFStringRef myString;
3c24dad6 433 HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)GetSelection(), &myString );
46cc7c4e
SC
434 return wxMacCFStringHolder( myString, m_font.GetEncoding() ).AsString();
435#else
436 wxString result;
150e31d2 437
46cc7c4e
SC
438 if ( m_text == NULL )
439 {
440 result = m_choice->GetString( m_choice->GetSelection() );
441 }
442 else
443 {
444 result = m_text->GetValue();
445 }
150e31d2 446
46cc7c4e
SC
447 return result;
448#endif
449}
450
451void wxComboBox::SetValue(const wxString& value)
452{
453#if USE_HICOMBOBOX
150e31d2 454
46cc7c4e
SC
455#else
456 int s = FindString (value);
457 if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) )
458 {
3c24dad6 459 m_choice->Append(value);
46cc7c4e 460 }
3c24dad6 461 SetStringSelection( value );
46cc7c4e
SC
462#endif
463}
464
465// Clipboard operations
466void wxComboBox::Copy()
467{
468 if ( m_text != NULL )
469 {
470 m_text->Copy();
471 }
472}
473
474void wxComboBox::Cut()
475{
476 if ( m_text != NULL )
477 {
478 m_text->Cut();
479 }
480}
481
482void wxComboBox::Paste()
483{
484 if ( m_text != NULL )
485 {
486 m_text->Paste();
487 }
488}
489
490void wxComboBox::SetEditable(bool editable)
491{
492 if ( ( m_text == NULL ) && editable )
493 {
494 m_text = new wxComboBoxText( this );
495 }
496 else if ( ( m_text != NULL ) && !editable )
497 {
498 delete m_text;
499 m_text = NULL;
500 }
501
502 int currentX, currentY;
503 GetPosition( &currentX, &currentY );
150e31d2 504
46cc7c4e
SC
505 int currentW, currentH;
506 GetSize( &currentW, &currentH );
507
508 DoMoveWindow( currentX, currentY, currentW, currentH );
509}
510
511void wxComboBox::SetInsertionPoint(long pos)
512{
513 // TODO
514}
515
516void wxComboBox::SetInsertionPointEnd()
517{
518 // TODO
519}
520
521long wxComboBox::GetInsertionPoint() const
522{
523 // TODO
524 return 0;
525}
526
7d8268a1 527wxTextPos wxComboBox::GetLastPosition() const
46cc7c4e
SC
528{
529 // TODO
530 return 0;
531}
532
533void wxComboBox::Replace(long from, long to, const wxString& value)
534{
535 // TODO
536}
537
538void wxComboBox::Remove(long from, long to)
539{
540 // TODO
541}
542
543void wxComboBox::SetSelection(long from, long to)
544{
545 // TODO
546}
547
150e31d2 548int wxComboBox::DoAppend(const wxString& item)
46cc7c4e
SC
549{
550#if USE_HICOMBOBOX
551 CFIndex outIndex;
3c24dad6
SC
552 HIComboBoxAppendTextItem( m_peer->GetControlRef(), wxMacCFStringHolder( item, m_font.GetEncoding() ), &outIndex );
553 //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
46cc7c4e
SC
554 return (int) outIndex;
555#else
3c24dad6 556 return m_choice->DoAppend( item );
46cc7c4e
SC
557#endif
558}
559
aa61d352 560int wxComboBox::DoInsert(const wxString& item, unsigned int pos)
46cc7c4e
SC
561{
562#if USE_HICOMBOBOX
3c24dad6 563 HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) );
150e31d2 564
3c24dad6 565 //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
150e31d2 566
46cc7c4e
SC
567 return pos;
568#else
3c24dad6 569 return m_choice->DoInsert( item , pos );
46cc7c4e
SC
570#endif
571}
572
aa61d352 573void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
46cc7c4e
SC
574{
575#if USE_HICOMBOBOX
576 return; //TODO
577#else
3c24dad6 578 return m_choice->DoSetItemClientData( n , clientData );
46cc7c4e
SC
579#endif
580}
581
aa61d352 582void* wxComboBox::DoGetItemClientData(unsigned int n) const
46cc7c4e
SC
583{
584#if USE_HICOMBOBOX
585 return NULL; //TODO
586#else
3c24dad6 587 return m_choice->DoGetItemClientData( n );
46cc7c4e
SC
588#endif
589}
590
aa61d352 591void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
46cc7c4e
SC
592{
593#if USE_HICOMBOBOX
594 return; //TODO
595#else
3c24dad6 596 return m_choice->DoSetItemClientObject( n , clientData );
46cc7c4e
SC
597#endif
598}
599
aa61d352 600wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const
46cc7c4e
SC
601{
602#if USE_HICOMBOBOX
603 return NULL;
604#else
3c24dad6 605 return m_choice->DoGetItemClientObject( n );
46cc7c4e
SC
606#endif
607}
608
609void wxComboBox::FreeData()
610{
aa61d352 611 if (HasClientObjectData())
46cc7c4e 612 {
aa61d352
VZ
613 unsigned int count = GetCount();
614 for ( unsigned int n = 0; n < count; n++ )
46cc7c4e
SC
615 {
616 SetClientObject( n, NULL );
617 }
618 }
619}
620
aa61d352 621unsigned int wxComboBox::GetCount() const {
46cc7c4e 622#if USE_HICOMBOBOX
3c24dad6 623 return (unsigned int) HIComboBoxGetItemCount( m_peer->GetControlRef() );
46cc7c4e 624#else
3c24dad6 625 return m_choice->GetCount();
46cc7c4e
SC
626#endif
627}
628
aa61d352 629void wxComboBox::Delete(unsigned int n)
46cc7c4e
SC
630{
631#if USE_HICOMBOBOX
3c24dad6 632 HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex)n );
46cc7c4e
SC
633#else
634 // force client object deletion
635 if( HasClientObjectData() )
636 SetClientObject( n, NULL );
637 m_choice->Delete( n );
638#endif
639}
640
641void wxComboBox::Clear()
642{
b310cebd 643 FreeData();
46cc7c4e 644#if USE_HICOMBOBOX
3c24dad6
SC
645 for ( CFIndex i = GetCount() - 1; i >= 0; ++ i )
646 verify_noerr( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), i ) );
21fd5529 647 m_peer->SetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag,CFSTR(""));
46cc7c4e 648#else
46cc7c4e
SC
649 m_choice->Clear();
650#endif
651}
652
653int wxComboBox::GetSelection() const
654{
655#if USE_HICOMBOBOX
3c24dad6 656 return FindString( GetStringSelection() );
46cc7c4e
SC
657#else
658 return m_choice->GetSelection();
659#endif
660}
661
662void wxComboBox::SetSelection(int n)
663{
664#if USE_HICOMBOBOX
3c24dad6 665 SetControl32BitValue( m_peer->GetControlRef() , n + 1 );
46cc7c4e
SC
666#else
667 m_choice->SetSelection( n );
150e31d2 668
46cc7c4e
SC
669 if ( m_text != NULL )
670 {
aa61d352 671 m_text->SetValue(GetString(n));
46cc7c4e
SC
672 }
673#endif
674}
675
11e62fe6 676int wxComboBox::FindString(const wxString& s, bool bCase) const
46cc7c4e
SC
677{
678#if USE_HICOMBOBOX
aa61d352 679 for( unsigned int i = 0 ; i < GetCount() ; i++ )
46cc7c4e 680 {
aa61d352 681 if (GetString(i).IsSameAs(s, bCase) )
46cc7c4e
SC
682 return i ;
683 }
3c24dad6 684 return wxNOT_FOUND;
46cc7c4e 685#else
11e62fe6 686 return m_choice->FindString( s, bCase );
46cc7c4e
SC
687#endif
688}
689
aa61d352 690wxString wxComboBox::GetString(unsigned int n) const
46cc7c4e
SC
691{
692#if USE_HICOMBOBOX
693 CFStringRef itemText;
3c24dad6 694 HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)n, &itemText );
46cc7c4e
SC
695 return wxMacCFStringHolder(itemText).AsString();
696#else
697 return m_choice->GetString( n );
698#endif
699}
700
701wxString wxComboBox::GetStringSelection() const
702{
b310cebd 703#if USE_HICOMBOBOX
3c24dad6 704 return wxMacCFStringHolder(m_peer->GetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag)).AsString();
b310cebd 705#else
46cc7c4e 706 int sel = GetSelection ();
aa61d352
VZ
707 if (sel != wxNOT_FOUND)
708 return wxString(this->GetString((unsigned int)sel));
46cc7c4e
SC
709 else
710 return wxEmptyString;
b310cebd 711#endif
46cc7c4e
SC
712}
713
aa61d352 714void wxComboBox::SetString(unsigned int n, const wxString& s)
46cc7c4e
SC
715{
716#if USE_HICOMBOBOX
3c24dad6 717 verify_noerr ( HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex) n,
b310cebd 718 wxMacCFStringHolder(s, m_font.GetEncoding()) ) );
3c24dad6 719 verify_noerr ( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex) n + 1 ) );
46cc7c4e 720#else
3c24dad6 721 m_choice->SetString( n , s );
46cc7c4e
SC
722#endif
723}
724
150e31d2
JS
725bool wxComboBox::IsEditable() const
726{
727#if USE_HICOMBOBOX
7d8268a1
WS
728 // TODO
729 return !HasFlag(wxCB_READONLY);
150e31d2 730#else
7d8268a1 731 return m_text != NULL && !HasFlag(wxCB_READONLY);
150e31d2
JS
732#endif
733}
734
735void wxComboBox::Undo()
736{
737#if USE_HICOMBOBOX
7d8268a1 738 // TODO
150e31d2
JS
739#else
740 if (m_text != NULL)
741 m_text->Undo();
742#endif
743}
744
745void wxComboBox::Redo()
746{
747#if USE_HICOMBOBOX
7d8268a1 748 // TODO
150e31d2
JS
749#else
750 if (m_text != NULL)
751 m_text->Redo();
752#endif
753}
754
755void wxComboBox::SelectAll()
756{
757#if USE_HICOMBOBOX
7d8268a1 758 // TODO
150e31d2
JS
759#else
760 if (m_text != NULL)
761 m_text->SelectAll();
762#endif
763}
764
765bool wxComboBox::CanCopy() const
766{
767#if USE_HICOMBOBOX
7d8268a1
WS
768 // TODO
769 return false;
150e31d2
JS
770#else
771 if (m_text != NULL)
772 return m_text->CanCopy();
773 else
774 return false;
775#endif
776}
777
778bool wxComboBox::CanCut() const
779{
780#if USE_HICOMBOBOX
7d8268a1
WS
781 // TODO
782 return false;
150e31d2
JS
783#else
784 if (m_text != NULL)
785 return m_text->CanCut();
786 else
787 return false;
788#endif
789}
790
791bool wxComboBox::CanPaste() const
792{
793#if USE_HICOMBOBOX
7d8268a1
WS
794 // TODO
795 return false;
150e31d2
JS
796#else
797 if (m_text != NULL)
798 return m_text->CanPaste();
799 else
800 return false;
801#endif
802}
803
804bool wxComboBox::CanUndo() const
805{
806#if USE_HICOMBOBOX
7d8268a1
WS
807 // TODO
808 return false;
150e31d2
JS
809#else
810 if (m_text != NULL)
811 return m_text->CanUndo();
812 else
813 return false;
814#endif
815}
816
817bool wxComboBox::CanRedo() const
818{
819#if USE_HICOMBOBOX
7d8268a1
WS
820 // TODO
821 return false;
150e31d2
JS
822#else
823 if (m_text != NULL)
824 return m_text->CanRedo();
825 else
826 return false;
827#endif
828}
46cc7c4e 829
150e31d2 830wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
46cc7c4e 831{
46cc7c4e
SC
832 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
833 event.SetInt(GetSelection());
834 event.SetEventObject(this);
835 event.SetString(GetStringSelection());
836 ProcessCommand(event);
3c24dad6 837 return noErr;
46cc7c4e 838}