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-2013 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     setFocusable(true);
00068 
00069     // create single shot timer
00070     this->timer = new MMSTimer(true);
00071     this->timeOut_connection = this->timer->timeOut.connect(sigc::mem_fun(this, &MMSPopupWindow::timeOut));
00072 
00073     return MMSWindow::create(dx, dy, w, h, alignment, flags, own_surface, backbuffer);
00074 }
00075 
00076 void MMSPopupWindow::timeOut(void) {
00077 
00078     // timeout reached, hide the window
00079     hide(false, true);
00080 }
00081 
00082 void MMSPopupWindow::afterShowAction(MMSPulser *pulser) {
00083 
00084     // call default window routine
00085     MMSWindow::afterShowAction(pulser);
00086 
00087     // start the timer
00088     unsigned int duration = getDuration();
00089     if (duration > 0) {
00090         this->timer->start(duration * 1000);
00091     }
00092 }
00093 
00094 bool MMSPopupWindow::beforeHideAction(MMSPulser *pulser) {
00095 
00096     // stop the timer if running
00097     this->timer->stop();
00098 
00099     // call default window routine and return
00100     return MMSWindow::beforeHideAction(pulser);
00101 }
00102 
00103 
00104 /***********************************************/
00105 /* begin of theme access methods (get methods) */
00106 /***********************************************/
00107 
00108 #define GETPOPUPWINDOW(x) \
00109     if (this->myPopupWindowClass.is##x()) return myPopupWindowClass.get##x(); \
00110     else if ((popupWindowClass)&&(popupWindowClass->is##x())) return popupWindowClass->get##x(); \
00111     else return this->theme->popupWindowClass.get##x();
00112 
00113 unsigned int MMSPopupWindow::getDuration() {
00114     GETPOPUPWINDOW(Duration);
00115 }
00116 
00117 /***********************************************/
00118 /* begin of theme access methods (set methods) */
00119 /***********************************************/
00120 
00121 void MMSPopupWindow::setDuration(unsigned int duration) {
00122     myPopupWindowClass.setDuration(duration);
00123 
00124     /* restart timer if already running */
00125     if(duration == 0) {
00126         this->timer->stop();
00127     } else {
00128         if(this->isShown()) {
00129             if(!this->timer->isRunning()) {
00130                 this->timer->start(duration * 1000);
00131             } else {
00132                 this->timer->restart();
00133             } 
00134         }
00135     }
00136 }
00137 
00138 void MMSPopupWindow::updateFromThemeClass(MMSPopupWindowClass *themeClass) {
00139     if (themeClass->isDuration())
00140         setDuration(themeClass->getDuration());
00141 
00142     MMSWindow::updateFromThemeClass(&(themeClass->windowClass));
00143 }
00144 
00145 /***********************************************/
00146 /* end of theme access methods                 */
00147 /***********************************************/

Generated by doxygen