xref: /haiku/headers/os/app/Application.h (revision 6d2f2ec177bf615a117a7428d71be4330545b320)
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 	// 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 
97 private:
98 	typedef BLooper _inherited;
99 
100 	friend class Private;
101 	friend class BServer;
102 
103 								BApplication(const char* signature,
104 									const char* looperName, port_id port,
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 			port_id				_GetPort(const char* signature);
125 			void				BeginRectTracking(BRect r, bool trackWhole);
126 			void				EndRectTracking();
127 			status_t			_SetupServerAllocator();
128 			status_t			_InitGUIContext();
129 			status_t			_ConnectToServer();
130 			void				_ReconnectToServer();
131 			bool				_QuitAllWindows(bool force);
132 			bool				_WindowQuitLoop(bool quitFilePanels,
133 									bool force);
134 			void				_ArgvReceived(BMessage* message);
135 
136 			uint32				InitialWorkspace();
137 			int32				_CountWindows(bool includeMenus) const;
138 			BWindow*			_WindowAt(uint32 index,
139 									bool includeMenus) const;
140 
141 	static	void				_InitAppResources();
142 
143 private:
144 	static	BResources*			sAppResources;
145 
146 			const char*			fAppName;
147 			::BPrivate::PortLink*	fServerLink;
148 			::BPrivate::ServerMemoryAllocator* fServerAllocator;
149 
150 			void*				fCursorData;
151 			bigtime_t			fPulseRate;
152 			uint32				fInitialWorkspace;
153 			BMessageRunner*		fPulseRunner;
154 			status_t			fInitError;
155 			void*				fServerReadOnlyMemory;
156 			uint32				_reserved[12];
157 
158 			bool				fReadyToRunCalled;
159 };
160 
161 
162 // Global Objects
163 
164 extern BApplication* be_app;
165 extern BMessenger be_app_messenger;
166 
167 
168 #endif	// _APPLICATION_H
169