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

« back to all changes in this revision

Viewing changes to library/forms/winforms/wf_box.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) 2008, 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
#ifndef _WF_BOX_H_
 
21
#define _WF_BOX_H_
 
22
 
 
23
 
 
24
#include "mforms/box.h"
 
25
 
 
26
#include "wf_view.h"
 
27
 
 
28
using namespace System;
 
29
using namespace System::Windows::Forms;
 
30
using namespace System::Windows::Forms::Layout;
 
31
 
 
32
namespace MySQL {
 
33
  namespace Forms {
 
34
 
 
35
    ref class Box;
 
36
 
 
37
    public ref class GtkBoxLayout abstract : public LayoutEngine
 
38
    {
 
39
    public:
 
40
      virtual System:: Drawing::Size GetPreferredSize(Box^ container, System::Drawing::Size proposedSize) = 0;
 
41
    };
 
42
 
 
43
    // Implements an extended flow layout behavior which mimics the horizontal GTK.box layout.
 
44
    public ref class HorizontalGtkBoxLayout : public GtkBoxLayout
 
45
    {
 
46
    public:
 
47
      System::Drawing::Size ComputeLayout(Box^ box, System::Drawing::Size proposedSize, bool resizeChildren);
 
48
      virtual bool Layout(Object^ container, LayoutEventArgs^ arguments) override;
 
49
      virtual System::Drawing::Size GetPreferredSize(Box^ container, System::Drawing::Size proposedSize) override;
 
50
    };
 
51
 
 
52
    // Implements an extended flow layout behavior which mimics the vertical GTK.box layout.
 
53
    public ref class VerticalGtkBoxLayout : public GtkBoxLayout
 
54
    {
 
55
    public:
 
56
      System::Drawing::Size ComputeLayout(Box^ box, System::Drawing::Size proposedSize, bool resizeChildren);
 
57
      virtual bool Layout(Object^ container, LayoutEventArgs^ arguments) override;
 
58
      virtual System::Drawing::Size GetPreferredSize(Box^ container, System::Drawing::Size proposedSize) override;
 
59
    };
 
60
 
 
61
    // Implements a GTK.box like control.
 
62
    public ref class Box : public Panel
 
63
    {
 
64
    private:
 
65
      Dictionary<Control^, bool> expandInfo;
 
66
      Dictionary<Control^, bool> fillInfo;
 
67
 
 
68
      GtkBoxLayout^ layoutEngine;
 
69
      bool horizontal;
 
70
      bool homogeneous;
 
71
      int spacing;
 
72
      System::Drawing::Size preferredSize;
 
73
    public:
 
74
      Box()
 
75
      {
 
76
        horizontal= false;
 
77
        homogeneous= false;
 
78
        spacing= 0;
 
79
        preferredSize= System::Drawing::Size(0, 0);
 
80
      }
 
81
 
 
82
      bool GetControlExpands(Control ^ctl)
 
83
      {
 
84
        return expandInfo[ctl];
 
85
      }
 
86
 
 
87
      bool GetControlFills(Control ^ctl)
 
88
      {
 
89
        return fillInfo[ctl];
 
90
      }
 
91
 
 
92
      virtual System::Drawing::Size GetPreferredSize(System::Drawing::Size proposedSize) override;
 
93
 
 
94
      void Add(Control ^ctl, bool expands, bool fills)
 
95
      {
 
96
        ViewImpl::set_layout_dirty(this, true);
 
97
        expandInfo[ctl]= expands;
 
98
        fillInfo[ctl]= fills;
 
99
        Controls->Add(ctl);
 
100
      }
 
101
 
 
102
      void Remove(Control ^ctl)
 
103
      {
 
104
        expandInfo.Remove(ctl);
 
105
        fillInfo.Remove(ctl);
 
106
        Controls->Remove(ctl);
 
107
      }
 
108
 
 
109
      virtual property Windows::Forms::Layout::LayoutEngine^ LayoutEngine
 
110
      {
 
111
        Windows::Forms::Layout::LayoutEngine^ get() override
 
112
        {
 
113
          if (layoutEngine == nullptr)
 
114
          {
 
115
            if (horizontal)
 
116
              layoutEngine = gcnew HorizontalGtkBoxLayout();
 
117
            else
 
118
              layoutEngine = gcnew VerticalGtkBoxLayout();
 
119
          }
 
120
          return layoutEngine;
 
121
        }
 
122
      }
 
123
 
 
124
      virtual property bool Homogeneous
 
125
      {
 
126
        bool get()
 
127
        {
 
128
          return homogeneous;
 
129
        }
 
130
 
 
131
        void set(bool value)
 
132
        {
 
133
          if (homogeneous != value)
 
134
          {
 
135
            ViewImpl::set_layout_dirty(this, true);
 
136
            homogeneous= value;
 
137
            Refresh();
 
138
          }
 
139
        }
 
140
 
 
141
      }
 
142
 
 
143
      virtual property int Spacing
 
144
      {
 
145
        int get()
 
146
        {
 
147
          return spacing;
 
148
        }
 
149
 
 
150
        void set(int value)
 
151
        {
 
152
          if (spacing != value)
 
153
          {
 
154
            ViewImpl::set_layout_dirty(this, true);
 
155
            spacing= value;
 
156
            Refresh();
 
157
          }
 
158
        }
 
159
 
 
160
      }
 
161
 
 
162
      virtual property bool Horizontal
 
163
      {
 
164
        bool get() 
 
165
        { 
 
166
          return horizontal; 
 
167
        }
 
168
 
 
169
        void set(bool value)
 
170
        {
 
171
          if (horizontal != value)
 
172
          {
 
173
            horizontal= value;
 
174
            layoutEngine= nullptr;
 
175
            ViewImpl::set_layout_dirty(this, true);
 
176
            Refresh();
 
177
          }
 
178
        }
 
179
      }
 
180
    };
 
181
 
 
182
    // Implements a wrapper class that connects the backend's box class with a .NET box control.
 
183
    public ref class BoxImpl : public ViewImpl
 
184
    {
 
185
    protected:
 
186
      static bool create(::mforms::Box *self, bool horizontal);
 
187
      static void add(mforms::Box *self, mforms::View *child, bool expand, bool fill);
 
188
      static void add_end(mforms::Box *self, mforms::View *child, bool expand, bool fill);
 
189
      static void remove(mforms::Box *self, mforms::View *child);
 
190
      static void set_spacing(mforms::Box *self, int space);
 
191
      static void set_homogeneous(mforms::Box *self, bool value);
 
192
    public:
 
193
      BoxImpl(::mforms::View *view)
 
194
        : ViewImpl(view)
 
195
      {
 
196
      }
 
197
      void add(Windows::Forms::Control ^control, bool expand, bool fill);
 
198
      void add_end(Windows::Forms::Control ^control, bool expand, bool fill);
 
199
      void remove(Windows::Forms::Control ^control);
 
200
 
 
201
      void set_homogeneous(bool flag);
 
202
      void set_spacing(int space);
 
203
 
 
204
      static void init(Manager ^mgr)
 
205
      {
 
206
        ::mforms::ControlFactory *f= ::mforms::ControlFactory::get_instance();
 
207
 
 
208
        DEF_CALLBACK2(bool, ::mforms::Box*, bool, mgr, f->_box_impl, BoxImpl, create);
 
209
        DEF_CALLBACK4(void, ::mforms::Box*, ::mforms::View*, bool, bool, mgr, f->_box_impl, BoxImpl, add);
 
210
        DEF_CALLBACK4(void, ::mforms::Box*, ::mforms::View*, bool, bool, mgr, f->_box_impl, BoxImpl, add_end);
 
211
        DEF_CALLBACK2(void, ::mforms::Box*, ::mforms::View*, mgr, f->_box_impl, BoxImpl, remove);
 
212
        DEF_CALLBACK2(void, ::mforms::Box*, int, mgr, f->_box_impl, BoxImpl, set_spacing);
 
213
        DEF_CALLBACK2(void, ::mforms::Box*, bool, mgr, f->_box_impl, BoxImpl, set_homogeneous);
 
214
      }
 
215
    };
 
216
 
 
217
  };
 
218
};
 
219
 
 
220
#endif