]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/reseditr.cpp
*** empty log message ***
[wxWidgets.git] / utils / dialoged / src / reseditr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: reseditr.cpp
3 // Purpose: Resource editor class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "reseditr.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25
26 #include "wx/checkbox.h"
27 #include "wx/button.h"
28 #include "wx/choice.h"
29 #include "wx/listbox.h"
30 #include "wx/radiobox.h"
31 #include "wx/statbox.h"
32 #include "wx/gauge.h"
33 #include "wx/slider.h"
34 #include "wx/textctrl.h"
35 #endif
36
37 #include "wx/scrolbar.h"
38
39 #include <ctype.h>
40 #include <stdlib.h>
41 #include <math.h>
42 #include <string.h>
43
44 #if defined(__WINDOWS__) && !defined(__GNUWIN32__)
45 #include <strstrea.h>
46 #else
47 #include <strstream.h>
48 #endif
49
50 #ifdef __WINDOWS__
51 #include <windows.h>
52 #endif
53
54 #include "wx/help.h"
55
56 #include "reseditr.h"
57 #include "winprop.h"
58 #include "editrpal.h"
59 #include "dlghndlr.h"
60
61 static void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event);
62 void wxResourceEditWindow(wxWindow *win);
63 wxWindowPropertyInfo *wxCreatePropertyInfoForWindow(wxWindow *win);
64 wxResourceManager *wxResourceManager::currentResourceManager = NULL;
65
66 // Bitmaps for toolbar
67 wxBitmap *ToolbarLoadBitmap = NULL;
68 wxBitmap *ToolbarSaveBitmap = NULL;
69 wxBitmap *ToolbarNewBitmap = NULL;
70 wxBitmap *ToolbarVertBitmap = NULL;
71 wxBitmap *ToolbarAlignTBitmap = NULL;
72 wxBitmap *ToolbarAlignBBitmap = NULL;
73 wxBitmap *ToolbarHorizBitmap = NULL;
74 wxBitmap *ToolbarAlignLBitmap = NULL;
75 wxBitmap *ToolbarAlignRBitmap = NULL;
76 wxBitmap *ToolbarCopySizeBitmap = NULL;
77 wxBitmap *ToolbarToFrontBitmap = NULL;
78 wxBitmap *ToolbarToBackBitmap = NULL;
79 wxBitmap *ToolbarHelpBitmap = NULL;
80
81 wxBitmap *wxWinBitmap = NULL;
82
83 #ifdef __X__
84 #include "bitmaps/load.xbm"
85 #include "bitmaps/save.xbm"
86 #include "bitmaps/new.xbm"
87 #include "bitmaps/vert.xbm"
88 #include "bitmaps/alignt.xbm"
89 #include "bitmaps/alignb.xbm"
90 #include "bitmaps/horiz.xbm"
91 #include "bitmaps/alignl.xbm"
92 #include "bitmaps/alignr.xbm"
93 #include "bitmaps/copysize.xbm"
94 #include "bitmaps/tofront.xbm"
95 #include "bitmaps/toback.xbm"
96 #include "bitmaps/help.xbm"
97 #include "bitmaps/wxwin.xbm"
98 #endif
99
100 /*
101 * Resource manager
102 */
103
104
105 wxResourceManager::wxResourceManager(void)
106 {
107 currentResourceManager = this;
108 editorFrame = NULL;
109 editorPanel = NULL;
110 popupMenu = NULL;
111 editorResourceList = NULL;
112 editorPalette = NULL;
113 nameCounter = 1;
114 modified = FALSE;
115 currentFilename = "";
116 editMode = TRUE;
117 editorToolBar = NULL;
118
119 // Default window positions
120 resourceEditorWindowSize.width = 470;
121 resourceEditorWindowSize.height = 300;
122
123 resourceEditorWindowSize.x = 0;
124 resourceEditorWindowSize.y = 0;
125
126 propertyWindowSize.width = 300;
127 propertyWindowSize.height = 300;
128
129 helpInstance = NULL;
130 }
131
132 wxResourceManager::~wxResourceManager(void)
133 {
134 currentResourceManager = NULL;
135 SaveOptions();
136
137 helpInstance->Quit();
138 delete helpInstance;
139 helpInstance = NULL;
140 }
141
142 bool wxResourceManager::Initialize(void)
143 {
144 // Set up the resource filename for each platform.
145 #ifdef __WINDOWS__
146 // dialoged.ini in the Windows directory
147 char buf[256];
148 GetWindowsDirectory(buf, 256);
149 strcat(buf, "\\dialoged.ini");
150 optionsResourceFilename = buf;
151 #elif defined(__X__)
152 char buf[500];
153 (void)wxGetHomeDir(buf);
154 strcat(buf, "/.hardyrc");
155 optionsResourceFilename = buf;
156 #else
157 #error "Unsupported platform."
158 #endif
159
160 LoadOptions();
161
162 helpInstance = new wxHelpController;
163 helpInstance->Initialize("dialoged");
164
165 InitializeTools();
166 popupMenu = new wxMenu("", (wxFunction)ObjectMenuProc);
167 popupMenu->Append(OBJECT_MENU_EDIT, "Edit properties");
168 popupMenu->Append(OBJECT_MENU_DELETE, "Delete object");
169
170 if (!wxWinBitmap)
171 {
172 #ifdef __WINDOWS__
173 wxWinBitmap = new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE);
174 #endif
175 #ifdef __X__
176 wxWinBitmap = new wxBitmap(wxwin_bits, wxwin_width, wxwin_height);
177 #endif
178 }
179 return TRUE;
180 }
181
182 bool wxResourceManager::LoadOptions(void)
183 {
184 wxGetResource("DialogEd", "editorWindowX", &resourceEditorWindowSize.x, optionsResourceFilename.GetData());
185 wxGetResource("DialogEd", "editorWindowY", &resourceEditorWindowSize.y, optionsResourceFilename.GetData());
186 wxGetResource("DialogEd", "editorWindowWidth", &resourceEditorWindowSize.width, optionsResourceFilename.GetData());
187 wxGetResource("DialogEd", "editorWindowHeight", &resourceEditorWindowSize.height, optionsResourceFilename.GetData());
188 wxGetResource("DialogEd", "propertyWindowX", &propertyWindowSize.x, optionsResourceFilename.GetData());
189 wxGetResource("DialogEd", "propertyWindowY", &propertyWindowSize.y, optionsResourceFilename.GetData());
190 wxGetResource("DialogEd", "propertyWindowWidth", &propertyWindowSize.width, optionsResourceFilename.GetData());
191 wxGetResource("DialogEd", "propertyWindowHeight", &propertyWindowSize.height, optionsResourceFilename.GetData());
192 return TRUE;
193 }
194
195 bool wxResourceManager::SaveOptions(void)
196 {
197 wxWriteResource("DialogEd", "editorWindowX", resourceEditorWindowSize.x, optionsResourceFilename.GetData());
198 wxWriteResource("DialogEd", "editorWindowY", resourceEditorWindowSize.y, optionsResourceFilename.GetData());
199 wxWriteResource("DialogEd", "editorWindowWidth", resourceEditorWindowSize.width, optionsResourceFilename.GetData());
200 wxWriteResource("DialogEd", "editorWindowHeight", resourceEditorWindowSize.height, optionsResourceFilename.GetData());
201
202 wxWriteResource("DialogEd", "propertyWindowX", propertyWindowSize.x, optionsResourceFilename.GetData());
203 wxWriteResource("DialogEd", "propertyWindowY", propertyWindowSize.y, optionsResourceFilename.GetData());
204 wxWriteResource("DialogEd", "propertyWindowWidth", propertyWindowSize.width, optionsResourceFilename.GetData());
205 wxWriteResource("DialogEd", "propertyWindowHeight", propertyWindowSize.height, optionsResourceFilename.GetData());
206
207 return TRUE;
208 }
209
210 // Show or hide the resource editor frame, which displays a list
211 // of resources with ability to edit them.
212 bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *parent, const char *title)
213 {
214 if (show)
215 {
216 if (editorFrame)
217 {
218 editorFrame->Iconize(FALSE);
219 editorFrame->Show(TRUE);
220 return TRUE;
221 }
222 editorFrame = OnCreateEditorFrame(title);
223 SetFrameTitle("");
224 wxMenuBar *menuBar = OnCreateEditorMenuBar(editorFrame);
225 editorFrame->SetMenuBar(menuBar);
226 editorPanel = OnCreateEditorPanel(editorFrame);
227 editorToolBar = (EditorToolBar *)OnCreateToolBar(editorFrame);
228 editorPalette = OnCreatePalette(editorFrame);
229
230 // Constraints for toolbar
231 wxLayoutConstraints *c = new wxLayoutConstraints;
232 c->left.SameAs (editorFrame, wxLeft, 0);
233 c->top.SameAs (editorFrame, wxTop, 0);
234 c->right.SameAs (editorFrame, wxRight, 0);
235 c->bottom.Unconstrained();
236 c->width.Unconstrained();
237 c->height.Absolute(28);
238 editorToolBar->SetConstraints(c);
239
240 // Constraints for palette
241 c = new wxLayoutConstraints;
242 c->left.SameAs (editorFrame, wxLeft, 0);
243 c->top.SameAs (editorToolBar, wxBottom, 0);
244 c->right.SameAs (editorFrame, wxRight, 0);
245 c->bottom.Unconstrained();
246 c->width.Unconstrained();
247 c->height.Absolute(34);
248 editorPalette->SetConstraints(c);
249
250 // Constraints for panel
251 c = new wxLayoutConstraints;
252 c->left.SameAs (editorFrame, wxLeft, 0);
253 c->top.SameAs (editorPalette, wxBottom, 0);
254 c->right.SameAs (editorFrame, wxRight, 0);
255 c->bottom.SameAs (editorFrame, wxBottom, 0);
256 c->width.Unconstrained();
257 c->height.Unconstrained();
258 editorPanel->SetConstraints(c);
259
260 editorFrame->SetAutoLayout(TRUE);
261
262 UpdateResourceList();
263 editorFrame->Show(TRUE);
264 return TRUE;
265 }
266 else
267 {
268 wxFrame *fr = editorFrame;
269 if (editorFrame->OnClose())
270 {
271 fr->Show(FALSE);
272 delete fr;
273 editorFrame = NULL;
274 editorPanel = NULL;
275 }
276 }
277 return TRUE;
278 }
279
280 void wxResourceManager::SetFrameTitle(const wxString& filename)
281 {
282 if (editorFrame)
283 {
284 if (filename == wxString(""))
285 editorFrame->SetTitle("wxWindows Dialog Editor - untitled");
286 else
287 {
288 wxString str("wxWindows Dialog Editor - ");
289 wxString str2(wxFileNameFromPath(WXSTRINGCAST filename));
290 str += str2;
291 editorFrame->SetTitle(str);
292 }
293 }
294 }
295
296 bool wxResourceManager::Save(void)
297 {
298 if (currentFilename == wxString(""))
299 return SaveAs();
300 else
301 return Save(currentFilename);
302 }
303
304 bool wxResourceManager::Save(const wxString& filename)
305 {
306 // Ensure all visible windows are saved to their resources
307 currentFilename = filename;
308 SetFrameTitle(currentFilename);
309 InstantiateAllResourcesFromWindows();
310 if (resourceTable.Save(filename))
311 {
312 Modify(FALSE);
313 return TRUE;
314 }
315 else
316 return FALSE;
317 }
318
319 bool wxResourceManager::SaveAs(void)
320 {
321 wxString s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST currentFilename), wxFileNameFromPath(WXSTRINGCAST currentFilename),
322 "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT));
323
324 if (s.IsNull() || s == "")
325 return FALSE;
326
327 currentFilename = s;
328 Save(currentFilename);
329 return TRUE;
330 }
331
332 bool wxResourceManager::SaveIfModified(void)
333 {
334 if (Modified())
335 return Save();
336 else return TRUE;
337 }
338
339 bool wxResourceManager::Load(const wxString& filename)
340 {
341 return New(TRUE, filename);
342 }
343
344 bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
345 {
346 if (!Clear(TRUE, FALSE))
347 return FALSE;
348
349 if (loadFromFile)
350 {
351 wxString str = filename;
352 if (str == wxString(""))
353 {
354 wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, NULL));
355 if (!f.IsNull() && f != "")
356 str = f;
357 else
358 return FALSE;
359 }
360
361 if (!resourceTable.ParseResourceFile(WXSTRINGCAST str))
362 {
363 wxMessageBox("Could not read file.", "Resource file load error", wxOK | wxICON_EXCLAMATION);
364 return FALSE;
365 }
366 currentFilename = str;
367
368 SetFrameTitle(currentFilename);
369
370 UpdateResourceList();
371 }
372 else
373 {
374 SetFrameTitle("");
375 currentFilename = "";
376 }
377 Modify(FALSE);
378
379 return TRUE;
380 }
381
382 bool wxResourceManager::Clear(bool deleteWindows, bool force)
383 {
384 if (!force && Modified())
385 {
386 int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL);
387 if (ans == wxCANCEL)
388 return FALSE;
389 if (ans == wxYES)
390 if (!SaveIfModified())
391 return FALSE;
392 if (ans == wxNO)
393 Modify(FALSE);
394 }
395
396 DisassociateWindows(deleteWindows);
397
398 resourceTable.ClearTable();
399 UpdateResourceList();
400
401 return TRUE;
402 }
403
404 bool wxResourceManager::DisassociateWindows(bool deleteWindows)
405 {
406 resourceTable.BeginFind();
407 wxNode *node;
408 while (node = resourceTable.Next())
409 {
410 wxItemResource *res = (wxItemResource *)node->Data();
411 DisassociateResource(res, deleteWindows);
412 }
413
414 return TRUE;
415 }
416
417 void wxResourceManager::AssociateResource(wxItemResource *resource, wxWindow *win)
418 {
419 if (!resourceAssociations.Get((long)resource))
420 resourceAssociations.Put((long)resource, win);
421
422 wxNode *node = resource->GetChildren().First();
423 while (node)
424 {
425 wxItemResource *child = (wxItemResource *)node->Data();
426 wxWindow *childWindow = (wxWindow *)resourceAssociations.Get((long)child);
427 if (!childWindow)
428 childWindow = win->FindWindow(child->GetName());
429 if (childWindow)
430 AssociateResource(child, childWindow);
431 else
432 {
433 char buf[200];
434 sprintf(buf, "AssociateResource: cannot find child window %s", child->GetName() ? child->GetName() : "(unnamed)");
435 wxMessageBox(buf, "Dialog Editor problem", wxOK);
436 }
437
438 node = node->Next();
439 }
440 }
441
442 bool wxResourceManager::DisassociateResource(wxItemResource *resource, bool deleteWindow)
443 {
444 wxWindow *win = FindWindowForResource(resource);
445 if (!win)
446 return FALSE;
447
448 // Disassociate children of window without deleting windows
449 // since they'll be deleted by parent.
450 if (win->GetChildren())
451 {
452 wxNode *node = win->GetChildren()->First();
453 while (node)
454 {
455 wxWindow *child = (wxWindow *)node->Data();
456 if (child->IsKindOf(CLASSINFO(wxControl)))
457 DisassociateResource(child, FALSE);
458 node = node->Next();
459 }
460 }
461
462 if (deleteWindow)
463 {
464 if (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)))
465 delete win->GetParent(); // Delete frame
466 else if ( win->IsKindOf(CLASSINFO(wxControl)) )
467 {
468 wxEvtHandler *childHandler = win->GetEventHandler();
469 if ( childHandler != win )
470 {
471 win->PopEventHandler();
472 delete childHandler;
473 }
474 delete win;
475 }
476 else
477 // Is this enough? What about event handler? TODO
478 delete win;
479 }
480 RemoveSelection(win);
481 resourceAssociations.Delete((long)resource);
482 return TRUE;
483 }
484
485 bool wxResourceManager::DisassociateResource(wxWindow *win, bool deleteWindow)
486 {
487 wxItemResource *res = FindResourceForWindow(win);
488 if (res)
489 return DisassociateResource(res, deleteWindow);
490 return FALSE;
491 }
492
493 wxItemResource *wxResourceManager::FindResourceForWindow(wxWindow *win)
494 {
495 resourceAssociations.BeginFind();
496 wxNode *node;
497 while (node = resourceAssociations.Next())
498 {
499 wxWindow *w = (wxWindow *)node->Data();
500 if (w == win)
501 {
502 return (wxItemResource *)node->key.integer;
503 }
504 }
505 return NULL;
506 }
507
508 wxWindow *wxResourceManager::FindWindowForResource(wxItemResource *resource)
509 {
510 return (wxWindow *)resourceAssociations.Get((long)resource);
511 }
512
513
514 void wxResourceManager::MakeUniqueName(char *prefix, char *buf)
515 {
516 while (TRUE)
517 {
518 sprintf(buf, "%s%d", prefix, nameCounter);
519 nameCounter ++;
520
521 if (!resourceTable.FindResource(buf))
522 return;
523 }
524 }
525
526 wxFrame *wxResourceManager::OnCreateEditorFrame(const char *title)
527 {
528 int frameWidth = 420;
529 int frameHeight = 300;
530
531 wxResourceEditorFrame *frame = new wxResourceEditorFrame(this, NULL, (char *)title,
532
533 resourceEditorWindowSize.x, resourceEditorWindowSize.y,
534 resourceEditorWindowSize.width, resourceEditorWindowSize.height,
535
536 wxDEFAULT_FRAME);
537
538 wxFrame::UseNativeStatusBar(FALSE);
539
540 frame->CreateStatusBar(2);
541
542 wxFrame::UseNativeStatusBar(TRUE);
543
544 frame->SetStatusText(editMode ? "Edit mode" : "Test mode", 1);
545 frame->SetAutoLayout(TRUE);
546 #ifdef __WINDOWS__
547 wxIcon *icon = new wxIcon("DIALOGEDICON");
548 frame->SetIcon(icon);
549 #endif
550 return frame;
551 }
552
553 wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *parent)
554 {
555 wxMenuBar *menuBar = new wxMenuBar;
556
557 wxMenu *fileMenu = new wxMenu;
558 fileMenu->Append(RESED_NEW_DIALOG, "New &dialog", "Create a new dialog");
559 fileMenu->Append(RESED_NEW_PANEL, "New &panel", "Create a new panel");
560 fileMenu->AppendSeparator();
561 fileMenu->Append(wxID_NEW, "&New project", "Clear the current project");
562 fileMenu->Append(wxID_OPEN, "&Open...", "Load a resource file");
563 fileMenu->Append(wxID_SAVE, "&Save", "Save a resource file");
564 fileMenu->Append(wxID_SAVEAS, "Save &As...", "Save a resource file as...");
565 fileMenu->Append(RESED_CLEAR, "&Clear", "Clear current resources");
566 fileMenu->AppendSeparator();
567 fileMenu->Append(wxID_EXIT, "E&xit", "Exit resource editor");
568
569 wxMenu *editMenu = new wxMenu;
570 editMenu->Append(RESED_RECREATE, "&Recreate", "Recreate the selected resource(s)");
571 editMenu->Append(RESED_DELETE, "&Delete", "Delete the selected resource(s)");
572 editMenu->AppendSeparator();
573 editMenu->Append(RESED_TOGGLE_TEST_MODE, "&Toggle edit/test mode", "Toggle edit/test mode");
574
575 wxMenu *helpMenu = new wxMenu;
576 helpMenu->Append(RESED_CONTENTS, "&Help topics", "Invokes the on-line help");
577 helpMenu->AppendSeparator();
578 helpMenu->Append(wxID_ABOUT, "&About", "About wxWindows Dialog Editor");
579
580 menuBar->Append(fileMenu, "&File");
581 menuBar->Append(editMenu, "&Edit");
582 menuBar->Append(helpMenu, "&Help");
583
584 return menuBar;
585 }
586
587 wxPanel *wxResourceManager::OnCreateEditorPanel(wxFrame *parent)
588 {
589 wxResourceEditorPanel *panel = new wxResourceEditorPanel(parent);
590
591 editorResourceList = new wxListBox(panel, -1, wxPoint(0, 0), wxSize(-1, -1));
592
593 wxLayoutConstraints *c = new wxLayoutConstraints;
594 c->left.SameAs (panel, wxLeft, 5);
595 c->top.SameAs (panel, wxTop, 5);
596 c->right.SameAs (panel, wxRight, 5);
597 c->bottom.SameAs (panel, wxBottom, 5);
598 c->width.Unconstrained();
599 c->height.Unconstrained();
600 editorResourceList->SetConstraints(c);
601
602 return panel;
603 }
604
605 wxToolBarBase *wxResourceManager::OnCreateToolBar(wxFrame *parent)
606 {
607 // Load palette bitmaps
608 #ifdef __WINDOWS__
609 ToolbarLoadBitmap = new wxBitmap("LOADTOOL");
610 ToolbarSaveBitmap = new wxBitmap("SAVETOOL");
611 ToolbarNewBitmap = new wxBitmap("NEWTOOL");
612 ToolbarVertBitmap = new wxBitmap("VERTTOOL");
613 ToolbarAlignTBitmap = new wxBitmap("ALIGNTTOOL");
614 ToolbarAlignBBitmap = new wxBitmap("ALIGNBTOOL");
615 ToolbarHorizBitmap = new wxBitmap("HORIZTOOL");
616 ToolbarAlignLBitmap = new wxBitmap("ALIGNLTOOL");
617 ToolbarAlignRBitmap = new wxBitmap("ALIGNRTOOL");
618 ToolbarCopySizeBitmap = new wxBitmap("COPYSIZETOOL");
619 ToolbarToBackBitmap = new wxBitmap("TOBACKTOOL");
620 ToolbarToFrontBitmap = new wxBitmap("TOFRONTTOOL");
621 ToolbarHelpBitmap = new wxBitmap("HELPTOOL");
622 #endif
623 #ifdef __X__
624 ToolbarLoadBitmap = new wxBitmap(load_bits, load_width, load_height);
625 ToolbarSaveBitmap = new wxBitmap(save_bits, save_width, save_height);
626 ToolbarNewBitmap = new wxBitmap(new_bits, save_width, save_height);
627 ToolbarVertBitmap = new wxBitmap(vert_bits, vert_width, vert_height);
628 ToolbarAlignTBitmap = new wxBitmap(alignt_bits, alignt_width, alignt_height);
629 ToolbarAlignBBitmap = new wxBitmap(alignb_bits, alignb_width, alignb_height);
630 ToolbarHorizBitmap = new wxBitmap(horiz_bits, horiz_width, horiz_height);
631 ToolbarAlignLBitmap = new wxBitmap(alignl_bits, alignl_width, alignl_height);
632 ToolbarAlignRBitmap = new wxBitmap(alignr_bits, alignr_width, alignr_height);
633 ToolbarCopySizeBitmap = new wxBitmap(copysize_bits, copysize_width, copysize_height);
634 ToolbarToBackBitmap = new wxBitmap(toback_bits, toback_width, toback_height);
635 ToolbarToFrontBitmap = new wxBitmap(tofront_bits, tofront_width, tofront_height);
636 // ToolbarCPPBitmap = new wxBitmap(cpp_bits, cpp_width, cpp_height);
637 // ToolbarTreeBitmap = new wxBitmap(tree_bits, tree_width, tree_height);
638 ToolbarHelpBitmap = new wxBitmap(help_bits, help_width, help_height);
639 #endif
640
641 // Create the toolbar
642 EditorToolBar *toolbar = new EditorToolBar(parent, 0, 0, -1, -1, wxNO_BORDER,
643 wxVERTICAL, 1);
644 toolbar->SetMargins(2, 2);
645 // toolbar->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH);
646
647 #ifdef __WINDOWS__
648 int width = 24;
649 int dx = 2;
650 int gap = 6;
651 #else
652 int width = ToolbarLoadBitmap->GetWidth();
653 int dx = 2;
654 int gap = 6;
655 #endif
656 int currentX = gap;
657 toolbar->AddSeparator();
658 toolbar->AddTool(TOOLBAR_NEW, ToolbarNewBitmap, (wxBitmap *)NULL,
659 FALSE, (float)currentX, -1, NULL, "New dialog");
660 currentX += width + dx;
661 toolbar->AddTool(TOOLBAR_LOAD_FILE, ToolbarLoadBitmap, (wxBitmap *)NULL,
662 FALSE, (float)currentX, -1, NULL, "Load");
663 currentX += width + dx;
664 toolbar->AddTool(TOOLBAR_SAVE_FILE, ToolbarSaveBitmap, (wxBitmap *)NULL,
665 FALSE, (float)currentX, -1, NULL, "Save");
666 currentX += width + dx + gap;
667 toolbar->AddSeparator();
668 toolbar->AddTool(TOOLBAR_FORMAT_HORIZ, ToolbarVertBitmap, (wxBitmap *)NULL,
669 FALSE, (float)currentX, -1, NULL, "Horizontal align");
670 currentX += width + dx;
671 toolbar->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN, ToolbarAlignTBitmap, (wxBitmap *)NULL,
672 FALSE, (float)currentX, -1, NULL, "Top align");
673 currentX += width + dx;
674 toolbar->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN, ToolbarAlignBBitmap, (wxBitmap *)NULL,
675 FALSE, (float)currentX, -1, NULL, "Bottom align");
676 currentX += width + dx;
677 toolbar->AddTool(TOOLBAR_FORMAT_VERT, ToolbarHorizBitmap, (wxBitmap *)NULL,
678 FALSE, (float)currentX, -1, NULL, "Vertical align");
679 currentX += width + dx;
680 toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN, ToolbarAlignLBitmap, (wxBitmap *)NULL,
681 FALSE, (float)currentX, -1, NULL, "Left align");
682 currentX += width + dx;
683 toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN, ToolbarAlignRBitmap, (wxBitmap *)NULL,
684 FALSE, (float)currentX, -1, NULL, "Right align");
685 currentX += width + dx;
686 toolbar->AddTool(TOOLBAR_COPY_SIZE, ToolbarCopySizeBitmap, (wxBitmap *)NULL,
687 FALSE, (float)currentX, -1, NULL, "Copy size");
688 currentX += width + dx + gap;
689 toolbar->AddSeparator();
690 toolbar->AddTool(TOOLBAR_TO_FRONT, ToolbarToFrontBitmap, (wxBitmap *)NULL,
691 FALSE, (float)currentX, -1, NULL, "To front");
692 currentX += width + dx;
693 toolbar->AddTool(TOOLBAR_TO_BACK, ToolbarToBackBitmap, (wxBitmap *)NULL,
694 FALSE, (float)currentX, -1, NULL, "To back");
695 currentX += width + dx + gap;
696 /*
697 toolbar->AddTool(TOOLBAR_GEN_CPP, ToolbarCPPBitmap, (wxBitmap *)NULL,
698 FALSE, (float)currentX, -1, NULL);
699 currentX += width + dx;
700
701 toolbar->AddTool(TOOLBAR_TREE, ToolbarTreeBitmap, (wxBitmap *)NULL,
702 FALSE, (float)currentX, -1, NULL);
703 currentX += width + dx;
704 */
705 toolbar->AddSeparator();
706 toolbar->AddTool(TOOLBAR_HELP, ToolbarHelpBitmap, (wxBitmap *)NULL,
707 FALSE, (float)currentX, -1, NULL, "Help");
708 currentX += width + dx;
709
710 toolbar->CreateTools();
711
712 return toolbar;
713
714 // parent->OnSize(-1, -1);
715 }
716
717 void wxResourceManager::UpdateResourceList(void)
718 {
719 editorResourceList->Clear();
720 resourceTable.BeginFind();
721 wxNode *node;
722 while (node = resourceTable.Next())
723 {
724 wxItemResource *res = (wxItemResource *)node->Data();
725 wxString resType(res->GetType());
726 // if (res->GetType() == wxTYPE_DIALOG_BOX || res->GetType() == wxTYPE_FRAME || res->GetType() == wxTYPE_BITMAP)
727 if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel" || resType == "wxBitmap")
728 {
729 AddItemsRecursively(0, res);
730 }
731 }
732 }
733
734 void wxResourceManager::AddItemsRecursively(int level, wxItemResource *resource)
735 {
736 int padWidth = level*4;
737
738 wxString theString("");
739 theString.Append(' ', padWidth);
740 theString += resource->GetName();
741
742 editorResourceList->Append(theString.GetData(), (char *)resource);
743
744 if (strcmp(resource->GetType(), "wxBitmap") != 0)
745 {
746 wxNode *node = resource->GetChildren().First();
747 while (node)
748 {
749 wxItemResource *res = (wxItemResource *)node->Data();
750 AddItemsRecursively(level+1, res);
751 node = node->Next();
752 }
753 }
754 }
755
756 bool wxResourceManager::EditSelectedResource(void)
757 {
758 int sel = editorResourceList->GetSelection();
759 if (sel > -1)
760 {
761 wxItemResource *res = (wxItemResource *)editorResourceList->wxListBox::GetClientData(sel);
762 return Edit(res);
763 }
764 return FALSE;
765 }
766
767 bool wxResourceManager::Edit(wxItemResource *res)
768 {
769 wxString resType(res->GetType());
770 if (resType == "wxDialog" || resType == "wxDialogBox")
771 {
772 wxDialog *dialog = (wxDialog *)FindWindowForResource(res);
773 if (dialog)
774 dialog->Show(TRUE);
775 else
776 {
777 dialog = new wxDialog;
778 wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(dialog, res, dialog->GetEventHandler(),
779 this);
780 dialog->PushEventHandler(handler);
781
782 // dialog->SetUserEditMode(TRUE);
783
784 dialog->LoadFromResource(GetEditorFrame(), res->GetName(), &resourceTable);
785 handler->AddChildHandlers(); // Add event handlers for all controls
786 dialog->SetModal(FALSE);
787 AssociateResource(res, dialog);
788 dialog->Show(TRUE);
789 }
790 }
791 else if (resType == "wxPanel")
792 {
793 wxPanel *panel = (wxPanel *)FindWindowForResource(res);
794 if (panel)
795 panel->GetParent()->Show(TRUE);
796 else
797 {
798 DialogEditorPanelFrame *frame = new DialogEditorPanelFrame(GetEditorFrame(), res->GetName(), 10, 10, 400, 300, wxDEFAULT_FRAME_STYLE, res->GetName());
799 panel = new wxPanel;
800 wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, res, panel->GetEventHandler(),
801 this);
802 panel->PushEventHandler(handler);
803 // panel->SetUserEditMode(TRUE);
804
805 panel->LoadFromResource(frame, res->GetName(), &resourceTable);
806 handler->AddChildHandlers(); // Add event handlers for all controls
807 AssociateResource(res, panel);
808 frame->SetClientSize(res->GetWidth(), res->GetHeight());
809 frame->Show(TRUE);
810 }
811 }
812 return FALSE;
813 }
814
815 bool wxResourceManager::CreateNewDialog(void)
816 {
817 char buf[256];
818 MakeUniqueName("dialog", buf);
819
820 wxItemResource *resource = new wxItemResource;
821 // resource->SetType(wxTYPE_DIALOG_BOX);
822 resource->SetType("wxDialog");
823 resource->SetName(buf);
824 resource->SetTitle(buf);
825 resourceTable.AddResource(resource);
826
827 #ifdef __MOTIF__
828 wxDialog *dialog = new wxDialog(GetEditorFrame(), -1, buf, wxPoint(10, 10), wxSize(400, 300), wxDEFAULT_DIALOG_STYLE, buf);
829 /*
830 dialog->SetBackgroundColour(*wxLIGHT_GREY);
831 dialog->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH);
832 dialog->SetButtonColour(*wxBLACK);
833 dialog->SetLabelColour(*wxBLACK);
834 */
835 #else
836 wxDialog *dialog = new wxDialog(GetEditorFrame(), -1, buf, wxPoint(10, 10), wxSize(400, 300), wxDEFAULT_DIALOG_STYLE, buf);
837 #endif
838
839 resource->SetValue1(FALSE); // Modeless to start with
840 resource->SetStyle(dialog->GetWindowStyleFlag());
841
842 // For editing in situ we will need to use the hash table to ensure
843 // we don't dereference invalid pointers.
844 // resourceWindowTable.Put((long)resource, dialog);
845
846 wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(dialog, resource, dialog->GetEventHandler(),
847 this);
848
849 dialog->PushEventHandler(handler);
850
851 dialog->Centre(wxBOTH);
852 // dialog->SetUserEditMode(TRUE);
853 dialog->Show(TRUE);
854
855 SetEditMode(TRUE, FALSE);
856
857 AssociateResource(resource, dialog);
858 // SetCurrentResource(resource);
859 // SetCurrentResourceWindow(dialog);
860 UpdateResourceList();
861
862 Modify(TRUE);
863
864 return TRUE;
865 }
866
867 bool wxResourceManager::CreateNewPanel(void)
868 {
869 char buf[256];
870 MakeUniqueName("panel", buf);
871
872 wxItemResource *resource = new wxItemResource;
873 // resource->SetType(wxTYPE_PANEL);
874 resource->SetType("wxPanel");
875 resource->SetName(buf);
876 resource->SetTitle(buf);
877 resourceTable.AddResource(resource);
878
879 DialogEditorPanelFrame *frame = new DialogEditorPanelFrame(GetEditorFrame(), buf, 10, 10, 400, 300, wxDEFAULT_FRAME_STYLE, buf);
880
881 #ifdef __MOTIF__
882 wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 300), 0, buf);
883 /*
884 panel->SetBackgroundColour(*wxLIGHT_GREY);
885 panel->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH);
886 panel->SetButtonColour(*wxBLACK);
887 panel->SetLabelColour(*wxBLACK);
888 */
889
890 #else
891 wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 300), 0, buf);
892 #endif
893
894 resource->SetStyle(panel->GetWindowStyleFlag());
895
896 // For editing in situ we will need to use the hash table to ensure
897 // we don't dereference invalid pointers.
898 // resourceWindowTable.Put((long)resource, panel);
899
900 wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, resource, panel->GetEventHandler(),
901 this);
902 panel->PushEventHandler(handler);
903
904 panel->Centre(wxBOTH);
905 // panel->SetUserEditMode(TRUE);
906 frame->Show(TRUE);
907
908 SetEditMode(TRUE, FALSE);
909
910 AssociateResource(resource, panel);
911 // SetCurrentResource(resource);
912 // SetCurrentResourceWindow(panel);
913 UpdateResourceList();
914
915 Modify(TRUE);
916
917 return TRUE;
918 }
919
920 bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *panel, char *iType, int x, int y, bool isBitmap)
921 {
922 char buf[256];
923 if (!panel->IsKindOf(CLASSINFO(wxPanel)) && !panel->IsKindOf(CLASSINFO(wxDialog)))
924 return FALSE;
925
926 Modify(TRUE);
927
928 wxItemResource *res = new wxItemResource;
929 wxControl *newItem = NULL;
930 res->SetSize(x, y, -1, -1);
931 res->SetType(iType);
932
933 wxString itemType(iType);
934
935 if (itemType == "wxButton")
936 {
937 MakeUniqueName("button", buf);
938 res->SetName(buf);
939 if (isBitmap)
940 newItem = new wxBitmapButton(panel, -1, wxWinBitmap, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
941 else
942 newItem = new wxButton(panel, -1, "Button", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
943 }
944 if (itemType == "wxBitmapButton")
945 {
946 MakeUniqueName("button", buf);
947 res->SetName(buf);
948 newItem = new wxBitmapButton(panel, -1, wxWinBitmap, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
949 }
950 else if (itemType == "wxMessage" || itemType == "wxStaticText")
951 {
952 MakeUniqueName("message", buf);
953 res->SetName(buf);
954 if (isBitmap)
955 newItem = new wxStaticBitmap(panel, -1, wxWinBitmap, wxPoint(x, y), wxSize(0, 0), 0, buf);
956 else
957 newItem = new wxStaticText(panel, -1, "Message", wxPoint(x, y), wxSize(-1, -1), 0, buf);
958 }
959 else if (itemType == "wxStaticBitmap")
960 {
961 MakeUniqueName("message", buf);
962 res->SetName(buf);
963 newItem = new wxStaticBitmap(panel, -1, wxWinBitmap, wxPoint(x, y), wxSize(-1, -1), 0, buf);
964 }
965 else if (itemType == "wxCheckBox")
966 {
967 MakeUniqueName("checkbox", buf);
968 res->SetName(buf);
969 newItem = new wxCheckBox(panel, -1, "Checkbox", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
970 }
971 else if (itemType == "wxListBox")
972 {
973 MakeUniqueName("listbox", buf);
974 res->SetName(buf);
975 newItem = new wxListBox(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf);
976 }
977 else if (itemType == "wxRadioBox")
978 {
979 MakeUniqueName("radiobox", buf);
980 res->SetName(buf);
981 wxString names[] = { "One", "Two" };
982 newItem = new wxRadioBox(panel, -1, "Radiobox", wxPoint(x, y), wxSize(-1, -1), 2, names, 2,
983 wxHORIZONTAL, wxDefaultValidator, buf);
984 res->SetStringValues(new wxStringList("One", "Two", NULL));
985 }
986 else if (itemType == "wxChoice")
987 {
988 MakeUniqueName("choice", buf);
989 res->SetName(buf);
990 newItem = new wxChoice(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf);
991 }
992 else if (itemType == "wxGroupBox" || itemType == "wxStaticBox")
993 {
994 MakeUniqueName("group", buf);
995 res->SetName(buf);
996 newItem = new wxStaticBox(panel, -1, "Groupbox", wxPoint(x, y), wxSize(200, 200), 0, buf);
997 }
998 else if (itemType == "wxGauge")
999 {
1000 MakeUniqueName("gauge", buf);
1001 res->SetName(buf);
1002 newItem = new wxGauge(panel, -1, 10, wxPoint(x, y), wxSize(80, 30), wxHORIZONTAL, wxDefaultValidator, buf);
1003 }
1004 else if (itemType == "wxSlider")
1005 {
1006 MakeUniqueName("slider", buf);
1007 res->SetName(buf);
1008 newItem = new wxSlider(panel, -1, 1, 1, 10, wxPoint(x, y), wxSize(120, -1), wxHORIZONTAL, wxDefaultValidator, buf);
1009 }
1010 else if (itemType == "wxText" || itemType == "wxTextCtrl")
1011 {
1012 MakeUniqueName("text", buf);
1013 res->SetName(buf);
1014 newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, -1), 0, wxDefaultValidator, buf);
1015 }
1016 /*
1017 else if (itemType == "wxMultiText")
1018 {
1019 MakeUniqueName("multitext", buf);
1020 res->SetName(buf);
1021 newItem = new wxMultiText(panel, (wxFunction)NULL, "Multitext", "", x, y, -1, -1, 0, wxDefaultValidator, buf);
1022 }
1023 */
1024 else if (itemType == "wxScrollBar")
1025 {
1026 MakeUniqueName("scrollbar", buf);
1027 res->SetName(buf);
1028 newItem = new wxScrollBar(panel, -1, wxPoint(x, y), wxSize(140, -1), wxHORIZONTAL, wxDefaultValidator, buf);
1029 }
1030 if (!newItem)
1031 return FALSE;
1032
1033 newItem->PushEventHandler(new wxResourceEditorControlHandler(newItem, newItem));
1034
1035 res->SetStyle(newItem->GetWindowStyleFlag());
1036 AssociateResource(res, newItem);
1037 panelResource->GetChildren().Append(res);
1038
1039 UpdateResourceList();
1040
1041 return TRUE;
1042 }
1043
1044 // Find the first dialog or panel for which
1045 // there is a selected panel item.
1046 wxWindow *wxResourceManager::FindParentOfSelection(void)
1047 {
1048 resourceTable.BeginFind();
1049 wxNode *node;
1050 while (node = resourceTable.Next())
1051 {
1052 wxItemResource *res = (wxItemResource *)node->Data();
1053 wxWindow *win = FindWindowForResource(res);
1054 if (win)
1055 {
1056 wxNode *node1 = win->GetChildren()->First();
1057 while (node1)
1058 {
1059 wxControl *item = (wxControl *)node1->Data();
1060 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
1061 if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected())
1062 return win;
1063 node1 = node1->Next();
1064 }
1065 }
1066 }
1067 return NULL;
1068 }
1069
1070 // Format the panel items according to 'flag'
1071 void wxResourceManager::AlignItems(int flag)
1072 {
1073 wxWindow *win = FindParentOfSelection();
1074 if (!win)
1075 return;
1076
1077 wxNode *node = GetSelections().First();
1078 if (!node)
1079 return;
1080
1081 wxControl *firstSelection = (wxControl *)node->Data();
1082 if (firstSelection->GetParent() != win)
1083 return;
1084
1085 int firstX, firstY;
1086 int firstW, firstH;
1087 firstSelection->GetPosition(&firstX, &firstY);
1088 firstSelection->GetSize(&firstW, &firstH);
1089 int centreX = (int)(firstX + (firstW / 2));
1090 int centreY = (int)(firstY + (firstH / 2));
1091
1092 while (node = node->Next())
1093 {
1094 wxControl *item = (wxControl *)node->Data();
1095 if (item->GetParent() == win)
1096 {
1097 int x, y, w, h;
1098 item->GetPosition(&x, &y);
1099 item->GetSize(&w, &h);
1100
1101 int newX, newY;
1102
1103 switch (flag)
1104 {
1105 case TOOLBAR_FORMAT_HORIZ:
1106 {
1107 newX = x;
1108 newY = (int)(centreY - (h/2.0));
1109 break;
1110 }
1111 case TOOLBAR_FORMAT_VERT:
1112 {
1113 newX = (int)(centreX - (w/2.0));
1114 newY = y;
1115 break;
1116 }
1117 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
1118 {
1119 newX = firstX;
1120 newY = y;
1121 break;
1122 }
1123 case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
1124 {
1125 newX = x;
1126 newY = firstY;
1127 break;
1128 }
1129 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
1130 {
1131 newX = firstX + firstW - w;
1132 newY = y;
1133 break;
1134 }
1135 case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
1136 {
1137 newX = x;
1138 newY = firstY + firstH - h;
1139 break;
1140 }
1141 default:
1142 newX = x; newY = y;
1143 break;
1144 }
1145
1146 item->SetSize(newX, newY, w, h);
1147 }
1148 }
1149 win->Refresh();
1150 }
1151
1152 // Copy the first image's size to subsequent images
1153 void wxResourceManager::CopySize(void)
1154 {
1155 wxWindow *win = FindParentOfSelection();
1156 if (!win)
1157 return;
1158
1159 wxNode *node = GetSelections().First();
1160 if (!node)
1161 return;
1162
1163 wxControl *firstSelection = (wxControl *)node->Data();
1164 if (firstSelection->GetParent() != win)
1165 return;
1166
1167 int firstX, firstY;
1168 int firstW, firstH;
1169 firstSelection->GetPosition(&firstX, &firstY);
1170 firstSelection->GetSize(&firstW, &firstH);
1171 int centreX = (int)(firstX + (firstW / 2));
1172 int centreY = (int)(firstY + (firstH / 2));
1173
1174 while (node = node->Next())
1175 {
1176 wxControl *item = (wxControl *)node->Data();
1177 if (item->GetParent() == win)
1178 item->SetSize(-1, -1, firstW, firstH);
1179 }
1180 win->Refresh();
1181 }
1182
1183 void wxResourceManager::ToBackOrFront(bool toBack)
1184 {
1185 wxWindow *win = FindParentOfSelection();
1186 if (!win)
1187 return;
1188 wxItemResource *winResource = FindResourceForWindow(win);
1189
1190 wxNode *node = GetSelections().First();
1191 while (node)
1192 {
1193 wxControl *item = (wxControl *)node->Data();
1194 wxItemResource *itemResource = FindResourceForWindow(item);
1195 if (item->GetParent() == win)
1196 {
1197 win->GetChildren()->DeleteObject(item);
1198 if (winResource)
1199 winResource->GetChildren().DeleteObject(itemResource);
1200 if (toBack)
1201 {
1202 win->GetChildren()->Insert(item);
1203 if (winResource)
1204 winResource->GetChildren().Insert(itemResource);
1205 }
1206 else
1207 {
1208 win->GetChildren()->Append(item);
1209 if (winResource)
1210 winResource->GetChildren().Append(itemResource);
1211 }
1212 }
1213 node = node->Next();
1214 }
1215 // win->Refresh();
1216 }
1217
1218 void wxResourceManager::AddSelection(wxWindow *win)
1219 {
1220 if (!selections.Member(win))
1221 selections.Append(win);
1222 }
1223
1224 void wxResourceManager::RemoveSelection(wxWindow *win)
1225 {
1226 selections.DeleteObject(win);
1227 }
1228
1229 // Need to search through resource table removing this from
1230 // any resource which has this as a parent.
1231 bool wxResourceManager::RemoveResourceFromParent(wxItemResource *res)
1232 {
1233 resourceTable.BeginFind();
1234 wxNode *node;
1235 while (node = resourceTable.Next())
1236 {
1237 wxItemResource *thisRes = (wxItemResource *)node->Data();
1238 if (thisRes->GetChildren().Member(res))
1239 {
1240 thisRes->GetChildren().DeleteObject(res);
1241 return TRUE;
1242 }
1243 }
1244 return FALSE;
1245 }
1246
1247 bool wxResourceManager::DeleteResource(wxItemResource *res)
1248 {
1249 if (!res)
1250 return FALSE;
1251
1252 RemoveResourceFromParent(res);
1253
1254 wxNode *node = res->GetChildren().First();
1255 while (node)
1256 {
1257 wxNode *next = node->Next();
1258 wxItemResource *child = (wxItemResource *)node->Data();
1259 DeleteResource(child);
1260 node = next;
1261 }
1262
1263 // If this is a button or message resource, delete the
1264 // associate bitmap resource if not being used.
1265 wxString resType(res->GetType());
1266
1267 if ((resType == "wxMessage" || resType == "wxButton") && res->GetValue4())
1268 {
1269 PossiblyDeleteBitmapResource(res->GetValue4());
1270 }
1271
1272 resourceTable.Delete(res->GetName());
1273 delete res;
1274 Modify(TRUE);
1275 return TRUE;
1276 }
1277
1278 bool wxResourceManager::DeleteResource(wxWindow *win, bool deleteWindow)
1279 {
1280 if (win->IsKindOf(CLASSINFO(wxControl)))
1281 {
1282 // Deselect and refresh window in case we leave selection
1283 // handles behind
1284 wxControl *item = (wxControl *)win;
1285 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
1286 if (childHandler->IsSelected())
1287 {
1288 RemoveSelection(item);
1289 childHandler->SelectItem(FALSE);
1290 item->GetParent()->Refresh();
1291 }
1292 }
1293
1294 wxItemResource *res = FindResourceForWindow(win);
1295
1296 DisassociateResource(res, deleteWindow);
1297 DeleteResource(res);
1298 UpdateResourceList();
1299
1300 // What about associated event handler? Must clean up! BUGBUG
1301 // if (win && deleteWindow)
1302 // delete win;
1303 return TRUE;
1304 }
1305
1306 // Will eventually have bitmap type information, for different
1307 // kinds of bitmap.
1308 char *wxResourceManager::AddBitmapResource(char *filename)
1309 {
1310 wxItemResource *resource = FindBitmapResourceByFilename(filename);
1311 if (!resource)
1312 {
1313 char buf[256];
1314 MakeUniqueName("bitmap", buf);
1315 resource = new wxItemResource;
1316 resource->SetType("wxBitmap");
1317 resource->SetName(buf);
1318
1319 // A bitmap resource has one or more children, specifying
1320 // alternative bitmaps.
1321 wxItemResource *child = new wxItemResource;
1322 child->SetType("wxBitmap");
1323 child->SetName(filename);
1324 child->SetValue1(wxBITMAP_TYPE_BMP);
1325 child->SetValue2(RESOURCE_PLATFORM_ANY);
1326 child->SetValue3(0); // Depth
1327 child->SetSize(0,0,0,0);
1328 resource->GetChildren().Append(child);
1329
1330 resourceTable.AddResource(resource);
1331
1332 UpdateResourceList();
1333 }
1334 if (resource)
1335 return resource->GetName();
1336 else
1337 return NULL;
1338 }
1339
1340 // Delete the bitmap resource if it isn't being used by another resource.
1341 void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName)
1342 {
1343 if (!IsBitmapResourceUsed(resourceName))
1344 {
1345 wxItemResource *res = resourceTable.FindResource(resourceName);
1346 DeleteResource(res);
1347 UpdateResourceList();
1348 }
1349 }
1350
1351 bool wxResourceManager::IsBitmapResourceUsed(char *resourceName)
1352 {
1353 resourceTable.BeginFind();
1354 wxNode *node;
1355 while (node = resourceTable.Next())
1356 {
1357 wxItemResource *res = (wxItemResource *)node->Data();
1358 wxString resType(res->GetType());
1359 if (resType == "wxDialog")
1360 {
1361 wxNode *node1 = res->GetChildren().First();
1362 while (node1)
1363 {
1364 wxItemResource *child = (wxItemResource *)node1->Data();
1365 wxString childResType(child->GetType());
1366
1367 if ((childResType == "wxMessage" || childResType == "wxButton") &&
1368 child->GetValue4() &&
1369 (strcmp(child->GetValue4(), resourceName) == 0))
1370 return TRUE;
1371 node1 = node1->Next();
1372 }
1373 }
1374 }
1375 return FALSE;
1376 }
1377
1378 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1379 char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource)
1380 {
1381 if (!resource || !resource->GetValue4())
1382 return NULL;
1383 wxItemResource *bitmapResource = resourceTable.FindResource(resource->GetValue4());
1384 if (!bitmapResource)
1385 return NULL;
1386
1387 wxNode *node = bitmapResource->GetChildren().First();
1388 while (node)
1389 {
1390 // Eventually augment this to return a bitmap of the right kind or something...
1391 // Maybe the root of the filename remains the same, so it doesn't matter which we
1392 // pick up. Otherwise how do we specify multiple filenames... too boring...
1393 wxItemResource *child = (wxItemResource *)node->Data();
1394 return child->GetName();
1395
1396 node = node->Next();
1397 }
1398 return NULL;
1399 }
1400
1401 wxItemResource *wxResourceManager::FindBitmapResourceByFilename(char *filename)
1402 {
1403 resourceTable.BeginFind();
1404 wxNode *node;
1405 while (node = resourceTable.Next())
1406 {
1407 wxItemResource *res = (wxItemResource *)node->Data();
1408 wxString resType(res->GetType());
1409 if (resType == "wxBitmap")
1410 {
1411 wxNode *node1 = res->GetChildren().First();
1412 while (node1)
1413 {
1414 wxItemResource *child = (wxItemResource *)node1->Data();
1415 if (child->GetName() && (strcmp(child->GetName(), filename) == 0))
1416 return res;
1417 node1 = node1->Next();
1418 }
1419 }
1420 }
1421 return NULL;
1422 }
1423
1424 // Deletes 'win' and creates a new window from the resource that
1425 // was associated with it. E.g. if you can't change properties on the
1426 // fly, you'll need to delete the window and create it again.
1427 wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info)
1428 {
1429 wxItemResource *resource = FindResourceForWindow(win);
1430
1431 // Put the current window properties into the wxItemResource object
1432
1433 wxWindowPropertyInfo *newInfo = NULL;
1434 if (!info)
1435 {
1436 newInfo = wxCreatePropertyInfoForWindow(win);
1437 info = newInfo;
1438 }
1439
1440 info->InstantiateResource(resource);
1441
1442 wxWindow *newWin = NULL;
1443 wxWindow *parent = win->GetParent();
1444
1445 if (win->IsKindOf(CLASSINFO(wxPanel)))
1446 {
1447 bool isDialog = win->IsKindOf(CLASSINFO(wxDialog));
1448 wxWindow *parent = win->GetParent();
1449
1450 win->GetEventHandler()->OnClose();
1451
1452 if (!isDialog && parent)
1453 {
1454 // Delete frame parent of panel if this is not a dialog box
1455 parent->Close(TRUE);
1456 }
1457
1458 Edit(resource);
1459 newWin = FindWindowForResource(resource);
1460 }
1461 else
1462 {
1463 DisassociateResource(resource, FALSE);
1464 delete win;
1465 newWin = resourceTable.CreateItem((wxPanel *)parent, resource);
1466 AssociateResource(resource, newWin);
1467 UpdateResourceList();
1468 }
1469
1470 if (info)
1471 info->SetPropertyWindow(newWin);
1472
1473 if (newInfo)
1474 delete newInfo;
1475
1476 return newWin;
1477 }
1478
1479 // Delete resource highlighted in the listbox
1480 bool wxResourceManager::DeleteSelection(bool deleteWindow)
1481 {
1482 int sel = editorResourceList->GetSelection();
1483 if (sel > -1)
1484 {
1485 wxItemResource *res = (wxItemResource *)editorResourceList->wxListBox::GetClientData(sel);
1486 wxWindow *win = FindWindowForResource(res);
1487 /*
1488 if (res == currentResource)
1489 {
1490 currentResource = NULL;
1491 currentResourceWindow = NULL;
1492 }
1493 */
1494
1495 DisassociateResource(res, deleteWindow);
1496 DeleteResource(res);
1497 UpdateResourceList();
1498
1499 /*
1500 // What about associated event handler? Must clean up! BUGBUG
1501 if (win && deleteWindow)
1502 delete win;
1503 */
1504
1505 Modify(TRUE);
1506 }
1507
1508 return FALSE;
1509 }
1510
1511 // Delete resource highlighted in the listbox
1512 bool wxResourceManager::RecreateSelection(void)
1513 {
1514 wxNode *node = GetSelections().First();
1515 while (node)
1516 {
1517 wxControl *item = (wxControl *)node->Data();
1518 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
1519 wxNode *next = node->Next();
1520 childHandler->SelectItem(FALSE);
1521
1522 RemoveSelection(item);
1523
1524 RecreateWindowFromResource(item);
1525
1526 node = next;
1527 }
1528 return TRUE;
1529 }
1530
1531 bool wxResourceManager::EditDialog(wxDialog *dialog, wxWindow *parent)
1532 {
1533 return FALSE;
1534 }
1535
1536 void wxResourceManager::SetEditMode(bool flag, bool changeCurrentResource)
1537 {
1538 editMode = flag;
1539 if (editorFrame)
1540 editorFrame->SetStatusText(editMode ? "Edit mode" : "Test mode", 1);
1541
1542 // Switch mode for each dialog in the resource list
1543 resourceTable.BeginFind();
1544 wxNode *node = resourceTable.Next();
1545 while (node)
1546 {
1547 wxItemResource *resource = (wxItemResource *)node->Data();
1548 wxWindow *currentResourceWindow = FindWindowForResource(resource);
1549
1550 if (changeCurrentResource && currentResourceWindow && (currentResourceWindow->IsKindOf(CLASSINFO(wxPanel))))
1551 {
1552 wxPanel *panel = (wxPanel *)currentResourceWindow;
1553 if (editMode)
1554 {
1555 // If we have already installed our own handler, don't bother editing.
1556 // This test will need to be changed eventually because for in-situ editing,
1557 // the user might have installed a different one anyway.
1558 wxEvtHandler *handler = panel->GetEventHandler();
1559 handler->SetEvtHandlerEnabled(TRUE);
1560 // Enable all children
1561 wxNode *node = panel->GetChildren()->First();
1562 while (node)
1563 {
1564 wxControl *item = (wxControl *)node->Data();
1565 if ( item->IsKindOf(CLASSINFO(wxControl)) )
1566 {
1567 wxEvtHandler *childHandler = item->GetEventHandler();
1568 childHandler->SetEvtHandlerEnabled(TRUE);
1569 }
1570 node = node->Next();
1571 }
1572 }
1573 else
1574 {
1575 wxEvtHandler *handler = panel->GetEventHandler();
1576 handler->SetEvtHandlerEnabled(FALSE);
1577 // Deselect all items on the dialog and refresh.
1578 wxNode *node = panel->GetChildren()->First();
1579 while (node)
1580 {
1581 wxControl *item = (wxControl *)node->Data();
1582 if (item->IsKindOf(CLASSINFO(wxControl)))
1583 {
1584 wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
1585 childHandler->SetEvtHandlerEnabled(FALSE);
1586 childHandler->SelectItem(FALSE);
1587 }
1588 node = node->Next();
1589 }
1590 panel->Refresh();
1591 }
1592 }
1593 node = resourceTable.Next();
1594 }
1595 }
1596
1597 // Ensures that all currently shown windows are saved to resources,
1598 // e.g. just before writing to a .wxr file.
1599 bool wxResourceManager::InstantiateAllResourcesFromWindows(void)
1600 {
1601 resourceTable.BeginFind();
1602 wxNode *node;
1603 while (node = resourceTable.Next())
1604 {
1605 wxItemResource *res = (wxItemResource *)node->Data();
1606 wxString resType(res->GetType());
1607
1608 if (resType == "wxDialog")
1609 {
1610 wxWindow *win = (wxWindow *)FindWindowForResource(res);
1611 if (win)
1612 InstantiateResourceFromWindow(res, win, TRUE);
1613 }
1614 else if (resType == "wxPanel")
1615 {
1616 wxWindow *win = (wxWindow *)FindWindowForResource(res);
1617 if (win)
1618 InstantiateResourceFromWindow(res, win, TRUE);
1619 }
1620 }
1621 return TRUE;
1622 }
1623
1624 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse)
1625 {
1626 wxWindowPropertyInfo *info = wxCreatePropertyInfoForWindow(window);
1627 info->SetResource(resource);
1628 info->InstantiateResource(resource);
1629 delete info;
1630
1631 if (recurse)
1632 {
1633 wxNode *node = resource->GetChildren().First();
1634 while (node)
1635 {
1636 wxItemResource *child = (wxItemResource *)node->Data();
1637 wxWindow *childWindow = FindWindowForResource(child);
1638
1639 if (!childWindow)
1640 {
1641 char buf[200];
1642 sprintf(buf, "Could not find window %s", child->GetName());
1643 wxMessageBox(buf, "Dialog Editor problem", wxOK);
1644 }
1645 else
1646 InstantiateResourceFromWindow(child, childWindow, recurse);
1647 node = node->Next();
1648 }
1649 }
1650
1651 return TRUE;
1652 }
1653
1654
1655 /*
1656 * Resource editor frame
1657 */
1658
1659 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, char *title,
1660 int x, int y, int width, int height, long style, char *name):
1661 wxFrame(parent, -1, title, wxPoint(x, y), wxSize(width, height), style, name)
1662 {
1663 manager = resMan;
1664 }
1665
1666 wxResourceEditorFrame::~wxResourceEditorFrame(void)
1667 {
1668 }
1669
1670 void wxResourceEditorFrame::OldOnMenuCommand(int cmd)
1671 {
1672 switch (cmd)
1673 {
1674 case wxID_NEW:
1675 {
1676 manager->New(FALSE);
1677 break;
1678 }
1679 case RESED_NEW_DIALOG:
1680 {
1681 manager->CreateNewDialog();
1682 break;
1683 }
1684 case RESED_NEW_PANEL:
1685 {
1686 manager->CreateNewPanel();
1687 break;
1688 }
1689 case wxID_OPEN:
1690 {
1691 manager->New(TRUE);
1692 break;
1693 }
1694 case RESED_CLEAR:
1695 {
1696 manager->Clear(TRUE, FALSE);
1697 break;
1698 }
1699 case wxID_SAVE:
1700 {
1701 manager->Save();
1702 break;
1703 }
1704 case wxID_SAVEAS:
1705 {
1706 manager->SaveAs();
1707 break;
1708 }
1709 case wxID_EXIT:
1710 {
1711 manager->Clear(TRUE, FALSE) ;
1712 this->Close();
1713 break;
1714 }
1715 case wxID_ABOUT:
1716 {
1717 char buf[300];
1718 sprintf(buf, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION);
1719 (void)wxMessageBox(buf, "About Dialog Editor", wxOK|wxCENTRE);
1720 break;
1721 }
1722 case RESED_CONTENTS:
1723 {
1724 wxBeginBusyCursor();
1725 manager->GetHelpInstance()->LoadFile();
1726 manager->GetHelpInstance()->DisplayContents();
1727 wxEndBusyCursor();
1728 break;
1729 }
1730 case RESED_DELETE:
1731 {
1732 manager->DeleteSelection();
1733 break;
1734 }
1735 case RESED_RECREATE:
1736 {
1737 manager->RecreateSelection();
1738 break;
1739 }
1740 case RESED_TOGGLE_TEST_MODE:
1741 {
1742 manager->SetEditMode(!manager->GetEditMode());
1743 break;
1744 }
1745 default:
1746 break;
1747 }
1748 }
1749
1750 bool wxResourceEditorFrame::OnClose(void)
1751 {
1752 if (manager->Modified())
1753 {
1754 /*
1755 int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL);
1756 if (ans == wxCANCEL)
1757 return FALSE;
1758 if (ans == wxYES)
1759 if (!manager->SaveIfModified())
1760 return FALSE;
1761 */
1762 if (!manager->Clear(TRUE, FALSE))
1763 return FALSE;
1764 }
1765
1766 if (!Iconized())
1767 {
1768 int w, h;
1769 GetSize(&w, &h);
1770 manager->resourceEditorWindowSize.width = w;
1771 manager->resourceEditorWindowSize.height = h;
1772
1773 int x, y;
1774 GetPosition(&x, &y);
1775
1776 manager->resourceEditorWindowSize.x = x;
1777 manager->resourceEditorWindowSize.y = y;
1778 }
1779 manager->SetEditorFrame(NULL);
1780 manager->SetEditorToolBar(NULL);
1781 manager->SetEditorPalette(NULL);
1782
1783 return TRUE;
1784 }
1785
1786 /*
1787 * Resource editor panel
1788 */
1789
1790 wxResourceEditorPanel::wxResourceEditorPanel(wxWindow *parent, int x, int y, int width, int height,
1791 long style, char *name):
1792 wxPanel(parent, -1, wxPoint(x, y), wxSize(width, height), style, name)
1793 {
1794 }
1795
1796 wxResourceEditorPanel::~wxResourceEditorPanel(void)
1797 {
1798 }
1799
1800 void wxResourceEditorPanel::OnDefaultAction(wxControl *item)
1801 {
1802 wxResourceEditorFrame *frame = (wxResourceEditorFrame *)GetParent();
1803 wxResourceManager *manager = frame->manager;
1804
1805 if (item == manager->GetEditorResourceList())
1806 {
1807 manager->EditSelectedResource();
1808 }
1809 }
1810
1811 // Popup menu callback
1812 void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event)
1813 {
1814 wxWindow *data = (wxWindow *)menu.GetClientData();
1815 if (!data)
1816 return;
1817
1818 switch (event.GetInt())
1819 {
1820 case OBJECT_MENU_EDIT:
1821 {
1822 wxResourceEditWindow(data);
1823 break;
1824 }
1825 case OBJECT_MENU_DELETE:
1826 {
1827 wxResourceManager::currentResourceManager->DeleteResource(data);
1828 break;
1829 }
1830 default:
1831 break;
1832 }
1833 }
1834
1835 wxWindowPropertyInfo *wxCreatePropertyInfoForWindow(wxWindow *win)
1836 {
1837 wxWindowPropertyInfo *info = NULL;
1838 if (win->IsKindOf(CLASSINFO(wxScrollBar)))
1839 {
1840 info = new wxScrollBarPropertyInfo(win);
1841 }
1842 else if (win->IsKindOf(CLASSINFO(wxStaticBox)))
1843 {
1844 info = new wxGroupBoxPropertyInfo(win);
1845 }
1846 else if (win->IsKindOf(CLASSINFO(wxCheckBox)))
1847 {
1848 info = new wxCheckBoxPropertyInfo(win);
1849 }
1850 else if (win->IsKindOf(CLASSINFO(wxSlider)))
1851 {
1852 info = new wxSliderPropertyInfo(win);
1853 }
1854 else if (win->IsKindOf(CLASSINFO(wxGauge)))
1855 {
1856 info = new wxGaugePropertyInfo(win);
1857 }
1858 else if (win->IsKindOf(CLASSINFO(wxListBox)))
1859 {
1860 info = new wxListBoxPropertyInfo(win);
1861 }
1862 else if (win->IsKindOf(CLASSINFO(wxRadioBox)))
1863 {
1864 info = new wxRadioBoxPropertyInfo(win);
1865 }
1866 else if (win->IsKindOf(CLASSINFO(wxChoice)))
1867 {
1868 info = new wxChoicePropertyInfo(win);
1869 }
1870 else if (win->IsKindOf(CLASSINFO(wxButton)))
1871 {
1872 info = new wxButtonPropertyInfo(win);
1873 /*
1874 if (((wxButton *)win)->IsBitmap())
1875 ((wxButtonPropertyInfo *)info)->isBitmapButton = TRUE;
1876 */
1877 }
1878 else if (win->IsKindOf(CLASSINFO(wxStaticText)))
1879 {
1880 info = new wxStaticTextPropertyInfo(win);
1881 /*
1882 if (((wxMessage *)win)->IsBitmap())
1883 ((wxMessagePropertyInfo *)info)->isBitmapMessage = TRUE;
1884 */
1885 }
1886 else if (win->IsKindOf(CLASSINFO(wxTextCtrl)))
1887 {
1888 info = new wxTextPropertyInfo(win);
1889 }
1890 else if (win->IsKindOf(CLASSINFO(wxDialog)))
1891 {
1892 info = new wxDialogPropertyInfo(win);
1893 }
1894 else if (win->IsKindOf(CLASSINFO(wxPanel)))
1895 {
1896 info = new wxPanelPropertyInfo(win);
1897 }
1898 else
1899 {
1900 info = new wxWindowPropertyInfo(win);
1901 }
1902 return info;
1903 }
1904
1905 // Popup menu callback
1906 void wxResourceEditWindow(wxWindow *win)
1907 {
1908 wxWindowPropertyInfo *info = wxCreatePropertyInfoForWindow(win);
1909 if (info)
1910 {
1911 info->SetResource(wxResourceManager::currentResourceManager->FindResourceForWindow(win));
1912 wxString str("Editing ");
1913 str += win->GetClassInfo()->GetClassName();
1914 str += ": ";
1915 if (win->GetName() != "")
1916 str += win->GetName();
1917 else
1918 str += "properties";
1919 info->Edit(NULL, WXSTRINGCAST str);
1920 delete info;
1921 }
1922 }
1923
1924 /*
1925 * Main toolbar
1926 *
1927 */
1928
1929 #if defined(__WINDOWS__) && defined(__WIN95__)
1930 BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar95)
1931 #elif defined(__WINDOWS__)
1932 BEGIN_EVENT_TABLE(EditorToolBar, wxToolBarMSW)
1933 #else
1934 BEGIN_EVENT_TABLE(EditorToolBar, wxToolBarSimple)
1935 #endif
1936 EVT_PAINT(EditorToolBar::OnPaint)
1937 END_EVENT_TABLE()
1938
1939 EditorToolBar::EditorToolBar(wxFrame *frame, int x, int y, int w, int h,
1940 long style, int direction, int RowsOrColumns):
1941 #if defined(__WINDOWS__) && defined(__WIN95__)
1942 wxToolBar95(frame, -1, wxPoint(x, y), wxSize(w, h), style, direction, RowsOrColumns)
1943 #elif defined(__WINDOWS__)
1944 wxToolBarMSW(frame, -1, wxPoint(x, y), wxSize(w, h), style, direction, RowsOrColumns)
1945 #else
1946 wxToolBarSimple(frame, -1, wxPoint(x, y), wxSize(w, h), style, direction, RowsOrColumns)
1947 #endif
1948 {
1949 }
1950
1951 bool EditorToolBar::OnLeftClick(int toolIndex, bool toggled)
1952 {
1953 wxResourceManager *manager = wxResourceManager::currentResourceManager;
1954
1955 switch (toolIndex)
1956 {
1957 case TOOLBAR_LOAD_FILE:
1958 {
1959 manager->New(TRUE);
1960 break;
1961 }
1962 case TOOLBAR_NEW:
1963 {
1964 manager->New(FALSE);
1965 break;
1966 }
1967 case TOOLBAR_SAVE_FILE:
1968 {
1969 manager->Save();
1970 break;
1971 }
1972 case TOOLBAR_HELP:
1973 {
1974 wxBeginBusyCursor();
1975 manager->GetHelpInstance()->LoadFile();
1976 manager->GetHelpInstance()->DisplayContents();
1977 wxEndBusyCursor();
1978 break;
1979 }
1980 case TOOLBAR_FORMAT_HORIZ:
1981 {
1982 manager->AlignItems(TOOLBAR_FORMAT_HORIZ);
1983 break;
1984 }
1985 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
1986 {
1987 manager->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN);
1988 break;
1989 }
1990 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
1991 {
1992 manager->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN);
1993 break;
1994 }
1995 case TOOLBAR_FORMAT_VERT:
1996 {
1997 manager->AlignItems(TOOLBAR_FORMAT_VERT);
1998 break;
1999 }
2000 case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
2001 {
2002 manager->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN);
2003 break;
2004 }
2005 case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
2006 {
2007 manager->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN);
2008 break;
2009 }
2010 case TOOLBAR_COPY_SIZE:
2011 {
2012 manager->CopySize();
2013 break;
2014 }
2015 case TOOLBAR_TO_BACK:
2016 {
2017 manager->ToBackOrFront(TRUE);
2018 break;
2019 }
2020 case TOOLBAR_TO_FRONT:
2021 {
2022 manager->ToBackOrFront(FALSE);
2023 break;
2024 }
2025 default:
2026 break;
2027 }
2028 return TRUE;
2029 }
2030
2031 void EditorToolBar::OnMouseEnter(int toolIndex)
2032 {
2033 wxFrame *frame = (wxFrame *)GetParent();
2034
2035 if (!frame) return;
2036
2037 if (toolIndex > -1)
2038 {
2039 switch (toolIndex)
2040 {
2041 case TOOLBAR_LOAD_FILE:
2042 frame->SetStatusText("Load project file");
2043 break;
2044 case TOOLBAR_SAVE_FILE:
2045 frame->SetStatusText("Save project file");
2046 break;
2047 case TOOLBAR_NEW:
2048 frame->SetStatusText("Create a new resource");
2049 break;
2050 case TOOLBAR_FORMAT_HORIZ:
2051 frame->SetStatusText("Align items horizontally");
2052 break;
2053 case TOOLBAR_FORMAT_VERT:
2054 frame->SetStatusText("Align items vertically");
2055 break;
2056 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
2057 frame->SetStatusText("Left-align items");
2058 break;
2059 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
2060 frame->SetStatusText("Right-align items");
2061 break;
2062 case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
2063 frame->SetStatusText("Top-align items");
2064 break;
2065 case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
2066 frame->SetStatusText("Bottom-align items");
2067 break;
2068 case TOOLBAR_COPY_SIZE:
2069 frame->SetStatusText("Copy size from first selection");
2070 break;
2071 case TOOLBAR_TO_FRONT:
2072 frame->SetStatusText("Put image to front");
2073 break;
2074 case TOOLBAR_TO_BACK:
2075 frame->SetStatusText("Put image to back");
2076 break;
2077 case TOOLBAR_HELP:
2078 frame->SetStatusText("Display help contents");
2079 break;
2080 default:
2081 break;
2082 }
2083 }
2084 else frame->SetStatusText("");
2085 }
2086
2087 void EditorToolBar::OnPaint(wxPaintEvent& event)
2088 {
2089 #if defined(__WINDOWS__) && defined(__WIN95__)
2090 wxToolBar95::OnPaint(event);
2091 #elif defined(__WINDOWS__)
2092 wxToolBarMSW::OnPaint(event);
2093 #else
2094 wxToolBarSimple::OnPaint(event);
2095 #endif
2096
2097 wxPaintDC dc(this);
2098 int w, h;
2099 GetSize(&w, &h);
2100 dc.SetPen(wxBLACK_PEN);
2101 dc.SetBrush(wxTRANSPARENT_BRUSH);
2102 dc.DrawLine(0, h-1, w, h-1);
2103 }
2104
2105 /*
2106 * Frame for editing a panel in
2107 */
2108
2109 bool DialogEditorPanelFrame::OnClose(void)
2110 {
2111 wxWindow *child = (wxWindow *)GetChildren()->First()->Data();
2112 wxEvtHandler *handler = child->GetEventHandler();
2113 return handler->OnClose();
2114 }