1 /* 2 * Copyright 2001-2014 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 status_t GetAppInfo(app_info* info) const; 81 static BResources* AppResources(); 82 83 virtual void DispatchMessage(BMessage* message, 84 BHandler* handler); 85 void SetPulseRate(bigtime_t rate); 86 87 // More scripting 88 virtual status_t GetSupportedSuites(BMessage* data); 89 90 91 // Private or reserved 92 virtual status_t Perform(perform_code d, void* arg); 93 94 class Private; 95 96 private: 97 typedef BLooper _inherited; 98 99 friend class Private; 100 friend class BServer; 101 102 BApplication(const char* signature, bool initGUI, 103 status_t* error); 104 BApplication(uint32 signature); 105 BApplication(const BApplication&); 106 BApplication& operator=(const BApplication&); 107 108 virtual void _ReservedApplication1(); 109 virtual void _ReservedApplication2(); 110 virtual void _ReservedApplication3(); 111 virtual void _ReservedApplication4(); 112 virtual void _ReservedApplication5(); 113 virtual void _ReservedApplication6(); 114 virtual void _ReservedApplication7(); 115 virtual void _ReservedApplication8(); 116 117 virtual bool ScriptReceived(BMessage* msg, int32 index, 118 BMessage* specifier, int32 form, 119 const char* property); 120 void _InitData(const char* signature, bool initGUI, 121 status_t* error); 122 void BeginRectTracking(BRect r, bool trackWhole); 123 void EndRectTracking(); 124 status_t _SetupServerAllocator(); 125 status_t _InitGUIContext(); 126 status_t _ConnectToServer(); 127 void _ReconnectToServer(); 128 bool _QuitAllWindows(bool force); 129 bool _WindowQuitLoop(bool quitFilePanels, bool force); 130 void _ArgvReceived(BMessage* message); 131 132 uint32 InitialWorkspace(); 133 int32 _CountWindows(bool includeMenus) const; 134 BWindow* _WindowAt(uint32 index, bool includeMenus) const; 135 136 static void _InitAppResources(); 137 138 private: 139 static BResources* sAppResources; 140 141 const char* fAppName; 142 ::BPrivate::PortLink* fServerLink; 143 ::BPrivate::ServerMemoryAllocator* fServerAllocator; 144 145 void* fCursorData; 146 bigtime_t fPulseRate; 147 uint32 fInitialWorkspace; 148 BMessageRunner* fPulseRunner; 149 status_t fInitError; 150 void* fServerReadOnlyMemory; 151 uint32 _reserved[12]; 152 153 bool fReadyToRunCalled; 154 }; 155 156 157 // Global Objects 158 159 extern BApplication* be_app; 160 extern BMessenger be_app_messenger; 161 162 163 #endif // _APPLICATION_H 164