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

mmsdialogmanager.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/mmsdialogmanager.h"
00034 #include "mmsgui/mmswindows.h"
00035 #include "mmsgui/mmswidgets.h"
00036 #include "mmsgui/mmscanvasfactory.h"
00037 #include "mmsgui/theme/mmsthememanager.h"
00038 #include <string.h>
00039 #include <algorithm>
00040 
00041 // read widget attributes from TAFF which are not defined in theme classes
00042 #define READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height) \
00043     case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_name: \
00044         name = attrval_str; \
00045         break; \
00046     case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_size: \
00047         size = attrval_str; \
00048         break; \
00049     case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_min_width: \
00050         min_width = attrval_str; \
00051         break; \
00052     case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_min_height: \
00053         min_height = attrval_str; \
00054         break; \
00055     case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_max_width: \
00056         max_width = attrval_str; \
00057         break; \
00058     case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_max_height: \
00059         max_height = attrval_str; \
00060         break;
00061 
00062 
00063 // set widget attributes which are not defined in theme classes
00064 #define SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(widget, name, size, min_width, min_height, max_width, max_height) \
00065     if (!name.empty()) { \
00066         widget->setName(name); \
00067         insertNamedWidget(widget); \
00068     } \
00069     if (!size.empty()) { \
00070         if (!widget->setSizeHint(size)) \
00071             throw MMSDialogManagerError(1, "invalid widget size '" + size + "'"); \
00072     } \
00073     if (!min_width.empty()) { \
00074         if (!widget->setMinWidth(min_width)) \
00075             throw MMSDialogManagerError(1, "invalid widget min_width '" + min_width + "'"); \
00076     } \
00077     if (!min_height.empty()) { \
00078         if (!widget->setMinHeight(min_height)) \
00079             throw MMSDialogManagerError(1, "invalid widget min_height '" + min_height + "'"); \
00080     } \
00081     if (!max_width.empty()) { \
00082         if (!widget->setMaxWidth(max_width)) \
00083             throw MMSDialogManagerError(1, "invalid widget max_width '" + max_width + "'"); \
00084     } \
00085     if (!max_height.empty()) { \
00086         if (!widget->setMaxHeight(max_height)) \
00087             throw MMSDialogManagerError(1, "invalid widget max_height '" + max_height + "'"); \
00088     }
00089 
00090 
00091 MMSDialogManager::MMSDialogManager(bool leave_window) :
00092     leave_window(leave_window),
00093     rootWindow(NULL),
00094     rootWindow_is_mine(true) {
00095 }
00096 
00097 MMSDialogManager::MMSDialogManager(MMSWindow *rootWindow) :
00098     leave_window(false),
00099     rootWindow(rootWindow),
00100     rootWindow_is_mine(!rootWindow) {
00101 }
00102 
00103 MMSDialogManager::~MMSDialogManager() {
00104     if (!this->leave_window) {
00105         // have to delete my objects
00106         if (this->rootWindow_is_mine) {
00107             // delete the rootWindow if it was initialized by me
00108             if (this->rootWindow)
00109                 delete this->rootWindow;
00110         }
00111         else {
00112             // i should not delete the rootWindow because it was not initialized by me
00113             // so delete only the loaded child windows
00114             for(vector<MMSChildWindow*>::iterator i = this->childWins.begin(); i != this->childWins.end(); ++i) {
00115                 delete *i;
00116             }
00117             this->childWins.clear();
00118         }
00119     }
00120 }
00121 
00122 bool MMSDialogManager::isLoaded() {
00123     return (this->rootWindow != NULL);
00124 }
00125 
00126 void MMSDialogManager::insertNamedWidget(MMSWidget *widget) {
00127     this->namedWidgets.push_back(widget);
00128 }
00129 
00130 
00131 MMSWidget* MMSDialogManager::findWidget(string name) {
00132     if (this->rootWindow)
00133         return this->rootWindow->findWidget(name);
00134     else
00135         return NULL;
00136 }
00137 
00138 MMSWidget* MMSDialogManager::operator[](string name) {
00139     MMSWidget *widget;
00140 
00141     if ((widget = findWidget(name)))
00142         return widget;
00143     throw MMSDialogManagerError(1, "widget " + name + " not found");
00144 }
00145 
00146 
00147 
00148 MMSWindow* MMSDialogManager::loadDialog(string filename, MMSTheme *theme) {
00149 
00150     if (this->leave_window) {
00151         // reset all values if a window is already loaded
00152         if (this->rootWindow) {
00153             childWins.clear();
00154             namedWidgets.clear();
00155             description.unsetAll();
00156             this->filename = "";
00157             if (this->rootWindow_is_mine)
00158                 this->rootWindow = NULL;
00159         }
00160     }
00161 
00162     // get taff file name
00163     string tafffilename = filename + ".taff";
00164 
00165     //check for file
00166     if(!file_exist(filename))
00167         if(!file_exist(tafffilename))
00168             throw MMSDialogManagerError(1, "dialog file (" + filename + ") not found");
00169 
00170     // open the taff file
00171     MMSTaffFile *tafff = new MMSTaffFile(tafffilename, &mmsgui_taff_description,
00172                                          filename, MMSTAFF_EXTERNAL_TYPE_XML);
00173 
00174     if (!tafff)
00175         throw MMSDialogManagerError(1, "could not load dialog file " + filename);
00176 
00177     if (!tafff->isLoaded()) {
00178         delete tafff;
00179         throw MMSDialogManagerError(1, "could not load dialog file " + filename);
00180     }
00181 
00182     // get root tag
00183     int tagid = tafff->getFirstTag();
00184     if (tagid < 0) {
00185         delete tafff;
00186         throw MMSDialogManagerError(1, "invalid taff file " + tafffilename);
00187     }
00188 
00189     // check if the correct tag
00190     if (tagid != MMSGUI_TAGTABLE_TAG_MMSDIALOG) {
00191         DEBUGMSG("MMSGUI", "no valid dialog file: %s", filename.c_str());
00192         return NULL;
00193     }
00194 
00195     // save the filename
00196     this->filename = filename;
00197 
00198     // through the doc
00199     this->throughDoc(tafff, NULL, this->rootWindow, theme);
00200 
00201     // free the document
00202     delete tafff;
00203 
00204     return rootWindow;
00205 }
00206 
00207 MMSChildWindow* MMSDialogManager::loadChildDialog(string filename, MMSTheme *theme) {
00208 
00209     unsigned int cw_size = childWins.size();
00210 
00211     // get taff file name
00212     string tafffilename = filename + ".taff";
00213 
00214     //check for file
00215     if(!file_exist(filename))
00216         if(!file_exist(tafffilename))
00217             throw MMSDialogManagerError(1, "dialog file (" + filename + ") not found");
00218 
00219     // open the taff file
00220     MMSTaffFile *tafff = new MMSTaffFile(tafffilename, &mmsgui_taff_description,
00221                                          filename, MMSTAFF_EXTERNAL_TYPE_XML);
00222 
00223     if (!tafff)
00224         throw MMSDialogManagerError(1, "could not load dialog file " + filename);
00225 
00226     if (!tafff->isLoaded()) {
00227         delete tafff;
00228         throw MMSDialogManagerError(1, "could not load dialog file " + filename);
00229     }
00230 
00231     // get root tag
00232     int tagid = tafff->getFirstTag();
00233     if (tagid < 0) {
00234         delete tafff;
00235         throw MMSDialogManagerError(1, "invalid taff file " + tafffilename);
00236     }
00237 
00238     // check if the correct tag
00239     if (tagid != MMSGUI_TAGTABLE_TAG_MMSDIALOG) {
00240         DEBUGMSG("MMSGUI", "no valid dialog file: %s", filename.c_str());
00241         return NULL;
00242     }
00243 
00244     // through the doc
00245 //printf("loadChildDialog(), root=%x, file=%s\n", this->rootWindow, filename.c_str());
00246     this->throughDoc(tafff, NULL, this->rootWindow, theme);
00247 
00248     // free the document
00249     delete tafff;
00250 
00251     if (cw_size < childWins.size())
00252         return childWins.at(cw_size);
00253     else
00254         return NULL;
00255 }
00256 
00257 MMSDescriptionClass MMSDialogManager::getDescription() {
00258     return this->description;
00259 }
00260 
00261 
00262 void MMSDialogManager::throughDoc(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow,
00263                                   MMSTheme *theme, bool only_first_child) {
00264     vector<string> widgetNames;
00265     string widgetName;
00266     bool loop = true;
00267 
00268     // iterate through childs
00269     while (loop) {
00270         if (only_first_child) loop = false;
00271 
00272         bool eof;
00273         int tid = tafff->getNextTag(eof);
00274         if (eof) break;
00275         if (tid < 0) break;
00276 
00277         switch (tid) {
00278         case MMSGUI_TAGTABLE_TAG_DESCRIPTION:
00279             getDescriptionValues(tafff, theme);
00280             // get close tag of description
00281             tafff->getNextTag(eof);
00282             break;
00283         case MMSGUI_TAGTABLE_TAG_MAINWINDOW:
00284             getMainWindowValues(tafff, theme);
00285             break;
00286         case MMSGUI_TAGTABLE_TAG_POPUPWINDOW:
00287             getPopupWindowValues(tafff, theme);
00288             break;
00289         case MMSGUI_TAGTABLE_TAG_ROOTWINDOW:
00290             getRootWindowValues(tafff, theme);
00291             break;
00292         case MMSGUI_TAGTABLE_TAG_CHILDWINDOW:
00293             getChildWindowValues(tafff, rootWindow, theme);
00294             break;
00295         default: {
00296                 widgetName="";
00297                 switch (tid) {
00298                 case MMSGUI_TAGTABLE_TAG_TEMPLATE:
00299                     widgetName = getTemplateValues(tafff, currentWidget, rootWindow, theme);
00300                     break;
00301                 case MMSGUI_TAGTABLE_TAG_VBOXWIDGET:
00302                     widgetName = getVBoxValues(tafff, currentWidget, rootWindow, theme);
00303                     break;
00304                 case MMSGUI_TAGTABLE_TAG_HBOXWIDGET:
00305                     widgetName = getHBoxValues(tafff, currentWidget, rootWindow, theme);
00306                     break;
00307                 case MMSGUI_TAGTABLE_TAG_LABELWIDGET:
00308                     widgetName = getLabelValues(tafff, currentWidget, rootWindow, theme);
00309                     break;
00310                 case MMSGUI_TAGTABLE_TAG_BUTTONWIDGET:
00311                     widgetName = getButtonValues(tafff, currentWidget, rootWindow, theme);
00312                     break;
00313                 case MMSGUI_TAGTABLE_TAG_IMAGEWIDGET:
00314                     widgetName = getImageValues(tafff, currentWidget, rootWindow, theme);
00315                     break;
00316                 case MMSGUI_TAGTABLE_TAG_PROGRESSBARWIDGET:
00317                     widgetName = getProgressBarValues(tafff, currentWidget, rootWindow, theme);
00318                     break;
00319                 case MMSGUI_TAGTABLE_TAG_MENUWIDGET:
00320                     widgetName = getMenuValues(tafff, currentWidget, rootWindow, theme);
00321                     break;
00322                 case MMSGUI_TAGTABLE_TAG_TEXTBOXWIDGET:
00323                     widgetName = getTextBoxValues(tafff, currentWidget, rootWindow, theme);
00324                     break;
00325                 case MMSGUI_TAGTABLE_TAG_ARROWWIDGET:
00326                     widgetName = getArrowValues(tafff, currentWidget, rootWindow, theme);
00327                     break;
00328                 case MMSGUI_TAGTABLE_TAG_SLIDERWIDGET:
00329                     widgetName = getSliderValues(tafff, currentWidget, rootWindow, theme);
00330                     break;
00331                 case MMSGUI_TAGTABLE_TAG_INPUTWIDGET:
00332                     widgetName = getInputValues(tafff, currentWidget, rootWindow, theme);
00333                     break;
00334                 case MMSGUI_TAGTABLE_TAG_CHECKBOXWIDGET:
00335                     widgetName = getCheckBoxValues(tafff, currentWidget, rootWindow, theme);
00336                     break;
00337                 case MMSGUI_TAGTABLE_TAG_GAPWIDGET:
00338                     widgetName = getGapValues(tafff, currentWidget, rootWindow, theme);
00339                     break;
00340                 case MMSGUI_TAGTABLE_TAG_CANVASWIDGET:
00341                     widgetName = getCanvasValues(tafff, currentWidget, rootWindow, theme);
00342                     break;
00343                 }
00344 
00345                 if(!widgetName.empty()) {
00346                     // search for duplicate names for the same parent
00347                     if(find(widgetNames.begin(), widgetNames.end(), widgetName) != widgetNames.end()) {
00348                         throw MMSDialogManagerError(1, "duplicate widget name: " + widgetName);
00349                     }
00350                     widgetNames.push_back(widgetName);
00351                 }
00352 
00353             }
00354             break;
00355         }
00356     }
00357 }
00358 
00359 void MMSDialogManager::getDescriptionValues(MMSTaffFile *tafff, MMSTheme *theme) {
00360 
00361     this->description.setAttributesFromTAFF(tafff);
00362 }
00363 
00364 void MMSDialogManager::getMainWindowValues(MMSTaffFile *tafff, MMSTheme *theme) {
00365     MMSMainWindowClass themeClass;
00366     string             name = "", dx = "", dy = "", width = "", height = "";
00367 
00368     if(this->rootWindow)
00369         throw MMSDialogManagerError(1, "found nested windows, new mainwindow rejected");
00370 
00371     // get themepath
00372     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
00373 
00374     themeClass.windowClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
00375     themeClass.windowClass.setAttributesFromTAFF(tafff, &themePath);
00376     themeClass.setAttributesFromTAFF(tafff, &themePath);
00377 
00378     if (themeClass.windowClass.getDx(dx))
00379         if (getPixelFromSizeHint(NULL, dx, 10000, 0) == false)
00380             throw MMSDialogManagerError(1, "invalid window dx '" + dx + "'");
00381 
00382     if (themeClass.windowClass.getDy(dy))
00383         if (getPixelFromSizeHint(NULL, dy, 10000, 0) == false)
00384             throw MMSDialogManagerError(1, "invalid window dy '" + dy + "'");
00385 
00386     if (themeClass.windowClass.getWidth(width))
00387         if (getPixelFromSizeHint(NULL, width, 10000, 0) == false)
00388             throw MMSDialogManagerError(1, "invalid window width '" + width + "'");
00389 
00390     if (themeClass.windowClass.getHeight(height))
00391         if (getPixelFromSizeHint(NULL, height, 10000, 0) == false)
00392             throw MMSDialogManagerError(1, "invalid window height '" + height + "'");
00393 
00394     bool os;
00395     bool *osp = NULL;
00396     if (themeClass.windowClass.getOwnSurface(os))
00397         osp = &os;
00398     bool bb;
00399     bool *bbp = NULL;
00400     if (themeClass.windowClass.getBackBuffer(bb))
00401         bbp = &bb;
00402 
00403     startTAFFScan
00404     {
00405         switch (attrid) {
00406         case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_name:
00407             name = attrval_str;
00408             break;
00409         }
00410     }
00411     endTAFFScan
00412 
00413     MMSALIGNMENT alignment;
00414     if (!themeClass.windowClass.getAlignment(alignment))
00415         alignment = MMSALIGNMENT_NOTSET;
00416 
00417     if ((themeClass.windowClass.isDx())||(themeClass.windowClass.isDy()))
00418         this->rootWindow = new MMSMainWindow(themeClass.getClassName(),
00419                                              dx,
00420                                              dy,
00421                                              width,
00422                                              height,
00423                                              alignment,
00424                                              MMSW_NONE,
00425                                              theme,
00426                                              osp,
00427                                              bbp);
00428     else
00429         this->rootWindow = new MMSMainWindow(themeClass.getClassName(),
00430                                              width,
00431                                              height,
00432                                              alignment,
00433                                              MMSW_NONE,
00434                                              theme,
00435                                              osp,
00436                                              bbp);
00437 
00438     this->rootWindow->setName(name);
00439     ((MMSMainWindow*)this->rootWindow)->updateFromThemeClass(&themeClass);
00440 
00441     throughDoc(tafff, NULL, this->rootWindow, theme);
00442 }
00443 
00444 
00445 void MMSDialogManager::getPopupWindowValues(MMSTaffFile *tafff, MMSTheme *theme) {
00446     MMSPopupWindowClass themeClass;
00447     string              name = "", dx = "", dy = "", width = "", height = "";
00448 
00449     if(this->rootWindow)
00450         throw MMSDialogManagerError(1, "found nested windows, new popupwindow rejected");
00451 
00452     // get themepath
00453     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
00454 
00455     themeClass.windowClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
00456     themeClass.windowClass.setAttributesFromTAFF(tafff, &themePath);
00457     themeClass.setAttributesFromTAFF(tafff, &themePath);
00458 
00459     if (themeClass.windowClass.getDx(dx))
00460         if (getPixelFromSizeHint(NULL, dx, 10000, 0) == false)
00461             throw MMSDialogManagerError(1, "invalid window dx '" + dx + "'");
00462 
00463     if (themeClass.windowClass.getDy(dy))
00464         if (getPixelFromSizeHint(NULL, dy, 10000, 0) == false)
00465             throw MMSDialogManagerError(1, "invalid window dy '" + dy + "'");
00466 
00467     if (themeClass.windowClass.getWidth(width))
00468         if (getPixelFromSizeHint(NULL, width, 10000, 0) == false)
00469             throw MMSDialogManagerError(1, "invalid window width '" + width + "'");
00470 
00471     if (themeClass.windowClass.getHeight(height))
00472         if (getPixelFromSizeHint(NULL, height, 10000, 0) == false)
00473             throw MMSDialogManagerError(1, "invalid window height '" + height + "'");
00474 
00475     bool os;
00476     bool *osp = NULL;
00477     if (themeClass.windowClass.getOwnSurface(os))
00478         osp = &os;
00479     bool bb;
00480     bool *bbp = NULL;
00481     if (themeClass.windowClass.getBackBuffer(bb))
00482         bbp = &bb;
00483 
00484     startTAFFScan
00485     {
00486         switch (attrid) {
00487         case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_name:
00488             name = attrval_str;
00489             break;
00490         }
00491     }
00492     endTAFFScan
00493 
00494     MMSALIGNMENT alignment;
00495     if (!themeClass.windowClass.getAlignment(alignment))
00496         alignment = MMSALIGNMENT_NOTSET;
00497 
00498     if ((themeClass.windowClass.isDx())||(themeClass.windowClass.isDy()))
00499         this->rootWindow = new MMSPopupWindow(themeClass.getClassName(),
00500                                               dx,
00501                                               dy,
00502                                               width,
00503                                               height,
00504                                               alignment,
00505                                               MMSW_NONE,
00506                                               theme,
00507                                               osp,
00508                                               bbp,
00509                                               0);
00510     else
00511         this->rootWindow = new MMSPopupWindow(themeClass.getClassName(),
00512                                               width,
00513                                               height,
00514                                               alignment,
00515                                               MMSW_NONE,
00516                                               theme,
00517                                               osp,
00518                                               bbp,
00519                                               0);
00520 
00521     this->rootWindow->setName(name);
00522     ((MMSPopupWindow*)this->rootWindow)->updateFromThemeClass(&themeClass);
00523 
00524     throughDoc(tafff, NULL, this->rootWindow, theme);
00525 }
00526 
00527 void MMSDialogManager::getRootWindowValues(MMSTaffFile *tafff, MMSTheme *theme) {
00528     MMSRootWindowClass themeClass;
00529     string             name = "", dx = "", dy = "", width = "", height = "";
00530 
00531     if(this->rootWindow)
00532         throw MMSDialogManagerError(1, "found nested windows, new rootwindow rejected");
00533 
00534     // get themepath
00535     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
00536 
00537     themeClass.windowClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
00538     themeClass.windowClass.setAttributesFromTAFF(tafff, &themePath);
00539     themeClass.setAttributesFromTAFF(tafff, &themePath);
00540 
00541     if (themeClass.windowClass.getDx(dx))
00542         if (getPixelFromSizeHint(NULL, dx, 10000, 0) == false)
00543             throw MMSDialogManagerError(1, "invalid window dx '" + dx + "'");
00544 
00545     if (themeClass.windowClass.getDy(dy))
00546         if (getPixelFromSizeHint(NULL, dy, 10000, 0) == false)
00547             throw MMSDialogManagerError(1, "invalid window dy '" + dy + "'");
00548 
00549     if (themeClass.windowClass.getWidth(width))
00550         if (getPixelFromSizeHint(NULL, width, 10000, 0) == false)
00551             throw MMSDialogManagerError(1, "invalid window width '" + width + "'");
00552 
00553     if (themeClass.windowClass.getHeight(height))
00554         if (getPixelFromSizeHint(NULL, height, 10000, 0) == false)
00555             throw MMSDialogManagerError(1, "invalid window height '" + height + "'");
00556 
00557     bool os;
00558     bool *osp = NULL;
00559     if (themeClass.windowClass.getOwnSurface(os))
00560         osp = &os;
00561     bool bb;
00562     bool *bbp = NULL;
00563     if (themeClass.windowClass.getBackBuffer(bb))
00564         bbp = &bb;
00565 
00566     startTAFFScan
00567     {
00568         switch (attrid) {
00569         case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_name:
00570             name = attrval_str;
00571             break;
00572         }
00573     }
00574     endTAFFScan
00575 
00576     MMSALIGNMENT alignment;
00577     if (!themeClass.windowClass.getAlignment(alignment))
00578         alignment = MMSALIGNMENT_NOTSET;
00579 
00580     if ((themeClass.windowClass.isDx())||(themeClass.windowClass.isDy()))
00581         this->rootWindow = new MMSRootWindow(themeClass.getClassName(),
00582                                              dx,
00583                                              dy,
00584                                              width,
00585                                              height,
00586                                              alignment,
00587                                              MMSW_NONE,
00588                                              theme,
00589                                              osp,
00590                                              bbp);
00591     else
00592         this->rootWindow = new MMSRootWindow(themeClass.getClassName(),
00593                                              width,
00594                                              height,
00595                                              alignment,
00596                                              MMSW_NONE,
00597                                              theme,
00598                                              osp,
00599                                              bbp);
00600 
00601     this->rootWindow->setName(name);
00602     ((MMSRootWindow*)this->rootWindow)->updateFromThemeClass(&themeClass);
00603 
00604     throughDoc(tafff, NULL, this->rootWindow, theme);
00605 }
00606 
00607 void MMSDialogManager::getChildWindowValues(MMSTaffFile *tafff, MMSWindow *rootWindow, MMSTheme *theme) {
00608     MMSChildWindowClass themeClass;
00609     MMSChildWindow      *childwin;
00610     string              name = "", dx = "", dy = "", width = "", height = "";
00611     bool                show = false;
00612 
00613     if(!rootWindow)
00614         throw MMSDialogManagerError(1, "no parent window found, new childwindow rejected");
00615 
00616     // get themepath
00617     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
00618 
00619     themeClass.windowClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
00620     themeClass.windowClass.setAttributesFromTAFF(tafff, &themePath);
00621     themeClass.setAttributesFromTAFF(tafff, &themePath);
00622 
00623     if (themeClass.windowClass.getDx(dx))
00624         if (getPixelFromSizeHint(NULL, dx, 10000, 0) == false)
00625             throw MMSDialogManagerError(1, "invalid window dx '" + dx + "'");
00626 
00627     if (themeClass.windowClass.getDy(dy))
00628         if (getPixelFromSizeHint(NULL, dy, 10000, 0) == false)
00629             throw MMSDialogManagerError(1, "invalid window dy '" + dy + "'");
00630 
00631     if (themeClass.windowClass.getWidth(width))
00632         if (getPixelFromSizeHint(NULL, width, 10000, 0) == false)
00633             throw MMSDialogManagerError(1, "invalid window width '" + width + "'");
00634 
00635     if (themeClass.windowClass.getHeight(height))
00636         if (getPixelFromSizeHint(NULL, height, 10000, 0) == false)
00637             throw MMSDialogManagerError(1, "invalid window height '" + height + "'");
00638 
00639     bool os;
00640     bool *osp = NULL;
00641     if (themeClass.windowClass.getOwnSurface(os))
00642         osp = &os;
00643     bool bb;
00644     bool *bbp = NULL;
00645     if (themeClass.windowClass.getBackBuffer(bb))
00646         bbp = &bb;
00647 
00648     startTAFFScan
00649     {
00650         switch (attrid) {
00651         case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_name:
00652             name = attrval_str;
00653             break;
00654         case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_show:
00655             show = (attrval_int) ? true : false;
00656             break;
00657         }
00658     }
00659     endTAFFScan
00660 
00661     MMSALIGNMENT alignment;
00662     if (!themeClass.windowClass.getAlignment(alignment))
00663         alignment = MMSALIGNMENT_NOTSET;
00664 
00665     if ((themeClass.windowClass.isDx())||(themeClass.windowClass.isDy()))
00666         childwin = new MMSChildWindow(themeClass.getClassName(),
00667                                       rootWindow,
00668                                       dx,
00669                                       dy,
00670                                       width,
00671                                       height,
00672                                       alignment,
00673                                       MMSW_NONE,
00674                                       theme,
00675                                       osp,
00676                                       bbp);
00677     else
00678         childwin = new MMSChildWindow(themeClass.getClassName(),
00679                                       rootWindow,
00680                                       width,
00681                                       height,
00682                                       alignment,
00683                                       MMSW_NONE,
00684                                       theme,
00685                                       osp,
00686                                       bbp);
00687 
00688     // store only the 'root' child window in my list
00689     if (this->rootWindow == rootWindow)
00690         childWins.push_back(childwin);
00691 
00692     childwin->setName(name);
00693     childwin->updateFromThemeClass(&themeClass);
00694 
00695     throughDoc(tafff, NULL, childwin, theme);
00696 
00697     if (show) childwin->show();
00698 }
00699 
00700 string MMSDialogManager::getTemplateValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
00701     MMSTemplateClass    themeClass, *templateClass = NULL;
00702     string              name, size, min_width, min_height, max_width, max_height;
00703     bool                show = false;
00704     MMSTaffFile         *tf;
00705     vector<string>      widgetNames;
00706 
00707     // read settings from dialog
00708     themeClass.setAttributesFromTAFF(tafff);
00709 
00710     // is a class name given?
00711     if (!themeClass.getClassName().empty()) {
00712         // can load templateClass?
00713         if (theme) {
00714             templateClass = theme->getTemplateClass(themeClass.getClassName());
00715         }
00716         else {
00717             templateClass = globalTheme->getTemplateClass(themeClass.getClassName());
00718         }
00719     }
00720 
00721     if (templateClass) {
00722         // are there any childs stored in the templateClass?
00723         if (!(tf = templateClass->getTAFF()))
00724             templateClass = NULL;
00725     }
00726 
00727     if (!templateClass) {
00728         // parse the children from dialog's template tag
00729         throughDoc(tafff, currentWidget, rootWindow, theme);
00730 
00731         return "";
00732     }
00733 
00734     // search for attributes which are only supported within dialog
00735     startTAFFScan
00736     {
00737         switch (attrid) {
00738         // read widget attributes from TAFF which are not defined in theme classes
00739         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
00740 
00741         case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_show:
00742             show = (attrval_int)?true:false;
00743             break;
00744         }
00745     }
00746     endTAFFScan
00747     startTAFFScan_WITHOUT_ID
00748     {
00749         if (memcmp(attrname, "widget.", 7)==0) {
00750             // search for attributes which are to be set for templates child widgets
00751             string widgetName = &attrname[7];
00752             int pos = (int)widgetName.find(".");
00753             if (pos > 0) {
00754                 widgetName = widgetName.substr(0, pos);
00755 
00756                 // store the requested widget name here
00757                 if(find(widgetNames.begin(), widgetNames.end(), widgetName) == widgetNames.end()) {
00758                     widgetNames.push_back(widgetName);
00759                 }
00760             }
00761         }
00762     }
00763     endTAFFScan_WITHOUT_ID
00764 
00765     // parse the children from templateClass
00766     throughDoc(tf, currentWidget, rootWindow, theme);
00767 
00768     // get the last window of root window
00769     MMSWindow *newWindow = (!currentWidget)?rootWindow->getLastWindow():NULL;
00770 
00771     if (!newWindow) {
00772         // get the last widget of currentWidget
00773         MMSWidget *newWidget = (!currentWidget)?((*rootWindow)[""]):currentWidget->getLastWidget();
00774 
00775         if (newWidget) {
00776             // set widget attributes which are not defined in theme classes
00777             SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(newWidget, name, size, min_width, min_height, max_width, max_height);
00778 
00779             // for each child widget which is named by attribute
00780             vector<string>::iterator i;
00781             vector<string>::iterator end = widgetNames.end();
00782             for (i = widgetNames.begin(); i != end; ++i) {
00783                 updateTAFFAttributes(tafff, newWidget->findWidget(*i), *i);
00784             }
00785         }
00786         else {
00787             throw MMSDialogManagerError(1, "template error, no widget");
00788         }
00789     }
00790     else {
00791         if (!name.empty()) {
00792             // set name of window
00793             newWindow->setName(name);
00794         }
00795 
00796         if (show) {
00797             // show window
00798             newWindow->show();
00799         }
00800 
00801         // for each child widget which is named by attribute
00802         vector<string>::iterator i;
00803         vector<string>::iterator end = widgetNames.end();
00804         for (i = widgetNames.begin(); i != end; ++i) {
00805             updateTAFFAttributes(tafff, newWindow->findWidget(*i), *i);
00806         }
00807     }
00808 
00809     // parse the children from dialog's template tag
00810     throughDoc(tafff, currentWidget, rootWindow, theme);
00811 
00812     // return the name of the widget
00813     return name;
00814 }
00815 
00816 
00817 string MMSDialogManager::getVBoxValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
00818     MMSVBoxWidget *vbox;
00819     string name, size, min_width, min_height, max_width, max_height;
00820 
00821     startTAFFScan
00822     {
00823         switch (attrid) {
00824         // read widget attributes from TAFF which are not defined in theme classes
00825         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
00826         }
00827     }
00828     endTAFFScan
00829 
00830     vbox = new MMSVBoxWidget(rootWindow);
00831 
00832     // set widget attributes which are not defined in theme classes
00833     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(vbox, name, size, min_width, min_height, max_width, max_height);
00834 
00835     if (currentWidget)
00836         currentWidget->add(vbox);
00837     else
00838         rootWindow->add(vbox);
00839 
00840     throughDoc(tafff, vbox, rootWindow, theme);
00841 
00842     // return the name of the widget
00843     return name;
00844 }
00845 
00846 string MMSDialogManager::getHBoxValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
00847     MMSHBoxWidget *hbox;
00848     string name, size, min_width, min_height, max_width, max_height;
00849 
00850     startTAFFScan
00851     {
00852         switch (attrid) {
00853         // read widget attributes from TAFF which are not defined in theme classes
00854         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
00855         }
00856     }
00857     endTAFFScan
00858 
00859     hbox = new MMSHBoxWidget(rootWindow);
00860 
00861     // set widget attributes which are not defined in theme classes
00862     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(hbox, name, size, min_width, min_height, max_width, max_height);
00863 
00864     if (currentWidget)
00865         currentWidget->add(hbox);
00866     else
00867         rootWindow->add(hbox);
00868 
00869     throughDoc(tafff, hbox, rootWindow, theme);
00870 
00871     // return the name of the widget
00872     return name;
00873 }
00874 
00875 
00876 string MMSDialogManager::getLabelValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
00877     MMSLabelWidgetClass   themeClass;
00878     MMSLabelWidget  *label;
00879     string name, size, min_width, min_height, max_width, max_height;
00880 
00881     // get themepath
00882     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
00883 
00884     // read settings from dialog
00885     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
00886     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
00887     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
00888 
00889     // create new label from theme class
00890     label = new MMSLabelWidget(rootWindow, themeClass.getClassName(), theme);
00891 
00892     // apply settings from dialog
00893     label->updateFromThemeClass(&themeClass);
00894 
00895     // search for attributes which are only supported within dialog
00896     startTAFFScan
00897     {
00898         switch (attrid) {
00899         // read widget attributes from TAFF which are not defined in theme classes
00900         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
00901         }
00902     }
00903     endTAFFScan
00904 
00905     // set widget attributes which are not defined in theme classes
00906     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(label, name, size, min_width, min_height, max_width, max_height);
00907 
00908     if (currentWidget)
00909         currentWidget->add(label);
00910     else
00911         rootWindow->add(label);
00912 
00913     throughDoc(tafff, label, rootWindow, theme);
00914 
00915     // return the name of the widget
00916     return name;
00917 }
00918 
00919 
00920 
00921 string MMSDialogManager::getButtonValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
00922     MMSButtonWidgetClass  themeClass;
00923     MMSButtonWidget *button;
00924     string name, size, min_width, min_height, max_width, max_height;
00925 
00926     // get themepath
00927     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
00928 
00929     // read settings from dialog
00930     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
00931     themeClass.widgetClass.setAttributesFromTAFF(tafff,  NULL, &themePath);
00932     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
00933 
00934     // create new button from theme class
00935     button = new MMSButtonWidget(rootWindow, themeClass.getClassName(), theme);
00936 
00937     // apply settings from dialog
00938     button->updateFromThemeClass(&themeClass);
00939 
00940     // search for attributes which are only supported within dialog
00941     startTAFFScan
00942     {
00943         switch (attrid) {
00944         // read widget attributes from TAFF which are not defined in theme classes
00945         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
00946         }
00947     }
00948     endTAFFScan
00949 
00950     // set widget attributes which are not defined in theme classes
00951     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(button, name, size, min_width, min_height, max_width, max_height);
00952 
00953     if (currentWidget)
00954         currentWidget->add(button);
00955     else
00956         rootWindow->add(button);
00957 
00958     throughDoc(tafff, button, rootWindow, theme);
00959 
00960     // return the name of the widget
00961     return name;
00962 }
00963 
00964 string MMSDialogManager::getCanvasValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
00965     MMSCanvasWidgetClass  themeClass;
00966     MMSCanvasWidget *canvas;
00967     string name, size, min_width, min_height, max_width, max_height, factoryname;
00968 
00969     // get themepath
00970     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
00971 
00972     // read settings from dialog
00973     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
00974     themeClass.widgetClass.setAttributesFromTAFF(tafff,  NULL, &themePath);
00975     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
00976 
00977 
00978     themeClass.widgetClass.getFactoryName(factoryname);
00979     // create new canvas from factory with theme class
00980     if(factoryname.empty()) {
00981         throw MMSDialogManagerError(1, "canvas without factoryname is not allowed!");
00982     }
00983 
00984     MMSCanvasFactory factory;
00985     canvas = factory.constructCanvas(factoryname.c_str(), rootWindow, themeClass.getClassName(), theme);
00986 
00987     if(!canvas) {
00988         throw MMSDialogManagerError(1, "canvas with factoryname = '" + factoryname + "' is not registered!");
00989     }
00990 
00991     // apply settings from dialog
00992     canvas->updateFromThemeClass(canvas->canvasWidgetClass);
00993 
00994     // apply settings from dialog
00995     canvas->updateFromThemeClass(&themeClass);
00996 
00997     // search for attributes which are only supported within dialog
00998     startTAFFScan
00999     {
01000         switch (attrid) {
01001         // read widget attributes from TAFF which are not defined in theme classes
01002         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01003         }
01004     }
01005     endTAFFScan
01006 
01007     // set widget attributes which are not defined in theme classes
01008     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(canvas, name, size, min_width, min_height, max_width, max_height);
01009 
01010 
01011     if (currentWidget)
01012         currentWidget->add(canvas);
01013     else
01014         rootWindow->add(canvas);
01015 
01016     throughDoc(tafff, canvas, rootWindow, theme);
01017 
01018     // return the name of the widget
01019     return name;
01020 }
01021 
01022 string MMSDialogManager::getImageValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01023     MMSImageWidgetClass   themeClass;
01024     MMSImageWidget  *image;
01025     string name, size, min_width, min_height, max_width, max_height;
01026 
01027     // get themepath
01028     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
01029 
01030     // read settings from dialog
01031     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
01032     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01033     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01034 
01035     // create new image from theme class
01036     image = new MMSImageWidget(rootWindow, themeClass.getClassName(), theme);
01037 
01038     // apply settings from dialog
01039     image->updateFromThemeClass(&themeClass);
01040 
01041     // search for attributes which are only supported within dialog
01042     startTAFFScan
01043     {
01044         switch (attrid) {
01045         // read widget attributes from TAFF which are not defined in theme classes
01046         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01047         }
01048     }
01049     endTAFFScan
01050 
01051     // set widget attributes which are not defined in theme classes
01052     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(image, name, size, min_width, min_height, max_width, max_height);
01053 
01054     if (currentWidget)
01055         currentWidget->add(image);
01056     else
01057         rootWindow->add(image);
01058 
01059     throughDoc(tafff, image, rootWindow, theme);
01060 
01061     // return the name of the widget
01062     return name;
01063 }
01064 
01065 
01066 string MMSDialogManager::getProgressBarValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01067     MMSProgressBarWidgetClass   themeClass;
01068     MMSProgressBarWidget    *pBar;
01069     string name, size, min_width, min_height, max_width, max_height;
01070 
01071     // get themepath
01072     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
01073 
01074     // read settings from dialog
01075     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
01076     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01077     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01078 
01079     // create new progressbar from theme class
01080     pBar = new MMSProgressBarWidget(rootWindow, themeClass.getClassName(), theme);
01081 
01082     // apply settings from dialog
01083     pBar->updateFromThemeClass(&themeClass);
01084 
01085     // search for attributes which are only supported within dialog
01086     startTAFFScan
01087     {
01088         switch (attrid) {
01089         // read widget attributes from TAFF which are not defined in theme classes
01090         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01091         }
01092     }
01093     endTAFFScan
01094 
01095     // set widget attributes which are not defined in theme classes
01096     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(pBar, name, size, min_width, min_height, max_width, max_height);
01097 
01098     if (currentWidget)
01099         currentWidget->add(pBar);
01100     else
01101         rootWindow->add(pBar);
01102 
01103     throughDoc(tafff, pBar, rootWindow, theme);
01104 
01105     // return the name of the widget
01106     return name;
01107 }
01108 
01109 
01110 bool MMSDialogManager::getMenuItems(MMSTaffFile *tafff, MMSMenuWidget *menu, MMSTheme *theme) {
01111     bool haveItems = false;
01112     bool returntag = true;
01113 
01114     // iterate through children
01115     while (1) {
01116         bool eof;
01117         int tid = tafff->getNextTag(eof);
01118         if (eof) break;
01119         if (tid < 0) {
01120             if (returntag) break;
01121             returntag = true;
01122             continue;
01123         }
01124         else
01125             returntag = false;
01126 
01127         // check if a <menuitem/> is given
01128         if (tid == MMSGUI_TAGTABLE_TAG_MENUITEM) {
01129             // new menu item
01130             MMSWidget *item = NULL;
01131             haveItems = true;
01132 
01133             if (tafff->hasAttributes()) {
01134                 // menu item has attributes, so we assume that the new item should be created with item template style
01135                 // create new menu item
01136                 item = menu->newItem();
01137 
01138                 // here we must loop for n widgets
01139                 vector<string> wgs;
01140                 bool wg_break = false;
01141                 while (!wg_break) {
01142                     wg_break = true;
01143                     startTAFFScan_WITHOUT_ID
01144                     {
01145                         if (memcmp(attrname, "widget.", 7)==0) {
01146                             // search for attributes which are to be set for menu items child widgets
01147                             string widgetName = &attrname[7];
01148                             int pos = (int)widgetName.find(".");
01149                             if (pos > 0) {
01150                                 // widget name found
01151                                 widgetName = widgetName.substr(0, pos);
01152 
01153                                 // check if i have already processed this widget
01154                                 if(find(wgs.begin(), wgs.end(), widgetName) != wgs.end()) {
01155                                     widgetName = "";
01156                                     continue;
01157                                 }
01158                                 wg_break = false;
01159                                 wgs.push_back(widgetName);
01160 
01161                                 // okay, searching for the widget within the new item
01162                                 MMSWidget *widget;
01163                                 if (item->getName() == widgetName) {
01164                                     widget = item;
01165                                 }else {
01166                                     widget = item->findWidget(widgetName);
01167                                 }
01168 
01169                                 updateTAFFAttributes(tafff, widget, widgetName);
01170                             }
01171                         }
01172                     }
01173                     endTAFFScan_WITHOUT_ID
01174                 }
01175 
01176                 startTAFFScan_WITHOUT_ID
01177                 {
01178                     if (memcmp(attrname, "childwindow", 11)==0) {
01179                         // there is a child window given which represents a sub menu
01180                         menu->setSubMenuName(menu->getSize()-1, attrval_str);
01181                     }
01182                     else
01183                     if (memcmp(attrname, "goback", 6)==0) {
01184                         // if true, this item should be the go-back-item
01185                         //! if the user enters this item, the parent menu (if does exist) will be shown
01186                         if (memcmp(attrval_str, "true", 4)==0)
01187                             menu->setBackItem(menu->getSize()-1);
01188                     }
01189                 }
01190                 endTAFFScan_WITHOUT_ID
01191 
01192                 startTAFFScan
01193                 {
01194                     switch (attrid) {
01195                     case MMSGUI_BASE_ATTR::MMSGUI_BASE_ATTR_IDS_name:
01196                         if (*attrval_str)
01197                             item->setName(attrval_str);
01198                         break;
01199                     }
01200                 }
01201                 endTAFFScan
01202             }
01203             else {
01204                 // menu item has NO attributes, so we try to read a specific item style from the <menuitem/> children
01205                 // checking for tags within <menuitem/>
01206                 MMSHBoxWidget *tmpWidget = new MMSHBoxWidget(NULL);
01207 
01208                 // parse the childs from dialog file
01209                 throughDoc(tafff, tmpWidget, NULL, theme);
01210                 returntag = true;
01211 
01212                 // here we create a new menu item based on disconnected child (if != NULL) or item template style
01213                 item = menu->newItem(-1, tmpWidget->disconnectChild());
01214 
01215                 // delete the temporary container
01216                 delete tmpWidget;
01217             }
01218         }
01219         else {
01220             // any other widgets given in the menu
01221             printf("Warning: Tag <%s/> is not supported within <menu/>.\n", tafff->getCurrentTagName());
01222 
01223             // we need a temporary widget
01224             MMSHBoxWidget *tmpWidget = new MMSHBoxWidget(NULL);
01225 
01226             // parse the childs from dialog file
01227             throughDoc(tafff, tmpWidget, NULL, theme);
01228             returntag = true;
01229 
01230             // delete the widget, we cannot use it
01231             delete tmpWidget;
01232         }
01233     }
01234 
01235     return haveItems;
01236 }
01237 
01238 string MMSDialogManager::getMenuValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01239     MMSMenuWidgetClass    themeClass;
01240     MMSMenuWidget   *menu;
01241     string name, size, min_width, min_height, max_width, max_height;
01242     MMSTaffFile     *tf;
01243 
01244     // get themepath
01245     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
01246 
01247     // read settings from dialog
01248     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
01249     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01250     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01251 
01252     // create new menu from theme class
01253     menu = new MMSMenuWidget(rootWindow, themeClass.getClassName(), theme);
01254 
01255     // apply settings from dialog
01256     menu->updateFromThemeClass(&themeClass);
01257 
01258     // search for attributes which are only supported within dialog
01259     startTAFFScan
01260     {
01261         switch (attrid) {
01262         // read widget attributes from TAFF which are not defined in theme classes
01263         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01264         }
01265     }
01266     endTAFFScan
01267 
01268     // set widget attributes which are not defined in theme classes
01269     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(menu, name, size, min_width, min_height, max_width, max_height);
01270 
01271     if (currentWidget)
01272         currentWidget->add(menu);
01273     else
01274         rootWindow->add(menu);
01275 
01276     // set the item layout, we need a temporary parent widget
01277     MMSHBoxWidget *tmpWidget = new MMSHBoxWidget(NULL);
01278 
01279     // are there any childs stored in the theme?
01280     if ((tf = menu->getTAFF())) {
01281         // yes, parse the childs from theme
01282         throughDoc(tf, tmpWidget, NULL, theme, true);
01283     }
01284     else {
01285         // no, parse the childs from dialog file
01286         throughDoc(tafff, tmpWidget, NULL, theme, true);
01287     }
01288 
01289     bool haveItemTemplate = false;
01290     MMSWidget *itemTemplate = tmpWidget->disconnectChild();
01291     if (itemTemplate) {
01292         menu->setItemTemplate(itemTemplate);
01293         haveItemTemplate = true;
01294     }
01295     else {
01296         if (tf) {
01297             // try with theme failed, retry with childs from dialog file
01298             throughDoc(tafff, tmpWidget, NULL, theme, true);
01299             MMSWidget *itemTemplate = tmpWidget->disconnectChild();
01300             if (itemTemplate) {
01301                 menu->setItemTemplate(itemTemplate);
01302                 haveItemTemplate = true;
01303             }
01304         }
01305     }
01306 
01307     delete tmpWidget;
01308 
01309     if (haveItemTemplate) {
01310         // have a template
01311         bool haveItems = false;
01312 
01313         if (tf) {
01314             // searching for menu items which are set in the THEME file
01315             haveItems = getMenuItems(tf, menu, theme);
01316         }
01317 
01318         // searching for menu items which are set in the DIALOG file
01319         if (getMenuItems(tafff, menu, theme)) {
01320             haveItems = true;
01321         }
01322 
01323         if (haveItems) {
01324             menu->setFocus(false, false);
01325         }
01326     }
01327 
01328     // return the name of the widget
01329     return name;
01330 }
01331 
01332 
01333 string MMSDialogManager::getTextBoxValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01334     MMSTextBoxWidgetClass   themeClass;
01335     MMSTextBoxWidget    *textbox;
01336     string name, size, min_width, min_height, max_width, max_height;
01337 
01338     // get themepath
01339     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
01340 
01341     // read settings from dialog
01342     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
01343     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01344     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01345 
01346     // create new textbox from theme class
01347     textbox = new MMSTextBoxWidget(rootWindow, themeClass.getClassName(), theme);
01348 
01349     // apply settings from dialog
01350     textbox->updateFromThemeClass(&themeClass);
01351 
01352     // search for attributes which are only supported within dialog
01353     startTAFFScan
01354     {
01355         switch (attrid) {
01356         // read widget attributes from TAFF which are not defined in theme classes
01357         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01358         }
01359     }
01360     endTAFFScan
01361 
01362     // set widget attributes which are not defined in theme classes
01363     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(textbox, name, size, min_width, min_height, max_width, max_height);
01364 
01365     if (currentWidget)
01366         currentWidget->add(textbox);
01367     else
01368         rootWindow->add(textbox);
01369 
01370     throughDoc(tafff, textbox, rootWindow, theme);
01371 
01372     // return the name of the widget
01373     return name;
01374 }
01375 
01376 string MMSDialogManager::getArrowValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01377     MMSArrowWidgetClass   themeClass;
01378     MMSArrowWidget  *arrow;
01379     string name, size, min_width, min_height, max_width, max_height;
01380 
01381     // get themepath
01382     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
01383 
01384     // read settings from dialog
01385     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
01386     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01387     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01388 
01389     // create new arrow from theme class
01390     arrow = new MMSArrowWidget(rootWindow, themeClass.getClassName(), theme);
01391 
01392     // apply settings from dialog
01393     arrow->updateFromThemeClass(&themeClass);
01394 
01395     // search for attributes which are only supported within dialog
01396     startTAFFScan
01397     {
01398         switch (attrid) {
01399         // read widget attributes from TAFF which are not defined in theme classes
01400         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01401         }
01402     }
01403     endTAFFScan
01404 
01405     // set widget attributes which are not defined in theme classes
01406     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(arrow, name, size, min_width, min_height, max_width, max_height);
01407 
01408     if (currentWidget)
01409         currentWidget->add(arrow);
01410     else
01411         rootWindow->add(arrow);
01412 
01413     throughDoc(tafff, arrow, rootWindow, theme);
01414 
01415     // return the name of the widget
01416     return name;
01417 }
01418 
01419 string MMSDialogManager::getSliderValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01420     MMSSliderWidgetClass  themeClass;
01421     MMSSliderWidget *slider;
01422     string name, size, min_width, min_height, max_width, max_height;
01423 
01424     // get themepath
01425     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
01426 
01427     // read settings from dialog
01428     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
01429     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01430     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01431 
01432     // create new slider from theme class
01433     slider = new MMSSliderWidget(rootWindow, themeClass.getClassName(), theme);
01434 
01435     // apply settings from dialog
01436     slider->updateFromThemeClass(&themeClass);
01437 
01438     // search for attributes which are only supported within dialog
01439     startTAFFScan
01440     {
01441         switch (attrid) {
01442         // read widget attributes from TAFF which are not defined in theme classes
01443         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01444         }
01445     }
01446     endTAFFScan
01447 
01448     // set widget attributes which are not defined in theme classes
01449     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(slider, name, size, min_width, min_height, max_width, max_height);
01450 
01451     if (currentWidget)
01452         currentWidget->add(slider);
01453     else
01454         rootWindow->add(slider);
01455 
01456     throughDoc(tafff, slider, rootWindow, theme);
01457 
01458     // return the name of the widget
01459     return name;
01460 }
01461 
01462 string MMSDialogManager::getInputValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01463     MMSInputWidgetClass   themeClass;
01464     MMSInputWidget  *input;
01465     string name, size, min_width, min_height, max_width, max_height;
01466 
01467     // get themepath
01468     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
01469 
01470     // read settings from dialog
01471     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
01472     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01473     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01474 
01475     // create new label from theme class
01476     input = new MMSInputWidget(rootWindow, themeClass.getClassName(), theme);
01477 
01478     // apply settings from dialog
01479     input->updateFromThemeClass(&themeClass);
01480 
01481     // search for attributes which are only supported within dialog
01482     startTAFFScan
01483     {
01484         switch (attrid) {
01485         // read widget attributes from TAFF which are not defined in theme classes
01486         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01487         }
01488     }
01489     endTAFFScan
01490 
01491     // set widget attributes which are not defined in theme classes
01492     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(input, name, size, min_width, min_height, max_width, max_height);
01493 
01494     if (currentWidget)
01495         currentWidget->add(input);
01496     else
01497         rootWindow->add(input);
01498 
01499     throughDoc(tafff, input, rootWindow, theme);
01500 
01501     // return the name of the widget
01502     return name;
01503 }
01504 
01505 
01506 string MMSDialogManager::getCheckBoxValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01507     MMSCheckBoxWidgetClass  themeClass;
01508     MMSCheckBoxWidget       *checkbox;
01509     string name, size, min_width, min_height, max_width, max_height;
01510 
01511     // get themepath
01512     string themePath = (theme ? theme->getThemePath() : globalTheme->getThemePath());
01513 
01514     // read settings from dialog
01515     themeClass.widgetClass.border.setAttributesFromTAFF(tafff, NULL, &themePath);
01516     themeClass.widgetClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01517     themeClass.setAttributesFromTAFF(tafff, NULL, &themePath);
01518 
01519     // create new checkbox from theme class
01520     checkbox = new MMSCheckBoxWidget(rootWindow, themeClass.getClassName(), theme);
01521 
01522     // apply settings from dialog
01523     checkbox->updateFromThemeClass(&themeClass);
01524 
01525     // search for attributes which are only supported within dialog
01526     startTAFFScan
01527     {
01528         switch (attrid) {
01529         // read widget attributes from TAFF which are not defined in theme classes
01530         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01531         }
01532     }
01533     endTAFFScan
01534 
01535     // set widget attributes which are not defined in theme classes
01536     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(checkbox, name, size, min_width, min_height, max_width, max_height);
01537 
01538     if (currentWidget)
01539         currentWidget->add(checkbox);
01540     else
01541         rootWindow->add(checkbox);
01542 
01543     throughDoc(tafff, checkbox, rootWindow, theme);
01544 
01545     // return the name of the widget
01546     return name;
01547 }
01548 
01549 string MMSDialogManager::getGapValues(MMSTaffFile *tafff, MMSWidget *currentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01550     MMSGapWidget *gap;
01551     string name, size, min_width, min_height, max_width, max_height;
01552 
01553     startTAFFScan
01554     {
01555         switch (attrid) {
01556         // read widget attributes from TAFF which are not defined in theme classes
01557         READ_DM_SPECIFIC_WIDGET_ATTRIBUTES(name, size, min_width, min_height, max_width, max_height);
01558         }
01559     }
01560     endTAFFScan
01561 
01562     gap = new MMSGapWidget(rootWindow);
01563 
01564     // set widget attributes which are not defined in theme classes
01565     SET_DM_SPECIFIC_WIDGET_ATTRIBUTES(gap, name, size, min_width, min_height, max_width, max_height);
01566 
01567     if (currentWidget)
01568         currentWidget->add(gap);
01569     else
01570         rootWindow->add(gap);
01571 
01572     throughDoc(tafff, gap, rootWindow, theme);
01573 
01574     // return the name of the widget
01575     return name;
01576 }
01577 
01578 
01579 MMSWindow *MMSDialogManager::getWindow() {
01580     return this->rootWindow;
01581 }
01582 
01583 
01584 void MMSDialogManager::updateTAFFAttributes(MMSTaffFile *tafff, MMSWidget *widget, string &widgetName) {
01585     if(!widget) {
01586         return;
01587     }
01588 
01589     string prefix = "widget." + widgetName + ".";
01590 
01591     switch (widget->getType()) {
01592         case MMSWIDGETTYPE_HBOX:
01593         case MMSWIDGETTYPE_VBOX:
01594             break;
01595         case MMSWIDGETTYPE_BUTTON:
01596             {
01597                 // read attributes from node
01598                 MMSButtonWidgetClass themeCls;
01599                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01600                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01601                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01602                 // apply settings from node
01603                 ((MMSButtonWidget*)widget)->updateFromThemeClass(&themeCls);
01604             }
01605             break;
01606         case MMSWIDGETTYPE_IMAGE:
01607             {
01608                 // read attributes from node
01609                 MMSImageWidgetClass themeCls;
01610                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01611                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01612                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01613                 // apply settings from node
01614                 ((MMSImageWidget*)widget)->updateFromThemeClass(&themeCls);
01615             }
01616             break;
01617         case MMSWIDGETTYPE_LABEL:
01618             {
01619                 // read attributes from node
01620                 MMSLabelWidgetClass themeCls;
01621                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01622                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01623                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01624                 // apply settings from node
01625                 ((MMSLabelWidget*)widget)->updateFromThemeClass(&themeCls);
01626             }
01627             break;
01628         case MMSWIDGETTYPE_MENU:
01629             break;
01630         case MMSWIDGETTYPE_PROGRESSBAR:
01631             {
01632                 // read attributes from node
01633                 MMSProgressBarWidgetClass themeCls;
01634                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01635                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01636                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01637                 // apply settings from node
01638                 ((MMSProgressBarWidget*)widget)->updateFromThemeClass(&themeCls);
01639             }
01640             break;
01641         case MMSWIDGETTYPE_TEXTBOX:
01642             {
01643                 // read attributes from node
01644                 MMSTextBoxWidgetClass themeCls;
01645                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01646                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01647                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01648                 // apply settings from node
01649                 ((MMSTextBoxWidget*)widget)->updateFromThemeClass(&themeCls);
01650             }
01651             break;
01652         case MMSWIDGETTYPE_ARROW:
01653             {
01654                 // read attributes from node
01655                 MMSArrowWidgetClass themeCls;
01656                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01657                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01658                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01659                 // apply settings from node
01660                 ((MMSArrowWidget*)widget)->updateFromThemeClass(&themeCls);
01661             }
01662             break;
01663         case MMSWIDGETTYPE_SLIDER:
01664             {
01665                 // read attributes from node
01666                 MMSSliderWidgetClass themeCls;
01667                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01668                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01669                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01670                 // apply settings from node
01671                 ((MMSSliderWidget*)widget)->updateFromThemeClass(&themeCls);
01672             }
01673             break;
01674         case MMSWIDGETTYPE_INPUT:
01675             break;
01676         case MMSWIDGETTYPE_CHECKBOX:
01677             {
01678                 // read attributes from node
01679                 MMSCheckBoxWidgetClass themeCls;
01680                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01681                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01682                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01683                 // apply settings from node
01684                 ((MMSCheckBoxWidget*)widget)->updateFromThemeClass(&themeCls);
01685             }
01686             break;
01687         case MMSWIDGETTYPE_CANVAS:
01688             {
01689                 // read attributes from node
01690                 MMSCanvasWidgetClass themeCls;
01691                 themeCls.widgetClass.border.setAttributesFromTAFF(tafff, &prefix);
01692                 themeCls.widgetClass.setAttributesFromTAFF(tafff, &prefix);
01693                 themeCls.setAttributesFromTAFF(tafff, &prefix);
01694                 // apply settings from node
01695                 ((MMSCanvasWidget*)widget)->updateFromThemeClass(&themeCls);
01696             }
01697             break;
01698         case MMSWIDGETTYPE_GAP:
01699             break;
01700     }
01701 }
01702 
01703 
01704 MMSWidget *MMSDialogManager::createWidgetFromTemplate(string className, MMSWidget *parentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01705 
01706     // prepare input
01707     if (!parentWidget) return NULL;
01708     if (!rootWindow) rootWindow = this->rootWindow;
01709     if (!theme) theme = globalTheme;
01710 
01711     // find template class
01712     MMSTemplateClass *tc = theme->getTemplateClass(className);
01713     if (!tc) return NULL;
01714 
01715     // get TAFF buffer from template
01716     MMSTaffFile *tf = tc->getTAFF();
01717     if (!tf) return NULL;
01718 
01719     // we need a temporary parent widget
01720     MMSHBoxWidget *tmpWidget = new MMSHBoxWidget(NULL);
01721 
01722     // parse the childs from theme
01723     throughDoc(tf, tmpWidget, NULL, theme, true);
01724 
01725     // get real template tree
01726     MMSWidget *tmp = tmpWidget->disconnectChild();
01727     delete tmpWidget;
01728 
01729     if (!tmp) return NULL;
01730 
01731     // init widget
01732     tmp->setParent(parentWidget);
01733     tmp->setRootWindow(rootWindow);
01734 
01735     // return widget
01736     // note: the widget is NOT added to parent widget!!!
01737     return tmp;
01738 }
01739 
01740 
01741 MMSWidget *MMSDialogManager::addWidgetFromTemplate(string className, MMSWidget *parentWidget, MMSWindow *rootWindow, MMSTheme *theme) {
01742 
01743     MMSWidget *widget = createWidgetFromTemplate(className, parentWidget, rootWindow, theme);
01744 
01745     if (widget) {
01746         parentWidget->add(widget);
01747     }
01748 
01749     return widget;
01750 }

Generated by doxygen