#ifndef GUITEXTENTRY_HEADER #define GUITEXTENTRY_HEADER 1 ////////////////////////////////////////////////// //! file="amma/GUI/GTK/TextEntry.hh" //! lib=GUI //! author="Charles Galambos" //! date="23/03/99" //! docentry="GUI.Widget" //! rcsid="$Id: TextEntry.hh,v 1.9 2000/12/13 15:44:53 ees1cg Exp $" #include "amma/PThread/Mutex.hh" #include "amma/GUI/Widget.hh" #include "amma/String.hh" #include "amma/DP/Signal1.hh" #include "amma/DP/Signal2.hh" //! userlevel=Develop //: TextEntry body class GUITextEntryBodyC : public GUIWidgetBodyC { public: GUITextEntryBodyC(const StringC &ntext,IntT MaxLen = -1,BooleanT 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 BooleanT Create(); //: Create the widget. virtual BooleanT Entry(const StringC &text); //: Some new text has been entered. virtual BooleanT Service(); //: Service request. // Used to send signals from other // threads to the program. StringC Text(); //: Access text BooleanT Text(const StringC &txt); //: Update text. // This is thread safe. Signal1C &Activate() { return activate; } //: Activate, called when text is changed. protected: BooleanT SetText(const StringC &txt); //: Set text to edit. // This should only be called within the GUI thread. void SigChanged(); //: Got a changed signal. void SigActivate(); //: Got a activate signal. PThread::MutexC access; StringC text; // Default text. IntT maxLen; // Maximum length, -1==Unset. BooleanT sigAllChanges; // Signal all changes to text. Signal1C activate; // Return has been pressed. Signal0C changed; // Text in box has been changed. }; //! userlevel=Normal //: TextEntry // This displays some text. class GUITextEntryC : public GUIWidgetC { public: GUITextEntryC() : DPEntityC(TRUE) {} //: Default constructor. // Creates an invalid handle. GUITextEntryC(const StringC &text,IntT nMaxLen = -1,BooleanT sigAllChanges = false) : DPEntityC(*new GUITextEntryBodyC(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: GUITextEntryBodyC &Body() { return dynamic_cast(DPEntityC::Body()); } //: Access body. const GUITextEntryBodyC &Body() const { return dynamic_cast(DPEntityC::Body()); } //: Access body. public: StringC Text() { return Body().Text(); } //: Access text BooleanT 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. }; namespace StdGUI { inline GUITextEntryC TextEntry(const StringC &def,int maxLen = -1) { return GUITextEntryC(def,maxLen); } //: Create a text entry. template GUITextEntryC TextEntry(const StringC &def,const DataT &dat,void (DataT::*func)(StringC &ref),int maxLen = -1,BooleanT sigAllChanges = false) { GUITextEntryC ret(def,maxLen,sigAllChanges); StdDP::Connect(ret.Activate(),dat,func); return ret; } template GUITextEntryC TextEntryR(const StringC &def,DataT &dat,void (DataT::*func)(StringC &ref),int maxLen = -1,BooleanT sigAllChanges = false) { GUITextEntryC ret(def,maxLen,sigAllChanges); StdDP::ConnectRef(ret.Activate(),dat,func); return ret; } template GUITextEntryC TextEntry(const StringC &def,void (*func)(StringC &ref,DataT &dat),const DataT &dat,int maxLen = -1,BooleanT sigAllChanges = false) { GUITextEntryC ret(def,maxLen,sigAllChanges); StdDP::Connect(ret.Activate(),func,StringC(""),dat); return ret; } } #endif