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