xref: /haiku/headers/os/app/Application.h (revision 84cc2b9655c438c28cd0073991f41684d41d1fe8)
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 
17 class BCursor;
18 class BList;
19 class BLocker;
20 class BMessageRunner;
21 class BResources;
22 class BServer;
23 class BWindow;
24 
25 struct app_info;
26 
27 
28 namespace BPrivate {
29 	class PortLink;
30 	class ServerMemoryAllocator;
31 }
32 
33 
34 class BApplication : public BLooper {
35 public:
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 	// Register a BLooper to be quit before the BApplication
89 	// object is destroyed.
90 			status_t			RegisterLooper(BLooper* looper);
91 			status_t			UnregisterLooper(BLooper* looper);
92 
93 	// More scripting
94 	virtual status_t			GetSupportedSuites(BMessage* data);
95 
96 
97 	// Private or reserved
98 	virtual status_t			Perform(perform_code d, void* arg);
99 
100 	class Private;
101 
102 private:
103 	typedef BLooper _inherited;
104 
105 	friend class Private;
106 	friend class BServer;
107 
108 								BApplication(const char* signature,
109 									const char* looperName, port_id port,
110 									bool initGUI, status_t* error);
111 								BApplication(uint32 signature);
112 								BApplication(const BApplication&);
113 			BApplication&		operator=(const BApplication&);
114 
115 	virtual	void				_ReservedApplication1();
116 	virtual	void				_ReservedApplication2();
117 	virtual	void				_ReservedApplication3();
118 	virtual	void				_ReservedApplication4();
119 	virtual	void				_ReservedApplication5();
120 	virtual	void				_ReservedApplication6();
121 	virtual	void				_ReservedApplication7();
122 	virtual	void				_ReservedApplication8();
123 
124 	virtual	bool				ScriptReceived(BMessage* msg, int32 index,
125 									BMessage* specifier, int32 form,
126 									const char* property);
127 			void				_InitData(const char* signature, bool initGUI,
128 									status_t* error);
129 			port_id				_GetPort(const char* signature);
130 			void				BeginRectTracking(BRect r, bool trackWhole);
131 			void				EndRectTracking();
132 			status_t			_SetupServerAllocator();
133 			status_t			_InitGUIContext();
134 			status_t			_ConnectToServer();
135 			void				_ReconnectToServer();
136 			bool				_QuitAllWindows(bool force);
137 			bool				_WindowQuitLoop(bool quitFilePanels,
138 									bool force);
139 			void				_ArgvReceived(BMessage* message);
140 
141 			uint32				InitialWorkspace();
142 			int32				_CountWindows(bool includeMenus) const;
143 			BWindow*			_WindowAt(uint32 index,
144 									bool includeMenus) const;
145 
146 	static	void				_InitAppResources();
147 
148 private:
149 	static	BResources*			sAppResources;
150 
151 			const char*			fAppName;
152 			::BPrivate::PortLink*	fServerLink;
153 			::BPrivate::ServerMemoryAllocator* fServerAllocator;
154 
155 			void*				fCursorData;
156 			bigtime_t			fPulseRate;
157 			uint32				fInitialWorkspace;
158 			BMessageRunner*		fPulseRunner;
159 			status_t			fInitError;
160 			void*				fServerReadOnlyMemory;
161 			uint32				_reserved[12];
162 
163 			bool				fReadyToRunCalled;
164 };
165 
166 
167 // Global Objects
168 
169 extern BApplication* be_app;
170 extern BMessenger be_app_messenger;
171 
172 
173 #endif	// _APPLICATION_H
174