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