GuiDialog.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* GuiDialog.cpp
  2. *
  3. * Copyright (C) 1993-2012,2013,2015,2017 Paul Boersma, 2013 Tom Naughton
  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. Thing_implement (GuiDialog, GuiShell, 0);
  20. #if gtk
  21. static void _GuiGtkDialog_destroyCallback (GuiObject widget, gpointer void_me) {
  22. (void) widget;
  23. iam (GuiDialog);
  24. forget (me);
  25. }
  26. static gboolean _GuiGtkDialog_goAwayCallback (GuiObject widget, GdkEvent *event, gpointer void_me) {
  27. (void) widget;
  28. (void) event;
  29. iam (GuiDialog);
  30. if (my d_goAwayCallback) {
  31. my d_goAwayCallback (my d_goAwayBoss);
  32. }
  33. return true; // signal handled (don't destroy dialog)
  34. }
  35. #elif motif
  36. static void _GuiMotifDialog_destroyCallback (GuiObject widget, XtPointer void_me, XtPointer call) {
  37. (void) widget; (void) call;
  38. iam (GuiDialog);
  39. forget (me);
  40. }
  41. static void _GuiMotifDialog_goAwayCallback (GuiObject widget, XtPointer void_me, XtPointer call) {
  42. (void) widget; (void) call;
  43. iam (GuiDialog);
  44. if (my d_goAwayCallback) {
  45. my d_goAwayCallback (my d_goAwayBoss);
  46. }
  47. }
  48. #endif
  49. GuiDialog GuiDialog_create (GuiWindow parent, int x, int y, int width, int height,
  50. conststring32 title, GuiShell_GoAwayCallback goAwayCallback, Thing goAwayBoss, uint32 flags)
  51. {
  52. autoGuiDialog me = Thing_new (GuiDialog);
  53. my d_parent = parent;
  54. my d_goAwayCallback = goAwayCallback;
  55. my d_goAwayBoss = goAwayBoss;
  56. #if gtk
  57. my d_gtkWindow = (GtkWindow *) gtk_dialog_new ();
  58. if (parent) {
  59. Melder_assert (parent -> d_widget);
  60. GuiObject toplevel = gtk_widget_get_ancestor (GTK_WIDGET (parent -> d_widget), GTK_TYPE_WINDOW);
  61. if (toplevel) {
  62. gtk_window_set_transient_for (GTK_WINDOW (my d_gtkWindow), GTK_WINDOW (toplevel));
  63. gtk_window_set_destroy_with_parent (GTK_WINDOW (my d_gtkWindow), true);
  64. }
  65. }
  66. g_signal_connect (G_OBJECT (my d_gtkWindow), "delete-event",
  67. goAwayCallback ? G_CALLBACK (_GuiGtkDialog_goAwayCallback) : G_CALLBACK (gtk_widget_hide_on_delete), me.get());
  68. gtk_window_set_default_size (GTK_WINDOW (my d_gtkWindow), width, height);
  69. gtk_window_set_modal (GTK_WINDOW (my d_gtkWindow), flags & GuiDialog_MODAL);
  70. GuiShell_setTitle (me.get(), title);
  71. GuiObject vbox = GTK_DIALOG (my d_gtkWindow) -> vbox;
  72. my d_widget = gtk_fixed_new ();
  73. _GuiObject_setUserData (my d_widget, me.get());
  74. gtk_widget_set_size_request (GTK_WIDGET (my d_widget), width, height);
  75. gtk_container_add (GTK_CONTAINER (vbox /*my d_gtkWindow*/), GTK_WIDGET (my d_widget));
  76. gtk_widget_show (GTK_WIDGET (my d_widget));
  77. g_signal_connect (G_OBJECT (my d_widget), "destroy", G_CALLBACK (_GuiGtkDialog_destroyCallback), me.get());
  78. #elif motif
  79. my d_xmShell = XmCreateDialogShell (parent -> d_widget, "dialogShell", nullptr, 0);
  80. XtVaSetValues (my d_xmShell, XmNdeleteResponse, goAwayCallback ? XmDO_NOTHING : XmUNMAP, XmNx, x, XmNy, y, nullptr);
  81. if (goAwayCallback) {
  82. XmAddWMProtocolCallback (my d_xmShell, 'delw', _GuiMotifDialog_goAwayCallback, (char *) me.get());
  83. }
  84. GuiShell_setTitle (me.get(), title);
  85. my d_widget = XmCreateForm (my d_xmShell, "dialog", nullptr, 0);
  86. XtVaSetValues (my d_widget, XmNwidth, (Dimension) width, XmNheight, (Dimension) height, nullptr);
  87. _GuiObject_setUserData (my d_widget, me.get());
  88. XtAddCallback (my d_widget, XmNdestroyCallback, _GuiMotifDialog_destroyCallback, me.get());
  89. XtVaSetValues (my d_widget, XmNdialogStyle,
  90. (flags & GuiDialog_MODAL) ? XmDIALOG_FULL_APPLICATION_MODAL : XmDIALOG_MODELESS,
  91. XmNautoUnmanage, False, nullptr);
  92. #elif cocoa
  93. (void) parent;
  94. NSRect rect = { { (CGFloat) x, (CGFloat) y }, { (CGFloat) width, (CGFloat) height } };
  95. my d_cocoaShell = [[GuiCocoaShell alloc]
  96. initWithContentRect: rect
  97. styleMask: NSTitledWindowMask | NSClosableWindowMask
  98. backing: NSBackingStoreBuffered
  99. defer: false];
  100. [my d_cocoaShell setMinSize: NSMakeSize (500.0, 500.0)]; // BUG: should not be needed
  101. [my d_cocoaShell setTitle: (NSString *) Melder_peek32toCfstring (title)];
  102. //[my d_cocoaShell makeKeyAndOrderFront: nil];
  103. my d_widget = (GuiObject) [my d_cocoaShell contentView];
  104. [my d_cocoaShell setUserData: me.get()];
  105. [my d_cocoaShell setReleasedWhenClosed: NO];
  106. #endif
  107. my d_shell = me.get();
  108. return me.releaseToAmbiguousOwner();
  109. }
  110. /* End of file GuiDialog.cpp */