Patch level : 10.0
Files correlati : Ricompilazione Demo : [ ] Commento : Riportato wxTreeListCtrl Dalla 11.0 git-svn-id: svn://10.65.10.50/branches/R_10_00@21912 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
		
							parent
							
								
									2ebb52552c
								
							
						
					
					
						commit
						377c121076
					
				@ -4,7 +4,7 @@
 | 
			
		||||
// Author:      Robert Roebling
 | 
			
		||||
// Maintainer:  $Author: guy $
 | 
			
		||||
// Created:     01/02/97
 | 
			
		||||
// RCS-ID:      $Id: treelistctrl.cpp,v 1.1 2010-08-11 12:53:55 guy Exp $
 | 
			
		||||
// RCS-ID:      $Id: treelistctrl.cpp,v 1.1.2.1 2011-04-06 14:09:31 guy Exp $
 | 
			
		||||
// Copyright:   (c) 2004-2008 Robert Roebling, Julian Smart, Alberto Griggio,
 | 
			
		||||
//              Vadim Zeitlin, Otto Wyss, Ronan Chartois
 | 
			
		||||
// Licence:     wxWindows
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
// Author:      Robert Roebling
 | 
			
		||||
// Maintainer:  Otto Wyss
 | 
			
		||||
// Created:     01/02/97
 | 
			
		||||
// RCS-ID:      $Id: treelistctrl.h,v 1.1 2010-08-11 12:53:55 guy Exp $
 | 
			
		||||
// RCS-ID:      $Id: treelistctrl.h,v 1.1.2.1 2011-04-06 14:09:31 guy Exp $
 | 
			
		||||
// Copyright:   (c) 2004 Robert Roebling, Julian Smart, Alberto Griggio,
 | 
			
		||||
//              Vadim Zeitlin, Otto Wyss
 | 
			
		||||
// Licence:     wxWindows
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										26
									
								
								xvaga/xvt.h
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								xvaga/xvt.h
									
									
									
									
									
								
							@ -500,6 +500,32 @@ XVTDLL BOOLEAN           xvt_prop_set_data(WINDOW win, XVT_TREEVIEW_NODE node, c
 | 
			
		||||
XVTDLL BOOLEAN           xvt_prop_set_read_only(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN ro);
 | 
			
		||||
XVTDLL BOOLEAN           xvt_prop_suspend(WINDOW win);
 | 
			
		||||
 | 
			
		||||
XVTDLL XVT_TREEVIEW_NODE xvt_treelist_add_child_node(WINDOW win, 
 | 
			
		||||
  XVT_TREEVIEW_NODE parent, XVT_TREEVIEW_NODE_TYPE type,
 | 
			
		||||
  XVT_IMAGE item_image, XVT_IMAGE collapsed_image, XVT_IMAGE expanded_image, 
 | 
			
		||||
  const char* string, XVT_TREEVIEW_CALLBACK callback, const char* data);
 | 
			
		||||
XVTDLL WINDOW xvt_treelist_create(WINDOW parent_win,
 | 
			
		||||
  RCT * rct_p, char * title, long ctl_flags, long app_data, int ctl_id, 
 | 
			
		||||
  XVT_IMAGE item_image, XVT_IMAGE collapsed_image, XVT_IMAGE expanded_image,
 | 
			
		||||
  long attrs, int line_height);
 | 
			
		||||
XVTDLL void              xvt_treelist_destroy_node(WINDOW win, XVT_TREEVIEW_NODE node);
 | 
			
		||||
XVTDLL BOOLEAN           xvt_treelist_enable_node(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN on);
 | 
			
		||||
XVTDLL BOOLEAN           xvt_treelist_expand_node(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN recurse);
 | 
			
		||||
XVTDLL XVT_TREEVIEW_NODE xvt_treelist_find_node_string(WINDOW win, const char* text);
 | 
			
		||||
XVTDLL XVT_TREEVIEW_NODE xvt_treelist_get_child_node(WINDOW win, XVT_TREEVIEW_NODE parent_node, int position);
 | 
			
		||||
XVTDLL const char*       xvt_treelist_get_node_data(WINDOW win, XVT_TREEVIEW_NODE node);
 | 
			
		||||
XVTDLL XVT_TREEVIEW_NODE xvt_treelist_get_root_node(WINDOW win);
 | 
			
		||||
XVTDLL XVT_TREEVIEW_NODE xvt_treelist_get_selected_node(WINDOW win);
 | 
			
		||||
XVTDLL BOOLEAN           xvt_treelist_remove_child_node(WINDOW win, XVT_TREEVIEW_NODE node);
 | 
			
		||||
XVTDLL BOOLEAN           xvt_treelist_remove_node_children(WINDOW win, XVT_TREEVIEW_NODE node);
 | 
			
		||||
XVTDLL void              xvt_treelist_resume(WINDOW win);
 | 
			
		||||
XVTDLL void              xvt_treelist_select_node(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN sel);
 | 
			
		||||
XVTDLL void              xvt_treelist_set_node_bold(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN bold);
 | 
			
		||||
XVTDLL void              xvt_treelist_set_node_images(WINDOW win, XVT_TREEVIEW_NODE node, 
 | 
			
		||||
                             XVT_IMAGE item_image, XVT_IMAGE collapsed_image, XVT_IMAGE expanded_image);
 | 
			
		||||
XVTDLL void              xvt_treelist_set_node_string(WINDOW win, XVT_TREEVIEW_NODE node, const char* text);
 | 
			
		||||
XVTDLL void              xvt_treelist_suspend(WINDOW win);
 | 
			
		||||
 | 
			
		||||
XVTDLL BOOLEAN  xvt_mail_send(const char* to, const char* cc, const char* ccn,
 | 
			
		||||
                              const char* subject, const char* msg, const char* attach, short flags); // 0x1=UI; 0x2=Receipt
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -237,6 +237,7 @@ WC_VSLIDER,     /* vertical slider control */
 | 
			
		||||
WC_POPUP,       /* list of listedit control or popup menu */
 | 
			
		||||
WC_PROPGRID,    /* property grid */
 | 
			
		||||
WC_MVC,         /* model view controller */
 | 
			
		||||
WC_TREELIST,    /* tree list */
 | 
			
		||||
} WIN_TYPE;
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										524
									
								
								xvaga/xvtctl.cpp
									
									
									
									
									
								
							
							
						
						
									
										524
									
								
								xvaga/xvtctl.cpp
									
									
									
									
									
								
							@ -3,9 +3,11 @@
 | 
			
		||||
#include "xvtart.h"
 | 
			
		||||
#include "xvtwin.h"
 | 
			
		||||
#include "statbar.h"
 | 
			
		||||
#include "treelistctrl.h"
 | 
			
		||||
 | 
			
		||||
#include <wx/artprov.h>
 | 
			
		||||
#include <wx/filename.h>
 | 
			
		||||
#include <wx/tokenzr.h>
 | 
			
		||||
#include <wx/treectrl.h>
 | 
			
		||||
#include <wx/vlbox.h>
 | 
			
		||||
#include <wx/aui/aui.h>
 | 
			
		||||
@ -124,9 +126,10 @@ public:
 | 
			
		||||
  ~TwxNoteBook();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
WX_DECLARE_VOIDPTR_HASH_MAP(int, XVT_IMAGE_Map);
 | 
			
		||||
 | 
			
		||||
class TwxTreeCtrl : public wxTreeCtrl
 | 
			
		||||
{
 | 
			
		||||
  WX_DECLARE_VOIDPTR_HASH_MAP(int, XVT_IMAGE_Map);
 | 
			
		||||
	XVT_IMAGE_Map m_img;
 | 
			
		||||
  wxColour m_clrSelFore, m_clrSelBack, m_clrDisFore;
 | 
			
		||||
  int m_nFrozen;
 | 
			
		||||
@ -156,6 +159,32 @@ public:
 | 
			
		||||
  TwxTreeCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TwxTreeListCtrl : public wxTreeListCtrl
 | 
			
		||||
{
 | 
			
		||||
	XVT_IMAGE_Map m_img;
 | 
			
		||||
  wxColour m_clrSelFore, m_clrSelBack, m_clrDisFore;
 | 
			
		||||
  int m_nFrozen;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
  int img2int(XVT_IMAGE img); // Store img into internal image list
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  DECLARE_EVENT_TABLE();
 | 
			
		||||
  void OnExpanding(wxTreeEvent& e);  // Called when node is about to be expanded
 | 
			
		||||
  void OnExpanded(wxTreeEvent& e);   // Called when node has been expanded
 | 
			
		||||
  void OnCollapsed(wxTreeEvent& e);  // Called when node has been collapsed
 | 
			
		||||
  void OnSelChanged(wxTreeEvent& e); // Called when node has been selected
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  void SetNodeImages(const wxTreeItemId& id, XVT_IMAGE item_image, 
 | 
			
		||||
                     XVT_IMAGE collapsed_image, XVT_IMAGE expanded_image);
 | 
			
		||||
  void SetColors(const XVT_COLOR_COMPONENT* colors);
 | 
			
		||||
  void Suspend();
 | 
			
		||||
  void Resume();
 | 
			
		||||
  void Enable(const wxTreeItemId& id, bool on);
 | 
			
		||||
  TwxTreeListCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct TwxOutlookItem
 | 
			
		||||
{
 | 
			
		||||
  wxString m_strText;
 | 
			
		||||
@ -2635,3 +2664,496 @@ BOOLEAN xvt_prop_set_read_only(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN ro)
 | 
			
		||||
  }
 | 
			
		||||
  return pg != NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TwxTreeListCtrl
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
BEGIN_EVENT_TABLE(TwxTreeListCtrl, wxTreeListCtrl)
 | 
			
		||||
  EVT_TREE_ITEM_EXPANDING(wxID_ANY, TwxTreeListCtrl::OnExpanding)
 | 
			
		||||
  EVT_TREE_ITEM_EXPANDED (wxID_ANY, TwxTreeListCtrl::OnExpanded)
 | 
			
		||||
  EVT_TREE_ITEM_COLLAPSED(wxID_ANY, TwxTreeListCtrl::OnCollapsed)
 | 
			
		||||
  EVT_TREE_SEL_CHANGED   (wxID_ANY, TwxTreeListCtrl::OnSelChanged)
 | 
			
		||||
END_EVENT_TABLE();
 | 
			
		||||
 | 
			
		||||
int TwxTreeListCtrl::img2int(XVT_IMAGE xvt_img)
 | 
			
		||||
{
 | 
			
		||||
  int i = -1;
 | 
			
		||||
  if (xvt_img != NULL)
 | 
			
		||||
  {
 | 
			
		||||
    i = m_img[xvt_img] - 1;       // Ho memorizzato indice+1
 | 
			
		||||
    if (i < 0)                    // Immagine sconosciuta
 | 
			
		||||
    {
 | 
			
		||||
      const wxImage& img = *(wxImage*)xvt_img;
 | 
			
		||||
      wxImageList* il = GetImageList();
 | 
			
		||||
      if (il == NULL)             // Lista non ancora creata
 | 
			
		||||
      { 
 | 
			
		||||
        il = new wxImageList;
 | 
			
		||||
        il->Create(img.GetWidth(), img.GetHeight(), true, 3);
 | 
			
		||||
        AssignImageList(il);      // DON'T CALL SetImageList!
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        int old_w, old_h; il->GetSize(0, old_w, old_h); 
 | 
			
		||||
        const int new_w = img.GetWidth(), new_h = img.GetHeight();
 | 
			
		||||
        if (new_w > old_w)  // L'immagine nuova e' troppo grande?
 | 
			
		||||
        {
 | 
			
		||||
          const int old_ratio = old_w * 100 / old_h;
 | 
			
		||||
          const int new_ratio = new_w * 100 / new_h;
 | 
			
		||||
          const int old_count = il->GetImageCount();
 | 
			
		||||
          wxImageList* nil = new wxImageList;
 | 
			
		||||
          nil->Create(new_w, new_h, true, 3*old_count/2);
 | 
			
		||||
          for (int k = 0; k < old_count; k++)
 | 
			
		||||
          {
 | 
			
		||||
            wxImage old = il->GetBitmap(k).ConvertToImage();
 | 
			
		||||
            if (old_ratio == new_ratio)
 | 
			
		||||
              old.Rescale(new_w, new_h, wxIMAGE_QUALITY_HIGH);
 | 
			
		||||
            else
 | 
			
		||||
              old.Resize(wxSize(new_w, new_h), wxPoint((new_w-old_w)/2, (new_h-old_h)/2));
 | 
			
		||||
            nil->Add(old);
 | 
			
		||||
          }
 | 
			
		||||
          AssignImageList(il = nil);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (!img.HasMask())
 | 
			
		||||
      {
 | 
			
		||||
        wxImage& trans = (wxImage&)img;
 | 
			
		||||
        const int r = img.GetRed(0,0);
 | 
			
		||||
        const int g = img.GetGreen(0,0);
 | 
			
		||||
        const int b = img.GetBlue(0,0);
 | 
			
		||||
        trans.SetMask();
 | 
			
		||||
        trans.SetMaskColour(r, g, b);
 | 
			
		||||
      }
 | 
			
		||||
      const wxBitmap bmp(img);
 | 
			
		||||
      i = il->Add(bmp);
 | 
			
		||||
      m_img[xvt_img] = i+1;       // Memorizzo indice+1
 | 
			
		||||
    }
 | 
			
		||||
    if (i < 0)
 | 
			
		||||
      SORRY_BOX();   
 | 
			
		||||
  }
 | 
			
		||||
  return i;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::OnExpanding(wxTreeEvent& evt)
 | 
			
		||||
{
 | 
			
		||||
  const wxTreeItemId id = evt.GetItem();
 | 
			
		||||
  XVT_EVENT e(E_CONTROL);
 | 
			
		||||
  e.v.ctl.id = evt.GetId();
 | 
			
		||||
  e.v.ctl.ci.type = WC_TREELIST;
 | 
			
		||||
  e.v.ctl.ci.win = WINDOW(this);
 | 
			
		||||
  e.v.ctl.ci.v.treeview.node = id.m_pItem;
 | 
			
		||||
  e.v.ctl.ci.v.treeview.expanded  = TRUE;   
 | 
			
		||||
  if (GetChildrenCount(id) == 0) // Trucco perfido ...
 | 
			
		||||
    e.v.ctl.ci.v.treeview.collapsed = TRUE; // ... stato indeterminato = EXPANDING
 | 
			
		||||
  TwxWindow* win = wxStaticCast(GetParent(), TwxWindow);
 | 
			
		||||
  win->DoXvtEvent(e);
 | 
			
		||||
  if (GetChildrenCount(id) == 0) // Allora e' proprio vero ...
 | 
			
		||||
    SetItemHasChildren(id, false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::OnExpanded(wxTreeEvent& WXUNUSED(evt))
 | 
			
		||||
{ Refresh(false); } // Non dovrebbe servire ma ...
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::OnCollapsed(wxTreeEvent& WXUNUSED(evt))
 | 
			
		||||
{ Refresh(false); } // Non dovrebbe servire ma ...
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::OnSelChanged(wxTreeEvent& evt)
 | 
			
		||||
{ 
 | 
			
		||||
  if (!m_nFrozen)
 | 
			
		||||
  {
 | 
			
		||||
    Suspend();
 | 
			
		||||
    XVT_EVENT e(E_CONTROL);
 | 
			
		||||
    e.v.ctl.id = evt.GetId();
 | 
			
		||||
    e.v.ctl.ci.type = WC_TREELIST;
 | 
			
		||||
    e.v.ctl.ci.win = WINDOW(this);
 | 
			
		||||
    e.v.ctl.ci.v.treeview.node = evt.GetItem().m_pItem;
 | 
			
		||||
    e.v.ctl.ci.v.treeview.sgl_click = TRUE;
 | 
			
		||||
    TwxWindow* win = wxStaticCast(GetParent(), TwxWindow);
 | 
			
		||||
    win->DoXvtEvent(e);
 | 
			
		||||
    Resume();
 | 
			
		||||
  }
 | 
			
		||||
  Refresh(false); // Non dovrebbe servire ma ...
 | 
			
		||||
} 
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::Enable(const wxTreeItemId& id, bool on)
 | 
			
		||||
{ SetItemTextColour(id, on ? m_clrSelFore : m_clrDisFore); }
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::Suspend()
 | 
			
		||||
{ m_nFrozen++; }
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::Resume()
 | 
			
		||||
{
 | 
			
		||||
  wxASSERT(m_nFrozen > 0);
 | 
			
		||||
  if (m_nFrozen > 0)
 | 
			
		||||
    m_nFrozen--;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::SetColors(const XVT_COLOR_COMPONENT* colors)
 | 
			
		||||
{
 | 
			
		||||
  for (int i = 0; colors[i].type; i++)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_COLOR(colors[i].color, rgb);
 | 
			
		||||
    switch(colors[i].type)
 | 
			
		||||
    {
 | 
			
		||||
    case XVT_COLOR_BACKGROUND: SetOwnBackgroundColour(rgb); break;
 | 
			
		||||
    case XVT_COLOR_FOREGROUND: SetOwnForegroundColour(rgb); break;
 | 
			
		||||
    case XVT_COLOR_HIGHLIGHT : m_clrSelBack = rgb; break;
 | 
			
		||||
    case XVT_COLOR_SELECT    : m_clrSelFore = rgb; break;
 | 
			
		||||
    case XVT_COLOR_TROUGH    : m_clrDisFore = rgb; break;
 | 
			
		||||
    default                  : break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TwxTreeListCtrl::SetNodeImages(const wxTreeItemId& id, XVT_IMAGE item_image, 
 | 
			
		||||
                                    XVT_IMAGE collapsed_image, XVT_IMAGE expanded_image)
 | 
			
		||||
{
 | 
			
		||||
  const int ii = img2int(item_image);
 | 
			
		||||
  if (ii >= 0)
 | 
			
		||||
    SetItemImage(id, ii);
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    const int ic = img2int(collapsed_image);
 | 
			
		||||
    if (ic >= 0)
 | 
			
		||||
    {
 | 
			
		||||
      SetItemImage(id, ic);
 | 
			
		||||
      const int ie = img2int(expanded_image);
 | 
			
		||||
      if (ie >= 0)
 | 
			
		||||
        SetItemImage(id, ie, wxTreeItemIcon_Selected);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TwxTreeListCtrl::TwxTreeListCtrl(wxWindow *parent, wxWindowID id, 
 | 
			
		||||
                         const wxPoint& pos, const wxSize& size)
 | 
			
		||||
               : wxTreeListCtrl(parent, id, pos, size, 
 | 
			
		||||
                 wxTR_HAS_BUTTONS|wxTR_HIDE_ROOT|wxTR_ROW_LINES|wxTR_COLUMN_LINES|wxTR_SINGLE), 
 | 
			
		||||
                 m_nFrozen(0)
 | 
			
		||||
{ 
 | 
			
		||||
  AddColumn(wxEmptyString, size.x);
 | 
			
		||||
  AddRoot("Root");
 | 
			
		||||
  SetIndent(GetIndent()/2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define CAST_TREELIST(win, tv) TwxTreeListCtrl& tv = *wxStaticCast((wxObject*)win, TwxTreeListCtrl);
 | 
			
		||||
 | 
			
		||||
WINDOW xvt_treelist_create(WINDOW parent_win,
 | 
			
		||||
  RCT * rct_p, char * title, long ctl_flags,
 | 
			
		||||
  long app_data, int ctl_id, XVT_IMAGE WXUNUSED(item_image),
 | 
			
		||||
  XVT_IMAGE WXUNUSED(collapsed_image), XVT_IMAGE WXUNUSED(expanded_image),
 | 
			
		||||
  long WXUNUSED(attrs), int line_height)
 | 
			
		||||
{
 | 
			
		||||
  wxASSERT(parent_win != NULL_WIN);
 | 
			
		||||
  // La xvt_ctl_create_def accetta un array di controlli da inizializzare, 
 | 
			
		||||
  // per cui le passero' un elemento valido ed uno nullo che funga da terminatore
 | 
			
		||||
  WIN_DEF win_def[2]; memset(win_def, 0, sizeof(WIN_DEF));
 | 
			
		||||
  win_def->wtype = WC_TREELIST;
 | 
			
		||||
  if (xvt_rect_is_empty(rct_p))
 | 
			
		||||
    xvt_vobj_get_client_rect(parent_win, &win_def->rct);
 | 
			
		||||
  else
 | 
			
		||||
    win_def->rct = *rct_p;
 | 
			
		||||
  win_def->text = title;
 | 
			
		||||
  win_def->v.ctl.ctrl_id = ctl_id;
 | 
			
		||||
  win_def->v.ctl.flags = ctl_flags;
 | 
			
		||||
  WINDOW win = xvt_ctl_create_def(win_def, parent_win, app_data);
 | 
			
		||||
  
 | 
			
		||||
  if (win != NULL_WIN && line_height > 12)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    tv.SetLineSpacing(line_height);
 | 
			
		||||
  }
 | 
			
		||||
  return win;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XVT_TREEVIEW_NODE xvt_treelist_add_child_node(WINDOW win,
 | 
			
		||||
  XVT_TREEVIEW_NODE parent, XVT_TREEVIEW_NODE_TYPE type,
 | 
			
		||||
  XVT_IMAGE item_image, XVT_IMAGE collapsed_image, XVT_IMAGE expanded_image,
 | 
			
		||||
  const char* string, XVT_TREEVIEW_CALLBACK WXUNUSED(callback), const char* data)
 | 
			
		||||
{
 | 
			
		||||
  XVT_TREEVIEW_NODE node = NULL;
 | 
			
		||||
  if (win != NULL_WIN)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    TwxTreeItemData* pData = new TwxTreeItemData;
 | 
			
		||||
    pData->m_strData = data;
 | 
			
		||||
    wxTreeItemId pa(parent);
 | 
			
		||||
    if (!pa.IsOk())
 | 
			
		||||
      pa = tv.GetRootItem();
 | 
			
		||||
 | 
			
		||||
    wxStringTokenizer tok(string, "\t", wxTOKEN_RET_EMPTY);
 | 
			
		||||
 | 
			
		||||
    wxTreeItemId id = tv.AppendItem(pa, tok.GetNextToken(), -1, -1, pData);
 | 
			
		||||
    if (id.IsOk())
 | 
			
		||||
    {
 | 
			
		||||
      const int nColumns = tv.GetColumnCount();
 | 
			
		||||
      for (int c = 1; c < nColumns && tok.HasMoreTokens(); c++)
 | 
			
		||||
        tv.SetItemText(id, c, tok.GetNextToken());
 | 
			
		||||
      tv.SetItemHasChildren(pa, true);
 | 
			
		||||
      tv.SetItemHasChildren(id, type == XVT_TREEVIEW_NODE_NONTERMINAL);
 | 
			
		||||
      tv.SetNodeImages(id, item_image, collapsed_image, expanded_image);
 | 
			
		||||
      tv.SetItemFont(id, tv.GetFont());
 | 
			
		||||
      node = id.m_pItem;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return node;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XVT_TREEVIEW_NODE xvt_treelist_get_child_node(WINDOW win, XVT_TREEVIEW_NODE parent_node, 
 | 
			
		||||
                                              int position)
 | 
			
		||||
{
 | 
			
		||||
  XVT_TREEVIEW_NODE child_node = NULL;
 | 
			
		||||
  if (win != NULL_WIN && position >= 0)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    wxTreeItemId parent(parent_node);
 | 
			
		||||
    if (!parent.IsOk())
 | 
			
		||||
      parent = tv.GetRootItem();
 | 
			
		||||
 | 
			
		||||
    if (parent.IsOk() && position < (int)tv.GetChildrenCount(parent))
 | 
			
		||||
    {
 | 
			
		||||
      wxTreeItemIdValue cookie;
 | 
			
		||||
      wxTreeItemId id;
 | 
			
		||||
      int i = -1;
 | 
			
		||||
      for (id = tv.GetFirstChild(parent, cookie), i = -1; 
 | 
			
		||||
           i < position && id.IsOk(); id = tv.GetNextChild(parent, cookie), i++);
 | 
			
		||||
      child_node = id.m_pItem;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return child_node;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* xvt_treelist_get_node_data(WINDOW win, XVT_TREEVIEW_NODE node)
 | 
			
		||||
{
 | 
			
		||||
  const char* data = NULL;
 | 
			
		||||
  if (win != NULL_WIN && node != NULL)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    const wxTreeItemId id(node);
 | 
			
		||||
    TwxTreeItemData* pData = (TwxTreeItemData*)tv.GetItemData(id);
 | 
			
		||||
    if (pData != NULL)
 | 
			
		||||
      data = (const char*)pData->m_strData;
 | 
			
		||||
  }
 | 
			
		||||
  return data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xvt_treelist_destroy_node(WINDOW win, XVT_TREEVIEW_NODE node)
 | 
			
		||||
{ 
 | 
			
		||||
  if (win != NULL_WIN && node != NULL)
 | 
			
		||||
  {  
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    wxTreeItemId id(node);
 | 
			
		||||
    tv.Delete(id);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BOOLEAN xvt_treelist_enable_node(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN on)
 | 
			
		||||
{
 | 
			
		||||
  BOOLEAN ok = (win != NULL_WIN) && (node != NULL);
 | 
			
		||||
  if (ok)
 | 
			
		||||
  {  
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    wxTreeItemId id(node);
 | 
			
		||||
    tv.Enable(id, on != FALSE);
 | 
			
		||||
  }
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BOOLEAN xvt_treelist_expand_node(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN recurse)
 | 
			
		||||
{
 | 
			
		||||
  BOOLEAN ok = (win != NULL_WIN) && (node != NULL);
 | 
			
		||||
  if (ok)
 | 
			
		||||
  {  
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    tv.Suspend();
 | 
			
		||||
    const wxTreeItemId id(node);
 | 
			
		||||
    if (recurse)
 | 
			
		||||
      tv.ExpandAll(id);
 | 
			
		||||
    else
 | 
			
		||||
      tv.Expand(id);
 | 
			
		||||
    tv.Resume();
 | 
			
		||||
  }
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XVT_TREEVIEW_NODE xvt_treelist_get_root_node(WINDOW win)
 | 
			
		||||
{
 | 
			
		||||
  XVT_TREEVIEW_NODE pRoot = NULL;
 | 
			
		||||
  if (win != NULL_WIN)
 | 
			
		||||
  {  
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    const wxTreeItemId id = tv.GetRootItem();
 | 
			
		||||
    pRoot = id.m_pItem;
 | 
			
		||||
  }
 | 
			
		||||
  return pRoot;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XVT_TREEVIEW_NODE xvt_treelist_get_selected_node(WINDOW win)
 | 
			
		||||
{
 | 
			
		||||
  CAST_TREELIST(win, tv);
 | 
			
		||||
  const wxTreeItemId id = tv.GetSelection();
 | 
			
		||||
  return id.m_pItem;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BOOLEAN xvt_treelist_remove_child_node(WINDOW win, XVT_TREEVIEW_NODE node)
 | 
			
		||||
{
 | 
			
		||||
  BOOLEAN ok = (win != NULL_WIN) && (node != NULL);
 | 
			
		||||
  if (ok)
 | 
			
		||||
  {  
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    const wxTreeItemId id(node);
 | 
			
		||||
    if (id == tv.GetRootItem())
 | 
			
		||||
      tv.DeleteChildren(id);
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      tv.Suspend();
 | 
			
		||||
      tv.Delete(id);
 | 
			
		||||
      tv.Resume();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BOOLEAN xvt_treelist_remove_node_children(WINDOW win, XVT_TREEVIEW_NODE node)
 | 
			
		||||
{
 | 
			
		||||
  BOOLEAN ok = FALSE;
 | 
			
		||||
  if (win != NULL_WIN)
 | 
			
		||||
  {  
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    tv.Suspend();
 | 
			
		||||
    wxTreeItemId id(node);
 | 
			
		||||
    if (!id.IsOk()) 
 | 
			
		||||
      id = tv.GetRootItem();
 | 
			
		||||
    tv.DeleteChildren(id);
 | 
			
		||||
    tv.Resume();
 | 
			
		||||
    ok = TRUE;
 | 
			
		||||
  }
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xvt_treelist_resume(WINDOW win)
 | 
			
		||||
{
 | 
			
		||||
  CAST_TREELIST(win, tv);
 | 
			
		||||
  tv.Resume();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xvt_treelist_select_node(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN sel)
 | 
			
		||||
{
 | 
			
		||||
  if (win != NULL_WIN && node != NULL)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    const wxTreeItemId id(node);
 | 
			
		||||
    if (sel)
 | 
			
		||||
    {
 | 
			
		||||
      tv.Suspend();
 | 
			
		||||
      tv.SelectItem(id, id, true);
 | 
			
		||||
      tv.EnsureVisible(id);
 | 
			
		||||
      tv.Resume();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
      tv.UnselectAll();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xvt_treelist_set_node_images(WINDOW win, XVT_TREEVIEW_NODE node, XVT_IMAGE item_image, 
 | 
			
		||||
                                  XVT_IMAGE collapsed_image, XVT_IMAGE expanded_image)
 | 
			
		||||
{
 | 
			
		||||
  if (win != NULL_WIN && node != NULL)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    const wxTreeItemId id(node);
 | 
			
		||||
    tv.SetNodeImages(id, item_image, collapsed_image, expanded_image);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xvt_treelist_set_node_string(WINDOW win, XVT_TREEVIEW_NODE node, const char* text)
 | 
			
		||||
{
 | 
			
		||||
  if (win != NULL_WIN)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    const int cc = tv.GetColumnCount();
 | 
			
		||||
    wxStringTokenizer tok(text, "\t", wxTOKEN_RET_EMPTY);
 | 
			
		||||
    if (node != NULL)
 | 
			
		||||
    {
 | 
			
		||||
      const wxTreeItemId id(node);
 | 
			
		||||
      for (int c = 0; c < cc && tok.HasMoreTokens(); c++)
 | 
			
		||||
        tv.SetItemText(id, c, tok.GetNextToken());
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      for (int c = 0; tok.HasMoreTokens(); c++)
 | 
			
		||||
      {
 | 
			
		||||
        wxString str = tok.GetNextToken();
 | 
			
		||||
        int width = 0;
 | 
			
		||||
        bool bRightAlign = false;
 | 
			
		||||
        const int a = str.Find('@');
 | 
			
		||||
        if (a > 0)
 | 
			
		||||
        {
 | 
			
		||||
          width = 10*wxAtoi(str.Mid(a+1));
 | 
			
		||||
          bRightAlign = str.Find('R', true) > a;
 | 
			
		||||
          str.Truncate(a);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
          width = 10*str.Len();
 | 
			
		||||
        if (c >= cc)
 | 
			
		||||
          tv.AddColumn(str, width, bRightAlign ? wxALIGN_RIGHT : wxALIGN_LEFT);
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          tv.SetColumnText(c, str);
 | 
			
		||||
          const int oldw = tv.GetColumnWidth(c);
 | 
			
		||||
          if (width < 2*oldw/3 || width > 3*oldw/2)
 | 
			
		||||
            tv.SetColumnWidth(c, width);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xvt_treelist_suspend(WINDOW win)
 | 
			
		||||
{
 | 
			
		||||
  CAST_TREELIST(win, tv);
 | 
			
		||||
  tv.Suspend();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void  xvt_treelist_set_node_bold(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN bold)
 | 
			
		||||
{
 | 
			
		||||
  if (win != NULL_WIN && node != NULL)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    const wxTreeItemId id(node);
 | 
			
		||||
    tv.SetItemBold(id, bold != FALSE);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static XVT_TREEVIEW_NODE FindTreeListNodeString(wxTreeListCtrl& tv, const wxTreeItemId& parent, const char* text)
 | 
			
		||||
{
 | 
			
		||||
  if (parent.IsOk())
 | 
			
		||||
  {
 | 
			
		||||
    TwxTreeItemData* pData = (TwxTreeItemData*)tv.GetItemData(parent);
 | 
			
		||||
    if (pData != NULL && pData->m_strData == text)
 | 
			
		||||
      return parent.m_pItem;
 | 
			
		||||
    
 | 
			
		||||
    wxTreeItemIdValue cookie;
 | 
			
		||||
    for (wxTreeItemId id = tv.GetFirstChild(parent, cookie); id.IsOk(); 
 | 
			
		||||
         id = tv.GetNextChild(parent, cookie))
 | 
			
		||||
    {
 | 
			
		||||
      XVT_TREEVIEW_NODE node = FindTreeListNodeString(tv, id, text);
 | 
			
		||||
      if (node != NULL)
 | 
			
		||||
        return node;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XVT_TREEVIEW_NODE xvt_treelist_find_node_string(WINDOW win, const char* text)
 | 
			
		||||
{
 | 
			
		||||
  XVT_TREEVIEW_NODE node = NULL;
 | 
			
		||||
  if (win != NULL_WIN && text && *text)
 | 
			
		||||
  {
 | 
			
		||||
    CAST_TREELIST(win, tv);
 | 
			
		||||
    node = FindTreeListNodeString(tv, tv.GetSelection(), text);
 | 
			
		||||
    if (node == NULL)
 | 
			
		||||
      node = FindTreeListNodeString(tv, tv.GetRootItem(), text);
 | 
			
		||||
  }
 | 
			
		||||
  return node;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user