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