From f4e325b3df3d4c0b3ca21d4d1781acab6a488e4c Mon Sep 17 00:00:00 2001 From: Denis Pershin Date: Mon, 10 Aug 1998 17:53:44 +0000 Subject: [PATCH] DP: native wxTreeCtrl for GTK. It *should* be buggy... Cause I do not know GTK... But it works... I do not know why... Robert, please look at it... I am not sure that it is ok... git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@495 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/bitmap.h | 3 + include/wx/gtk/treectrl.h | 331 ++++++++++++++++++ include/wx/gtk1/bitmap.h | 3 + include/wx/gtk1/treectrl.h | 331 ++++++++++++++++++ include/wx/treectrl.h | 4 +- src/generic/treectrl.cpp | 1 + src/gtk.inc | 4 +- src/gtk/treectrl.cpp | 696 +++++++++++++++++++++++++++++++++++++ src/gtk1/treectrl.cpp | 696 +++++++++++++++++++++++++++++++++++++ 9 files changed, 2064 insertions(+), 5 deletions(-) create mode 100644 include/wx/gtk/treectrl.h create mode 100644 include/wx/gtk1/treectrl.h create mode 100644 src/gtk/treectrl.cpp create mode 100644 src/gtk1/treectrl.cpp diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index f0eb372f92..fe5f8eddec 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -32,6 +32,7 @@ class wxToolBar; class wxBitmapButton; class wxStaticBitmap; class wxFrame; +class wxTreeCtrl; class wxMask; class wxBitmap; @@ -61,6 +62,7 @@ class wxMask: public wxObject friend wxBitmapButton; friend wxStaticBitmap; friend wxFrame; + friend wxTreeCtrl; GdkBitmap *GetBitmap() const; @@ -122,6 +124,7 @@ class wxBitmap: public wxObject friend wxBitmapButton; friend wxStaticBitmap; friend wxFrame; + friend wxTreeCtrl; GdkPixmap *GetPixmap() const; GdkBitmap *GetBitmap() const; diff --git a/include/wx/gtk/treectrl.h b/include/wx/gtk/treectrl.h new file mode 100644 index 0000000000..d6949a6482 --- /dev/null +++ b/include/wx/gtk/treectrl.h @@ -0,0 +1,331 @@ +/* + * Author: Robert Roebling + * + * Copyright: (C) 1997,1998 Robert Roebling + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the wxWindows Licence, which + * you have received with this library (see Licence.htm). + * + */ + +#ifndef __GTKTREECTRL_H__ +#define __GTKTREECTRL_H__ + +#ifdef __GNUG__ +#pragma interface "treectrl.h" +#endif + +#include "wx/defs.h" +#include "wx/string.h" +#include "wx/list.h" +#include "wx/control.h" +#include "wx/event.h" +#include "wx/imaglist.h" +#include "wx/scrolwin.h" +#include "wx/dcclient.h" + +#include + +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- + +class wxTreeItem; +class wxTreeCtrl; +class wxTreeEvent; + +class wxImageList; + +//----------------------------------------------------------------------------- +// constants +//----------------------------------------------------------------------------- + +// WXDLLEXPORT extern const char *wxTreeNameStr; + +#define wxTREE_MASK_HANDLE 0x0001 +#define wxTREE_MASK_STATE 0x0002 +#define wxTREE_MASK_TEXT 0x0004 +#define wxTREE_MASK_IMAGE 0x0008 +#define wxTREE_MASK_SELECTED_IMAGE 0x0010 +#define wxTREE_MASK_CHILDREN 0x0020 +#define wxTREE_MASK_DATA 0x0040 + +#define wxTREE_STATE_BOLD 0x0001 +#define wxTREE_STATE_DROPHILITED 0x0002 +#define wxTREE_STATE_EXPANDED 0x0004 +#define wxTREE_STATE_EXPANDEDONCE 0x0008 +#define wxTREE_STATE_FOCUSED 0x0010 +#define wxTREE_STATE_SELECTED 0x0020 +#define wxTREE_STATE_CUT 0x0040 + +#define wxTREE_HITTEST_ABOVE 0x0001 // Above the client area. +#define wxTREE_HITTEST_BELOW 0x0002 // Below the client area. +#define wxTREE_HITTEST_NOWHERE 0x0004 // In the client area but below the last item. +#define wxTREE_HITTEST_ONITEMBUTTON 0x0010 // On the button associated with an item. +#define wxTREE_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item. +#define wxTREE_HITTEST_ONITEMINDENT 0x0040 // In the indentation associated with an item. +#define wxTREE_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item. +#define wxTREE_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item. +#define wxTREE_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state. +#define wxTREE_HITTEST_TOLEFT 0x0400 // To the right of the client area. +#define wxTREE_HITTEST_TORIGHT 0x0800 // To the left of the client area. + +#define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON) + +// Flags for GetNextItem +enum { + wxTREE_NEXT_CARET, // Retrieves the currently selected item. + wxTREE_NEXT_CHILD, // Retrieves the first child item. The hItem parameter must be NULL. + wxTREE_NEXT_DROPHILITE, // Retrieves the item that is the target of a drag-and-drop operation. + wxTREE_NEXT_FIRSTVISIBLE, // Retrieves the first visible item. + wxTREE_NEXT_NEXT, // Retrieves the next sibling item. + wxTREE_NEXT_NEXTVISIBLE, // Retrieves the next visible item that follows the specified item. + wxTREE_NEXT_PARENT, // Retrieves the parent of the specified item. + wxTREE_NEXT_PREVIOUS, // Retrieves the previous sibling item. + wxTREE_NEXT_PREVIOUSVISIBLE, // Retrieves the first visible item that precedes the specified item. + wxTREE_NEXT_ROOT // Retrieves the first child item of the root item of which the specified item is a part. +}; + +// Flags for ExpandItem +enum { + wxTREE_EXPAND_EXPAND, + wxTREE_EXPAND_COLLAPSE, + wxTREE_EXPAND_COLLAPSE_RESET, + wxTREE_EXPAND_TOGGLE +}; + +// Flags for InsertItem +enum { + wxTREE_INSERT_LAST = -1, + wxTREE_INSERT_FIRST = -2, + wxTREE_INSERT_SORT = -3 +}; + +//----------------------------------------------------------------------------- +// wxTreeItem +//----------------------------------------------------------------------------- + + +class WXDLLEXPORT wxTreeItem: public wxObject +{ +public: + wxTreeCtrl *m_owner; + GtkWidget *m_parentwidget; + GtkTreeItem *m_widget; + GtkTree *m_tree; + long m_mask; + long m_itemId; + long m_state; + long m_stateMask; + wxString m_text; + int m_image; + int m_selectedImage; + int m_children; + wxList m_childlist; + long m_data; + + wxTreeItem(); + wxTreeItem(GtkWidget *parent, const wxTreeItem &item); + ~wxTreeItem(); + + void Create(); + + void AddChild(wxTreeItem *child); + void DeleteChildren(); + bool HasChildren(); + wxTreeItem *FindItem(long itemId) const; + wxTreeItem *FindItem(GtkTreeItem *item) const; + + // Accessors + inline long GetMask() const { return m_mask; } + inline long GetItemId() const { return m_itemId; } + inline long GetState() const { return m_state; } + inline long GetStateMask() const { return m_stateMask; } + inline wxString GetText() const { return m_text; } + inline int GetImage() const { return m_image; } + inline int GetSelectedImage() const { return m_selectedImage; } + inline const wxList &GetChildren() const { return m_childlist; } + inline long GetData() const { return m_data; } + + inline void SetMask(long mask) { m_mask = mask; } + inline void SetItemId(long id) { m_itemId = m_itemId = id; } + inline void GetState(long state) { m_state = state; } + inline void SetStateMask(long stateMask) { m_stateMask = stateMask; } + inline void GetText(const wxString& text) { m_text = text; } + inline void SetImage(int image) { m_image = image; } + inline void SetSelectedImage(int selImage) { m_selectedImage = selImage; } + inline void SetChildren(const wxList &children) { m_childlist = children; } + inline void SetData(long data) { m_data = data; } + + int NumberOfVisibleDescendents(); +private: + friend wxTreeCtrl; + friend void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItem *treeitem); + friend void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItem *treeitem); + friend void gtk_treeitem_select_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem); + friend void gtk_treeitem_deselect_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem); + + void AddSubtree(); + void PrepareEvent(wxTreeEvent &event); + void SendDelete(wxWindow *target); + void SendExpand(wxWindow *target); + void SendExpanding(wxWindow *target); + void SendCollapse(wxWindow *target); + void SendCollapsing(wxWindow *target); + void SendSelChanged(wxWindow *target); + void SendSelChanging(wxWindow *target); + + inline wxTreeItem *GetChild(long no) { + return (wxTreeItem *)(m_childlist.Nth(no)->Data()); + } + inline long GetChildrenNumber() { + return m_childlist.Number(); + } + + guint expand_handler; + guint collapse_handler; + + DECLARE_DYNAMIC_CLASS(wxTreeItem) +}; + +//----------------------------------------------------------------------------- +// wxTreeCtrl +//----------------------------------------------------------------------------- + +class wxTreeCtrl: public wxScrolledWindow { +public: + GtkTree *m_tree; + + wxTreeCtrl(); + wxTreeCtrl(wxWindow *parent, const wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTR_HAS_BUTTONS, + const wxString& name = "wxTreeCtrl" ); + ~wxTreeCtrl(); + bool Create(wxWindow *parent, const wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTR_HAS_BUTTONS, + const wxString& name = "wxTreeCtrl"); + + int GetCount() const; + + long InsertItem( long parent, const wxString& label, long data = 0, + int image = -1, int selImage = -1, + long insertAfter = wxTREE_INSERT_LAST ); + + long InsertItem( long parent, wxTreeItem &info, + long insertAfter = wxTREE_INSERT_LAST ); + void DeleteItem( long item ); + void DeleteChildren( long item ); + bool DeleteAllItems(); + + bool ExpandItem(long item) { return ExpandItem(item, wxTREE_EXPAND_EXPAND); } + bool ExpandItem( long item, int action ); + + bool CollapseItem(long item) { return ExpandItem(item, wxTREE_EXPAND_COLLAPSE); } + bool ToggleItem(long item) { return ExpandItem(item, wxTREE_EXPAND_TOGGLE); } + + // is the item expanded now? + bool IsItemExpanded(long item) + { + wxTreeItem *pItem = FindItem(item); + return pItem && (pItem->GetState() & wxTREE_STATE_EXPANDED); + } + +/* + bool GetItem( wxTreeItem &info ) const; +*/ + + long GetItemData( long item ) const; + wxString GetItemText( long item ) const; + int GetItemImage(long item) const; + long GetParent( long item ) const; + long GetRootItem() const; +/* + long GetSelection() const; + bool SelectItem( long item ); +*/ + + bool ItemHasChildren( long item ) const; + void SetIndent( int indent ); + int GetIndent() const; + +/* + bool SetItem( wxTreeItem &info ); + bool SetItemData( long item, long data ); + bool SetItemText( long item, const wxString &text ); + void SetItemImage(long item, int image, int imageSel) const; + long HitTest( const wxPoint& point, int &flags ); +*/ + + wxTreeItem *FindItem(GtkTreeItem *item) const; + + wxImageList *GetImageList(int which = wxIMAGE_LIST_NORMAL) const; + void SetImageList(wxImageList *imageList, int which = wxIMAGE_LIST_NORMAL); + +private: + // set the selection to the specified item generating appropriate event(s) if + // not disabled + void SelectItem(wxTreeItem *item, bool bDoEvents = TRUE); + + wxTreeItem *m_anchor; + wxTreeItem *m_current; + int m_indent; + long m_lastId; + bool m_isCreated; + wxImageList *m_imageList; + wxImageList *m_smallImageList; + + void CalculateLevel( wxTreeItem *item, wxPaintDC &dc, int level, int &y ); + void CalculatePositions(); + wxTreeItem *FindItem( long itemId ) const; + +// DECLARE_EVENT_TABLE() + DECLARE_DYNAMIC_CLASS(wxTreeCtrl) +}; + +//----------------------------------------------------------------------------- +// wxTreeEvent +//----------------------------------------------------------------------------- + +class WXDLLEXPORT wxTreeEvent: public wxCommandEvent +{ + DECLARE_DYNAMIC_CLASS(wxTreeEvent) + + public: + wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); + + int m_code; + wxTreeItem m_item; + long m_oldItem; + wxPoint m_pointDrag; + + inline long GetOldItem() const { return m_oldItem; } + inline wxTreeItem& GetItem() const { return (wxTreeItem&) m_item; } + inline wxPoint GetPoint() const { return m_pointDrag; } + inline void SetCode(int code) { m_code = code; } + inline int GetCode() const { return m_code; } +}; + +typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); + +#define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn , NULL }, +#define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, ( wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, ( wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, + +#endif + // __GTKTREECTRL_H__ diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index f0eb372f92..fe5f8eddec 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -32,6 +32,7 @@ class wxToolBar; class wxBitmapButton; class wxStaticBitmap; class wxFrame; +class wxTreeCtrl; class wxMask; class wxBitmap; @@ -61,6 +62,7 @@ class wxMask: public wxObject friend wxBitmapButton; friend wxStaticBitmap; friend wxFrame; + friend wxTreeCtrl; GdkBitmap *GetBitmap() const; @@ -122,6 +124,7 @@ class wxBitmap: public wxObject friend wxBitmapButton; friend wxStaticBitmap; friend wxFrame; + friend wxTreeCtrl; GdkPixmap *GetPixmap() const; GdkBitmap *GetBitmap() const; diff --git a/include/wx/gtk1/treectrl.h b/include/wx/gtk1/treectrl.h new file mode 100644 index 0000000000..d6949a6482 --- /dev/null +++ b/include/wx/gtk1/treectrl.h @@ -0,0 +1,331 @@ +/* + * Author: Robert Roebling + * + * Copyright: (C) 1997,1998 Robert Roebling + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the wxWindows Licence, which + * you have received with this library (see Licence.htm). + * + */ + +#ifndef __GTKTREECTRL_H__ +#define __GTKTREECTRL_H__ + +#ifdef __GNUG__ +#pragma interface "treectrl.h" +#endif + +#include "wx/defs.h" +#include "wx/string.h" +#include "wx/list.h" +#include "wx/control.h" +#include "wx/event.h" +#include "wx/imaglist.h" +#include "wx/scrolwin.h" +#include "wx/dcclient.h" + +#include + +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- + +class wxTreeItem; +class wxTreeCtrl; +class wxTreeEvent; + +class wxImageList; + +//----------------------------------------------------------------------------- +// constants +//----------------------------------------------------------------------------- + +// WXDLLEXPORT extern const char *wxTreeNameStr; + +#define wxTREE_MASK_HANDLE 0x0001 +#define wxTREE_MASK_STATE 0x0002 +#define wxTREE_MASK_TEXT 0x0004 +#define wxTREE_MASK_IMAGE 0x0008 +#define wxTREE_MASK_SELECTED_IMAGE 0x0010 +#define wxTREE_MASK_CHILDREN 0x0020 +#define wxTREE_MASK_DATA 0x0040 + +#define wxTREE_STATE_BOLD 0x0001 +#define wxTREE_STATE_DROPHILITED 0x0002 +#define wxTREE_STATE_EXPANDED 0x0004 +#define wxTREE_STATE_EXPANDEDONCE 0x0008 +#define wxTREE_STATE_FOCUSED 0x0010 +#define wxTREE_STATE_SELECTED 0x0020 +#define wxTREE_STATE_CUT 0x0040 + +#define wxTREE_HITTEST_ABOVE 0x0001 // Above the client area. +#define wxTREE_HITTEST_BELOW 0x0002 // Below the client area. +#define wxTREE_HITTEST_NOWHERE 0x0004 // In the client area but below the last item. +#define wxTREE_HITTEST_ONITEMBUTTON 0x0010 // On the button associated with an item. +#define wxTREE_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item. +#define wxTREE_HITTEST_ONITEMINDENT 0x0040 // In the indentation associated with an item. +#define wxTREE_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item. +#define wxTREE_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item. +#define wxTREE_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state. +#define wxTREE_HITTEST_TOLEFT 0x0400 // To the right of the client area. +#define wxTREE_HITTEST_TORIGHT 0x0800 // To the left of the client area. + +#define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON) + +// Flags for GetNextItem +enum { + wxTREE_NEXT_CARET, // Retrieves the currently selected item. + wxTREE_NEXT_CHILD, // Retrieves the first child item. The hItem parameter must be NULL. + wxTREE_NEXT_DROPHILITE, // Retrieves the item that is the target of a drag-and-drop operation. + wxTREE_NEXT_FIRSTVISIBLE, // Retrieves the first visible item. + wxTREE_NEXT_NEXT, // Retrieves the next sibling item. + wxTREE_NEXT_NEXTVISIBLE, // Retrieves the next visible item that follows the specified item. + wxTREE_NEXT_PARENT, // Retrieves the parent of the specified item. + wxTREE_NEXT_PREVIOUS, // Retrieves the previous sibling item. + wxTREE_NEXT_PREVIOUSVISIBLE, // Retrieves the first visible item that precedes the specified item. + wxTREE_NEXT_ROOT // Retrieves the first child item of the root item of which the specified item is a part. +}; + +// Flags for ExpandItem +enum { + wxTREE_EXPAND_EXPAND, + wxTREE_EXPAND_COLLAPSE, + wxTREE_EXPAND_COLLAPSE_RESET, + wxTREE_EXPAND_TOGGLE +}; + +// Flags for InsertItem +enum { + wxTREE_INSERT_LAST = -1, + wxTREE_INSERT_FIRST = -2, + wxTREE_INSERT_SORT = -3 +}; + +//----------------------------------------------------------------------------- +// wxTreeItem +//----------------------------------------------------------------------------- + + +class WXDLLEXPORT wxTreeItem: public wxObject +{ +public: + wxTreeCtrl *m_owner; + GtkWidget *m_parentwidget; + GtkTreeItem *m_widget; + GtkTree *m_tree; + long m_mask; + long m_itemId; + long m_state; + long m_stateMask; + wxString m_text; + int m_image; + int m_selectedImage; + int m_children; + wxList m_childlist; + long m_data; + + wxTreeItem(); + wxTreeItem(GtkWidget *parent, const wxTreeItem &item); + ~wxTreeItem(); + + void Create(); + + void AddChild(wxTreeItem *child); + void DeleteChildren(); + bool HasChildren(); + wxTreeItem *FindItem(long itemId) const; + wxTreeItem *FindItem(GtkTreeItem *item) const; + + // Accessors + inline long GetMask() const { return m_mask; } + inline long GetItemId() const { return m_itemId; } + inline long GetState() const { return m_state; } + inline long GetStateMask() const { return m_stateMask; } + inline wxString GetText() const { return m_text; } + inline int GetImage() const { return m_image; } + inline int GetSelectedImage() const { return m_selectedImage; } + inline const wxList &GetChildren() const { return m_childlist; } + inline long GetData() const { return m_data; } + + inline void SetMask(long mask) { m_mask = mask; } + inline void SetItemId(long id) { m_itemId = m_itemId = id; } + inline void GetState(long state) { m_state = state; } + inline void SetStateMask(long stateMask) { m_stateMask = stateMask; } + inline void GetText(const wxString& text) { m_text = text; } + inline void SetImage(int image) { m_image = image; } + inline void SetSelectedImage(int selImage) { m_selectedImage = selImage; } + inline void SetChildren(const wxList &children) { m_childlist = children; } + inline void SetData(long data) { m_data = data; } + + int NumberOfVisibleDescendents(); +private: + friend wxTreeCtrl; + friend void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItem *treeitem); + friend void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItem *treeitem); + friend void gtk_treeitem_select_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem); + friend void gtk_treeitem_deselect_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem); + + void AddSubtree(); + void PrepareEvent(wxTreeEvent &event); + void SendDelete(wxWindow *target); + void SendExpand(wxWindow *target); + void SendExpanding(wxWindow *target); + void SendCollapse(wxWindow *target); + void SendCollapsing(wxWindow *target); + void SendSelChanged(wxWindow *target); + void SendSelChanging(wxWindow *target); + + inline wxTreeItem *GetChild(long no) { + return (wxTreeItem *)(m_childlist.Nth(no)->Data()); + } + inline long GetChildrenNumber() { + return m_childlist.Number(); + } + + guint expand_handler; + guint collapse_handler; + + DECLARE_DYNAMIC_CLASS(wxTreeItem) +}; + +//----------------------------------------------------------------------------- +// wxTreeCtrl +//----------------------------------------------------------------------------- + +class wxTreeCtrl: public wxScrolledWindow { +public: + GtkTree *m_tree; + + wxTreeCtrl(); + wxTreeCtrl(wxWindow *parent, const wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTR_HAS_BUTTONS, + const wxString& name = "wxTreeCtrl" ); + ~wxTreeCtrl(); + bool Create(wxWindow *parent, const wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTR_HAS_BUTTONS, + const wxString& name = "wxTreeCtrl"); + + int GetCount() const; + + long InsertItem( long parent, const wxString& label, long data = 0, + int image = -1, int selImage = -1, + long insertAfter = wxTREE_INSERT_LAST ); + + long InsertItem( long parent, wxTreeItem &info, + long insertAfter = wxTREE_INSERT_LAST ); + void DeleteItem( long item ); + void DeleteChildren( long item ); + bool DeleteAllItems(); + + bool ExpandItem(long item) { return ExpandItem(item, wxTREE_EXPAND_EXPAND); } + bool ExpandItem( long item, int action ); + + bool CollapseItem(long item) { return ExpandItem(item, wxTREE_EXPAND_COLLAPSE); } + bool ToggleItem(long item) { return ExpandItem(item, wxTREE_EXPAND_TOGGLE); } + + // is the item expanded now? + bool IsItemExpanded(long item) + { + wxTreeItem *pItem = FindItem(item); + return pItem && (pItem->GetState() & wxTREE_STATE_EXPANDED); + } + +/* + bool GetItem( wxTreeItem &info ) const; +*/ + + long GetItemData( long item ) const; + wxString GetItemText( long item ) const; + int GetItemImage(long item) const; + long GetParent( long item ) const; + long GetRootItem() const; +/* + long GetSelection() const; + bool SelectItem( long item ); +*/ + + bool ItemHasChildren( long item ) const; + void SetIndent( int indent ); + int GetIndent() const; + +/* + bool SetItem( wxTreeItem &info ); + bool SetItemData( long item, long data ); + bool SetItemText( long item, const wxString &text ); + void SetItemImage(long item, int image, int imageSel) const; + long HitTest( const wxPoint& point, int &flags ); +*/ + + wxTreeItem *FindItem(GtkTreeItem *item) const; + + wxImageList *GetImageList(int which = wxIMAGE_LIST_NORMAL) const; + void SetImageList(wxImageList *imageList, int which = wxIMAGE_LIST_NORMAL); + +private: + // set the selection to the specified item generating appropriate event(s) if + // not disabled + void SelectItem(wxTreeItem *item, bool bDoEvents = TRUE); + + wxTreeItem *m_anchor; + wxTreeItem *m_current; + int m_indent; + long m_lastId; + bool m_isCreated; + wxImageList *m_imageList; + wxImageList *m_smallImageList; + + void CalculateLevel( wxTreeItem *item, wxPaintDC &dc, int level, int &y ); + void CalculatePositions(); + wxTreeItem *FindItem( long itemId ) const; + +// DECLARE_EVENT_TABLE() + DECLARE_DYNAMIC_CLASS(wxTreeCtrl) +}; + +//----------------------------------------------------------------------------- +// wxTreeEvent +//----------------------------------------------------------------------------- + +class WXDLLEXPORT wxTreeEvent: public wxCommandEvent +{ + DECLARE_DYNAMIC_CLASS(wxTreeEvent) + + public: + wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); + + int m_code; + wxTreeItem m_item; + long m_oldItem; + wxPoint m_pointDrag; + + inline long GetOldItem() const { return m_oldItem; } + inline wxTreeItem& GetItem() const { return (wxTreeItem&) m_item; } + inline wxPoint GetPoint() const { return m_pointDrag; } + inline void SetCode(int code) { m_code = code; } + inline int GetCode() const { return m_code; } +}; + +typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); + +#define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn , NULL }, +#define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, ( wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, ( wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, +#define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, + +#endif + // __GTKTREECTRL_H__ diff --git a/include/wx/treectrl.h b/include/wx/treectrl.h index 10afdbcd42..32b7de143c 100644 --- a/include/wx/treectrl.h +++ b/include/wx/treectrl.h @@ -6,9 +6,7 @@ #elif defined(__WXMOTIF__) #include "wx/generic/treectrl.h" #elif defined(__WXGTK__) -#include "wx/generic/treectrl.h" -#elif defined(__WXQT__) -#include "wx/generic/treectrl.h" +#include "wx/gtk/treectrl.h" #endif #endif diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index ce7c7f47d3..440747a71e 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -15,6 +15,7 @@ #include "wx/treectrl.h" #include "wx/settings.h" #include "wx/log.h" +#include //----------------------------------------------------------------------------- // wxTreeItem diff --git a/src/gtk.inc b/src/gtk.inc index 616b986a18..38e86a8d17 100644 --- a/src/gtk.inc +++ b/src/gtk.inc @@ -91,6 +91,7 @@ LIB_CPP_SRC=\ gtk/tbargtk.cpp \ gtk/textctrl.cpp \ gtk/timer.cpp \ + gtk/treectrl.cpp \ gtk/utilsgtk.cpp \ gtk/utilsres.cpp \ gtk/window.cpp \ @@ -109,8 +110,7 @@ LIB_CPP_SRC=\ generic/splitter.cpp \ generic/statusbr.cpp \ generic/tabg.cpp \ - generic/textdlgg.cpp \ - generic/treectrl.cpp + generic/textdlgg.cpp LIB_C_SRC=\ diff --git a/src/gtk/treectrl.cpp b/src/gtk/treectrl.cpp new file mode 100644 index 0000000000..8c3c50ffbc --- /dev/null +++ b/src/gtk/treectrl.cpp @@ -0,0 +1,696 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: treectrl.cpp +// Purpose: +// Author: Denis Pershin +// Created: 07/05/98 +// Id: $Id$ +// Copyright: (c) 1998 Denis Pershin and Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "treectrlgtk.h" +#endif + +#include "wx/gtk/treectrl.h" +#include "wx/settings.h" +#include "wx/log.h" + +#ifdef USE_GDK_IMLIB +#include "../gdk_imlib/gdk_imlib.h" +#endif + +//----------------------------------------------------------------------------- +// wxTreeItem +//----------------------------------------------------------------------------- + +// clicked + +void gtk_treeitem_expand_callback(GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) { + treeitem->SendExpanding(treeitem->m_owner); + treeitem->SendExpand(treeitem->m_owner); +}; + +void gtk_treeitem_collapse_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) { + treeitem->SendCollapsing(treeitem->m_owner); + treeitem->SendCollapse(treeitem->m_owner); +}; + +void gtk_treeitem_select_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) { + treeitem->SendSelChanging(treeitem->m_owner); + treeitem->m_state |= wxTREE_STATE_SELECTED; + treeitem->SendSelChanged(treeitem->m_owner); +} + +void gtk_treeitem_deselect_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) { + treeitem->SendSelChanging(treeitem->m_owner); + treeitem->m_state &= !wxTREE_STATE_SELECTED; + treeitem->SendSelChanged(treeitem->m_owner); +} + +IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject) + +wxTreeItem::wxTreeItem() { + m_mask = 0; + m_itemId = 0; + m_state = 0; + m_stateMask = 0; + m_image = -1; + m_children = 0; + m_selectedImage = -1; + m_tree = NULL; + m_parentwidget = NULL; + m_widget = NULL; + m_data = 0; + m_owner = 0; + expand_handler = 0; + collapse_handler = 0; +}; + +wxTreeItem::wxTreeItem(GtkWidget *parent, const wxTreeItem &item) { + m_mask = item.m_mask; + m_text = item.m_text; + m_itemId = item.m_itemId; + m_state = item.m_state; + m_stateMask = item.m_stateMask; + m_image = item.m_image; + m_tree = NULL; + m_owner = 0; + m_selectedImage = item.m_selectedImage; + m_children = item.m_children; + m_childlist = item.m_childlist; + m_data = item.m_data; + m_parentwidget = parent; + expand_handler = 0; + collapse_handler = 0; + + Create(); +} + +void wxTreeItem::Create() { + wxASSERT(m_parentwidget != NULL); + + m_widget = GTK_TREE_ITEM(gtk_tree_item_new_with_label ((char *)(const char *)m_text)); + gtk_container_add (GTK_CONTAINER(m_parentwidget), GTK_WIDGET(m_widget)); + gtk_widget_show(GTK_WIDGET(m_widget)); + + gtk_signal_connect(GTK_OBJECT(m_widget), "select", + GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this ); + + gtk_signal_connect(GTK_OBJECT(m_widget), "deselect", + GTK_SIGNAL_FUNC(gtk_treeitem_deselect_callback), (gpointer)this ); + + if ((m_mask & wxTREE_MASK_CHILDREN) != 0) + AddSubtree(); +} + +wxTreeItem::~wxTreeItem() { + if (m_owner != NULL) + SendDelete(m_owner); + DeleteChildren(); + if ((m_widget != NULL) && (m_parentwidget != NULL)) + gtk_container_remove(GTK_CONTAINER(m_parentwidget), + GTK_WIDGET(m_widget)); +// if (m_tree != NULL) { +// gtk_widget_destroy(GTK_WIDGET(m_tree)); +// m_tree = NULL; +// } + +// if (m_widget != NULL) +// gtk_widget_destroy(GTK_WIDGET(m_widget)); +} + +void wxTreeItem::AddSubtree() { + if (m_widget == NULL) + return; + + m_tree = GTK_TREE(gtk_tree_new()); + + if (expand_handler == 0) + expand_handler = gtk_signal_connect(GTK_OBJECT(m_widget), "expand", + GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this ); + + if (collapse_handler == 0) + collapse_handler = gtk_signal_connect( GTK_OBJECT(m_widget), "collapse", + GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this ); + + gtk_tree_item_set_subtree(GTK_TREE_ITEM(m_widget), GTK_WIDGET(m_tree)); + gtk_widget_show(GTK_WIDGET(m_tree)); +} + +void wxTreeItem::AddChild(wxTreeItem *child) { + wxASSERT(child != NULL); + + m_childlist.Append(child); +} + +bool wxTreeItem::HasChildren() { + return (m_childlist.Number() != 0); +} + +void wxTreeItem::DeleteChildren() { + wxTreeItem *item; + long no = GetChildrenNumber(); + for (long i=0; isubtree == 0) + AddSubtree(); +} + +int wxTreeItem::NumberOfVisibleDescendents() { + wxTreeItem *item; + long no = GetChildrenNumber(); + long num = 0; + for (long i=0; iNumberOfVisibleDescendents(); + + num+=no; + + return num; +} + +wxTreeItem *wxTreeItem::FindItem(long itemId) const { + if (m_itemId == itemId) return (wxTreeItem*)(this); + wxNode *node = m_childlist.First(); + while (node) { + wxTreeItem *item = (wxTreeItem*)node->Data(); + wxTreeItem *res = item->FindItem( itemId ); + if (res) return (wxTreeItem*)(res); + node = node->Next(); + }; + return NULL; +}; + +wxTreeItem *wxTreeItem::FindItem(GtkTreeItem *item) const { + if (m_widget == item) + return (wxTreeItem*)(this); + wxNode *node = m_childlist.First(); + while (node) { + wxTreeItem *i = (wxTreeItem*)node->Data(); + wxTreeItem *res = i->FindItem(item); + if (res) return (wxTreeItem*)(res); + node = node->Next(); + }; + return NULL; +}; + +void wxTreeItem::PrepareEvent(wxTreeEvent &event) { + event.m_item.m_itemId = m_itemId; + event.m_item.m_state = m_state; + event.m_item.m_text = m_text; + event.m_item.m_image = m_image; + event.m_item.m_selectedImage = m_selectedImage; + event.m_item.m_children = (GetChildrenNumber() > 0); + event.m_item.m_data = m_data; + event.m_oldItem = 0; + event.m_code = 0; +// event.m_pointDrag.x = 0; +// event.m_pointDrag.y = 0; +}; + +void wxTreeItem::SendDelete(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_DELETE_ITEM, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendExpand(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDED, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendExpanding(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDING, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendCollapse(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendCollapsing(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendSelChanged(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGED, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendSelChanging(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +//----------------------------------------------------------------------------- +// wxTreeCtrl +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxScrolledWindow) + +wxTreeCtrl::wxTreeCtrl() { + m_current = NULL; + m_lastId = 0; + m_isCreated = FALSE; + m_imageList = NULL; + m_smallImageList = NULL; +}; + +wxTreeCtrl::wxTreeCtrl(wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name ) { + m_current = NULL; + m_lastId = 0; + m_isCreated = FALSE; + m_imageList = NULL; + m_smallImageList = NULL; + Create( parent, id, pos, size, style, name ); +}; + +wxTreeCtrl::~wxTreeCtrl() { + DeleteAllItems(); +}; + +bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name ) { + m_needParent = TRUE; + + PreCreation( parent, id, pos, size, style, name ); + + m_widget = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + m_tree = GTK_TREE(gtk_tree_new()); + +/* + gtk_signal_connect( GTK_OBJECT(m_tree), "selection_changed", + GTK_SIGNAL_FUNC(gtk_treectrl_selection_changed_callback), (gpointer)this); + gtk_signal_connect( GTK_OBJECT(m_tree), "select_child", + GTK_SIGNAL_FUNC(gtk_treectrl_select_child_callback), (gpointer)this); + gtk_signal_connect( GTK_OBJECT(m_tree), "unselect_child", + GTK_SIGNAL_FUNC(gtk_treectrl_unselect_child_callback), (gpointer)this); +*/ + + gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree)); + gtk_widget_show(GTK_WIDGET(m_tree)); + + PostCreation(); + + gtk_widget_realize(GTK_WIDGET(m_tree)); + + Show(TRUE); + + return TRUE; +}; + +int wxTreeCtrl::GetCount() const +{ + if (!m_anchor) return 0; + return m_anchor->NumberOfVisibleDescendents(); +}; + +long wxTreeCtrl::InsertItem(long parent, const wxString& label, long data, + int image, int selImage, long insertAfter) { + wxTreeItem item; + item.m_data = data; + if (!label.IsNull() || (label == "")) { + item.m_text = label; + item.m_mask |= wxTREE_MASK_TEXT; + }; + + if (image >= 0) { + item.m_image = image; + item.m_mask |= wxTREE_MASK_IMAGE; + }; + + if (selImage >= 0) { + item.m_selectedImage = selImage; + item.m_mask |= wxTREE_MASK_SELECTED_IMAGE; + }; + + return InsertItem(parent, item, insertAfter); +}; + +long wxTreeCtrl::InsertItem( long parent, wxTreeItem &info, long WXUNUSED(insertAfter) ) { + int oldMask = info.m_mask; + long ret = 0; + wxTreeItem *p = NULL; + wxTreeItem *new_child; + + if (parent == 0) { + if (m_anchor) + return -1; + } else { + p = FindItem(parent); + if (!p) return -1; + }; + + if ((info.m_mask & wxTREE_MASK_HANDLE) == 0) { + m_lastId++; + info.m_itemId = m_lastId; + info.m_mask |= wxTREE_MASK_HANDLE; + ret = m_lastId; + } else + ret = info.m_itemId; + + if (p) { + if (p->m_tree == NULL) + p->AddSubtree(); + + new_child = new wxTreeItem(GTK_WIDGET(p->m_tree), info); + p->AddChild(new_child); + } else { + new_child = new wxTreeItem(GTK_WIDGET(m_tree), info); + m_anchor = new_child; + } + +/* Disabled until wxImageList q solved + if ((info.m_mask & wxTREE_MASK_IMAGE) == 0) { + wxBitmap *bmp; + + if ((bmp = m_imageList->GetItem(info.m_image))->Ok()) { + GdkBitmap *mask = NULL; + if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask ); + + gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget)); + gtk_widget_show(pixmap); + GTK_TREE_ITEM(new_child->m_widget)->pixmaps_box = pixmap; + } + } +*/ + + new_child->m_owner = this; + + info.m_mask = oldMask; + return ret; +}; + + +bool wxTreeCtrl::ExpandItem( long item, int action ) { + wxTreeItem *i = FindItem( item ); + if (!i) + return FALSE; + + switch (action) { + case wxTREE_EXPAND_EXPAND: + gtk_tree_item_expand(GTK_TREE_ITEM(i->m_widget)); + break; + + case wxTREE_EXPAND_COLLAPSE_RESET: + case wxTREE_EXPAND_COLLAPSE: + gtk_tree_item_collapse(GTK_TREE_ITEM(i->m_widget)); + break; + + case wxTREE_EXPAND_TOGGLE: + if ((i->GetState() & wxTREE_STATE_EXPANDED) == 0) + gtk_tree_item_expand(GTK_TREE_ITEM(i->m_widget)); + else + gtk_tree_item_collapse(GTK_TREE_ITEM(i->m_widget)); + break; + } + + return TRUE; +}; + +void wxTreeCtrl::DeleteItem( long item ) +{ + wxTreeItem *pItem = FindItem( item ); + wxCHECK_RET( pItem != NULL, "wxTreeCtrl::DeleteItem: no such pItem." ); + +// pItem->m_parent->m_childlist.DeleteObject(pItem); +} + +void wxTreeCtrl::DeleteChildren( long item ) +{ + wxTreeItem *pItem = FindItem( item ); + wxCHECK_RET( pItem != NULL, "wxTreeCtrl::DeleteChildren: no such pItem." ); + + pItem->DeleteChildren(); +} + +bool wxTreeCtrl::DeleteAllItems() +{ + delete m_anchor; + m_anchor = NULL; + return TRUE; +}; + +/* +bool wxTreeCtrl::GetItem( wxTreeItem &info ) const +{ + wxTreeItem *i = FindItem( info.m_itemId ); + if (!i) return FALSE; + i->GetItem( info ); + return TRUE; +}; +*/ + +long wxTreeCtrl::GetItemData( long item ) const +{ + wxTreeItem *i = FindItem( item ); + if (!i) return 0; + return i->m_data; +}; + +wxString wxTreeCtrl::GetItemText( long item ) const +{ + wxTreeItem *i = FindItem( item ); + if (!i) return ""; + return i->m_text; +}; + +int wxTreeCtrl::GetItemImage(long item) const +{ + wxTreeItem *i = FindItem( item ); + return i == 0 ? -1 : i->GetImage(); +} + +long wxTreeCtrl::GetParent( long item ) const +{ + wxTreeItem *i = FindItem( item ); + if (!i) return -1; +/* + i = i->m_parent; + if (!i) return -1; + return i->m_parent->m_itemId; +*/ + return -1; +}; + +long wxTreeCtrl::GetRootItem() const +{ + if (m_anchor) return m_anchor->m_itemId; + return -1; +}; + +/* +long wxTreeCtrl::GetSelection() const +{ + return m_current ? m_current->GetItemId() : -1; +}; + +bool wxTreeCtrl::SelectItem(long itemId) +{ + wxTreeItem *pItem = FindItem(itemId); + if ( !pItem ) { + wxLogDebug("Can't select an item %d which doesn't exist.", itemId); + + return FALSE; + } + + SelectItem(pItem); + + return TRUE; +}; + +void wxTreeCtrl::SelectItem(wxTreeItem *item, bool bDoEvents ) +{ + if (m_current != item) + { + if (m_current) + { + m_current->SetHilight( FALSE ); +// RefreshLine( m_current ); + }; + m_current = item; + m_current->SetHilight( TRUE ); +// RefreshLine( m_current ); + + if (bDoEvents) m_current->SendSelected( this ); + } +} +*/ + +bool wxTreeCtrl::ItemHasChildren( long item ) const +{ + wxTreeItem *i = FindItem( item ); + if (!i) return FALSE; + return i->HasChildren(); +}; + +void wxTreeCtrl::SetIndent( int indent ) +{ + m_indent = indent; + Refresh(); +}; + +int wxTreeCtrl::GetIndent() const +{ + return m_indent; +}; + +/* +bool wxTreeCtrl::SetItem( wxTreeItem &info ) +{ + wxTreeItem *i = FindItem( info.m_itemId ); + if (!i) return FALSE; + wxClientDC dc(this); + i->SetItem( info, &dc ); + Refresh(); + return TRUE; +}; + +bool wxTreeCtrl::SetItemData( long item, long data ) +{ + wxTreeItem *i = FindItem( item ); + if (!i) return FALSE; + i->m_data = data; + return TRUE; +}; + +bool wxTreeCtrl::SetItemText( long item, const wxString &text ) +{ + wxTreeItem *i = FindItem( item ); + if (!i) return FALSE; + wxClientDC dc(this); + i->SetText( text, &dc ); + return TRUE; +}; + +void wxTreeCtrl::SetItemImage(long item, int image, int imageSel) const +{ + wxTreeItem *i = FindItem( item ); + if ( i != 0 ) { + i->SetImage(image); + i->SetSelectedImage(imageSel); + } +} + +long wxTreeCtrl::HitTest( const wxPoint& point, int &flags ) +{ + flags = 0; + if (!m_anchor) return -1; + return m_anchor->HitTest( point, flags ); +}; +*/ + +wxImageList *wxTreeCtrl::GetImageList( int which ) const +{ + if (which == wxIMAGE_LIST_NORMAL) return m_imageList; + return m_smallImageList; +}; + +void wxTreeCtrl::SetImageList( wxImageList *imageList, int which ) +{ + if (which == wxIMAGE_LIST_NORMAL) + { + if (m_imageList) delete m_imageList; + m_imageList = imageList; + } + else + { + if (m_smallImageList) delete m_smallImageList; + m_smallImageList = imageList; + }; +}; + +wxTreeItem *wxTreeCtrl::FindItem( long itemId ) const { + if (!m_anchor) return NULL; + return m_anchor->FindItem( itemId ); + return 0; +}; + +wxTreeItem *wxTreeCtrl::FindItem(GtkTreeItem *item) const { + if (!m_anchor) return NULL; + return m_anchor->FindItem(item); + return 0; +}; + +//----------------------------------------------------------------------------- +// wxTreeEvent +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent,wxCommandEvent) + +wxTreeEvent::wxTreeEvent( wxEventType commandType, int id ) : + wxCommandEvent( commandType, id ) +{ + m_code = 0; + m_oldItem = 0; +}; + +/* Bunch of old code might be useful */ +/* + wxBitmap *bmp; + + if ((bmp = m_imageList->GetItem(0))->Ok()) { + GdkBitmap *mask = NULL; + if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask ); + + gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget)); + gtk_widget_show(pixmap); + GTK_TREE_ITEM(new_child->m_widget)->pixmaps_box = pixmap; + } + + if ((bmp = m_imageList->GetItem(1))->Ok()) { + GdkBitmap *mask = NULL; + if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask ); + + gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget)); + gtk_widget_show(pixmap); + GTK_TREE_ITEM(new_child->m_widget)->plus_pix_widget = pixmap; + } + + if ((bmp = m_imageList->GetItem(2))->Ok()) { + GdkBitmap *mask = NULL; + if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask ); + + gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget)); + gtk_widget_show(pixmap); + GTK_TREE_ITEM(new_child->m_widget)->minus_pix_widget = pixmap; + } + + if (p) + if (p->m_childlist.Number() == 1) { + gtk_tree_item_collapse(GTK_TREE_ITEM(p->m_widget)); + gtk_tree_item_expand(GTK_TREE_ITEM(p->m_widget)); + } +*/ diff --git a/src/gtk1/treectrl.cpp b/src/gtk1/treectrl.cpp new file mode 100644 index 0000000000..8c3c50ffbc --- /dev/null +++ b/src/gtk1/treectrl.cpp @@ -0,0 +1,696 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: treectrl.cpp +// Purpose: +// Author: Denis Pershin +// Created: 07/05/98 +// Id: $Id$ +// Copyright: (c) 1998 Denis Pershin and Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "treectrlgtk.h" +#endif + +#include "wx/gtk/treectrl.h" +#include "wx/settings.h" +#include "wx/log.h" + +#ifdef USE_GDK_IMLIB +#include "../gdk_imlib/gdk_imlib.h" +#endif + +//----------------------------------------------------------------------------- +// wxTreeItem +//----------------------------------------------------------------------------- + +// clicked + +void gtk_treeitem_expand_callback(GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) { + treeitem->SendExpanding(treeitem->m_owner); + treeitem->SendExpand(treeitem->m_owner); +}; + +void gtk_treeitem_collapse_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) { + treeitem->SendCollapsing(treeitem->m_owner); + treeitem->SendCollapse(treeitem->m_owner); +}; + +void gtk_treeitem_select_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) { + treeitem->SendSelChanging(treeitem->m_owner); + treeitem->m_state |= wxTREE_STATE_SELECTED; + treeitem->SendSelChanged(treeitem->m_owner); +} + +void gtk_treeitem_deselect_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) { + treeitem->SendSelChanging(treeitem->m_owner); + treeitem->m_state &= !wxTREE_STATE_SELECTED; + treeitem->SendSelChanged(treeitem->m_owner); +} + +IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject) + +wxTreeItem::wxTreeItem() { + m_mask = 0; + m_itemId = 0; + m_state = 0; + m_stateMask = 0; + m_image = -1; + m_children = 0; + m_selectedImage = -1; + m_tree = NULL; + m_parentwidget = NULL; + m_widget = NULL; + m_data = 0; + m_owner = 0; + expand_handler = 0; + collapse_handler = 0; +}; + +wxTreeItem::wxTreeItem(GtkWidget *parent, const wxTreeItem &item) { + m_mask = item.m_mask; + m_text = item.m_text; + m_itemId = item.m_itemId; + m_state = item.m_state; + m_stateMask = item.m_stateMask; + m_image = item.m_image; + m_tree = NULL; + m_owner = 0; + m_selectedImage = item.m_selectedImage; + m_children = item.m_children; + m_childlist = item.m_childlist; + m_data = item.m_data; + m_parentwidget = parent; + expand_handler = 0; + collapse_handler = 0; + + Create(); +} + +void wxTreeItem::Create() { + wxASSERT(m_parentwidget != NULL); + + m_widget = GTK_TREE_ITEM(gtk_tree_item_new_with_label ((char *)(const char *)m_text)); + gtk_container_add (GTK_CONTAINER(m_parentwidget), GTK_WIDGET(m_widget)); + gtk_widget_show(GTK_WIDGET(m_widget)); + + gtk_signal_connect(GTK_OBJECT(m_widget), "select", + GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this ); + + gtk_signal_connect(GTK_OBJECT(m_widget), "deselect", + GTK_SIGNAL_FUNC(gtk_treeitem_deselect_callback), (gpointer)this ); + + if ((m_mask & wxTREE_MASK_CHILDREN) != 0) + AddSubtree(); +} + +wxTreeItem::~wxTreeItem() { + if (m_owner != NULL) + SendDelete(m_owner); + DeleteChildren(); + if ((m_widget != NULL) && (m_parentwidget != NULL)) + gtk_container_remove(GTK_CONTAINER(m_parentwidget), + GTK_WIDGET(m_widget)); +// if (m_tree != NULL) { +// gtk_widget_destroy(GTK_WIDGET(m_tree)); +// m_tree = NULL; +// } + +// if (m_widget != NULL) +// gtk_widget_destroy(GTK_WIDGET(m_widget)); +} + +void wxTreeItem::AddSubtree() { + if (m_widget == NULL) + return; + + m_tree = GTK_TREE(gtk_tree_new()); + + if (expand_handler == 0) + expand_handler = gtk_signal_connect(GTK_OBJECT(m_widget), "expand", + GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this ); + + if (collapse_handler == 0) + collapse_handler = gtk_signal_connect( GTK_OBJECT(m_widget), "collapse", + GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this ); + + gtk_tree_item_set_subtree(GTK_TREE_ITEM(m_widget), GTK_WIDGET(m_tree)); + gtk_widget_show(GTK_WIDGET(m_tree)); +} + +void wxTreeItem::AddChild(wxTreeItem *child) { + wxASSERT(child != NULL); + + m_childlist.Append(child); +} + +bool wxTreeItem::HasChildren() { + return (m_childlist.Number() != 0); +} + +void wxTreeItem::DeleteChildren() { + wxTreeItem *item; + long no = GetChildrenNumber(); + for (long i=0; isubtree == 0) + AddSubtree(); +} + +int wxTreeItem::NumberOfVisibleDescendents() { + wxTreeItem *item; + long no = GetChildrenNumber(); + long num = 0; + for (long i=0; iNumberOfVisibleDescendents(); + + num+=no; + + return num; +} + +wxTreeItem *wxTreeItem::FindItem(long itemId) const { + if (m_itemId == itemId) return (wxTreeItem*)(this); + wxNode *node = m_childlist.First(); + while (node) { + wxTreeItem *item = (wxTreeItem*)node->Data(); + wxTreeItem *res = item->FindItem( itemId ); + if (res) return (wxTreeItem*)(res); + node = node->Next(); + }; + return NULL; +}; + +wxTreeItem *wxTreeItem::FindItem(GtkTreeItem *item) const { + if (m_widget == item) + return (wxTreeItem*)(this); + wxNode *node = m_childlist.First(); + while (node) { + wxTreeItem *i = (wxTreeItem*)node->Data(); + wxTreeItem *res = i->FindItem(item); + if (res) return (wxTreeItem*)(res); + node = node->Next(); + }; + return NULL; +}; + +void wxTreeItem::PrepareEvent(wxTreeEvent &event) { + event.m_item.m_itemId = m_itemId; + event.m_item.m_state = m_state; + event.m_item.m_text = m_text; + event.m_item.m_image = m_image; + event.m_item.m_selectedImage = m_selectedImage; + event.m_item.m_children = (GetChildrenNumber() > 0); + event.m_item.m_data = m_data; + event.m_oldItem = 0; + event.m_code = 0; +// event.m_pointDrag.x = 0; +// event.m_pointDrag.y = 0; +}; + +void wxTreeItem::SendDelete(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_DELETE_ITEM, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendExpand(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDED, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendExpanding(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDING, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendCollapse(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendCollapsing(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendSelChanged(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGED, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +void wxTreeItem::SendSelChanging(wxWindow *target) { + wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, target->GetId()); + PrepareEvent(event); + event.SetEventObject(target); + target->ProcessEvent(event); +}; + +//----------------------------------------------------------------------------- +// wxTreeCtrl +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxScrolledWindow) + +wxTreeCtrl::wxTreeCtrl() { + m_current = NULL; + m_lastId = 0; + m_isCreated = FALSE; + m_imageList = NULL; + m_smallImageList = NULL; +}; + +wxTreeCtrl::wxTreeCtrl(wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name ) { + m_current = NULL; + m_lastId = 0; + m_isCreated = FALSE; + m_imageList = NULL; + m_smallImageList = NULL; + Create( parent, id, pos, size, style, name ); +}; + +wxTreeCtrl::~wxTreeCtrl() { + DeleteAllItems(); +}; + +bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name ) { + m_needParent = TRUE; + + PreCreation( parent, id, pos, size, style, name ); + + m_widget = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + m_tree = GTK_TREE(gtk_tree_new()); + +/* + gtk_signal_connect( GTK_OBJECT(m_tree), "selection_changed", + GTK_SIGNAL_FUNC(gtk_treectrl_selection_changed_callback), (gpointer)this); + gtk_signal_connect( GTK_OBJECT(m_tree), "select_child", + GTK_SIGNAL_FUNC(gtk_treectrl_select_child_callback), (gpointer)this); + gtk_signal_connect( GTK_OBJECT(m_tree), "unselect_child", + GTK_SIGNAL_FUNC(gtk_treectrl_unselect_child_callback), (gpointer)this); +*/ + + gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree)); + gtk_widget_show(GTK_WIDGET(m_tree)); + + PostCreation(); + + gtk_widget_realize(GTK_WIDGET(m_tree)); + + Show(TRUE); + + return TRUE; +}; + +int wxTreeCtrl::GetCount() const +{ + if (!m_anchor) return 0; + return m_anchor->NumberOfVisibleDescendents(); +}; + +long wxTreeCtrl::InsertItem(long parent, const wxString& label, long data, + int image, int selImage, long insertAfter) { + wxTreeItem item; + item.m_data = data; + if (!label.IsNull() || (label == "")) { + item.m_text = label; + item.m_mask |= wxTREE_MASK_TEXT; + }; + + if (image >= 0) { + item.m_image = image; + item.m_mask |= wxTREE_MASK_IMAGE; + }; + + if (selImage >= 0) { + item.m_selectedImage = selImage; + item.m_mask |= wxTREE_MASK_SELECTED_IMAGE; + }; + + return InsertItem(parent, item, insertAfter); +}; + +long wxTreeCtrl::InsertItem( long parent, wxTreeItem &info, long WXUNUSED(insertAfter) ) { + int oldMask = info.m_mask; + long ret = 0; + wxTreeItem *p = NULL; + wxTreeItem *new_child; + + if (parent == 0) { + if (m_anchor) + return -1; + } else { + p = FindItem(parent); + if (!p) return -1; + }; + + if ((info.m_mask & wxTREE_MASK_HANDLE) == 0) { + m_lastId++; + info.m_itemId = m_lastId; + info.m_mask |= wxTREE_MASK_HANDLE; + ret = m_lastId; + } else + ret = info.m_itemId; + + if (p) { + if (p->m_tree == NULL) + p->AddSubtree(); + + new_child = new wxTreeItem(GTK_WIDGET(p->m_tree), info); + p->AddChild(new_child); + } else { + new_child = new wxTreeItem(GTK_WIDGET(m_tree), info); + m_anchor = new_child; + } + +/* Disabled until wxImageList q solved + if ((info.m_mask & wxTREE_MASK_IMAGE) == 0) { + wxBitmap *bmp; + + if ((bmp = m_imageList->GetItem(info.m_image))->Ok()) { + GdkBitmap *mask = NULL; + if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask ); + + gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget)); + gtk_widget_show(pixmap); + GTK_TREE_ITEM(new_child->m_widget)->pixmaps_box = pixmap; + } + } +*/ + + new_child->m_owner = this; + + info.m_mask = oldMask; + return ret; +}; + + +bool wxTreeCtrl::ExpandItem( long item, int action ) { + wxTreeItem *i = FindItem( item ); + if (!i) + return FALSE; + + switch (action) { + case wxTREE_EXPAND_EXPAND: + gtk_tree_item_expand(GTK_TREE_ITEM(i->m_widget)); + break; + + case wxTREE_EXPAND_COLLAPSE_RESET: + case wxTREE_EXPAND_COLLAPSE: + gtk_tree_item_collapse(GTK_TREE_ITEM(i->m_widget)); + break; + + case wxTREE_EXPAND_TOGGLE: + if ((i->GetState() & wxTREE_STATE_EXPANDED) == 0) + gtk_tree_item_expand(GTK_TREE_ITEM(i->m_widget)); + else + gtk_tree_item_collapse(GTK_TREE_ITEM(i->m_widget)); + break; + } + + return TRUE; +}; + +void wxTreeCtrl::DeleteItem( long item ) +{ + wxTreeItem *pItem = FindItem( item ); + wxCHECK_RET( pItem != NULL, "wxTreeCtrl::DeleteItem: no such pItem." ); + +// pItem->m_parent->m_childlist.DeleteObject(pItem); +} + +void wxTreeCtrl::DeleteChildren( long item ) +{ + wxTreeItem *pItem = FindItem( item ); + wxCHECK_RET( pItem != NULL, "wxTreeCtrl::DeleteChildren: no such pItem." ); + + pItem->DeleteChildren(); +} + +bool wxTreeCtrl::DeleteAllItems() +{ + delete m_anchor; + m_anchor = NULL; + return TRUE; +}; + +/* +bool wxTreeCtrl::GetItem( wxTreeItem &info ) const +{ + wxTreeItem *i = FindItem( info.m_itemId ); + if (!i) return FALSE; + i->GetItem( info ); + return TRUE; +}; +*/ + +long wxTreeCtrl::GetItemData( long item ) const +{ + wxTreeItem *i = FindItem( item ); + if (!i) return 0; + return i->m_data; +}; + +wxString wxTreeCtrl::GetItemText( long item ) const +{ + wxTreeItem *i = FindItem( item ); + if (!i) return ""; + return i->m_text; +}; + +int wxTreeCtrl::GetItemImage(long item) const +{ + wxTreeItem *i = FindItem( item ); + return i == 0 ? -1 : i->GetImage(); +} + +long wxTreeCtrl::GetParent( long item ) const +{ + wxTreeItem *i = FindItem( item ); + if (!i) return -1; +/* + i = i->m_parent; + if (!i) return -1; + return i->m_parent->m_itemId; +*/ + return -1; +}; + +long wxTreeCtrl::GetRootItem() const +{ + if (m_anchor) return m_anchor->m_itemId; + return -1; +}; + +/* +long wxTreeCtrl::GetSelection() const +{ + return m_current ? m_current->GetItemId() : -1; +}; + +bool wxTreeCtrl::SelectItem(long itemId) +{ + wxTreeItem *pItem = FindItem(itemId); + if ( !pItem ) { + wxLogDebug("Can't select an item %d which doesn't exist.", itemId); + + return FALSE; + } + + SelectItem(pItem); + + return TRUE; +}; + +void wxTreeCtrl::SelectItem(wxTreeItem *item, bool bDoEvents ) +{ + if (m_current != item) + { + if (m_current) + { + m_current->SetHilight( FALSE ); +// RefreshLine( m_current ); + }; + m_current = item; + m_current->SetHilight( TRUE ); +// RefreshLine( m_current ); + + if (bDoEvents) m_current->SendSelected( this ); + } +} +*/ + +bool wxTreeCtrl::ItemHasChildren( long item ) const +{ + wxTreeItem *i = FindItem( item ); + if (!i) return FALSE; + return i->HasChildren(); +}; + +void wxTreeCtrl::SetIndent( int indent ) +{ + m_indent = indent; + Refresh(); +}; + +int wxTreeCtrl::GetIndent() const +{ + return m_indent; +}; + +/* +bool wxTreeCtrl::SetItem( wxTreeItem &info ) +{ + wxTreeItem *i = FindItem( info.m_itemId ); + if (!i) return FALSE; + wxClientDC dc(this); + i->SetItem( info, &dc ); + Refresh(); + return TRUE; +}; + +bool wxTreeCtrl::SetItemData( long item, long data ) +{ + wxTreeItem *i = FindItem( item ); + if (!i) return FALSE; + i->m_data = data; + return TRUE; +}; + +bool wxTreeCtrl::SetItemText( long item, const wxString &text ) +{ + wxTreeItem *i = FindItem( item ); + if (!i) return FALSE; + wxClientDC dc(this); + i->SetText( text, &dc ); + return TRUE; +}; + +void wxTreeCtrl::SetItemImage(long item, int image, int imageSel) const +{ + wxTreeItem *i = FindItem( item ); + if ( i != 0 ) { + i->SetImage(image); + i->SetSelectedImage(imageSel); + } +} + +long wxTreeCtrl::HitTest( const wxPoint& point, int &flags ) +{ + flags = 0; + if (!m_anchor) return -1; + return m_anchor->HitTest( point, flags ); +}; +*/ + +wxImageList *wxTreeCtrl::GetImageList( int which ) const +{ + if (which == wxIMAGE_LIST_NORMAL) return m_imageList; + return m_smallImageList; +}; + +void wxTreeCtrl::SetImageList( wxImageList *imageList, int which ) +{ + if (which == wxIMAGE_LIST_NORMAL) + { + if (m_imageList) delete m_imageList; + m_imageList = imageList; + } + else + { + if (m_smallImageList) delete m_smallImageList; + m_smallImageList = imageList; + }; +}; + +wxTreeItem *wxTreeCtrl::FindItem( long itemId ) const { + if (!m_anchor) return NULL; + return m_anchor->FindItem( itemId ); + return 0; +}; + +wxTreeItem *wxTreeCtrl::FindItem(GtkTreeItem *item) const { + if (!m_anchor) return NULL; + return m_anchor->FindItem(item); + return 0; +}; + +//----------------------------------------------------------------------------- +// wxTreeEvent +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent,wxCommandEvent) + +wxTreeEvent::wxTreeEvent( wxEventType commandType, int id ) : + wxCommandEvent( commandType, id ) +{ + m_code = 0; + m_oldItem = 0; +}; + +/* Bunch of old code might be useful */ +/* + wxBitmap *bmp; + + if ((bmp = m_imageList->GetItem(0))->Ok()) { + GdkBitmap *mask = NULL; + if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask ); + + gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget)); + gtk_widget_show(pixmap); + GTK_TREE_ITEM(new_child->m_widget)->pixmaps_box = pixmap; + } + + if ((bmp = m_imageList->GetItem(1))->Ok()) { + GdkBitmap *mask = NULL; + if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask ); + + gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget)); + gtk_widget_show(pixmap); + GTK_TREE_ITEM(new_child->m_widget)->plus_pix_widget = pixmap; + } + + if ((bmp = m_imageList->GetItem(2))->Ok()) { + GdkBitmap *mask = NULL; + if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask ); + + gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget)); + gtk_widget_show(pixmap); + GTK_TREE_ITEM(new_child->m_widget)->minus_pix_widget = pixmap; + } + + if (p) + if (p->m_childlist.Number() == 1) { + gtk_tree_item_collapse(GTK_TREE_ITEM(p->m_widget)); + gtk_tree_item_expand(GTK_TREE_ITEM(p->m_widget)); + } +*/ -- 2.45.2