2
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
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
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.
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
24
#include "mforms/box.h"
28
using namespace System;
29
using namespace System::Windows::Forms;
30
using namespace System::Windows::Forms::Layout;
37
public ref class GtkBoxLayout abstract : public LayoutEngine
40
virtual System:: Drawing::Size GetPreferredSize(Box^ container, System::Drawing::Size proposedSize) = 0;
43
// Implements an extended flow layout behavior which mimics the horizontal GTK.box layout.
44
public ref class HorizontalGtkBoxLayout : public GtkBoxLayout
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;
52
// Implements an extended flow layout behavior which mimics the vertical GTK.box layout.
53
public ref class VerticalGtkBoxLayout : public GtkBoxLayout
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;
61
// Implements a GTK.box like control.
62
public ref class Box : public Panel
65
Dictionary<Control^, bool> expandInfo;
66
Dictionary<Control^, bool> fillInfo;
68
GtkBoxLayout^ layoutEngine;
72
System::Drawing::Size preferredSize;
79
preferredSize= System::Drawing::Size(0, 0);
82
bool GetControlExpands(Control ^ctl)
84
return expandInfo[ctl];
87
bool GetControlFills(Control ^ctl)
92
virtual System::Drawing::Size GetPreferredSize(System::Drawing::Size proposedSize) override;
94
void Add(Control ^ctl, bool expands, bool fills)
96
ViewImpl::set_layout_dirty(this, true);
97
expandInfo[ctl]= expands;
102
void Remove(Control ^ctl)
104
expandInfo.Remove(ctl);
105
fillInfo.Remove(ctl);
106
Controls->Remove(ctl);
109
virtual property Windows::Forms::Layout::LayoutEngine^ LayoutEngine
111
Windows::Forms::Layout::LayoutEngine^ get() override
113
if (layoutEngine == nullptr)
116
layoutEngine = gcnew HorizontalGtkBoxLayout();
118
layoutEngine = gcnew VerticalGtkBoxLayout();
124
virtual property bool Homogeneous
133
if (homogeneous != value)
135
ViewImpl::set_layout_dirty(this, true);
143
virtual property int Spacing
152
if (spacing != value)
154
ViewImpl::set_layout_dirty(this, true);
162
virtual property bool Horizontal
171
if (horizontal != value)
174
layoutEngine= nullptr;
175
ViewImpl::set_layout_dirty(this, true);
182
// Implements a wrapper class that connects the backend's box class with a .NET box control.
183
public ref class BoxImpl : public ViewImpl
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);
193
BoxImpl(::mforms::View *view)
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);
201
void set_homogeneous(bool flag);
202
void set_spacing(int space);
204
static void init(Manager ^mgr)
206
::mforms::ControlFactory *f= ::mforms::ControlFactory::get_instance();
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);