Gui.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Gui.cpp
  2. *
  3. * Copyright (C) 1992-2008,2010-2017 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 2 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. #include "GuiP.h"
  19. #include "machine.h"
  20. #include <math.h> // floor
  21. #include <locale.h>
  22. Thing_implement (GuiThing, Thing, 0);
  23. Thing_implement (GuiControl, GuiThing, 0);
  24. int Gui_getResolution (GuiObject widget) {
  25. static int resolution = 0;
  26. if (0) {
  27. #if gtk
  28. resolution = gdk_screen_get_resolution (gdk_display_get_default_screen (gtk_widget_get_display (GTK_WIDGET (widget))));
  29. #elif motif
  30. (void) widget;
  31. resolution = 100;
  32. #elif cocoa
  33. (void) widget;
  34. CGDirectDisplayID display = CGMainDisplayID ();
  35. CGSize size = CGDisplayScreenSize (display);
  36. resolution = Melder_iround (25.4 * (double) CGDisplayPixelsWide (display) / size.width);
  37. //resolution = 72;
  38. #else
  39. Melder_fatal (U"Gui_getResolution: unknown platform.");
  40. #endif
  41. }
  42. return 100; // in conformance with most other applications; and so that fonts always look the same size in the Demo window
  43. return resolution;
  44. }
  45. #if gtk
  46. void GuiGtk_initialize () {
  47. static bool gtkHasBeenInitialized = false;
  48. if (! gtkHasBeenInitialized) {
  49. trace (U"before initing GTK: locale is ", Melder_peek8to32 (setlocale (LC_ALL, nullptr)));
  50. gtk_disable_setlocale (); // otherwise 1.5 will be written "1,5" on computers with a French or German locale
  51. trace (U"during initing GTK: locale is ", Melder_peek8to32 (setlocale (LC_ALL, nullptr)));
  52. gtk_init_check (nullptr, nullptr);
  53. trace (U"after initing GTK: locale is ", Melder_peek8to32 (setlocale (LC_ALL, nullptr)));
  54. gtkHasBeenInitialized = true;
  55. }
  56. }
  57. #endif
  58. void Gui_getWindowPositioningBounds (double *x, double *y, double *width, double *height) {
  59. #if gtk
  60. GuiGtk_initialize ();
  61. GdkScreen *screen = gdk_screen_get_default ();
  62. /*
  63. if (parent) {
  64. GuiObject parent_win = gtk_widget_get_ancestor (GTK_WIDGET (parent), GTK_TYPE_WINDOW);
  65. if (parent_win) {
  66. screen = gtk_window_get_screen (GTK_WINDOW (parent_win));
  67. }
  68. }
  69. */
  70. if (x) *x = 0;
  71. if (y) *y = 0;
  72. if (width) *width = gdk_screen_get_width (screen);
  73. if (height) *height = gdk_screen_get_height (screen);
  74. #elif motif
  75. #if 1
  76. RECT rect;
  77. SystemParametersInfo (SPI_GETWORKAREA, 0, & rect, 0); // BUG: use GetMonitorInfo instead
  78. if (x) *x = rect. left;
  79. if (y) *y = rect. top;
  80. if (width) *width = rect. right - rect. left - 2 * GetSystemMetrics (SM_CXSIZEFRAME);
  81. if (height) *height = rect.bottom - rect.top - GetSystemMetrics (SM_CYCAPTION) - 2 * GetSystemMetrics (SM_CYSIZEFRAME);
  82. #else
  83. HMONITOR monitor = MonitorFromWindow (HWND window, MONITOR_DEFAULTTONEAREST);
  84. MONITORINFO monitorInfo;
  85. monitorInfo. cbSize = sizeof (MONITORINFO);
  86. GetMonitorInfo (monitor, & monitorInfo);
  87. if (x) *x = monitorInfo. rcWork. left;
  88. if (y) *y = monitorInfo. rcWork. top;
  89. if (width) *width = monitorInfo. rcWork. right - monitorInfo. rcWork. left;
  90. if (height) *height = monitorInfo. rcWork.bottom - monitorInfo. rcWork.top /*- GetSystemMetrics (SM_CYMINTRACK)*/; // SM_CXSIZEFRAME SM_CYCAPTION
  91. #endif
  92. #elif cocoa
  93. NSRect rect;
  94. NSArray *screenArray = [NSScreen screens];
  95. NSInteger screenCount = [screenArray count];
  96. NSInteger index = 0;
  97. for (index = 0; index < screenCount; index ++) {
  98. NSScreen *screen = [screenArray objectAtIndex: index];
  99. rect = [screen visibleFrame];
  100. }
  101. if (x) *x = rect. origin. x;
  102. if (y) *y = rect. origin. y;
  103. if (width) *width = rect. size. width;
  104. if (height) *height = rect. size. height - 22; // subtract title bar height (or is it the menu height?)
  105. #endif
  106. }
  107. /* End of file Gui.cpp */