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