Index: A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
Every application contains an AppBase object. The AppBase object is the top object in an application's UI hierarchy ; all the FlexFrames, FlexDialogs, and other windows in an application are children of the application's AppBase object. Additionally, AppBase objects have member functions that applications can override to know when to build and destroy the application UI. It also contains mechanisms and API for manipulating user interface concepts such as the keyboard focus, pen grab, and active window. As is the case with all UI components, the AppBase member functions must be invoked on an application's first (main) thread.
This is an abstract class and cannot be directly instantiated.
#include <ui/appbase.h>
public: | ||
AppBase(); | ||
~AppBase(); | ||
enum | AppState; | |
Result | AddFocusChangeListener(FocusChangeListenerInterface& listener); | |
Result | AddInkListener(InkListenerInterface& listener); | |
Result | AddTargetChangeListener(TargetChangeListenerInterface& listener); | |
Result | AddWindowListener(WindowListenerInterface& listener); | |
void | Exit(void); | |
static Result | FlushInput(void); | |
static AppBase * | GetAppBase(void); | |
TCHAR * | GetAppContext(void); | |
uint32 | GetDesiredStackSize(void) const; | |
static FlexComponent * | GetFocus(void); | |
AppState | GetState(void) const; | |
Thread * | GetThread(void) const; | |
static FlexComponent * | GetTarget(void); | |
const TCHAR * | GetUAL(void) const; | |
Boolean | HandleUndispatchedMessage(Message *msg); | |
void | Idle(void); | |
void | Lower(void); | |
void | ProcessFocusChangeEvent(FocusChangeEvent& e); | |
void | ProcessInkEvent(InkEvent& e); | |
void | ProcessTargetChangeEvent(TargetChangeEvent& e); | |
void | ProcessWindowEvent(WindowEvent &e); | |
void | Raise(void); | |
void | RemoveFocusChangeListener(FocusChangeListenerInterface& listener); | |
void | RemoveInkListener(InkListenerInterface& listener); | |
void | RemoveTargetChangeListener(TargetChangeListenerInterface& listener); | |
void | RemoveWindowListener(WindowListenerInterface& listener); | |
void | SetAppContext(const TCHAR *context) ; | // pure virtual |
static FlexComponent * | SetFocus(FlexComponent *focusObj); | |
void | SetState(AppState state); | |
static FlexComponent * | SetTarget(FlexComponent *targetObj); | |
static Result | UpdateDisplay(void); | |
protected: |
public: | ||
---|---|---|
// FlexComponent members | ||
enum | HorizontalSizePreference; | |
enum | VerticalSizePreference; | |
Result | AddComponentListener(ComponentListenerInterface& listener); | |
Result | AddFocusListener(FocusListenerInterface& listener); | |
Result | AddKeyListener(KeyListenerInterface& listener); | |
Result | AddMouseListener(MouseListenerInterface& listener); | |
Result | AddMouseMotionListener(MouseMotionListenerInterface& listener); | |
void | AddNotify(void); | |
Boolean | Contains(WinCoord x, WinCoord y); | |
Boolean | Contains(WinXYPoint& point); | |
void | DelayedDelete(void); | |
void | DoLayout(void); | |
Colorant | GetBackground(void); | |
WinRectangle | GetBounds(void) const; | |
FlexComponent * | GetComponentAt(WinCoord x, WinCoord y, Boolean visibleOnly ); | |
FlexComponent * | GetComponentAt(WinXYPoint& point, Boolean visibleOnly ); | |
Colorant | GetForeground(void); | |
FlexComponentID | GetID(void); | |
WinXYPoint | GetLocation(void); | |
Dimension | GetMinimumSize(void); | |
FlexContainer * | GetParent(void) const; | |
FlexWindow * | GetFlexWindowAncestor(void); | |
Dimension | GetPreferredSize(void); | |
Dimension | GetSize(void) const; | |
void | GetSizePreference(HorizontalSizePreference &horizontalSizePref, VerticalSizePreference &verticalSizePref); | |
void | Invalidate(void); | |
Boolean | IsEnabled(void) const; | |
Boolean | IsFocusTraversable(void); | |
Boolean | IsShowing(void) const; | |
Boolean | IsGeometryValid(void) const; | |
Boolean | IsVisible(void) const; | |
void | Paint(void); | |
void | RemoveComponentListener(ComponentListenerInterface& listener); | |
void | RemoveFocusListener(FocusListenerInterface& listener); | |
void | RemoveKeyListener(KeyListenerInterface& listener); | |
void | RemoveMouseListener(MouseListenerInterface& listener); | |
void | RemoveMouseMotionListener(MouseMotionListenerInterface& listener); | |
void | RemoveNotify(void); | |
void | Repaint(void); | |
void | Repaint(WinCoord x, WinCoord y, uint16 width, uint16 height); | |
void | RequestFocus(void); | |
Result | SetBackground(Colorant color); | |
void | SetBounds(WinCoord x, WinCoord y, uint16 width, uint16 height); | |
void | SetBounds(WinRectangle& rect); | |
void | SetEnabled(Boolean enable); | |
Result | SetForeground(Colorant color); | |
void | SetID(FlexComponentID id); | |
void | SetLocation(WinCoord x, WinCoord y); | |
void | SetLocation(const WinXYPoint& point); | |
void | SetSize(const Dimension& dimension); | |
void | SetSize(uint16 width, uint16 height); | |
void | SetSizePreference(HorizontalSizePreference horizontalSizePref, VerticalSizePreference verticalSizePref); | |
Result | SetVisible(Boolean visible); | |
void | TransferFocus(void); | |
void | Update(WinCoord x, WinCoord y, uint16 width, uint16 height); | |
void | Validate(void); | |
// Event processing methods | ||
void | ProcessActionEvent(ActionEvent& actionEvent); | |
void | ProcessComponentEvent(ComponentEvent& componentEvent); | |
void | ProcessFocusEvent(FocusEvent& focusEvent); | |
void | ProcessKeyEvent(KeyEvent& keyEvent); | |
void | ProcessMouseEvent(MouseEvent& mouseEvent); | |
void | ProcessMouseMotionEvent(MouseEvent& mouseEvent); | |
// Graphical rendering methods | ||
void * | CopyArea(const WinRectangle *bounds) const; | |
WinCoord | FontMetric( FontMetricInfo info, const TextState& textState ) const; | |
void | BrushLine( WinXYPoint p1, WinXYPoint p2, Colorant lineCOlor, WinCoord penWidth ); | |
void | DrawLine( WinXYPoint p1, WinXYPoint p2, Colorant lineColor ); | |
void | DrawHLine( WinCoord xStart, WinCoord xEnd, WinCoord yCoord, Colorant lineColor ); | |
void | DrawVLine( WinCoord xCoord, WinCoord yStart, WinCoord yEnd, Colorant lineColor); | |
void | DrawBitmap(const Bitmap& bitmap, WinXYPoint destUpLeft, Colorant color); | |
void | DrawBitmap(const Bitmap& bitmap, WinXYPoint destUpLeft); | |
void | DrawPoint( WinCoord xPos, WinCoord yPos, Colorant dotColor ); | |
void | DrawPoint( WinXYPoint point, Colorant dotColor ); | |
void | DrawString( const TCHAR string[], TextState& textState ); | |
void | DrawString( const TCHAR string[], int32 numChars, TextState& textState ); | |
void | DrawUIShape( const UIShape srcUIShape, const WinXYPoint& basePoint, Colorant fgColor, int16 parm0 , int16 parm1 , int16 parm2 , int16 parm3 ); | |
void | InvertUIShape( const UIShape srcUIShape, const WinXYPoint& basePoint, int16 parm0 , int16 parm1 , int16 parm2 , int16 parm3 ); | |
void | FillRect( WinCoord leftCorner, WinCoord topCorner, WinCoord rightCorner, WinCoord bottomCorner, Colorant fillColor ); | |
void | InvertRect( WinCoord leftCorner, WinCoord topCorner, WinCoord rightCorner, WinCoord bottomCorner ); | |
void | InvertLine( WinXYPoint p1, WinXYPoint p2 ); | |
void | InvertLine( WinCoord x1, WinCoord y1, WinCoord x2, WinCoord y2 ); | |
void | SetClipRect( const WinXYPoint& clipUpLeft, const WinXYPoint& clipLowRight ); | |
void | ClearClipRect(void); | |
void | Render(Renderer& renderer); | |
WinCoord | StringWidth( const TCHAR string[], const TextState& textState ) const; | |
WinCoord | StringWidth( const TCHAR string[], int32 numChars, const TextState& textState ) const; | |
// FlexContainer members | ||
Result | Add(FlexComponent *child); | |
Result | Add(FlexComponent *child, uint32 position); | |
Result | Add(LayoutTagType tag, FlexComponent *child); | |
Result | AddContainerListener(ContainerListenerInterface& listener); | |
uint32 | FindFlexComponent(FlexComponent *child); | |
FlexComponent * | GetFlexComponent(uint32 position); | |
FlexComponent * | GetFlexComponent(uint32 position, LayoutTagType& tag); | |
uint32 | GetFlexComponentCount(void); | |
FlexComponent** | GetFlexComponents(void); | |
FocusManagerInterface * | GetFocusManager(void); | |
LayoutManagerInterface * | GetLayout(void); | |
LayoutTagType | GetLayoutTag(uint32 position); | |
Insets | GetInsets(void); | |
Result | GetRelativeBounds(FlexComponent *descendant, WinRectangle &bounds); | |
Result | GetRelativeLocation(FlexComponent *descendant, WinXYPoint point, WinXYPoint &location); | |
Boolean | IsAncestorOf(FlexComponent *child); | |
FlexComponent * | Remove(FlexComponent *child); | |
FlexComponent * | Remove(uint32 position); | |
void | RemoveAll(void); | |
void | RemoveContainerListener(ContainerListenerInterface& listener); | |
FocusManagerInterface * | RemoveFocusManager(void); | |
LayoutManagerInterface * | RemoveLayout(void); | |
void | SetFocusManager(FocusManagerInterface *focusManager); | |
void | SetLayout(LayoutManagerInterface *layoutManager); | |
void | SetLayoutTag(LayoutTagType tag, uint32 position); | |
// Event processing methods | ||
void | ProcessContainerEvent(ContainerEvent& containerEvent); | |
protected: | ||
EC (static void EnsureInAppThread(void)); |
Class constructor - the default constructor sets the state to AS_UNLOADED. There is no associated WindowManager (so many of the functions like SetFocus() will not work) until after Init() is invoked.
Prototype:
AppBase();
Class destructor.
Prototype:
~AppBase();
AppState is an enumerated type that describes the current state of the application.
Declared as:
enum AppState { AS_UNLOADED, AS_BACKGROUND, AS_CACHED, AS_ACTIVE, AS_EXITING };
Result AddFocusChangeListener(FocusChangeListenerInterface& listener);
Called to register a listener that is notified whenever the focus changes under this application.
Parameters:
See also: RemoveFocusChangeListener(), SetFocus(), GetFocus()
Prototype:
Result AddFocusChangeListener(FocusChangeListenerInterface& listener);
Result AddInkListener(InkListenerInterface& listener);
AddInkListener is called to register objects to be notified when the user begins drawing ink. For example, menus tend to close themselves when either a mouse event or ink drawing begins, so open menus often override this member function.
Parameters:
See also: RemoveInkListener()
Prototype:
Result AddInkListener(InkListenerInterface& listener);
Result AddTargetChangeListener(TargetChangeListenerInterface& listener);
AddTargetChangeListener is called to register a listener that is notified whenever the target changes under this application.
Parameters:
See also: RemoveTargetChangeListener(), SetTarget(), GetTarget()
Prototype:
Result AddTargetChangeListener(TargetChangeListenerInterface& listener);
Result AddWindowListener(WindowListenerInterface& listener);
AddWindowListener is called to register a listener to receive window events for this application (WINDOW_CLOSED, WINDOW_OPENED, WINDOW_TO_FRONT, WINDOW_TO_BACK).
Note that AppBase is not really a subclass of FlexWindow(), so the source field for these WindowEvent objects will be NULL. Listeners can always get a pointer to the AppBase by invoking AppBase::GetAppBase().
Parameters:
See also: RemoveWindowListener()
Prototype:
Result AddWindowListener(WindowListenerInterface& listener);
Exit() is invoked by the ApplicationCache when an application is being unloaded, to give the application an opportunity to destroy the UI built via SetAppContext() and, generally, to clean up and prepare for unloading. The default handler for Exit() frees up all the children of the AppBase object, and sets a flag so the application will exit the next time the thread goes idle.
Exit() can be overridden to provide app-specific behavior (such as freeing EventListeners and LayoutManagers, and other associated non-UI objects), but the baseclass handler should always be invoked, otherwise the app will remain loaded.
An application can also override this function and return without calling the base class, and in that case the application will not exit. This is useful when writing an application that should always be resident - applications that only wish to temporarily prevent unloading should invoke ApplicationCache::PreventUnloading().
Applications can also invoke Exit() on their own AppBase object, to force the application to unload - this is typically useful if an error occurs while starting up the app.
See also: SetAppContext()
Prototype:
virtual void Exit(void);
Sets an internal flag so that all input messages that are currently on the application thread's MessageQueue will be ignored. Input messages that arrive *after* FlushInput() is called will be processed normally.
Return value: SUCCESS if input is being flushed, else FAILURE if input could not be flushed due to lack of memory.
Prototype:
static Result FlushInput(void);
GetAppBase returns a pointer to the appbase for the current thread, or NULL if there is no appbase for this thread
Return value: Pointer to an AppBase object, or NULL.
See also: Thread::GetAppBase()
Prototype:
static AppBase *GetAppBase(void);
Returns a pointer to a context string that describes the current state of an app. When the app is reloaded and brought to the foreground, this string is passed to the SetAppContext() handler. The idea is that if the app is unloaded and reloaded, given the context string it should be able to return to the same state from the user's perspective.
Return value: A pointer to a string describing the current context. This is freed by the caller if non-NULL. If the application always displays the same UI (like an About box or a system status box), then this need not be subclassed -- the default handler returns NULL.
See also: SetAppContext()
Prototype:
virtual TCHAR *GetAppContext(void);
uint32 GetDesiredStackSize(void) const;
Invoked when an application is being loaded. It is overridden by the application if it wants a non-standard stack size (a very simple application may want a smaller stack than normal, while a very complex application may need a deeper stack).
Return value: Stack size in bytes
See also: Thread::Start()
Prototype:
virtual uint32 GetDesiredStackSize(void) const;
FlexComponent *GetFocus(void);
Called to find out which object currently has the focus.
The "focus" is the object that will receive all incoming keyboard input.
Return value: The object that has the focus.
See also: SetFocus()
Prototype:
static FlexComponent *GetFocus(void);
AppState GetState(void) const;
Returns the current state of the application.
Return value: AppState (the state of the application).
See also: SetState(), AppState
Prototype:
AppState GetState(void) const;
Thread *GetThread(void) const;
Returns a pointer to the thread associated with this application (the thread that is dispatching events from the MessageQueue associated with this application).
Return value: Pointer to the thread associated with this application.
See also: GetMessageQueue()
Prototype:
Thread *GetThread(void) const;
FlexComponent *GetTarget(void);
Called to find out which object currently has the target. The default is NULL, and this routine will return NULL unless a target is explicitly set via SetTarget().
The target is used on devices that support clipboards - the target is the object that will receive cut/copy/paste requests.
Return value: The object that has the target.
See also: SetTarget()
Prototype:
static FlexComponent *GetTarget(void);
const TCHAR *GetUAL(void) const;
Returns a pointer to the UAL for this application. This is a string that uniquely identifies this application and can be passed to various ApplicationCache API to switch to/from this application.
Return value: Pointer to the UAL string for this application. The pointer is guaranteed to be valid for the life of this application.
Prototype:
const TCHAR *GetUAL(void) const;
Boolean HandleUndispatchedMessage(Message *msg);
Invoked by the message dispatch loop when a message is retrieved from the app's MessageQueue, but the message type was unknown to the default handler. This can be overridden to provide handling of custom message types, in the same way that MessageQueue::DispatchMessage() is overridden.
Parameters:
See also: MessageQueue::DispatchMessage()
Prototype:
virtual Boolean HandleUndispatchedMessage(Message *msg);
Invoked when the application is idle (there are no more messages in the message queue).
Applications can override this to perform operations at idle time (such as updating status bars).
Prototype:
virtual void Idle(void);
Invoked by the ApplicationCache when another application has been brought to the foreground (made this one inactive). This can be subclassed by applications if they are interested in tracking when they are the active app, with the caveat that Lower() is not invoked synchronously with another app becoming active.
See also: Raise()
Prototype:
virtual void Lower(void);
void ProcessFocusChangeEvent(FocusChangeEvent& e);
ProcessFocusChangeEvent is called to dispatch a FocusChangeEvent to any registered listeners when the focus changes.
This is not invoked synchronously with the call to SetFocus, as giving an object the focus (such as a window) may then cause another object to get the focus immediately thereafter. To avoid a flood of spurious updates, we enqueue a message and notify the listeners after the set focus calls have returned.
Parameters:
Prototype:
virtual void ProcessFocusChangeEvent(FocusChangeEvent& e);
void ProcessInkEvent(InkEvent& e);
ProcessInkEvent() is invoked by the AppBase when the user begins and finishes drawing ink under an application.
Parameters:
Prototype:
virtual void ProcessInkEvent(InkEvent& e);
void ProcessTargetChangeEvent(TargetChangeEvent& e);
Called to dispatch a TargetChangeEvent to any registered listeners when the focus changes.
This is not invoked synchronously with the call to SetTarget, as giving an object the focus (such as a window) may then cause another object to get the focus immediately thereafter. To avoid a flood of spurious updates, we enqueue a message and notify the listeners after the set focus calls have returned.
Parameters:
Prototype:
virtual void ProcessTargetChangeEvent(TargetChangeEvent& e);
void ProcessWindowEvent(WindowEvent &e);
Invoked to generate window events to notify the application (and any listeners) when the appbase object has become active, closed, etc.
Parameters:
Prototype:
virtual void ProcessWindowEvent(WindowEvent &e);
Invoked by the ApplicationCache when this application has come to the foreground. This can be subclassed by applications if they are interested in tracking when they are the active app, with the caveat that Raise() and Lower() are not invoked synchronously with another app becoming active/inactive.
See also: Lower()
Prototype:
virtual void Raise(void);
void RemoveFocusChangeListener(FocusChangeListenerInterface& listener);
Called to unregister a listener that was registered using AddFocusChangeListener().
Parameters:
Prototype:
void RemoveFocusChangeListener(FocusChangeListenerInterface& listener);
void RemoveInkListener(InkListenerInterface& listener);
Called to unregister objects that were previously registered to receive InkEvents via AddInkListener().
Parameters:
Prototype:
void RemoveInkListener(InkListenerInterface& listener);
void RemoveTargetChangeListener(TargetChangeListenerInterface& listener);
Called to unregister a listener that was registered using AddTargetChangeListener().
Parameters:
Prototype:
void RemoveTargetChangeListener(TargetChangeListenerInterface& listener);
void RemoveWindowListener(WindowListenerInterface& listener);
Called to unregister a listener that was previously registered via AddWindowListener().
Parameters:
Prototype:
void RemoveWindowListener(WindowListenerInterface& listener);
void SetAppContext(const TCHAR *context) ;
Used to restore an application to a certain state. It could also potentially be used to execute tasks in other applications (such as look up an entry in the address book application). If the application always displays the same UI, the passed context may be ignored.
Here's a basic summary of when SetAppContext() will be invoked:
2) If your app was loaded via AppliationCache::SwitchTo(), SetAppContext() is invoked with the last saved context. Subsequent calls to SwitchTo() will not cause new SetAppContext() calls.
3) If your app was loaded via ApplicationCache::Goto(), the string passed to Goto() is passed to your app. Every call to Goto() will result in a new SetAppContext() invocation on your app. In addition, if your app is *loaded* via Goto() (as opposed to having Goto() invoked on it while it is already running), the first time it is brought to the foreground via ApplicationCache::SwitchTo(), it will get another SetAppContext() call as described in case #2.
4) Once an app has processed an Exit() call by allowing the base AppBase::Exit() to execute, it is treated as being unloaded, so the next SwitchTo() call will cause a new SetAppContext() invocation.
AppBase::Exit() will free up any FlexComponent objects that are children of the AppBase object. Any other dynamically created objects that are not children of the AppBase object (such as LayoutManagers, or UI objects that are not added to the AppBase linkage) must be manually freed by the application itself in its Exit() handler.
Parameters:
Prototype:
virtual void SetAppContext(const TCHAR *context) = 0;
FlexComponent *SetFocus(FlexComponent *focusObj);
Called to give a UI object the focus, which means that the object will now receive all keyboard events received by this application. This is generally called by the UI as a result of a new window being brought to the foreground, or due to the user clicking on a new object, but this can also be called by applications.
FlexComponent::ProcessFocusEvent() is invoked on both the new and old focused objects, to notify them that they have gained or lost the focus. If the new object is not focusable for some reason (perhaps because there is a modal dialog on screen or because the object itself is not focusable) then this call is ignored.
Parameters:
See also: GetFocus(), AddFocusChangeListener()
Prototype:
static FlexComponent *SetFocus(FlexComponent *focusObj);
void SetState(AppState state);
Sets the current AppState, which can be fetched via GetState(). Setting the AppState incorrectly can cause strange application behavior (premature exiting, extra invocations of SetAppContext(), etc.), so SetState() is typically not invoked by applications.
Parameters:
Prototype:
void SetState(AppState state);
FlexComponent *SetTarget(FlexComponent *targetObj);
Called to give a FlexComponent the target. This causes any global clipboard menus to operate on this object. Typically, applications give the target to their "main" document object.
If you have called SetTarget() to give the target to a FlexComponent, you must give the target to some other component (or set it to NULL) before freeing your FlexComponent.
Parameters:
See also: GetTarget(), AddTargetChangeListener()
Prototype:
static FlexComponent *SetTarget(FlexComponent *targetObj);
Called to update the image of the application's UI on the hardware display. Typically, all drawing operations happen to off-screen bitmaps, and these bitmaps are displayed on the hardware only when the application goes idle. Applications that want to update the hardware display immediately can call this function.
Note that the application will not update the screen until the geometry is valid. Applications may need to invoke AppBase::Validate() before calling this routine if they have performed operations (such as adding, removing, and resizing FlexComponent objects) that require a geometry update.
Return value: FAILURE if the display could not be updated for some reason (lack of RAM, app not visible, geometry not valid).
Prototype:
static Result UpdateDisplay(void);