Added event skeletons, defines, event ids..
Implemented wxEVT_DATAVIEW_ROW_SELECTED. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41586 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -327,6 +327,73 @@ protected:
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataViewEvent - the event class for the wxDataViewCtrl notifications
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxDataViewEvent : public wxNotifyEvent
|
||||
{
|
||||
public:
|
||||
wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
|
||||
: wxNotifyEvent(commandType, winid),
|
||||
m_col(-1),
|
||||
m_row(-1),
|
||||
m_model(NULL),
|
||||
m_value(wxNullVariant),
|
||||
m_editCancelled(false)
|
||||
{ }
|
||||
|
||||
wxDataViewEvent(const wxDataViewEvent& event)
|
||||
: wxNotifyEvent(event),
|
||||
m_col(event.m_col),
|
||||
m_row(event.m_col),
|
||||
m_model(event.m_model),
|
||||
m_value(event.m_value),
|
||||
m_editCancelled(event.m_editCancelled)
|
||||
{ }
|
||||
|
||||
int GetColumn() const { return m_col; }
|
||||
void SetColumn( int col ) { m_col = col; }
|
||||
int GetRow() const { return m_row; }
|
||||
void SetRow( int row ) { m_row = row; }
|
||||
wxDataViewModel* GetModel() const { return m_model; }
|
||||
void SetModel( wxDataViewModel *model ) { m_model = model; }
|
||||
const wxVariant &GetValue() const { return m_value; }
|
||||
void SetValue( const wxVariant &value ) { m_value = value; }
|
||||
|
||||
// was label editing canceled? (for wxEVT_COMMAND_DATVIEW_END_LABEL_EDIT only)
|
||||
bool IsEditCancelled() const { return m_editCancelled; }
|
||||
void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; }
|
||||
|
||||
virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
|
||||
|
||||
protected:
|
||||
int m_col;
|
||||
int m_row;
|
||||
wxDataViewModel *m_model;
|
||||
wxVariant m_value;
|
||||
bool m_editCancelled;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
|
||||
};
|
||||
|
||||
BEGIN_DECLARE_EVENT_TYPES()
|
||||
DECLARE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED, -1)
|
||||
END_DECLARE_EVENT_TYPES()
|
||||
|
||||
typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
|
||||
|
||||
#define wxDataViewEventHandler(func) \
|
||||
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
|
||||
|
||||
#define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
|
||||
wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
|
||||
|
||||
#define EVT_DATAVIEW_ROW_SELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ROW_SELECTED, id, fn)
|
||||
|
||||
|
||||
#if defined(wxUSE_GENERICDATAVIEWCTRL)
|
||||
#include "wx/generic/dataview.h"
|
||||
#elif defined(__WXGTK20__)
|
||||
|
@@ -299,13 +299,17 @@ enum my_events
|
||||
ID_PREPEND_ROW_RIGHT,
|
||||
ID_INSERT_ROW_RIGHT,
|
||||
ID_DELETE_ROW_RIGHT,
|
||||
ID_EDIT_ROW_RIGHT
|
||||
ID_EDIT_ROW_RIGHT,
|
||||
|
||||
ID_SORTED,
|
||||
ID_UNSORTED
|
||||
};
|
||||
|
||||
class MySortingFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
|
||||
~MySortingFrame();
|
||||
|
||||
public:
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
@@ -323,10 +327,16 @@ public:
|
||||
void OnDeleteRowRight(wxCommandEvent& event);
|
||||
void OnEditRowRight(wxCommandEvent& event);
|
||||
|
||||
void OnSelectedUnsorted(wxDataViewEvent &event);
|
||||
void OnSelectedSorted(wxDataViewEvent &event);
|
||||
|
||||
private:
|
||||
wxDataViewCtrl* dataview_left;
|
||||
wxDataViewCtrl* dataview_right;
|
||||
|
||||
wxLog *m_logOld;
|
||||
wxTextCtrl *m_logWindow;
|
||||
|
||||
MyUnsortedTextModel *m_unsorted_model;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
@@ -346,7 +356,7 @@ bool MyApp::OnInit(void)
|
||||
MyFrame *frame = new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 10, 10, 800, 340);
|
||||
frame->Show(true);
|
||||
|
||||
MySortingFrame *frame2 = new MySortingFrame(NULL, wxT("wxDataViewCtrl sorting test"), 10, 350, 600, 300);
|
||||
MySortingFrame *frame2 = new MySortingFrame(NULL, wxT("wxDataViewCtrl sorting test"), 10, 150, 600, 500);
|
||||
frame2->Show(true);
|
||||
|
||||
SetTopWindow(frame);
|
||||
@@ -451,11 +461,15 @@ BEGIN_EVENT_TABLE(MySortingFrame,wxFrame)
|
||||
EVT_BUTTON( ID_PREPEND_ROW_LEFT, MySortingFrame::OnPrependRowLeft )
|
||||
EVT_BUTTON( ID_INSERT_ROW_LEFT, MySortingFrame::OnInsertRowLeft )
|
||||
EVT_BUTTON( ID_DELETE_ROW_LEFT, MySortingFrame::OnDeleteRowLeft )
|
||||
EVT_DATAVIEW_ROW_SELECTED( ID_SORTED, MySortingFrame::OnSelectedSorted )
|
||||
EVT_DATAVIEW_ROW_SELECTED( ID_UNSORTED, MySortingFrame::OnSelectedUnsorted )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
|
||||
wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
|
||||
{
|
||||
m_logOld = NULL;
|
||||
|
||||
SetIcon(wxICON(sample));
|
||||
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
@@ -476,7 +490,7 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int
|
||||
|
||||
|
||||
// Left wxDataViewCtrl
|
||||
dataview_left = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE );
|
||||
dataview_left = new wxDataViewCtrl( this, ID_UNSORTED, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE );
|
||||
|
||||
m_unsorted_model = new MyUnsortedTextModel;
|
||||
dataview_left->AssociateModel( m_unsorted_model );
|
||||
@@ -488,7 +502,7 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int
|
||||
dataview_left->AppendColumn( new wxDataViewColumn( wxT("icon"), new wxDataViewBitmapCell, 3, 25 ) );
|
||||
|
||||
// Right wxDataViewCtrl using the sorting model
|
||||
dataview_right = new wxDataViewCtrl( this, wxID_ANY );
|
||||
dataview_right = new wxDataViewCtrl( this, ID_SORTED );
|
||||
|
||||
wxDataViewSortedListModel *sorted_model =
|
||||
new wxDataViewSortedListModel( m_unsorted_model );
|
||||
@@ -529,9 +543,32 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int
|
||||
main_sizer->Add( top_sizer, 1, wxGROW );
|
||||
main_sizer->Add( button_sizer, 0, wxGROW );
|
||||
|
||||
m_logWindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxTE_MULTILINE | wxSUNKEN_BORDER);
|
||||
main_sizer->Add( 20,20 );
|
||||
main_sizer->Add( m_logWindow, 1, wxGROW );
|
||||
|
||||
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow));
|
||||
|
||||
SetSizer( main_sizer );
|
||||
}
|
||||
|
||||
MySortingFrame::~MySortingFrame()
|
||||
{
|
||||
delete wxLog::SetActiveTarget(m_logOld);
|
||||
}
|
||||
|
||||
void MySortingFrame::OnSelectedUnsorted(wxDataViewEvent &event)
|
||||
{
|
||||
wxLogMessage( wxT("OnSelected from unsorted list, selected %d"), (int) event.GetRow() );
|
||||
}
|
||||
|
||||
void MySortingFrame::OnSelectedSorted(wxDataViewEvent &event)
|
||||
{
|
||||
wxLogMessage( wxT("OnSelected from sorted list, selected %d"), (int) event.GetRow() );
|
||||
}
|
||||
|
||||
void MySortingFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
Close(true);
|
||||
|
@@ -804,4 +804,13 @@ wxDataViewColumn* wxDataViewCtrlBase::GetColumn( unsigned int pos )
|
||||
return (wxDataViewColumn*) m_cols[ pos ];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// wxDataViewEvent
|
||||
// ---------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED)
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -1477,6 +1477,41 @@ int wxDataViewColumn::GetFixedWidth()
|
||||
return gtk_tree_view_column_get_fixed_width( (GtkTreeViewColumn *)m_column );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewCtrl signal callbacks
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCtrl *dv )
|
||||
{
|
||||
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED, dv->GetId() );
|
||||
if (dv->HasFlag(wxDV_MULTIPLE))
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
|
||||
|
||||
// do something
|
||||
// ...
|
||||
|
||||
// delete list
|
||||
g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
|
||||
g_list_free( list );
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter );
|
||||
if (has_selection)
|
||||
{
|
||||
unsigned int row = (wxUIntPtr) iter.user_data;
|
||||
event.SetRow( row );
|
||||
}
|
||||
}
|
||||
event.SetModel( dv->GetModel() );
|
||||
dv->GetEventHandler()->ProcessEvent( event );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewCtrl
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -1529,6 +1564,10 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||
|
||||
m_parent->DoAddChild( this );
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
g_signal_connect_after (selection, "changed",
|
||||
G_CALLBACK (wxdataview_selection_changed_callback), this);
|
||||
|
||||
PostCreation(size);
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user