adding a few methods for selection handling in native combobox
authorStefan Csomor <csomor@advancedconcepts.ch>
Mon, 17 May 2004 04:57:53 +0000 (04:57 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Mon, 17 May 2004 04:57:53 +0000 (04:57 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27315 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/combobxc.cpp

index e0549c540a0410604527c03c3d3efb6ee5ec2ea0..853a335aa541c2c0f5353ca299c6b748a1390185 100644 (file)
@@ -594,10 +594,15 @@ void wxComboBox::Delete(int n)
 
 void wxComboBox::Clear()
 {
+    FreeData();
 #if USE_HICOMBOBOX
-    //TODO
+    for ( CFIndex i = GetCount() - 1 ; i >= 0 ; ++ i )
+        verify_noerr( HIComboBoxRemoveItemAtIndex( (HIViewRef) m_macControl, i ) );
+    wxMacCFStringHolder cf(wxEmptyString,m_font.GetEncoding()) ;
+    CFStringRef cfr = cf ;
+    SetControlData((ControlRef) m_macControl,kHIComboBoxEditTextPart,kControlEditTextCFStringTag, 
+           sizeof(CFStringRef),(Ptr) &cfr);
 #else
-    FreeData();
     m_choice->Clear();
 #endif
 }
@@ -605,8 +610,7 @@ void wxComboBox::Clear()
 int wxComboBox::GetSelection() const
 {
 #if USE_HICOMBOBOX
-    int result =  GetControl32BitValue( (HIViewRef) m_macControl ) -1;
-    return result;
+    return FindString( GetStringSelection() ) ;
 #else
     return m_choice->GetSelection();
 #endif
@@ -653,11 +657,20 @@ wxString wxComboBox::GetString(int n) const
 
 wxString wxComboBox::GetStringSelection() const
 {
+#if USE_HICOMBOBOX
+    CFStringRef cfr ;
+    verify_noerr(GetControlData((ControlRef) m_macControl,kHIComboBoxEditTextPart,kControlEditTextCFStringTag, 
+           sizeof(CFStringRef),(Ptr) &cfr,NULL));
+    // takes of release responsibility
+    wxMacCFStringHolder cf( cfr ) ;
+    return cf.AsString() ;
+#else
     int sel = GetSelection ();
     if (sel > -1)
         return wxString(this->GetString (sel));
     else
         return wxEmptyString;
+#endif
 }
 
 bool wxComboBox::SetStringSelection(const wxString& sel)
@@ -675,7 +688,9 @@ bool wxComboBox::SetStringSelection(const wxString& sel)
 void wxComboBox::SetString(int n, const wxString& s) 
 {
 #if USE_HICOMBOBOX
-
+    verify_noerr ( HIComboBoxInsertTextItemAtIndex( (HIViewRef) m_macControl, (CFIndex) n, 
+        wxMacCFStringHolder(s, m_font.GetEncoding()) ) );
+    verify_noerr ( HIComboBoxRemoveItemAtIndex( (HIViewRef) m_macControl, (CFIndex) n + 1 ) );
 #else
     m_choice->SetString( n , s ) ;
 #endif
@@ -684,14 +699,11 @@ void wxComboBox::SetString(int n, const wxString& s)
 
 wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) 
 {
-/*
     wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
     event.SetInt(GetSelection());
     event.SetEventObject(this);
     event.SetString(GetStringSelection());
     ProcessCommand(event);
     return noErr ;
-*/
-    return eventNotHandledErr ;
 }