2
// <copyright see="prj:///doc/copyright.txt"/>
3
// <license see="prj:///doc/license.txt"/>
4
// <owner name="Oakland Software Incorporated" email="general@oaklandsoftware.com"/>
5
// <version>$Revision$</version>
9
using System.ComponentModel.Design;
11
using System.Windows.Forms;
13
using ICSharpCode.Core;
14
using NoGoop.Controls;
16
using NoGoop.ObjBrowser.GuiDesigner;
18
namespace NoGoop.ObjBrowser
20
internal class ImagePanel : Panel
24
CheckBox _designCheck;
27
Panel _nonDesignPanel;
28
Panel _desLabelPanel = new Panel();
30
internal static ImagePanel CreateImagePanel(int width, bool showDesignModeCheckButton)
32
ObjectBrowser objB = ObjectBrowser.ObjBrowser;
34
ImagePanel panel = new ImagePanel();
35
panel._nonDesignPanel = new Panel();
36
panel._nonDesignPanel.Name = "Non-Design Surface";
37
panel._nonDesignPanel.Dock = DockStyle.Fill;
39
panel._designPanel = new Panel();
40
panel._designPanel.Name = "Design Surface";
41
panel._designPanel.Dock = DockStyle.Fill;
43
panel.WrapImagePanel(width, showDesignModeCheckButton);
47
internal Panel DesignPanel {
53
internal Panel WrapperPanel {
59
void WrapImagePanel(int width, bool showDesignModeCheckButton)
61
// Create the label for the check box to control design time
62
_desLabelPanel = new Panel();
63
_desLabelPanel.Dock = DockStyle.Left;
64
_desLabelPanel.Width = width;
65
_desLabelPanel.Height = TreeListPanel.BASE_HEADER_HEIGHT;
67
if (showDesignModeCheckButton) {
68
_checkLabel = new Label();
69
_checkLabel.Dock = DockStyle.Left;
70
_checkLabel.Text = StringParser.Parse("${res:ComponentInspector.ImagePanel.DesignModeLabel}");
71
_checkLabel.AutoSize = true;
72
_desLabelPanel.Controls.Add(_checkLabel);
74
_designCheck = new CheckBox();
75
_designCheck.Checked = true;
76
_designCheck.Dock = DockStyle.Left;
78
// This does not work because the checkbox alignment of the text
79
// does not match that of text outside of the checkbox, sigh
80
//_designCheck.Text = "Design mode";
81
//_designCheck.TextAlign = ContentAlignment.TopRight;
82
_designCheck.CheckAlign = ContentAlignment.TopLeft;
83
_designCheck.Width = 15;
84
_designCheck.CheckedChanged += new EventHandler(DesignChecked);
85
_desLabelPanel.Controls.Add(_designCheck);
88
Label panelName = new Label();
89
panelName.Dock = DockStyle.Right;
90
panelName.Text = StringParser.Parse("${res:ComponentInspector.ImagePanel.ControlDesignSurfaceLabel}");
91
panelName.AutoSize = true;
92
_desLabelPanel.Controls.Add(panelName);
94
_wrapperPanel = new Panel();
95
_wrapperPanel.Width = width;
96
_wrapperPanel.Controls.Add(_designPanel);
97
_wrapperPanel.BorderStyle = BorderStyle.Fixed3D;
98
new PanelLabel(_wrapperPanel, _desLabelPanel);
101
void SwitchWindowTarget(Control con)
105
foreach (Control c in con.Controls) {
106
if (c.Site is DesignerSite) {
107
if (_designCheck.Checked) {
108
wt = ((DesignerSite)c.Site).DesignWindowTarget;
110
// The designer gets the windows events
114
wt = ((DesignerSite)c.Site).OrigWindowTarget;
116
// So the control gets the windows events
117
// instead of the designer
122
SwitchWindowTarget(c);
126
void DesignChecked(Object sender, EventArgs args)
128
Control selUIService = DesignerHost.Host.SelectionUIService;
130
// Swap the design/non design panels by rebuilding the control
131
// list for the wrapper panel.
132
ObjectBrowser.DesignerHost.DesignMode = _designCheck.Checked;
133
_wrapperPanel.Controls.Clear();
135
if (_designCheck.Checked) {
136
// Move the controls from the non-design panel to the
138
for (int i = 0; i < _nonDesignPanel.Controls.Count; ) {
139
Control c = (Control)_nonDesignPanel.Controls[i];
140
_nonDesignPanel.Controls.Remove(c);
142
// This Control could have been added to the design
143
// surface while it was not in design mode
144
if (c.Site == null) {
145
IDesigner designer = DesignerHost.Host.GetDesigner(c);
146
if (designer != null)
147
designer.Initialize(c);
150
_designPanel.Controls.Add(c);
153
SwitchWindowTarget(_designPanel);
154
_wrapperPanel.Controls.Add(_designPanel);
156
// Move the controls from the design panel to the
158
for (int i = 0; i < _designPanel.Controls.Count; ) {
159
Control c = (Control)_designPanel.Controls[i];
160
if (selUIService.Equals(c)) {
164
_designPanel.Controls.Remove(c);
166
_nonDesignPanel.Controls.Add(c);
167
} catch (Exception ex) {
169
"Error adding control " + c + " to "
170
+ "non-design panel",
171
MessageBoxIcon.Warning);
175
SwitchWindowTarget(_nonDesignPanel);
176
_wrapperPanel.Controls.Add(_nonDesignPanel);
178
ResetSize(selUIService);
180
new PanelLabel(_wrapperPanel, _desLabelPanel);
183
internal void ResetSize(Control selUIService)
185
if (_designCheck == null || _designCheck.Checked) {
186
selUIService.Height = _designPanel.ClientSize.Height;
187
selUIService.Width = _designPanel.ClientSize.Width;
189
selUIService.Height = 0;
190
selUIService.Width = 0;
194
// This is used to add a control to the design surface
195
// when it was added to the object tree, this is not used
196
// when the control is dragged directly to the design surface
197
internal void AddControl(ObjectInfo objInfo, Control control)
199
// For some reason, property grid gets an error when
200
// initially associated with the image panel, associated
201
// it with another panel first.
202
//if (control is PropertyGrid)
203
// ObjectBrowser._testPanel.Controls.Add(control);
205
IDesigner designer = null;
206
DesignerHost host = DesignerHost.Host;
207
if (host.DesignMode) {
208
host.AddingControls = true;
209
designer = host.GetDesigner(control, objInfo);
210
if (designer != null)
211
designer.Initialize(control);
213
// If no designer, can't add it to design surface
214
if (designer != null)
215
_designPanel.Controls.Add(control);
216
host.AddingControls = false;
218
_nonDesignPanel.Controls.Add(control);
223
//if (control is PropertyGrid)
224
// designer.Initialize(control);
227
// returns true if the control is found
228
bool RemoveControlFromControl(Control parent, Control control)
230
if (parent.Controls.Contains(control)) {
231
parent.Controls.Remove(control);
235
foreach (Control c in parent.Controls) {
236
if (RemoveControlFromControl(c, control))
242
internal void RemoveControl(Control control)
244
RemoveControlFromControl(_designPanel, control);
245
RemoveControlFromControl(_nonDesignPanel, control);