xref: /haiku/headers/os/app/Application.h (revision 687d231c5fab1e917f93e3b63b48b7b0e97882e3)
1 /*
2  * Copyright 2001-2005, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Erik Jaesler (erik@cgsoftware.com)
7  */
8 #ifndef _APPLICATION_H
9 #define _APPLICATION_H
10 
11 
12 #include <BeBuild.h>
13 #include <AppDefs.h>		// For convenience
14 #include <InterfaceDefs.h>
15 #include <Looper.h>
16 #include <Messenger.h>
17 #include <Point.h>
18 #include <Rect.h>
19 
20 
21 class BCursor;
22 class BList;
23 class BWindow;
24 class _BSession_;
25 class BResources;
26 class BMessageRunner;
27 class BServer;
28 struct _server_heap_;
29 struct _drag_data_;
30 
31 namespace BPrivate {
32 	class PortLink;
33 }
34 
35 
36 class BApplication : public BLooper {
37 public:
38 							BApplication(const char* signature);
39 							BApplication(const char* signature,
40 										 status_t* error);
41 	virtual					~BApplication();
42 
43 	// Archiving
44 							BApplication(BMessage* data);
45 	static	BArchivable*	Instantiate(BMessage* data);
46 	virtual	status_t		Archive(BMessage* data, bool deep = true) const;
47 
48 			status_t		InitCheck() const;
49 
50 	// App control and System Message handling
51 	virtual	thread_id		Run();
52 	virtual	void			Quit();
53 	virtual bool			QuitRequested();
54 	virtual	void			Pulse();
55 	virtual	void			ReadyToRun();
56 	virtual	void			MessageReceived(BMessage* msg);
57 	virtual	void			ArgvReceived(int32 argc, char** argv);
58 	virtual	void			AppActivated(bool active);
59 	virtual	void			RefsReceived(BMessage* message);
60 	virtual	void			AboutRequested();
61 
62 	// Scripting
63 	virtual BHandler*		ResolveSpecifier(BMessage* msg,
64 											 int32 index,
65 											 BMessage* specifier,
66 											 int32 form,
67 											 const char* property);
68 
69 	// Cursor control, window/looper list, and app info
70 			void			ShowCursor();
71 			void			HideCursor();
72 			void			ObscureCursor();
73 			bool			IsCursorHidden() const;
74 			void			SetCursor(const void* cursor);
75 			void			SetCursor(const BCursor* cursor, bool sync = true);
76 			int32			CountWindows() const;
77 			BWindow*		WindowAt(int32 index) const;
78 			int32			CountLoopers() const;
79 			BLooper*		LooperAt(int32 index) const;
80 			bool			IsLaunching() 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 
102 	friend class BServer;
103 
104 							BApplication(const char* signature, bool initGUI,
105 										 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			run_task();
123 			void			InitData(const char* signature, bool initGUI,
124 								status_t* error);
125 			void			BeginRectTracking(BRect r, bool trackWhole);
126 			void			EndRectTracking();
127 			status_t		setup_server_heaps();
128 			void*			rw_offs_to_ptr(uint32 offset);
129 			void*			ro_offs_to_ptr(uint32 offset);
130 			void*			global_ro_offs_to_ptr(uint32 offset);
131 			status_t		_InitGUIContext();
132 			status_t		connect_to_app_server();
133 			void			send_drag(	BMessage* msg,
134 										int32 vs_token,
135 										BPoint offset,
136 										BRect drag_rect,
137 										BHandler* reply_to);
138 			void			send_drag(	BMessage* msg,
139 										int32 vs_token,
140 										BPoint offset,
141 										int32 bitmap_token,
142 										drawing_mode dragMode,
143 										BHandler* reply_to);
144 			void			write_drag(_BSession_* session, BMessage* a_message);
145 			bool			quit_all_windows(bool force);
146 			bool			window_quit_loop(bool, bool);
147 			void			do_argv(BMessage* msg);
148 			void			SetAppCursor();
149 
150 			uint32			InitialWorkspace();
151 			int32			count_windows(bool incl_menus) const;
152 			BWindow*		window_at(uint32 index, bool incl_menus) const;
153 			status_t		get_window_list(BList* list, bool incl_menus) const;
154 	static	int32			async_quit_entry(void*);
155 	static	BResources*		_app_resources;
156 	static	BLocker			_app_resources_lock;
157 
158 			const char*		fAppName;
159 			BPrivate::PortLink* fServerLink;
160 			uint32			_unused0;
161 
162 			void*			fCursorData;
163 			_server_heap_* 	fServerHeap;
164 			bigtime_t		fPulseRate;
165 			uint32			fInitialWorkspace;
166 			_drag_data_*	fDraggedMessage;
167 			BMessageRunner*	fPulseRunner;
168 			status_t		fInitError;
169 			uint32			_reserved[11];
170 
171 			bool			fReadyToRunCalled;
172 };
173 
174 // Global Objects
175 
176 extern _IMPEXP_BE BApplication*	be_app;
177 extern _IMPEXP_BE BMessenger be_app_messenger;
178 
179 #endif	// _APPLICATION_H
180