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