Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmspopupwindow.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2012 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsgui/mmspopupwindow.h"
00034 
00035 MMSPopupWindow::MMSPopupWindow(string className, string dx, string dy, string w, string h, MMSALIGNMENT alignment,
00036                                MMSWINDOW_FLAGS flags, MMSTheme *theme, bool *own_surface,
00037                                bool *backbuffer, unsigned int duration) {
00038     create(className, dx, dy, w, h, alignment, flags, theme, own_surface, backbuffer, duration);
00039 }
00040 
00041 MMSPopupWindow::MMSPopupWindow(string className, string w, string h, MMSALIGNMENT alignment,
00042                                MMSWINDOW_FLAGS flags, MMSTheme *theme, bool *own_surface,
00043                                bool *backbuffer, unsigned int duration) {
00044     create(className, "", "", w, h, alignment, flags, theme, own_surface, backbuffer, duration);
00045 }
00046 
00047 MMSPopupWindow::~MMSPopupWindow() {
00048     this->timeOut_connection.disconnect();
00049     if (this->timer) {
00050         delete this->timer;
00051     }
00052 }
00053 
00054 bool MMSPopupWindow::create(string className, string dx, string dy, string w, string h, MMSALIGNMENT alignment,
00055                             MMSWINDOW_FLAGS flags, MMSTheme *theme, bool *own_surface,
00056                             bool *backbuffer, unsigned int duration) {
00057     this->type = MMSWINDOWTYPE_POPUPWINDOW;
00058     this->className = className;
00059     if (theme) this->theme = theme; else this->theme = globalTheme;
00060     this->popupWindowClass = this->theme->getPopupWindowClass(className);
00061     this->baseWindowClass = &(this->theme->popupWindowClass.windowClass);
00062     if (this->popupWindowClass) this->windowClass = &(this->popupWindowClass->windowClass); else this->windowClass = NULL;
00063 
00064     if (duration)
00065         setDuration(duration);
00066 
00067     // create single shot timer
00068     this->timer = new MMSTimer(true);
00069     this->timeOut_connection = this->timer->timeOut.connect(sigc::mem_fun(this, &MMSPopupWindow::timeOut));
00070 
00071     return MMSWindow::create(dx, dy, w, h, alignment, flags, own_surface, backbuffer);
00072 }
00073 
00074 void MMSPopupWindow::timeOut(void) {
00075 
00076     // timeout reached, hide the window
00077     hide(false, true);
00078 }
00079 
00080 void MMSPopupWindow::afterShowAction(MMSPulser *pulser) {
00081 
00082     // call default window routine
00083     MMSWindow::afterShowAction(pulser);
00084 
00085     // start the timer
00086     unsigned int duration = getDuration();
00087     if (duration > 0) {
00088         this->timer->start(duration * 1000);
00089     }
00090 }
00091 
00092 bool MMSPopupWindow::beforeHideAction(MMSPulser *pulser) {
00093 
00094     // stop the timer if running
00095     this->timer->stop();
00096 
00097     // call default window routine and return
00098     return MMSWindow::beforeHideAction(pulser);
00099 }
00100 
00101 
00102 /***********************************************/
00103 /* begin of theme access methods (get methods) */
00104 /***********************************************/
00105 
00106 #define GETPOPUPWINDOW(x) \
00107     if (this->myPopupWindowClass.is##x()) return myPopupWindowClass.get##x(); \
00108     else if ((popupWindowClass)&&(popupWindowClass->is##x())) return popupWindowClass->get##x(); \
00109     else return this->theme->popupWindowClass.get##x();
00110 
00111 unsigned int MMSPopupWindow::getDuration() {
00112     GETPOPUPWINDOW(Duration);
00113 }
00114 
00115 /***********************************************/
00116 /* begin of theme access methods (set methods) */
00117 /***********************************************/
00118 
00119 void MMSPopupWindow::setDuration(unsigned int duration) {
00120     myPopupWindowClass.setDuration(duration);
00121 
00122     /* restart timer if already running */
00123     if(duration == 0) {
00124         this->timer->stop();
00125     } else {
00126         if(this->isShown()) {
00127             if(!this->timer->isRunning()) {
00128                 this->timer->start(duration * 1000);
00129             } else {
00130                 this->timer->restart();
00131             } 
00132         }
00133     }
00134 }
00135 
00136 void MMSPopupWindow::updateFromThemeClass(MMSPopupWindowClass *themeClass) {
00137     if (themeClass->isDuration())
00138         setDuration(themeClass->getDuration());
00139 
00140     MMSWindow::updateFromThemeClass(&(themeClass->windowClass));
00141 }
00142 
00143 /***********************************************/
00144 /* end of theme access methods                 */
00145 /***********************************************/

Generated by doxygen