Files
l7/LBoundComboBox.cpp

279 lines
6.3 KiB
C++
Raw Permalink Normal View History

2018-04-25 20:43:41 +02:00
/*
* File: LBoundComboBox.cpp
2022-11-19 16:05:44 +01:00
* Author: Saleem Edah-Tally - nmset@yandex.com
2018-04-25 20:43:41 +02:00
* License : LGPL version 2.1
2022-11-19 16:05:44 +01:00
* Copyright Saleem Edah-Tally, M. D. - © 2014
2018-04-25 20:43:41 +02:00
*
* Created on 3 juin 2014, 19:00
*/
#include "LBoundComboBox.h"
#include "LItemData.h"
LBoundComboBox::LBoundComboBox(wxWindow* parent, wxWindowID id)
: wxComboBox(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY)
{
m_sqlQuote = wxEmptyString;
SetNull();
}
LBoundComboBox::~LBoundComboBox()
{
if (m_rs) m_rs->UnRegisterControl(this);
}
bool LBoundComboBox::IsTranslated() const
{
if (HasClientObjectData())
{
for (unsigned int i = 0; i < GetCount(); i++)
{
LItemData * x = static_cast<LItemData*> (GetClientObject(i));
if (x != NULL) return true;
}
}
return false;
}
bool LBoundComboBox::SelectionIsTranslated() const
{
if (IsTranslated())
{
LItemData * x = static_cast<LItemData*> (GetClientObject(GetSelection()));
return (x != NULL);
}
else
{
return false;
}
}
const wxAny LBoundComboBox::GetDataOfIndex(unsigned int idx) const
{
if (IsTranslated())
{
LItemData * x = static_cast<LItemData*> (GetClientObject(idx));
if (x != NULL) return x->GetData();
return wxEmptyString;
}
else
{
return GetString(idx);
}
}
const int LBoundComboBox::GetIndexOfData(const wxAny& data) const
{
const wxString sdata = data.As<wxString>();
if (IsTranslated())
{
/* C001 Can be costly if there are thousands of items !
* In such a case, the control's usefulness is doubtful.
*/
for (unsigned int i = 0; i < GetCount(); i++)
{
LItemData * x = static_cast<LItemData*> (GetClientObject(i));
if (x)
{
if (x->GetData().As<wxString>() == sdata)
{
return i;
}
}
}
return wxNOT_FOUND;
}
else
{
return FindString(sdata);
}
}
const wxString LBoundComboBox::GetItemOfData(const wxAny& data) const
{
if (IsTranslated())
{
// See C001
const wxString sdata = data.As<wxString>();
for (unsigned int i = 0; i < GetCount(); i++)
{
LItemData * x = static_cast<LItemData*> (GetClientObject(i));
if (x != NULL)
{
if (x->GetData().As<wxString>() == sdata)
{
return GetString(i);
}
}
}
}
return wxEmptyString;
}
const wxAny LBoundComboBox::GetDataOfItem(const wxString& item) const
{
if (IsTranslated())
{
const int idx = FindString(item, true);
LItemData * x = static_cast<LItemData*> (GetClientObject(idx));
if (x != NULL) return x->GetData();
return wxEmptyString;
}
else
{
return item;
}
}
const wxString LBoundComboBox::GetItemOfNull() const
{
if (IsTranslated())
{
// See C001
for (unsigned int i = 0; i < GetCount(); i++)
{
LItemData * x = static_cast<LItemData*> (GetClientObject(i));
if (x == NULL) return GetString(i);
}
}
return wxEmptyString;
}
const int LBoundComboBox::GetIndexOfNull() const
{
if (IsTranslated())
{
// See C001
for (unsigned int i = 0; i < GetCount(); i++)
{
LItemData * x = static_cast<LItemData*> (GetClientObject(i));
if (x == NULL) return i;
}
}
return wxNOT_FOUND;
}
void LBoundComboBox::Clear()
{
wxComboBox::Clear();
const long wsflags = GetWindowStyleFlag();
SetWindowStyleFlag(0);
SetSelection(wxNOT_FOUND);
SetValue(wxEmptyString);
SetWindowStyleFlag(wsflags);
}
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
void LBoundComboBox::SetData(const wxAny& data)
2018-04-25 20:43:41 +02:00
{
const wxString sData = data.As<wxString>();
if (IsTranslated())
{
if (data.IsNull()
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
|| sData.IsEmpty()
|| sData == L_SQLNULL)
2018-04-25 20:43:41 +02:00
{
SetNull();
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
return;
2018-04-25 20:43:41 +02:00
}
for (unsigned int i = 0; i < GetCount(); i++)
{
LItemData * x = static_cast<LItemData*> (GetClientObject(i));
if (x)
{
if (x->GetData().As<wxString>() == sData)
{
SetSelection(i);
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
return;
2018-04-25 20:43:41 +02:00
}
}
}
}
else
{
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
//bool hasData = FindString(sData, true);
2018-04-25 20:43:41 +02:00
SetValue(sData);
}
}
const wxAny LBoundComboBox::GetData()
{
if (IsNull()) return L_SQLNULL;
if (IsTranslated())
{
LItemData * x = static_cast<LItemData*> (GetClientObject(GetSelection()));
if (x != NULL)
{
return x->GetData();
}
else
{
return L_SQLNULL;
}
}
else
{
return GetValue();
}
}
void LBoundComboBox::SetResultSet(LResultSet* newResultSet)
{
m_rs = newResultSet;
if (m_rs == NULL) return;
m_rs->RegisterControl(this);
}
bool LBoundComboBox::IsNull()
{
if (IsTranslated())
{
if (GetSelection() != wxNOT_FOUND)
{
if (SelectionIsTranslated())
{
LItemData * x = static_cast<LItemData*> (GetClientObject(GetSelection()));
if (x != NULL) return false;
}
}
return true;
}
else
{
return (GetValue().IsEmpty());
}
}
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
void LBoundComboBox::SetNull()
2018-04-25 20:43:41 +02:00
{
if (IsTranslated())
{
for (unsigned int i = 0; i < GetCount(); i++)
{
wxClientData * x = GetClientObject(i);
if (x == NULL)
{
SetSelection(i);
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
return;
2018-04-25 20:43:41 +02:00
}
}
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
return;
2018-04-25 20:43:41 +02:00
}
long wsflags = GetWindowStyleFlag();
SetWindowStyleFlag(0);
SetSelection(wxNOT_FOUND);
SetValue(wxEmptyString);
SetWindowStyleFlag(wsflags);
}
bool LBoundComboBox::IsDirty()
{
wxASSERT_MSG(m_rs != NULL, "m_rs est NULL.");
wxAny BEData = m_rs->GetData(m_columnName);
if (BEData.As<wxString>().IsEmpty()) BEData = L_SQLNULL;
return (GetData().As<wxString>() != BEData.As<wxString>());
}
const wxString LBoundComboBox::GetDisplayedData()
{
return GetValue();
}