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

mmsfbwindow.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/fb/mmsfbwindow.h"
00034 #include "mmsgui/fb/mmsfbwindowmanager.h"
00035 
00036 /*****************************************************************************/
00037 /* Use DFB Window Manager                                                    */
00038 /*****************************************************************************/
00039 #ifdef USE_DFB_WINMAN
00040 
00041 #define INITCHECK  if(!this->dfbwindow){MMSFB_SetError(0,"not initialized");return false;}
00042 
00043 MMSFBWindow::MMSFBWindow(IDirectFBWindow *dfbwindow, int x, int y) {
00044     /* init me */
00045     this->dfbwindow = dfbwindow;
00046     this->surface = NULL;
00047 
00048     /* get the current config */
00049     if (this->dfbwindow) {
00050         getConfiguration();
00051         this->dfbwindow->SetOpacity(this->dfbwindow, 0);
00052         this->config.posx = x;
00053         this->config.posy = y;
00054         this->config.opacity = 255;
00055         this->config.shown = false;
00056     }
00057 }
00058 
00059 MMSFBWindow::~MMSFBWindow() {
00060     if (this->dfbwindow)
00061         this->dfbwindow->Release(this->dfbwindow);
00062 }
00063 
00064 bool MMSFBWindow::getSurface(MMSFBSurface **surface) {
00065     DFBResult           dfbres;
00066     IDirectFBSurface    *dfbsurface;
00067 
00068     /* check if initialized */
00069     INITCHECK;
00070 
00071     if (this->surface) {
00072         /* i have already a surface */
00073         *surface = this->surface;
00074         return true;
00075     }
00076 
00077     /* get windows surface */
00078     if ((dfbres=this->dfbwindow->GetSurface(this->dfbwindow, &dfbsurface)) != DFB_OK) {
00079         MMSFB_SetError(dfbres, "IDirectFBWindow::GetSurface() failed");
00080         return false;
00081     }
00082 
00083     /* create a new surface instance */
00084     *surface = new MMSFBSurface(dfbsurface);
00085     if (!*surface) {
00086         dfbsurface->Release(dfbsurface);
00087         MMSFB_SetError(0, "cannot create new instance of MMSFBSurface");
00088         return false;
00089     }
00090 
00091     /* save this for the next call */
00092     this->surface = *surface;
00093 
00094     return true;
00095 }
00096 
00097 bool MMSFBWindow::getConfiguration(MMSFBWindowConfig *config) {
00098     DFBResult   dfbres;
00099 
00100     /* check if initialized */
00101     INITCHECK;
00102 
00103     /* get windows surface */
00104     MMSFBSurface *s;
00105     if (!getSurface(&s))
00106         return false;
00107 
00108     /* get surface config */
00109     if (!this->surface->getConfiguration(&(this->config.surface_config)))
00110         return false;
00111 
00112     /* fill return config */
00113     if (config)
00114         *config = this->config;
00115 
00116     return true;
00117 }
00118 
00119 bool MMSFBWindow::isShown() {
00120 
00121     /* check if initialized */
00122     INITCHECK;
00123 
00124     /* return the shown flag */
00125     return this->config.shown;
00126 }
00127 
00128 bool MMSFBWindow::show() {
00129     DFBResult   dfbres;
00130 
00131     /* check if initialized */
00132     INITCHECK;
00133 
00134     /* already shown */
00135     if (this->config.shown)
00136         return true;
00137 
00138     /* set the opacity */
00139     if ((dfbres=this->dfbwindow->SetOpacity(this->dfbwindow, this->config.opacity)) != DFB_OK) {
00140         MMSFB_SetError(dfbres, "IDirectFBWindow::SetOpacity(" + iToStr(this->config.opacity) + ") failed");
00141         return false;
00142     }
00143 
00144     this->config.shown = true;
00145     return true;
00146 }
00147 
00148 bool MMSFBWindow::hide() {
00149     DFBResult   dfbres;
00150 
00151     /* check if initialized */
00152     INITCHECK;
00153 
00154     /* already hidden */
00155     if (!this->config.shown)
00156         return true;
00157 
00158     /* set the opacity */
00159     if ((dfbres=this->dfbwindow->SetOpacity(this->dfbwindow, 0)) != DFB_OK) {
00160         MMSFB_SetError(dfbres, "IDirectFBWindow::SetOpacity(0) failed");
00161         return false;
00162     }
00163 
00164     this->config.shown = false;
00165     return true;
00166 }
00167 
00168 bool MMSFBWindow::getOpacity(unsigned char *opacity) {
00169 
00170     /* check if initialized */
00171     INITCHECK;
00172 
00173     /* return the opacity */
00174     *opacity = this->config.opacity;
00175 
00176     return true;
00177 }
00178 
00179 bool MMSFBWindow::setOpacity(unsigned char opacity) {
00180     DFBResult   dfbres;
00181 
00182     /* check if initialized */
00183     INITCHECK;
00184 
00185     if (this->config.shown) {
00186         /* window is shown, set the opacity */
00187         if ((dfbres=this->dfbwindow->SetOpacity(this->dfbwindow, opacity)) != DFB_OK) {
00188             MMSFB_SetError(dfbres, "IDirectFBWindow::SetOpacity(" + iToStr(opacity) + ") failed");
00189             return false;
00190         }
00191     }
00192 
00193     /* save opacity */
00194     this->config.opacity = opacity;
00195 
00196     return true;
00197 }
00198 
00199 bool MMSFBWindow::getPosition(int *x, int *y) {
00200 
00201     /* check if initialized */
00202     INITCHECK;
00203 
00204     /* return the position */
00205     *x = this->config.posx;
00206     *y = this->config.posy;
00207 
00208     return true;
00209 }
00210 
00211 bool MMSFBWindow::moveTo(int x, int y) {
00212     DFBResult   dfbres;
00213 
00214     /* check if initialized */
00215     INITCHECK;
00216 
00217     /* move window */
00218     if ((dfbres=this->dfbwindow->MoveTo(this->dfbwindow, x, y)) != DFB_OK) {
00219         MMSFB_SetError(dfbres, "IDirectFBWindow::MoveTo(" + iToStr(x) + "," + iToStr(y) + ") failed");
00220         return false;
00221     }
00222 
00223     /* save the position */
00224     this->config.posx = x;
00225     this->config.posy = y;
00226 
00227     return true;
00228 }
00229 
00230 bool MMSFBWindow::getSize(int *w, int *h) {
00231 
00232     /* check if initialized */
00233     INITCHECK;
00234 
00235     /* return the size */
00236     *w = this->config.surface_config.w;
00237     *h = this->config.surface_config.h;
00238 
00239     return true;
00240 }
00241 
00242 bool MMSFBWindow::resize(int w, int h) {
00243     DFBResult   dfbres;
00244 
00245     /* check if initialized */
00246     INITCHECK;
00247 
00248     /* resize window */
00249     if ((dfbres=this->dfbwindow->Resize(this->dfbwindow, w, h)) != DFB_OK) {
00250         MMSFB_SetError(dfbres, "IDirectFBWindow::Resize(" + iToStr(w) + "x" + iToStr(h) + ") failed");
00251         return false;
00252     }
00253 
00254     /* get surface config */
00255     if (!this->surface->getConfiguration(&this->config.surface_config))
00256         return false;
00257 
00258     return true;
00259 }
00260 
00261 bool MMSFBWindow::raiseToTop(int zlevel) {
00262     DFBResult   dfbres;
00263 
00264 //TODO: zlevel does not work for DFB
00265 
00266     /* check if initialized */
00267     INITCHECK;
00268 
00269     /* raise */
00270     if ((dfbres=this->dfbwindow->RaiseToTop(this->dfbwindow)) != DFB_OK) {
00271         MMSFB_SetError(dfbres, "IDirectFBWindow::RaiseToTop() failed");
00272         return false;
00273     }
00274     return true;
00275 }
00276 
00277 bool MMSFBWindow::lowerToBottom() {
00278     DFBResult   dfbres;
00279 
00280     /* check if initialized */
00281     INITCHECK;
00282 
00283     /* lower */
00284     if ((dfbres=this->dfbwindow->LowerToBottom(this->dfbwindow)) != DFB_OK) {
00285         MMSFB_SetError(dfbres, "IDirectFBWindow::LowerToBottom() failed");
00286         return false;
00287     }
00288     return true;
00289 }
00290 
00291 #endif
00292 
00293 
00294 /*****************************************************************************/
00295 /* Use MMSFB Window Manager                                                  */
00296 /*****************************************************************************/
00297 #ifdef USE_MMSFB_WINMAN
00298 
00299 #define INITCHECK  if(!this->surface){MMSFB_SetError(0,"not initialized");return false;}
00300 
00301 MMSFBWindow::MMSFBWindow(MMSFBSurface *surface, int x, int y) {
00302     /* init me */
00303 #ifdef  __HAVE_DIRECTFB__
00304     this->dfbwindow = NULL;
00305 #endif
00306     this->surface = surface;
00307 
00308     /* get the current config */
00309     if (this->surface) {
00310         getConfiguration();
00311         this->config.posx = x;
00312         this->config.posy = y;
00313         this->config.opacity = 255;
00314         this->config.shown = false;
00315     }
00316 }
00317 
00318 MMSFBWindow::~MMSFBWindow() {
00319     if (this->surface)
00320         delete this->surface;
00321 }
00322 
00323 bool MMSFBWindow::getSurface(MMSFBSurface **surface) {
00324 
00325     /* check if initialized */
00326     INITCHECK;
00327 
00328     /* return the surface */
00329     *surface = this->surface;
00330 
00331     return true;
00332 }
00333 
00334 bool MMSFBWindow::getConfiguration(MMSFBWindowConfig *config) {
00335 
00336     /* check if initialized */
00337     INITCHECK;
00338 
00339     /* get surface config */
00340     if (!this->surface->getConfiguration(&(this->config.surface_config)))
00341         return false;
00342 
00343     /* fill return config */
00344     if (config)
00345         *config = this->config;
00346 
00347     return true;
00348 }
00349 
00350 bool MMSFBWindow::isShown() {
00351 
00352     /* check if initialized */
00353     INITCHECK;
00354 
00355     /* return the shown flag */
00356     return this->config.shown;
00357 }
00358 
00359 bool MMSFBWindow::show() {
00360 
00361     /* check if initialized */
00362     INITCHECK;
00363 
00364     /* already shown */
00365     if (this->config.shown)
00366         return true;
00367 
00368     /* set the shown flag */
00369     this->config.shown = true;
00370 
00371     /* inform the window manager */
00372     mmsfbwindowmanager->showWindow(this);
00373 
00374     return true;
00375 }
00376 
00377 bool MMSFBWindow::hide() {
00378 
00379     /* check if initialized */
00380     INITCHECK;
00381 
00382     /* already hidden */
00383     if (!this->config.shown)
00384         return true;
00385 
00386     /* clear the shown flag */
00387     this->config.shown = false;
00388 
00389     /* inform the window manager */
00390     mmsfbwindowmanager->hideWindow(this);
00391 
00392     return true;
00393 }
00394 
00395 bool MMSFBWindow::getOpacity(unsigned char *opacity) {
00396 
00397     /* check if initialized */
00398     INITCHECK;
00399 
00400     /* return the opacity */
00401     *opacity = this->config.opacity;
00402 
00403     return true;
00404 }
00405 
00406 bool MMSFBWindow::setOpacity(unsigned char opacity) {
00407 
00408     /* check if initialized */
00409     INITCHECK;
00410 
00411     /* save opacity */
00412     this->config.opacity = opacity;
00413 
00414     /* inform the window manager */
00415     mmsfbwindowmanager->setWindowOpacity(this);
00416 
00417     return true;
00418 }
00419 
00420 bool MMSFBWindow::getPosition(int *x, int *y) {
00421 
00422     /* check if initialized */
00423     INITCHECK;
00424 
00425     /* return the position */
00426     *x = this->config.posx;
00427     *y = this->config.posy;
00428 
00429     return true;
00430 }
00431 
00432 bool MMSFBWindow::moveTo(int x, int y, bool move_vrect) {
00433 
00434     // check if initialized
00435     INITCHECK;
00436 
00437     // get visible rectangle
00438     MMSFBRectangle vrect;
00439     if (move_vrect) {
00440         if (getVisibleRectangle(&vrect)) {
00441             vrect.x+= this->config.posx - x;
00442             vrect.y+= this->config.posy - y;
00443         }
00444         else
00445             move_vrect = false;
00446     }
00447 
00448     // save the position
00449     this->config.posx = x;
00450     this->config.posy = y;
00451 
00452     // inform the window manager
00453     if (move_vrect)
00454         mmsfbwindowmanager->setWindowPosition(this, &vrect);
00455     else
00456         mmsfbwindowmanager->setWindowPosition(this);
00457 
00458     return true;
00459 }
00460 
00461 bool MMSFBWindow::getSize(int *w, int *h) {
00462 
00463     /* check if initialized */
00464     INITCHECK;
00465 
00466     /* return the size */
00467     *w = this->config.surface_config.w;
00468     *h = this->config.surface_config.h;
00469 
00470     return true;
00471 }
00472 
00473 bool MMSFBWindow::resize(int w, int h) {
00474 
00475     /* check if initialized */
00476     INITCHECK;
00477 
00478     /* inform the window manager */
00479     mmsfbwindowmanager->setWindowSize(this, w, h);
00480 
00481     return true;
00482 }
00483 
00484 bool MMSFBWindow::raiseToTop(int zlevel) {
00485 
00486     // check if initialized
00487     INITCHECK;
00488 
00489     // save opacity
00490     this->config.zlevel = zlevel;
00491 
00492     // raise to top of the window stack
00493     mmsfbwindowmanager->raiseToTop(this);
00494 
00495     return true;
00496 }
00497 
00498 bool MMSFBWindow::lowerToBottom() {
00499 
00500     /* check if initialized */
00501     INITCHECK;
00502 
00503     // save opacity
00504     this->config.zlevel = 1000;
00505 
00506     /* lower to bottom of the window stack */
00507     mmsfbwindowmanager->lowerToBottom(this);
00508 
00509     return true;
00510 }
00511 
00512 bool MMSFBWindow::setVisibleRectangle(MMSFBRectangle *rect) {
00513 
00514     // check if initialized
00515     INITCHECK;
00516 
00517     // inform the window manager
00518     return mmsfbwindowmanager->setWindowVisibleRectangle(this, rect);
00519 }
00520 
00521 bool MMSFBWindow::getVisibleRectangle(MMSFBRectangle *rect) {
00522 
00523     // check if initialized
00524     INITCHECK;
00525 
00526     // get it from the window manager
00527     return mmsfbwindowmanager->getWindowVisibleRectangle(this, rect);
00528 }
00529 
00530 bool MMSFBWindow::getScreenshot() {
00531 
00532     // check if initialized
00533     INITCHECK;
00534 
00535     // get it from the window manager
00536     return mmsfbwindowmanager->getScreenshot(this);
00537 }
00538 
00539 #endif
00540 

Generated by doxygen