A container object for an application. More...
Inherits BLooper.
Public Member Functions | |
BApplication (const char *signature) | |
Initialize a BApplication with the passed in signature. | |
BApplication (const char *signature, status_t *error) | |
Initialize a BApplication with the passed in signature and a pointer to an error message. | |
virtual | ~BApplication () |
Destructor Method. | |
status_t | InitCheck () const |
Returns the status of the constructor. | |
virtual status_t | Perform (perform_code d, void *arg) |
Internal method. | |
Message Loop Control | |
virtual thread_id | Run () |
Starts the message loop in the thread that it is called from, and doesn't return until the message loop stops. | |
virtual void | Quit () |
Tells the thread to finish processing the message queue, disallowing any new messages. | |
Hook Methods | |
virtual bool | QuitRequested () |
Hook method that gets invoked when the BApplication receives a B_QUIT_REQUESTED message. | |
virtual void | ReadyToRun () |
Hook method that's invoked when the BApplication receives a B_READY_TO_RUN message. | |
virtual void | ArgvReceived (int32 argc, char **argv) |
Hook method that gets invoked when the application receives a B_ARGV_RECEIVED message. | |
virtual void | AppActivated (bool active) |
Hook method that gets invoked when the application receives B_APP_ACTIVATED message. | |
virtual void | RefsReceived (BMessage *message) |
Hook method that gets invoked when the application receives a B_REFS_RECEIVED message. | |
virtual void | AboutRequested () |
Hook method that gets invoked when the BApplication receives a B_ABOUT_REQUESTED message. | |
Pulse | |
virtual void | Pulse () |
Hook method that gets invoked when the BApplication receives a B_PULSE message. | |
void | SetPulseRate (bigtime_t rate) |
Sets the interval that the B_PULSE messages are sent. | |
Message Mechanics | |
virtual void | MessageReceived (BMessage *message) |
virtual void | DispatchMessage (BMessage *message, BHandler *handler) |
Scripting | |
virtual BHandler * | ResolveSpecifier (BMessage *message, int32 index, BMessage *specifier, int32 form, const char *property) |
virtual status_t | GetSupportedSuites (BMessage *data) |
Cursor | |
void | ShowCursor () |
Restores the cursor. | |
void | HideCursor () |
Hides the cursor from the screen. | |
void | ObscureCursor () |
Hides the cursor until the mouse is moved. | |
bool | IsCursorHidden () const |
Returns whether or not the cursor is hidden. | |
void | SetCursor (const void *cursor) |
Sets the cursor to be used when the application is active. | |
void | SetCursor (const BCursor *cursor, bool sync=true) |
Sets the cursor to be used when the application is active with sync immediately option. | |
Info | |
int32 | CountWindows () const |
Returns the number of windows created by the application. | |
BWindow * | WindowAt (int32 index) const |
Returns the BWindow object at the specified index in the application's window list. | |
int32 | CountLoopers () const |
Returns the number of BLoopers created by the application. | |
BLooper * | LooperAt (int32 index) const |
Returns the BLooper object at the specified index in the application's looper list. | |
Lifecycle Management | |
status_t | RegisterLooper (BLooper *looper) |
Register a looper to quit when the application quits. | |
status_t | UnregisterLooper (BLooper *looper) |
Remove a previously registered Looper from the quit-list. | |
Public Member Functions inherited from BLooper | |
BLooper (const char *name=NULL, int32 priority=B_NORMAL_PRIORITY, int32 portCapacity=B_LOOPER_PORT_DEFAULT_CAPACITY) | |
Construct a new BLooper with a priority and an capacity. | |
virtual | ~BLooper () |
Destruct the looper. | |
virtual status_t | Perform (perform_code d, void *arg) |
Internal method. | |
status_t | PostMessage (uint32 command) |
Post a message with the command as what identifier to this looper. | |
status_t | PostMessage (BMessage *message) |
Post a message to this looper. | |
status_t | PostMessage (uint32 command, BHandler *handler, BHandler *replyTo=NULL) |
Sends a message with command what identifier to the handler associated with this looper. A response may be sent to the replyTo handler asynchronously. | |
status_t | PostMessage (BMessage *message, BHandler *handler, BHandler *replyTo=NULL) |
Send a message to the handler associated with this looper. A response may be sent to the replyTo handler asynchronously. | |
BMessage * | CurrentMessage () const |
Retrieve the current message. | |
BMessage * | DetachCurrentMessage () |
Get ownership of the message currently being processed. | |
void | DispatchExternalMessage (BMessage *message, BHandler *handler, bool &_detached) |
Internal method to support single-threaded GUI toolkits. | |
BMessageQueue * | MessageQueue () const |
Get a pointer to the internal message queue of this looper. | |
bool | IsMessageWaiting () const |
Check if there is a message waiting. | |
void | AddHandler (BHandler *handler) |
Associate a handler to this looper. | |
bool | RemoveHandler (BHandler *handler) |
Disassociate a handler from this looper. | |
int32 | CountHandlers () const |
Get the number of handlers associated with this looper. | |
BHandler * | HandlerAt (int32 index) const |
Get the handler at an index of the list of associated handlers. | |
int32 | IndexOf (BHandler *handler) const |
Get the index of the handler that is in the associated handler list. | |
BHandler * | PreferredHandler () const |
Get the preferred handler. | |
void | SetPreferredHandler (BHandler *handler) |
Set a preferred handler. | |
thread_id | LockingThread () const |
Return the thread id of the thread that currently holds the lock. | |
int32 | CountLocks () const |
Return the number of recursive locks that are currently being held on this looper. | |
int32 | CountLockRequests () const |
Return the number of pending locks. | |
sem_id | Sem () const |
Return the id of the semaphore that is used to lock this looper. | |
virtual void | AddCommonFilter (BMessageFilter *filter) |
Add a common filter to the list of filters that are applied to all incoming messages. | |
virtual bool | RemoveCommonFilter (BMessageFilter *filter) |
Remove a filter from the common message filter list. | |
virtual void | SetCommonFilterList (BList *filters) |
Set a new list of filters that need to be applied to all incoming messages. | |
BList * | CommonFilterList () const |
Return a list of filters applied to all incoming messages. | |
BLooper (BMessage *data) | |
Construct a looper from an archived message. | |
void | Loop () |
Run the event loop in the current thread. | |
bool | Lock () |
Lock the looper. | |
void | Unlock () |
Unlock a locked looper. | |
bool | IsLocked () const |
Check if a looper is locked. | |
status_t | LockWithTimeout (bigtime_t timeout) |
Lock a looper with a timeout. | |
thread_id | Thread () const |
Return the thread id of the internal message looper thread. | |
team_id | Team () const |
Return the team id in which this looper exists. | |
Public Member Functions inherited from BHandler | |
BHandler (const char *name=NULL) | |
Construct a new handler with a name. | |
virtual | ~BHandler () |
Free the filters of this handler, as well as the list of observers. | |
virtual status_t | Perform (perform_code d, void *arg) |
Perform some action (Internal method defined for binary compatibility purposes). | |
BHandler (BMessage *data) | |
Construct a handler from an archived message. | |
BLooper * | Looper () const |
Return a pointer to the looper that this handler is associated with. | |
void | SetName (const char *name) |
Set or change the name of this handler. | |
const char * | Name () const |
Return the name of this handler. | |
virtual void | SetNextHandler (BHandler *handler) |
Set the next handler in the chain that the message is passed on to if this handler cannot process it. | |
BHandler * | NextHandler () const |
Return the next hander in the chain to which the message is passed on. | |
virtual void | AddFilter (BMessageFilter *filter) |
Add filter as a prerequisite to this handler. | |
virtual bool | RemoveFilter (BMessageFilter *filter) |
Remove filter from the filter list. | |
virtual void | SetFilterList (BList *filters) |
Set the internal list of filters to filters. | |
BList * | FilterList () |
Return a pointer to the list of filters. | |
bool | LockLooper () |
Lock the looper associated with this handler. | |
status_t | LockLooperWithTimeout (bigtime_t timeout) |
Lock the looper associated with this handler, with a time out value. | |
void | UnlockLooper () |
Unlock the looper. | |
status_t | StartWatching (BMessenger target, uint32 what) |
Subscribe this handler to watch a specific state change of a target. | |
status_t | StartWatchingAll (BMessenger target) |
Subscribe this handler to watch a target for all events. | |
status_t | StopWatching (BMessenger target, uint32 what) |
Unsubscribe this handler from watching a specific state. | |
status_t | StopWatchingAll (BMessenger target) |
Unsubscribe this handler from watching all states. | |
status_t | StartWatching (BHandler *observer, uint32 what) |
Subscribe an observer for a specific state change of this handler. | |
status_t | StartWatchingAll (BHandler *observer) |
Subscribe an observer for a all state changes. | |
status_t | StopWatching (BHandler *observer, uint32 what) |
Unsubscribe an observer from watching a specific state. | |
status_t | StopWatchingAll (BHandler *observer) |
Unsubscribe an observer from watching all states. | |
virtual void | SendNotices (uint32 what, const BMessage *notice=NULL) |
Emit a state change to the observers. | |
bool | IsWatched () const |
Check if there are any observers watching this handler. | |
Public Member Functions inherited from BArchivable | |
BArchivable () | |
Constructor. Does nothing. | |
BArchivable (BMessage *from) | |
Constructor. Does important behind-the-scenes work in the unarchiving process. | |
virtual | ~BArchivable () |
Destructor. Does nothing. | |
virtual status_t | AllArchived (BMessage *archive) const |
Method relating to the use of BArchiver . | |
virtual status_t | AllUnarchived (const BMessage *archive) |
Method relating to the use of BUnarchiver . | |
virtual status_t | Archive (BMessage *into, bool deep=true) const |
Archive the object into a BMessage. | |
virtual status_t | Perform (perform_code d, void *arg) |
Perform some action (Internal method defined for binary compatibility purposes). | |
Archiving | |
BApplication (BMessage *data) | |
Initialize a BApplication object from a message. | |
virtual status_t | Archive (BMessage *data, bool deep=true) const |
Archive the BApplication object into a BMessage. | |
static BArchivable * | Instantiate (BMessage *data) |
Restores the BApplication object from a BMessage. | |
Status | |
bool | IsLaunching () const |
Returns whether or not the application is in the process of launching. | |
const char * | Signature () const |
Returns the signature of the Application. | |
status_t | GetAppInfo (app_info *info) const |
Fills out the info parameter with information about the application. | |
static BResources * | AppResources () |
Returns a BResources object for the application. | |
Additional Inherited Members | |
Static Public Member Functions inherited from BLooper | |
static BArchivable * | Instantiate (BMessage *data) |
Static method to instantiate a looper from an archived message. | |
static BLooper * | LooperForThread (thread_id thread) |
Static method to retrieve a BLooper for a specified thread. | |
Static Public Member Functions inherited from BHandler | |
static BArchivable * | Instantiate (BMessage *data) |
Static method to instantiate a handler from an archived message. | |
Static Public Member Functions inherited from BArchivable | |
static BArchivable * | Instantiate (BMessage *archive) |
Static member to restore objects from messages. | |
Protected Member Functions inherited from BLooper | |
BMessage * | MessageFromPort (bigtime_t=B_INFINITE_TIMEOUT) |
Hook method to retrieve a message from the looper's port. | |
A container object for an application.
A BApplication establishes a connection between the application and the Application Server.
The most common task performed by a BApplication object is to handle messages sent to it. The BApplication object also is used to get information about your application such as the number of windows it has, its signature, executable location, and launch flags.
The BApplication object is automatically assigned to the global be_app
variable. The be_app
variable allows you to refer to your BApplication object from anywhere in the code.
To use a BApplication you first construct the object and then begin its message loop by calling the Run() method. The Run() method continues until the application is told to quit. Once Run() returns you should then delete the BApplication object to free its memory usage.
Typically, you initialize the BApplication object in the programs main() function. A typical main() function looks something like this:
BApplication::BApplication | ( | const char * | signature | ) |
Initialize a BApplication with the passed in signature.
The new BApplication is, by default, not running yet. If you have everything set up properly call Run() to start the application.
You should call InitCheck() to check for constructor initialization errors.
signature | The signature of the application. |
BApplication::BApplication | ( | const char * | signature, |
status_t * | _error | ||
) |
Initialize a BApplication with the passed in signature and a pointer to an error message.
Any error that occurs while constructing the BApplication will be set to the _error pointer. If _error points to a status_t
error then you should not call Run().
Alternately, you can call InitCheck() to check for constructor initialization errors.
signature | The signature of the application. |
_error | A pointer to a status_t set by the BApplication constructor. |
|
virtual |
Destructor Method.
BApplication::BApplication | ( | BMessage * | data | ) |
Initialize a BApplication object from a message.
The message must contain the signature of the application you wish to initialize in the "mime_sig" variable.
data | The message to initialize the BApplication from. |
|
virtual |
Hook method that gets invoked when the BApplication receives a B_ABOUT_REQUESTED
message.
You should override this method to pop an alert to provide information about the application.
The default implementation pops a basic alert dialog.
|
virtual |
Hook method that gets invoked when the application receives B_APP_ACTIVATED
message.
The message is sent whenever the application changes its active application status. The active flag set to is true
when the application becomes active and is set to false
when the application becomes inactive.
The application becomes activated in response to a user action such as clicking on or unhiding one of its windows. The application can have its active status set programmatically by calling either the BWindow::Activate() or BRoster::ActivateApp() methods.
This method is called after ReadyToRun() provided the application is displaying a window that can be set active.
|
static |
Returns a BResources object for the application.
Archive the BApplication object into a BMessage.
Reimplemented from BLooper.
|
virtual |
Hook method that gets invoked when the application receives a B_ARGV_RECEIVED
message.
If command line arguments are specified when the application is launched from the the shell, or if argv/argc
values are passed to BRoster::Launch(), then this method is executed.
argv/argc
values.The arguments passed to ArgvReceived() are the constructed in the same way as those passed to command line programs. The number of command line arguments is passed in argc and the arguments themselves are passed as an array of strings in argv. The first argv string is the name of the program and the rest of the strings are the command line arguments.
BRoster::Launch() adds the program name to the front of the argv array and increments the argc value.
The B_ARGV_RECEIVED
message (if sent) is sent only once, just before the B_READY_TO_RUN
message is sent. However, if you try to relaunch an application that is already running and the application is set to B_EXCLUSIVE_LAUNCH
or B_SINGLE_LAUNCH
then the application will generate a B_ARGV_RECEIVED
message and send it to the already running instance. Thus in this case the B_ARGV_RECEIVED
message can show up at any time.
int32 BApplication::CountLoopers | ( | ) | const |
Returns the number of BLoopers created by the application.
B_ERROR
.int32 BApplication::CountWindows | ( | ) | const |
Returns the number of windows created by the application.
Dispatch a message to a handler. Override if there are messages that you want to catch before they are sent to the handlers.
This method is called by the message looping thread to dispatch a message to handler. If you implement the BLooper class and your looper receives messages that absolutely have to be processed by the looper instead of any of the handlers, override this method. For example, the default implementation catches B_QUIT_REQUESTED messages before they are sent to the handlers, so that the looper will quit at those messages.
You are discouraged from using this method to filter out any messages you do not want to process. For this, there is a more generic method using the BMessageFilter class. If you want to skip messages with certain patterns, have a look at the AddCommonFilter() and SetCommonFilterList() methods.
If you do override this method, please remember to call the DispatchMessage() method of the parent class.
Reimplemented from BLooper.
Fills out the info parameter with information about the application.
This is equivalent to be_roster->GetRunningAppInfo(be_app->Team(), info);
B_NO_INIT
on an error or B_OK
if all goes well.Reports the suites of messages and specifiers that derived classes understand.
Reimplemented from BLooper.
void BApplication::HideCursor | ( | ) |
Hides the cursor from the screen.
status_t BApplication::InitCheck | ( | ) | const |
Returns the status of the constructor.
B_OK
, otherwise returns an error status.
|
static |
bool BApplication::IsCursorHidden | ( | ) | const |
Returns whether or not the cursor is hidden.
true
if the cursor is hidden, false
if not.bool BApplication::IsLaunching | ( | ) | const |
Returns whether or not the application is in the process of launching.
true
if the application is launching, false
if the application is already running.
|
virtual |
Handle message that has been received by the associated looper.
This method is reimplemented by subclasses. If the messages that have been received by a looper pass through the filters, then they end up in the MessageReceived() methods.
The example below shows a very common way to handle message. Usually, this involves parsing the BMessage::what constant and then perform an action based on that.
If your handler cannot process this message, you should pass it on to the base class. Eventually, it will reach the base implementation, which will reply with B_MESSAGE_NOT_UNDERSTOOD
.
message | The message that needs to be handled. |
Reimplemented from BLooper.
void BApplication::ObscureCursor | ( | ) |
Hides the cursor until the mouse is moved.
|
virtual |
|
virtual |
Hook method that gets invoked when the BApplication receives a B_PULSE
message.
An action is performed each time app_server calls the Pulse() method. The pulse rate is set by SetPulseRate(). You can implement Pulse() to do anything you want. The default version does nothing. The pulse granularity is no better than once per 100,000 microseconds.
|
virtual |
Tells the thread to finish processing the message queue, disallowing any new messages.
Quit() doesn't kill the looper thread. After Quit() returns, it doesn't wait for the message queue to empty. Run() will be then able to return.
Quit() doesn't delete the BApplication object after Run() is called. You should delete the BApplication object yourself one Run() returns. However Quit() does delete the object if it's called before the message loop starts i.e. before Run() is called.
Reimplemented from BLooper.
|
virtual |
Hook method that gets invoked when the BApplication receives a B_QUIT_REQUESTED
message.
BApplication sends a QuitRequested() message to each of its BWindow objects. If all of the BWindow s return true
then the windows are each destroyed (through BWindow::Quit()) and QuitRequested() returns true
. If any of the BWindow returns false
, the BWindow s are not destroyed and QuitRequested() returns false
.
true
if the application quit or false
if the application failed to quit.Reimplemented from BLooper.
|
virtual |
Hook method that's invoked when the BApplication receives a B_READY_TO_RUN
message.
The ReadyToRun() method is automatically called by the Run() method. It is sent after the initial B_REFS_RECEIVED
and B_ARGV_RECEIVED
messages (if any) have already been handled. ReadyToRun() is the only message that every running application is guaranteed to receive.
The default version of ReadyToRun() is empty. You should override the ReadyToRun() method to do whatever you want to do. If you haven't constructed any windows in your application yet then this would be a good place to do so.
|
virtual |
Hook method that gets invoked when the application receives a B_REFS_RECEIVED
message.
The message is sent in response to a user action such as a user drag-and-dropping a file on your app's icon or opening a file that the application is set to handle. You can use the IsLaunching() method to discern whether the message arrived when the application is launched or after the application has already been running.
The default implementation is empty. You can override this method to do something with the received refs. Typically you create BEntry or BFile objects from the passed in refs.
message | contains a single field named "be:refs" that contains one or more entry_ref (B_REF_TYPE ) items, one for each file sent. |
Register a looper to quit when the application quits.
There are situations where you create BLooper objects, that you may want to have BApplication quit properly, when the application is quitting. This method allows you to add Loopers under management of BApplication.
Note that Windows are automatically handled by BApplication, so there is no need to manually register BWindow-based loopers using this method.
B_OK
when the looper was registered without an issue, B_BAD_VALUE
when you try to register a BWindow, or B_ERROR
when the looper was already registered.
|
virtual |
Determine the proper handler for a scripting message.
message | The scripting message to determine the handler. |
index | The index of the specifier. |
specifier | The message which contains the specifier. |
what | The 'what' field of the specifier message. |
property | The name of the target property. |
Reimplemented from BLooper.
|
virtual |
Starts the message loop in the thread that it is called from, and doesn't return until the message loop stops.
Run() does not spawn a new thread.
Reimplemented from BLooper.
void BApplication::SetCursor | ( | const BCursor * | cursor, |
bool | sync = true |
||
) |
Sets the cursor to be used when the application is active with sync immediately option.
The default BCursors to use are B_CURSOR_SYSTEM_DEFAULT
for the hand cursor and B_CURSOR_I_BEAM
for the I-beam cursor.
cursor | A BCursor object to set the cursor to. |
sync | synchronize the cursor immediately. |
void BApplication::SetCursor | ( | const void * | cursor | ) |
Sets the cursor to be used when the application is active.
You can pass one of the pre-defined cursor constants such as B_HAND_CURSOR
or B_I_BEAM_CURSOR
or you can create your own pass in your own cursor image. The cursor data format is described in the BCursor class.
cursor | The cursor data to set the cursor to. |
void BApplication::SetPulseRate | ( | bigtime_t | rate | ) |
Sets the interval that the B_PULSE
messages are sent.
If the rate is set to 0 then the B_PULSE
messages are not sent. The pulse rate can be no faster than once per 100,000 microseconds or so.
rate | The rate at which B_PULSE messages are sent to the application. |
BApplication::ShowCursor | ( | ) |
Restores the cursor.
const char * BApplication::Signature | ( | ) | const |
Returns the signature of the Application.
Remove a previously registered Looper from the quit-list.
If a looper has been added to the quit list using BApplication::RegisterLooper, they can be unregistered using this method. You should do this in the case the looper quits before the application does.
Note that Windows are automatically handled by BApplication, so you don't have to use this function to unregister windows.
B_OK
when the looper has been removed, B_BAD_VALUE
when you try to unregister a BWindow, or B_ERROR
when the looper was not previously registered.Returns the BWindow object at the specified index in the application's window list.
If index is out of range, this function returns NULL
.
index | The index of the desired BWindow. |
NULL
if the index is out of range.