1
//////////////////////////////////////////////////////////////////////////
3
// pgAdmin III - PostgreSQL Tools
4
// RCS-ID: $Id: ctlComboBox.cpp 4874 2006-01-06 17:33:27Z dpage $
5
// Copyright (C) 2002 - 2006, The pgAdmin Development Team
6
// This software is released under the Artistic Licence
8
// ctlComboBox.cpp - enhanced combobox control
10
//////////////////////////////////////////////////////////////////////////
15
#include "ctl/ctlComboBox.h"
16
#include "base/pgConnBase.h"
17
#include "base/pgSetBase.h"
20
class StringClientData : public wxClientData
23
StringClientData(const wxChar *c) { str=c; }
30
int ctlComboBoxFix::Append(const wxString& item, const wxString &str)
32
return wxComboBox::Append(item, new StringClientData(str));
36
int ctlComboBoxFix::Append(const wxString& item, long l)
38
return wxComboBox::Append(item, (void*)l);
42
int ctlComboBoxFix::Append(const wxString& item, OID oid)
44
return wxComboBox::Append(item, (void*)oid);
48
int ctlComboBoxFix::FillLongKey(pgConnBase *conn, const wxChar *qry)
51
pgSetIterator set(conn->ExecuteSet(qry));
52
while (set.RowsLeft())
54
long l=set.GetLong(0);
55
wxString txt=set.GetVal(1);
63
int ctlComboBoxFix::FillOidKey(pgConnBase *conn, const wxChar *qry)
66
pgSetIterator set(conn->ExecuteSet(qry));
67
while (set.RowsLeft())
69
OID oid=set.GetOid(0);
70
wxString txt=set.GetVal(1);
78
int ctlComboBoxFix::FillStringKey(pgConnBase *conn, const wxChar *qry)
81
pgSetIterator set(conn->ExecuteSet(qry));
82
while (set.RowsLeft())
84
wxString str=set.GetVal(0);
85
wxString txt=set.GetVal(1);
92
long ctlComboBoxFix::GetLongKey(int sel)
96
return (long)GetClientData(sel);
99
OID ctlComboBoxFix::GetOIDKey(int sel)
102
sel = GetSelection();
103
return (OID)GetClientData(sel);
106
wxString ctlComboBoxFix::GetStringKey(int sel)
109
sel = GetSelection();
110
StringClientData *scd=(StringClientData*)GetClientObject(sel);
113
return wxEmptyString;
117
ctlComboBoxFix::ctlComboBoxFix(wxWindow *wnd, int id, wxPoint pos, wxSize siz, long attr)
118
: wxComboBox(wnd, id, wxEmptyString, pos, siz, 0, NULL, attr)
123
bool ctlComboBoxFix::SetKey(long val)
126
for (i=0 ; i < GetCount() ; i++)
128
if (GetLongKey(i) == val)
134
SetSelection(wxNOT_FOUND);
139
bool ctlComboBoxFix::SetKey(OID val)
142
for (i=0 ; i < GetCount() ; i++)
144
if (GetOIDKey(i) == val)
150
SetSelection(wxNOT_FOUND);
155
bool ctlComboBoxFix::SetKey(const wxString &val)
158
for (i=0 ; i < GetCount() ; i++)
160
if (GetStringKey(i) == val)
166
SetSelection(wxNOT_FOUND);
171
////////////////////////////////////////////
173
ctlComboBox::ctlComboBox(wxWindow *wnd, int id, wxPoint pos, wxSize siz, long attr)
174
: ctlComboBoxFix(wnd, id, pos, siz, attr)
182
int ctlComboBox::GuessSelection(wxCommandEvent &ev)
184
if (ev.GetEventType() != wxEVT_COMMAND_TEXT_UPDATED)
185
return GetGuessedSelection();
187
wxString str=wxComboBox::GetValue();
190
long pos=GetInsertionPoint();
192
long sel, count=GetCount();
193
int len=str.Length();
194
for (sel = 0 ; sel < count ; sel++)
196
if (str == GetString(sel).Left(len))
199
wxString current = GetString(sel);
200
SetSelection(pos, current.Length());
209
int ctlComboBox::GetGuessedSelection() const
211
int sel=GetCurrentSelection();
214
sel = FindString(GetValue());
218
int ctlComboBox::GetSelection() const
220
int sel=GetCurrentSelection();
223
sel = FindString(GetValue());
227
wxString ctlComboBox::GetGuessedStringSelection() const
229
int sel=GetGuessedSelection();
231
return wxEmptyString;
233
return GetString(sel);