treelistctrl.h

来自「Wxpython Implemented on Windows CE, Sou」· C头文件 代码 · 共 557 行 · 第 1/2 页

H
557
字号
/////////////////////////////////////////////////////////////////////////////
// Name:        treelistctrl.h
// Purpose:     wxTreeListCtrl class
// Author:      Robert Roebling
// Modified by: Alberto Griggio, 2002
// Created:     01/02/97
// RCS-ID:      $Id: treelistctrl.h,v 1.7 2005/09/23 12:56:44 MR Exp $
// Copyright:   (c) Robert Roebling, Julian Smart, Alberto Griggio,
//              Vadim Zeitlin, Otto Wyss
// Licence:     wxWindows license
/////////////////////////////////////////////////////////////////////////////


#ifndef TREELISTCTRL_H
#define TREELISTCTRL_H

#include <wx/treectrl.h>
#include <wx/control.h>
#include <wx/pen.h>
#include <wx/listctrl.h> // for wxListEvent

#ifdef GIZMOISDLL
#define GIZMODLLEXPORT WXDLLEXPORT
#else
#define GIZMODLLEXPORT
#endif


class GIZMODLLEXPORT wxTreeListItem;
class GIZMODLLEXPORT wxTreeListHeaderWindow;
class GIZMODLLEXPORT wxTreeListMainWindow;


// Using this typedef removes an ambiguity when calling Remove()
#ifdef __WXMSW__
#if !wxCHECK_VERSION(2, 5, 0)
typedef long wxTreeItemIdValue;
#else
typedef void *wxTreeItemIdValue;
#endif
#endif


#define wxTR_DONT_ADJUST_MAC    0x0100          // Don't adjust the style for the Mac

//-----------------------------------------------------------------------------
// wxTreeListColumnAttrs
//-----------------------------------------------------------------------------

enum wxTreeListColumnAlign {
    wxTL_ALIGN_LEFT,
    wxTL_ALIGN_RIGHT,
    wxTL_ALIGN_CENTER
};


class GIZMODLLEXPORT wxTreeListColumnInfo: public wxObject {
public:
    enum { DEFAULT_COL_WIDTH = 100 };

    wxTreeListColumnInfo(const wxString &text = wxT(""),
                         int image = -1,
                         size_t width = DEFAULT_COL_WIDTH,
                         bool shown = true,
                         wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT)
    {
        m_image = image;
        m_selected_image = -1;
        m_text = text;
        m_width = width;
        m_shown = shown;
        m_alignment = alignment;
    }

    wxTreeListColumnInfo(const wxTreeListColumnInfo& other)
    {
        m_image = other.m_image;
        m_selected_image = other.m_selected_image;
        m_text = other.m_text;
        m_width = other.m_width;
        m_shown = other.m_shown;
        m_alignment = other.m_alignment;
    }

    ~wxTreeListColumnInfo() {}

    // getters
    bool GetShown() const { return m_shown; }
    wxTreeListColumnAlign GetAlignment() const { return m_alignment; }
    wxString GetText() const { return m_text; }
    int GetImage() const { return m_image; }
    int GetSelectedImage() const { return m_selected_image; }
    size_t GetWidth() const { return m_width; }

    // setters
    wxTreeListColumnInfo& SetShown(bool shown)
    { m_shown = shown; return *this; }

    wxTreeListColumnInfo& SetAlignment(wxTreeListColumnAlign alignment)
    { m_alignment = alignment; return *this; }

    wxTreeListColumnInfo& SetText(const wxString& text)
    { m_text = text; return *this; }

    wxTreeListColumnInfo& SetImage(int image)
    { m_image = image; return *this; }

    wxTreeListColumnInfo& SetSelectedImage(int image)
    { m_selected_image = image; return *this; }

    wxTreeListColumnInfo& SetWidth(size_t with)
    { m_width = with; return *this; }

private:
    bool m_shown;
    wxTreeListColumnAlign m_alignment;
    wxString m_text;
    int m_image;
    int m_selected_image;
    size_t m_width;
};

//----------------------------------------------------------------------------
// wxTreeListCtrl - the multicolumn tree control
//----------------------------------------------------------------------------

// flags for FindItem
const int wxTL_SEARCH_VISIBLE = 0x0000;
const int wxTL_SEARCH_LEVEL   = 0x0001;
const int wxTL_SEARCH_FULL    = 0x0002;
const int wxTL_SEARCH_PARTIAL = 0x0010;
const int wxTL_SEARCH_NOCASE  = 0x0020;

// additional flag for HitTest
const int wxTREE_HITTEST_ONITEMCOLUMN = 0x2000;
extern GIZMODLLEXPORT const wxChar* wxTreeListCtrlNameStr;


class GIZMODLLEXPORT wxTreeListCtrl : public wxControl
{
public:
    // creation
    // --------
    wxTreeListCtrl()
        : m_header_win(0), m_main_win(0), m_headerHeight(0)
    {}

    wxTreeListCtrl(wxWindow *parent, wxWindowID id = -1,
               const wxPoint& pos = wxDefaultPosition,
               const wxSize& size = wxDefaultSize,
               long style = wxTR_DEFAULT_STYLE,
               const wxValidator &validator = wxDefaultValidator,
               const wxString& name = wxTreeListCtrlNameStr )
        : m_header_win(0), m_main_win(0), m_headerHeight(0)
    {
        Create(parent, id, pos, size, style, validator, name);
    }

    virtual ~wxTreeListCtrl() {}

    bool Create(wxWindow *parent, wxWindowID id = -1,
                const wxPoint& pos = wxDefaultPosition,
                const wxSize& size = wxDefaultSize,
                long style = wxTR_DEFAULT_STYLE,
                const wxValidator &validator = wxDefaultValidator,
                const wxString& name = wxTreeListCtrlNameStr );

    void Refresh(bool erase=TRUE, const wxRect* rect=NULL);
    void SetFocus();
    // accessors
    // ---------

    // get the total number of items in the control
    size_t GetCount() const;

    // indent is the number of pixels the children are indented relative to
    // the parents position. SetIndent() also redraws the control
    // immediately.
    unsigned int GetIndent() const;
    void SetIndent(unsigned int indent);

    // line spacing is the space above and below the text on each line
    unsigned int GetLineSpacing() const;
    void SetLineSpacing(unsigned int spacing);

    // image list: these functions allow to associate an image list with
    // the control and retrieve it. Note that when assigned with
    // SetImageList, the control does _not_ delete
    // the associated image list when it's deleted in order to allow image
    // lists to be shared between different controls. If you use
    // AssignImageList, the control _does_ delete the image list.
    //
    // The normal image list is for the icons which correspond to the
    // normal tree item state (whether it is selected or not).
    // Additionally, the application might choose to show a state icon
    // which corresponds to an app-defined item state (for example,
    // checked/unchecked) which are taken from the state image list.
    wxImageList *GetImageList() const;
    wxImageList *GetStateImageList() const;
    wxImageList *GetButtonsImageList() const;

    void SetImageList(wxImageList *imageList);
    void SetStateImageList(wxImageList *imageList);
    void SetButtonsImageList(wxImageList *imageList);
    void AssignImageList(wxImageList *imageList);
    void AssignStateImageList(wxImageList *imageList);
    void AssignButtonsImageList(wxImageList *imageList);


    // Functions to work with tree list ctrl columns

    // adds a column
    void AddColumn(const wxString& text)
        { AddColumn(wxTreeListColumnInfo(text)); }
    void AddColumn(const wxString& text,
                   size_t width,
                   wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT)
        { AddColumn(wxTreeListColumnInfo(text,
                                         -1,
                                         width,
                                         true,
                                         alignment)); }
    void AddColumn(const wxTreeListColumnInfo& col);

    // inserts a column before the given one
    void InsertColumn(size_t before, const wxString& text)
    { InsertColumn(before, wxTreeListColumnInfo(text)); }
    void InsertColumn(size_t before, const wxTreeListColumnInfo& col);

    // deletes the given column - does not delete the corresponding column
    // of each item
    void RemoveColumn(size_t column);

    // returns the number of columns in the ctrl
    size_t GetColumnCount() const;

    void SetColumnWidth(size_t column, size_t width);
    int GetColumnWidth(size_t column) const;

    // tells which column is the "main" one, i.e. the "threaded" one
    void SetMainColumn(size_t column);
    size_t GetMainColumn() const;

    void SetColumnText(size_t column, const wxString& text);
    wxString GetColumnText(size_t column) const;

    void SetColumn(size_t column, const wxTreeListColumnInfo& info);
    wxTreeListColumnInfo& GetColumn(size_t column);
    const wxTreeListColumnInfo& GetColumn(size_t column) const;

    // other column-related methods
    void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
    wxTreeListColumnAlign GetColumnAlignment(size_t column) const;

    void SetColumnImage(size_t column, int image);
    int GetColumnImage(size_t column) const;

    void ShowColumn(size_t column, bool shown);
    bool IsColumnShown(size_t column) const;

    // Functions to work with tree list ctrl items.

    // accessors
    // ---------

    // retrieve item's label (of the main column)
    wxString GetItemText(const wxTreeItemId& item) const
        { return GetItemText(item, GetMainColumn()); }
    // retrieves item's label of the given column
    wxString GetItemText(const wxTreeItemId& item, size_t column) const;

    // get one of the images associated with the item (normal by default)
    int GetItemImage(const wxTreeItemId& item,
                     wxTreeItemIcon which = wxTreeItemIcon_Normal) const
    { return GetItemImage(item, GetMainColumn(), which); }
    int GetItemImage(const wxTreeItemId& item, size_t column,
                     wxTreeItemIcon which = wxTreeItemIcon_Normal) const;

    // get the data associated with the item

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?