InfoEditor.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* InfoEditor.cpp
  2. *
  3. * Copyright (C) 2004-2011,2012,2013,2015,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 "InfoEditor.h"
  19. Thing_implement (InfoEditor, TextEditor, 0);
  20. static InfoEditor theReferenceToTheOnlyInfoEditor;
  21. void structInfoEditor :: v_destroy () noexcept {
  22. theReferenceToTheOnlyInfoEditor = nullptr; // undangle
  23. InfoEditor_Parent :: v_destroy ();
  24. }
  25. void structInfoEditor :: v_clear () {
  26. Melder_clearInfo ();
  27. }
  28. InfoEditor InfoEditor_getTheReferenceToTheOnlyInstance () {
  29. if (! theReferenceToTheOnlyInfoEditor) {
  30. autoInfoEditor editor = Thing_new (InfoEditor);
  31. TextEditor_init (editor.get(), U"");
  32. Thing_setName (editor.get(), U"Praat Info");
  33. theReferenceToTheOnlyInfoEditor = editor.get();
  34. editor.releaseToUser();
  35. }
  36. return theReferenceToTheOnlyInfoEditor;
  37. }
  38. static void gui_information (conststring32 message) {
  39. InfoEditor editor = InfoEditor_getTheReferenceToTheOnlyInstance ();
  40. GuiText_setString (editor -> textWidget, message);
  41. GuiThing_show (editor -> windowForm);
  42. /*
  43. Try to make sure that the invalidated text widget and the elements of the fronted window are
  44. redrawn before the next event.
  45. The following Praat script can test this:
  46. writeInfoLine: "hoi"
  47. for i to 100
  48. appendInfoLine: i
  49. endfor
  50. The Info window should scroll continuously while the lines are added,
  51. not just show the end result.
  52. */
  53. #if cocoa
  54. #if 1
  55. NSEvent *nsEvent = [NSApp
  56. nextEventMatchingMask: NSAnyEventMask
  57. untilDate: [NSDate distantPast]
  58. inMode: NSDefaultRunLoopMode
  59. dequeue: NO
  60. ];
  61. if (nsEvent) {
  62. NSUInteger nsEventType = [nsEvent type];
  63. if (nsEventType == NSKeyDown) NSBeep ();
  64. //[[nsEvent window] sendEvent: nsEvent];
  65. }
  66. #else
  67. /*
  68. The following is an attempt to explicitly perform the actions that event waiting is supposed to perform.
  69. It would be nice not to actually have to wait for events (with nextEventMatchingMask),
  70. because we are not interested in the events; we're interested only in the graphics update.
  71. */
  72. //[editor -> windowForm -> d_cocoaShell displayIfNeeded]; // apparently, this does not suffice
  73. //[editor -> textWidget -> d_cocoaTextView lockFocus]; // this displays the menu as well as the text
  74. [editor -> windowForm -> d_cocoaShell display]; // this displays the menu as well as the text
  75. //[editor -> textWidget -> d_cocoaTextView displayIfNeeded]; // this displays only the text
  76. //[editor -> textWidget -> d_cocoaTextView display];
  77. //[editor -> textWidget -> d_cocoaTextView unlockFocus]; // this displays the menu as well as the text
  78. [editor -> windowForm -> d_cocoaShell flushWindow];
  79. [NSApp updateWindows]; // called automatically?
  80. #endif
  81. #elif defined (macintosh)
  82. GuiShell_drain (editor -> windowForm);
  83. #endif
  84. }
  85. void InfoEditor_injectInformationProc () {
  86. Melder_setInformationProc (gui_information);
  87. }
  88. /* End of file InfoEditor.cpp */