~ubuntu-branches/debian/squeeze/pgadmin3/squeeze

« back to all changes in this revision

Viewing changes to src/ctl/ctlComboBox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Porcheron
  • Date: 2008-02-07 00:56:22 UTC
  • mto: (2.1.6 hardy) (6.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080207005622-c2ail8p4d0sk3dnw
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////
2
 
//
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
7
 
//
8
 
// ctlComboBox.cpp - enhanced combobox control
9
 
//
10
 
//////////////////////////////////////////////////////////////////////////
11
 
 
12
 
 
13
 
 
14
 
// App headers
15
 
#include "ctl/ctlComboBox.h"
16
 
#include "base/pgConnBase.h"
17
 
#include "base/pgSetBase.h"
18
 
 
19
 
 
20
 
class StringClientData : public wxClientData
21
 
{
22
 
public:
23
 
    StringClientData(const wxChar *c) { str=c; }
24
 
    wxString str;
25
 
};
26
 
 
27
 
 
28
 
 
29
 
 
30
 
int ctlComboBoxFix::Append(const wxString& item, const wxString &str)
31
 
{
32
 
    return wxComboBox::Append(item, new StringClientData(str));
33
 
}
34
 
 
35
 
 
36
 
int ctlComboBoxFix::Append(const wxString& item, long l)
37
 
{
38
 
    return wxComboBox::Append(item, (void*)l);
39
 
}
40
 
 
41
 
 
42
 
int ctlComboBoxFix::Append(const wxString& item, OID oid)
43
 
{
44
 
    return wxComboBox::Append(item, (void*)oid);
45
 
}
46
 
 
47
 
 
48
 
int ctlComboBoxFix::FillLongKey(pgConnBase *conn, const wxChar *qry)
49
 
{
50
 
    int cnt=0;
51
 
    pgSetIterator set(conn->ExecuteSet(qry));
52
 
    while (set.RowsLeft())
53
 
    {
54
 
        long l=set.GetLong(0);
55
 
        wxString txt=set.GetVal(1);
56
 
        Append(txt, l);
57
 
        cnt++;
58
 
    }
59
 
    return cnt;
60
 
}
61
 
 
62
 
 
63
 
int ctlComboBoxFix::FillOidKey(pgConnBase *conn, const wxChar *qry)
64
 
{
65
 
    int cnt=0;
66
 
    pgSetIterator set(conn->ExecuteSet(qry));
67
 
    while (set.RowsLeft())
68
 
    {
69
 
        OID oid=set.GetOid(0);
70
 
        wxString txt=set.GetVal(1);
71
 
        Append(txt, oid);
72
 
        cnt++;
73
 
    }
74
 
    return cnt;
75
 
}
76
 
 
77
 
 
78
 
int ctlComboBoxFix::FillStringKey(pgConnBase *conn, const wxChar *qry)
79
 
{
80
 
    int cnt=0;
81
 
    pgSetIterator set(conn->ExecuteSet(qry));
82
 
    while (set.RowsLeft())
83
 
    {
84
 
        wxString str=set.GetVal(0);
85
 
        wxString txt=set.GetVal(1);
86
 
        Append(txt, str);
87
 
        cnt++;
88
 
    }
89
 
    return cnt;
90
 
}
91
 
 
92
 
long ctlComboBoxFix::GetLongKey(int sel)
93
 
{
94
 
    if (sel < 0)
95
 
        sel = GetSelection();
96
 
    return (long)GetClientData(sel);
97
 
}
98
 
 
99
 
OID ctlComboBoxFix::GetOIDKey(int sel)
100
 
{
101
 
    if (sel < 0)
102
 
        sel = GetSelection();
103
 
    return (OID)GetClientData(sel);
104
 
}
105
 
 
106
 
wxString ctlComboBoxFix::GetStringKey(int sel)
107
 
{
108
 
    if (sel < 0)
109
 
        sel = GetSelection();
110
 
    StringClientData *scd=(StringClientData*)GetClientObject(sel);
111
 
    if (scd)
112
 
        return scd->str;
113
 
    return wxEmptyString;
114
 
}
115
 
 
116
 
 
117
 
ctlComboBoxFix::ctlComboBoxFix(wxWindow *wnd, int id, wxPoint pos, wxSize siz, long attr)
118
 
: wxComboBox(wnd, id, wxEmptyString, pos, siz, 0, NULL, attr)
119
 
{
120
 
}
121
 
 
122
 
 
123
 
bool ctlComboBoxFix::SetKey(long val)
124
 
{
125
 
    int i;
126
 
    for (i=0 ; i < GetCount() ; i++)
127
 
    {
128
 
        if (GetLongKey(i) == val)
129
 
        {
130
 
            SetSelection(i);
131
 
            return true;
132
 
        }
133
 
    }
134
 
    SetSelection(wxNOT_FOUND);
135
 
    return false;
136
 
}
137
 
 
138
 
 
139
 
bool ctlComboBoxFix::SetKey(OID val)
140
 
{
141
 
    int i;
142
 
    for (i=0 ; i < GetCount() ; i++)
143
 
    {
144
 
        if (GetOIDKey(i) == val)
145
 
        {
146
 
            SetSelection(i);
147
 
            return true;
148
 
        }
149
 
    }
150
 
    SetSelection(wxNOT_FOUND);
151
 
    return false;
152
 
}
153
 
 
154
 
 
155
 
bool ctlComboBoxFix::SetKey(const wxString &val)
156
 
{
157
 
    int i;
158
 
    for (i=0 ; i < GetCount() ; i++)
159
 
    {
160
 
        if (GetStringKey(i) == val)
161
 
        {
162
 
            SetSelection(i);
163
 
            return true;
164
 
        }
165
 
    }
166
 
    SetSelection(wxNOT_FOUND);
167
 
    return false;
168
 
}
169
 
 
170
 
 
171
 
////////////////////////////////////////////
172
 
 
173
 
ctlComboBox::ctlComboBox(wxWindow *wnd, int id, wxPoint pos, wxSize siz, long attr)
174
 
: ctlComboBoxFix(wnd, id, pos, siz, attr)
175
 
{
176
 
#ifdef __WXGTK__
177
 
    SetEditable(false);
178
 
#endif
179
 
}
180
 
 
181
 
 
182
 
int ctlComboBox::GuessSelection(wxCommandEvent &ev)
183
 
{
184
 
    if (ev.GetEventType() != wxEVT_COMMAND_TEXT_UPDATED)
185
 
        return GetGuessedSelection();
186
 
 
187
 
    wxString str=wxComboBox::GetValue();
188
 
    if (str.Length())
189
 
    {
190
 
        long pos=GetInsertionPoint();
191
 
    
192
 
        long sel, count=GetCount();
193
 
        int len=str.Length();
194
 
        for (sel = 0 ; sel < count ; sel++)
195
 
        {
196
 
            if (str == GetString(sel).Left(len))
197
 
            {
198
 
                SetSelection(sel);
199
 
                wxString current = GetString(sel);
200
 
                SetSelection(pos, current.Length());
201
 
                return sel;
202
 
            }
203
 
        }
204
 
    }
205
 
    return -1;
206
 
}
207
 
 
208
 
 
209
 
int ctlComboBox::GetGuessedSelection() const
210
 
{
211
 
    int sel=GetCurrentSelection();
212
 
 
213
 
    if (sel < 0)
214
 
        sel = FindString(GetValue());
215
 
    return sel;
216
 
}
217
 
 
218
 
int ctlComboBox::GetSelection() const
219
 
{
220
 
    int sel=GetCurrentSelection();
221
 
 
222
 
    if (sel < 0)
223
 
        sel = FindString(GetValue());
224
 
    return sel;
225
 
}
226
 
 
227
 
wxString ctlComboBox::GetGuessedStringSelection() const
228
 
{
229
 
    int sel=GetGuessedSelection();
230
 
    if (sel < 0)
231
 
        return wxEmptyString;
232
 
    else
233
 
        return GetString(sel);
234
 
}