From 435fe83e747aba481a255bab37768038cf9a9e81 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 16 Dec 1998 08:06:02 +0000 Subject: [PATCH] Added layout constraints call to wxNotebook Renamed key_down events to match MSW equivalents Invened activated events to tree and list ctrl Added patches to text ctrl from georg git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1207 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/event.h | 2 ++ include/wx/generic/listctrl.h | 1 + include/wx/generic/treectrl.h | 3 +++ include/wx/msw/listctrl.h | 1 + include/wx/msw/treectrl.h | 3 +++ samples/listctrl/listtest.cpp | 14 ++++++++++++++ samples/listctrl/listtest.h | 1 + samples/treectrl/treetest.cpp | 8 +++++++- samples/treectrl/treetest.h | 1 + src/generic/listctrl.cpp | 9 +++++++-- src/generic/treectrl.cpp | 9 +++++++-- src/gtk/notebook.cpp | 2 ++ src/gtk/textctrl.cpp | 5 +++-- src/gtk1/notebook.cpp | 2 ++ src/gtk1/textctrl.cpp | 5 +++-- 15 files changed, 57 insertions(+), 9 deletions(-) diff --git a/include/wx/event.h b/include/wx/event.h index 576e271156..aa5431881c 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -164,6 +164,7 @@ const wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING = wxEVT_FIRST + 610; const wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED = wxEVT_FIRST + 611; const wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING = wxEVT_FIRST + 612; const wxEventType wxEVT_COMMAND_TREE_KEY_DOWN = wxEVT_FIRST + 613; +const wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED = wxEVT_FIRST + 614; /* List control event types */ const wxEventType wxEVT_COMMAND_LIST_BEGIN_DRAG = wxEVT_FIRST + 700; @@ -181,6 +182,7 @@ const wxEventType wxEVT_COMMAND_LIST_INSERT_ITEM = wxEVT_FIRST + 711; const wxEventType wxEVT_COMMAND_LIST_COL_CLICK = wxEVT_FIRST + 712; const wxEventType wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK = wxEVT_FIRST + 713; const wxEventType wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK = wxEVT_FIRST + 714; +const wxEventType wxEVT_COMMAND_LIST_ITEM_ACTIVATED = wxEVT_FIRST + 715; /* Tab and notebook control event types */ const wxEventType wxEVT_COMMAND_TAB_SEL_CHANGED = wxEVT_FIRST + 800; diff --git a/include/wx/generic/listctrl.h b/include/wx/generic/listctrl.h index afe4e8a7ce..b0fd434549 100644 --- a/include/wx/generic/listctrl.h +++ b/include/wx/generic/listctrl.h @@ -224,6 +224,7 @@ typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&); #define EVT_LIST_COL_CLICK(id, fn) { wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL }, #define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) { wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL }, #define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) { wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL }, +#define EVT_LIST_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL }, //----------------------------------------------------------------------------- // wxListItemData (internal) diff --git a/include/wx/generic/treectrl.h b/include/wx/generic/treectrl.h index 49e3e4fb3f..818bf59a2a 100644 --- a/include/wx/generic/treectrl.h +++ b/include/wx/generic/treectrl.h @@ -168,6 +168,9 @@ typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); // be deleted just after the return of this event handler (if any) #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, +// GetItem() returns the item that was activated (double click, enter, space) +#define EVT_TREE_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, + // ----------------------------------------------------------------------------- // wxTreeCtrl - the tree control // ----------------------------------------------------------------------------- diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index ff52f6a80a..863f46b01c 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -474,6 +474,7 @@ typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&); #define EVT_LIST_KEY_DOWN(id, fn) { wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL }, #define EVT_LIST_INSERT_ITEM(id, fn) { wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL }, #define EVT_LIST_COL_CLICK(id, fn) { wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL }, +#define EVT_LIST_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL }, #endif // _WX_LISTCTRL_H_ diff --git a/include/wx/msw/treectrl.h b/include/wx/msw/treectrl.h index 4f5cb941d1..d50417d5af 100644 --- a/include/wx/msw/treectrl.h +++ b/include/wx/msw/treectrl.h @@ -535,5 +535,8 @@ typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); // be deleted just after the return of this event handler (if any) #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, +// GetItem() returns the item that was activated (double click, enter, space) +#define EVT_TREE_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, + #endif // _WX_TREECTRL_H_ diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index d745798ddf..8f17b941d9 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -56,6 +56,7 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected) EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) + EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -449,6 +450,18 @@ void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event)) text->WriteText("OnDeselected\n"); } +void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(event)) +{ + if ( !wxGetApp().GetTopWindow() ) + return; + + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; + + text->WriteText("OnActivated\n"); +} + void MyListCtrl::OnListKeyDown(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) @@ -461,3 +474,4 @@ void MyListCtrl::OnListKeyDown(wxListEvent& WXUNUSED(event)) text->WriteText("OnListKeyDown\n"); } + diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index bc089abbac..c9bbb749bd 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -37,6 +37,7 @@ public: void OnSelected(wxListEvent& event); void OnDeselected(wxListEvent& event); void OnListKeyDown(wxListEvent& event); + void OnActivated(wxListEvent& event); DECLARE_EVENT_TABLE() }; diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 17d2ac3490..4095a541e6 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -65,6 +65,7 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl) EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged) EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging) EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown) + EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, MyTreeCtrl::OnItemActivated) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -318,6 +319,11 @@ void MyTreeCtrl::OnItemCollapsing(wxTreeEvent& event) } void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent&WXUNUSED(event)) +{ + wxLogMessage("OnTreeKeyDown"); +} + +void MyTreeCtrl::OnItemActivated(wxTreeEvent&WXUNUSED(event)) { // show some info about this item wxTreeItemId itemId = GetSelection(); @@ -328,7 +334,7 @@ void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent&WXUNUSED(event)) item->ShowInfo(this); } - wxLogMessage("OnTreeKeyDown"); + wxLogMessage("OnItemActivated"); } static inline const char *Bool2String(bool b) diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 9adacc8acf..8ca521827d 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -55,6 +55,7 @@ public: void OnSelChanged(wxTreeEvent& event); void OnSelChanging(wxTreeEvent& event); void OnTreeKeyDown(wxTreeEvent& event); + void OnItemActivated(wxTreeEvent& event); void GetItemsRecursively(const wxTreeItemId& idParent, long cookie); diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 6db8a65314..3d4dd01729 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -1216,7 +1216,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) m_lastOnSame = FALSE; m_renameTimer->Stop(); - SendNotify( line, wxEVT_COMMAND_LIST_KEY_DOWN ); + SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); return; } @@ -1369,6 +1369,11 @@ void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown ) void wxListMainWindow::OnChar( wxKeyEvent &event ) { + wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, m_parent->GetId() ); + le.m_code = event.KeyCode(); + le.SetEventObject( m_parent ); + m_parent->GetEventHandler()->ProcessEvent( le ); + /* if (event.KeyCode() == WXK_TAB) { @@ -1482,7 +1487,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) case WXK_RETURN: case WXK_EXECUTE: { - wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); + wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() ); le.SetEventObject( GetParent() ); le.m_itemIndex = GetIndexOfLine( m_current ); m_current->GetItem( 0, le.m_item ); diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index 480eb4c13f..04d3717ec3 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -1112,6 +1112,11 @@ void wxTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) void wxTreeCtrl::OnChar( wxKeyEvent &event ) { + wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() ); + te.m_code = event.KeyCode(); + te.SetEventObject( this ); + GetEventHandler()->ProcessEvent( te ); + if (m_current == 0) { event.Skip(); @@ -1144,7 +1149,7 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event ) case ' ': case WXK_RETURN: { - wxTreeEvent event( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() ); + wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() ); event.m_item = m_current; event.m_code = 0; event.SetEventObject( this ); @@ -1236,7 +1241,7 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event ) if ( event.LeftDClick() ) { - wxTreeEvent event( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() ); + wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() ); event.m_item = item; event.m_code = 0; event.SetEventObject( this ); diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 0ae08846d6..ca9146b045 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -99,6 +99,8 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* } win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); + + if (win->GetAutoLayout()) win->Layout(); } //----------------------------------------------------------------------------- diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index bb72ccea1b..549f3488f3 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -303,7 +303,8 @@ bool wxTextCtrl::LoadFile( const wxString &file ) if (m_windowStyle & wxTE_MULTILINE) { - gtk_editable_insert_text( GTK_EDITABLE(m_text), text, 0, &len ); + gint pos = 0; + gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos ); } else { @@ -555,7 +556,7 @@ void wxTextCtrl::Replace( long from, long to, const wxString &value ) gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); if (value.IsNull()) return; - gint pos = (gint)to; + gint pos = (gint)from; gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); } diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 0ae08846d6..ca9146b045 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -99,6 +99,8 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* } win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); + + if (win->GetAutoLayout()) win->Layout(); } //----------------------------------------------------------------------------- diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index bb72ccea1b..549f3488f3 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -303,7 +303,8 @@ bool wxTextCtrl::LoadFile( const wxString &file ) if (m_windowStyle & wxTE_MULTILINE) { - gtk_editable_insert_text( GTK_EDITABLE(m_text), text, 0, &len ); + gint pos = 0; + gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos ); } else { @@ -555,7 +556,7 @@ void wxTextCtrl::Replace( long from, long to, const wxString &value ) gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); if (value.IsNull()) return; - gint pos = (gint)to; + gint pos = (gint)from; gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); } -- 2.45.2