From 5888ef1e7dc9f70e074bbfe9eabed332b3db6870 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 15 Feb 2000 23:57:33 +0000 Subject: [PATCH] 1. dnd demo in treetest 2. compilation fix in drawing (for VC++) 3. refresh bug fixed in regtest, dnd/copying keys seems to work git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6065 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/dialogs/dialogs.cpp | 5 +-- samples/drawing/drawing.cpp | 5 +-- samples/regtest/regtest.cpp | 62 +++++++++++++++++++++++++++-------- samples/treectrl/treetest.cpp | 54 +++++++++++++++++++++++++++++- samples/treectrl/treetest.h | 6 ++-- 5 files changed, 111 insertions(+), 21 deletions(-) diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 5289c6a711..5f40eb07f9 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -231,12 +231,13 @@ void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) void MyFrame::LogDialog(wxCommandEvent& event) { wxLogMessage("This is some message - everything is ok so far."); - wxLogMessage("Another message..."); + wxLogMessage("Another message...\n... this one is on multiple lines"); wxLogWarning("And then something went wrong!"); // if we have this wxYield() here, everything breaks under GTK wxYield(); wxLogError("Intermediary error handler decided to abort."); - wxLogError("The top level caller detected an error."); + wxLogError("The top level caller detected an unrecoverable error."); + wxLog::FlushActive(); wxLogMessage("And this is the same dialog but with only one message."); diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index b6649b9f85..a5e06a3925 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -791,7 +791,8 @@ void MyCanvas::DrawWithLogicalOps(wxDC& dc) dc.SetPen(wxPen(m_owner->m_colourForeground, 1, wxSOLID)); dc.SetBrush(*wxTRANSPARENT_BRUSH); - for ( size_t n = 0; n < WXSIZEOF(rasterOperations); n++ ) + size_t n; + for ( n = 0; n < WXSIZEOF(rasterOperations); n++ ) { wxCoord x = 20 + 150*(n%4), y = 20 + 100*(n/4); @@ -806,7 +807,7 @@ void MyCanvas::DrawWithLogicalOps(wxDC& dc) // now some filled rectangles dc.SetBrush(wxBrush(m_owner->m_colourForeground, wxSOLID)); - for ( size_t n = 0; n < WXSIZEOF(rasterOperations); n++ ) + for ( n = 0; n < WXSIZEOF(rasterOperations); n++ ) { wxCoord x = 20 + 150*(n%4), y = 500 + 100*(n/4); diff --git a/samples/regtest/regtest.cpp b/samples/regtest/regtest.cpp index 3717bed45e..79c3655f83 100644 --- a/samples/regtest/regtest.cpp +++ b/samples/regtest/regtest.cpp @@ -84,6 +84,7 @@ public: void OnMenuTest(); // operations + void Refresh(); void DeleteSelected(); void ShowProperties(); void CreateNewKey(const wxString& strName); @@ -174,6 +175,7 @@ public: void OnExpand (wxCommandEvent& event); void OnCollapse(wxCommandEvent& event); void OnToggle (wxCommandEvent& event); + void OnRefresh (wxCommandEvent& event); void OnDelete (wxCommandEvent& event); void OnNewKey (wxCommandEvent& event); @@ -200,6 +202,7 @@ enum Menu_Expand, Menu_Collapse, Menu_Toggle, + Menu_Refresh, Menu_New, Menu_NewKey, Menu_NewText, @@ -221,6 +224,7 @@ BEGIN_EVENT_TABLE(RegFrame, wxFrame) EVT_MENU(Menu_Expand, RegFrame::OnExpand) EVT_MENU(Menu_Collapse, RegFrame::OnCollapse) EVT_MENU(Menu_Toggle, RegFrame::OnToggle) + EVT_MENU(Menu_Refresh, RegFrame::OnRefresh) EVT_MENU(Menu_Delete, RegFrame::OnDelete) EVT_MENU(Menu_NewKey, RegFrame::OnNewKey) EVT_MENU(Menu_NewText, RegFrame::OnNewText) @@ -266,6 +270,8 @@ wxMenu *CreateRegistryMenu() pMenuReg->Append(Menu_Collapse, "&Collapse", "Collapse current key"); pMenuReg->Append(Menu_Toggle, "&Toggle", "Toggle current key"); pMenuReg->AppendSeparator(); + pMenuReg->Append(Menu_Refresh, "&Refresh", "Refresh the subtree"); + pMenuReg->AppendSeparator(); pMenuReg->Append(Menu_Info, "&Properties","Information about current selection"); return pMenuReg; @@ -322,11 +328,7 @@ RegFrame::RegFrame(wxFrame *parent, char *title, int x, int y, int w, int h) // create the status line // ---------------------- - int aWidths[2]; - aWidths[0] = 200; - aWidths[1] = -1; CreateStatusBar(2); - SetStatusWidths(2, aWidths); } RegFrame::~RegFrame() @@ -370,6 +372,11 @@ void RegFrame::OnToggle(wxCommandEvent& event) m_treeCtrl->ExpandItem(m_treeCtrl->GetSelection(), wxTREE_EXPAND_TOGGLE); } +void RegFrame::OnRefresh(wxCommandEvent& event) +{ + m_treeCtrl->Refresh(); +} + void RegFrame::OnDelete(wxCommandEvent& event) { m_treeCtrl->DeleteSelected(); @@ -517,13 +524,11 @@ void RegTreeCtrl::OnRightClick(wxMouseEvent& event) { int iFlags; long lId = HitTest(wxPoint(event.GetX(), event.GetY()), iFlags); - if ( !(iFlags & wxTREE_HITTEST_ONITEMLABEL) ) { - // take the currently selected item if click not on item - lId = GetSelection(); - } - else { + if ( iFlags & wxTREE_HITTEST_ONITEMLABEL ) { + // select the item first SelectItem(lId); } + //else: take the currently selected item if click not on item PopupMenu(m_pMenuPopup, event.GetX(), event.GetY()); } @@ -664,7 +669,7 @@ void RegTreeCtrl::OnEndDrag(wxTreeEvent& event) bool isKey = src->IsKey(); if ( (isKey && (src == dst)) || - (!isKey && (src->Parent() == dst)) ) { + (!isKey && (dst->Parent() == src)) ) { wxLogStatus("Can't copy something on itself"); return; @@ -697,7 +702,14 @@ void RegTreeCtrl::OnEndDrag(wxTreeEvent& event) bool ok; if ( isKey ) { wxRegKey& key = src->Key(); - ok = key.Copy(dst->Key()); + wxRegKey keyDst(dst->Key(), src->m_strName); + ok = keyDst.Create(FALSE); + if ( !ok ) { + wxLogError("Key '%s' already exists"); + } + else { + ok = key.Copy(keyDst); + } if ( ok && dstExpanded ) { dst->OnCollapse(); dst->OnExpand(); @@ -715,7 +727,7 @@ void RegTreeCtrl::OnEndDrag(wxTreeEvent& event) wxRegKey& key = src->Parent()->Key(); ok = key.CopyValue(src->m_strName, dst->Key()); if ( ok && !m_copyOnDrop ) { - // we move it, so delete the old one + // we moved it, so delete the old one ok = key.DeleteValue(src->m_strName); if ( ok ) { // reexpand the key @@ -848,11 +860,19 @@ void RegTreeCtrl::TreeNode::OnCollapse() void RegTreeCtrl::TreeNode::Refresh() { - if ( m_pTree->IsExpanded(Id()) ) - { + if ( !IsKey() ) + return; + + if ( m_pTree->IsExpanded(Id()) ) { m_pTree->Collapse(Id()); + OnCollapse(); m_pTree->SetItemHasChildren(Id()); m_pTree->Expand(Id()); + OnExpand(); + } + else { + // just allow it to be expanded + m_pTree->SetItemHasChildren(Id()); } } @@ -1065,3 +1085,17 @@ bool RegTreeCtrl::IsKeySelected() const return pCurrent->IsKey(); } + +void RegTreeCtrl::Refresh() +{ + long lId = GetSelection(); + if ( !lId ) + return; + + TreeNode *pNode = (TreeNode *)GetItemData(lId); + + wxCHECK_RET( pNode != NULL, "tree item without data?" ); + + pNode->Refresh(); +} + diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 2bd8bfa646..135b59b7ed 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -96,6 +96,7 @@ END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl) EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl, MyTreeCtrl::OnBeginDrag) EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl, MyTreeCtrl::OnBeginRDrag) + EVT_TREE_END_DRAG(TreeTest_Ctrl, MyTreeCtrl::OnEndDrag) EVT_TREE_BEGIN_LABEL_EDIT(TreeTest_Ctrl, MyTreeCtrl::OnBeginLabelEdit) EVT_TREE_END_LABEL_EDIT(TreeTest_Ctrl, MyTreeCtrl::OnEndLabelEdit) EVT_TREE_DELETE_ITEM(TreeTest_Ctrl, MyTreeCtrl::OnDeleteItem) @@ -626,7 +627,6 @@ void MyTreeCtrl::name(wxTreeEvent& WXUNUSED(event)) \ wxLogMessage(#name); \ } -TREE_EVENT_HANDLER(OnBeginDrag) TREE_EVENT_HANDLER(OnBeginRDrag) TREE_EVENT_HANDLER(OnDeleteItem) TREE_EVENT_HANDLER(OnGetInfo) @@ -639,6 +639,58 @@ TREE_EVENT_HANDLER(OnSelChanging) #undef TREE_EVENT_HANDLER +void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event) +{ + // need to explicitly allow drag + if ( event.GetItem() != GetRootItem() ) + { + m_draggedItem = event.GetItem(); + + wxLogMessage("OnBeginDrag: started dragging %s", + GetItemText(m_draggedItem).c_str()); + + event.Allow(); + } + else + { + wxLogMessage("OnBeginDrag: this item can't be dragged."); + } +} + +void MyTreeCtrl::OnEndDrag(wxTreeEvent& event) +{ + wxTreeItemId itemSrc = m_draggedItem, + itemDst = event.GetItem(); + m_draggedItem = 0; + + // where to copy the item? + if ( itemDst.IsOk() && !ItemHasChildren(itemDst) ) + { + // copy to the parent then + itemDst = GetParent(itemDst); + } + + if ( !itemDst.IsOk() ) + { + wxLogMessage("OnEndDrag: can't drop here."); + + return; + } + + wxString text = GetItemText(itemSrc); + wxLogMessage("OnEndDrag: '%s' copied to '%s'.", + text.c_str(), GetItemText(itemDst).c_str()); + + // just do append here - we could also insert it just before/after the item + // on which it was dropped, but this requires slightly more work... we also + // completely ignore the client data and icon of the old item but could + // copy them as well. + // + // Finally, we only copy one item here but we might copy the entire tree if + // we were dragging a folder. + AppendItem(itemDst, text); +} + void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event) { wxLogMessage("OnBeginLabelEdit"); diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 0c0cd57395..7ae426cbf4 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -48,6 +48,7 @@ public: void OnBeginDrag(wxTreeEvent& event); void OnBeginRDrag(wxTreeEvent& event); + void OnEndDrag(wxTreeEvent& event); void OnBeginLabelEdit(wxTreeEvent& event); void OnEndLabelEdit(wxTreeEvent& event); void OnDeleteItem(wxTreeEvent& event); @@ -90,8 +91,9 @@ private: size_t folder); wxImageList *m_imageListNormal; - bool m_reverseSort; // flag for OnCompareItems - wxTreeItemId m_lastItem; // for OnEnsureVisible() + bool m_reverseSort; // flag for OnCompareItems + wxTreeItemId m_lastItem, // for OnEnsureVisible() + m_draggedItem; // item being dragged right now // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS() // if you want your overloaded OnCompareItems() to be called.