]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/listbox.mm
* Implement GetValue() and SetValue().
[wxWidgets.git] / src / cocoa / listbox.mm
CommitLineData
812edc25
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: cocoa/listbox.mm
3// Purpose: wxListBox
4// Author: David Elliott
5// Modified by:
6// Created: 2003/03/18
7// RCS-ID: $Id:
8// Copyright: (c) 2003 David Elliott
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/app.h"
13#include "wx/listbox.h"
14#include "wx/log.h"
15
bcaadf7e
DE
16#include "wx/cocoa/string.h"
17#include "wx/cocoa/NSTableDataSource.h"
18
19#import <Foundation/NSArray.h>
20#import <Foundation/NSEnumerator.h>
21#import <AppKit/NSTableView.h>
22#import <AppKit/NSTableColumn.h>
981af57c 23
812edc25
DE
24IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
25BEGIN_EVENT_TABLE(wxListBox, wxListBoxBase)
26END_EVENT_TABLE()
bcaadf7e 27WX_IMPLEMENT_COCOA_OWNER(wxListBox,NSTableView,NSControl,NSView)
812edc25
DE
28
29bool wxListBox::Create(wxWindow *parent, wxWindowID winid,
30 const wxPoint& pos,
31 const wxSize& size,
32 int n, const wxString choices[],
33 long style,
34 const wxValidator& validator,
35 const wxString& name)
36{
37 if(!CreateControl(parent,winid,pos,size,style,validator,name))
38 return false;
39
bcaadf7e
DE
40 // Provide the data
41 m_cocoaItems = [[NSMutableArray arrayWithCapacity:n] retain];
42 for(int i=0; i < n; i++)
43 {
44 [m_cocoaItems addObject: wxNSStringWithWxString(choices[i])];
45 }
46 // Remove everything
47 m_clientData.Clear();
48 // Initialize n elements to NULL
49 m_clientData.SetCount(n,NULL);
50
51 SetNSTableView([[NSTableView alloc] initWithFrame: MakeDefaultNSRect(size)]);
981af57c
DE
52 [m_cocoaNSView release];
53
bcaadf7e
DE
54 // Set up the data source
55 m_cocoaDataSource = [[wxCocoaNSTableDataSource alloc] init];
56 [GetNSTableView() setDataSource:m_cocoaDataSource];
57
58 // Add the single column
59 NSTableColumn *tableColumn = [[NSTableColumn alloc] initWithIdentifier:nil];
60 [GetNSTableView() addTableColumn: tableColumn];
61// [tableColumn release];
62
63 // Finish
812edc25
DE
64 if(m_parent)
65 m_parent->CocoaAddChild(this);
bcaadf7e
DE
66 SetInitialFrameRect(pos,size);
67
812edc25
DE
68 return true;
69}
70
71wxListBox::~wxListBox()
72{
bcaadf7e
DE
73 [GetNSTableView() setDataSource: nil];
74 [m_cocoaDataSource release];
75 [m_cocoaItems release];
76 DisassociateNSTableView(m_cocoaNSView);
77}
78
79int wxListBox::CocoaDataSource_numberOfRows()
80{
81 return [m_cocoaItems count];
82}
83
84struct objc_object* wxListBox::CocoaDataSource_objectForTableColumn(
85 WX_NSTableColumn tableColumn, int rowIndex)
86{
87 return [m_cocoaItems objectAtIndex:rowIndex];
812edc25
DE
88}
89
90// pure virtuals from wxListBoxBase
91bool wxListBox::IsSelected(int n) const
92{
bcaadf7e 93 return [GetNSTableView() isRowSelected: n];
812edc25
DE
94}
95
96void wxListBox::SetSelection(int n, bool select)
97{
bcaadf7e
DE
98 if(select)
99 [GetNSTableView() selectRow: n byExtendingSelection:NO];
100 else
101 [GetNSTableView() deselectRow: n];
812edc25
DE
102}
103
104int wxListBox::GetSelections(wxArrayInt& aSelections) const
105{
bcaadf7e
DE
106 aSelections.Clear();
107 NSEnumerator *enumerator = [GetNSTableView() selectedRowEnumerator];
108 while(NSNumber *num = [enumerator nextObject])
109 {
110 aSelections.Add([num intValue]);
111 }
112 return [GetNSTableView() numberOfSelectedRows];
812edc25
DE
113}
114
115void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
116{
bcaadf7e
DE
117 for(int i=int(items.GetCount())-1; i >= 0; i--)
118 {
119 [m_cocoaItems insertObject: wxNSStringWithWxString(items[i])
120 atIndex: pos];
121 m_clientData.Insert(NULL,pos);
122 }
123 [GetNSTableView() reloadData];
812edc25
DE
124}
125
126void wxListBox::DoSetItems(const wxArrayString& items, void **clientData)
127{
bcaadf7e
DE
128 // Remove everything
129 [m_cocoaItems removeAllObjects];
130 m_clientData.Clear();
131 // Provide the data
132 for(size_t i=0; i < items.GetCount(); i++)
133 {
134 [m_cocoaItems addObject: wxNSStringWithWxString(items[i])];
135 m_clientData.Add(clientData[i]);
136 }
137 [GetNSTableView() reloadData];
812edc25
DE
138}
139
140void wxListBox::DoSetFirstItem(int n)
141{
142}
143
144
145// pure virtuals from wxItemContainer
146 // deleting items
147void wxListBox::Clear()
148{
149}
150
151void wxListBox::Delete(int n)
152{
153}
154
155 // accessing strings
156int wxListBox::GetCount() const
157{
158 return 0;
159}
160
161wxString wxListBox::GetString(int n) const
162{
163 return wxEmptyString;
164}
165
166void wxListBox::SetString(int n, const wxString& s)
167{
168}
169
170int wxListBox::FindString(const wxString& s) const
171{
172 return 0;
173}
174
175 // selection
176void wxListBox::Select(int n)
177{
178}
179
180int wxListBox::GetSelection() const
181{
182 return 0;
183}
184
185int wxListBox::DoAppend(const wxString& item)
186{
187 return 0;
188}
189
190void wxListBox::DoSetItemClientData(int n, void* clientData)
191{
192}
193
194void* wxListBox::DoGetItemClientData(int n) const
195{
196 return NULL;
197}
198
199void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData)
200{
201}
202
203wxClientData* wxListBox::DoGetItemClientObject(int n) const
204{
205 return NULL;
206}
207