#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/GUI/GTK/TextEntry.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVLGUITEXTENTRY_HEADER #define RAVLGUITEXTENTRY_HEADER 1 ////////////////////////////////////////////////// //! file="Ravl/GUI/GTK/TextEntry.hh" //! lib=RavlGUI //! author="Charles Galambos" //! date="23/03/99" //! docentry="Ravl.GUI.Control" //! rcsid="$Id: TextEntry.hh,v 1.3 2001/09/23 12:41:16 craftit Exp $" #include "Ravl/GUI/Widget.hh" #include "Ravl/Threads/Mutex.hh" #include "Ravl/String.hh" #include "Ravl/Threads/Signal1.hh" #include "Ravl/Threads/Signal2.hh" namespace RavlGUIN { class TextEntryC; //! userlevel=Develop //: TextEntry body class TextEntryBodyC : public WidgetBodyC { public: TextEntryBodyC(const StringC &ntext,IntT MaxLen = -1,bool sigAllChanges = false); //: Constructor. // The inital content of the entry is set to ntext. // If MaxLen is set to a negative number, the length is unlimited. virtual bool Create(); //: Create the widget. virtual bool Entry(const StringC &text); //: Some new text has been entered. StringC Text(); //: Access text bool Text(const StringC &txt); //: Update text. // This is thread safe. Signal1C &Activate() { return activate; } //: Activate, called when text is changed. protected: bool SetText(const StringC &txt); //: Set text to edit. // This should only be called within the GUI thread. bool GUISetText(StringC &txt); //: Set text to edit. // This should only be called within the GUI thread. bool SigChanged(); //: Got a changed signal. bool SigActivate(); //: Got a activate signal. MutexC access; StringC text; // Default text. IntT maxLen; // Maximum length, -1==Unset. bool sigAllChanges; // Signal all changes to text. Signal1C activate; // Return has been pressed. Signal0C changed; // Text in box has been changed. friend class TextEntryC; }; //! userlevel=Normal //: TextEntry // This displays some text. class TextEntryC : public WidgetC { public: TextEntryC() {} //: Default constructor. // Creates an invalid handle. TextEntryC(const StringC &text,IntT nMaxLen = -1,bool sigAllChanges = false) : WidgetC(*new TextEntryBodyC(text,nMaxLen,sigAllChanges)) {} //: Constructor // The inital content of the entry is set to ntext. // If MaxLen is set to a negative number, the length is unlimited. protected: TextEntryC(TextEntryBodyC &bod) : WidgetC(bod) {} //: Body constructor. TextEntryBodyC &Body() { return static_cast(WidgetC::Body()); } //: Access body. const TextEntryBodyC &Body() const { return static_cast(WidgetC::Body()); } //: Access body. bool GUISetText(StringC &txt) { return Body().GUISetText(txt); } //: Set text to edit. // This should only be called within the GUI thread. public: StringC Text() { return Body().Text(); } //: Access text bool Text(const StringC &txt) { return Body().Text(txt); } //: Update text. // This is thread safe, with respect to the GUI thread. void SetText(StringC &txt) { Body().Text(txt); } //: Update text, for signal functions. // This is thread safe, with respect to the GUI thread. Signal1C &Activate() { return Body().Activate(); } //: Activate, called when text is changed. friend class TextEntryBodyC; }; inline TextEntryC TextEntry(const StringC &def,int maxLen = -1) { return TextEntryC(def,maxLen); } //: Create a text entry. template TextEntryC TextEntry(const StringC &def,const DataT &dat,bool (DataT::*func)(StringC &ref),int maxLen = -1,bool sigAllChanges = false) { TextEntryC ret(def,maxLen,sigAllChanges); Connect(ret.Activate(),dat,func); return ret; } template TextEntryC TextEntryR(const StringC &def,DataT &dat,bool (DataT::*func)(StringC &ref),int maxLen = -1,bool sigAllChanges = false) { TextEntryC ret(def,maxLen,sigAllChanges); ConnectRef(ret.Activate(),dat,func); return ret; } template TextEntryC TextEntry(const StringC &def,bool (*func)(StringC &ref,DataT &dat),const DataT &dat,int maxLen = -1,bool sigAllChanges = false) { TextEntryC ret(def,maxLen,sigAllChanges); Connect(ret.Activate(),func,StringC(""),dat); return ret; } } #endif