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

mmstextboxwidget.h

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 #ifndef MMSTEXTBOXWIDGET_H_
00034 #define MMSTEXTBOXWIDGET_H_
00035 
00036 #include "mmsgui/mmswidget.h"
00037 
00038 
00039 //! With this class you can display text with more than one line.
00040 /*!
00041 The textbox is focusable. So the user can scroll in it.
00042 Line breaks will be done with the normal line feed (\n (0x0a)). Specify &#10; as line feed within XML.
00043 If you want to display only one line of static text, you should use the MMSLabel widget.
00044 \author Jens Schneider
00045 */
00046 class MMSTextBoxWidget : public MMSWidget {
00047     private:
00048         typedef struct {
00049             MMSFBRectangle geom;
00050             string       word;
00051             unsigned int line;
00052             unsigned int paragraph;
00053         } TEXTBOX_WORDGEOM;
00054 
00055         string                  className;
00056         MMSTextBoxWidgetClass   *textBoxWidgetClass;
00057         MMSTextBoxWidgetClass   myTextBoxWidgetClass;
00058 
00059         //! language in which the text is to be translated
00060         MMSLanguage lang;
00061 
00062         //! loaded font
00063         MMSFBFont *font;
00064 
00065         //! path to the loaded font file
00066         string fontpath;
00067 
00068         //! name of the loaded font file
00069         string fontname;
00070 
00071         //! requested size of the font
00072         unsigned int fontsize;
00073 
00074         //! have to (re)load font?
00075         bool load_font;
00076 
00077 
00078         vector<TEXTBOX_WORDGEOM *> wordgeom;
00079 
00080         string  lasttext;
00081         bool    surfaceChanged;
00082 
00083         //! the translated text will be stored here, this is used in the draw() method
00084         string translated_text;
00085 
00086         //! if true the translated_text is valid
00087         bool translated;
00088 
00089         //! swap left-right alignment
00090         bool swap_left_right;
00091 
00092         //! used to load text from a file
00093         MMSFile *file;
00094 
00095         //! current foreground values set?
00096         bool            current_fgset;
00097 
00098         //! current foreground color
00099         MMSFBColor      current_fgcolor;
00100 
00101         bool create(MMSWindow *root, string className, MMSTheme *theme);
00102 
00103         void initLanguage(MMSTextBoxWidget *widget = NULL);
00104         void loadFont(MMSTextBoxWidget *widget = NULL);
00105 
00106         bool setSurfaceGeometry(unsigned int width = 0, unsigned int height = 0);
00107 
00108         bool calcWordGeom(string &text, unsigned int startWidth, unsigned int startHeight,
00109                           unsigned int *realWidth, unsigned int *realHeight,
00110                           unsigned int *scrollDX, unsigned int *scrollDY, unsigned int *lines, unsigned int *paragraphs,
00111                           bool wrap = true, bool splitwords = true, MMSALIGNMENT alignment = MMSALIGNMENT_CENTER,
00112                           unsigned int *minWidth = NULL, unsigned int *minHeight = NULL, bool force_recalc = false);
00113 
00114         bool init();
00115         bool release();
00116 
00117         bool prepareText(int *width, int *height, bool recalc = false);
00118         void calcContentSize();
00119 
00120         void getForeground(MMSFBColor *color);
00121         bool enableRefresh(bool enable = true);
00122         bool checkRefreshStatus();
00123 
00124         bool draw(bool *backgroundFilled = NULL);
00125 
00126         //! Internal method: Inform the widget, that the language has changed.
00127         void targetLangChanged(MMSLanguage lang);
00128 
00129         bool loadFile(bool refresh);
00130 
00131     public:
00132         MMSTextBoxWidget(MMSWindow *root, string className, MMSTheme *theme = NULL);
00133         ~MMSTextBoxWidget();
00134 
00135         MMSWidget *copyWidget();
00136 
00137     public:
00138         //! reload the file and display it in the textbox
00139         bool reloadFile();
00140 
00141         // theme access methods
00142         string getFontPath();
00143         string getFontName(MMSLanguage lang = MMSLANG_NONE);
00144         unsigned int getFontSize();
00145         MMSALIGNMENT getAlignment();
00146         bool getWrap();
00147         bool getSplitWords();
00148         MMSFBColor getColor();
00149         MMSFBColor getSelColor();
00150         MMSFBColor getColor_p();
00151         MMSFBColor getSelColor_p();
00152         MMSFBColor getColor_i();
00153         MMSFBColor getSelColor_i();
00154         string getText();
00155         void getText(string &text);
00156         bool getTranslate();
00157         string getFilePath();
00158         string getFileName();
00159         MMSFBColor getShadowColor(MMSPOSITION position);
00160         MMSFBColor getSelShadowColor(MMSPOSITION position);
00161 
00162         void setFontPath(string fontpath, bool load = true, bool refresh = true);
00163         void setFontName(MMSLanguage lang, string fontname, bool load = true, bool refresh = true);
00164         void setFontName(string fontname, bool load = true, bool refresh = true);
00165         void setFontSize(unsigned int  fontsize, bool load = true, bool refresh = true);
00166         void setFont(MMSLanguage lang, string fontpath, string fontname, unsigned int fontsize, bool load = true, bool refresh = true);
00167         void setFont(string fontpath, string fontname, unsigned int fontsize, bool load = true, bool refresh = true);
00168         void setAlignment(MMSALIGNMENT alignment, bool refresh = true);
00169         void setWrap(bool wrap, bool refresh = true);
00170         void setSplitWords(bool splitwords, bool refresh = true);
00171         void setColor(MMSFBColor color, bool refresh = true);
00172         void setSelColor(MMSFBColor selcolor, bool refresh = true);
00173         void setColor_p(MMSFBColor color_p, bool refresh = true);
00174         void setSelColor_p(MMSFBColor selcolor_p, bool refresh = true);
00175         void setColor_i(MMSFBColor color_i, bool refresh = true);
00176         void setSelColor_i(MMSFBColor selcolor_i, bool refresh = true);
00177         void setText(string *text, bool refresh = true);
00178         void setText(string text, bool refresh = true);
00179         void setTranslate(bool translate, bool refresh = true);
00180         void setFilePath(string filepath, bool load = true, bool refresh = true);
00181         void setFileName(string filename, bool load = true, bool refresh = true);
00182         void setShadowColor(MMSPOSITION position, MMSFBColor color, bool refresh = true);
00183         void setSelShadowColor(MMSPOSITION position, MMSFBColor selcolor, bool refresh = true);
00184 
00185         void updateFromThemeClass(MMSTextBoxWidgetClass *themeClass);
00186 
00187     // friends
00188     friend class MMSWindow;
00189 };
00190 
00191 #endif /*MMSTEXTBOXWIDGET_H_*/

Generated by doxygen