Application.h revision 0690387c
1/*
2 * Copyright 2001-2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _APPLICATION_H
6#define _APPLICATION_H
7
8
9#include <AppDefs.h>
10#include <InterfaceDefs.h>
11#include <Looper.h>
12#include <Messenger.h>
13#include <Point.h>
14#include <Rect.h>
15
16
17class BCursor;
18class BList;
19class BLocker;
20class BMessageRunner;
21class BResources;
22class BServer;
23class BWindow;
24
25struct app_info;
26
27
28namespace BPrivate {
29	class PortLink;
30	class ServerMemoryAllocator;
31}
32
33
34class BApplication : public BLooper {
35public:
36								BApplication(const char* signature);
37								BApplication(const char* signature,
38									status_t* error);
39	virtual						~BApplication();
40
41	// Archiving
42								BApplication(BMessage* data);
43	static	BArchivable*		Instantiate(BMessage* data);
44	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
45
46			status_t			InitCheck() const;
47
48	// App control and System Message handling
49	virtual	thread_id			Run();
50	virtual	void				Quit();
51	virtual bool				QuitRequested();
52	virtual	void				Pulse();
53	virtual	void				ReadyToRun();
54	virtual	void				MessageReceived(BMessage* message);
55	virtual	void				ArgvReceived(int32 argc, char** argv);
56	virtual	void				AppActivated(bool active);
57	virtual	void				RefsReceived(BMessage* message);
58	virtual	void				AboutRequested();
59
60	// Scripting
61	virtual BHandler*			ResolveSpecifier(BMessage* message, int32 index,
62									BMessage* specifier, int32 form,
63									const char* property);
64
65	// Cursor control, window/looper list, and app info
66			void				ShowCursor();
67			void				HideCursor();
68			void				ObscureCursor();
69			bool				IsCursorHidden() const;
70			void				SetCursor(const void* cursor);
71			void				SetCursor(const BCursor* cursor,
72									bool sync = true);
73
74			int32				CountWindows() const;
75			BWindow*			WindowAt(int32 index) const;
76
77			int32				CountLoopers() const;
78			BLooper*			LooperAt(int32 index) const;
79			bool				IsLaunching() const;
80			const char*			Signature() const;
81			status_t			GetAppInfo(app_info* info) const;
82	static	BResources*			AppResources();
83
84	virtual	void				DispatchMessage(BMessage* message,
85									BHandler* handler);
86			void				SetPulseRate(bigtime_t rate);
87
88	// More scripting
89	virtual status_t			GetSupportedSuites(BMessage* data);
90
91
92	// Private or reserved
93	virtual status_t			Perform(perform_code d, void* arg);
94
95	class Private;
96
97private:
98	typedef BLooper _inherited;
99
100	friend class Private;
101	friend class BServer;
102
103								BApplication(const char* signature,
104									const char* looperName,
105									bool initGUI, status_t* error);
106								BApplication(uint32 signature);
107								BApplication(const BApplication&);
108			BApplication&		operator=(const BApplication&);
109
110	virtual	void				_ReservedApplication1();
111	virtual	void				_ReservedApplication2();
112	virtual	void				_ReservedApplication3();
113	virtual	void				_ReservedApplication4();
114	virtual	void				_ReservedApplication5();
115	virtual	void				_ReservedApplication6();
116	virtual	void				_ReservedApplication7();
117	virtual	void				_ReservedApplication8();
118
119	virtual	bool				ScriptReceived(BMessage* msg, int32 index,
120									BMessage* specifier, int32 form,
121									const char* property);
122			void				_InitData(const char* signature, bool initGUI,
123									status_t* error);
124			void				BeginRectTracking(BRect r, bool trackWhole);
125			void				EndRectTracking();
126			status_t			_SetupServerAllocator();
127			status_t			_InitGUIContext();
128			status_t			_ConnectToServer();
129			void				_ReconnectToServer();
130			bool				_QuitAllWindows(bool force);
131			bool				_WindowQuitLoop(bool quitFilePanels,
132									bool force);
133			void				_ArgvReceived(BMessage* message);
134
135			uint32				InitialWorkspace();
136			int32				_CountWindows(bool includeMenus) const;
137			BWindow*			_WindowAt(uint32 index,
138									bool includeMenus) const;
139
140	static	void				_InitAppResources();
141
142private:
143	static	BResources*			sAppResources;
144
145			const char*			fAppName;
146			::BPrivate::PortLink*	fServerLink;
147			::BPrivate::ServerMemoryAllocator* fServerAllocator;
148
149			void*				fCursorData;
150			bigtime_t			fPulseRate;
151			uint32				fInitialWorkspace;
152			BMessageRunner*		fPulseRunner;
153			status_t			fInitError;
154			void*				fServerReadOnlyMemory;
155			uint32				_reserved[12];
156
157			bool				fReadyToRunCalled;
158};
159
160
161// Global Objects
162
163extern BApplication* be_app;
164extern BMessenger be_app_messenger;
165
166
167#endif	// _APPLICATION_H
168