Skip to content

Commit ae140b7

Browse files
authored
Merge pull request #113 from aryanchoudharypro/main
Implement missing wxMenu and wxMenuBar wrappers
2 parents f121e65 + 37ee30f commit ae140b7

File tree

5 files changed

+469
-1
lines changed

5 files changed

+469
-1
lines changed

rust/wxdragon-sys/cpp/include/widgets/wxd_menu.h

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ wxd_MenuBar_EnableItem(wxd_MenuBar_t* menubar, wxd_Id id, bool enable);
2424
WXD_EXPORTED bool
2525
wxd_MenuBar_IsItemEnabled(const wxd_MenuBar_t* menubar, wxd_Id id);
2626

27+
/**
28+
* @brief Check or uncheck a menu item by its id across the entire menubar.
29+
*/
30+
WXD_EXPORTED void
31+
wxd_MenuBar_CheckItem(wxd_MenuBar_t* menubar, wxd_Id id, bool check);
32+
33+
/**
34+
* @brief Query whether a menu item is checked via the menubar.
35+
*/
36+
WXD_EXPORTED bool
37+
wxd_MenuBar_IsItemChecked(const wxd_MenuBar_t* menubar, wxd_Id id);
38+
2739
/**
2840
* @brief Find a menu item by its id in the menubar.
2941
* @param menubar Pointer to wxMenuBar.
@@ -90,6 +102,18 @@ wxd_Menu_ItemEnable(wxd_Menu_t* menu, wxd_Id id, bool enable);
90102
WXD_EXPORTED bool
91103
wxd_Menu_IsItemEnabled(const wxd_Menu_t* menu, wxd_Id id);
92104

105+
/**
106+
* @brief Check or uncheck a menu item by its id.
107+
*/
108+
WXD_EXPORTED void
109+
wxd_Menu_CheckItem(wxd_Menu_t* menu, wxd_Id id, bool check);
110+
111+
/**
112+
* @brief Query whether a menu item is checked by its id.
113+
*/
114+
WXD_EXPORTED bool
115+
wxd_Menu_IsItemChecked(const wxd_Menu_t* menu, wxd_Id id);
116+
93117
/**
94118
* @brief Find a menu item by its id.
95119
* @param menu Pointer to wxMenu.
@@ -168,6 +192,75 @@ wxd_Menu_DeleteItem(wxd_Menu_t* menu, wxd_MenuItem_t* item);
168192
WXD_EXPORTED wxd_MenuItem_t*
169193
wxd_Menu_FindItemByPosition(const wxd_Menu_t* menu, size_t pos);
170194

195+
/**
196+
* @brief Get the help string associated with a menu item.
197+
*/
198+
WXD_EXPORTED int
199+
wxd_Menu_GetHelpString(const wxd_Menu_t* menu, wxd_Id id, char* buffer, size_t buffer_size);
200+
201+
/**
202+
* @brief Set the help string associated with a menu item.
203+
*/
204+
WXD_EXPORTED void
205+
wxd_Menu_SetHelpString(wxd_Menu_t* menu, wxd_Id id, const char* helpString);
206+
207+
/**
208+
* @brief Update the UI of the menu items.
209+
*/
210+
WXD_EXPORTED void
211+
wxd_Menu_UpdateUI(wxd_Menu_t* menu, wxd_EvtHandler_t* source);
212+
213+
/**
214+
* @brief Insert a break in the menu.
215+
*/
216+
WXD_EXPORTED void
217+
wxd_Menu_Break(wxd_Menu_t* menu);
218+
219+
// --- MenuBar Extended Functions ---
220+
221+
/**
222+
* @brief Get the menu at the specified index.
223+
*/
224+
WXD_EXPORTED wxd_Menu_t*
225+
wxd_MenuBar_GetMenu(const wxd_MenuBar_t* menubar, size_t index);
226+
227+
/**
228+
* @brief Get the number of menus in the menubar.
229+
*/
230+
WXD_EXPORTED size_t
231+
wxd_MenuBar_GetMenuCount(const wxd_MenuBar_t* menubar);
232+
233+
/**
234+
* @brief Find the index of a menu by its title.
235+
*/
236+
WXD_EXPORTED int
237+
wxd_MenuBar_FindMenu(const wxd_MenuBar_t* menubar, const char* title);
238+
239+
/**
240+
* @brief Enable or disable a whole menu.
241+
*/
242+
WXD_EXPORTED void
243+
wxd_MenuBar_EnableTop(wxd_MenuBar_t* menubar, size_t pos, bool enable);
244+
245+
/**
246+
* @brief Get the label of a top-level menu.
247+
*/
248+
WXD_EXPORTED int
249+
wxd_MenuBar_GetMenuLabel(const wxd_MenuBar_t* menubar, size_t pos, char* buffer, size_t buffer_size);
250+
251+
/**
252+
* @brief Set the label of a top-level menu.
253+
*/
254+
WXD_EXPORTED void
255+
wxd_MenuBar_SetMenuLabel(wxd_MenuBar_t* menubar, size_t pos, const char* label);
256+
257+
/**
258+
* @brief Replace the menu at the given position with another one.
259+
* Returns the old menu (caller takes ownership).
260+
*/
261+
WXD_EXPORTED wxd_Menu_t*
262+
wxd_MenuBar_Replace(wxd_MenuBar_t* menubar, size_t pos, wxd_Menu_t* menu, const char* title);
263+
171264
WXD_EXPORTED void
172265
wxd_MenuItem_Destroy(wxd_MenuItem_t* item);
173266

@@ -208,4 +301,23 @@ wxd_MenuItem_GetOwningWindow(const wxd_MenuItem_t* item);
208301
WXD_EXPORTED int
209302
wxd_MenuItem_GetId(const wxd_MenuItem_t* item);
210303

304+
/**
305+
* @brief Get the submenu associated with this menu item, if any.
306+
*/
307+
WXD_EXPORTED wxd_Menu_t*
308+
wxd_MenuItem_GetSubMenu(const wxd_MenuItem_t* item);
309+
310+
/**
311+
* @brief Set the bitmap for the menu item.
312+
*/
313+
WXD_EXPORTED void
314+
wxd_MenuItem_SetBitmap(wxd_MenuItem_t* item, const wxd_Bitmap_t* bitmap);
315+
316+
/**
317+
* @brief Get the bitmap associated with the menu item.
318+
* Returns a new heap-allocated clone of the bitmap; caller must destroy.
319+
*/
320+
WXD_EXPORTED wxd_Bitmap_t*
321+
wxd_MenuItem_GetBitmap(const wxd_MenuItem_t* item);
322+
211323
#endif // WXD_MENU_H

rust/wxdragon-sys/cpp/src/menu.cpp

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ wxd_MenuBar_IsItemEnabled(const wxd_MenuBar_t* menubar, wxd_Id id)
4949
return wx_menubar->IsEnabled(id);
5050
}
5151

52+
WXD_EXPORTED void
53+
wxd_MenuBar_CheckItem(wxd_MenuBar_t* menubar, wxd_Id id, bool check)
54+
{
55+
if (!menubar)
56+
return;
57+
wxMenuBar* wx_menubar = reinterpret_cast<wxMenuBar*>(menubar);
58+
wx_menubar->Check(id, check);
59+
}
60+
61+
WXD_EXPORTED bool
62+
wxd_MenuBar_IsItemChecked(const wxd_MenuBar_t* menubar, wxd_Id id)
63+
{
64+
if (!menubar)
65+
return false;
66+
const wxMenuBar* wx_menubar = reinterpret_cast<const wxMenuBar*>(menubar);
67+
return wx_menubar->IsChecked(id);
68+
}
69+
5270
WXD_EXPORTED wxd_MenuItem_t*
5371
wxd_MenuBar_FindItem(wxd_MenuBar_t* menubar, wxd_Id id, wxd_Menu_t** menu)
5472
{
@@ -176,6 +194,24 @@ wxd_Menu_IsItemEnabled(const wxd_Menu_t* menu, wxd_Id id)
176194
return item->IsEnabled();
177195
}
178196

197+
WXD_EXPORTED void
198+
wxd_Menu_CheckItem(wxd_Menu_t* menu, wxd_Id id, bool check)
199+
{
200+
if (!menu)
201+
return;
202+
wxMenu* wx_menu = reinterpret_cast<wxMenu*>(menu);
203+
wx_menu->Check(id, check);
204+
}
205+
206+
WXD_EXPORTED bool
207+
wxd_Menu_IsItemChecked(const wxd_Menu_t* menu, wxd_Id id)
208+
{
209+
if (!menu)
210+
return false;
211+
const wxMenu* wx_menu = reinterpret_cast<const wxMenu*>(menu);
212+
return wx_menu->IsChecked(id);
213+
}
214+
179215
WXD_EXPORTED wxd_MenuItem_t*
180216
wxd_Menu_FindItem(wxd_Menu_t* menu, wxd_Id id)
181217
{
@@ -316,6 +352,114 @@ wxd_Menu_FindItemByPosition(const wxd_Menu_t* menu, size_t pos)
316352
return reinterpret_cast<wxd_MenuItem_t*>(item);
317353
}
318354

355+
WXD_EXPORTED int
356+
wxd_Menu_GetHelpString(const wxd_Menu_t* menu, wxd_Id id, char* buffer, size_t buffer_size)
357+
{
358+
if (!menu)
359+
return -1;
360+
const wxMenu* wx_menu = reinterpret_cast<const wxMenu*>(menu);
361+
wxString help = wx_menu->GetHelpString(id);
362+
return (int)wxd_cpp_utils::copy_wxstring_to_buffer(help, buffer, buffer_size);
363+
}
364+
365+
WXD_EXPORTED void
366+
wxd_Menu_SetHelpString(wxd_Menu_t* menu, wxd_Id id, const char* helpString)
367+
{
368+
if (!menu)
369+
return;
370+
wxMenu* wx_menu = reinterpret_cast<wxMenu*>(menu);
371+
wx_menu->SetHelpString(id, wxString::FromUTF8(helpString ? helpString : ""));
372+
}
373+
374+
WXD_EXPORTED void
375+
wxd_Menu_UpdateUI(wxd_Menu_t* menu, wxd_EvtHandler_t* source)
376+
{
377+
if (!menu)
378+
return;
379+
wxMenu* wx_menu = reinterpret_cast<wxMenu*>(menu);
380+
wxEvtHandler* wx_source = source ? reinterpret_cast<wxEvtHandler*>(source) : nullptr;
381+
wx_menu->UpdateUI(wx_source);
382+
}
383+
384+
WXD_EXPORTED void
385+
wxd_Menu_Break(wxd_Menu_t* menu)
386+
{
387+
if (!menu)
388+
return;
389+
wxMenu* wx_menu = reinterpret_cast<wxMenu*>(menu);
390+
wx_menu->Break();
391+
}
392+
393+
// --- MenuBar Extended Functions ---
394+
395+
WXD_EXPORTED wxd_Menu_t*
396+
wxd_MenuBar_GetMenu(const wxd_MenuBar_t* menubar, size_t index)
397+
{
398+
if (!menubar)
399+
return nullptr;
400+
const wxMenuBar* wx_menubar = reinterpret_cast<const wxMenuBar*>(menubar);
401+
wxMenu* menu = wx_menubar->GetMenu(index);
402+
return reinterpret_cast<wxd_Menu_t*>(menu);
403+
}
404+
405+
WXD_EXPORTED size_t
406+
wxd_MenuBar_GetMenuCount(const wxd_MenuBar_t* menubar)
407+
{
408+
if (!menubar)
409+
return 0;
410+
const wxMenuBar* wx_menubar = reinterpret_cast<const wxMenuBar*>(menubar);
411+
return wx_menubar->GetMenuCount();
412+
}
413+
414+
WXD_EXPORTED int
415+
wxd_MenuBar_FindMenu(const wxd_MenuBar_t* menubar, const char* title)
416+
{
417+
if (!menubar)
418+
return wxNOT_FOUND;
419+
const wxMenuBar* wx_menubar = reinterpret_cast<const wxMenuBar*>(menubar);
420+
return wx_menubar->FindMenu(wxString::FromUTF8(title ? title : ""));
421+
}
422+
423+
WXD_EXPORTED void
424+
wxd_MenuBar_EnableTop(wxd_MenuBar_t* menubar, size_t pos, bool enable)
425+
{
426+
if (!menubar)
427+
return;
428+
wxMenuBar* wx_menubar = reinterpret_cast<wxMenuBar*>(menubar);
429+
wx_menubar->EnableTop(pos, enable);
430+
}
431+
432+
WXD_EXPORTED int
433+
wxd_MenuBar_GetMenuLabel(const wxd_MenuBar_t* menubar, size_t pos, char* buffer, size_t buffer_size)
434+
{
435+
if (!menubar)
436+
return -1;
437+
const wxMenuBar* wx_menubar = reinterpret_cast<const wxMenuBar*>(menubar);
438+
wxString label = wx_menubar->GetMenuLabel(pos);
439+
return (int)wxd_cpp_utils::copy_wxstring_to_buffer(label, buffer, buffer_size);
440+
}
441+
442+
WXD_EXPORTED void
443+
wxd_MenuBar_SetMenuLabel(wxd_MenuBar_t* menubar, size_t pos, const char* label)
444+
{
445+
if (!menubar)
446+
return;
447+
wxMenuBar* wx_menubar = reinterpret_cast<wxMenuBar*>(menubar);
448+
wx_menubar->SetMenuLabel(pos, wxString::FromUTF8(label ? label : ""));
449+
}
450+
451+
WXD_EXPORTED wxd_Menu_t*
452+
wxd_MenuBar_Replace(wxd_MenuBar_t* menubar, size_t pos, wxd_Menu_t* menu, const char* title)
453+
{
454+
if (!menubar || !menu)
455+
return nullptr;
456+
wxMenuBar* wx_menubar = reinterpret_cast<wxMenuBar*>(menubar);
457+
wxMenu* wx_menu = reinterpret_cast<wxMenu*>(menu);
458+
// wxMenuBar takes ownership of the new menu
459+
wxMenu* old = wx_menubar->Replace(pos, wx_menu, wxString::FromUTF8(title ? title : ""));
460+
return reinterpret_cast<wxd_Menu_t*>(old);
461+
}
462+
319463
// --- MenuItem Functions ---
320464
WXD_EXPORTED void
321465
wxd_MenuItem_Destroy(wxd_MenuItem_t* item)
@@ -412,4 +556,35 @@ wxd_MenuItem_GetId(const wxd_MenuItem_t* item)
412556
return wx_item->GetId();
413557
}
414558

559+
WXD_EXPORTED wxd_Menu_t*
560+
wxd_MenuItem_GetSubMenu(const wxd_MenuItem_t* item)
561+
{
562+
if (!item)
563+
return nullptr;
564+
const wxMenuItem* wx_item = reinterpret_cast<const wxMenuItem*>(item);
565+
return reinterpret_cast<wxd_Menu_t*>(wx_item->GetSubMenu());
566+
}
567+
568+
WXD_EXPORTED void
569+
wxd_MenuItem_SetBitmap(wxd_MenuItem_t* item, const wxd_Bitmap_t* bitmap)
570+
{
571+
if (!item)
572+
return;
573+
wxMenuItem* wx_item = reinterpret_cast<wxMenuItem*>(item);
574+
const wxBitmap* wx_bitmap = reinterpret_cast<const wxBitmap*>(bitmap);
575+
wx_item->SetBitmap(wx_bitmap ? *wx_bitmap : wxNullBitmap);
576+
}
577+
578+
WXD_EXPORTED wxd_Bitmap_t*
579+
wxd_MenuItem_GetBitmap(const wxd_MenuItem_t* item)
580+
{
581+
if (!item)
582+
return nullptr;
583+
const wxMenuItem* wx_item = reinterpret_cast<const wxMenuItem*>(item);
584+
const wxBitmap& bmp = wx_item->GetBitmap();
585+
if (!bmp.IsOk())
586+
return nullptr;
587+
return reinterpret_cast<wxd_Bitmap_t*>(new wxBitmap(bmp));
588+
}
589+
415590
} // extern "C"

0 commit comments

Comments
 (0)