Tux Paint for macOS can localize menus (feature request #183)
Tux Paint for macOS can now localize the macOS menubar. Translation files (*.po) will be required for the actual translations to show.
This commit is contained in:
parent
aa4c72d4ed
commit
7aa000b68a
4 changed files with 141 additions and 2 deletions
10
Makefile
10
Makefile
|
|
@ -159,7 +159,7 @@ ios_BUNDLE:=./TuxPaint-$(SDK).app
|
||||||
BUNDLE:=$($(OS)_BUNDLE)
|
BUNDLE:=$($(OS)_BUNDLE)
|
||||||
|
|
||||||
windows_ARCH_LIBS:=obj/win32_print.o obj/resource.o obj/win32_trash.o
|
windows_ARCH_LIBS:=obj/win32_print.o obj/resource.o obj/win32_trash.o
|
||||||
macos_ARCH_LIBS:=src/macos_print.m obj/macos.o
|
macos_ARCH_LIBS:=src/macos_print.m obj/macos.o obj/macosm.o
|
||||||
ios_ARCH_LIBS:=src/ios_print.m obj/ios.o
|
ios_ARCH_LIBS:=src/ios_print.m obj/ios.o
|
||||||
beos_ARCH_LIBS:=obj/BeOS_print.o
|
beos_ARCH_LIBS:=obj/BeOS_print.o
|
||||||
linux_ARCH_LIBS:=obj/postscript_print.o
|
linux_ARCH_LIBS:=obj/postscript_print.o
|
||||||
|
|
@ -1304,10 +1304,16 @@ obj/postscript_print.o: src/postscript_print.c \
|
||||||
|
|
||||||
obj/macos.o: src/macos.c src/macos.h src/platform.h src/debug.h
|
obj/macos.o: src/macos.c src/macos.h src/platform.h src/debug.h
|
||||||
@echo
|
@echo
|
||||||
@echo "...Compiling macOS support..."
|
@echo "...Compiling macOS support (Part 1)..."
|
||||||
@$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \
|
@$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \
|
||||||
-c src/macos.c -o obj/macos.o
|
-c src/macos.c -o obj/macos.o
|
||||||
|
|
||||||
|
obj/macosm.o: src/macos.m src/macos.h src/platform.h src/debug.h
|
||||||
|
@echo
|
||||||
|
@echo "...Compiling macOS support (Part 2)..."
|
||||||
|
@$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \
|
||||||
|
-c src/macos.m -o obj/macosm.o
|
||||||
|
|
||||||
obj/ios.o: src/ios.c src/ios.h src/platform.h src/debug.h
|
obj/ios.o: src/ios.c src/ios.h src/platform.h src/debug.h
|
||||||
@echo
|
@echo
|
||||||
@echo "...Compiling iOS support..."
|
@echo "...Compiling iOS support..."
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
#define KMOD_CTRL KMOD_META /* Anywhere Linux/Windows uses CTRL, use CMD on macOS */
|
#define KMOD_CTRL KMOD_META /* Anywhere Linux/Windows uses CTRL, use CMD on macOS */
|
||||||
|
|
||||||
|
|
||||||
|
void apple_init(void);
|
||||||
const char *apple_fontsPath(void);
|
const char *apple_fontsPath(void);
|
||||||
const char *apple_preferencesPath(void);
|
const char *apple_preferencesPath(void);
|
||||||
const char *apple_globalPreferencesPath(void);
|
const char *apple_globalPreferencesPath(void);
|
||||||
|
|
|
||||||
128
src/macos.m
Normal file
128
src/macos.m
Normal file
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
macos.m
|
||||||
|
|
||||||
|
Copyright (c) 2022
|
||||||
|
http://www.tuxpaint.org/
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
(See COPYING.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <libintl.h>
|
||||||
|
#import "macos.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void setupApplicationMenu(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Forked from SDLMain.m that comes with the SDL source code that comes with
|
||||||
|
* MacPorts. Credits to Darrell Walisser <dwaliss1@purdue.edu> and Max Horn
|
||||||
|
* <max@quendi.de>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* warning: this code is very odd */
|
||||||
|
NSMenu *appleMenu;
|
||||||
|
NSMenuItem *menuItem;
|
||||||
|
NSString *title;
|
||||||
|
|
||||||
|
appleMenu = [[NSMenu alloc] initWithTitle:@""];
|
||||||
|
|
||||||
|
/* Add menu items */
|
||||||
|
title = [NSString stringWithUTF8String:gettext("About Tux Paint")];
|
||||||
|
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
|
||||||
|
|
||||||
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
title = [NSString stringWithUTF8String:gettext("Hide Tux Paint")];
|
||||||
|
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
|
||||||
|
|
||||||
|
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:[NSString stringWithUTF8String:gettext("Hide Others")] action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
|
||||||
|
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
|
||||||
|
|
||||||
|
[appleMenu addItemWithTitle:[NSString stringWithUTF8String:gettext("Show All")] action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
||||||
|
|
||||||
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
title = [NSString stringWithUTF8String:gettext("Quit Tux Paint")];
|
||||||
|
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
||||||
|
|
||||||
|
|
||||||
|
/* Put menu into the menubar */
|
||||||
|
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
||||||
|
[menuItem setSubmenu:appleMenu];
|
||||||
|
[[NSApp mainMenu] addItem:menuItem];
|
||||||
|
|
||||||
|
/* Tell the application object that this is now the application menu */
|
||||||
|
[NSApp setAppleMenu:appleMenu];
|
||||||
|
|
||||||
|
/* Finally give up our references to the objects */
|
||||||
|
[appleMenu release];
|
||||||
|
[menuItem release];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void setupWindowMenu(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Forked from SDLMain.m that comes with the SDL source code that comes with
|
||||||
|
* MacPorts. Credits to Darrell Walisser <dwaliss1@purdue.edu> and Max Horn
|
||||||
|
* <max@quendi.de>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
NSMenu *windowMenu;
|
||||||
|
NSMenuItem *windowMenuItem;
|
||||||
|
NSMenuItem *menuItem;
|
||||||
|
|
||||||
|
windowMenu = [[NSMenu alloc] initWithTitle:[NSString stringWithUTF8String:gettext("Window")]];
|
||||||
|
|
||||||
|
/* "Minimize" item */
|
||||||
|
menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithUTF8String:gettext("Minimize")] action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
||||||
|
[windowMenu addItem:menuItem];
|
||||||
|
[menuItem release];
|
||||||
|
|
||||||
|
/* Put menu into the menubar */
|
||||||
|
windowMenuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithUTF8String:gettext("Window")] action:nil keyEquivalent:@""];
|
||||||
|
[windowMenuItem setSubmenu:windowMenu];
|
||||||
|
[[NSApp mainMenu] addItem:windowMenuItem];
|
||||||
|
|
||||||
|
/* Tell the application object that this is now the window menu */
|
||||||
|
[NSApp setWindowsMenu:windowMenu];
|
||||||
|
|
||||||
|
/* Finally give up our references to the objects */
|
||||||
|
[windowMenu release];
|
||||||
|
[windowMenuItem release];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void removeSdlMenu(void)
|
||||||
|
{
|
||||||
|
NSMenu* rootMenu = [NSApp mainMenu];
|
||||||
|
|
||||||
|
/* SDL has two menus. Remove both. */
|
||||||
|
|
||||||
|
[rootMenu removeItemAtIndex:0];
|
||||||
|
[rootMenu removeItemAtIndex:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void apple_init(void)
|
||||||
|
{
|
||||||
|
/* Override SDL's default menu with our gettext-translatable menu. We do
|
||||||
|
* this by adding our menus, then removing the menus installed by SDL. */
|
||||||
|
setupApplicationMenu();
|
||||||
|
setupWindowMenu();
|
||||||
|
removeSdlMenu();
|
||||||
|
}
|
||||||
|
|
@ -25971,6 +25971,10 @@ static void setup(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
apple_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
im_init(&im_data, get_current_language());
|
im_init(&im_data, get_current_language());
|
||||||
|
|
||||||
#ifndef NO_SDLPANGO
|
#ifndef NO_SDLPANGO
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue