1 #include "Docking.h"
2
3 namespace Upp {
4
5 #define IMAGECLASS DockingImg
6 #define IMAGEFILE <Docking/Docking.iml>
7 #include <Draw/iml_source.h>
8
GetContainer() const9 DockCont * DockableCtrl::GetContainer() const
10 {
11 return dynamic_cast<DockCont *>(GetParent());
12 }
13
Set(const Image & _icon,const char * _title,String _group)14 DockableCtrl& DockableCtrl::Set(const Image& _icon, const char *_title, String _group)
15 {
16 return SetGroup(_group).Title(_title).Icon(_icon);
17 }
18
IsHotKey(dword key)19 bool DockableCtrl::IsHotKey(dword key)
20 {
21 return (keycode == key || (keyinfo &&
22 (key == keyinfo().key[0] || key == keyinfo().key[1] || key == keyinfo().key[2] || key == keyinfo().key[3])));
23 }
24
SizeHint(const Size & min,const Size & max,const Size & std)25 DockableCtrl& DockableCtrl::SizeHint(const Size& min, const Size& max, const Size& std)
26 {
27 minsize = min; maxsize = max; stdsize = std;
28 return *this;
29 }
30
Title(const WString & _title)31 DockableCtrl& DockableCtrl::Title(const WString& _title)
32 {
33 title = _title;
34 if (GetContainer())
35 GetContainer()->ChildTitleChanged(*this);
36 return *this;
37 }
38
Icon(const Image & m)39 DockableCtrl& DockableCtrl::Icon(const Image& m)
40 {
41 icon = m;
42 if (GetContainer())
43 GetContainer()->ChildTitleChanged(*this);
44 return *this;
45 }
46
IsFloating() const47 bool DockableCtrl::IsFloating() const
48 {
49 DockCont *c = GetContainer();
50 return c && c->IsFloating();
51 }
52
IsDocked() const53 bool DockableCtrl::IsDocked() const
54 {
55 DockCont *c = GetContainer();
56 return c && c->IsDocked();
57 }
58
IsAutoHide() const59 bool DockableCtrl::IsAutoHide() const
60 {
61 DockCont *c = GetContainer();
62 return c && c->IsAutoHide();
63 }
64
IsTabbed() const65 bool DockableCtrl::IsTabbed() const
66 {
67 DockCont *c = GetContainer();
68 return c && (c->IsTabbed() || c->GetCount() > 1);
69 }
70
IsHidden() const71 bool DockableCtrl::IsHidden() const
72 {
73 DockCont *c = GetContainer();
74 return !c || c->IsHidden();
75 }
76
GetDockAlign() const77 int DockableCtrl::GetDockAlign() const
78 {
79 DockCont *c = GetContainer();
80 return c ? c->GetDockAlign() : -1;
81 }
82
SetGroup(const String & g)83 DockableCtrl& DockableCtrl::SetGroup(const String& g)
84 {
85 DockCont *c = GetContainer();
86 group = g;
87 if (c) c->GroupRefresh();
88 return *this;
89 }
90
Highlight()91 void DockableCtrl::Highlight()
92 {
93 if (!GetParent() || !IsOpen()) return;
94 ViewDraw v(this);
95 ChPaint(v, GetSize(), GetStyle().highlight[1]);
96 }
97
TimedHighlight(int ms)98 void DockableCtrl::TimedHighlight(int ms)
99 {
100 Highlight();
101 SetTimeCallback(ms, THISBACK(StopHighlight), TIMEID_HIGHLIGHT);
102 }
103
DockableCtrl()104 DockableCtrl::DockableCtrl()
105 {
106 style = NULL;
107 group = Null;
108 maxsize = Null;
109 stdsize = Null;
110 minsize = Size(0, 0);
111 keycode = 0;
112 keyinfo = 0;
113 AllowDockAll();
114 Transparent(true);
115 BackPaint();
116 }
117
DockableCtrlImgsLook(Value * look,int i,int n)118 void DockableCtrlImgsLook(Value* look, int i, int n)
119 {
120 while(n--)
121 *look++ = ChLookWith(Null, DockingImg::Get(i++), Point(0, 0)); // Center image
122 }
123
ChCrop(const Value & element,Size canvas,Rect crop,Color baseline)124 Image ChCrop(const Value& element, Size canvas, Rect crop, Color baseline)
125 {
126 ImageDraw draw(canvas);
127 ChPaint(draw, canvas, element);
128 if (!IsNull(baseline)) {
129 draw.DrawLine(0, canvas.cy-1, canvas.cx+1, canvas.cy, 1, baseline);
130 }
131 return Crop(draw, crop);
132 }
133
StandardHighlight(Color inside,Color border)134 Image StandardHighlight(Color inside, Color border)
135 {
136 Size sz(5, 5);
137 ImageBuffer ib(sz);
138 RGBA *q = ~ib;
139 for (int i = 0; i < 5; i++)
140 for (int j = 0; j < 5; j++)
141 *(q++) = (i == 4 || j == 4 || !i || !j) ? border : inside;
142 ib.SetHotSpot(Point(1, 1));
143 ib.Set2ndSpot(Point(3, 3));
144 return ib;
145 }
146
AlphaHighlight(const Image & img,int alpha)147 Image AlphaHighlight(const Image& img, int alpha)
148 {
149 ImageDraw draw(img.GetSize());
150 draw.Alpha().DrawRect(img.GetSize(), GrayColor(alpha));
151 draw.DrawImage(0, 0, img);
152 // Is there a better way to set hotspots than this?
153 Image temp = (Image)draw; // GCC
154 ImageBuffer ib(temp);
155 ib.SetHotSpot(Point(1, 1));
156 ib.Set2ndSpot(Point(3, 3));
157 return ib;
158 }
159
CH_STYLE(DockableCtrl,Style,StyleDefault)160 CH_STYLE(DockableCtrl, Style, StyleDefault)
161 {
162 const TabCtrl::Style *style = &TabCtrl::StyleDefault();
163
164 #ifdef PLATFORM_COCOA
165 handle[0] = SColorFace();
166 handle[1] = SColorHighlight();
167 #else
168 handle[0] = ChCrop(style->normal[0], Size(20, 20), Rect(2, 2, 11, 20), SColorShadow); // No focus
169 handle[1] = Colorize(handle[0], SColorHighlight(), 160); // Focus
170 #endif
171 handle_margins = Rect(2, 0, 0, 0);
172 handle_vert = false;
173
174 title_font = StdFont();
175 title_ink[0] = SColorInfoText(); // No focus
176 title_ink[1] = SColorHighlightText(); // Focus
177
178 DockableCtrlImgsLook(close, DockingImg::I_DClosed, 4);
179 DockableCtrlImgsLook(windowpos, DockingImg::I_DMenud, 4);
180 DockableCtrlImgsLook(autohide, DockingImg::I_DHided, 4);
181 DockableCtrlImgsLook(pin, DockingImg::I_DPind, 4);
182
183 Image img = StandardHighlight(Blend(SColorHighlight, SColorPaper, 90), Blend(SColorHighlight, SBlack, 90));
184 highlight[0] = img;
185 highlight[1] = AlphaHighlight(img, 160);
186 }
187
CH_STYLE(DockableCtrl,Style,StyleDefaultVert)188 CH_STYLE(DockableCtrl, Style, StyleDefaultVert)
189 {
190 Assign(DockableCtrl::StyleDefault());
191
192 handle[0] = RotateAntiClockwise(handle[0]); // No focus
193 handle[1] = RotateAntiClockwise(handle[1]); // Focus
194 handle_margins = Rect(0, 2, 2, 1);
195 handle_vert = true;
196 }
197
198 }
199