// messwin.cpp -- a message window // // Written by Frederic Bouvier, started February 2002. // // Copyright (C) 2002 Frederic Bouvier - fredb@users.sourceforge.net // // 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., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: messwin.cpp,v 1.9 2005/05/09 07:02:10 fredb Exp $ #include "messwin.hpp" #include #include #include "question.xpm" #include "information.xpm" #include "warning.xpm" #include "error.xpm" Fl_Pixmap FGSD_MessageWindow::_question( question_xpm ); Fl_Pixmap FGSD_MessageWindow::_information( information_xpm ); Fl_Pixmap FGSD_MessageWindow::_warning( warning_xpm ); Fl_Pixmap FGSD_MessageWindow::_error( error_xpm ); FGSD_MessageWindow::FGSD_MessageWindow( const char *__title, const char *__message, IconType __iconType, int __buttons ) : _window( 0 ) , _icon( 0 ) , _text( 0 ) , _btOk( 0 ) , _btCancel( 0 ) , _btYes( 0 ) , _btNo( 0 ) , _btRetry( 0 ) , _btAbort( 0 ) , _btHelp( 0 ) , _pressed( _None ) { int mx = 0, my = 0; fl_measure( __message, mx, my ); mx += 2; int bx = 0, by = 0; if ( __buttons & Yes ) { bx += 50; by = 40; } if ( __buttons & No ) { bx += 40; by = 40; } if ( __buttons & Retry ) { bx += 60; by = 40; } if ( __buttons & Abort ) { bx += 60; by = 40; } if ( __buttons & Ok ) { bx += 40; by = 40; } if ( __buttons & Cancel ) { bx += 70; by = 40; } if ( __buttons & Help ) { bx += 50; by = 40; } if ( bx > 0 ) bx -= 10; int ix = 0, iy = 0, bpp = 0; Fl_Image *image = 0; switch ( __iconType ) { case Question: image = &_question; break; case Information: image = &_information; break; case Warning: image = &_warning; break; case Error: image = &_error; break; } ix = image->w(); iy = image->h(); int dx = mx; if ( bx > dx ) dx = bx; int dy = my; if ( iy > dy ) dy = iy; int x = ( Fl::w() - ( dx + 20 ) ) / 2; int y = ( Fl::h() - ( dy + 20 + by ) ) / 2; int pmx = 10; if ( ix > 0 ) { pmx += ix + 10; dx += ix + 10; } _window = new FGSD_Window( x, y, dx + 20, dy + 20 + by, __title ); _window->begin(); if ( image ) { _icon = new Fl_Box( 10, 10, ix, iy ); _icon->box( FL_NO_BOX ); _icon->image( *image ); } _text = new Fl_Box( pmx, 10, mx, my, __message ); _text->align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT ); _text->box( FL_NO_BOX ); int px = 10; if ( __buttons & Yes ) { _btYes = new Fl_Button( px, iy + 20, 40, 30, "Yes" ); _btYes->callback( FGSD_MessageWindow::cbYes, this ); px += 50; } if ( __buttons & No ) { _btNo = new Fl_Button( px, iy + 20, 30, 30, "No" ); _btNo->callback( FGSD_MessageWindow::cbNo, this ); px += 40; } if ( __buttons & Retry ) { _btRetry = new Fl_Button( px, iy + 20, 50, 30, "Retry" ); _btRetry->callback( FGSD_MessageWindow::cbRetry, this ); px += 60; } if ( __buttons & Abort ) { _btAbort = new Fl_Button( px, iy + 20, 50, 30, "Abort" ); _btAbort->callback( FGSD_MessageWindow::cbAbort, this ); px += 60; } if ( __buttons & Ok ) { _btOk = new Fl_Button( px, iy + 20, 30, 30, "Ok" ); _btOk->callback( FGSD_MessageWindow::cbOk, this ); px += 40; } if ( __buttons & Cancel ) { _btCancel = new Fl_Button( px, iy + 20, 60, 30, "Cancel" ); _btCancel->callback( FGSD_MessageWindow::cbCancel, this ); px += 70; } if ( __buttons & Help ) { _btHelp = new Fl_Button( px, iy + 20, 40, 30, "Help" ); _btHelp->callback( FGSD_MessageWindow::cbHelp, this ); } _window->end(); } FGSD_MessageWindow::~FGSD_MessageWindow() { delete _window; } void FGSD_MessageWindow::cbOk( Fl_Widget *w, void *d ) { ((FGSD_MessageWindow *)d)->buttonPressed( Ok ); } void FGSD_MessageWindow::cbCancel( Fl_Widget *w, void *d ) { ((FGSD_MessageWindow *)d)->buttonPressed( Cancel ); } void FGSD_MessageWindow::cbYes( Fl_Widget *w, void *d ) { ((FGSD_MessageWindow *)d)->buttonPressed( Yes ); } void FGSD_MessageWindow::cbNo( Fl_Widget *w, void *d ) { ((FGSD_MessageWindow *)d)->buttonPressed( No ); } void FGSD_MessageWindow::cbRetry( Fl_Widget *w, void *d ) { ((FGSD_MessageWindow *)d)->buttonPressed( Retry ); } void FGSD_MessageWindow::cbAbort( Fl_Widget *w, void *d ) { ((FGSD_MessageWindow *)d)->buttonPressed( Abort ); } void FGSD_MessageWindow::cbHelp( Fl_Widget *w, void *d ) { ((FGSD_MessageWindow *)d)->buttonPressed( Help ); } void FGSD_MessageWindow::buttonPressed( Button b ) { _pressed = b; _window->set_value(); _window->hide(); }