-bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
- const wxString& value,
- const wxPoint& pos,
- const wxSize& size,
- int n, const wxString choices[],
- long style,
- const wxValidator& validator,
- const wxString& name)
-{
- m_text = NULL;
- m_choice = NULL;
-#if USE_HICOMBOBOX
- m_macIsUserPane = false;
-#endif
- if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
- wxDefaultValidator, name) )
- {
- return false;
- }
-#if USE_HICOMBOBOX
- Rect bounds = wxMacGetBoundsForControl( this , pos , size );
- HIRect hiRect;
-
- hiRect.origin.x = 20; //bounds.left;
- hiRect.origin.y = 25; //bounds.top;
- hiRect.size.width = 120;// bounds.right - bounds.left;
- hiRect.size.height = 24;
-
- //For some reason, this code causes the combo box not to be displayed at all.
- //hiRect.origin.x = bounds.left;
- //hiRect.origin.y = bounds.top;
- //hiRect.size.width = bounds.right - bounds.left;
- //hiRect.size.height = bounds.bottom - bounds.top;
- //printf("left = %d, right = %d, top = %d, bottom = %d\n", bounds.left, bounds.right, bounds.top, bounds.bottom);
- //printf("x = %d, y = %d, width = %d, height = %d\n", hibounds.origin.x, hibounds.origin.y, hibounds.size.width, hibounds.size.height);
- m_peer = new wxMacControl(this);
- verify_noerr( HIComboBoxCreate( &hiRect, CFSTR(""), NULL, NULL, kHIComboBoxStandardAttributes, m_peer->GetControlRefAddr() ) );
-
-
- m_peer->SetMinimum( 0 );
- m_peer->SetMaximum( 100);
- if ( n > 0 )
- m_peer->SetValue( 1 );
-
- MacPostControlCreate(pos,size);
-
- Append( choices[ i ] );
-
- HIViewSetVisible( m_peer->GetControlRef(), true );
- SetSelection(0);
- EventHandlerRef comboEventHandler;
- InstallControlEventHandler( m_peer->GetControlRef(), GetwxMacComboBoxEventHandlerUPP(),
- GetEventTypeCount(eventList), eventList, this,
- (EventHandlerRef *)&comboEventHandler);
-#else
- m_choice = new wxComboBoxChoice(this, style );
- m_choice->SetMinSize( wxSize( POPUPWIDTH , POPUPHEIGHT ) );
-
- wxSize csize = size;
- if ( style & wxCB_READONLY )
- {
- m_text = NULL;
- }
- else
- {
- m_text = new wxComboBoxText(this);
- if ( size.y == wxDefaultCoord ) {
- csize.y = m_text->GetSize().y;
- }
- }
-
- DoSetSize(pos.x, pos.y, csize.x, csize.y);
-
- m_choice->Append( n, choices );
- SetInitialSize(csize); // Needed because it is a wxControlWithItems
-#endif
-
- return true;
-}
-
-wxString wxComboBox::GetValue() const
-{
-#if USE_HICOMBOBOX
- CFStringRef myString;
- HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)GetSelection(), &myString );
- return wxMacCFStringHolder( myString, GetFont().GetEncoding() ).AsString();
-#else
- wxString result;
-
- if ( m_text == NULL )
- {
- result = m_choice->GetString( m_choice->GetSelection() );
- }
- else
- {
- result = m_text->GetValue();
- }
-
- return result;
-#endif
-}
-
-void wxComboBox::SetValue(const wxString& value)
-{
-#if USE_HICOMBOBOX
-
-#else
- int s = FindString (value);
- if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) )
- {
- m_choice->Append(value);
- }
- SetStringSelection( value );
-#endif
-}
-
-// Clipboard operations
-void wxComboBox::Copy()
-{
- if ( m_text != NULL )
- {
- m_text->Copy();
- }
-}
-
-void wxComboBox::Cut()
-{
- if ( m_text != NULL )
- {
- m_text->Cut();
- }
-}
-
-void wxComboBox::Paste()
-{
- if ( m_text != NULL )
- {
- m_text->Paste();
- }
-}
-
-void wxComboBox::SetEditable(bool editable)
-{
- if ( ( m_text == NULL ) && editable )
- {
- m_text = new wxComboBoxText( this );
- }
- else if ( ( m_text != NULL ) && !editable )
- {
- delete m_text;
- m_text = NULL;
- }
-
- int currentX, currentY;
- GetPosition( ¤tX, ¤tY );
-
- int currentW, currentH;
- GetSize( ¤tW, ¤tH );
-
- DoMoveWindow( currentX, currentY, currentW, currentH );
-}
-
-void wxComboBox::SetInsertionPoint(long pos)
-{
- // TODO
-}
-
-void wxComboBox::SetInsertionPointEnd()
-{
- // TODO
-}
-
-long wxComboBox::GetInsertionPoint() const
-{
- // TODO
- return 0;
-}
-
-wxTextPos wxComboBox::GetLastPosition() const
-{
- // TODO
- return 0;
-}
-
-void wxComboBox::Replace(long from, long to, const wxString& value)
-{
- // TODO
-}
-
-void wxComboBox::Remove(long from, long to)
-{
- // TODO
-}
-
-void wxComboBox::SetSelection(long from, long to)
-{
- // TODO
-}
-