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

« back to all changes in this revision

Viewing changes to library/forms/winforms/src/wf_view.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) 2008, 2012, 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
#include "stdafx.h"
 
21
#include "wf_view.h"
 
22
 
 
23
using namespace Windows::Forms;
 
24
using namespace System::Drawing;
 
25
 
 
26
using namespace MySQL;
 
27
using namespace MySQL::Forms;
 
28
using namespace MySQL::Utilities;
 
29
using namespace MySQL::Controls;
 
30
 
 
31
using namespace Aga::Controls::Tree;
 
32
using namespace ScintillaNet;
 
33
 
 
34
DEFAULT_LOG_DOMAIN(DOMAIN_MFORMS_WRAPPER)
 
35
 
 
36
//----------------- ViewImpl ----------------------------------------------------------------------
 
37
 
 
38
ViewImpl::ViewImpl(::mforms::View *view)
 
39
  : ObjectImpl(view)
 
40
{
 
41
  tooltip= nullptr;
 
42
}
 
43
 
 
44
//--------------------------------------------------------------------------------------------------
 
45
 
 
46
ViewImpl::~ViewImpl()
 
47
{
 
48
  delete tooltip;
 
49
}
 
50
 
 
51
//--------------------------------------------------------------------------------------------------
 
52
 
 
53
/**
 
54
 * Determines, depending on the type of the given control, if the layout process should use the control's
 
55
 * minimum or its preferred size. 
 
56
 * This is necessary because there is a discrepancy between what is considered the minimum size for layouting
 
57
 * and the same size for Windows controls. The latter is usually just 0. Instead the preferred size comes close
 
58
 * to what we need in the layouting process. Unfortunately, some controls just return their current size
 
59
 * (even if they are empty) or the size they need to fit their full text (text box).
 
60
 */
 
61
bool ViewImpl::use_min_width_for_layout(Control^ control)
 
62
{
 
63
  TextBox^ text= dynamic_cast<TextBox^>(control);
 
64
  bool needsMinWidth= (text != nullptr) && (text->Multiline);
 
65
  if (!needsMinWidth)
 
66
  {
 
67
    System::Type^ type = control->GetType();
 
68
    needsMinWidth= (type == TabControl::typeid) || (type == Panel::typeid) || (type == ComboBox::typeid)
 
69
      || (type == TreeViewAdv::typeid) || (type == ListBox::typeid) || (type == TextBox::typeid)
 
70
      || (type == SplitContainer::typeid) || (type == Scintilla::typeid)
 
71
      
 
72
      // TODO: investigate if we can remove this and override GetPreferredSize in FlatTabControl instead.
 
73
      || (type == FlatTabControl::typeid);
 
74
  }
 
75
 
 
76
  return needsMinWidth;
 
77
}
 
78
 
 
79
//--------------------------------------------------------------------------------------------------
 
80
 
 
81
bool ViewImpl::use_min_height_for_layout(Control^ control)
 
82
{
 
83
  TextBox^ text= dynamic_cast<TextBox^>(control);
 
84
  bool needsMinHeight= (text != nullptr) && (text->Multiline);
 
85
  if (!needsMinHeight)
 
86
  {
 
87
    System::Type^ type = control->GetType();
 
88
    needsMinHeight= (type == TabControl::typeid) || (type == Panel::typeid) || (type == ListBox::typeid)
 
89
      || (type == TreeViewAdv::typeid) || (type == SplitContainer::typeid) || (type == Scintilla::typeid)
 
90
 
 
91
    // TODO: investigate if we can remove this and override GetPreferredSize in FlatTabControl instead.
 
92
    || (type == FlatTabControl::typeid);
 
93
  }
 
94
 
 
95
  return needsMinHeight;
 
96
}
 
97
 
 
98
//--------------------------------------------------------------------------------------------------
 
99
 
 
100
/**
 
101
 * Removes the given mode from the auto resize settings of the given control.
 
102
 */
 
103
void ViewImpl::remove_auto_resize(Control^ control, mforms::AutoResizeMode mode)
 
104
{
 
105
  // Get backend object for the control, which allows to set individual auto resize modes.
 
106
  mforms::View* view= ViewImpl::get_backend_control<mforms::View>(control);
 
107
  switch (mode)
 
108
  {
 
109
    case mforms::ResizeBoth:
 
110
      view->set_resize_mode(mforms::ResizeNone);
 
111
      break;
 
112
    case mforms::ResizeHorizontal:
 
113
      if (view->get_resize_mode() == mforms::ResizeBoth)
 
114
        view->set_resize_mode(mforms::ResizeVertical);
 
115
      else
 
116
        view->set_resize_mode(mforms::ResizeNone);
 
117
      break;
 
118
    case mforms::ResizeVertical:
 
119
      if (view->get_resize_mode() == mforms::ResizeBoth)
 
120
        view->set_resize_mode(mforms::ResizeHorizontal);
 
121
      else
 
122
        view->set_resize_mode(mforms::ResizeNone);
 
123
      break;
 
124
  }
 
125
}
 
126
 
 
127
//-------------------------------------------------------------------------------------------------
 
128
 
 
129
/**
 
130
 * Returns the current resize mode set for the associated back end object of control.
 
131
 */
 
132
mforms::AutoResizeMode ViewImpl::get_auto_resize(Control^ control)
 
133
{
 
134
  mforms::View* view= ViewImpl::get_backend_control<mforms::View>(control);
 
135
  return view->get_resize_mode();
 
136
}
 
137
 
 
138
//-------------------------------------------------------------------------------------------------
 
139
 
 
140
/**
 
141
 * Determines if the given control can be resized in horizontal direction.
 
142
 */
 
143
bool ViewImpl::can_auto_resize_horizontally(Control^ control)
 
144
{
 
145
  mforms::View* view= ViewImpl::get_backend_control<mforms::View>(control);
 
146
  mforms::AutoResizeMode mode= view->get_resize_mode();
 
147
 
 
148
  return (mode == mforms::ResizeHorizontal) || (mode == mforms::ResizeBoth);
 
149
}
 
150
 
 
151
//-------------------------------------------------------------------------------------------------
 
152
 
 
153
/**
 
154
 * Determines if the given control can be resized in vertical direction.
 
155
 */
 
156
bool ViewImpl::can_auto_resize_vertically(Control^ control)
 
157
{
 
158
  mforms::View* view= ViewImpl::get_backend_control<mforms::View>(control);
 
159
  mforms::AutoResizeMode mode= view->get_resize_mode();
 
160
 
 
161
  return (mode == mforms::ResizeVertical) || (mode == mforms::ResizeBoth);
 
162
}
 
163
 
 
164
//-------------------------------------------------------------------------------------------------
 
165
 
 
166
/**
 
167
 * Enables resizing of the control in both directions.
 
168
 */
 
169
void ViewImpl::set_full_auto_resize(Control^ control)
 
170
{
 
171
  ViewImpl::get_backend_control<mforms::View>(control)->set_resize_mode(mforms::ResizeBoth);
 
172
}
 
173
 
 
174
//-------------------------------------------------------------------------------------------------
 
175
 
 
176
/**
 
177
 * Sets resize mode whatever the caller specified.
 
178
 */
 
179
void ViewImpl::set_auto_resize(Control^ control, mforms::AutoResizeMode mode)
 
180
{
 
181
  ViewImpl::get_backend_control<mforms::View>(control)->set_resize_mode(mode);
 
182
}
 
183
 
 
184
//-------------------------------------------------------------------------------------------------
 
185
 
 
186
bool ViewImpl::is_layout_dirty(Control^ control)
 
187
{
 
188
  mforms::View* view= ViewImpl::get_backend_control<mforms::View>(control);
 
189
  return view->is_layout_dirty();
 
190
}
 
191
 
 
192
//-------------------------------------------------------------------------------------------------
 
193
 
 
194
void ViewImpl::set_layout_dirty(Control^ control, bool value)
 
195
{
 
196
  mforms::View* view= ViewImpl::get_backend_control<mforms::View>(control);
 
197
  view->set_layout_dirty(value);
 
198
}
 
199
 
 
200
//-------------------------------------------------------------------------------------------------
 
201
 
 
202
void ViewImpl::destroy(::mforms::View *self)
 
203
{
 
204
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
205
  delete view;
 
206
}
 
207
 
 
208
//--------------------------------------------------------------------------------------------------
 
209
 
 
210
void ViewImpl::show(::mforms::View *self, bool show)
 
211
{
 
212
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
213
 
 
214
  if (view != nullptr)
 
215
  {
 
216
    Control^ control= view->get_control<Control>();
 
217
    control->Visible= show;
 
218
 
 
219
    // Unfortunately, we cannot optimize handling here. Control::Visible not only returns the
 
220
    // visibility of itself but its entire view hierarchy. So we cannot distinct between the two
 
221
    // cases if the control itself is hidden or one of its parents. Setting Control::Visible
 
222
    // does the right job, though.
 
223
    //if (control->Visible != show)
 
224
    if (control->IsHandleCreated && self->get_parent() != NULL)
 
225
      self->get_parent()->set_layout_dirty(true);
 
226
  };
 
227
}
 
228
 
 
229
//-------------------------------------------------------------------------------------------------
 
230
 
 
231
int ViewImpl::get_width(::mforms::View *self)
 
232
{
 
233
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
234
  if (view != nullptr)
 
235
    return view->get_control<Control>()->Width;
 
236
  return 0;
 
237
}
 
238
 
 
239
//-------------------------------------------------------------------------------------------------
 
240
 
 
241
int ViewImpl::get_height(::mforms::View *self)
 
242
{
 
243
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
244
  if (view != nullptr)
 
245
    return view->get_control<Control>()->Height;
 
246
  return 0;
 
247
}
 
248
 
 
249
//-------------------------------------------------------------------------------------------------
 
250
 
 
251
int ViewImpl::get_preferred_width(::mforms::View *self)
 
252
{
 
253
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
254
  if (view != nullptr)
 
255
  {
 
256
    return view->get_control<Control>()->PreferredSize.Width;
 
257
  }
 
258
  return 0;
 
259
}
 
260
 
 
261
//-------------------------------------------------------------------------------------------------
 
262
 
 
263
int ViewImpl::get_preferred_height(::mforms::View *self)
 
264
{
 
265
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
266
  if (view != nullptr)
 
267
  {
 
268
    return view->get_control<Control>()->PreferredSize.Height;
 
269
  }
 
270
  return 0;
 
271
}
 
272
 
 
273
//-------------------------------------------------------------------------------------------------
 
274
 
 
275
int ViewImpl::get_x(::mforms::View *self)
 
276
{
 
277
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
278
  if (view != nullptr)
 
279
  {
 
280
    return view->get_control<Control>()->Left;
 
281
  }
 
282
  return 0;
 
283
}
 
284
 
 
285
//-------------------------------------------------------------------------------------------------
 
286
 
 
287
int ViewImpl::get_y(::mforms::View *self)
 
288
{
 
289
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
290
  if (view != nullptr)
 
291
  {
 
292
    return view->get_control<Control>()->Top;
 
293
  }
 
294
  return 0;
 
295
}
 
296
 
 
297
//-------------------------------------------------------------------------------------------------
 
298
 
 
299
void ViewImpl::set_size(::mforms::View *self, int w, int h)
 
300
{
 
301
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
302
  if (view != nullptr)
 
303
    view->set_size(w, h);
 
304
}
 
305
 
 
306
//-------------------------------------------------------------------------------------------------
 
307
 
 
308
void ViewImpl::set_padding(::mforms::View *self, int left, int top, int right, int bottom)
 
309
{
 
310
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
311
  if (view != nullptr)
 
312
  {
 
313
    self->set_layout_dirty(true);
 
314
    view->set_padding(left, top, right, bottom);
 
315
  }
 
316
}
 
317
 
 
318
//-------------------------------------------------------------------------------------------------
 
319
 
 
320
void ViewImpl::set_position(::mforms::View *self, int x, int y)
 
321
{
 
322
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
323
  if (view != nullptr)
 
324
  {
 
325
    if (self->get_parent() != NULL)
 
326
      self->get_parent()->set_layout_dirty(true);
 
327
    view->set_position(x, y);
 
328
  }
 
329
}
 
330
 
 
331
//-------------------------------------------------------------------------------------------------
 
332
 
 
333
void ViewImpl::client_to_screen(::mforms::View *self, int& x, int& y)
 
334
{
 
335
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
336
  if (view != nullptr)
 
337
  {
 
338
    System::Drawing::Point location= System::Drawing::Point(x, y);
 
339
    location= view->get_control<Control>()->PointToScreen(location);
 
340
    x = location.X;
 
341
    y = location.Y;
 
342
  }
 
343
}
 
344
 
 
345
//-------------------------------------------------------------------------------------------------
 
346
 
 
347
ViewImpl^ ViewImpl::get_parent()
 
348
{
 
349
  mforms::View* view= get_backend_control<mforms::View>(get_control<Control>());
 
350
  if (view != NULL && view->get_parent() != NULL)
 
351
    return (ViewImpl^) ObjectImpl::FromUnmanaged(view->get_parent());
 
352
 
 
353
  return nullptr;
 
354
}
 
355
 
 
356
//-------------------------------------------------------------------------------------------------
 
357
 
 
358
void ViewImpl::relayout()
 
359
{
 
360
  Control^ control= get_control<Control>();
 
361
  if (control->InvokeRequired)
 
362
    control->BeginInvoke(gcnew MethodInvoker(this, &ViewImpl::relayout));
 
363
  else
 
364
    control->PerformLayout();
 
365
}
 
366
 
 
367
//-------------------------------------------------------------------------------------------------
 
368
 
 
369
void ViewImpl::set_enabled(::mforms::View *self, bool flag)
 
370
{
 
371
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
372
  if (view != nullptr)
 
373
    view->get_control<Control>()->Enabled= flag;
 
374
}
 
375
 
 
376
//-------------------------------------------------------------------------------------------------
 
377
 
 
378
bool ViewImpl::is_enabled(::mforms::View *self)
 
379
{
 
380
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
381
  if (view != nullptr)
 
382
    return view->get_control<Control>()->Enabled;
 
383
  return false;
 
384
}
 
385
 
 
386
//-------------------------------------------------------------------------------------------------
 
387
 
 
388
View *ViewImpl::find_subview(::mforms::View *self, std::string &name)
 
389
{
 
390
  return 0;
 
391
}
 
392
 
 
393
//-------------------------------------------------------------------------------------------------
 
394
 
 
395
void ViewImpl::set_name(::mforms::View *self, const std::string& text)
 
396
{
 
397
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
398
  if (view != nullptr)
 
399
    view->get_control<Control>()->Name = CppStringToNative(text);
 
400
}
 
401
 
 
402
//-------------------------------------------------------------------------------------------------
 
403
 
 
404
void ViewImpl::relayout(::mforms::View *self)
 
405
{
 
406
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
407
  if (view != nullptr)
 
408
    view->relayout();
 
409
}
 
410
 
 
411
//-------------------------------------------------------------------------------------------------
 
412
 
 
413
void ViewImpl::set_needs_repaint(::mforms::View *self)
 
414
{
 
415
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
416
  if (view != nullptr)
 
417
    view->get_control<Control>()->Refresh();
 
418
}
 
419
 
 
420
//-------------------------------------------------------------------------------------------------
 
421
 
 
422
void ViewImpl::suspend_layout(::mforms::View *self, bool flag)
 
423
{
 
424
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
425
  if (view != nullptr)
 
426
  {
 
427
    if (flag)
 
428
      view->get_control<Control>()->SuspendLayout();
 
429
    else
 
430
    {
 
431
      view->get_control<Control>()->ResumeLayout();
 
432
      if (self->is_layout_dirty())
 
433
        view->get_control<Control>()->PerformLayout();
 
434
    }
 
435
  }
 
436
}
 
437
 
 
438
//-------------------------------------------------------------------------------------------------
 
439
 
 
440
void ViewImpl::set_front_color(mforms::View *self, const std::string &color)
 
441
{
 
442
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
443
  if (view != nullptr)
 
444
    view->set_front_color(CppStringToNative(color));
 
445
}
 
446
 
 
447
//-------------------------------------------------------------------------------------------------
 
448
 
 
449
std::string ViewImpl::get_front_color(mforms::View *self)
 
450
{
 
451
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
452
  if (view != nullptr)
 
453
    return NativeToCppString(view->get_front_color());
 
454
  return "#ffffff";
 
455
}
 
456
 
 
457
//-------------------------------------------------------------------------------------------------
 
458
 
 
459
void ViewImpl::set_back_color(mforms::View *self, const std::string &color)
 
460
{
 
461
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
462
  if (view != nullptr)
 
463
    view->set_back_color(CppStringToNative(color));
 
464
}
 
465
 
 
466
//-------------------------------------------------------------------------------------------------
 
467
 
 
468
std::string ViewImpl::get_back_color(mforms::View *self)
 
469
{
 
470
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
471
  if (view != nullptr)
 
472
    return NativeToCppString(view->get_back_color());
 
473
  return "#000000";
 
474
}
 
475
 
 
476
//-------------------------------------------------------------------------------------------------
 
477
 
 
478
void ViewImpl::set_back_image(mforms::View *self, const std::string &path, mforms::ImageLayout layout)
 
479
{
 
480
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
481
  if (view != nullptr)
 
482
    view->set_back_image(CppStringToNative(path), layout);
 
483
}
 
484
 
 
485
 
 
486
//-------------------------------------------------------------------------------------------------
 
487
 
 
488
void ViewImpl::set_tooltip(::mforms::View *self, const std::string& text)
 
489
{
 
490
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
491
  if (view != nullptr)
 
492
    view->set_tooltip(text);
 
493
}
 
494
 
 
495
//-------------------------------------------------------------------------------------------------
 
496
 
 
497
void ViewImpl::set_font(::mforms::View *self, const std::string& fontDescription)
 
498
{
 
499
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
500
  if (view != nullptr)
 
501
    view->set_font(fontDescription);
 
502
}
 
503
 
 
504
//-------------------------------------------------------------------------------------------------
 
505
 
 
506
bool ViewImpl::is_shown(::mforms::View *self)
 
507
{
 
508
  ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(self);
 
509
  if (view != nullptr)
 
510
    return view->get_control<Control>()->Visible;
 
511
  return false;
 
512
}
 
513
 
 
514
//-------------------------------------------------------------------------------------------------
 
515
 
 
516
void ViewImpl::set_size(int width, int height)
 
517
{
 
518
  Control^ control= get_control<Control>();
 
519
  Size newSize= control->Size;
 
520
  if (width >= 0)
 
521
    newSize.Width= width;
 
522
  if (height >= 0)
 
523
    newSize.Height= height;
 
524
  
 
525
  control->MinimumSize = newSize; // TODO: wrong place for this, when we restore loaded settings we don't want to set a min size.
 
526
                                  //       Implement an own set_min_size function.
 
527
  control->Size = newSize;
 
528
}
 
529
 
 
530
//-------------------------------------------------------------------------------------------------
 
531
 
 
532
void ViewImpl::set_padding(int left, int top, int right, int bottom)
 
533
{
 
534
  Control^ control= get_control<Control>();
 
535
  control->Padding = Windows::Forms::Padding(left, top, right, bottom);
 
536
}
 
537
 
 
538
//-------------------------------------------------------------------------------------------------
 
539
 
 
540
void ViewImpl::set_position(int x, int y)
 
541
{
 
542
  get_control<Control>()->Location = Point(x, y);
 
543
}
 
544
 
 
545
//-------------------------------------------------------------------------------------------------
 
546
 
 
547
void ViewImpl::set_tooltip(const std::string& text)
 
548
{
 
549
  if (tooltip == nullptr)
 
550
  {
 
551
    tooltip= gcnew ToolTip();
 
552
    tooltip->AutoPopDelay = 10000; // 10 sec. show time
 
553
    tooltip->InitialDelay = 500;   // 500 ms before showing the tooltip if none was visible before.
 
554
    tooltip->ReshowDelay = 250;    // 250 ms before showing the tooltip if another one was active.
 
555
    tooltip->ShowAlways = true;    // Show tooltip even if the control is not active.
 
556
  }
 
557
  tooltip->SetToolTip(get_control<Control>(), CppStringToNative(text));
 
558
}
 
559
 
 
560
//-------------------------------------------------------------------------------------------------
 
561
 
 
562
void ViewImpl::set_font(const std::string& fontDescription)
 
563
{
 
564
  std::string font;
 
565
  int size;
 
566
  bool bold;
 
567
  bool italic;
 
568
  base::parse_font_description(fontDescription, font, size, bold, italic);
 
569
 
 
570
  FontStyle style = FontStyle::Regular;
 
571
  if (bold)
 
572
    style = (FontStyle) (style | FontStyle::Bold);
 
573
  if (italic)
 
574
    style = (FontStyle) (style | FontStyle::Italic);
 
575
 
 
576
  try
 
577
  {
 
578
    get_control<Control>()->Font = ControlUtilities::GetFont(CppStringToNativeRaw(font),
 
579
      (float) size, style);
 
580
  }
 
581
  catch (System::ArgumentException^ e)
 
582
  {
 
583
    // Argument exception pops up when the system cannot find the Regular font style (corrupt font).
 
584
    log_error("ViewImpl::set_font failed. %s\n", e->Message);
 
585
  }
 
586
}
 
587
 
 
588
//-------------------------------------------------------------------------------------------------
 
589
 
 
590
void ViewImpl::set_front_color(String ^color)
 
591
{
 
592
  get_control<Control>()->ForeColor= System::Drawing::ColorTranslator::FromHtml(color);
 
593
}
 
594
 
 
595
//-------------------------------------------------------------------------------------------------
 
596
 
 
597
String^ ViewImpl::get_front_color()
 
598
{
 
599
  return System::Drawing::ColorTranslator::ToHtml(get_control<Control>()->ForeColor);
 
600
}
 
601
 
 
602
//-------------------------------------------------------------------------------------------------
 
603
 
 
604
void ViewImpl::set_back_color(String ^color)
 
605
{
 
606
  get_control<Control>()->BackColor= System::Drawing::ColorTranslator::FromHtml(color);
 
607
}
 
608
 
 
609
//-------------------------------------------------------------------------------------------------
 
610
 
 
611
String^ ViewImpl::get_back_color()
 
612
{
 
613
  return System::Drawing::ColorTranslator::ToHtml(get_control<Control>()->BackColor);
 
614
}
 
615
 
 
616
//-------------------------------------------------------------------------------------------------
 
617
 
 
618
void ViewImpl::set_back_image(String ^path, mforms::ImageLayout layout)
 
619
{
 
620
  Windows::Forms::ImageLayout native_layout;
 
621
  switch (layout)
 
622
  {
 
623
    case mforms::LayoutTile:
 
624
      native_layout= Windows::Forms::ImageLayout::Tile;
 
625
      break;
 
626
    case mforms::LayoutCenter:
 
627
      native_layout= Windows::Forms::ImageLayout::Center;
 
628
      break;
 
629
    case mforms::LayoutStretch:
 
630
      native_layout= Windows::Forms::ImageLayout::Stretch;
 
631
      break;
 
632
    case mforms::LayoutZoom:
 
633
      native_layout= Windows::Forms::ImageLayout::Zoom;
 
634
      break;
 
635
    default:
 
636
        native_layout= Windows::Forms::ImageLayout::None;
 
637
  }
 
638
 
 
639
  // An exception is raised if the image cannot be found.
 
640
  Image^ image= Image::FromFile(path, true);
 
641
  get_control<Control>()->BackgroundImage= image;
 
642
  get_control<Control>()->BackgroundImageLayout= native_layout;
 
643
}
 
644
 
 
645
//-------------------------------------------------------------------------------------------------
 
646
 
 
647
/**
 
648
 * Resizes the given control according to its dock state. Sizes of the control which were not changed
 
649
 * are also reset in the given Size structure to allow for proper child layouting.
 
650
 */
 
651
void ViewImpl::resize_with_docking(Control^ control, System::Drawing::Size& size)
 
652
{
 
653
  // If the control is docked somewhere resizing must be restricted not to destroy the docked
 
654
  // appearance.
 
655
  // Do not resize if the control has the fill dock style. In that case it must stay as it is.
 
656
  if (control->Dock == DockStyle::Fill)
 
657
    return;
 
658
 
 
659
  if (control->Dock == DockStyle::Left || control->Dock == DockStyle::Right)
 
660
    size.Height= control->Size.Height;
 
661
  else
 
662
    if (control->Dock == DockStyle::Top || control->Dock == DockStyle::Bottom)
 
663
      size.Width= control->Size.Width;
 
664
 
 
665
  control->Size= size;
 
666
  set_layout_dirty(control, true);
 
667
}
 
668
 
 
669
//-------------------------------------------------------------------------------------------------
 
670
 
 
671
/**
 
672
 * Removes auto resizing flags if a control is limited in resizing by docking.
 
673
 */
 
674
void ViewImpl::adjust_auto_resize_from_docking(Control^ control)
 
675
{
 
676
  if (control->Dock == DockStyle::Fill)
 
677
    set_auto_resize(control, mforms::ResizeNone);
 
678
  else
 
679
    if (control->Dock == DockStyle::Left || control->Dock == DockStyle::Right)
 
680
      remove_auto_resize(control, mforms::ResizeHorizontal);
 
681
    else
 
682
      if (control->Dock == DockStyle::Top || control->Dock == DockStyle::Bottom)
 
683
        remove_auto_resize(control, mforms::ResizeVertical);
 
684
}
 
685
 
 
686
//-------------------------------------------------------------------------------------------------
 
687
 
 
688
void ViewImpl::flush_events(::mforms::View *)
 
689
{
 
690
  Application::DoEvents();
 
691
}
 
692
 
 
693
//-------------------------------------------------------------------------------------------------