~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/forms/winforms/src/wf_listbox.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
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
 
7
 * License.
 
8
 * 
 
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.
 
13
 * 
 
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
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
/**
 
21
 * Implementation of the listbox wrapper for the mforms library.
 
22
 */
 
23
 
 
24
#include "stdafx.h"
 
25
#include "wf_listbox.h"
 
26
 
 
27
using namespace MySQL;
 
28
using namespace MySQL::Forms;
 
29
 
 
30
//----------------- Static interface functions -----------------------------------------------------
 
31
 
 
32
bool ListBoxImpl::create(::mforms::ListBox *self, bool multi_select)
 
33
{
 
34
  ListBoxImpl ^listbox= gcnew ListBoxImpl(self);
 
35
 
 
36
  if (listbox != nullptr)
 
37
  {
 
38
    ListBox^ l= ViewImpl::create<ListBox>(self, listbox);
 
39
    l->Size= Size(100, 100);
 
40
    if (multi_select)
 
41
      l->SelectionMode= SelectionMode::MultiExtended;
 
42
    l->SelectedIndexChanged += gcnew System::EventHandler(&ListBoxImpl::selection_changed);
 
43
    return true;
 
44
  }
 
45
  return false;
 
46
}
 
47
 
 
48
//--------------------------------------------------------------------------------------------------
 
49
 
 
50
void ListBoxImpl::selection_changed(System::Object ^sender, System::EventArgs ^e)
 
51
{
 
52
  Windows::Forms::ListBox^ list= (Windows::Forms::ListBox^)sender;
 
53
 
 
54
  if (list->Tag != nullptr)
 
55
  {
 
56
    ::mforms::ListBox* listbox= ViewImpl::get_backend_control<::mforms::ListBox>(list);
 
57
    if (listbox != 0)
 
58
      listbox->selection_changed();
 
59
  }
 
60
}
 
61
 
 
62
//--------------------------------------------------------------------------------------------------
 
63
 
 
64
void ListBoxImpl::clear(::mforms::ListBox *self)
 
65
{
 
66
  ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
 
67
  if (listbox != nullptr)
 
68
    listbox->clear();
 
69
}
 
70
 
 
71
//--------------------------------------------------------------------------------------------------
 
72
 
 
73
void ListBoxImpl::set_heading(::mforms::ListBox *self, const std::string &text)
 
74
{
 
75
  // TODO: what's the heading of a listbox?
 
76
}
 
77
 
 
78
//--------------------------------------------------------------------------------------------------
 
79
 
 
80
void ListBoxImpl::add_items(::mforms::ListBox *self, const list<string> &items)
 
81
{
 
82
  ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
 
83
  if (listbox != nullptr)
 
84
    listbox->add_items(items);
 
85
}
 
86
 
 
87
//--------------------------------------------------------------------------------------------------
 
88
 
 
89
int ListBoxImpl::add_item(::mforms::ListBox *self, const std::string &item)
 
90
{
 
91
  ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
 
92
  if (listbox != nullptr)
 
93
    return listbox->add_item(item);
 
94
  return -1;
 
95
}
 
96
 
 
97
//--------------------------------------------------------------------------------------------------
 
98
 
 
99
string ListBoxImpl::get_text(::mforms::ListBox *self)
 
100
{
 
101
  ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
 
102
  if (listbox != nullptr)
 
103
    return listbox->get_text();
 
104
  return "";
 
105
}
 
106
 
 
107
//--------------------------------------------------------------------------------------------------
 
108
 
 
109
void ListBoxImpl::set_index(::mforms::ListBox *self, int index)
 
110
{
 
111
  ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
 
112
  if (listbox != nullptr)
 
113
    listbox->set_index(index);
 
114
}
 
115
 
 
116
//--------------------------------------------------------------------------------------------------
 
117
 
 
118
int ListBoxImpl::get_index(::mforms::ListBox *self)
 
119
{
 
120
  ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
 
121
  if (listbox != nullptr)
 
122
    return listbox->get_index();
 
123
  return -1;
 
124
}
 
125
 
 
126
//--------------------------------------------------------------------------------------------------
 
127
 
 
128
std::vector<int> ListBoxImpl::get_selected_indices(::mforms::ListBox *self)
 
129
{
 
130
  ListBoxImpl^ listbox= (ListBoxImpl^)ObjectImpl::FromUnmanaged(self);
 
131
  if (listbox != nullptr)
 
132
    return listbox->get_selected_indices();
 
133
  return std::vector<int>();
 
134
}
 
135
 
 
136
//----------------- Actual implementation ----------------------------------------------------------
 
137
 
 
138
ListBoxImpl::ListBoxImpl(::mforms::ListBox *self)
 
139
  : ViewImpl(self)
 
140
{
 
141
}
 
142
 
 
143
//--------------------------------------------------------------------------------------------------
 
144
 
 
145
void ListBoxImpl::clear()
 
146
{
 
147
  get_control<ListBox>()->Items->Clear();
 
148
}
 
149
 
 
150
//--------------------------------------------------------------------------------------------------
 
151
 
 
152
void ListBoxImpl::set_heading(const std::string &text)
 
153
{
 
154
  // TODO: make composite with a box, a label and a listbox.
 
155
}
 
156
 
 
157
//--------------------------------------------------------------------------------------------------
 
158
 
 
159
void ListBoxImpl::add_items(const list<string> &items)
 
160
{
 
161
  ListBox^ listbox= get_control<ListBox>();
 
162
  listbox->BeginUpdate();
 
163
  try
 
164
  {
 
165
    for each(string entry in items)
 
166
      listbox->Items->Add(CppStringToNative(entry));
 
167
  }
 
168
  finally
 
169
  {
 
170
    listbox->EndUpdate();
 
171
  }
 
172
}
 
173
 
 
174
//--------------------------------------------------------------------------------------------------
 
175
 
 
176
int ListBoxImpl::add_item(const string &item)
 
177
{
 
178
  return get_control<ListBox>()->Items->Add(CppStringToNative(item));
 
179
}
 
180
 
 
181
//--------------------------------------------------------------------------------------------------
 
182
 
 
183
string ListBoxImpl::get_text()
 
184
{
 
185
  if (get_control<ListBox>()->SelectedIndex < 0)
 
186
    return "";
 
187
 
 
188
  return NativeToCppString(get_control<ListBox>()->SelectedItem->ToString());
 
189
}
 
190
 
 
191
//--------------------------------------------------------------------------------------------------
 
192
 
 
193
void ListBoxImpl::set_index(int index)
 
194
{
 
195
  get_control<ListBox>()->SelectedIndex= index;
 
196
}
 
197
 
 
198
//--------------------------------------------------------------------------------------------------
 
199
 
 
200
int ListBoxImpl::get_index()
 
201
{
 
202
  return get_control<ListBox>()->SelectedIndex;
 
203
}
 
204
 
 
205
//--------------------------------------------------------------------------------------------------
 
206
 
 
207
std::vector<int> ListBoxImpl::get_selected_indices()
 
208
{
 
209
  std::vector<int> result;
 
210
  ListBox^ listbox= get_control<ListBox>();
 
211
  for each (int index in listbox->SelectedIndices)
 
212
    result.push_back(index);
 
213
  return result;
 
214
}
 
215
 
 
216
//--------------------------------------------------------------------------------------------------
 
217