1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 #ifndef _CONTAINER_WINDOW_H 35 #define _CONTAINER_WINDOW_H 36 37 38 #include <Window.h> 39 40 #include "LockingList.h" 41 #include "Model.h" 42 #include "SlowContextPopup.h" 43 #include "TaskLoop.h" 44 45 class BPopUpMenu; 46 class BMenuBar; 47 48 namespace BPrivate { 49 50 class BNavigator; 51 class BPoseView; 52 class ModelMenuItem; 53 class AttributeStreamNode; 54 class BackgroundImage; 55 class Model; 56 class ModelNodeLazyOpener; 57 class SelectionWindow; 58 59 #define kDefaultFolderTemplate "DefaultFolderTemplate" 60 61 extern const char* kAddOnsMenuName; 62 63 const window_feel kPrivateDesktopWindowFeel = window_feel(1024); 64 const window_look kPrivateDesktopWindowLook = window_look(4); 65 // this is a mirror of an app server private values 66 67 enum { 68 // flags that describe opening of the window 69 kRestoreWorkspace = 0x1, 70 kIsHidden = 0x2, 71 // set when opening a window during initial Tracker start 72 kRestoreDecor = 0x4 73 }; 74 75 class BContainerWindow : public BWindow { 76 public: 77 BContainerWindow(LockingList<BWindow>* windowList, 78 uint32 containerWindowFlags, 79 window_look look = B_DOCUMENT_WINDOW_LOOK, 80 window_feel feel = B_NORMAL_WINDOW_FEEL, 81 uint32 flags = B_WILL_ACCEPT_FIRST_CLICK 82 | B_NO_WORKSPACE_ACTIVATION, 83 uint32 workspace = B_CURRENT_WORKSPACE); 84 85 virtual ~BContainerWindow(); 86 87 virtual void Init(const BMessage* message = NULL); 88 89 static BRect InitialWindowRect(window_feel); 90 91 virtual void Minimize(bool minimize); 92 virtual void Quit(); 93 virtual bool QuitRequested(); 94 95 virtual void UpdateIfTrash(Model*); 96 97 virtual void CreatePoseView(Model*); 98 99 virtual void ShowContextMenu(BPoint, const entry_ref*, BView*); 100 virtual uint32 ShowDropContextMenu(BPoint); 101 virtual void MenusBeginning(); 102 virtual void MenusEnded(); 103 virtual void MessageReceived(BMessage*); 104 virtual void FrameResized(float, float); 105 virtual void FrameMoved(BPoint); 106 virtual void Zoom(BPoint, float, float); 107 virtual void WorkspacesChanged(uint32, uint32); 108 109 // virtuals that control setup of window 110 virtual bool ShouldAddMenus() const; 111 virtual bool ShouldAddScrollBars() const; 112 virtual bool ShouldAddCountView() const; 113 114 virtual void CheckScreenIntersect(); 115 116 bool IsTrash() const; 117 bool InTrash() const; 118 bool IsPrintersDir() const; 119 120 virtual bool IsShowing(const node_ref*) const; 121 virtual bool IsShowing(const entry_ref*) const; 122 123 void ResizeToFit(); 124 125 Model* TargetModel() const; 126 BPoseView* PoseView() const; 127 BNavigator* Navigator() const; 128 129 virtual void SelectionChanged(); 130 virtual void ViewModeChanged(uint32 oldMode, uint32 newMode); 131 132 virtual void RestoreState(); 133 virtual void RestoreState(const BMessage &); 134 void RestoreStateCommon(); 135 virtual void SaveState(bool hide = true); 136 virtual void SaveState(BMessage &) const; 137 void UpdateTitle(); 138 139 bool StateNeedsSaving() const; 140 bool SaveStateIsEnabled() const; 141 void SetSaveStateEnabled(bool); 142 143 void UpdateBackgroundImage(); 144 145 static status_t GetLayoutState(BNode*, BMessage*); 146 static status_t SetLayoutState(BNode*, const BMessage*); 147 // calls for inheriting window size, attribute layout, etc. 148 // deprecated 149 150 virtual void AddMimeTypesToMenu(BMenu*); 151 void AddMimeTypesToMenu(); 152 virtual void MarkAttributeMenu(BMenu*); 153 void MarkAttributeMenu(); 154 void MarkArrangeByMenu(BMenu*); 155 BMenuItem* NewAttributeMenuItem(const char* label, const char* name, 156 int32 type, float width, int32 align, bool editable, 157 bool statField); 158 BMenuItem* NewAttributeMenuItem(const char* label, const char* name, 159 int32 type, const char* displayAs, float width, int32 align, 160 bool editable, bool statField); 161 virtual void NewAttributeMenu(BMenu*); 162 163 void HideAttributeMenu(); 164 void ShowAttributeMenu(); 165 PiggybackTaskLoop* DelayedTaskLoop(); 166 // use for RunLater queueing 167 void PulseTaskLoop(); 168 // called by some view that has pulse, either BackgroundView 169 // or BPoseView 170 171 static bool DefaultStateSourceNode(const char* name, BNode* result, 172 bool createNew = false, bool createFolder = true); 173 174 // add-on iteration 175 void EachAddon(bool (*)(const Model*, const char*, uint32 shortcut, 176 bool primary, void*), void*, BObjectList<BString> &); 177 178 BPopUpMenu* ContextMenu(); 179 180 // drag&drop support 181 status_t DragStart(const BMessage*); 182 void DragStop(); 183 bool Dragging() const; 184 BMessage* DragMessage() const; 185 186 void ShowSelectionWindow(); 187 188 void ShowNavigator(bool); 189 void SetSingleWindowBrowseShortcuts(bool); 190 191 void SetPathWatchingEnabled(bool); 192 bool IsPathWatchingEnabled(void) const; 193 194 protected: 195 virtual BPoseView* NewPoseView(Model*, BRect, uint32); 196 // instantiate a different flavor of BPoseView for different 197 // ContainerWindows 198 199 virtual void RestoreWindowState(AttributeStreamNode*); 200 virtual void RestoreWindowState(const BMessage &); 201 virtual void SaveWindowState(AttributeStreamNode*); 202 virtual void SaveWindowState(BMessage&) const; 203 204 virtual bool NeedsDefaultStateSetup(); 205 virtual void SetUpDefaultState(); 206 // these two virtuals control setting up a new folder that 207 // does not have any state settings yet with the default 208 209 virtual void AddMenus(); 210 virtual void AddShortcuts(); 211 // add equivalents of the menu shortcuts to the menuless 212 // desktop window 213 virtual void AddFileMenu(BMenu* menu); 214 virtual void AddWindowMenu(BMenu* menu); 215 216 virtual void AddContextMenus(); 217 218 virtual void AddFileContextMenus(BMenu*); 219 virtual void AddWindowContextMenus(BMenu*); 220 virtual void AddVolumeContextMenus(BMenu*); 221 virtual void AddDropContextMenus(BMenu*); 222 virtual void AddTrashContextMenus(BMenu*); 223 224 virtual void RepopulateMenus(); 225 void PopulateArrangeByMenu(BMenu*); 226 227 virtual void SetCutItem(BMenu*); 228 virtual void SetCopyItem(BMenu*); 229 virtual void SetPasteItem(BMenu*); 230 virtual void SetArrangeMenu(BMenu*); 231 virtual void SetCloseItem(BMenu*); 232 virtual void SetupNavigationMenu(const entry_ref*, BMenu*); 233 virtual void SetupMoveCopyMenus(const entry_ref*, BMenu*); 234 virtual void PopulateMoveCopyNavMenu(BNavMenu*, uint32, 235 const entry_ref*, bool); 236 237 virtual void SetupOpenWithMenu(BMenu*); 238 virtual void SetUpEditQueryItem(BMenu*); 239 virtual void SetUpDiskMenu(BMenu*); 240 241 virtual void BuildAddOnMenu(BMenu*); 242 void BuildMimeTypeList(BObjectList<BString>& mimeTypes); 243 244 enum UpdateMenuContext { 245 kMenuBarContext, 246 kPosePopUpContext, 247 kWindowPopUpContext 248 }; 249 250 virtual void UpdateMenu(BMenu* menu, UpdateMenuContext context); 251 252 BMenu* AddMimeMenu(const BMimeType& mimeType, bool isSuperType, 253 BMenu* menu, int32 start); 254 255 BHandler* ResolveSpecifier(BMessage*, int32, BMessage*, int32, 256 const char*); 257 258 bool EachAddon(BPath &path, 259 bool (*)(const Model*, const char*, uint32, bool, void*), 260 BObjectList<Model>*, void*, BObjectList<BString> &); 261 void LoadAddOn(BMessage*); 262 263 BPopUpMenu* fFileContextMenu; 264 BPopUpMenu* fWindowContextMenu; 265 BPopUpMenu* fDropContextMenu; 266 BPopUpMenu* fVolumeContextMenu; 267 BPopUpMenu* fTrashContextMenu; 268 BSlowContextMenu* fDragContextMenu; 269 BMenuItem* fMoveToItem; 270 BMenuItem* fCopyToItem; 271 BMenuItem* fCreateLinkItem; 272 BMenuItem* fOpenWithItem; 273 ModelMenuItem* fNavigationItem; 274 BMenuBar* fMenuBar; 275 BNavigator* fNavigator; 276 BPoseView* fPoseView; 277 LockingList<BWindow>* fWindowList; 278 BMenu* fAttrMenu; 279 BMenu* fWindowMenu; 280 BMenu* fFileMenu; 281 BMenu* fArrangeByMenu; 282 283 SelectionWindow* fSelectionWindow; 284 285 PiggybackTaskLoop* fTaskLoop; 286 287 bool fIsTrash; 288 bool fInTrash; 289 bool fIsPrinters; 290 291 uint32 fContainerWindowFlags; 292 BackgroundImage* fBackgroundImage; 293 294 private: 295 BRect fSavedZoomRect; 296 BRect fPreviousBounds; 297 298 static BRect sNewWindRect; 299 300 BPopUpMenu* fContextMenu; 301 BMessage* fDragMessage; 302 BObjectList<BString>* fCachedTypesList; 303 bool fWaitingForRefs; 304 305 bool fStateNeedsSaving; 306 bool fSaveStateIsEnabled; 307 308 bool fIsWatchingPath; 309 310 typedef BWindow _inherited; 311 312 friend int32 show_context_menu(void*); 313 friend class BackgroundView; 314 315 void _UpdateSelectionMIMEInfo(); 316 }; 317 318 class WindowStateNodeOpener { 319 // this class manages opening and closing the proper node for 320 // state restoring / saving; the constructor knows how to decide whether 321 // to use a special directory for root, etc. 322 // setter calls used when no attributes can be read from a node and 323 // defaults are to be substituted 324 public: 325 WindowStateNodeOpener(BContainerWindow* window, bool forWriting); 326 virtual ~WindowStateNodeOpener(); 327 328 void SetTo(const BDirectory*); 329 void SetTo(const BEntry* entry, bool forWriting); 330 void SetTo(Model*, bool forWriting); 331 332 AttributeStreamNode* StreamNode() const; 333 BNode* Node() const; 334 335 private: 336 ModelNodeLazyOpener* fModelOpener; 337 BNode* fNode; 338 AttributeStreamNode* fStreamNode; 339 }; 340 341 class BackgroundView : public BView { 342 // background view placed in a BContainerWindow, under the pose view 343 public: 344 BackgroundView(BRect); 345 virtual void AttachedToWindow(); 346 virtual void FrameResized(float, float); 347 virtual void Draw(BRect); 348 349 void PoseViewFocused(bool); 350 virtual void Pulse(); 351 352 protected: 353 virtual void WindowActivated(bool); 354 355 private: 356 typedef BView _inherited; 357 }; 358 359 int CompareLabels(const BMenuItem*, const BMenuItem*); 360 361 // inlines --------- 362 363 inline BNavigator* 364 BContainerWindow::Navigator() const 365 { 366 return fNavigator; 367 } 368 369 inline BPoseView* 370 BContainerWindow::PoseView() const 371 { 372 return fPoseView; 373 } 374 375 inline bool 376 BContainerWindow::IsTrash() const 377 { 378 return fIsTrash; 379 } 380 381 inline bool 382 BContainerWindow::InTrash() const 383 { 384 return fInTrash; 385 } 386 387 inline bool 388 BContainerWindow::IsPrintersDir() const 389 { 390 return fIsPrinters; 391 } 392 393 inline void 394 BContainerWindow::SetUpDiskMenu(BMenu*) 395 { 396 // nothing at this level 397 } 398 399 inline BPopUpMenu* 400 BContainerWindow::ContextMenu() 401 { 402 return fContextMenu; 403 } 404 405 inline bool 406 BContainerWindow::Dragging() const 407 { 408 return fDragMessage && fCachedTypesList; 409 } 410 411 inline BMessage* 412 BContainerWindow::DragMessage() const 413 { 414 return fDragMessage; 415 } 416 inline 417 bool 418 BContainerWindow::SaveStateIsEnabled() const 419 { 420 return fSaveStateIsEnabled; 421 } 422 423 inline 424 void 425 BContainerWindow::SetSaveStateEnabled(bool value) 426 { 427 fSaveStateIsEnabled = value; 428 } 429 430 inline 431 bool 432 BContainerWindow::IsPathWatchingEnabled() const 433 { 434 return fIsWatchingPath; 435 } 436 437 filter_result ActivateWindowFilter(BMessage* message, BHandler** target, 438 BMessageFilter* messageFilter); 439 440 } // namespace BPrivate 441 442 using namespace BPrivate; 443 444 #endif 445