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

« back to all changes in this revision

Viewing changes to library/forms/winforms/src/wf_appview.cpp

  • 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
/**
 
21
 * Contains the implementation of the wrapper for a .NET form used by the mforms backend.
 
22
 */
 
23
 
 
24
#include "stdafx.h"
 
25
 
 
26
#include "wf_appview.h"
 
27
#include "wf_menubar.h"
 
28
#include "wf_toolbar.h"
 
29
#include "wf_view.h"
 
30
 
 
31
using namespace System::Drawing::Drawing2D;
 
32
 
 
33
using namespace MySQL::Forms;
 
34
using namespace MySQL::Controls;
 
35
 
 
36
//--------------------------------------------------------------------------------------------------
 
37
 
 
38
bool AppViewImpl::create(::mforms::AppView *self, bool horizontal)
 
39
{
 
40
  AppViewImpl^ appview= gcnew AppViewImpl(self);
 
41
 
 
42
  if (appview != nullptr)
 
43
  {
 
44
    // The next steps are the same as with a BoxImpl.
 
45
    Box^ native_box= ViewImpl::create<Box>(self, appview);
 
46
    native_box->Horizontal= horizontal;
 
47
    self->set_resize_mode(::mforms::ResizeNone);
 
48
 
 
49
    return true;
 
50
  }
 
51
  return false;
 
52
}
 
53
 
 
54
//--------------------------------------------------------------------------------------------------
 
55
 
 
56
/**
 
57
 * Called when this app view is about to be docked in a host container. Create the front end
 
58
 * tab document if not yet done and return it to the caller.
 
59
 */
 
60
TabDocument^ AppViewImpl::GetHost()
 
61
{
 
62
  if (_host == nullptr)
 
63
    setup();
 
64
  return _host;
 
65
}
 
66
 
 
67
//--------------------------------------------------------------------------------------------------
 
68
 
 
69
MenuStrip^ AppViewImpl::GetMenuBar()
 
70
{
 
71
  mforms::MenuBar* menu = _appView->get_menubar();
 
72
  if (menu == NULL)
 
73
    return nullptr;
 
74
 
 
75
  MenuBarImpl^ menubar_impl = (MenuBarImpl^) ViewImpl::FromUnmanaged(menu);
 
76
 
 
77
  return menubar_impl->get_control<MenuStrip>();
 
78
}
 
79
 
 
80
//--------------------------------------------------------------------------------------------------
 
81
 
 
82
ToolStrip^ AppViewImpl::GetToolBar()
 
83
{
 
84
  mforms::ToolBar* toolbar = _appView->get_toolbar();
 
85
  if (toolbar == NULL)
 
86
    return nullptr;
 
87
 
 
88
  ToolBarImpl^ toolbar_impl = (ToolBarImpl^) ViewImpl::FromUnmanaged(toolbar);
 
89
 
 
90
  return toolbar_impl->get_control<ToolStrip>();
 
91
}
 
92
 
 
93
//--------------------------------------------------------------------------------------------------
 
94
 
 
95
bool AppViewImpl::DocumentClosing()
 
96
{
 
97
  Control^ control= get_control<Control>();
 
98
 
 
99
  if (control->Tag != nullptr)
 
100
  {
 
101
    ::mforms::AppView* view= ViewImpl::get_backend_control<::mforms::AppView>(control);
 
102
    if (view != NULL)
 
103
      return view->on_close();
 
104
  }
 
105
  return true;
 
106
}
 
107
 
 
108
//--------------------------------------------------------------------------------------------------
 
109
 
 
110
AppViewImpl::AppViewImpl(::mforms::AppView* app)
 
111
  : BoxImpl(app), _appView(app)
 
112
{
 
113
}
 
114
 
 
115
//--------------------------------------------------------------------------------------------------
 
116
 
 
117
void AppViewImpl::setup()
 
118
{
 
119
  // In order to ease maintenance we create a special document host for our content.
 
120
  _host = gcnew AppViewDockContent(this);
 
121
  Control^ control = get_control<Control>();
 
122
  _host->Controls->Add(control);
 
123
  control->Dock = DockStyle::Fill;
 
124
}
 
125
 
 
126
//--------------------------------------------------------------------------------------------------
 
127
 
 
128
void AppViewImpl::ContentPanelPaint(System::Object^ sender, PaintEventArgs^ e)
 
129
{
 
130
  Graphics^ g = e->Graphics;
 
131
  g->SmoothingMode = SmoothingMode::None;
 
132
 
 
133
  System::Drawing::Rectangle clientArea = ((Panel^)(sender))->ClientRectangle;
 
134
 
 
135
  Pen^ pen = gcnew Pen(Color::FromArgb(175, 210, 239), 1);
 
136
  g->DrawRectangle(pen, clientArea.Left, clientArea.Top, clientArea.Width - 1, clientArea.Height - 1);
 
137
  delete pen;
 
138
}
 
139
 
 
140
//--------------------------------------------------------------------------------------------------
 
141
 
 
142
void AppViewImpl::MenuPanelPaint(System::Object^ sender, PaintEventArgs^ e)
 
143
{
 
144
  Graphics^ g = e->Graphics;
 
145
  Panel^ panel = dynamic_cast<Panel^>(sender);
 
146
 
 
147
  ToolStripHelper::MenuPanelPaint(g, panel->ClientRectangle);
 
148
}
 
149
 
 
150
//----------------- AppViewDockContent -------------------------------------------------------------
 
151
 
 
152
AppViewDockContent::AppViewDockContent(AppViewImpl^ appview)
 
153
{
 
154
  _appview= appview;
 
155
  _appview->get_unmanaged_object()->retain();
 
156
};
 
157
 
 
158
//--------------------------------------------------------------------------------------------------
 
159
 
 
160
AppViewDockContent::~AppViewDockContent()
 
161
{
 
162
  _appview->get_unmanaged_object()->release();
 
163
  _appview= nullptr;
 
164
}
 
165
 
 
166
//--------------------------------------------------------------------------------------------------
 
167
 
 
168
AppViewImpl^ AppViewDockContent::GetAppView()
 
169
{
 
170
  return _appview;
 
171
};
 
172
 
 
173
//--------------------------------------------------------------------------------------------------
 
174
 
 
175
mforms::AppView* AppViewDockContent::get_unmanaged_object()
 
176
{
 
177
  return _appview->get_unmanaged_object();
 
178
}
 
179
 
 
180
//--------------------------------------------------------------------------------------------------
 
181
 
 
182
String^ AppViewDockContent::GetAppViewIdentifier()
 
183
{
 
184
  return CppStringToNative(_appview->get_unmanaged_object()->identifier());
 
185
}
 
186
 
 
187
//--------------------------------------------------------------------------------------------------