Thu, 01 Jan 2015 17:22:55 +0100
improved box (Motif)
54
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2014 Olaf Wintermann. All rights reserved. |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <inttypes.h> |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <QMenuBar> |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include <QAction> |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "menu.h" |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "toolkit.h" |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "../common/context.h" |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #include "../ui/properties.h" |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "../ui/window.h" |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "stock.h" |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | static UcxList *menus; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | static UcxList *current; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | /* -------------------------- UiMenu -------------------------- */ |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | UiMenu::UiMenu(char* label) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | this->items = NULL; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | this->label = label; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | void UiMenu::addMenuItem(UiMenuItemI* item) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | items = ucx_list_append(items, item); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | void UiMenu::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | QMenu *m = NULL; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | if(menubar) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | m = menubar->addMenu(label); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | } else { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | m = menu->addMenu(label); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | UCX_FOREACH(elm, items) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | UiMenuItemI *item = (UiMenuItemI*)elm->data; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | item->addTo(obj, NULL, m); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | /* -------------------------- UiMenuItem -------------------------- */ |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | UiMenuItem::UiMenuItem(char* label, ui_callback f, void* userdata) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | this->label = label; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | this->callback = f; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | this->userdata = userdata; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | this->groups = NULL; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | void UiMenuItem::addGroup(int group) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | groups = ucx_list_append(groups, (void*)(intptr_t)group); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | void UiMenuItem::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | QString str = QString::fromUtf8(label); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | UiAction *action = new UiAction(obj, str, callback, userdata); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | menu->addAction(action); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | //UiEventWrapper *ev = new UiEventWrapper(callback, userdata); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | /* -------------------------- UiStMenuItem -------------------------- */ |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | UiStMenuItem::UiStMenuItem(char* stockid, ui_callback f, void* userdata) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | this->stockid = stockid; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | this->callback = f; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | this->userdata = userdata; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | this->groups = NULL; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | void UiStMenuItem::addGroup(int group) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | groups = ucx_list_append(groups, (void*)(intptr_t)group); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | void UiStMenuItem::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | UiStockItem *stockItem = ui_get_stock_item(stockid); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | QString str = QString::fromUtf8(stockItem->label); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | UiAction *action = new UiAction(obj, str, callback, userdata); |
55
9076eb40454d
added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
111 | action->setIcon(QIcon::fromTheme(stockItem->icon_name)); |
9076eb40454d
added toolbar (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
112 | action->setIconVisibleInMenu(true); |
54
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | menu->addAction(action); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | //UiEventWrapper *ev = new UiEventWrapper(callback, userdata); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | /* -------------------------- UiAction -------------------------- */ |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | UiAction::UiAction(UiObject *obj, QString &label, ui_callback f, void* userdata) : QAction(label, NULL) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | //QAction(label, NULL); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | this->obj = obj; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | this->callback = f; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | this->userdata = userdata; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | void UiAction::trigger() { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | UiEvent e; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | e.obj = obj; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | e.window = obj->window; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | e.document = obj->ctx->document; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | e.eventdata = NULL; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | e.intval = 0; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | callback(&e, userdata); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | void ui_menu(char *label) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | // free current menu hierarchy |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | ucx_list_free(current); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | // create menu |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | UiMenu *menu = new UiMenu(label); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | current = ucx_list_prepend(NULL, menu); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | menus = ucx_list_append(menus, menu); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | void ui_submenu(char *label) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | UiMenu *menu = new UiMenu(label); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | // add submenu to current menu |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | UiMenu *cm = (UiMenu*)current->data; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | cm->addMenuItem(menu); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | // set the submenu to current menu |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | current = ucx_list_prepend(current, menu); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | void ui_submenu_end() { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | if(ucx_list_size(current) < 2) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | return; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | current = ucx_list_remove(current, current); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | //UcxList *c = current; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | void ui_menuitem(char *label, ui_callback f, void *userdata) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | ui_menuitem_gr(label, f, userdata, -1); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | void ui_menuitem_st(char *stockid, ui_callback f, void *userdata) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | ui_menuitem_stgr(stockid, f, userdata, -1); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | void ui_menuitem_gr(char *label, ui_callback f, void *userdata, ...) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | if(!current) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | return; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | UiMenuItem *item = new UiMenuItem(label, f, userdata); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | // add groups |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | va_list ap; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | va_start(ap, userdata); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | int group; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | while((group = va_arg(ap, int)) != -1) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | item->addGroup(group); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | va_end(ap); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | UiMenu *cm = (UiMenu*)current->data; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | cm->addMenuItem(item); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | void ui_menuitem_stgr(char *stockid, ui_callback f, void *userdata, ...) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | if(!current) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | return; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | UiStMenuItem *item = new UiStMenuItem(stockid, f, userdata); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | // add groups |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | va_list ap; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | va_start(ap, userdata); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | int group; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | while((group = va_arg(ap, int)) != -1) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | item->addGroup(group); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | va_end(ap); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | UiMenu *cm = (UiMenu*)current->data; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | cm->addMenuItem(item); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | void ui_add_menus(UiObject *obj, QMainWindow *window) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | QMenuBar *mb = window->menuBar(); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | UCX_FOREACH(elm, menus) { |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | UiMenu *menu = (UiMenu*)elm->data; |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | menu->addTo(obj, mb, NULL); |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | } |
97bafeca1c7c
added Qt window and menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | } |