tan wrote:
I'd like to look at your class definition and the metods implementation.
I don't beleive it will compile since I did not include all necessary files. but you'll see all the class.
Code: Select all
#define __COMBOBOX_H
// wxWindows headers
#include <wx/wx.h>
#include "pg/base.h"
class pgConnBase;
class ctlComboBox : public wxComboBox
{
public:
ctlComboBox(wxWindow *wnd, int id, wxPoint pos, wxSize siz, long attr);
int Append(const wxString& item, const wxString &str);
int Append(const wxString& item, long l);
long GetLongKey(int sel=-1);
wxString GetStringKey(int sel=-1);
bool SetKey(long val);
bool SetKey(const wxString &val);
int FillLongKey(pgConn &conn, const wxChar *qry);
int FillStringKey (pgConn &conn, const wxChar *qry, bool lPrependKey);
void FillComboLib(pgConn &conn, const wxString groupe, bool lPrependKey=false);
void FillComboSeg(pgConn &conn, const wxString groupe, bool lPrependKey=false);
}
#endif
Code: Select all
// App headers
#include "pg/pgConnBase.h"
#include "pg/pgSetBase.h"
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
ctlComboBox::ctlComboBox(wxWindow *wnd, int id, wxPoint pos, wxSize siz, long attr)
: wxComboBox(wnd, id, wxEmptyString, pos, siz, 0, NULL, attr)
{}
int ctlComboBox::Append(const wxString& item, const wxString &str)
{
return wxComboBox::Append(item, new wxStringClientData (str));
}
int ctlComboBox::Append(const wxString& item, long l)
{
return wxComboBox::Append(item, (void*)l);
}
int ctlComboBox::FillLongKey(pgConn &conn, const wxChar *qry)
{
int cnt=0;
pgSetIterator set(conn.ExecuteSet(qry));
while (set.RowsLeft())
{
long l=set.GetLong(0);
wxString txt=set.GetVal(1);
Append(txt, l);
cnt++;
}
return cnt;
}
int ctlComboBox::FillStringKey(pgConn &conn, const wxChar *qry, bool lPrependKey)
{
int cnt=0;
pgSetIterator Set(conn.ExecuteSet(qry));
while (Set.RowsLeft()) // Fill it now !
{
wxString str=Set.GetVal(0);
wxString txt=Set.GetVal(0); //.Set()->TLibell();// Process with user language concern
str = str.Strip(wxString::trailing);
txt = txt.Strip(wxString::trailing);
if (lPrependKey)
{
txt = txt.Prepend(_(" - ")); // Key is preprended to the item text
txt = txt.Prepend(str);
}
Append(txt, str);
cnt++;
}
}
long ctlComboBox::GetLongKey(int sel)
{
if (sel < 0)
sel = GetSelection();
return (long)GetClientData(sel);
}
wxString ctlComboBox::GetStringKey(int sel)
{
if (sel < 0)
sel = GetSelection();
wxStringClientData *scd=(wxStringClientData *)GetClientObject(sel);
if (scd)
return scd->GetData() ;
return wxEmptyString;
}
bool ctlComboBox::SetKey(long val)
{
int i;
for (i=0 ; i < GetCount() ; i++)
{
if (GetLongKey(i) == val)
{
SetSelection(i);
return true;
}
}
SetSelection(wxNOT_FOUND);
return false;
}
bool ctlComboBox::SetKey(const wxString &val)
{
int i;
for (i=0 ; i < GetCount() ; i++)
{
if (GetStringKey(i) == val)
{
SetSelection(i);
return true;
}
}
SetSelection(wxNOT_FOUND);
return false;
}