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