You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TXDialog.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. //
  19. // TXDialog.h
  20. //
  21. // A TXDialog is a pop-up dialog window. The dialog can be made visible by
  22. // calling its show() method. Dialogs can be modal or non-modal. For a modal
  23. // dialog box, the show() method only returns when the dialog box has been
  24. // dismissed. For a non-modal dialog box, the show() method returns
  25. // immediately.
  26. //
  27. #ifndef __TXDIALOG_H__
  28. #define __TXDIALOG_H__
  29. #include "TXWindow.h"
  30. #include <errno.h>
  31. class TXDialog : public TXWindow, public TXDeleteWindowCallback {
  32. public:
  33. TXDialog(Display* dpy, int width, int height, const char* name,
  34. bool modal_=false)
  35. : TXWindow(dpy, width, height), done(false), ok(false), modal(modal_)
  36. {
  37. toplevel(name, this);
  38. resize(width, height);
  39. }
  40. virtual ~TXDialog() {}
  41. // show() makes the dialog visible. For a modal dialog box, this processes X
  42. // events until the done flag has been set, after which it returns the value
  43. // of the ok flag. For a non-modal dialog box it always returns true
  44. // immediately.
  45. bool show() {
  46. ok = false;
  47. done = false;
  48. initDialog();
  49. raise();
  50. map();
  51. if (modal) {
  52. while (true) {
  53. TXWindow::handleXEvents(dpy);
  54. if (done) {
  55. return ok;
  56. }
  57. fd_set rfds;
  58. FD_ZERO(&rfds);
  59. FD_SET(ConnectionNumber(dpy), &rfds);
  60. int n = select(FD_SETSIZE, &rfds, 0, 0, 0);
  61. if (n < 0) throw rdr::SystemException("select",errno);
  62. }
  63. }
  64. return true;
  65. }
  66. // initDialog() can be overridden in a derived class. Typically it is used
  67. // to make sure that checkboxes have the right state, etc.
  68. virtual void initDialog() {}
  69. // resize() is overridden here to re-center the dialog
  70. void resize(int w, int h) {
  71. TXWindow::resize(w,h);
  72. int dpyWidth = WidthOfScreen(DefaultScreenOfDisplay(dpy));
  73. int dpyHeight = HeightOfScreen(DefaultScreenOfDisplay(dpy));
  74. setUSPosition((dpyWidth - width() - 10) / 2, (dpyHeight - height() - 30) / 2);
  75. }
  76. protected:
  77. virtual void deleteWindow(TXWindow* /*w*/) {
  78. ok = false;
  79. done = true;
  80. unmap();
  81. }
  82. bool done;
  83. bool ok;
  84. bool modal;
  85. };
  86. #endif