tigervnc/tx/TXDialog.h
Constantin Kaplinsky 47ed8d321c Initial revision
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2 3789f03b-4d11-0410-bbf8-ca57d06f2519
2004-10-08 09:43:57 +00:00

91 lines
2.7 KiB
C++

/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
//
// TXDialog.h
//
// A TXDialog is a pop-up dialog window. The dialog can be made visible by
// calling its show() method. Dialogs can be modal or non-modal. For a modal
// dialog box, the show() method only returns when the dialog box has been
// dismissed. For a non-modal dialog box, the show() method returns
// immediately.
//
#ifndef __TXDIALOG_H__
#define __TXDIALOG_H__
#include "TXWindow.h"
#include <errno.h>
class TXDialog : public TXWindow, public TXDeleteWindowCallback {
public:
TXDialog(Display* dpy, int width, int height, const char* name,
bool modal_=false)
: TXWindow(dpy, width, height), done(false), ok(false), modal(modal_)
{
toplevel(name, this);
int dpyWidth = WidthOfScreen(DefaultScreenOfDisplay(dpy));
int dpyHeight = HeightOfScreen(DefaultScreenOfDisplay(dpy));
setUSPosition((dpyWidth - width - 10) / 2, (dpyHeight - height - 30) / 2);
}
virtual ~TXDialog() {}
// show() makes the dialog visible. For a modal dialog box, this processes X
// events until the done flag has been set, after which it returns the value
// of the ok flag. For a non-modal dialog box it always returns true
// immediately.
bool show() {
ok = false;
done = false;
initDialog();
raise();
map();
if (modal) {
while (true) {
TXWindow::handleXEvents(dpy);
if (done) {
return ok;
}
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(ConnectionNumber(dpy), &rfds);
int n = select(FD_SETSIZE, &rfds, 0, 0, 0);
if (n < 0) throw rdr::SystemException("select",errno);
}
}
return true;
}
// initDialog() can be overridden in a derived class. Typically it is used
// to make sure that checkboxes have the right state, etc.
virtual void initDialog() {}
protected:
virtual void deleteWindow(TXWindow* w) {
ok = false;
done = true;
unmap();
}
bool done;
bool ok;
bool modal;
};
#endif