Back to index

nux  3.0.0
EditTextBox.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef EDITTEXTBOX_H
00024 #define EDITTEXTBOX_H
00025 
00026 #include "KeyboardHandler.h"
00027 #include "TimerProc.h"
00028 
00029 namespace nux
00030 {
00031   class HLayout;
00032   class VLayout;
00033   class Layout;
00034   class BaseKeyboardHandler;
00035   class TextLine;
00036   class Validator;
00037 
00038 
00039   class EditTextBox : public View
00040   {
00041   public:
00042     EditTextBox(const char *Caption, NUX_FILE_LINE_PROTO);
00043     ~EditTextBox();
00044     virtual void Draw(GraphicsEngine &graphics_engine, bool force_draw);
00045     virtual void DrawContent(GraphicsEngine &graphics_engine, bool force_draw);
00046     virtual void PostDraw(GraphicsEngine &graphics_engine, bool force_draw);
00047 
00049     virtual bool InspectKeyEvent(unsigned int eventType,
00050       unsigned int keysym,
00051       const char* character);
00052 
00053     void SetText(const char &Caption);
00054     void SetText(const char *Caption);
00055     void SetText(const tstring &Caption);
00056     void SetText(const NString &Caption);
00057     const char *GetText() const;
00058     unsigned int GetTextSize() const
00059     {
00060       return (unsigned int) m_Text.Length();
00061     }
00062 
00063     void SetDoubleValue(double d);
00064     void SetIntegerValue(int i);
00065 
00067     virtual NString GetCleanText() const;
00068 
00069     void SetTextBackgroundColor(const Color &color);
00070     Color GetTextBackgroundColor() const;
00071 
00072     void SetSelectedTextColor(Color color)
00073     {
00074       m_SelectedTextColor = color;
00075     }
00076     void SetSelectedTextBackgroundColor(Color color)
00077     {
00078       m_SelectedTextBackgroundColor = color;
00079     }
00080     void SetTextBlinkColor(Color color)
00081     {
00082       m_TextBlinkColor = color;
00083     }
00084     void SetCursorColor(Color color)
00085     {
00086       m_CursorColor = color;
00087     }
00088 
00089     Color GetSelectedTextColor() const
00090     {
00091       return m_SelectedTextColor;
00092     }
00093     Color GetSelectedTextBackgroundColor() const
00094     {
00095       return m_SelectedTextBackgroundColor;
00096     }
00097     Color GetTextBlinkColor() const
00098     {
00099       return m_TextBlinkColor;
00100     }
00101     Color GetCursorColor() const
00102     {
00103       return m_CursorColor;
00104     }
00105 
00106     void SetKeyEntryType(BaseKeyboardHandler::eKeyEntryType keytype)
00107     {
00108       m_KeyboardHandler.SetKeyEntryType(keytype);
00109     }
00110     BaseKeyboardHandler::eKeyEntryType GetKeyEntryType()
00111     {
00112       return m_KeyboardHandler.GetKeyEntryType();
00113     }
00114 
00115     //  Receivers
00116     void RecvMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
00117     void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
00118     void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
00119     void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00120     void RecvKeyEvent(
00121       unsigned long    eventType  ,   /*event type*/
00122       unsigned long    keysym     ,   /*event keysym*/
00123       unsigned long    state      ,   /*event state*/
00124       const char*     character  ,   /*character*/
00125       unsigned short   keyCount       /*key repeat count*/);
00126 
00127     void RecvStartKeyFocus();
00128     void RecvEndKeyFocus();
00129 
00130 
00131     void SetPrefix(const tstring &p)
00132     {
00133       m_Prefix = p;
00134     };
00135     void SetPrefix(const char *p)
00136     {
00137       m_Prefix = p;
00138     };
00139     void SetPrefix(const char &p)
00140     {
00141       m_Prefix = p;
00142     };
00143     void SetPrefix(const NString &p)
00144     {
00145       m_Prefix = p;
00146     };
00147     NString GetPrefix() const
00148     {
00149       return m_Prefix;
00150     };
00151 
00152     void SetSuffix(const tstring &s)
00153     {
00154       m_Suffix = s;
00155     };
00156     void SetSuffix(const char *s)
00157     {
00158       m_Suffix = s;
00159     };
00160     void SetSuffix(const char &s)
00161     {
00162       m_Suffix = s;
00163     };
00164     void SetSuffix(const NString &s)
00165     {
00166       m_Suffix = s;
00167     };
00168     NString Getsuffix() const
00169     {
00170       return m_Suffix;
00171     };
00172 
00173     void SetValidator(const Validator *validator);
00174 
00175     sigc::signal< void, EditTextBox *, unsigned int > sigCharacter; // Emitted every time a character typed
00176     sigc::signal< void, EditTextBox * > sigEditChange; // Emitted every time a character typed
00177 
00178     sigc::signal< void, EditTextBox *, const NString &> sigValidateKeyboardEntry;
00179     sigc::signal< void, EditTextBox * > sigValidateEntry;   // Emitted when the text is validated
00180     sigc::signal< void, EditTextBox * > sigSetText;     // Emitted when text is set with setCaption
00181     sigc::signal< void, EditTextBox * > sigEscapeKeyboardFocus;
00182     sigc::signal< void, EditTextBox * > sigStartKeyboardFocus;
00183     sigc::signal< void, EditTextBox * > sigEndKeyboardFocus;
00184 
00185     bool IsTextSelected()
00186     {
00187       return m_KeyboardHandler.IsTextSelected();
00188     }
00189     bool IsEmpty();
00190 
00191   private:
00192     bool ValidateKeyboardEntry(const char *text) const;
00193     void EscapeKeyboardFocus();
00194     void EnteringKeyboardFocus();
00195     void QuitingKeyboardFocus();
00196 
00197     virtual long PostLayoutManagement(long LayoutResult);
00198 
00199     NString m_Text;
00200     HLayout *hlayout;
00201 
00202     Color m_BackgroundColor;
00203     Color m_SelectedTextColor;
00204     Color m_SelectedTextBackgroundColor;
00205     Color m_TextBlinkColor;
00206     Color m_CursorColor;
00207 
00208     BaseKeyboardHandler m_KeyboardHandler;
00209     NString m_temporary_caption;
00210     BaseKeyboardHandler::eKeyEntryType m_keytype;
00211 
00212     Validator *m_Validator;
00213     NString m_Suffix;
00214     NString m_Prefix;
00215 
00216     bool BlinkCursor;
00217     void BlinkCursorTimerInterrupt(void *v);
00218     void StopBlinkCursor(bool BlinkState = false);
00219     void StartBlinkCursor(bool BlinkState = false);
00220     TimerFunctor *m_BlinkTimerFunctor;
00221     TimerHandle m_BlinkTimerHandler;
00222 
00223     void ScrollTimerInterrupt(void *v);
00224     TimerFunctor *m_ScrollTimerFunctor;
00225     TimerHandle m_ScrollTimerHandler;
00226 
00228     bool m_WriteAlpha;
00229 
00230     bool text_input_mode_;
00231     bool key_nav_mode_;
00232 
00233     friend class RGBValuator;
00234   };
00235 
00236 }
00237 
00238 #endif // EDITTEXTBOX_H
00239