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