]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/combobxc.cpp
further encapsulation of graphics context, wxdc becoming 'generic'
[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 );
402
403 m_choice = new wxComboBoxChoice(this, style );
3c24dad6 404 m_choice->SetSizeHints( wxSize( POPUPWIDTH , POPUPHEIGHT ) );
150e31d2 405
46cc7c4e
SC
406 wxSize csize = size;
407 if ( style & wxCB_READONLY )
408 {
409 m_text = NULL;
410 }
411 else
412 {
413 m_text = new wxComboBoxText(this);
3dee36ae 414 if ( size.y == wxDefaultCoord ) {
3c24dad6 415 csize.y = m_text->GetSize().y;
46cc7c4e
SC
416 }
417 }
150e31d2 418
46cc7c4e 419 DoSetSize(pos.x, pos.y, csize.x, csize.y);
150e31d2 420
3c24dad6 421 for ( int i = 0; i < n; i++ )
46cc7c4e
SC
422 {
423 m_choice->DoAppend( choices[ i ] );
424 }
425 SetBestSize(csize); // Needed because it is a wxControlWithItems
426#endif
427
7d8268a1 428 return true;
46cc7c4e
SC
429}
430
431wxString wxComboBox::GetValue() const
432{
433#if USE_HICOMBOBOX
434 CFStringRef myString;
3c24dad6 435 HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)GetSelection(), &myString );
46cc7c4e
SC
436 return wxMacCFStringHolder( myString, m_font.GetEncoding() ).AsString();
437#else
438 wxString result;
150e31d2 439
46cc7c4e
SC
440 if ( m_text == NULL )
441 {
442 result = m_choice->GetString( m_choice->GetSelection() );
443 }
444 else
445 {
446 result = m_text->GetValue();
447 }
150e31d2 448
46cc7c4e
SC
449 return result;
450#endif
451}
452
453void wxComboBox::SetValue(const wxString& value)
454{
455#if USE_HICOMBOBOX
150e31d2 456
46cc7c4e
SC
457#else
458 int s = FindString (value);
459 if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) )
460 {
3c24dad6 461 m_choice->Append(value);
46cc7c4e 462 }
3c24dad6 463 SetStringSelection( value );
46cc7c4e
SC
464#endif
465}
466
467// Clipboard operations
468void wxComboBox::Copy()
469{
470 if ( m_text != NULL )
471 {
472 m_text->Copy();
473 }
474}
475
476void wxComboBox::Cut()
477{
478 if ( m_text != NULL )
479 {
480 m_text->Cut();
481 }
482}
483
484void wxComboBox::Paste()
485{
486 if ( m_text != NULL )
487 {
488 m_text->Paste();
489 }
490}
491
492void wxComboBox::SetEditable(bool editable)
493{
494 if ( ( m_text == NULL ) && editable )
495 {
496 m_text = new wxComboBoxText( this );
497 }
498 else if ( ( m_text != NULL ) && !editable )
499 {
500 delete m_text;
501 m_text = NULL;
502 }
503
504 int currentX, currentY;
505 GetPosition( &currentX, &currentY );
150e31d2 506
46cc7c4e
SC
507 int currentW, currentH;
508 GetSize( &currentW, &currentH );
509
510 DoMoveWindow( currentX, currentY, currentW, currentH );
511}
512
513void wxComboBox::SetInsertionPoint(long pos)
514{
515 // TODO
516}
517
518void wxComboBox::SetInsertionPointEnd()
519{
520 // TODO
521}
522
523long wxComboBox::GetInsertionPoint() const
524{
525 // TODO
526 return 0;
527}
528
7d8268a1 529wxTextPos wxComboBox::GetLastPosition() const
46cc7c4e
SC
530{
531 // TODO
532 return 0;
533}
534
535void wxComboBox::Replace(long from, long to, const wxString& value)
536{
537 // TODO
538}
539
540void wxComboBox::Remove(long from, long to)
541{
542 // TODO
543}
544
545void wxComboBox::SetSelection(long from, long to)
546{
547 // TODO
548}
549
150e31d2 550int wxComboBox::DoAppend(const wxString& item)
46cc7c4e
SC
551{
552#if USE_HICOMBOBOX
553 CFIndex outIndex;
3c24dad6
SC
554 HIComboBoxAppendTextItem( m_peer->GetControlRef(), wxMacCFStringHolder( item, m_font.GetEncoding() ), &outIndex );
555 //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
46cc7c4e
SC
556 return (int) outIndex;
557#else
3c24dad6 558 return m_choice->DoAppend( item );
46cc7c4e
SC
559#endif
560}
561
aa61d352 562int wxComboBox::DoInsert(const wxString& item, unsigned int pos)
46cc7c4e
SC
563{
564#if USE_HICOMBOBOX
3c24dad6 565 HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) );
150e31d2 566
3c24dad6 567 //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
150e31d2 568
46cc7c4e
SC
569 return pos;
570#else
3c24dad6 571 return m_choice->DoInsert( item , pos );
46cc7c4e
SC
572#endif
573}
574
aa61d352 575void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
46cc7c4e
SC
576{
577#if USE_HICOMBOBOX
578 return; //TODO
579#else
3c24dad6 580 return m_choice->DoSetItemClientData( n , clientData );
46cc7c4e
SC
581#endif
582}
583
aa61d352 584void* wxComboBox::DoGetItemClientData(unsigned int n) const
46cc7c4e
SC
585{
586#if USE_HICOMBOBOX
587 return NULL; //TODO
588#else
3c24dad6 589 return m_choice->DoGetItemClientData( n );
46cc7c4e
SC
590#endif
591}
592
aa61d352 593void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
46cc7c4e
SC
594{
595#if USE_HICOMBOBOX
596 return; //TODO
597#else
3c24dad6 598 return m_choice->DoSetItemClientObject( n , clientData );
46cc7c4e
SC
599#endif
600}
601
aa61d352 602wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const
46cc7c4e
SC
603{
604#if USE_HICOMBOBOX
605 return NULL;
606#else
3c24dad6 607 return m_choice->DoGetItemClientObject( n );
46cc7c4e
SC
608#endif
609}
610
611void wxComboBox::FreeData()
612{
aa61d352 613 if (HasClientObjectData())
46cc7c4e 614 {
aa61d352
VZ
615 unsigned int count = GetCount();
616 for ( unsigned int n = 0; n < count; n++ )
46cc7c4e
SC
617 {
618 SetClientObject( n, NULL );
619 }
620 }
621}
622
aa61d352 623unsigned int wxComboBox::GetCount() const {
46cc7c4e 624#if USE_HICOMBOBOX
3c24dad6 625 return (unsigned int) HIComboBoxGetItemCount( m_peer->GetControlRef() );
46cc7c4e 626#else
3c24dad6 627 return m_choice->GetCount();
46cc7c4e
SC
628#endif
629}
630
aa61d352 631void wxComboBox::Delete(unsigned int n)
46cc7c4e
SC
632{
633#if USE_HICOMBOBOX
3c24dad6 634 HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex)n );
46cc7c4e
SC
635#else
636 // force client object deletion
637 if( HasClientObjectData() )
638 SetClientObject( n, NULL );
639 m_choice->Delete( n );
640#endif
641}
642
643void wxComboBox::Clear()
644{
b310cebd 645 FreeData();
46cc7c4e 646#if USE_HICOMBOBOX
3c24dad6
SC
647 for ( CFIndex i = GetCount() - 1; i >= 0; ++ i )
648 verify_noerr( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), i ) );
21fd5529 649 m_peer->SetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag,CFSTR(""));
46cc7c4e 650#else
46cc7c4e
SC
651 m_choice->Clear();
652#endif
653}
654
655int wxComboBox::GetSelection() const
656{
657#if USE_HICOMBOBOX
3c24dad6 658 return FindString( GetStringSelection() );
46cc7c4e
SC
659#else
660 return m_choice->GetSelection();
661#endif
662}
663
664void wxComboBox::SetSelection(int n)
665{
666#if USE_HICOMBOBOX
3c24dad6 667 SetControl32BitValue( m_peer->GetControlRef() , n + 1 );
46cc7c4e
SC
668#else
669 m_choice->SetSelection( n );
150e31d2 670
46cc7c4e
SC
671 if ( m_text != NULL )
672 {
aa61d352 673 m_text->SetValue(GetString(n));
46cc7c4e
SC
674 }
675#endif
676}
677
11e62fe6 678int wxComboBox::FindString(const wxString& s, bool bCase) const
46cc7c4e
SC
679{
680#if USE_HICOMBOBOX
aa61d352 681 for( unsigned int i = 0 ; i < GetCount() ; i++ )
46cc7c4e 682 {
aa61d352 683 if (GetString(i).IsSameAs(s, bCase) )
46cc7c4e
SC
684 return i ;
685 }
3c24dad6 686 return wxNOT_FOUND;
46cc7c4e 687#else
11e62fe6 688 return m_choice->FindString( s, bCase );
46cc7c4e
SC
689#endif
690}
691
aa61d352 692wxString wxComboBox::GetString(unsigned int n) const
46cc7c4e
SC
693{
694#if USE_HICOMBOBOX
695 CFStringRef itemText;
3c24dad6 696 HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)n, &itemText );
46cc7c4e
SC
697 return wxMacCFStringHolder(itemText).AsString();
698#else
699 return m_choice->GetString( n );
700#endif
701}
702
703wxString wxComboBox::GetStringSelection() const
704{
b310cebd 705#if USE_HICOMBOBOX
3c24dad6 706 return wxMacCFStringHolder(m_peer->GetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag)).AsString();
b310cebd 707#else
46cc7c4e 708 int sel = GetSelection ();
aa61d352
VZ
709 if (sel != wxNOT_FOUND)
710 return wxString(this->GetString((unsigned int)sel));
46cc7c4e
SC
711 else
712 return wxEmptyString;
b310cebd 713#endif
46cc7c4e
SC
714}
715
aa61d352 716void wxComboBox::SetString(unsigned int n, const wxString& s)
46cc7c4e
SC
717{
718#if USE_HICOMBOBOX
3c24dad6 719 verify_noerr ( HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex) n,
b310cebd 720 wxMacCFStringHolder(s, m_font.GetEncoding()) ) );
3c24dad6 721 verify_noerr ( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex) n + 1 ) );
46cc7c4e 722#else
3c24dad6 723 m_choice->SetString( n , s );
46cc7c4e
SC
724#endif
725}
726
150e31d2
JS
727bool wxComboBox::IsEditable() const
728{
729#if USE_HICOMBOBOX
7d8268a1
WS
730 // TODO
731 return !HasFlag(wxCB_READONLY);
150e31d2 732#else
7d8268a1 733 return m_text != NULL && !HasFlag(wxCB_READONLY);
150e31d2
JS
734#endif
735}
736
737void wxComboBox::Undo()
738{
739#if USE_HICOMBOBOX
7d8268a1 740 // TODO
150e31d2
JS
741#else
742 if (m_text != NULL)
743 m_text->Undo();
744#endif
745}
746
747void wxComboBox::Redo()
748{
749#if USE_HICOMBOBOX
7d8268a1 750 // TODO
150e31d2
JS
751#else
752 if (m_text != NULL)
753 m_text->Redo();
754#endif
755}
756
757void wxComboBox::SelectAll()
758{
759#if USE_HICOMBOBOX
7d8268a1 760 // TODO
150e31d2
JS
761#else
762 if (m_text != NULL)
763 m_text->SelectAll();
764#endif
765}
766
767bool wxComboBox::CanCopy() const
768{
769#if USE_HICOMBOBOX
7d8268a1
WS
770 // TODO
771 return false;
150e31d2
JS
772#else
773 if (m_text != NULL)
774 return m_text->CanCopy();
775 else
776 return false;
777#endif
778}
779
780bool wxComboBox::CanCut() const
781{
782#if USE_HICOMBOBOX
7d8268a1
WS
783 // TODO
784 return false;
150e31d2
JS
785#else
786 if (m_text != NULL)
787 return m_text->CanCut();
788 else
789 return false;
790#endif
791}
792
793bool wxComboBox::CanPaste() const
794{
795#if USE_HICOMBOBOX
7d8268a1
WS
796 // TODO
797 return false;
150e31d2
JS
798#else
799 if (m_text != NULL)
800 return m_text->CanPaste();
801 else
802 return false;
803#endif
804}
805
806bool wxComboBox::CanUndo() const
807{
808#if USE_HICOMBOBOX
7d8268a1
WS
809 // TODO
810 return false;
150e31d2
JS
811#else
812 if (m_text != NULL)
813 return m_text->CanUndo();
814 else
815 return false;
816#endif
817}
818
819bool wxComboBox::CanRedo() const
820{
821#if USE_HICOMBOBOX
7d8268a1
WS
822 // TODO
823 return false;
150e31d2
JS
824#else
825 if (m_text != NULL)
826 return m_text->CanRedo();
827 else
828 return false;
829#endif
830}
46cc7c4e 831
150e31d2 832wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
46cc7c4e 833{
46cc7c4e
SC
834 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
835 event.SetInt(GetSelection());
836 event.SetEventObject(this);
837 event.SetString(GetStringSelection());
838 ProcessCommand(event);
3c24dad6 839 return noErr;
46cc7c4e 840}