1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxInstall Builder
4 // Author: Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
29 #include "wx/toolbar.h"
33 // define this to 1 to use wxToolBarSimple instead of the native one
34 #define USE_GENERIC_TBAR 0
37 #if !wxUSE_TOOLBAR_SIMPLE
38 #error wxToolBarSimple is not compiled in, set wxUSE_TOOLBAR_SIMPLE \
39 to 1 in setup.h and recompile the library.
41 #include "wx/tbarsmpl.h"
43 #endif // USE_GENERIC_TBAR
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 #if defined(__WXGTK__) || defined(__WXMOTIF__)
50 #include "mondrian.xpm"
51 #include "bitmaps/new.xpm"
52 #include "bitmaps/open.xpm"
53 #include "bitmaps/save.xpm"
54 #include "bitmaps/copy.xpm"
55 #include "bitmaps/cut.xpm"
56 #include "bitmaps/preview.xpm" // paste XPM
57 #include "bitmaps/print.xpm"
58 #include "bitmaps/help.xpm"
59 #endif // GTK or Motif
61 char appName
[] = "wxInstall Builder";
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // Define a new application
68 class MyApp
: public wxApp
75 class MyFrame
: public wxFrame
78 MyFrame(wxFrame
*parent
,
80 const wxString
& title
= "wxInstall Builder",
81 const wxPoint
& pos
= wxDefaultPosition
,
82 const wxSize
& size
= wxDefaultSize
,
83 long style
= wxDEFAULT_FRAME_STYLE
);
85 void RecreateToolbar();
87 void OnQuit(wxCommandEvent
& event
);
88 void OnAbout(wxCommandEvent
& event
);
90 void OnNewScript(wxCommandEvent
& event
);
91 void OnOpenScript(wxCommandEvent
& event
);
92 void OnSaveScript(wxCommandEvent
& event
);
93 void OnNewProject(wxCommandEvent
& event
);
94 void OnOpenProject(wxCommandEvent
& event
);
95 void OnSaveProject(wxCommandEvent
& event
);
97 void OnCut(wxCommandEvent
& event
);
98 void OnCopy(wxCommandEvent
& event
);
99 void OnPaste(wxCommandEvent
& event
);
101 void OnListBoxDoubleClick(wxCommandEvent
& event
);
104 virtual wxToolBar
*OnCreateToolBar(long style
,
106 const wxString
& name
);
107 #endif // USE_GENERIC_TBAR
112 size_t m_rows
; // 1 or 2 only
114 wxTextCtrl
* m_textWindow
;
115 wxListBox
* m_listBox
;
117 DECLARE_EVENT_TABLE()
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
124 const int ID_TOOLBAR
= 500;
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
145 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
146 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
147 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
149 EVT_MENU(wxID_NEW_SCRIPT
, MyFrame::OnNewScript
)
150 EVT_MENU(wxID_OPEN_SCRIPT
, MyFrame::OnOpenScript
)
151 EVT_MENU(wxID_SAVE_SCRIPT
, MyFrame::OnSaveScript
)
152 EVT_MENU(wxID_NEW_PROJECT
, MyFrame::OnNewProject
)
153 EVT_MENU(wxID_OPEN_PROJECT
, MyFrame::OnOpenProject
)
154 EVT_MENU(wxID_SAVE_PROJECT
, MyFrame::OnSaveProject
)
156 EVT_MENU(wxID_CUT
, MyFrame::OnCut
)
157 EVT_MENU(wxID_COPY
, MyFrame::OnCopy
)
158 EVT_MENU(wxID_PASTE
, MyFrame::OnPaste
)
160 EVT_LISTBOX_DCLICK(ID_LISTBOX
, MyFrame::OnListBoxDoubleClick
)
163 // ============================================================================
165 // ============================================================================
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
173 // The `main program' equivalent, creating the windows and returning the
177 // Create the main frame window
178 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, -1,
180 wxPoint(100, 100), wxSize(450, 300));
182 frame
->SetAutoLayout(TRUE
);
186 frame
->SetStatusText("Welcome to wxWindows Install Builder");
193 void MyFrame::RecreateToolbar()
195 // delete and recreate the toolbar
196 wxToolBarBase
*toolBar
= GetToolBar();
201 long style
= wxNO_BORDER
| wxTB_FLAT
| wxTB_DOCKABLE
;
202 style
|= m_horzToolbar
? wxTB_HORIZONTAL
: wxTB_VERTICAL
;
204 toolBar
= CreateToolBar(style
, ID_TOOLBAR
);
205 toolBar
->SetMargins( 4, 4 );
208 wxBitmap toolBarBitmaps
[8];
210 toolBarBitmaps
[0] = wxBITMAP(new);
211 toolBarBitmaps
[1] = wxBITMAP(open
);
212 toolBarBitmaps
[2] = wxBITMAP(save
);
213 toolBarBitmaps
[3] = wxBITMAP(copy
);
214 toolBarBitmaps
[4] = wxBITMAP(cut
);
215 toolBarBitmaps
[5] = wxBITMAP(paste
);
216 toolBarBitmaps
[6] = wxBITMAP(print
);
217 toolBarBitmaps
[7] = wxBITMAP(help
);
219 if ( !m_smallToolbar
)
221 int w
= 2*toolBarBitmaps
[0].GetWidth(),
222 h
= 2*toolBarBitmaps
[0].GetHeight();
223 for ( size_t n
= 0; n
< WXSIZEOF(toolBarBitmaps
); n
++ )
226 wxImage(toolBarBitmaps
[n
]).Scale(w
, h
).ConvertToBitmap();
229 toolBar
->SetToolBitmapSize(wxSize(w
, h
));
240 toolBar
->AddTool(wxID_NEW_SCRIPT
, toolBarBitmaps
[0], wxNullBitmap
, FALSE
, currentX
, -1, (wxObject
*) NULL
, "New script");
241 currentX
+= width
+ 5;
242 toolBar
->AddTool(wxID_OPEN_SCRIPT
, toolBarBitmaps
[1], wxNullBitmap
, FALSE
, currentX
, -1, (wxObject
*) NULL
, "Open script");
244 // neither the generic nor Motif native toolbars really support this
245 currentX
+= width
+ 5;
246 toolBar
->AddTool(wxID_SAVE_SCRIPT
, toolBarBitmaps
[2], wxNullBitmap
, FALSE
, currentX
, -1, (wxObject
*) NULL
, "Save script");
247 currentX
+= width
+ 5;
248 toolBar
->AddTool(wxID_COPY
, toolBarBitmaps
[3], wxNullBitmap
, FALSE
, currentX
, -1, (wxObject
*) NULL
, "Copy");
249 currentX
+= width
+ 5;
250 toolBar
->AddTool(wxID_CUT
, toolBarBitmaps
[4], wxNullBitmap
, FALSE
, currentX
, -1, (wxObject
*) NULL
, "Cut");
251 currentX
+= width
+ 5;
252 toolBar
->AddTool(wxID_PASTE
, toolBarBitmaps
[5], wxNullBitmap
, FALSE
, currentX
, -1, (wxObject
*) NULL
, "Paste");
253 currentX
+= width
+ 5;
254 toolBar
->AddSeparator();
255 toolBar
->AddTool(wxID_HELP
, toolBarBitmaps
[7], wxNullBitmap
, FALSE
, currentX
, -1, (wxObject
*) NULL
, "Help button");
257 // after adding the buttons to the toolbar, must call Realize() to reflect
261 toolBar
->SetRows(m_horzToolbar
? m_rows
: 10 / m_rows
);
264 // ----------------------------------------------------------------------------
266 // ----------------------------------------------------------------------------
268 // Define my frame constructor
269 MyFrame::MyFrame(wxFrame
* parent
,
271 const wxString
& title
,
275 : wxFrame(parent
, id
, title
, pos
, size
, style
)
277 m_listBox
= new wxListBox(this, ID_LISTBOX
, wxPoint(0,0), wxSize(-1, -1));
279 m_listBox
->Append("loadwxr");
280 m_listBox
->Append("closeold");
281 m_listBox
->Append("mleview");
282 m_listBox
->Append("setbutton");
283 m_listBox
->Append("getcheck");
284 m_listBox
->Append("message");
285 m_listBox
->Append("disable");
286 m_listBox
->Append("settext");
287 m_listBox
->Append("gettext");
288 m_listBox
->Append("grabfile");
289 m_listBox
->Append("remove");
290 m_listBox
->Append("system");
291 m_listBox
->Append("startinst");
293 wxLayoutConstraints
*b1
= new wxLayoutConstraints
;
294 b1
->left
.SameAs (this, wxLeft
, 0);
295 b1
->top
.SameAs (this, wxTop
, 0);
296 b1
->width
.PercentOf (this, wxWidth
, 20);
297 b1
->bottom
.SameAs (this, wxBottom
, 0);
298 m_listBox
->SetConstraints(b1
);
300 m_textWindow
= new wxTextCtrl(this, -1, "", wxPoint(0,0), wxSize(-1, -1), wxTE_MULTILINE
);
302 m_textWindow
->AppendText("; Script generated by wxInstall Builder\n");
304 wxLayoutConstraints
*b2
= new wxLayoutConstraints
;
305 b2
->top
.SameAs (this, wxTop
, 0);
306 b2
->left
.SameAs (m_listBox
, wxRight
, 0);
307 b2
->width
.PercentOf (this, wxWidth
, 80);
308 b2
->bottom
.SameAs (this, wxBottom
, 0);
309 m_textWindow
->SetConstraints(b2
);
311 m_smallToolbar
= TRUE
;
312 m_horzToolbar
= TRUE
;
315 // Give it a status line
319 SetIcon(wxICON(mondrian
));
321 wxMenu
*fileMenu
= new wxMenu
;
322 fileMenu
->Append(wxID_NEW_SCRIPT
, "&New Script", "New wxInstall Script" );
323 fileMenu
->Append(wxID_OPEN_SCRIPT
, "&Open Script", "Open wxInstall Script" );
324 fileMenu
->Append(wxID_SAVE_SCRIPT
, "&Save Script", "Save wxInstall Script" );
325 fileMenu
->AppendSeparator();
326 /*fileMenu->Append(wxID_NEW_PROJECT, "N&ew Project", "New wxInstall Project" );
327 fileMenu->Append(wxID_OPEN_PROJECT, "O&pen Project", "Open wxInstall Project" );
328 fileMenu->Append(wxID_SAVE_PROJECT, "S&ave Project", "Save wxInstall Project" );
329 fileMenu->AppendSeparator();*/
330 fileMenu
->Append(wxID_EXIT
, "E&xit", "Quit wxInstall Builder" );
332 wxMenu
*helpMenu
= new wxMenu
;
333 helpMenu
->Append(wxID_HELP
, "&About", "About wxInstall Builder");
335 wxMenuBar
* menuBar
= new wxMenuBar( wxMB_DOCKABLE
);
337 menuBar
->Append(fileMenu
, "&File");
338 menuBar
->Append(helpMenu
, "&Help");
340 // Associate the menu bar with the frame
343 // Create the toolbar
349 wxToolBar
* MyFrame::OnCreateToolBar(long style
,
351 const wxString
& name
)
353 return (wxToolBar
*)new wxToolBarSimple(this, id
,
354 wxDefaultPosition
, wxDefaultSize
,
358 #endif // USE_GENERIC_TBAR
360 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
365 void MyFrame::OnCut(wxCommandEvent
& WXUNUSED(event
))
370 void MyFrame::OnCopy(wxCommandEvent
& WXUNUSED(event
))
372 m_textWindow
->Copy();
375 void MyFrame::OnPaste(wxCommandEvent
& WXUNUSED(event
))
377 m_textWindow
->Paste();
380 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
382 (void)wxMessageBox("wxInstall Builder by Brian Smith", "About wxInstall Builder");
385 void MyFrame::OnNewScript(wxCommandEvent
& event
)
387 m_textWindow
->Clear();
388 m_textWindow
->AppendText("; Script generated by wxInstall Builder\n");
391 void MyFrame::OnOpenScript(wxCommandEvent
& event
)
393 wxFileDialog
dialog2(this, "Open Script", "", "", "*.ini", 0);
395 if (dialog2
.ShowModal() == wxID_OK
)
396 m_textWindow
->LoadFile(dialog2
.GetPath());
399 void MyFrame::OnSaveScript(wxCommandEvent
& event
)
401 wxFileDialog
dialog2(this, "Save Script", "", "", "*.ini", 0);
403 if (dialog2
.ShowModal() == wxID_OK
)
404 m_textWindow
->SaveFile(dialog2
.GetPath());
407 void MyFrame::OnNewProject(wxCommandEvent
& event
)
411 void MyFrame::OnOpenProject(wxCommandEvent
& event
)
415 void MyFrame::OnSaveProject(wxCommandEvent
& event
)
419 void MyFrame::OnListBoxDoubleClick( wxCommandEvent
&event
)
423 item
= m_listBox
->GetSelection();
429 wxFileDialog
dialog2(this, "Choose wxr filename", "", "", "*.wxr", 0);
431 if (dialog2
.ShowModal() == wxID_OK
)
433 char tempbuf
[1024] = "DialogEd ";
434 wxString tmp
= dialog2
.GetFilename();
436 m_textWindow
->WriteText("loadwxr,");
437 m_textWindow
->WriteText(tmp
);
438 m_textWindow
->WriteText("\n");
440 strcat(tempbuf
, tmp
);
447 m_textWindow
->WriteText("closeold\n");
452 wxFileDialog
dialog2(this, "Choose filename to view", "", "", "*.txt", 0);
454 if (dialog2
.ShowModal() == wxID_OK
)
456 wxTextEntryDialog
dialog3(this,
457 "Please enter name of the MLE widget",
462 if (dialog3
.ShowModal() == wxID_OK
)
464 m_textWindow
->WriteText("mleview,");
465 m_textWindow
->WriteText(dialog3
.GetValue());
466 m_textWindow
->WriteText(",");
467 m_textWindow
->WriteText(dialog2
.GetFilename());
468 m_textWindow
->WriteText("\n");
475 wxFileDialog
dialog2(this, "Choose script to attach to button", "", "", "*.ini", 0);
477 if (dialog2
.ShowModal() == wxID_OK
)
479 wxTextEntryDialog
dialog3(this,
480 "Please enter ID of the button",
485 if (dialog3
.ShowModal() == wxID_OK
)
487 m_textWindow
->WriteText("setbutton,");
488 m_textWindow
->WriteText(dialog3
.GetValue());
489 m_textWindow
->WriteText(",");
490 m_textWindow
->WriteText(dialog2
.GetFilename());
491 m_textWindow
->WriteText("\n");
498 wxFileDialog
dialog2(this, "Choose script to run if not checked", "", "", "*.ini", 0);
500 if (dialog2
.ShowModal() == wxID_OK
)
502 wxTextEntryDialog
dialog3(this,
503 "Please enter name of the checkbox widget",
508 if (dialog3
.ShowModal() == wxID_OK
)
510 m_textWindow
->WriteText("getcheck,");
511 m_textWindow
->WriteText(dialog3
.GetValue());
512 m_textWindow
->WriteText(",");
513 m_textWindow
->WriteText(dialog2
.GetFilename());
514 m_textWindow
->WriteText("\n");
521 wxTextEntryDialog
dialog2(this,
522 "Please enter the message to display to the user",
527 if (dialog2
.ShowModal() == wxID_OK
)
529 m_textWindow
->WriteText("message,\"");
530 m_textWindow
->WriteText(dialog2
.GetValue());
531 m_textWindow
->WriteText("\"\n");
537 wxTextEntryDialog
dialog2(this,
538 "Please enter the widget name to disable",
543 if (dialog2
.ShowModal() == wxID_OK
)
545 m_textWindow
->WriteText("disable,");
546 m_textWindow
->WriteText(dialog2
.GetValue());
547 m_textWindow
->WriteText("\n");
553 wxTextEntryDialog
dialog2(this,
554 "Please enter text widget name to set from",
559 if (dialog2
.ShowModal() == wxID_OK
)
561 m_textWindow
->WriteText("settext,");
562 m_textWindow
->WriteText(dialog2
.GetValue());
563 m_textWindow
->WriteText("\n");
569 wxTextEntryDialog
dialog2(this,
570 "Please enter text widget name to get from",
575 if (dialog2
.ShowModal() == wxID_OK
)
577 m_textWindow
->WriteText("gettext,");
578 m_textWindow
->WriteText(dialog2
.GetValue());
579 m_textWindow
->WriteText("\n");
585 wxFileDialog
dialog2(this, "Choose file to grab", "", "", "*", 0);
587 if (dialog2
.ShowModal() == wxID_OK
)
589 m_textWindow
->WriteText("grabfile,");
590 m_textWindow
->WriteText(dialog2
.GetFilename());
591 m_textWindow
->WriteText("\n");
597 wxFileDialog
dialog2(this, "Choose file to remove", "", "", "*", 0);
599 if (dialog2
.ShowModal() == wxID_OK
)
601 m_textWindow
->WriteText("remove,");
602 m_textWindow
->WriteText(dialog2
.GetFilename());
603 m_textWindow
->WriteText("\n");
609 wxTextEntryDialog
dialog2(this,
610 "Please enter the command to execute",
615 if (dialog2
.ShowModal() == wxID_OK
)
617 m_textWindow
->WriteText("system,");
618 m_textWindow
->WriteText(dialog2
.GetValue());
619 m_textWindow
->WriteText("\n");
625 wxFileDialog
dialog2(this, "Choose script to run at installation completion", "", "", "*.ini", 0);
627 if (dialog2
.ShowModal() == wxID_OK
)
629 wxTextEntryDialog
dialog3(this,
630 "Please enter name of the gauge widget",
635 if (dialog3
.ShowModal() == wxID_OK
)
637 m_textWindow
->WriteText("startinst,");
638 m_textWindow
->WriteText(dialog3
.GetValue());
639 m_textWindow
->WriteText(",");
640 m_textWindow
->WriteText(dialog2
.GetFilename());
641 m_textWindow
->WriteText("\n");