GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/menus.c
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 33 0.0%
Functions: 0 5 0.0%
Branches: 0 16 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/ui/menus.h"
30
31 gate_ui_menulist_t* gate_ui_menulist_init(gate_ui_menulist_t* menulist)
32 {
33 if (menulist)
34 {
35 menulist->count = 0;
36 }
37 return menulist;
38 }
39 gate_ui_menu_entry_t* gate_ui_menulist_add(gate_ui_menulist_t* menulist, gate_uint32_t id, gate_uint32_t type, char const* text, gate_uint32_t flags)
40 {
41 gate_ui_menu_entry_t* entry = NULL;
42 if (menulist != NULL)
43 {
44 if (menulist->count < (sizeof(menulist->entries) / sizeof(menulist->entries[0])))
45 {
46 entry = &menulist->entries[menulist->count];
47 entry->id = id;
48 entry->entry_type = type;
49 entry->text = text;
50 entry->flags = flags;
51 entry->submenus = NULL;
52 ++menulist->count;
53 }
54 }
55 return entry;
56 }
57 void gate_ui_menu_attach_submenu(gate_ui_menu_entry_t* entry, gate_ui_menulist_t const* submenu)
58 {
59 entry->submenus = submenu;
60 }
61 gate_ui_menu_entry_t const* gate_ui_menulist_resolve(gate_ui_menulist_t const* menulist, gate_uint32_t id)
62 {
63 gate_ui_menu_entry_t const* ret = NULL;
64 gate_size_t ndx;
65 if (menulist != NULL)
66 {
67 for (ndx = 0; ndx < menulist->count; ++ndx)
68 {
69 if (menulist->entries[ndx].submenus != NULL)
70 {
71 ret = gate_ui_menulist_resolve(menulist->entries[ndx].submenus, id);
72 if (ret != NULL)
73 {
74 break;
75 }
76 }
77 if (menulist->entries[ndx].id == id)
78 {
79 ret = &menulist->entries[ndx];
80 break;
81 }
82 }
83 }
84
85 return ret;
86 }
87
88
89
90 #if defined(GATE_UI_WINAPI)
91
92 #include "gate/results.h"
93 #include "gate/ui/gateui_winapi.h"
94 #include "gate/platforms.h"
95
96 gate_result_t gate_ui_popupmenu_show(gate_ui_ctrl_t* parent, gate_ui_menulist_t const* menulist,
97 gate_ui_point_t const* position, gate_ui_menu_entry_t const** selected_entry)
98 {
99 HMENU hMenu = CreatePopupMenu();
100 HWND hParent = NULL;
101 BOOL result;
102 gate_uint16_t startId = 1024;
103 gate_ui_menu_entry_t const* menuentry;
104 POINT pos;
105 UINT flags;
106
107 if (position == NULL)
108 {
109 GetCursorPos(&pos);
110 }
111 else
112 {
113 pos.x = position->x;
114 pos.y = position->y;
115 }
116
117 gate_ui_winapi_build_menu((void*)hMenu, &startId, menulist);
118 if (parent != NULL)
119 {
120 hParent = (HWND)GATE_UI_WINAPI_GET_HWND(parent);
121 }
122 else
123 {
124 hParent = GetDesktopWindow();
125 }
126 flags = TPM_LEFTALIGN;
127 #if !defined(GATE_SYS_WIN16)
128 flags |= TPM_RETURNCMD | TPM_NONOTIFY;
129 #endif
130 result = TrackPopupMenu(hMenu, flags, pos.x, pos.y, 0, hParent, NULL);
131 if (result != FALSE)
132 {
133 startId = 1024;
134 menuentry = gate_ui_winapi_resolve_menu(&startId, (gate_uint16_t)result, menulist);
135 if (menuentry != NULL)
136 {
137 *selected_entry = menuentry;
138 return GATE_RESULT_OK;
139 }
140 }
141 return GATE_RESULT_CANCELED;
142 }
143 #endif /* GATE_UI_WINAPI */
144
145
146
147 #if defined(GATE_UI_GTK)
148
149 #include "gate/ui/gateui_gtk.h"
150
151 gate_result_t gate_ui_popupmenu_show(gate_ui_ctrl_t* parent, gate_ui_menulist_t const* menulist,
152 gate_ui_point_t const* position, gate_ui_menu_entry_t const** selected_entry)
153 {
154 return GATE_RESULT_NOTIMPLEMENTED;
155 }
156
157 #endif /* GATE_UI_GTK */
158
159
160
161 #if defined(GATE_UI_MOTIF)
162
163 #include "gate/results.h"
164
165 gate_result_t gate_ui_popupmenu_show(gate_ui_ctrl_t* parent, gate_ui_menulist_t const* menulist, gate_ui_point_t const* position,
166 gate_ui_menu_entry_t const** selected_entry)
167 {
168 return GATE_RESULT_NOTIMPLEMENTED;
169 }
170
171
172 #endif /* GATE_UI_MOTIF */
173