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