Added some temporary icons to the repository
[qemu-gui.git] / menubar.cpp
blob689accd97c553291b3a177c4c1f4158ebec50d19
1 #include <wx/intl.h>
2 #include <wx/menu.h>
3 #include "menubar.h"
4 #include "events.h"
5 #include "mainframe.h"
7 QemuUIMenuBar::QemuUIMenuBar() : wxMenuBar(){
8 this->Append(CreateFileMenu(), _("&File"));
9 this->Append(CreateViewMenu(), _("&View"));
10 this->Append(CreateVMMenu(), _("V&M"));
11 this->Append(CreatePowerMenu(), _("&Power"));
12 this->Append(CreateWindowMenu(),_("&Windows"));
13 this->Append(CreateHelpMenu(), _("&Help"));
16 wxMenu *QemuUIMenuBar::CreateFileMenu(){
17 this->filemenu = new wxMenu();
19 filemenu->Append(
20 QEMU_NEW,
21 _("&N&ew\tCtrl-N"),
22 _("Create a new VM")
25 filemenu->Append(
26 QEMU_OPEN,
27 _("&Open\tCtrl-O"),
28 _("Open an existing VM")
31 filemenu->Append(
32 QEMU_CLOSE,
33 _("&Close\tCtrl-Q"),
34 _("Close this VM")
37 filemenu->AppendSeparator();
39 filemenu->Append(
40 QEMU_QUIT,
41 _("E&xit\tCtrl-X"),
42 _("Quit this program")
45 return this->filemenu;
48 wxMenu *QemuUIMenuBar::CreateViewMenu(){
49 this->viewmenu = new wxMenu();
51 viewmenu->Append(
52 QEMU_HOMEPAGE,
53 _("&Homepage"),
54 _("Show start screen")
57 viewmenu->AppendCheckItem(
58 QEMU_FULLSCREEN,
59 _("&Fullscreen"),
60 _("Toggle fullscreen mode")
63 wxMenu *toolbarmenu = new wxMenu();
64 toolbarmenu->AppendCheckItem(
65 QEMU_TOGGLE_TOOLBAR,
66 _("&Toolbar"),
67 _("Toggle toolbar")
69 toolbarmenu->Check(QEMU_TOGGLE_TOOLBAR,true);
70 toolbarmenu->AppendSeparator();
71 toolbarmenu->AppendRadioItem(QEMU_TOOLBAR_ICONS,_("Icons"));
72 toolbarmenu->AppendRadioItem(QEMU_TOOLBAR_TEXT,_("Text"));
73 toolbarmenu->AppendRadioItem(QEMU_TOOLBAR_BOTH,_("Both"));
74 toolbarmenu->Check(QEMU_TOOLBAR_BOTH,true);
76 viewmenu->Append(
77 wxID_ANY,
78 _("Toolbar"),
79 toolbarmenu,
80 _("Toolbar related settings")
83 viewmenu->AppendCheckItem(
84 QEMU_TOGGLE_STATUSBAR,
85 _("&Status Bar"),
86 _("Toggle status bar")
88 viewmenu->Check(QEMU_TOGGLE_STATUSBAR,true);
90 return this->viewmenu;
93 wxMenu* QemuUIMenuBar::CreateVMMenu(){
94 this->vmmenu = new wxMenu();
95 vmmenu->Append(QEMU_VM_SEND_CTRL_ALT_DEL,_("Send Ctrl+Alt+Del"));
96 vmmenu->Append(QEMU_VM_SETTINGS,_("Settings"));
97 return this->vmmenu;
101 wxMenu* QemuUIMenuBar::CreatePowerMenu(){
102 this->powermenu = new wxMenu();
103 powermenu->Append(QEMU_VM_START,_("Power on"));
104 powermenu->Append(QEMU_VM_SHUTDOWN,_("Power off"));
105 powermenu->Append(QEMU_VM_PAUSE,_("Pause"));
106 powermenu->Append(QEMU_VM_RESET,_("Reset"));
107 return this->powermenu;
110 wxMenu* QemuUIMenuBar::CreateWindowMenu(){
111 this->windowmenu = new wxMenu();
112 windowmenu->AppendSeparator();
113 windowmenu->Append(
114 QEMU_WINDOW_NEXT,
115 _("&Next Window\tCtrl+TAB")
117 windowmenu->Append(
118 QEMU_WINDOW_PREV,
119 _("&Previous Window\tCtrl+Shift+Tab")
121 return this->windowmenu;
124 wxMenu *QemuUIMenuBar::CreateHelpMenu(){
125 this->helpmenu = new wxMenu();
126 helpmenu->Append(
127 QEMU_DOC,
128 _("&Documentation\tF1"),
129 _("Show Qemu documentation")
131 helpmenu->Append(
132 QEMU_ABOUT,
133 _("&About"),
134 _("Show about dialog")
136 return this->helpmenu;
139 void QemuUIMenuBar::Disable(){
140 powermenu->Enable(QEMU_VM_START,false);
141 powermenu->Enable(QEMU_VM_PAUSE,false);
142 powermenu->Enable(QEMU_VM_SHUTDOWN,false);
143 powermenu->Enable(QEMU_VM_RESET,false);
144 vmmenu->Enable(QEMU_VM_SETTINGS,false);
145 vmmenu->Enable(QEMU_VM_SEND_CTRL_ALT_DEL,false);
148 void QemuUIMenuBar::Settings(bool state){
149 vmmenu->Enable(QEMU_VM_SETTINGS,state);
152 void QemuUIMenuBar::SendCtrlAltDel(bool state){
153 vmmenu->Enable(QEMU_VM_SEND_CTRL_ALT_DEL,state);
156 void QemuUIMenuBar::PowerOn(bool state){
157 powermenu->Enable(QEMU_VM_START,state);
160 void QemuUIMenuBar::Pause(bool state){
161 powermenu->Enable(QEMU_VM_PAUSE,state);
164 void QemuUIMenuBar::PowerOff(bool state){
165 powermenu->Enable(QEMU_VM_SHUTDOWN,state);
168 void QemuUIMenuBar::Reset(bool state){
169 powermenu->Enable(QEMU_VM_RESET,state);
172 void QemuUIMenuBar::EnableToolbar(bool value){
173 viewmenu->Enable(QEMU_TOOLBAR_TEXT,value);
174 viewmenu->Enable(QEMU_TOOLBAR_ICONS,value);
175 viewmenu->Enable(QEMU_TOOLBAR_BOTH,value);
178 void QemuUIMenuBar::CheckFavorites(bool value){
179 viewmenu->Check(QEMU_SPLIT,value);
182 void QemuUIMenuBar::UpdateWindowMenu(const size_t posOld,const size_t posNew){
183 wxMenuItem *item = windowmenu->FindItemByPosition(posOld);
184 if(item){
185 windowmenu->Remove(item);
186 windowmenu->Insert(posNew,item);
190 void QemuUIMenuBar::RemoveWindowMenuEntry(const size_t pos){
191 wxMenuItem *item = windowmenu->FindItemByPosition(pos);
192 if(item){
193 windowmenu->Remove(item);
194 delete item;
195 CheckWindowMenuEntry(pos > 0 ? pos - 1 : 0);
199 void QemuUIMenuBar::InsertWindowMenuEntry(const size_t pos,const wxString& title){
200 /* there seem to be a problem in wxwidgets which occurs
201 * when radio items are removed and then later back added
202 * so this is an ugly workaround. All items are removed
203 * and then back added.
205 * see also my post to wx-dev
206 * http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?5:mss:76732:200608:mfgbpjnmoondkdinmimb
208 const int count = windowmenu->GetMenuItemCount();
209 wxMenuItem *tmp[count];
210 for(int i = count - 1; i >= 0; i--){
211 tmp[i] = windowmenu->FindItemByPosition(i);
212 windowmenu->Remove(tmp[i]);
215 wxMenuItem *workaround = windowmenu->Append(-1,wxEmptyString);
216 windowmenu->Remove(workaround);
217 delete workaround;
219 const int id = wxNewId();
220 wxMenuItem *item = new wxMenuItem(windowmenu,id,title,wxEmptyString,
221 wxITEM_RADIO);
222 // this evalutes to false on windows, and thus the menuentries do not
223 // respond to user events.
224 if(GetParent()){
225 GetParent()->Connect(
227 wxEVT_COMMAND_MENU_SELECTED,
228 wxCommandEventHandler(QemuMainFrame::OnChangeWindow)
232 for(int i = 0; i < count; i++){
233 if(i == pos){
234 windowmenu->Append(item);
236 windowmenu->Append(tmp[i]);
240 void QemuUIMenuBar::AppendWindowMenuEntry(const wxString& title){
241 // subtract 3 because of the separator and
242 // the 2 standard menu items
243 const int pos = windowmenu->GetMenuItemCount() - 3;
244 InsertWindowMenuEntry(pos,title);
247 void QemuUIMenuBar::PrependWindowMenuEntry(const wxString& title){
248 InsertWindowMenuEntry(0,title);
251 void QemuUIMenuBar::CheckWindowMenuEntry(size_t pos){
252 // return if there are no entries available
253 // check for 3 because of the separator and the
254 // 2 standard menu items which are allways there
255 const size_t count = windowmenu->GetMenuItemCount();
257 if(count <= 3)
258 return;
260 wxMenuItem *item = windowmenu->FindItemByPosition(pos);
261 if(item)
262 item->Check(true);
265 int QemuUIMenuBar::GetCheckedWindowMenuEntry(){
266 for(int i = 0; i < windowmenu->GetMenuItemCount() - 3; i++){
267 wxMenuItem *item = windowmenu->FindItemByPosition(i);
268 if(item->IsChecked())
269 return i;
273 wxMenu* QemuUIMenuBar::GetFileMenu(){
274 return this->filemenu;
277 void QemuUIMenuBar::UpdateFileHistory(const size_t fileHistoryCount){
278 wxMenuItem *separator = NULL;
279 for(int i = filemenu->GetMenuItemCount() - 1; i >= 0; i--){
280 separator = filemenu->FindItemByPosition(i);
281 if(separator->GetKind() == wxITEM_SEPARATOR){
282 filemenu->Remove(separator);
285 if(fileHistoryCount > 0){
286 filemenu->InsertSeparator(filemenu->GetMenuItemCount() - fileHistoryCount - 1);
288 wxMenuItem *exit = filemenu->Remove(QEMU_QUIT);
289 filemenu->AppendSeparator();
290 filemenu->Append(exit);