summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2025-11-19 16:57:02 +0100
committerMatthias Melcher <github@matthiasm.com>2025-11-19 16:58:08 +0100
commit94008f57c30eadff13217e3de733cb9895ee41e8 (patch)
tree905b8557229266ea825ae4959a96ed04ecfeecf1 /src
parent2182bd60c0cabbb6cf65ca953d4643ec03006725 (diff)
Add headline menu item style (#1059)
A menu item can be designated as a headline. Fully integrated and used in Fluid.
Diffstat (limited to 'src')
-rw-r--r--src/Fl_MacOS_Sys_Menu_Bar.mm16
-rw-r--r--src/Fl_Menu.cxx18
2 files changed, 28 insertions, 6 deletions
diff --git a/src/Fl_MacOS_Sys_Menu_Bar.mm b/src/Fl_MacOS_Sys_Menu_Bar.mm
index 87c5089cd..f41db31b4 100644
--- a/src/Fl_MacOS_Sys_Menu_Bar.mm
+++ b/src/Fl_MacOS_Sys_Menu_Bar.mm
@@ -229,6 +229,14 @@ const char *Fl_Mac_App_Menu::quit = "Quit %@";
FLMenuItem *item = [[FLMenuItem alloc] initWithTitle:title
action:selector
keyEquivalent:@""];
+ if (mitem->labelfont() & FL_BOLD) {
+ NSFont *boldFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]];
+ NSAttributedString *attributed =
+ [ [ [NSAttributedString alloc] initWithString:title
+ attributes:@{ NSFontAttributeName: boldFont }]
+ autorelease];
+ item.attributedTitle = attributed;
+ }
// >= 0 if mitem is in the menu items of fl_sys_menu_bar, -1 if not
NSInteger index = (fl_sys_menu_bar ? fl_sys_menu_bar->find_index(mitem) : -1);
[item setTag:index];
@@ -369,6 +377,14 @@ static void createSubMenu( NSMenu *mh, pFl_Menu_Item &mm, const Fl_Menu_Item *m
cnt = (int)[mh numberOfItems];
cnt--;
menuItem = [mh itemAtIndex:cnt];
+ if (mitem->labelfont() & FL_BOLD) {
+ NSFont *boldFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]];
+ NSAttributedString *attributed =
+ [ [ [NSAttributedString alloc] initWithString:title
+ attributes:@{ NSFontAttributeName: boldFont }]
+ autorelease];
+ menuItem.attributedTitle = attributed;
+ }
[menuItem setSubmenu:submenu];
[submenu release];
} else submenu = mh;
diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx
index f938f50d3..3ace3e495 100644
--- a/src/Fl_Menu.cxx
+++ b/src/Fl_Menu.cxx
@@ -727,7 +727,10 @@ static int forward(int menu) { // go to next item in menu menu if possible
do {
while (++item < m.numitems) {
const Fl_Menu_Item* m1 = m.menu->next(item);
- if (m1->activevisible()) {setitem(m1, menu, item); return 1;}
+ if (m1->selectable()) {
+ setitem(m1, menu, item);
+ return 1;
+ }
}
if (wrapped) break;
item = -1;
@@ -748,7 +751,10 @@ static int backward(int menu) { // previous item in menu menu if possible
do {
while (--item >= 0) {
const Fl_Menu_Item* m1 = m.menu->next(item);
- if (m1->activevisible()) {setitem(m1, menu, item); return 1;}
+ if (m1->selectable()) {
+ setitem(m1, menu, item);
+ return 1;
+ }
}
if (wrapped) break;
item = m.numitems;
@@ -868,7 +874,7 @@ int menuwindow::handle_part1(int e) {
goto RIGHT;
}
// Ignore keypresses over inactive items, mark KEYBOARD event as used.
- if (pp.current_item && !pp.current_item->activevisible())
+ if (pp.current_item && !pp.current_item->selectable())
return 1;
// Mark the menu 'done' which will trigger the callback
pp.state = DONE_STATE;
@@ -961,7 +967,7 @@ int menuwindow::handle_part1(int e) {
} else
#endif
// do nothing if they try to pick an inactive item, or a submenu with no callback
- if (!pp.current_item || (pp.current_item->activevisible() &&
+ if (!pp.current_item || (pp.current_item->selectable() &&
(!pp.current_item->submenu() || pp.current_item->callback_ || (pp.menubar && pp.menu_number <= 0))))
pp.state = DONE_STATE;
}
@@ -1038,7 +1044,7 @@ const Fl_Menu_Item* Fl_Menu_Item::pulldown(
}
initial_item = pp.current_item;
if (initial_item) {
- if (menubar && !initial_item->activevisible()) { // pointing at inactive item
+ if (menubar && !initial_item->selectable()) { // pointing at inactive item
Fl::grab(0);
return NULL;
}
@@ -1085,7 +1091,7 @@ const Fl_Menu_Item* Fl_Menu_Item::pulldown(
STARTUP:
menuwindow& cw = *pp.p[pp.menu_number];
const Fl_Menu_Item* m = pp.current_item;
- if (!m->activevisible()) { // pointing at inactive item
+ if (!m->selectable()) { // pointing at inactive item
cw.set_selected(-1);
initial_item = 0; // turn off startup code
continue;