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