-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1828 from arturo-lang/add-support-for-window-menus
Add (better) support for window menus
- Loading branch information
Showing
7 changed files
with
755 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.} |
Oops, something went wrong.