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