+//
+// Impl notes:
+// 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 returned by an NSNumber
+// from the methods.
+//
+// One problem though is that wxCB_SORT isn't implemented...
+//
+// Also, not sure if it is correctly getting text field events since
+// I'm using SetNSComboBox instead of SetNSTextField
+//
+// 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
+//
+// setIntercellSpacing:/setItemHeight: to autoadjust to number of inserted items?
+//
+/*
+ //example of autocompletion from SimpleComboBox Example
+ // ==========================================================
+// Combo box data source methods
+// ==========================================================
+
+- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox {
+ return [genres count];
+}
+- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index {
+ return [genres objectAtIndex:index];
+}
+- (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)string {
+ return [genres indexOfObject: string];
+}
+
+- (NSString *) firstGenreMatchingPrefix:(NSString *)prefix {
+ NSString *string = nil;
+ NSString *lowercasePrefix = [prefix lowercaseString];
+ NSEnumerator *stringEnum = [genres objectEnumerator];
+ while ((string = [stringEnum nextObject])) {
+ if ([[string lowercaseString] hasPrefix: lowercasePrefix]) return string;
+ }
+ return nil;
+}
+
+- (NSString *)comboBox:(NSComboBox *)aComboBox completedString:(NSString *)inputString {
+ // This method is received after each character typed by the user, because we have checked the "completes" flag for genreComboBox in IB.
+ // Given the inputString the user has typed, see if we can find a genre with the prefix, and return it as the suggested complete string.
+ NSString *candidate = [self firstGenreMatchingPrefix: inputString];
+ return (candidate ? candidate : inputString);
+}
+*/
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "wx/wxprec.h"
+#if wxUSE_COMBOBOX
+
+#ifndef WX_PRECOMP
+ #include "wx/window.h"
+#endif // WX_PRECOMP
+
+#include "wx/cocoa/ObjcPose.h"
+#include "wx/combobox.h"
+
+#import <AppKit/NSComboBox.h>
+#import <Foundation/NSNotification.h>
+#import <Foundation/NSString.h>
+
+// ----------------------------------------------------------------------------
+// globals
+// ----------------------------------------------------------------------------
+WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSComboBox)
+
+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];
+ [[NSNotificationCenter defaultCenter] addObserver:(id)cocoaNSComboBox selector:@selector(comboBoxSelectionDidChange:) name:@"NSComboBoxWillPopUpNotification" object:cocoaNSComboBox];
+ }
+}
+
+void wxCocoaNSComboBox::DisassociateNSComboBox(WX_NSComboBox cocoaNSComboBox)
+{
+ if(cocoaNSComboBox)
+ {
+ sm_cocoaHash.erase(cocoaNSComboBox);
+ [[NSNotificationCenter defaultCenter] removeObserver:(id)cocoaNSComboBox name:@"NSComboBoxSelectionDidChangeNotification" object:cocoaNSComboBox];
+ [[NSNotificationCenter defaultCenter] removeObserver:(id)cocoaNSComboBox name:@"NSComboBoxSelectionIsChangingNotification" object:cocoaNSComboBox];
+ [[NSNotificationCenter defaultCenter] removeObserver:(id)cocoaNSComboBox name:@"NSComboBoxWillDismissNotification" object:cocoaNSComboBox];
+ [[NSNotificationCenter defaultCenter] removeObserver:(id)cocoaNSComboBox name:@"NSComboBoxWillPopUpNotification" object:cocoaNSComboBox];
+ }
+}
+
+// ============================================================================
+// @class wxPoserNSComboBox
+// ============================================================================
+@interface wxPoserNSComboBox : NSComboBox
+{
+}
+
+- (void)comboBoxSelectionDidChange:(NSNotification *)notification;
+- (void)comboBoxSelectionIsChanging:(NSNotification *)notification;
+- (void)comboBoxWillDismiss:(NSNotification *)notification;
+- (void)comboBoxWillPopUp:(NSNotification *)notification;
+@end // wxPoserNSComboBox
+
+//WX_IMPLEMENT_POSER(wxPoserNSComboBox);
+@implementation wxPoserNSComboBox : NSComboBox
+
+- (void)comboBoxSelectionDidChange:(NSNotification *)notification
+{
+ wxCocoaNSComboBox *win = wxCocoaNSComboBox::GetFromCocoa(self);
+ win->doWxEvent(wxEVT_COMMAND_COMBOBOX_SELECTED);
+}
+
+- (void)comboBoxSelectionIsChanging:(NSNotification *)notification
+{
+ //...
+}
+
+- (void)comboBoxWillDismiss:(NSNotification *)notification
+{
+ //...
+}
+
+- (void)comboBoxWillPopUp:(NSNotification *)notification
+{
+ //...
+}
+
+@end // implementation wxPoserNSComboBox
+