00001
00002
00003
00004
00005
00006
00007
00008 #include "mmsgui/mmscanvaswidget.h"
00009 #include "mmsgui/mmscanvasfactory.h"
00010 #include <iostream>
00011 #include <sstream>
00012
00013
00014 MMSCanvasWidget::MMSCanvasWidget(MMSWindow *root, string className, MMSTheme *theme) : MMSWidget() {
00015 create(root,className, theme);
00016 this->initialized = false;
00017 }
00018
00019 MMSCanvasWidget::~MMSCanvasWidget() {
00020
00021 }
00022
00023 MMSWidget *MMSCanvasWidget::copyWidget() {
00024
00025 MMSCanvasFactory factory;
00026 MMSCanvasWidget *newWidget = factory.constructCanvas(factoryname.c_str(), rootwindow, className, this->da->theme);
00027
00028 newWidget->className = this->className;
00029 newWidget->canvasWidgetClass = this->canvasWidgetClass;
00030 newWidget->myCanvasWidgetClass = this->myCanvasWidgetClass;
00031
00032 newWidget->attributes = this->attributes;
00033 newWidget->attributemap = this->attributemap;
00034 newWidget->canvastheme = this->canvastheme;
00035
00036
00037 MMSWidget::copyWidget((MMSWidget*)newWidget);
00038
00039
00040 this->copyFunc((MMSWidget *)newWidget);
00041
00042 return newWidget;
00043 }
00044
00045 void MMSCanvasWidget::updateFromThemeClass(MMSCanvasWidgetClass *themeClass) {
00046
00047 if(!themeClass)
00048 return;
00049
00050 if( themeClass->isAttributes()) {
00051 this->setAttributes(themeClass->getAttributes());
00052
00053
00054 }
00055
00056 MMSWidget::updateFromThemeClass(&(themeClass->widgetClass));
00057 }
00058
00059 bool MMSCanvasWidget::create(MMSWindow *root, string className, MMSTheme *theme) {
00060 this->type = MMSWIDGETTYPE_CANVAS;
00061 this->className = className;
00062
00063
00064 this->da = new MMSWIDGET_DRAWABLE_ATTRIBUTES;
00065 if (theme) this->da->theme = theme; else this->da->theme = globalTheme;
00066 this->canvastheme = this->da->theme;
00067 this->canvasWidgetClass = this->da->theme->getCanvasWidgetClass(className);
00068 this->da->baseWidgetClass = &(this->da->theme->canvasWidgetClass.widgetClass);
00069 if (this->canvasWidgetClass) this->da->widgetClass = &(this->canvasWidgetClass->widgetClass); else this->da->widgetClass = NULL;
00070
00071
00072 this->current_fgset = false;
00073
00074
00075 return MMSWidget::create(root, true, true, true, true, true, true, true);
00076
00077 }
00078
00079 bool MMSCanvasWidget::init() {
00080
00081
00082 initFunc();
00083
00084 if (!MMSWidget::init())
00085 return false;
00086 return true;
00087 }
00088
00089 bool MMSCanvasWidget::release() {
00090
00091 if (!MMSWidget::release())
00092 return false;
00093
00094 return releaseFunc();
00095 }
00096
00097 bool MMSCanvasWidget::draw(bool *backgroundFilled) {
00098
00099 canvasSurface = this->surface;
00100
00101 this->surface->lock();
00102
00103 if (MMSWidget::draw(backgroundFilled)) {
00104 drawingFunc(this->surface, this->surfaceGeom, backgroundFilled);
00105 }
00106
00107 this->surface->unlock();
00108
00109
00110 return MMSWidget::drawDebug();
00111 }
00112
00113
00114 bool MMSCanvasWidget::enableRefresh(bool enable) {
00115 if (!MMSWidget::enableRefresh(enable)) return false;
00116
00117
00118 this->current_fgset = false;
00119
00120 return true;
00121 }
00122
00123 bool MMSCanvasWidget::checkRefreshStatus() {
00124 if (MMSWidget::checkRefreshStatus()) return true;
00125
00126 if (this->current_fgset) {
00127
00128 return false;
00129 }
00130
00131
00132 enableRefresh();
00133
00134 return true;
00135 }
00136
00137 void MMSCanvasWidget::handleInput(MMSInputEvent *inputevent) {
00138 if(!handleInputFunc(inputevent))
00139 throw MMSWidgetError(1,"input not handled");
00140 }
00141
00142 void MMSCanvasWidget::setAttributes(string attr) {
00143 std::stringstream ss(attr);
00144 std::string item, item2;
00145
00146 while(std::getline(ss,item, ';')) {
00147 std::stringstream ss2(item);
00148 std::string key = "";
00149 std::string val = "";
00150 while(std::getline(ss2,item2, ':')) {
00151
00152 trim(item2);
00153 if(key.empty())
00154 key = item2;
00155 else
00156 val = item2;
00157 }
00158 if(!key.empty())
00159 attributemap.insert(std::make_pair(key,val));
00160 }
00161 }
00162
00163 MMSFontManager *MMSCanvasWidget::getFontManager() {
00164 return this->rootwindow->fm;
00165 }
00166
00167 void MMSCanvasWidget::checkInit() {
00168 if(!initialized)
00169 this->init();
00170 }
00171
00172 MMSImageManager *MMSCanvasWidget::getImageManager() {
00173 return this->rootwindow->im;
00174 }
00175
00176 void MMSCanvasWidget::add(MMSWidget *widget) {
00177 this->children.push_back(widget);
00178 widget->setParent(this);
00179 if (this->rootwindow)
00180 this->rootwindow->add(widget);
00181 }