// -*-c++-*- //------------------------------------------------------------------------------ // xword - (http://xword.sourceforge.net) // Copyright 2002 Patrick Crosby //------------------------------------------------------------------------------ // XDialog.cpp // // $Id: XDialog.cpp,v 1.2 2002/01/23 19:43:03 pcrosby Exp $ //------------------------------------------------------------------------------ // This program 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 program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple // Place, Suite 330, Boston, MA 02111-1307 USA //------------------------------------------------------------------------------ #include "XDialog.h" #include "Namespace.h" NAMESPACE_OPEN //------------------------------------------------------------------------------ XDialog* XDialog::m_pInstance(NULL); //------------------------------------------------------------------------------ XDialog::XDialog() { // set_usize(100, 100); // Needed to insure that the underlying GdkWindow* exists. This // is needed so that CenterOverWidget() can successfully call // gdk_window_get_size(). realize(); m_pPopupWin = GTK_WIDGET(>kobj()->window)->window; } //------------------------------------------------------------------------------ XDialog* XDialog::Instance() { if (m_pInstance == NULL) { m_pInstance = new XDialog; } return m_pInstance; } //------------------------------------------------------------------------------ void XDialog::WindowManagerDecides() { // You have to call set_position() before the map event. set_position(GTK_WIN_POS_NONE); show_all(); // This extra call to gdk_window_show() is needed to raise a // window that is mapped but obscured by another window or to // uniconify the window. gdk_window_show(m_pPopupWin); } //------------------------------------------------------------------------------ void XDialog::CenterOverDisplay() { // You have to call set_position() before the map event. set_position(GTK_WIN_POS_CENTER); show_all(); gdk_window_show(m_pPopupWin); // See comment in WindowManagerDecides(). } //------------------------------------------------------------------------------ void XDialog::CenterOverMouse() { // You have to call set_position() before the map event. set_position(GTK_WIN_POS_MOUSE); show_all(); gdk_window_show(m_pPopupWin); // See comment in WindowManagerDecides(). } //------------------------------------------------------------------------------ void XDialog::CenterOverWidget(Widget* targetWidget) { gint x, y, w, h; // parent upper-left position and width and height gint dw, dh; // popup`s width and height GdkWindow* gdkTargetWin = GTK_WIDGET(targetWidget->gtkobj())->window; if( gdkTargetWin == 0 ) { return CenterOverDisplay(); } if( !is_mapped() ) { // Surely there is an easier way to get the size of a Gtk::Window. gdk_window_get_origin(gdkTargetWin, &x, &y); gdk_window_get_size(gdkTargetWin, &w, &h); gdk_window_get_size(m_pPopupWin, &dw, &dh); int centerX = x + w/2 - dw/2; int centerY = y + h/2 - dh/2; set_position(GTK_WIN_POS_NONE); set_uposition(centerX, centerY); show_all(); } gdk_window_show(m_pPopupWin); // See comment in WindowManagerDecides(). } //------------------------------------------------------------------------------ gint XDialog::delete_event_impl(GdkEventAny* p0) { hide(); return 1; } //------------------------------------------------------------------------------ NAMESPACE_CLOSE //------------------------------------------------------------------------------