nux-1.16.0
EditTextBox.h
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   class TimerFunctor;
00038 
00039   class EditTextBox : public View
00040   {
00041   public:
00042     EditTextBox (const TCHAR *Caption, NUX_FILE_LINE_PROTO);
00043     ~EditTextBox();
00044     virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00045     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw);
00046     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00047     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00048 
00050     virtual bool InspectKeyEvent(unsigned int eventType,
00051       unsigned int keysym,
00052       const char* character);
00053 
00054     void SetText (const TCHAR &Caption);
00055     void SetText (const TCHAR *Caption);
00056     void SetText (const tstring &Caption);
00057     void SetText (const NString &Caption);
00058     const TCHAR *GetText() const;
00059     t_u32 GetTextSize() const
00060     {
00061       return (t_u32) m_Text.Length();
00062     }
00063 
00064     void SetDoubleValue (double d);
00065     void SetIntegerValue (int i);
00066 
00068     virtual NString GetCleanText() const;
00069 
00070     void SetTextBackgroundColor (const Color &color);
00071     Color GetTextBackgroundColor() const;
00072 
00073     void SetSelectedTextColor (Color color)
00074     {
00075       m_SelectedTextColor = color;
00076     }
00077     void SetSelectedTextBackgroundColor (Color color)
00078     {
00079       m_SelectedTextBackgroundColor = color;
00080     }
00081     void SetTextBlinkColor (Color color)
00082     {
00083       m_TextBlinkColor = color;
00084     }
00085     void SetCursorColor (Color color)
00086     {
00087       m_CursorColor = color;
00088     }
00089 
00090     Color GetSelectedTextColor() const
00091     {
00092       return m_SelectedTextColor;
00093     }
00094     Color GetSelectedTextBackgroundColor() const
00095     {
00096       return m_SelectedTextBackgroundColor;
00097     }
00098     Color GetTextBlinkColor() const
00099     {
00100       return m_TextBlinkColor;
00101     }
00102     Color GetCursorColor() const
00103     {
00104       return m_CursorColor;
00105     }
00106 
00107     void SetKeyEntryType (BaseKeyboardHandler::eKeyEntryType keytype)
00108     {
00109       m_KeyboardHandler.SetKeyEntryType (keytype);
00110     }
00111     BaseKeyboardHandler::eKeyEntryType GetKeyEntryType()
00112     {
00113       return m_KeyboardHandler.GetKeyEntryType();
00114     }
00115 
00116     //  Receivers
00117     void RecvMouseDoubleClick (int x, int y, unsigned long button_flags, unsigned long key_flags);
00118     void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
00119     void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
00120     void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00121     void RecvKeyEvent (
00122       unsigned long    eventType  ,   /*event type*/
00123       unsigned long    keysym     ,   /*event keysym*/
00124       unsigned long    state      ,   /*event state*/
00125       const TCHAR*     character  ,   /*character*/
00126       unsigned short   keyCount       /*key repeat count*/);
00127 
00128     void RecvStartKeyFocus();
00129     void RecvEndKeyFocus();
00130 
00131 
00132     void SetPrefix (const tstring &p)
00133     {
00134       m_Prefix = p;
00135     };
00136     void SetPrefix (const TCHAR *p)
00137     {
00138       m_Prefix = p;
00139     };
00140     void SetPrefix (const TCHAR &p)
00141     {
00142       m_Prefix = p;
00143     };
00144     void SetPrefix (const NString &p)
00145     {
00146       m_Prefix = p;
00147     };
00148     NString GetPrefix() const
00149     {
00150       return m_Prefix;
00151     };
00152 
00153     void SetSuffix (const tstring &s)
00154     {
00155       m_Suffix = s;
00156     };
00157     void SetSuffix (const TCHAR *s)
00158     {
00159       m_Suffix = s;
00160     };
00161     void SetSuffix (const TCHAR &s)
00162     {
00163       m_Suffix = s;
00164     };
00165     void SetSuffix (const NString &s)
00166     {
00167       m_Suffix = s;
00168     };
00169     NString Getsuffix() const
00170     {
00171       return m_Suffix;
00172     };
00173 
00174     void SetValidator (const Validator *validator);
00175 
00176     sigc::signal< void, EditTextBox *, unsigned int > sigCharacter; // Emitted every time a character typed
00177     sigc::signal< void, EditTextBox * > sigEditChange; // Emitted every time a character typed
00178 
00179     sigc::signal< void, EditTextBox *, const NString &> sigValidateKeyboardEntry;
00180     sigc::signal< void, EditTextBox * > sigValidateEntry;   // Emitted when the text is validated
00181     sigc::signal< void, EditTextBox * > sigSetText;     // Emitted when text is set with setCaption
00182     sigc::signal< void, EditTextBox * > sigEscapeKeyboardFocus;
00183     sigc::signal< void, EditTextBox * > sigStartKeyboardFocus;
00184     sigc::signal< void, EditTextBox * > sigEndKeyboardFocus;
00185 
00186     bool IsTextSelected()
00187     {
00188       return m_KeyboardHandler.IsTextSelected();
00189     }
00190     bool IsEmpty();
00191 
00192   private:
00193     bool ValidateKeyboardEntry (const TCHAR *text) const;
00194     void EscapeKeyboardFocus();
00195     void EnteringKeyboardFocus();
00196     void QuitingKeyboardFocus();
00197 
00198     virtual long PostLayoutManagement (long LayoutResult);
00199 
00200     NString m_Text;
00201     HLayout *hlayout;
00202 
00203     Color m_BackgroundColor;
00204     Color m_SelectedTextColor;
00205     Color m_SelectedTextBackgroundColor;
00206     Color m_TextBlinkColor;
00207     Color m_CursorColor;
00208 
00209     BaseKeyboardHandler m_KeyboardHandler;
00210     NString m_temporary_caption;
00211     BaseKeyboardHandler::eKeyEntryType m_keytype;
00212 
00213     Validator *m_Validator;
00214     NString m_Suffix;
00215     NString m_Prefix;
00216 
00217     bool BlinkCursor;
00218     void BlinkCursorTimerInterrupt (void *v);
00219     void StopBlinkCursor (bool BlinkState = false);
00220     void StartBlinkCursor (bool BlinkState = false);
00221     TimerFunctor *m_BlinkTimerFunctor;
00222     TimerHandle m_BlinkTimerHandler;
00223 
00224     void ScrollTimerInterrupt (void *v);
00225     TimerFunctor *m_ScrollTimerFunctor;
00226     TimerHandle m_ScrollTimerHandler;
00227 
00229     bool m_WriteAlpha;
00230 
00231     bool text_input_mode_;
00232     bool key_nav_mode_;
00233 
00234     friend class RGBValuator;
00235   };
00236 
00237 }
00238 
00239 #endif // EDITTEXTBOX_H
00240 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends