2
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21
* Implementation of the listbox wrapper for the mforms library.
25
#include "wf_listbox.h"
27
using namespace MySQL;
28
using namespace MySQL::Forms;
30
//----------------- Static interface functions -----------------------------------------------------
32
bool ListBoxImpl::create(::mforms::ListBox *self, bool multi_select)
34
ListBoxImpl ^listbox= gcnew ListBoxImpl(self);
36
if (listbox != nullptr)
38
ListBox^ l= ViewImpl::create<ListBox>(self, listbox);
39
l->Size= Size(100, 100);
41
l->SelectionMode= SelectionMode::MultiExtended;
42
l->SelectedIndexChanged += gcnew System::EventHandler(&ListBoxImpl::selection_changed);
48
//--------------------------------------------------------------------------------------------------
50
void ListBoxImpl::selection_changed(System::Object ^sender, System::EventArgs ^e)
52
Windows::Forms::ListBox^ list= (Windows::Forms::ListBox^)sender;
54
if (list->Tag != nullptr)
56
::mforms::ListBox* listbox= ViewImpl::get_backend_control<::mforms::ListBox>(list);
58
listbox->selection_changed();
62
//--------------------------------------------------------------------------------------------------
64
void ListBoxImpl::clear(::mforms::ListBox *self)
66
ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
67
if (listbox != nullptr)
71
//--------------------------------------------------------------------------------------------------
73
void ListBoxImpl::set_heading(::mforms::ListBox *self, const std::string &text)
75
// TODO: what's the heading of a listbox?
78
//--------------------------------------------------------------------------------------------------
80
void ListBoxImpl::add_items(::mforms::ListBox *self, const list<string> &items)
82
ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
83
if (listbox != nullptr)
84
listbox->add_items(items);
87
//--------------------------------------------------------------------------------------------------
89
int ListBoxImpl::add_item(::mforms::ListBox *self, const std::string &item)
91
ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
92
if (listbox != nullptr)
93
return listbox->add_item(item);
97
//--------------------------------------------------------------------------------------------------
99
string ListBoxImpl::get_text(::mforms::ListBox *self)
101
ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
102
if (listbox != nullptr)
103
return listbox->get_text();
107
//--------------------------------------------------------------------------------------------------
109
void ListBoxImpl::set_index(::mforms::ListBox *self, int index)
111
ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
112
if (listbox != nullptr)
113
listbox->set_index(index);
116
//--------------------------------------------------------------------------------------------------
118
int ListBoxImpl::get_index(::mforms::ListBox *self)
120
ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
121
if (listbox != nullptr)
122
return listbox->get_index();
126
//--------------------------------------------------------------------------------------------------
128
std::vector<int> ListBoxImpl::get_selected_indices(::mforms::ListBox *self)
130
ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
131
if (listbox != nullptr)
132
return listbox->get_selected_indices();
133
return std::vector<int>();
136
//----------------- Actual implementation ----------------------------------------------------------
138
ListBoxImpl::ListBoxImpl(::mforms::ListBox *self)
143
//--------------------------------------------------------------------------------------------------
145
void ListBoxImpl::clear()
147
get_control<ListBox>()->Items->Clear();
150
//--------------------------------------------------------------------------------------------------
152
void ListBoxImpl::set_heading(const std::string &text)
154
// TODO: make composite with a box, a label and a listbox.
157
//--------------------------------------------------------------------------------------------------
159
void ListBoxImpl::add_items(const list<string> &items)
161
ListBox^ listbox= get_control<ListBox>();
162
listbox->BeginUpdate();
165
for each(string entry in items)
166
listbox->Items->Add(CppStringToNative(entry));
170
listbox->EndUpdate();
174
//--------------------------------------------------------------------------------------------------
176
int ListBoxImpl::add_item(const string &item)
178
return get_control<ListBox>()->Items->Add(CppStringToNative(item));
181
//--------------------------------------------------------------------------------------------------
183
string ListBoxImpl::get_text()
185
if (get_control<ListBox>()->SelectedIndex < 0)
188
return NativeToCppString(get_control<ListBox>()->SelectedItem->ToString());
191
//--------------------------------------------------------------------------------------------------
193
void ListBoxImpl::set_index(int index)
195
get_control<ListBox>()->SelectedIndex= index;
198
//--------------------------------------------------------------------------------------------------
200
int ListBoxImpl::get_index()
202
return get_control<ListBox>()->SelectedIndex;
205
//--------------------------------------------------------------------------------------------------
207
std::vector<int> ListBoxImpl::get_selected_indices()
209
std::vector<int> result;
210
ListBox^ listbox= get_control<ListBox>();
211
for each (int index in listbox->SelectedIndices)
212
result.push_back(index);
216
//--------------------------------------------------------------------------------------------------