X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/acd3dca8bbcf856c29777b1cf58ffbe5923afe35..bf6c0db6243368ee239563a1151156beb5b848fa:/src/cocoa/combobox.mm?ds=sidebyside diff --git a/src/cocoa/combobox.mm b/src/cocoa/combobox.mm index b965d406bd..822194e427 100644 --- a/src/cocoa/combobox.mm +++ b/src/cocoa/combobox.mm @@ -1,23 +1,21 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: cocoa/combobox.mm +// Name: src/cocoa/combobox.mm // Purpose: wxComboBox -// Author: Ryan Norton +// Author: Ryan Norton // Modified by: // Created: 2005/02/16 // RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott -// Licence: wxWidgets licence +// Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// -// #include "wx/wxprec.h" - // // Impl notes: -// There is no custom data source because doing so unneccesaraly sacrifices -// some native autocompletion behavior (we would have to make our own - +// There is no custom data source because doing so unnecessarily sacrifices +// some native autocompletion behavior (we would have to make our own - // the SimpleComboBox sample does so in the developer folder that // comes with OSX). One reason you might want this would be to have -// only one array or be able to display numbers by returned an NSNumber +// only one array or be able to display numbers returned by an NSNumber // from the methods. // // One problem though is that wxCB_SORT isn't implemented... @@ -28,9 +26,9 @@ // doWxEvent is really hackish... but since there's only one event... // // Ideas for future improvement - other notes: -// Combox w/o wxCB_DROPDOWN doesn't seem to be implementable -//wxCB_READONLY Same as wxCB_DROPDOWN but only the strings specified as the combobox choices can be selected, it is impossible to select (even from a program) a string which is not in the choices list. -//wxCB_SORT is possible with data source +// Combox w/o wxCB_DROPDOWN doesn't seem to be implementable +//wxCB_READONLY Same as wxCB_DROPDOWN but only the strings specified as the combobox choices can be selected, it is impossible to select (even from a program) a string which is not in the choices list. +//wxCB_SORT is possible with data source // // setIntercellSpacing:/setItemHeight: to autoadjust to number of inserted items? // @@ -55,7 +53,7 @@ NSString *lowercasePrefix = [prefix lowercaseString]; NSEnumerator *stringEnum = [genres objectEnumerator]; while ((string = [stringEnum nextObject])) { - if ([[string lowercaseString] hasPrefix: lowercasePrefix]) return string; + if ([[string lowercaseString] hasPrefix: lowercasePrefix]) return string; } return nil; } @@ -67,18 +65,6 @@ return (candidate ? candidate : inputString); } */ -#if wxUSE_COMBOBOX - -///////////////////////////////////////////////////////////////////////////// -// Name: cocoa/NSComboBox.mm -// Purpose: wxCocoaNSComboBox -// Author: Ryan Norton -// Modified by: -// Created: 2005/02/16 -// RCS-ID: $Id: -// Copyright: (c) 2003 David Elliott -// Licence: wxWidgets licence -///////////////////////////////////////////////////////////////////////////// // ============================================================================ // declarations @@ -89,12 +75,18 @@ // ---------------------------------------------------------------------------- #include "wx/wxprec.h" + +#if wxUSE_COMBOBOX + +#include "wx/combobox.h" + #ifndef WX_PRECOMP #include "wx/window.h" + #include "wx/log.h" + #include "wx/app.h" #endif // WX_PRECOMP #include "wx/cocoa/ObjcPose.h" -#include "wx/combobox.h" #import #import @@ -110,7 +102,7 @@ void wxCocoaNSComboBox::AssociateNSComboBox(WX_NSComboBox cocoaNSComboBox) if(cocoaNSComboBox) { sm_cocoaHash.insert(wxCocoaNSComboBoxHash::value_type(cocoaNSComboBox,this)); - + [[NSNotificationCenter defaultCenter] addObserver:(id)cocoaNSComboBox selector:@selector(comboBoxSelectionDidChange:) name:@"NSComboBoxSelectionDidChangeNotification" object:cocoaNSComboBox]; [[NSNotificationCenter defaultCenter] addObserver:(id)cocoaNSComboBox selector:@selector(comboBoxSelectionDidChange:) name:@"NSComboBoxSelectionIsChangingNotification" object:cocoaNSComboBox]; [[NSNotificationCenter defaultCenter] addObserver:(id)cocoaNSComboBox selector:@selector(comboBoxSelectionDidChange:) name:@"NSComboBoxWillDismissNotification" object:cocoaNSComboBox]; @@ -169,10 +161,6 @@ void wxCocoaNSComboBox::DisassociateNSComboBox(WX_NSComboBox cocoaNSComboBox) @end // implementation wxPoserNSComboBox -#include "wx/app.h" -#include "wx/combobox.h" -#include "wx/log.h" - #include "wx/cocoa/autorelease.h" #include "wx/cocoa/string.h" @@ -210,7 +198,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID winid, wxAutoNSAutoreleasePool pool; if(!CreateControl(parent,winid,pos,size,style,validator,name)) return false; - + m_cocoaNSView = NULL; SetNSComboBox([[wxPoserNSComboBox alloc] initWithFrame:MakeDefaultNSRect(size)]); [m_cocoaNSView release]; @@ -222,9 +210,9 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID winid, for(int i = 0; i < n; ++i) wxComboBox::DoAppend(choices[i]); - + [GetNSComboBox() setCompletes:true]; //autocomplete :) - + return true; } @@ -266,34 +254,41 @@ void wxComboBox::Clear() m_Datas.Clear(); } -void wxComboBox::Delete(int nIndex) +void wxComboBox::Delete(unsigned int n) { - [GetNSComboBox() removeItemAtIndex:nIndex]; - m_Datas.RemoveAt(nIndex); + [GetNSComboBox() removeItemAtIndex:n]; + m_Datas.RemoveAt(n); } -int wxComboBox::GetCount() const +unsigned int wxComboBox::GetCount() const { - return [GetNSComboBox() numberOfItems]; + return (unsigned int)[GetNSComboBox() numberOfItems]; } -wxString wxComboBox::GetString(int nIndex) const -{ return wxStringWithNSString([GetNSComboBox() itemObjectValueAtIndex:nIndex]); } +wxString wxComboBox::GetString(unsigned int nIndex) const +{ + return wxStringWithNSString([GetNSComboBox() itemObjectValueAtIndex:nIndex]); +} -void wxComboBox::SetString(int nIndex, const wxString& szString) -{ +void wxComboBox::SetString(unsigned int nIndex, const wxString& szString) +{ wxAutoNSAutoreleasePool pool; //FIXME: There appears to be no "set item data" method - maybe //an assignment would work? [GetNSComboBox() removeItemAtIndex:nIndex]; - [GetNSComboBox() insertItemWithObjectValue:wxNSStringWithWxString(szString) atIndex:nIndex]; + [GetNSComboBox() insertItemWithObjectValue:wxNSStringWithWxString(szString) atIndex:nIndex]; } -int wxComboBox::FindString(const wxString& szItem) const -{ return [GetNSComboBox() indexOfItemWithObjectValue:wxNSStringWithWxString(szItem)]; } +int wxComboBox::FindString(const wxString& szItem, bool bCase) const +{ + // FIXME: use wxItemContainerImmutable::FindString for bCase parameter + return [GetNSComboBox() indexOfItemWithObjectValue:wxNSStringWithWxString(szItem)]; +} int wxComboBox::GetSelection() const -{ return [GetNSComboBox() indexOfSelectedItem]; } +{ + return [GetNSComboBox() indexOfSelectedItem]; +} int wxComboBox::DoAppend(const wxString& szItem) { @@ -303,30 +298,30 @@ int wxComboBox::DoAppend(const wxString& szItem) return [GetNSComboBox() numberOfItems]; } -int wxComboBox::DoInsert(const wxString& szItem, int nIndex) +int wxComboBox::DoInsert(const wxString& szItem, unsigned int nIndex) { m_Datas.Insert(NULL, nIndex); wxAutoNSAutoreleasePool pool; [GetNSComboBox() insertItemWithObjectValue:wxNSStringWithWxString(szItem) atIndex:nIndex]; - return nIndex; + return (int)nIndex; } -void wxComboBox::DoSetItemClientData(int nIndex, void* pData) +void wxComboBox::DoSetItemClientData(unsigned int nIndex, void* pData) { m_Datas[nIndex] = pData; } -void* wxComboBox::DoGetItemClientData(int nIndex) const +void* wxComboBox::DoGetItemClientData(unsigned int nIndex) const { return m_Datas[nIndex]; } -void wxComboBox::DoSetItemClientObject(int nIndex, wxClientData* pClientData) +void wxComboBox::DoSetItemClientObject(unsigned int nIndex, wxClientData* pClientData) { m_Datas[nIndex] = (void*) pClientData; } -wxClientData* wxComboBox::DoGetItemClientObject(int nIndex) const +wxClientData* wxComboBox::DoGetItemClientObject(unsigned int nIndex) const { return (wxClientData*) m_Datas[nIndex]; }