1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
|
//
// ToolStripPanel.cs
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2006 Jonathan Pobst
//
// Authors:
// Jonathan Pobst ([email protected])
//
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using ShiftUI.Layout;
using System;
namespace ShiftUI
{
[ComVisible (true)]
[ToolboxBitmap ("")]
[ClassInterface (ClassInterfaceType.AutoDispatch)]
//[Designer ("ShiftUI.Design.ToolStripPanelDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
public class ToolStripPanel : ContainerWidget, IComponent, IDisposable, IBindableComponent, IDropTarget
{
private bool done_first_layout;
private LayoutEngine layout_engine;
private bool locked;
private Orientation orientation;
private ToolStripRenderer renderer;
private ToolStripRenderMode render_mode;
private Padding row_margin;
private ToolStripPanelRowCollection rows;
public ToolStripPanel () : base ()
{
base.AutoSize = true;
this.locked = false;
this.renderer = null;
this.render_mode = ToolStripRenderMode.ManagerRenderMode;
this.row_margin = new Padding (3, 0, 0, 0);
this.rows = new ToolStripPanelRowCollection (this);
}
#region Public Properties
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override bool AllowDrop {
get { return base.AllowDrop; }
set { base.AllowDrop = value; }
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override bool AutoScroll {
get { return base.AutoScroll; }
set { base.AutoScroll = value; }
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new Size AutoScrollMargin {
get { return base.AutoScrollMargin; }
set { base.AutoScrollMargin = value; }
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new Size AutoScrollMinSize {
get { return base.AutoScrollMinSize; }
set { base.AutoScrollMinSize = value; }
}
[DefaultValue (true)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
public override bool AutoSize {
get { return base.AutoSize; }
set { base.AutoSize = value; }
}
public override DockStyle Dock {
get { return base.Dock; }
set {
base.Dock = value;
switch (value) {
case DockStyle.Top:
case DockStyle.Bottom:
case DockStyle.None:
this.orientation = Orientation.Horizontal;
break;
case DockStyle.Left:
case DockStyle.Right:
this.orientation = Orientation.Vertical;
break;
}
}
}
public override LayoutEngine LayoutEngine {
get {
if (this.layout_engine == null)
this.layout_engine = new FlowLayout ();
return this.layout_engine;
}
}
[Browsable (false)]
[DefaultValue (false)]
//[EditorBrowsable (EditorBrowsableState.Advanced)]
public bool Locked {
get { return this.locked; }
set { this.locked = value; }
}
public Orientation Orientation {
get { return this.orientation; }
set { this.orientation = value; }
}
[Browsable (false)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public ToolStripRenderer Renderer {
get {
if (this.render_mode == ToolStripRenderMode.ManagerRenderMode)
return ToolStripManager.Renderer;
return this.renderer;
}
set {
if (this.renderer != value) {
this.renderer = value;
this.render_mode = ToolStripRenderMode.Custom;
this.OnRendererChanged (EventArgs.Empty);
}
}
}
public ToolStripRenderMode RenderMode {
get { return this.render_mode; }
set {
if (!Enum.IsDefined (typeof (ToolStripRenderMode), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripRenderMode", value));
if (value == ToolStripRenderMode.Custom && this.renderer == null)
throw new NotSupportedException ("Must set Renderer property before setting RenderMode to Custom");
if (value == ToolStripRenderMode.Professional || value == ToolStripRenderMode.System)
this.Renderer = new ToolStripProfessionalRenderer ();
this.render_mode = value;
}
}
public Padding RowMargin {
get { return this.row_margin; }
set { this.row_margin = value; }
}
[Browsable (false)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public ToolStripPanelRow[] Rows {
get {
ToolStripPanelRow[] retval = new ToolStripPanelRow [this.rows.Count];
this.rows.CopyTo (retval, 0);
return retval;
}
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new int TabIndex {
get { return base.TabIndex; }
set { base.TabIndex = value; }
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public new bool TabStop {
get { return base.TabStop; }
set { base.TabStop = value; }
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
//[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override string Text {
get { return base.Text; }
set { base.Text = value; }
}
#endregion
#region Protected Properties
protected override Padding DefaultMargin {
get { return new Padding (0); }
}
protected override Padding DefaultPadding {
get { return new Padding (0); }
}
#endregion
#region Public Methods
public void BeginInit ()
{
}
public void EndInit ()
{
}
[MonoTODO("Not implemented")]
public void Join (ToolStrip toolStripToDrag)
{
if (!Contains (toolStripToDrag))
Widgets.Add (toolStripToDrag);
}
[MonoTODO("Not implemented")]
public void Join (ToolStrip toolStripToDrag, int row)
{
Join (toolStripToDrag);
}
[MonoTODO("Not implemented")]
public void Join (ToolStrip toolStripToDrag, Point location)
{
Join (toolStripToDrag);
}
[MonoTODO("Not implemented")]
public void Join (ToolStrip toolStripToDrag, int x, int y)
{
Join (toolStripToDrag);
}
public ToolStripPanelRow PointToRow (Point clientLocation)
{
foreach (ToolStripPanelRow row in this.rows)
if (row.Bounds.Contains (clientLocation))
return row;
return null;
}
#endregion
#region Protected Methods
protected override WidgetCollection CreateWidgetsInstance ()
{
return new ToolStripPanelWidgetCollection (this);
}
protected override void Dispose (bool disposing)
{
base.Dispose (disposing);
}
protected override void OnWidgetAdded (WidgetEventArgs e)
{
if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right)
(e.Widget as ToolStrip).LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
else
(e.Widget as ToolStrip).LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
if (done_first_layout && e.Widget is ToolStrip)
this.AddWidgetToRows (e.Widget);
base.OnWidgetAdded (e);
}
protected override void OnWidgetRemoved (WidgetEventArgs e)
{
base.OnWidgetRemoved (e);
foreach (ToolStripPanelRow row in this.rows)
if (row.Widgets.Contains (e.Widget))
row.OnWidgetRemoved (e.Widget, 0);
}
protected override void OnDockChanged (EventArgs e)
{
base.OnDockChanged (e);
}
protected override void OnLayout (LayoutEventArgs e)
{
// Don't see any reason to layout if we aren't created
if (!this.Created)
return;
// The first time through, we have to layout everything where it belongs.
// The key is that when we resize and stuff, we don't resize or move toolstrips.
if (!done_first_layout) {
ArrayList al = new ArrayList (this.Widgets);
al.Sort (new TabIndexComparer ());
foreach (ToolStrip ts in al)
this.AddWidgetToRows (ts);
done_first_layout = true;
}
// Lay out all the rows
Point position = this.DisplayRectangle.Location;
if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right) {
foreach (ToolStripPanelRow row in this.rows) {
row.SetBounds (new Rectangle (position, new Size (row.Bounds.Width, this.Height)));
position.X += row.Bounds.Width;
}
// Find how big we are so we can autosize ourself
if (this.rows.Count > 0) {
int last_row_right = this.rows[this.rows.Count - 1].Bounds.Right;
if (last_row_right != this.Width)
this.SetBounds (bounds.X, bounds.Y, last_row_right, bounds.Bottom);
}
} else {
foreach (ToolStripPanelRow row in this.rows) {
row.SetBounds (new Rectangle (position, new Size (this.Width, row.Bounds.Height)));
position.Y += row.Bounds.Height;
}
// Find how big we are so we can autosize ourself
if (this.rows.Count > 0) {
int last_row_bottom = this.rows[this.rows.Count - 1].Bounds.Bottom;
if (last_row_bottom != this.Height)
this.SetBounds (bounds.X, bounds.Y, bounds.Width, last_row_bottom);
}
}
this.Invalidate ();
return;
}
//[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override void OnPaintBackground (PaintEventArgs e)
{
base.OnPaintBackground (e);
this.Renderer.DrawToolStripPanelBackground (new ToolStripPanelRenderEventArgs (e.Graphics, this));
}
protected override void OnParentChanged (EventArgs e)
{
base.OnParentChanged (e);
}
protected virtual void OnRendererChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [RendererChangedEvent]);
if (eh != null)
eh (this, e);
}
protected override void OnRightToLeftChanged (EventArgs e)
{
base.OnRightToLeftChanged (e);
}
#endregion
#region Public Events
static object RendererChangedEvent = new object ();
[Browsable (true)]
//[EditorBrowsable (EditorBrowsableState.Always)]
public new event EventHandler AutoSizeChanged {
add { base.AutoSizeChanged += value; }
remove { base.AutoSizeChanged -= value; }
}
public event EventHandler RendererChanged {
add { Events.AddHandler (RendererChangedEvent, value); }
remove { Events.RemoveHandler (RendererChangedEvent, value); }
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler TabIndexChanged {
add { base.TabIndexChanged += value; }
remove { base.TabIndexChanged -= value; }
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler TabStopChanged {
add { base.TabStopChanged += value; }
remove { base.TabStopChanged -= value; }
}
[Browsable (false)]
//[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler TextChanged {
add { base.TextChanged += value; }
remove { base.TextChanged -= value; }
}
#endregion
#region Private Methods
private void AddWidgetToRows (Widget Widget)
{
if (this.rows.Count > 0)
if (this.rows[this.rows.Count - 1].CanMove ((ToolStrip)Widget)) {
this.rows[this.rows.Count - 1].OnWidgetAdded (Widget, 0);
return;
}
ToolStripPanelRow new_row = new ToolStripPanelRow (this);
if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right)
new_row.SetBounds (new Rectangle (0, 0, 25, this.Height));
else
new_row.SetBounds (new Rectangle (0, 0, this.Width, 25));
this.rows.Add (new_row);
new_row.OnWidgetAdded (Widget, 0);
}
/*
private Region FindBackgroundRegion ()
{
Region r = new Region (this.Bounds);
foreach (Widget c in this.Widgets)
r.Exclude (c.Bounds);
return r;
}
*/
#endregion
#region Nested Classes
[ComVisible (false)]
[ListBindable (false)]
public class ToolStripPanelRowCollection : ArrangedElementCollection, IList, ICollection, IEnumerable
{
//private ToolStripPanel owner;
public ToolStripPanelRowCollection (ToolStripPanel owner) : base ()
{
//this.owner = owner;
}
public ToolStripPanelRowCollection (ToolStripPanel owner, ToolStripPanelRow[] value) : this (owner)
{
if (value != null)
foreach (ToolStripPanelRow tspr in value)
this.Add (tspr);
}
public new virtual ToolStripPanelRow this [int index] {
get { return (ToolStripPanelRow)base[index]; }
}
#region Public Methods
public int Add (ToolStripPanelRow value)
{
return base.Add (value);
}
public void AddRange (ToolStripPanelRowCollection value)
{
if (value == null)
throw new ArgumentNullException ("value");
foreach (ToolStripPanelRow tspr in value)
this.Add (tspr);
}
public void AddRange (ToolStripPanelRow[] value)
{
if (value == null)
throw new ArgumentNullException ("value");
foreach (ToolStripPanelRow tspr in value)
this.Add (tspr);
}
public new virtual void Clear ()
{
base.Clear ();
}
public bool Contains (ToolStripPanelRow value)
{
return base.Contains (value);
}
public void CopyTo (ToolStripPanelRow[] array, int index)
{
base.CopyTo (array, index);
}
public int IndexOf (ToolStripPanelRow value)
{
return base.IndexOf (value);
}
public void Insert (int index, ToolStripPanelRow value)
{
base.Insert (index, value);
}
public void Remove (ToolStripPanelRow value)
{
base.Remove (value);
}
public void RemoveAt (int index)
{
base.InternalRemoveAt (index);
}
#endregion
#region IList Members
object IList.this [int index] {
get { return this [index]; }
[MonoTODO ("Stub, does nothing")]
set { }
}
bool IList.IsFixedSize {
get { return IsFixedSize; }
}
bool IList.IsReadOnly {
get { return IsReadOnly; }
}
int IList.Add (object value)
{
return Add (value as ToolStripPanelRow);
}
void IList.Clear ()
{
Clear ();
}
bool IList.Contains (object value)
{
return Contains (value as ToolStripPanelRow);
}
int IList.IndexOf (object value)
{
return IndexOf (value as ToolStripPanelRow);
}
void IList.Insert (int index, object value)
{
Insert (index, value as ToolStripPanelRow);
}
void IList.Remove (object value)
{
Remove (value as ToolStripPanelRow);
}
void IList.RemoveAt (int index)
{
base.InternalRemoveAt (index);
}
#endregion
}
private class ToolStripPanelWidgetCollection : WidgetCollection
{
public ToolStripPanelWidgetCollection (Widget owner) : base (owner)
{
}
}
private class TabIndexComparer : IComparer
{
#region IComparer Members
public int Compare (object x, object y)
{
if (!(x is Widget) || !(y is Widget))
throw new ArgumentException ();
return (x as Widget).TabIndex - (y as Widget).TabIndex;
}
#endregion
}
#endregion
}
}
|