Pyro higlevel API
Classes | Public Member Functions | List of all members
os::InputBox Class Reference

Simple InputBox class. More...

Inheritance diagram for os::InputBox:
os::Window os::Looper os::Handler

Classes

class  Private
 

Public Member Functions

 InputBox (os::Messenger *pcTarget=NULL, const os::String &cTitle="InputBox", const os::String &cLabel="Please enter your value here:", const os::String &cText="", const os::String &cOkBut="_Okay", const os::String &cCancelBut="_Cancel", bool bNumeric=false, uint32 nFlags=os::WND_MODAL|os::WND_NOT_RESIZABLE|os::WND_NO_DEPTH_BUT|os::WND_NO_ZOOM_BUT)
 InputBox constructor. More...
 
 ~InputBox ()
 
os::Variant GetValue () const
 
void SetNumeric (bool)
 
bool GetNumeric () const
 
void SetLabelText (const os::String &)
 
os::String GetLabelText () const
 
void SetInputText (const os::String &)
 
os::String GetInputText () const
 
void SetOkButtonText (const os::String &)
 
os::String GetOkButtonText () const
 
void SetCancelButtonText (const os::String &)
 
os::String GetCancelButtonText () const
 
void HandleMessage (os::Message *pcMessage)
 Handle a message targeted at this handler. More...
 
bool OkToQuit ()
 Check if it is ok to break the loop. More...
 
- Public Member Functions inherited from os::Window
 Window (const Rect &cFrame, const String &cName, const String &cTitle, uint32 nFlags=0, uint32 nDesktopMask=CURRENT_DESKTOP)
 Initialize the window. More...
 
 ~Window ()
 Destruct a window. More...
 
virtual void FrameMoved (const Point &cDelta)
 
virtual void FrameSized (const Point &cDelta)
 
virtual void ScreenModeChanged (const IPoint &cNewRes, color_space eColorSpace)
 Called whenever the screenmode changes. More...
 
virtual void DesktopActivated (int nDesktop, bool bActive)
 Called whenever the desktop displaying the window will be activated or deactivated. More...
 
virtual void DesktopsChanged (uint32 nOldDesktops, uint32 nNewDesktops)
 
virtual void WindowsChanged ()
 Called whenever the currently shown windows change. More...
 
void SetFlags (uint32 nFlags)
 
uint32 GetFlags () const
 
void SetSizeLimits (const Point &cMinSize, const Point &cMaxSize)
 Limit the minimum and maximum window size. More...
 
void SetAlignment (const IPoint &cSize=IPoint(1, 1), const IPoint &cSizeOffset=IPoint(0, 0), const IPoint &cPos=IPoint(1, 1), const IPoint &cPosOffset=IPoint(0, 0))
 
void AddChild (View *pcChild, bool bAssignTabOrder=false)
 Add a view to the window. More...
 
void RemoveChild (View *pcChild)
 Remove a view from the window. More...
 
void MakeFocus (bool bFocus=true)
 Activate/Deactivate the window. More...
 
void Close ()
 
void Show (bool bMakeVisible=true)
 Hide/Unhide the window. More...
 
void Hide ()
 
bool IsVisible () const
 
void Start ()
 Unlock the window and start the looper thread. More...
 
void SetTitle (const String &cTitle)
 Change the window title. More...
 
String GetTitle (void) const
 Obtain the current window title. More...
 
void SetIcon (Bitmap *pcIcon)
 Change the window icon. More...
 
BitmapGetIcon (void) const
 Not longer supported. More...
 
void Flush ()
 Flush the windows render queue. More...
 
void Sync ()
 Flush the render queue, and wait til the rendering is done. More...
 
ViewFindView (const String &cName) const
 
ViewFindView (const Point &cPos) const
 Find the view covering a given position on the window. More...
 
ViewGetFocusChild (void) const
 
ViewSetFocusChild (View *pcChild)
 Activate a view. More...
 
void SetDefaultButton (View *pcView)
 Assign a default button. More...
 
ViewGetDefaultButton () const
 Return the view assigned as the default button. More...
 
void SetDefaultWheelView (View *pcView)
 
ViewGetDefaultWheelView () const
 
Rect GetFrame () const
 Get the windows position and size on the current desktop. More...
 
Rect GetBounds () const
 Get the window boundary. More...
 
void SetFrame (const Rect &cRect, bool bNotifyServer=true)
 Set the window's position and size. More...
 
void MoveBy (const Point &cDelta)
 Move the window relative to it's current position. More...
 
void MoveBy (float vDeltaX, float vDeltaY)
 Move the window relative to it's current position. More...
 
void MoveTo (const Point &cPos)
 Move the window to an absolute position. More...
 
void MoveTo (float x, float y)
 Move the window to an absolute position. More...
 
void CenterInWindow (Window *pcWin)
 Move the window to the centre of another window. More...
 
void CenterInScreen ()
 Move the window to the center of the screen. More...
 
void ResizeBy (const Point &cDelta)
 Resize the window relative to it's current size. More...
 
void ResizeBy (float vDeltaW, float vDeltaH)
 Resize the window relative to it's current size. More...
 
void ResizeTo (const Point &cSize)
 Resize the window to a new absolute size. More...
 
void ResizeTo (float w, float h)
 Resize the window to a new absolute size. More...
 
void SetShapeRegion (const Region &cReg)
 
void ClearShapeRegion ()
 
bool IsActive () const
 
int ToggleDepth ()
 
void AddShortcut (const ShortcutKey &cKey, Message *pcMsg)
 Add a keyboard shortcut. More...
 
void AddShortcut (const ShortcutKey &cKey, View *pcView)
 Add a keyboard shortcut. More...
 
void RemoveShortcut (const ShortcutKey &cKey)
 Remove a keyboard shortcut. More...
 
void DispatchMessage (Message *pcMessage, Handler *pcHandler)
 The loopers message handling callback. More...
 
- Public Member Functions inherited from os::Looper
 Looper (const String &cName, int nPriority=NORMAL_PRIORITY, int nPortSize=DEFAULT_PORT_SIZE)
 The looper constructor. More...
 
virtual ~Looper ()
 Looper destructor. More...
 
void SetName (const String &cName)
 Rename the looper. More...
 
String GetName () const
 Get the loopers name. More...
 
bool IsPublic () const
 See if the looper's message port is public. More...
 
void SetPublic (bool bPublic)
 Make port public/private. More...
 
port_id GetMsgPort () const
 Obtain the low-level message port used by this looper. More...
 
thread_id GetThread () const
 Obtain the thread id of the looper thread. More...
 
proc_id GetProcess () const
 Obtain the process ID of the loopers thread. More...
 
status_t Lock ()
 Lock the looper object. More...
 
status_t Lock (bigtime_t nTimeout)
 Lock the looper with a timeout. More...
 
status_t SafeLock ()
 Attempt to lock the looper. More...
 
status_t Unlock ()
 Unlock the looper. More...
 
void SetMutex (Locker *pcMutex)
 Set a custom mutex to be used by the looper. More...
 
LockerGetMutex () const
 Get a pointer to the loopers mutex. More...
 
int GetLockCount () const
 Obtain the number of locks held on the looper. More...
 
thread_id GetLockingThread () const
 Obtaing the owner of the looper lock. More...
 
bool IsLocked () const
 Check if the looper lock is owned by the calling thread. More...
 
virtual thread_id Run ()
 Start and unlock the looper. More...
 
int Wait () const
 Wait for the looper thread to die. More...
 
status_t PostMessage (uint32 nCode)
 Deliver a message to the looper. More...
 
status_t PostMessage (Message *pcMsg)
 Deliver a message to the looper. More...
 
status_t PostMessage (uint32 cCode, Handler *pcHandler, Handler *pcReplyTo=NULL)
 Deliver a message to the looper. More...
 
status_t PostMessage (Message *pcMsg, Handler *pcHandler, Handler *pcReplyTo=NULL)
 Deliver a message to the looper. More...
 
void SpoolMessages ()
 Drain the low-level message port. More...
 
MessageGetCurrentMessage () const
 Obtain the message currently being processed. More...
 
MessageDetachCurrentMessage ()
 Steal the current message. More...
 
virtual void Started ()
 Called by the looper thread before entering the message loop. More...
 
virtual bool Idle ()
 Hook called each time the message queue is drained. More...
 
MessageQueueGetMessageQueue () const
 Obtain the internal message queue used by the looper. More...
 
virtual void Quit ()
 Unconditionally terminate the looper. More...
 
void Terminate ()
 Unconditionally terminate the looper. More...
 
void AddTimer (Handler *pcTarget, int nID, bigtime_t nTimeout, bool bOneShot=true)
 Add a timer to the looper. More...
 
bool RemoveTimer (Handler *pcTarget, int nID)
 Delete a timer. More...
 
const handler_mapGetHandlerMap () const
 Get the internal handler list. More...
 
void AddHandler (Handler *pcHandler)
 Add a handler to the looper. More...
 
bool RemoveHandler (Handler *pcHandler)
 Remove a handler previously added by AddHandler() More...
 
HandlerFindHandler (const String &cName) const
 Search the looper for a named handler. More...
 
int GetHandlerCount () const
 Obtain the count of handlers added to this looper. More...
 
void SetDefaultHandler (Handler *pcHandler)
 Set the default target for incomming messages. More...
 
HandlerGetDefaultHandler () const
 Obtain the default handler for the looper. More...
 
void AddCommonFilter (MessageFilter *pcFilter)
 
void RemoveCommonFilter (MessageFilter *pcFilter)
 
const MsgFilterListGetCommonFilterList () const
 
- Public Member Functions inherited from os::Handler
 Handler (const String &cName)
 Construct a handler. More...
 
virtual ~Handler ()
 Destructor. More...
 
virtual void TimerTick (int nID)
 Timer dispatch member. More...
 
String GetName () const
 Get the handlers name. More...
 
void SetName (const String &cName)
 Rename the handler. More...
 
LooperGetLooper () const
 Get a pointer to the looper this handler belongs to. More...
 
void SetNextHandler (Handler *pcNextHandler)
 Set a handler that should handle messages this handler is not interrested in. More...
 
HandlerGetNextHandler () const
 Get the next handler in a handler chain. More...
 
void AddFilter (MessageFilter *pcFilter)
 
void RemoveFilter (MessageFilter *pcFilter)
 
const MsgFilterListGetFilterList () const
 
const uint32 GetToken ()
 Get the handlers token. More...
 

Additional Inherited Members

- Public Types inherited from os::Looper
typedef std::map< int, Handler * > handler_map
 
- Static Public Member Functions inherited from os::Looper
static LooperGetLooperForThread (thread_id hThread)
 
- Protected Member Functions inherited from os::Looper
bool FilterMessage (Message *pcMsg, Handler **ppcTarget, std::list< MessageFilter * > *pcFilterList)
 

Detailed Description

Description:
An InputBox is a way to get user input from a user. Use an InputBox when you need some data from a user(e.g., a date, a number, a string, and anything else).

There are two ways you can use InputBox:

The first way is by catching the os::Message code(M_BOX_REQUESTED) like

YourHandler::HandleMessage(os::Message* pcMessage)
{ 
  switch (pcMessage->GetCode())
  {
          case M_BOX_REQUESTED:
          {
                  os::Variant cVariant = inputBox->GetValue();

                  //do something with it

                  break;
          }
  }
}

And the second way starts out like the first, except that when the message is passed to HandleMessage(),
it passes the value along with it. So You could do:

YourHandler::HandleMessage(os::Message* pcMessage)
{ 
  switch (pcMessage->GetCode())
  {
          case M_BOX_REQUESTED:
          {
                  os::Variant cVariant;
                  pcMessage->GetVariant("value",&cVariant);

                  //do something with it

                  break;
          }
  }
} 
See Also
os::Window, os::String, os::Messenger, os::Message, os::Variant, os::Handler
Author
Rick Caudill(rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

Constructor & Destructor Documentation

InputBox::InputBox ( os::Messenger pcTarget = NULL,
const os::String cTitle = "InputBox",
const os::String cLabel = "Please enter your value here:",
const os::String cText = "",
const os::String cOkBut = "_Okay",
const os::String cCancelBut = "_Cancel",
bool  bNumeric = false,
uint32  nFlags = os::WND_MODAL | os::WND_NOT_RESIZABLE | os::WND_NO_DEPTH_BUT | os::WND_NO_ZOOM_BUT 
)
Description:
InputBox constructor.
Parameters
pcTarget- os::Messeneger pointer to the parent(used to send messages).
cTitle- The title of the window
cLabel- The label displaying a message to the user
cText- The default input text
cOkBut- The okay button text
cCancelBut- The cancel button text
bNumeric- Whether or not the dialog is for numbers only
nFlags- The flags for the window
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::Window::AddChild(), os::Window::CenterInScreen(), os::LayoutView::GetPreferredSize(), os::InputBox::Private::m_pcInputTextBox, os::InputBox::Private::m_pcLayoutView, os::InputBox::Private::m_pcOkButton, os::Window::ResizeTo(), os::Window::SetDefaultButton(), and os::Window::SetFocusChild().

InputBox::~InputBox ( )

Member Function Documentation

os::String InputBox::GetCancelButtonText ( ) const
Description:
Returns the cancel button text(i.e., the text that is shown on the CancelButton).
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::GetCancelButtonText().

os::String InputBox::GetInputText ( ) const
Description:
Returns the input text. This can be used in lieu of GetValue() if you just want to capture the text inputed by the user.
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::GetInputText().

os::String InputBox::GetLabelText ( ) const
Description:
Returns the label text(i.e., the text that is shown by the os::StringView).
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::GetLabelText().

bool InputBox::GetNumeric ( ) const
Description:
Returns whether or not the InputBox is numeric.
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::GetNumeric().

os::String InputBox::GetOkButtonText ( ) const
Description:
Returns the ok button text(i.e., the text that is shown on the Ok Button).
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::GetOkButtonText().

os::Variant InputBox::GetValue ( void  ) const
Description:
Returns the value of the InputBox(as a Variant).

Essentially all we have is a TextView, so you would think that we would want to return this as an os::String, right? No, and the reasoning behind returning it as an os::Vairant is so you can do operations like: GetValue().AsFloat(), GetValue().AsString()

Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::TextView::GetBuffer(), and os::InputBox::Private::m_pcInputTextBox.

Referenced by HandleMessage().

void InputBox::HandleMessage ( os::Message pcMessage)
virtual
Description:
Overload this member to dispatch messages sendt to this handler. When a looper receives a message for one of it's handlers it will call the taget handlers HandleMessage() to allow the handler to dispatch the message.
The message passed in pcMessage is also available through os::Looper::GetCurrentMessage() and os::Looper::DetachCurrentMessage() until this member returns. This is normally not very usefull for HandleMessage() itself but it can be convinient for other members called from HandleMessage() in case they need data from the message that was not passed on from HandleMessage().
The looper will be locked when this member is called. The default implementation of this member will pass the message on to the next handler if one was set with SetNextHandler().
Note
Never do any lenthy operations in any hook members that are called from the looper thread if the looper is involved with the GUI (for example if the looper is a os::Window). The looper will not be able to dispatch messages until the hook returns so spending a long time in this members will make the GUI feel unresponsive.
Parameters
pcMessageThe message that should be handled. This message will be deleted by the looper when HandleMessage() returns unless you detach it with os::Looper::DetachCurrentMessage(),
See Also
os::Looper::DispatchMessage(), os::Looper::DetachCurrentMessage()
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

Reimplemented from os::Handler.

References os::Message::AddPointer(), os::Message::AddVariant(), os::Message::GetCode(), GetValue(), os::Handler::HandleMessage(), os::M_BOX_REQUESTED, os::M_BOX_REQUESTER_CANCELED, os::InputBox::Private::m_pcTarget, os::Handler::Message, os::Messenger::SendMessage(), and os::Window::Show().

bool InputBox::OkToQuit ( void  )
virtual
Description:
You can overload this function to affect how the looper will react to M_QUIT messages. When an M_QUIT message arrive the looper will call this function to figure out what to do. If it returns false the message is ignored. If it returns true the loop is terminated, the looper object deleted and the looper thread will exit.
Returns
true if it is ok to terminate the looper, false otherwise.
See Also
Quit(), PostMessage()
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

Reimplemented from os::Looper.

References os::Message::AddPointer(), os::M_BOX_REQUESTER_CANCELED, os::InputBox::Private::m_pcTarget, os::Handler::Message, os::Messenger::SendMessage(), and os::Window::Show().

void InputBox::SetCancelButtonText ( const os::String cText)
Description:
SetCancelButtonText sets the text that is displayed on the cancel button.
Parameters
cText- the new text to set the cancel button to
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::SetCancelButtonText().

void InputBox::SetInputText ( const os::String cText)
Description:
SetInputText sets the text that is displayed in the InputBox's TextView.
Parameters
cText- the new text to set the TextView to
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::SetInputText().

void InputBox::SetLabelText ( const os::String cText)
Description:
SetLabelText sets the text that is displayed in the InputBox's StringView.
Parameters
cText- the new text to set the label to
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::SetLabelText().

void InputBox::SetNumeric ( bool  bNumeric)
Description:
SetNumeric tells the os::InputBox whether or not it is for Numeric input only. Setting this to true will mean that only numbers(0-9), one decimal point(.), and one e(e) can be punched in.
Parameters
bNumeric- Whether or not the dialog is for numbers only
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::SetNumeric().

void InputBox::SetOkButtonText ( const os::String cText)
Description:
SetOkButtonText sets the text that is displayed on the okay button.
Parameters
cText- the new text to set the okay button to
Author
Rick Caudill (rick@.nosp@m.syll.nosp@m.able..nosp@m.org)

References os::InputBox::Private::SetOkButtonText().