-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXPMFoldPanel.cpp
432 lines (370 loc) · 15.3 KB
/
XPMFoldPanel.cpp
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
/***************************************************************
* Plugin: XPMEditor for Code::Blocks
* Name: XPMFoldPanel.cpp
* Purpose: A panel containing iall the other tool panels, collapsible - code
* Author: Seb ([email protected])
* Created: 2010-05-19
* Copyright: Seb ()
* License: GPL 3.0
**************************************************************/
#include "XPMEditorPanel.h"
#include "XPMFoldPanel.h"
#include "XPMToolPanel.h"
#include "XPMImageManipulationPanel.h"
#include "XPMImagePropertiesPanel.h"
#include "XPMHelpPanel.h"
//#include <sdk.h>
#include <wx/scrolbar.h>
#include <wx/settings.h>
//#include <sdk.h> // Code::Blocks SDK
//(*InternalHeaders(XPMFoldPanel)
#include <wx/intl.h>
#include <wx/string.h>
//*)
//(*IdInit(XPMFoldPanel)
const long XPMFoldPanel::ID_FOLDPANELBAR1 = wxNewId();
//*)
BEGIN_EVENT_TABLE(XPMFoldPanel,wxPanel)
//(*EventTable(XPMFoldPanel)
//*)
END_EVENT_TABLE()
XPMFoldPanel::XPMFoldPanel(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
BuildContent(parent,id,pos,size);
CreateSubPanels();
//expand some panels
FoldPanelBar1->Expand((size_t) 0, false); //expand tools panel
FoldPanelBar1->Expand((size_t) 3, false); //expand help panel
if (MainSizer) MainSizer->Layout();
}
void XPMFoldPanel::BuildContent(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
//(*Initialize(XPMFoldPanel)
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("wxID_ANY"));
MainSizer = new wxBoxSizer(wxHORIZONTAL);
FoldPanelBar1 = new wxFoldPanelEx(this);
MainSizer->Add(FoldPanelBar1, 1, wxALL|wxEXPAND, 0);
SetSizer(MainSizer);
MainSizer->Fit(this);
MainSizer->SetSizeHints(this);
//*)
ToolPanel = NULL;
ManipulationPanel = NULL;
PropertiesPanel = NULL;
HelpPanel = NULL;
}
XPMFoldPanel::~XPMFoldPanel()
{
//(*Destroy(XPMFoldPanel)
//*)
}
/** Create the various collapsible panels
*/
void XPMFoldPanel::CreateSubPanels(void)
{
//create the various collapsible panels
if (!FoldPanelBar1) return;
//create all the sub-panels first
ToolPanel = new XPMToolPanel(this); //Main tool buttons
ManipulationPanel = new XPMImageManipulationPanel(this); //Image Manipulation panel
PropertiesPanel = new XPMImagePropertiesPanel(this); //Image Properties panel
HelpPanel = new XPMHelpPanel(this); //Help panel
//add the panels to the foldbar
FoldPanelBar1->AddFoldPanel(_("Tools"), ToolPanel, WX_CAPTION_NORMAL); //Main tool buttons
FoldPanelBar1->AddFoldPanel(_("Image Modification"), ManipulationPanel, WX_CAPTION_NORMAL); //Image Manipulation panel
FoldPanelBar1->AddFoldPanel(_("Image Properties"), PropertiesPanel, WX_CAPTION_NORMAL); //Image Properties panel
FoldPanelBar1->AddFoldPanel(_("Help"), HelpPanel, WX_CAPTION_NORMAL); //Help panel
ComputeDimensions();
if (MainSizer)
{
MainSizer->Layout();
MainSizer->Fit(this);
}
}
/** Return the best size of the panel
* \return : the ideal size of the caption bar + the child panel
* orientation + expanded / collapsed state are taken into account
*/
wxSize XPMFoldPanel::DoGetBestSize(void)
{
ComputeDimensions();
//Manager::Get()->GetLogManager()->Log(_("XPMFoldPanel::DoGetBestSize"));
return(m_sBestSize);
}
/** Return the minimal size of the panel
* \return : the ideal size of the caption bar + the child panel
* orientation + expanded / collapsed state are taken into account
*/
wxSize XPMFoldPanel::DoGetMinSize(void)
{
ComputeDimensions();
//Manager::Get()->GetLogManager()->Log(_("XPMFoldPanel::DoGetMinSize"));
return(m_sMinSize);
}
/** Return the absolute minimal size of the panel (only the caption bars + 10)
* \return : the ideal size of the caption bar + the child panel
* orientation + expanded / collapsed state are taken into account
*/
wxSize XPMFoldPanel::DoGetAbsoluteMinimalSize(void)
{
ComputeDimensions();
//Manager::Get()->GetLogManager()->Log(_("XPMFoldPanel::DoGetMinSize"));
return(m_sAbsMinSize);
}
/** Return the maximal size of the panel
* \return : the ideal size of the caption bar + the child panel
* orientation + expanded / collapsed state are taken into account
*/
wxSize XPMFoldPanel::DoGetMaxSize(void)
{
ComputeDimensions();
//Manager::Get()->GetLogManager()->Log(_("XPMFoldPanel::DoGetMaxSize"));
return(m_sMaxSize);
}
void XPMFoldPanel::ComputeDimensions(void)
{
wxSize sCaptionBarSize(0,0);
wxSize sToolPanelSize(0,0);
wxSize sImagePropertiesPanelSize(0,0);
wxSize sImageManipulationPanelSize(0,0);
wxSize sHelpPanelSize(0,0);
wxFoldItemEx *f;
int iWidth, iHeight;
int iWidthMax, iHeightMax;
int iWidthAbs, iHeightAbs;
//default size
iWidth = 50;
iHeight = 50;
iWidthMax = 100;
iHeightMax = 100;
iWidthAbs = 10;
iHeightAbs = 10;
if (FoldPanelBar1)
{
//get the size of a caption bar
f = FoldPanelBar1->GetFoldItem(0);
if (f)
{
wxCaptionBarEx *c;
c = f->GetCaptionBar();
if (c) sCaptionBarSize = c->GetBestSize();
}
//get the size of all fold panels
//tool panel
if (f)
{
wxWindow *p;
p = f->GetChildWindow();
if (p) sToolPanelSize = p->GetBestSize();
}
//image manipulation panel
f = FoldPanelBar1->GetFoldItem(1);
if (f)
{
wxWindow *p;
p = f->GetChildWindow();
if (p) sImageManipulationPanelSize = p->GetBestSize();
}
//image properties panel
f = FoldPanelBar1->GetFoldItem(2);
if (f)
{
wxWindow *p;
p = f->GetChildWindow();
if (p) sImagePropertiesPanelSize = p->GetBestSize();
}
//help panel
f = FoldPanelBar1->GetFoldItem(3);
if (f)
{
wxWindow *p;
p = f->GetChildWindow();
if (p) sHelpPanelSize = p->GetBestSize();
}
/*
//log
iHeight = GetHorizontalScrollBarHeight();
iWidth = GetVerticalScrollBarWidth();
Manager::Get()->GetLogManager()->Log(_("-----------------------------------------------------------------"));
Manager::Get()->GetLogManager()->Log(wxString::Format(_("XPMFoldPanel::ComputeDimensions Caption Bar w=%d h=%d"), sCaptionBarSize.GetWidth(), sCaptionBarSize.GetHeight()));
Manager::Get()->GetLogManager()->Log(wxString::Format(_("XPMFoldPanel::ComputeDimensions Tool Panel w=%d h=%d"), sToolPanelSize.GetWidth(), sToolPanelSize.GetHeight()));
Manager::Get()->GetLogManager()->Log(wxString::Format(_("XPMFoldPanel::ComputeDimensions Manipulation w=%d h=%d"), sImageManipulationPanelSize.GetWidth(), sImageManipulationPanelSize.GetHeight()));
Manager::Get()->GetLogManager()->Log(wxString::Format(_("XPMFoldPanel::ComputeDimensions Properties w=%d h=%d"), sImagePropertiesPanelSize.GetWidth(), sImagePropertiesPanelSize.GetHeight()));
Manager::Get()->GetLogManager()->Log(wxString::Format(_("XPMFoldPanel::ComputeDimensions Help Panel w=%d h=%d"), sHelpPanelSize.GetWidth(), sHelpPanelSize.GetHeight()));
Manager::Get()->GetLogManager()->Log(wxString::Format(_("XPMFoldPanel::ComputeDimensions Scrollbars w=%d h=%d"), iWidth, iHeight));
Manager::Get()->GetLogManager()->Log(_("-----------------------------------------------------------------"));
*/
//compute the default size for each
if (FoldPanelBar1->IsVertical())
{
//vertical panel
//width is the greatest of all widths.
//height is the sum of all Caption bars height, + the height of the biggest panel
int iw;
//width calculation
iWidth = sCaptionBarSize.GetWidth();
if (sToolPanelSize.GetWidth() > iWidth) iWidth = sToolPanelSize.GetWidth();
if (sImageManipulationPanelSize.GetWidth() > iWidth) iWidth = sImageManipulationPanelSize.GetWidth();
if (sImagePropertiesPanelSize.GetWidth() > iWidth) iWidth = sImagePropertiesPanelSize.GetWidth();
if (sHelpPanelSize.GetWidth() > iWidth) iWidth = sHelpPanelSize.GetWidth();
//add the width of a vertical scrollbar
iw = GetVerticalScrollBarWidth();
if (iw > 0) iWidth = iWidth + iw;
iWidthMax = iWidth;
iWidthAbs = iWidth;
//height calculation
iHeight = sToolPanelSize.GetHeight();
if (sImageManipulationPanelSize.GetHeight() > iHeight) iHeight = sImageManipulationPanelSize.GetHeight();
if (sImagePropertiesPanelSize.GetHeight() > iHeight) iHeight = sImagePropertiesPanelSize.GetHeight();
if (sHelpPanelSize.GetHeight() > iHeight) iHeight = sHelpPanelSize.GetHeight();
iHeight = iHeight + 4 * sCaptionBarSize.GetHeight();
iHeightMax = 4 * sCaptionBarSize.GetHeight();
iHeightMax += sToolPanelSize.GetHeight();
iHeightMax += sImageManipulationPanelSize.GetHeight();
iHeightMax += sImagePropertiesPanelSize.GetHeight();
iHeightMax += sHelpPanelSize.GetHeight();
iHeightAbs = 10 + 4 * sCaptionBarSize.GetHeight();
}
else
{
//horizontal panel
//width is the sum of all Caption bars width, + the width of the biggest panel
//height is the greatest of all height.
int ih;
//width calculation
iWidth = sToolPanelSize.GetWidth();
if (sImageManipulationPanelSize.GetWidth() > iWidth) iWidth = sImageManipulationPanelSize.GetWidth();
if (sImagePropertiesPanelSize.GetWidth() > iWidth) iWidth = sImagePropertiesPanelSize.GetWidth();
if (sHelpPanelSize.GetWidth() > iWidth) iWidth = sHelpPanelSize.GetWidth();
iWidth = iWidth + 4 * sCaptionBarSize.GetWidth();
iWidthMax = 4 * sCaptionBarSize.GetWidth();
iWidthMax += sToolPanelSize.GetWidth();
iWidthMax += sImageManipulationPanelSize.GetWidth();
iWidthMax += sImagePropertiesPanelSize.GetWidth();
iWidthMax += sHelpPanelSize.GetWidth();
iWidthAbs = 10 + 4 * sCaptionBarSize.GetWidth();
//height calculation
iHeight = sCaptionBarSize.GetHeight();
if (sToolPanelSize.GetHeight() > iHeight) iHeight = sToolPanelSize.GetHeight();
if (sImageManipulationPanelSize.GetHeight() > iHeight) iHeight = sImageManipulationPanelSize.GetHeight();
if (sImagePropertiesPanelSize.GetHeight() > iHeight) iHeight = sImagePropertiesPanelSize.GetHeight();
if (sHelpPanelSize.GetHeight() > iHeight) iHeight = sHelpPanelSize.GetHeight();
//add the height of a horizontal scrollbar
ih = GetHorizontalScrollBarHeight();
if (ih > 0) iHeight = iHeight + ih;
iHeightMax = iHeight;
iHeightAbs = iHeight;
}
}
/*
Manager::Get()->GetLogManager()->Log(_("-----------------------------------------------------------------"));
Manager::Get()->GetLogManager()->Log(wxString::Format(_("XPMFoldPanel::ComputeDimensions TOTAL w=%d h=%d"), iWidth, iHeight));
Manager::Get()->GetLogManager()->Log(wxString::Format(_("XPMFoldPanel::ComputeDimensions TOTAL MAX w=%d h=%d"), iWidthMax, iHeightMax));
Manager::Get()->GetLogManager()->Log(_("-----------------------------------------------------------------"));
*/
SetMinSize(wxSize(iWidth, iHeight));
SetMaxSize(wxSize(iWidthMax, iHeightMax));
m_sMinSize = wxSize(iWidth, iHeight);
m_sBestSize = wxSize(iWidth, iHeight);
m_sMaxSize = wxSize(iWidthMax, iHeightMax);
m_sAbsMinSize = wxSize(iWidthAbs, iHeightAbs);
}
/** Set the parent of the panels
* \param parent : the functionnal parent of the panel
*/
void XPMFoldPanel::SetParentPanel(XPMEditorPanel *parent)
{
if (ToolPanel) ToolPanel->SetParentPanel(parent);
if (ManipulationPanel) ManipulationPanel->SetParentPanel(parent);
if (PropertiesPanel) PropertiesPanel->SetParentPanel(parent);
if (HelpPanel) HelpPanel->SetParentPanel(parent);
ComputeDimensions();
if (MainSizer)
{
MainSizer->Layout();
MainSizer->Fit(this);
}
}
//---- GET POINTERS TO CHILD PANELS ------------------//
/**return a pointer to the Tool Panel
*\return : a pointer to the wxPanel on success, NULL otherwise
*/
XPMToolPanel* XPMFoldPanel::GetToolPanel(void)
{
//return a pointer to the Tool Panel
return(ToolPanel);
}
/**return a pointer to the Tool Panel
*\return : a pointer to the wxPanel on success, NULL otherwise
*/
XPMHelpPanel* XPMFoldPanel::GetHelpPanel(void)
{
//return a pointer to the Help Panel
return(HelpPanel);
}
/**return a pointer to the Image Properties Panel
*\return : a pointer to the wxPanel on success, NULL otherwise
*/
XPMImagePropertiesPanel* XPMFoldPanel::GetPropertiesPanel(void)
{
//return a pointer to the Image Properties Panel
return(PropertiesPanel);
}
/**return a pointer to the Image Manipulation Panel
*\return : a pointer to the wxPanel on success, NULL otherwise
*/
XPMImageManipulationPanel* XPMFoldPanel::GetImageManipulationPanel(void)
{
//return a pointer to the Image Manipulation Panel
return(ManipulationPanel);
}
/** return the width of a standard vertical scrollbar
* \return the width of a standard vertical scrollbar
*/
int XPMFoldPanel::GetVerticalScrollBarWidth(void)
{
int iResult1, iResult2, iResult;
wxSize sSize;
iResult1 = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
iResult2 = wxSystemSettings::GetMetric(wxSYS_VSCROLL_ARROW_X);
iResult = iResult1;
if (iResult2 > iResult) iResult = iResult2;
if (iResult < 0)
{
//create a scrollbar and destroy it
wxScrollBar *sb;
sb = new wxScrollBar(this, wxNewId(), wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
if (sb)
{
sSize = sb->GetBestSize();
iResult = sSize.GetWidth();
sb->Destroy();
}
}
return(iResult);
}
/** return the height of a standard horizontal scrollbar
* \return the height of a standard horizontal scrollbar
*/
int XPMFoldPanel::GetHorizontalScrollBarHeight(void)
{
int iResult1, iResult2, iResult;
wxSize sSize;
iResult1 = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
iResult2 = wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_Y);
iResult = iResult1;
if (iResult2 > iResult) iResult = iResult2;
if (iResult < 0)
{
//create a scrollbar and destroy it
wxScrollBar *sb;
sb = new wxScrollBar(this, wxNewId(), wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL);
if (sb)
{
sSize = sb->GetBestSize();
iResult = sSize.GetHeight();
sb->Destroy();
}
}
return(iResult);
}