1 /* 2 * Copyright 2001-2007, 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 BLocker; 24 class BMessageRunner; 25 class BResources; 26 class BServer; 27 class BWindow; 28 struct app_info; 29 30 namespace BPrivate { 31 class PortLink; 32 class ServerMemoryAllocator; 33 } 34 35 36 class BApplication : public BLooper { 37 public: 38 BApplication(const char* signature); 39 BApplication(const char* signature, status_t* error); 40 virtual ~BApplication(); 41 42 // Archiving 43 BApplication(BMessage* data); 44 static BArchivable* Instantiate(BMessage* data); 45 virtual status_t Archive(BMessage* data, bool deep = true) const; 46 47 status_t InitCheck() const; 48 49 // App control and System Message handling 50 virtual thread_id Run(); 51 virtual void Quit(); 52 virtual bool QuitRequested(); 53 virtual void Pulse(); 54 virtual void ReadyToRun(); 55 virtual void MessageReceived(BMessage* msg); 56 virtual void ArgvReceived(int32 argc, char** argv); 57 virtual void AppActivated(bool active); 58 virtual void RefsReceived(BMessage* message); 59 virtual void AboutRequested(); 60 61 // Scripting 62 virtual BHandler* ResolveSpecifier(BMessage* msg, 63 int32 index, 64 BMessage* specifier, 65 int32 form, 66 const char* property); 67 68 // Cursor control, window/looper list, and app info 69 void ShowCursor(); 70 void HideCursor(); 71 void ObscureCursor(); 72 bool IsCursorHidden() const; 73 void SetCursor(const void* cursor); 74 void SetCursor(const BCursor* cursor, bool sync = true); 75 int32 CountWindows() const; 76 BWindow* WindowAt(int32 index) const; 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 send_drag( BMessage* msg, 128 int32 vs_token, 129 BPoint offset, 130 BRect drag_rect, 131 BHandler* reply_to); 132 void send_drag( BMessage* msg, 133 int32 vs_token, 134 BPoint offset, 135 int32 bitmap_token, 136 drawing_mode dragMode, 137 BHandler* reply_to); 138 void write_drag(_BSession_* session, BMessage* a_message); 139 */ bool _QuitAllWindows(bool force); 140 bool _WindowQuitLoop(bool quitFilePanels, bool force); 141 void _ArgvReceived(BMessage* message); 142 143 uint32 InitialWorkspace(); 144 int32 _CountWindows(bool includeMenus) const; 145 BWindow* _WindowAt(uint32 index, bool includeMenus) const; 146 147 static BResources* sAppResources; 148 static BLocker sAppResourcesLock; 149 150 const char* fAppName; 151 BPrivate::PortLink* fServerLink; 152 BPrivate::ServerMemoryAllocator* fServerAllocator; 153 154 void* fCursorData; 155 bigtime_t fPulseRate; 156 uint32 fInitialWorkspace; 157 //_drag_data_* fDraggedMessage; 158 BMessageRunner* fPulseRunner; 159 status_t fInitError; 160 void* fServerReadOnlyMemory; 161 uint32 _reserved[12]; 162 163 bool fReadyToRunCalled; 164 }; 165 166 // Global Objects 167 168 extern BApplication* be_app; 169 extern BMessenger be_app_messenger; 170 171 #endif // _APPLICATION_H 172