1 /** DGui project file.
2 
3 Copyright: Trogu Antonio Davide 2011-2013
4 
5 License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 
7 Authors: Trogu Antonio Davide
8 */
9 module dgui.core.controls.containercontrol;
10 
11 public import dgui.core.controls.reflectedcontrol;
12 
13 abstract class ContainerControl: ReflectedControl
14 {
15 	protected Collection!(Control) _childControls;
16 
17 	@property public final bool rtlLayout()
18 	{
19 		return cast(bool)(this.getExStyle() & WS_EX_LAYOUTRTL);
20 	}
21 
22 	@property public final void rtlLayout(bool b)
23 	{
24 		this.setExStyle(WS_EX_LAYOUTRTL, b);
25 	}
26 
27 	@property public final Control[] controls()
28 	{
29 		if(this._childControls)
30 		{
31 			return this._childControls.get();
32 		}
33 
34 		return null;
35 	}
36 
37 	private void addChildControl(Control c)
38 	{
39 		if(!this._childControls)
40 		{
41 			this._childControls = new Collection!(Control);
42 		}
43 
44 		this._childControls.add(c);
45 
46 		if(this.created)
47 		{
48 			c.show();
49 		}
50 	}
51 
52 	protected void doChildControls()
53 	{
54 		if(this._childControls)
55 		{
56 			foreach(Control c; this._childControls)
57 			{
58 				if(!c.created) //Extra Check: Avoid creating duplicate components (added at runtime)
59 				{
60 					c.show();
61 				}
62 			}
63 		}
64 	}
65 
66 	protected override void createControlParams(ref CreateControlParams ccp)
67 	{
68 		this.setStyle(WS_CLIPCHILDREN, true);
69 		this.setExStyle(WS_EX_CONTROLPARENT, true);
70 
71 		super.createControlParams(ccp);
72 	}
73 
74 	protected override void onDGuiMessage(ref Message m)
75 	{
76 		switch(m.msg)
77 		{
78 			case DGUI_ADDCHILDCONTROL:
79 				this.addChildControl(winCast!(Control)(m.wParam));
80 				break;
81 
82 			default:
83 				break;
84 		}
85 
86 		super.onDGuiMessage(m);
87 	}
88 
89 	protected override void onHandleCreated(EventArgs e)
90 	{
91 		this.doChildControls();
92 		super.onHandleCreated(e);
93 	}
94 }