1. warning in gtk/menu.cpp fixed

2. Unicode fix in msw/textctrl.cpp
3. more parameters support in grid editors/handlers


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6380 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2000-03-01 18:55:29 +00:00
parent 66eca538a0
commit c4608a8af3
6 changed files with 311 additions and 127 deletions

View File

@ -58,6 +58,7 @@
#define wxGRID_VALUE_BOOL _T("bool")
#define wxGRID_VALUE_NUMBER _T("long")
#define wxGRID_VALUE_FLOAT _T("double")
#define wxGRID_VALUE_CHOICE _T("choice")
#define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
#define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
@ -89,17 +90,17 @@ class WXDLLEXPORT wxSpinCtrl;
#define wxSafeDecRef(p) if ( p ) (p)->DecRef()
// ----------------------------------------------------------------------------
// wxGridCellRenderer: this class is responsible for actually drawing the cell
// in the grid. You may pass it to the wxGridCellAttr (below) to change the
// format of one given cell or to wxGrid::SetDefaultRenderer() to change the
// view of all cells. This is an ABC, you will normally use one of the
// predefined derived classes or derive your own class from it.
// wxGridCellWorker: common base class for wxGridCellRenderer and
// wxGridCellEditor
//
// NB: this is more an implementation convenience than a design issue, so this
// class is not documented and is not public at all
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGridCellRenderer
class WXDLLEXPORT wxGridCellWorker
{
public:
wxGridCellRenderer() { m_nRef = 1; }
wxGridCellWorker() { m_nRef = 1; }
// this class is ref counted: it is created with ref count of 1, so
// calling DecRef() once will delete it. Calling IncRef() allows to lock
@ -107,6 +108,34 @@ public:
void IncRef() { m_nRef++; }
void DecRef() { if ( !--m_nRef ) delete this; }
// interpret renderer parameters: arbitrary string whose interpretatin is
// left to the derived classes
virtual void SetParameters(const wxString& params);
protected:
// virtual dtor for any base class - private because only DecRef() can
// delete us
virtual ~wxGridCellWorker();
private:
size_t m_nRef;
// suppress the stupid gcc warning about the class having private dtor and
// no friends
friend class wxGridCellWorkerDummyFriend;
};
// ----------------------------------------------------------------------------
// wxGridCellRenderer: this class is responsible for actually drawing the cell
// in the grid. You may pass it to the wxGridCellAttr (below) to change the
// format of one given cell or to wxGrid::SetDefaultRenderer() to change the
// view of all cells. This is an ABC, you will normally use one of the
// predefined derived classes or derive your own class from it.
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGridCellRenderer : public wxGridCellWorker
{
public:
// draw the given cell on the provided DC inside the given rectangle
// using the style specified by the attribute and the default or selected
// state corresponding to the isSelected value.
@ -127,24 +156,8 @@ public:
wxDC& dc,
int row, int col) = 0;
// interpret renderer parameters: arbitrary string whose interpretatin is
// left to the derived classes
virtual void SetParameters(const wxString& params);
// create a new object which is the copy of this one
virtual wxGridCellRenderer *Clone() const = 0;
protected:
// virtual dtor for any base class - private because only DecRef() can
// delete us
virtual ~wxGridCellRenderer();
private:
size_t m_nRef;
// suppress the stupid gcc warning about the class having private dtor and
// no friends
friend class wxGridCellRendererDummyFriend;
};
// the default renderer for the cells containing string data
@ -278,17 +291,11 @@ private:
// even for the entire grid.
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGridCellEditor
class WXDLLEXPORT wxGridCellEditor : public wxGridCellWorker
{
public:
wxGridCellEditor();
// this class is ref counted: it is created with ref count of 1, so
// calling DecRef() once will delete it. Calling IncRef() allows to lock
// it until the matching DecRef() is called
void IncRef() { m_nRef++; }
void DecRef() { if ( !--m_nRef ) delete this; }
bool IsCreated() { return m_control != NULL; }
// Creates the actual edit control
@ -334,13 +341,13 @@ public:
// Final cleanup
virtual void Destroy();
// create a new object which is the copy of this one
virtual wxGridCellEditor *Clone() const = 0;
protected:
// the dtor is private because only DecRef() can delete us
virtual ~wxGridCellEditor();
// the ref count - when it goes to 0, we die
size_t m_nRef;
// the control we show on screen
wxControl* m_control;
@ -376,6 +383,12 @@ public:
virtual void StartingKey(wxKeyEvent& event);
virtual void HandleReturn(wxKeyEvent& event);
// parameters string format is "max_width"
virtual void SetParameters(const wxString& params);
virtual wxGridCellEditor *Clone() const
{ return new wxGridCellTextEditor; }
protected:
wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
@ -384,6 +397,7 @@ protected:
void DoReset(const wxString& startValue);
private:
size_t m_maxChars; // max number of chars allowed
wxString m_startValue;
};
@ -405,6 +419,12 @@ public:
virtual void Reset();
virtual void StartingKey(wxKeyEvent& event);
// parameters string format is "min,max"
virtual void SetParameters(const wxString& params);
virtual wxGridCellEditor *Clone() const
{ return new wxGridCellNumberEditor(m_min, m_max); }
protected:
wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
@ -436,6 +456,9 @@ public:
virtual void Reset();
virtual void StartingKey(wxKeyEvent& event);
virtual wxGridCellEditor *Clone() const
{ return new wxGridCellFloatEditor; }
protected:
// string representation of m_valueOld
wxString GetString() const
@ -462,6 +485,9 @@ public:
virtual void Reset();
virtual void StartingClick();
virtual wxGridCellEditor *Clone() const
{ return new wxGridCellBoolEditor; }
protected:
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
@ -474,7 +500,8 @@ 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[],
wxGridCellChoiceEditor(size_t count = 0,
const wxChar* choices[] = NULL,
bool allowOthers = FALSE);
virtual void Create(wxWindow* parent,
@ -488,6 +515,11 @@ public:
virtual void Reset();
// parameters string format is "item1[,item2[...,itemN]]"
virtual void SetParameters(const wxString& params);
virtual wxGridCellEditor *Clone() const;
protected:
wxComboBox *Combo() const { return (wxComboBox *)m_control; }

View File

@ -870,8 +870,10 @@ wxString BugsGridTable::GetTypeName(int WXUNUSED(row), int col)
// fall thorugh (TODO should be a list)
case Col_Summary:
return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING);
case Col_Platform:
return wxGRID_VALUE_STRING;
return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE);
case Col_Opened:
return wxGRID_VALUE_BOOL;

View File

@ -47,6 +47,7 @@
#include "wx/textfile.h"
#include "wx/spinctrl.h"
#include "wx/tokenzr.h"
#include "wx/grid.h"
@ -286,7 +287,19 @@ public:
void RegisterDataType(const wxString& typeName,
wxGridCellRenderer* renderer,
wxGridCellEditor* editor);
// find one of already registered data types
int FindRegisteredDataType(const wxString& typeName);
// try to FindRegisteredDataType(), if this fails and typeName is one of
// standard typenames, register it and return its index
int FindDataType(const wxString& typeName);
// try to FindDataType(), if it fails see if it is not one of already
// registered data types with some params in which case clone the
// registered data type and set params for it
int FindOrCloneDataType(const wxString& typeName);
wxGridCellRenderer* GetRenderer(int index);
wxGridCellEditor* GetEditor(int index);
@ -338,8 +351,6 @@ static const int GRID_HASH_SIZE = 100;
wxGridCellEditor::wxGridCellEditor()
{
m_control = NULL;
m_nRef = 1;
}
@ -455,6 +466,7 @@ void wxGridCellEditor::StartingClick()
wxGridCellTextEditor::wxGridCellTextEditor()
{
m_maxChars = 0;
}
void wxGridCellTextEditor::Create(wxWindow* parent,
@ -468,6 +480,8 @@ void wxGridCellTextEditor::Create(wxWindow* parent,
#endif
);
// TODO: use m_maxChars
wxGridCellEditor::Create(parent, id, evtHandler);
}
@ -604,6 +618,28 @@ void wxGridCellTextEditor::HandleReturn(wxKeyEvent& event)
#endif
}
void wxGridCellTextEditor::SetParameters(const wxString& params)
{
if ( !params )
{
// reset to default
m_maxChars = 0;
}
else
{
long tmp;
if ( !params.ToLong(&tmp) )
{
wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string "
"'%s' ignored"), params.c_str());
}
else
{
m_maxChars = (size_t)tmp;
}
}
}
// ----------------------------------------------------------------------------
// wxGridCellNumberEditor
// ----------------------------------------------------------------------------
@ -723,6 +759,35 @@ void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event)
event.Skip();
}
void wxGridCellNumberEditor::SetParameters(const wxString& params)
{
if ( !params )
{
// reset to default
m_min =
m_max = -1;
}
else
{
long tmp;
if ( params.BeforeFirst(_T(',')).ToLong(&tmp) )
{
m_min = (int)tmp;
if ( params.AfterFirst(_T(',')).ToLong(&tmp) )
{
m_max = (int)tmp;
// skip the error message below
return;
}
}
wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string "
"'%s' ignored"), params.c_str());
}
}
// ----------------------------------------------------------------------------
// wxGridCellFloatEditor
// ----------------------------------------------------------------------------
@ -925,13 +990,25 @@ wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count,
bool allowOthers)
: m_allowOthers(allowOthers)
{
m_choices.Alloc(count);
for ( size_t n = 0; n < count; n++ )
if ( count )
{
m_choices.Add(choices[n]);
m_choices.Alloc(count);
for ( size_t n = 0; n < count; n++ )
{
m_choices.Add(choices[n]);
}
}
}
wxGridCellEditor *wxGridCellChoiceEditor::Clone() const
{
wxGridCellChoiceEditor *editor = new wxGridCellChoiceEditor;
editor->m_allowOthers = m_allowOthers;
editor->m_choices = m_choices;
return editor;
}
void wxGridCellChoiceEditor::Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler)
@ -1007,6 +1084,23 @@ void wxGridCellChoiceEditor::Reset()
Combo()->SetInsertionPointEnd();
}
void wxGridCellChoiceEditor::SetParameters(const wxString& params)
{
if ( !params )
{
// what can we do?
return;
}
m_choices.Empty();
wxStringTokenizer tk(params, _T(','));
while ( tk.HasMoreTokens() )
{
m_choices.Add(tk.GetNextToken());
}
}
// ----------------------------------------------------------------------------
// wxGridCellEditorEvtHandler
// ----------------------------------------------------------------------------
@ -1049,6 +1143,20 @@ void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event)
}
}
// ----------------------------------------------------------------------------
// wxGridCellWorker is an (almost) empty common base class for
// wxGridCellRenderer and wxGridCellEditor managing ref counting
// ----------------------------------------------------------------------------
void wxGridCellWorker::SetParameters(const wxString& WXUNUSED(params))
{
// nothing to do
}
wxGridCellWorker::~wxGridCellWorker()
{
}
// ============================================================================
// renderer classes
// ============================================================================
@ -1079,15 +1187,6 @@ void wxGridCellRenderer::Draw(wxGrid& grid,
dc.DrawRectangle(rect);
}
void wxGridCellRenderer::SetParameters(const wxString& WXUNUSED(params))
{
// nothing to do
}
wxGridCellRenderer::~wxGridCellRenderer()
{
}
// ----------------------------------------------------------------------------
// wxGridCellStringRenderer
// ----------------------------------------------------------------------------
@ -1917,7 +2016,7 @@ void wxGridTypeRegistry::RegisterDataType(const wxString& typeName,
wxGridDataTypeInfo* info = new wxGridDataTypeInfo(typeName, renderer, editor);
// is it already registered?
int loc = FindDataType(typeName);
int loc = FindRegisteredDataType(typeName);
if ( loc != wxNOT_FOUND )
{
delete m_typeinfo[loc];
@ -1929,18 +2028,108 @@ void wxGridTypeRegistry::RegisterDataType(const wxString& typeName,
}
}
int wxGridTypeRegistry::FindDataType(const wxString& typeName)
int wxGridTypeRegistry::FindRegisteredDataType(const wxString& typeName)
{
int found = -1;
for (size_t i=0; i<m_typeinfo.Count(); i++) {
if (typeName == m_typeinfo[i]->m_typeName) {
found = i;
break;
size_t count = m_typeinfo.GetCount();
for ( size_t i = 0; i < count; i++ )
{
if ( typeName == m_typeinfo[i]->m_typeName )
{
return i;
}
}
return found;
return wxNOT_FOUND;
}
int wxGridTypeRegistry::FindDataType(const wxString& typeName)
{
int index = FindRegisteredDataType(typeName);
if ( index == wxNOT_FOUND )
{
// check whether this is one of the standard ones, in which case
// register it "on the fly"
if ( typeName == wxGRID_VALUE_STRING )
{
RegisterDataType(wxGRID_VALUE_STRING,
new wxGridCellStringRenderer,
new wxGridCellTextEditor);
}
else if ( typeName == wxGRID_VALUE_BOOL )
{
RegisterDataType(wxGRID_VALUE_BOOL,
new wxGridCellBoolRenderer,
new wxGridCellBoolEditor);
}
else if ( typeName == wxGRID_VALUE_NUMBER )
{
RegisterDataType(wxGRID_VALUE_NUMBER,
new wxGridCellNumberRenderer,
new wxGridCellNumberEditor);
}
else if ( typeName == wxGRID_VALUE_FLOAT )
{
RegisterDataType(wxGRID_VALUE_FLOAT,
new wxGridCellFloatRenderer,
new wxGridCellFloatEditor);
}
else if ( typeName == wxGRID_VALUE_CHOICE )
{
RegisterDataType(wxGRID_VALUE_CHOICE,
new wxGridCellStringRenderer,
new wxGridCellChoiceEditor);
}
else
{
return wxNOT_FOUND;
}
// we get here only if just added the entry for this type, so return
// the last index
index = m_typeinfo.GetCount() - 1;
}
return index;
}
int wxGridTypeRegistry::FindOrCloneDataType(const wxString& typeName)
{
int index = FindDataType(typeName);
if ( index == wxNOT_FOUND )
{
// the first part of the typename is the "real" type, anything after ':'
// are the parameters for the renderer
index = FindDataType(typeName.BeforeFirst(_T(':')));
if ( index == wxNOT_FOUND )
{
return wxNOT_FOUND;
}
wxGridCellRenderer *renderer = GetRenderer(index);
wxGridCellRenderer *rendererOld = renderer;
renderer = renderer->Clone();
rendererOld->DecRef();
wxGridCellEditor *editor = GetEditor(index);
wxGridCellEditor *editorOld = editor;
editor = editor->Clone();
editorOld->DecRef();
// do it even if there are no parameters to reset them to defaults
wxString params = typeName.AfterFirst(_T(':'));
renderer->SetParameters(params);
editor->SetParameters(params);
// register the new typename
renderer->IncRef();
editor->IncRef();
RegisterDataType(typeName, renderer, editor);
// we just registered it, it's the last one
index = m_typeinfo.GetCount() - 1;
}
return index;
}
wxGridCellRenderer* wxGridTypeRegistry::GetRenderer(int index)
@ -2928,21 +3117,8 @@ void wxGrid::Create()
m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT;
// data type registration: register all standard data types
// TODO: may be allow the app to selectively disable some of them?
// create the type registry
m_typeRegistry = new wxGridTypeRegistry;
RegisterDataType(wxGRID_VALUE_STRING,
new wxGridCellStringRenderer,
new wxGridCellTextEditor);
RegisterDataType(wxGRID_VALUE_BOOL,
new wxGridCellBoolRenderer,
new wxGridCellBoolEditor);
RegisterDataType(wxGRID_VALUE_NUMBER,
new wxGridCellNumberRenderer,
new wxGridCellNumberEditor);
RegisterDataType(wxGRID_VALUE_FLOAT,
new wxGridCellFloatRenderer,
new wxGridCellFloatEditor);
// subwindow components that make up the wxGrid
m_cornerLabelWin = new wxGridCornerLabelWindow( this,
@ -6933,7 +7109,7 @@ wxGridCellRenderer* wxGrid::GetDefaultRendererForCell(int row, int col) const
wxGridCellEditor*
wxGrid::GetDefaultEditorForType(const wxString& typeName) const
{
int index = m_typeRegistry->FindDataType(typeName);
int index = m_typeRegistry->FindOrCloneDataType(typeName);
if ( index == wxNOT_FOUND )
{
wxFAIL_MSG(wxT("Unknown data type name"));
@ -6947,41 +7123,15 @@ wxGrid::GetDefaultEditorForType(const wxString& typeName) const
wxGridCellRenderer*
wxGrid::GetDefaultRendererForType(const wxString& typeName) const
{
// first try to find an exact match
wxGridCellRenderer *renderer;
int index = m_typeRegistry->FindDataType(typeName);
int index = m_typeRegistry->FindOrCloneDataType(typeName);
if ( index == wxNOT_FOUND )
{
// then try to construct a renderer from the base name and parameters
// following it
wxFAIL_MSG(wxT("Unknown data type name"));
// the first part of the typename is the "real" type, anything after ':'
// are the parameters for the renderer
index = m_typeRegistry->FindDataType(typeName.BeforeFirst(_T(':')));
if ( index == wxNOT_FOUND )
{
wxFAIL_MSG(wxT("Unknown data type name"));
return NULL;
}
renderer = m_typeRegistry->GetRenderer(index);
wxGridCellRenderer *rendererOld = renderer;
renderer = renderer->Clone();
rendererOld->DecRef();
// do it even if there are no parameters to reset them to defaults
renderer->SetParameters(typeName.AfterFirst(_T(':')));
// register the new typename
m_typeRegistry->RegisterDataType(typeName, renderer, NULL);
}
else
{
renderer = m_typeRegistry->GetRenderer(index);
return NULL;
}
return renderer;
return m_typeRegistry->GetRenderer(index);
}

View File

@ -351,8 +351,8 @@ wxMenu *wxMenuBar::Remove(size_t pos)
if ( !menu )
return (wxMenu*) NULL;
GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget);
/*
GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget);
printf( "factory entries before %d\n", (int)g_slist_length(m_factory->items) );
printf( "menu shell entries before %d\n", (int)g_list_length( menu_shell->children ) );

View File

@ -351,8 +351,8 @@ wxMenu *wxMenuBar::Remove(size_t pos)
if ( !menu )
return (wxMenu*) NULL;
GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget);
/*
GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget);
printf( "factory entries before %d\n", (int)g_slist_length(m_factory->items) );
printf( "menu shell entries before %d\n", (int)g_list_length( menu_shell->children ) );

View File

@ -558,7 +558,7 @@ void wxTextCtrl::SetInsertionPoint(long pos)
SendMessage(hWnd, EM_SETSEL, 0, MAKELPARAM(pos, pos));
#endif // Win32/16
static const char *nothing = "";
static const wxChar *nothing = _T("");
SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
}