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

mmsinputwidget.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 MMSINPUTWIDGET_H_
00034 #define MMSINPUTWIDGET_H_
00035 
00036 #include "mmsgui/mmswidget.h"
00037 
00038 //! With this class you can display and edit one line text.
00039 /*!
00040 You can display and edit one line of text.
00041 \author Jens Schneider
00042 */
00043 class MMSInputWidget : public MMSWidget {
00044 
00045     private:
00046         string              className;
00047         MMSInputWidgetClass *inputWidgetClass;
00048         MMSInputWidgetClass myInputWidgetClass;
00049 
00050         //! language in which the text is to be translated
00051         MMSLanguage lang;
00052 
00053         //! loaded font
00054         MMSFBFont *font;
00055 
00056         //! path to the loaded font file
00057         string fontpath;
00058 
00059         //! name of the loaded font file
00060         string fontname;
00061 
00062         //! requested size of the font
00063         unsigned int fontsize;
00064 
00065         //! have to (re)load font?
00066         bool load_font;
00067 
00068         int             cursor_pos;
00069         bool            cursor_on;
00070         int             scroll_x;
00071         MMSFBRectangle  cursor_rect;
00072 
00073         class MMSInputWidgetThread  *iwt;
00074 
00075         //! current foreground values set?
00076         bool            current_fgset;
00077 
00078         //! current foreground color
00079         MMSFBColor      current_fgcolor;
00080 
00081         bool create(MMSWindow *root, string className, MMSTheme *theme);
00082 
00083         void initLanguage(MMSInputWidget *widget = NULL);
00084         void loadFont(MMSInputWidget *widget = NULL);
00085 
00086         void handleInput(MMSInputEvent *inputevent);
00087 
00088         bool init();
00089         bool release();
00090 
00091         void getForeground(MMSFBColor *color);
00092         bool enableRefresh(bool enable = true);
00093         bool checkRefreshStatus();
00094 
00095         bool draw(bool *backgroundFilled = NULL);
00096         void drawCursor(bool cursor_on);
00097 
00098         //! Internal method: Inform the widget, that the language has changed.
00099         void targetLangChanged(MMSLanguage lang);
00100 
00101     public:
00102         MMSInputWidget(MMSWindow *root, string className, MMSTheme *theme = NULL);
00103         ~MMSInputWidget();
00104 
00105         MMSWidget *copyWidget();
00106 
00107         void setCursorPos(int cursor_pos, bool refresh = true);
00108         bool addTextAfterCursorPos(string text, bool refresh = true);
00109         bool removeTextBeforeCursorPos(int textlen, bool refresh = true);
00110 
00111         //! Set one or more callbacks for the onBeforeChange event.
00112         /*!
00113         The connected callbacks will be called during handleInput() if user changes the text.
00114         If at least one of the callbacks returns false, the user input will be ignored
00115         and the text will not be changed.
00116 
00117         A callback method must be defined like this:
00118 
00119             bool myclass::mycallbackmethod(MMSWidget *widget, string text, bool add, MMSFBRectangle rect);
00120 
00121             Parameters:
00122 
00123                 widget -> is the pointer to the input widget which is to be changed
00124                 text   -> string to be added or removed
00125                 add    -> true: string is to be added, false: string is to be removed
00126                 rect   -> affected rectangle within the widget
00127 
00128             Returns:
00129 
00130                 true if the user input is accepted, else false if the input is to be ignored
00131 
00132         To connect your callback to onBeforeChange do this:
00133 
00134             sigc::connection connection;
00135             connection = mywindow->onBeforeChange->connect(sigc::mem_fun(myobject,&myclass::mycallbackmethod));
00136 
00137         To disconnect your callback do this:
00138 
00139             connection.disconnect();
00140 
00141         Please note:
00142 
00143             You HAVE TO disconnect myobject from onBeforeChange BEFORE myobject will be deleted!!!
00144             Else an abnormal program termination can occur.
00145             You HAVE TO call the disconnect() method of sigc::connection explicitly. The destructor will NOT do this!!!
00146         */
00147         sigc::signal<bool, MMSWidget*, string, bool, MMSFBRectangle>::accumulated<bool_accumulator> *onBeforeChange;
00148 
00149     public:
00150         /* theme access methods */
00151         string getFontPath();
00152         string getFontName(MMSLanguage lang = MMSLANG_NONE);
00153         unsigned int getFontSize();
00154         MMSALIGNMENT getAlignment();
00155         MMSFBColor getColor();
00156         MMSFBColor getSelColor();
00157         MMSFBColor getColor_p();
00158         MMSFBColor getSelColor_p();
00159         MMSFBColor getColor_i();
00160         MMSFBColor getSelColor_i();
00161         string getText();
00162         void getText(string &text);
00163         MMSSTATE getCursorState();
00164         MMSFBColor getShadowColor(MMSPOSITION position);
00165         MMSFBColor getSelShadowColor(MMSPOSITION position);
00166 
00167         void setFontPath(string fontpath, bool load = true, bool refresh = true);
00168         void setFontName(MMSLanguage lang, string fontname, bool load = true, bool refresh = true);
00169         void setFontName(string fontname, bool load = true, bool refresh = true);
00170         void setFontSize(unsigned int  fontsize, bool load = true, bool refresh = true);
00171         void setFont(MMSLanguage lang, string fontpath, string fontname, unsigned int fontsize, bool load = true, bool refresh = true);
00172         void setFont(string fontpath, string fontname, unsigned int fontsize, bool load = true, bool refresh = true);
00173         void setAlignment(MMSALIGNMENT alignment, bool refresh = true);
00174         void setColor(MMSFBColor color, bool refresh = true);
00175         void setSelColor(MMSFBColor selcolor, bool refresh = true);
00176         void setColor_p(MMSFBColor color_p, bool refresh = true);
00177         void setSelColor_p(MMSFBColor selcolor_p, bool refresh = true);
00178         void setColor_i(MMSFBColor color_i, bool refresh = true);
00179         void setSelColor_i(MMSFBColor selcolor_i, bool refresh = true);
00180         void setText(string text, bool refresh = true, bool reset_cursor = true);
00181         void setCursorState(MMSSTATE cursor_state, 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(MMSInputWidgetClass *themeClass);
00186 
00187     friend class MMSWindow;
00188     friend class MMSInputWidgetThread;
00189 };
00190 
00191 #endif /*MMSINPUTWIDGET_H_*/

Generated by doxygen