| 1 | /* Gui.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2008,2010-2017,2019-2021,2024-2026 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "GuiP.h"cxx . . $ `<file>/sys/GuiP.h`/ |
| 20 | #include "machine.h"cxx . . $ `<file>/sys/machine.h`/ |
| 21 | #include <locale.h> |
| 22 | |
| 23 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (GuiThing, Thing, 0); |
| 24 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (GuiControl, GuiThing, 0); |
| 25 | |
| 26 | int Gui_getResolutioncxx . . $ Gui_getResolution(dedf1e9b1c614a07). (GuiObjectcxx . . $ GuiObject# widget) { |
| 27 | static int resolution = 0; |
| 28 | if (0) { |
| 29 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 30 | resolution = gdk_screen_get_resolution (gdk_display_get_default_screen (gtk_widget_get_display (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (widget)))); |
| 31 | #elif motif |
| 32 | (void) widget; |
| 33 | resolution = 100; |
| 34 | #elif cocoa |
| 35 | (void) widget; |
| 36 | CGDirectDisplayID display = CGMainDisplayID (); |
| 37 | CGSize size = CGDisplayScreenSize (display); |
| 38 | resolution = Melder_iround (25.4 * (double) CGDisplayPixelsWide (display) / size.width); |
| 39 | //resolution = 72; |
| 40 | #else |
| 41 | Melder_crash (U"Gui_getResolution: unknown platform."); |
| 42 | #endif |
| 43 | } |
| 44 | return 100; // in conformance with most other applications; and so that fonts always look the same size in the Demo window |
| 45 | return resolution; |
| 46 | } |
| 47 | |
| 48 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 49 | void GuiGtk_initializecxx . . $ GuiGtk_initialize(49f6e7a06ebc5aa8). () { |
| 50 | static bool gtkHasBeenInitialized = false; |
| 51 | if (! gtkHasBeenInitialized) { |
| 52 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"before initing GTK: locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 53 | gtk_disable_setlocale (); // otherwise 1.5 will be written "1,5" on computers with a French or German locale |
| 54 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"during initing GTK: locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 55 | gtk_init_check (nullptr, nullptr); |
| 56 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"after initing GTK: locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr))); |
| 57 | gtkHasBeenInitialized = true; |
| 58 | } |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | void Gui_getWindowPositioningBoundscxx . . $ Gui_getWindowPositioningBounds(dec26d86168e59a). (double *x, double *y, double *width, double *height) { |
| 63 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 64 | GuiGtk_initializecxx . . $ GuiGtk_initialize(49f6e7a06ebc5aa8). (); |
| 65 | GdkScreen *screen = gdk_screen_get_default (); |
| 66 | /* |
| 67 | if (parent) { |
| 68 | GuiObject parent_win = gtk_widget_get_ancestor (GTK_WIDGET (parent), GTK_TYPE_WINDOW); |
| 69 | if (parent_win) { |
| 70 | screen = gtk_window_get_screen (GTK_WINDOW (parent_win)); |
| 71 | } |
| 72 | } |
| 73 | */ |
| 74 | if (x) *x = 0; |
| 75 | if (y) *y = 0; |
| 76 | if (width) *width = gdk_screen_get_width (screen); |
| 77 | if (height) *height = gdk_screen_get_height (screen); |
| 78 | #elif motif |
| 79 | #if 1 |
| 80 | RECT rect; |
| 81 | SystemParametersInfo (SPI_GETWORKAREA, 0, & rect, 0); // BUG: use GetMonitorInfo instead |
| 82 | if (x) *x = rect. left; |
| 83 | if (y) *y = rect. top; |
| 84 | if (width) *width = rect. right - rect. left - 2 * GetSystemMetrics (SM_CXSIZEFRAME); |
| 85 | if (height) *height = rect.bottom - rect.top - GetSystemMetrics (SM_CYCAPTION) - 2 * GetSystemMetrics (SM_CYSIZEFRAME); |
| 86 | #else |
| 87 | HMONITOR monitor = MonitorFromWindow (HWND window, MONITOR_DEFAULTTONEAREST); |
| 88 | MONITORINFO monitorInfo; |
| 89 | monitorInfo. cbSize = sizeof (MONITORINFO); |
| 90 | GetMonitorInfo (monitor, & monitorInfo); |
| 91 | if (x) *x = monitorInfo. rcWork. left; |
| 92 | if (y) *y = monitorInfo. rcWork. top; |
| 93 | if (width) *width = monitorInfo. rcWork. right - monitorInfo. rcWork. left; |
| 94 | if (height) *height = monitorInfo. rcWork.bottom - monitorInfo. rcWork.top /*- GetSystemMetrics (SM_CYMINTRACK)*/; // SM_CXSIZEFRAME SM_CYCAPTION |
| 95 | #endif |
| 96 | #elif cocoa |
| 97 | NSRect rect; |
| 98 | NSArray *screenArray = [NSScreen screens]; |
| 99 | NSUInteger screenCount = [screenArray count]; |
| 100 | Melder_assert (screenCount >= 1); // otherwise, output would be garbage |
| 101 | NSUInteger index = 0; |
| 102 | for (index = 0; index < screenCount; index ++) { |
| 103 | NSScreen *screen = [screenArray objectAtIndex: index]; |
| 104 | rect = [screen visibleFrame]; |
| 105 | } |
| 106 | if (x) *x = rect. origin. x; |
| 107 | if (y) *y = rect. origin. y; |
| 108 | if (width) *width = rect. size. width; |
| 109 | if (height) *height = rect. size. height - 22; // subtract title bar height (or is it the menu height?) |
| 110 | #endif |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | Fonts, brushes. |
| 115 | */ |
| 116 | |
| 117 | #if defined (macintosh) |
| 118 | NSFont *theMacGuiNormalLabelFont () { |
| 119 | static NSFont *font; |
| 120 | if (! font) |
| 121 | font = [NSFont systemFontOfSize: 13.0]; |
| 122 | return font; |
| 123 | } |
| 124 | NSFont *theMacGuiBoldLabelFont () { |
| 125 | static NSFont *font; |
| 126 | if (! font) |
| 127 | font = [NSFont boldSystemFontOfSize: 13.0]; |
| 128 | return font; |
| 129 | } |
| 130 | #elif defined (_WIN32) |
| 131 | HFONT theWinGuiNormalLabelFont () { |
| 132 | static HFONT font; |
| 133 | if (! font) |
| 134 | font = CreateFont (15, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, nullptr); |
| 135 | return font; |
| 136 | } |
| 137 | HFONT theWinGuiBoldLabelFont () { |
| 138 | static HFONT font; |
| 139 | if (! font) |
| 140 | font = CreateFont (15, 0, 0, 0, FW_HEAVY/*FW_BOLD*/, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, nullptr); |
| 141 | return font; |
| 142 | } |
| 143 | HBRUSH theWinGuiBackgroundBrush () { |
| 144 | static HBRUSH brush; |
| 145 | if (! brush) |
| 146 | brush = CreateSolidBrush (RGB (224, 224, 224)); |
| 147 | return brush; |
| 148 | } |
| 149 | #endif |
| 150 | |
| 151 | /* End of file Gui.cpp */ |