~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/forms/winforms/wf_grttreeview.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; version 2 of the
 
7
 * License.
 
8
 * 
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
 * GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
// included in wbpublic.wr because of dependency on TreeModel
 
21
 
 
22
#ifndef _WF_GRTTREEVIEW_H_
 
23
#define _WF_GRTTREEVIEW_H_
 
24
 
 
25
#include "grt/tree_model.h"
 
26
 
 
27
#include "mforms/grttreeview.h"
 
28
 
 
29
#include "wf_view.h"
 
30
 
 
31
using namespace std;
 
32
 
 
33
using namespace System;
 
34
using namespace Windows::Forms;
 
35
using namespace System::Collections::Generic;
 
36
 
 
37
using namespace Aga::Controls::Tree;
 
38
using namespace Aga::Controls::Tree::NodeControls;
 
39
 
 
40
namespace MySQL {
 
41
  namespace Forms {
 
42
 
 
43
    private ref struct ColumnEntry
 
44
    {
 
45
      NodeControl^ nodeControl;
 
46
      int column;
 
47
      bool editable;
 
48
      bool isIcon;
 
49
 
 
50
      ColumnEntry(NodeControl^ control, int column, bool editable, bool isIcon)
 
51
      {
 
52
        this->nodeControl= control;
 
53
        this->column= column;
 
54
        this->editable= editable;
 
55
        this->isIcon= isIcon;
 
56
      }
 
57
    };
 
58
 
 
59
    /**
 
60
     * Helper class to forward double clicks on the node icon.
 
61
     */
 
62
    private ref class SwitchNodeIcon : public NodeIcon
 
63
    {
 
64
    public:
 
65
      virtual void MouseDoubleClick(TreeNodeAdvMouseEventArgs^ args) override;
 
66
    };
 
67
 
 
68
    /**
 
69
     * Helper class to show our own expand icons.
 
70
     */
 
71
    private ref class TriangleNodeControl : public NodeControl
 
72
    {
 
73
    private:
 
74
      System::Drawing::Bitmap^ _expanded_icon;
 
75
      System::Drawing::Bitmap^ _collapsed_icon;
 
76
      System::Drawing::Size _size; 
 
77
    public:
 
78
      TriangleNodeControl();
 
79
 
 
80
      virtual System::Drawing::Size MeasureSize(TreeNodeAdv^ node, DrawContext context) override;
 
81
      virtual void Draw(TreeNodeAdv^ node, DrawContext context) override;
 
82
      virtual void MouseDown(TreeNodeAdvMouseEventArgs^ args) override;
 
83
      virtual void MouseDoubleClick(TreeNodeAdvMouseEventArgs^ args) override;
 
84
    };
 
85
 
 
86
    /**
 
87
     * Helper class to forward double clicks for non-editable node texts.
 
88
     */
 
89
    private ref class SwitchNodeText : public NodeTextBox
 
90
    {
 
91
    protected:
 
92
      virtual void OnDrawText(DrawEventArgs^ args) override;
 
93
    public:
 
94
      virtual void MouseDoubleClick(TreeNodeAdvMouseEventArgs^ args) override;
 
95
    };
 
96
 
 
97
    /**
 
98
     * Wrapper for a native .NET treeview control with GRT bec::TreeModel data.
 
99
     * We use the TreeViewAdv control as we need multicolumn support.
 
100
     */
 
101
    public ref class GRTTreeViewImpl : public ViewImpl
 
102
    {
 
103
    private:
 
104
      MySQL::Grt::TreeModel^ _tree_model;
 
105
      MySQL::Grt::SimpleGrtTreeModel^ _model;
 
106
      List<ColumnEntry^> _columns;
 
107
 
 
108
      void add_node_control(NodeControl^ control, int column, bool editable, bool isIcon);
 
109
 
 
110
      // Event handlers.
 
111
      static void SelectionChanged(System::Object^ sender, EventArgs^ e);
 
112
      static void OnMouseDown(System::Object^ sender, MouseEventArgs^ e);
 
113
 
 
114
    protected:
 
115
      static bool create(::mforms::GRTTreeView *self, mforms::TreeOptions options);
 
116
 
 
117
      static void set_model(::mforms::GRTTreeView* self, bec::TreeModel* model);
 
118
 
 
119
      static int add_column(::mforms::GRTTreeView *self, ::mforms::GRTTreeColumnType type, int model_column, const std::string &title);
 
120
      static int add_column_editable(::mforms::GRTTreeView *self, ::mforms::GRTTreeColumnType type, int model_column, const std::string &title);
 
121
 
 
122
      static void refresh(mforms::GRTTreeView* self, const bec::NodeId& node);
 
123
      static void set_column_width(mforms::GRTTreeView* self, int column, int width);
 
124
      static bool get_selected_node(mforms::GRTTreeView* self, bec::NodeId& node);
 
125
      static int get_selection(mforms::GRTTreeView* self, std::vector<bec::NodeId>& nodes);
 
126
      static void set_expanded(mforms::GRTTreeView* self, const bec::NodeId& node, bool expanded);
 
127
      static void enable_asynch_loading(mforms::GRTTreeView* self, bool enabled);
 
128
 
 
129
      static void set_allow_multi_selection(mforms::GRTTreeView *self, bool flag);
 
130
      static void row_count_changed(mforms::GRTTreeView *self, const bec::NodeId& node, int old_count);
 
131
 
 
132
      void set_model(bec::TreeModel*);
 
133
    public:
 
134
      GRTTreeViewImpl(::mforms::GRTTreeView *self);
 
135
      ~GRTTreeViewImpl();
 
136
 
 
137
      int add_column(::mforms::GRTTreeColumnType type, int model_column, String ^name, bool editable);
 
138
 
 
139
      static void init(Manager ^mgr)
 
140
      {
 
141
        ::mforms::ControlFactory *f= ::mforms::ControlFactory::get_instance();
 
142
 
 
143
        DEF_CALLBACK2(bool, ::mforms::GRTTreeView*, mforms::TreeOptions, mgr, f->_grttreeview_impl, GRTTreeViewImpl, create);
 
144
        DEF_CALLBACK2(void, ::mforms::GRTTreeView*, bec::TreeModel*, mgr, f->_grttreeview_impl, GRTTreeViewImpl, set_model);
 
145
        DEF_CALLBACK4(int, ::mforms::GRTTreeView*, ::mforms::GRTTreeColumnType, int, const std::string&, mgr, f->_grttreeview_impl, GRTTreeViewImpl, add_column);
 
146
        DEF_CALLBACK4(int, ::mforms::GRTTreeView*, ::mforms::GRTTreeColumnType, int, const std::string&, mgr, f->_grttreeview_impl, GRTTreeViewImpl, add_column_editable);
 
147
        DEF_CALLBACK2(void, ::mforms::GRTTreeView*, const bec::NodeId &, mgr, f->_grttreeview_impl, GRTTreeViewImpl, refresh);
 
148
        DEF_CALLBACK3(void, ::mforms::GRTTreeView*, int, int, mgr, f->_grttreeview_impl, GRTTreeViewImpl, set_column_width);
 
149
        DEF_CALLBACK2(bool, ::mforms::GRTTreeView*, bec::NodeId&, mgr, f->_grttreeview_impl, GRTTreeViewImpl, get_selected_node);
 
150
        DEF_CALLBACK2(int, ::mforms::GRTTreeView*, std::vector<bec::NodeId>&, mgr, f->_grttreeview_impl, GRTTreeViewImpl, get_selection);
 
151
        DEF_CALLBACK2(void, ::mforms::GRTTreeView*, bool, mgr, f->_grttreeview_impl, GRTTreeViewImpl, set_allow_multi_selection);
 
152
        DEF_CALLBACK3(void, ::mforms::GRTTreeView*, const bec::NodeId&, int, mgr, f->_grttreeview_impl, GRTTreeViewImpl, row_count_changed);
 
153
        DEF_CALLBACK3(void, ::mforms::GRTTreeView*, const bec::NodeId&, bool, mgr, f->_grttreeview_impl, GRTTreeViewImpl, set_expanded);
 
154
        DEF_CALLBACK2(void, ::mforms::GRTTreeView*, bool, mgr, f->_grttreeview_impl, GRTTreeViewImpl, enable_asynch_loading);
 
155
      }
 
156
    };
 
157
  }
 
158
}
 
159
 
 
160
#endif // _WF_GRTTREEVIEW_H_
 
 
b'\\ No newline at end of file'