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