Skip to content

Commit

Permalink
Merge pull request #1828 from arturo-lang/add-support-for-window-menus
Browse files Browse the repository at this point in the history
Add (better) support for window menus
  • Loading branch information
drkameleon authored Dec 30, 2024
2 parents df74e97 + 3e29d2d commit d39fc7b
Show file tree
Hide file tree
Showing 7 changed files with 755 additions and 7 deletions.
83 changes: 83 additions & 0 deletions src/extras/menus.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#=======================================================
# Windows management
# and utilities
#
# (c) 2024 Yanis Zafirópulos
#
# @license: see LICENSE file
# @file: extras/windows.nim
#=======================================================

#=======================================
# Libraries
#=======================================

import os

import extras/window

#=======================================
# Compilation & Linking
#=======================================

{.passC: "-I" & parentDir(currentSourcePath()) .}

when defined(linux):
{.compile("menus/menus.cc", staticExec"pkg-config --cflags gtk+-3.0 webkit2gtk-4.0").}
{.passC: staticExec"pkg-config --cflags gtk+-3.0 webkit2gtk-4.0".}
{.passL: staticExec"pkg-config --libs gtk+-3.0 webkit2gtk-4.0".}
elif defined(freebsd) or defined(netbsd) or defined(openbsd):
{.compile("menus/menus.cc", staticExec"pkg-config --cflags gtk3 webkit2-gtk3").}
{.passC: staticExec"pkg-config --cflags gtk3 webkit2-gtk3".}
{.passL: staticExec"pkg-config --libs gtk3 webkit2-gtk3".}
elif defined(macosx):
{.compile("menus/menus.cc", "-framework Foundation -framework AppKit -x objective-c++").}
{.passL: "-framework AppKit".}
elif defined(windows):
{.compile("menus/menus.cc", "-std=c++17").}
{.passL: """-std=c++17 -lgdiplus -lshlwapi""".} # version.lib shell32.lib gdiplus.lib

#=======================================
# Types
#=======================================

type
MenuActionCallback* = proc(userData: pointer) {.cdecl.}

MenuItemObj* {.importc: "struct MenuItemObj", bycopy.} = object
label*: cstring
shortcut*: cstring
enabled*: bool
checked*: bool
action*: MenuActionCallback
userData*: pointer
submenu*: MenuObj

MenuObj* {.importc: "struct MenuObj", bycopy.} = object
title*: cstring
items*: ptr MenuItemObj
itemCount*: csize_t

#=======================================
# Function prototypes
#=======================================

{.push header: "menus/menus.h", cdecl.}

# MenuObj management functions
proc create_menu*(title: cstring): ptr MenuObj {.importc.}
proc free_menu*(menu: ptr MenuObj) {.importc.}

proc add_menu_item*(menu: ptr MenuObj, label: cstring, action: MenuActionCallback): ptr MenuItemObj {.importc.}
proc add_menu_separator*(menu: ptr MenuObj): ptr MenuItemObj {.importc.}
proc add_submenu*(menu: ptr MenuObj, label: cstring, submenu: ptr MenuObj): ptr MenuItemObj {.importc.}

proc set_menu_item_enabled*(item: ptr MenuItemObj, enabled: bool) {.importc.}
proc set_menu_item_checked*(item: ptr MenuItemObj, checked: bool) {.importc.}
proc set_menu_item_shortcut*(item: ptr MenuItemObj, shortcut: cstring) {.importc.}

# Window menu bar functions
proc set_window_menu*(window: Window, menus: ptr ptr MenuObj, menuCount: csize_t) {.importc.}
proc remove_window_menu*(window: Window) {.importc.}

{.pop.}
Loading

0 comments on commit d39fc7b

Please sign in to comment.