added combobox editor
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6214 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -77,6 +77,7 @@ class WXDLLEXPORT wxGridWindow;
|
|||||||
class WXDLLEXPORT wxGridTypeRegistry;
|
class WXDLLEXPORT wxGridTypeRegistry;
|
||||||
|
|
||||||
class WXDLLEXPORT wxCheckBox;
|
class WXDLLEXPORT wxCheckBox;
|
||||||
|
class WXDLLEXPORT wxComboBox;
|
||||||
class WXDLLEXPORT wxTextCtrl;
|
class WXDLLEXPORT wxTextCtrl;
|
||||||
class WXDLLEXPORT wxSpinCtrl;
|
class WXDLLEXPORT wxSpinCtrl;
|
||||||
|
|
||||||
@@ -409,6 +410,33 @@ private:
|
|||||||
bool m_startValue;
|
bool m_startValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// the editor for string data allowing to choose from the list of strings
|
||||||
|
class WXDLLEXPORT wxGridCellChoiceEditor : public wxGridCellEditor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// if !allowOthers, user can't type a string not in choices array
|
||||||
|
wxGridCellChoiceEditor(size_t count, const wxChar* choices[],
|
||||||
|
bool allowOthers = FALSE);
|
||||||
|
|
||||||
|
virtual void Create(wxWindow* parent,
|
||||||
|
wxWindowID id,
|
||||||
|
wxEvtHandler* evtHandler);
|
||||||
|
|
||||||
|
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
|
||||||
|
|
||||||
|
virtual void BeginEdit(int row, int col, wxGrid* grid);
|
||||||
|
virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid);
|
||||||
|
|
||||||
|
virtual void Reset();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxString m_startValue;
|
||||||
|
wxArrayString m_choices;
|
||||||
|
bool m_allowOthers;
|
||||||
|
};
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGridCellAttr: this class can be used to alter the cells appearance in
|
// wxGridCellAttr: this class can be used to alter the cells appearance in
|
||||||
// the grid by changing their colour/font/... from default. An object of this
|
// the grid by changing their colour/font/... from default. An object of this
|
||||||
|
@@ -960,12 +960,17 @@ BugsGridFrame::BugsGridFrame()
|
|||||||
grid->SetTable(table, TRUE);
|
grid->SetTable(table, TRUE);
|
||||||
|
|
||||||
wxGridCellAttr *attrRO = new wxGridCellAttr,
|
wxGridCellAttr *attrRO = new wxGridCellAttr,
|
||||||
*attrRangeEditor = new wxGridCellAttr;
|
*attrRangeEditor = new wxGridCellAttr,
|
||||||
|
*attrCombo = new wxGridCellAttr;
|
||||||
|
|
||||||
attrRO->SetReadOnly();
|
attrRO->SetReadOnly();
|
||||||
attrRangeEditor->SetEditor(new wxGridCellNumberEditor(1, 5));
|
attrRangeEditor->SetEditor(new wxGridCellNumberEditor(1, 5));
|
||||||
|
attrCombo->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities),
|
||||||
|
severities));
|
||||||
|
|
||||||
grid->SetColAttr(Col_Id, attrRO);
|
grid->SetColAttr(Col_Id, attrRO);
|
||||||
grid->SetColAttr(Col_Priority, attrRangeEditor);
|
grid->SetColAttr(Col_Priority, attrRangeEditor);
|
||||||
|
grid->SetColAttr(Col_Severity, attrCombo);
|
||||||
|
|
||||||
grid->AutoSizeColumns();
|
grid->AutoSizeColumns();
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/textctrl.h"
|
#include "wx/textctrl.h"
|
||||||
#include "wx/checkbox.h"
|
#include "wx/checkbox.h"
|
||||||
|
#include "wx/combobox.h"
|
||||||
#include "wx/valtext.h"
|
#include "wx/valtext.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -858,6 +859,84 @@ void wxGridCellBoolEditor::StartingClick()
|
|||||||
CBox()->SetValue(!CBox()->GetValue());
|
CBox()->SetValue(!CBox()->GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxGridCellChoiceEditor
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count,
|
||||||
|
const wxChar* choices[],
|
||||||
|
bool allowOthers)
|
||||||
|
: m_allowOthers(allowOthers)
|
||||||
|
{
|
||||||
|
m_choices.Alloc(count);
|
||||||
|
for ( size_t n = 0; n < count; n++ )
|
||||||
|
{
|
||||||
|
m_choices.Add(choices[n]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGridCellChoiceEditor::Create(wxWindow* parent,
|
||||||
|
wxWindowID id,
|
||||||
|
wxEvtHandler* evtHandler)
|
||||||
|
{
|
||||||
|
size_t count = m_choices.GetCount();
|
||||||
|
wxString *choices = new wxString[count];
|
||||||
|
for ( size_t n = 0; n < count; n++ )
|
||||||
|
{
|
||||||
|
choices[n] = m_choices[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
m_control = new wxComboBox(parent, id, wxEmptyString,
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
count, choices,
|
||||||
|
m_allowOthers ? 0 : wxCB_READONLY);
|
||||||
|
|
||||||
|
delete [] choices;
|
||||||
|
|
||||||
|
wxGridCellEditor::Create(parent, id, evtHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGridCellChoiceEditor::PaintBackground(const wxRect& WXUNUSED(rectCell),
|
||||||
|
wxGridCellAttr * WXUNUSED(attr))
|
||||||
|
{
|
||||||
|
// as we fill the entire client area, don't do anything here to minimize
|
||||||
|
// flicker
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
|
||||||
|
{
|
||||||
|
wxASSERT_MSG(m_control,
|
||||||
|
wxT("The wxGridCellEditor must be Created first!"));
|
||||||
|
|
||||||
|
m_startValue = grid->GetTable()->GetValue(row, col);
|
||||||
|
|
||||||
|
Combo()->SetValue(m_startValue);
|
||||||
|
Combo()->SetInsertionPointEnd();
|
||||||
|
Combo()->SetFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxGridCellChoiceEditor::EndEdit(int row, int col,
|
||||||
|
bool saveValue,
|
||||||
|
wxGrid* grid)
|
||||||
|
{
|
||||||
|
wxString value = Combo()->GetValue();
|
||||||
|
bool changed = value != m_startValue;
|
||||||
|
|
||||||
|
if ( changed )
|
||||||
|
grid->GetTable()->SetValue(row, col, value);
|
||||||
|
|
||||||
|
m_startValue = wxEmptyString;
|
||||||
|
Combo()->SetValue(m_startValue);
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGridCellChoiceEditor::Reset()
|
||||||
|
{
|
||||||
|
Combo()->SetValue(m_startValue);
|
||||||
|
Combo()->SetInsertionPointEnd();
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGridCellEditorEvtHandler
|
// wxGridCellEditorEvtHandler
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -5363,7 +5442,7 @@ int wxGrid::YToRow( int y )
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_numRows; //-1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5377,7 +5456,7 @@ int wxGrid::XToCol( int x )
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_numCols; //-1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user