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 <GroupView.h> 39 #include <StringList.h> 40 #include <Window.h> 41 42 #include "LockingList.h" 43 #include "Model.h" 44 #include "SlowContextPopup.h" 45 #include "TaskLoop.h" 46 47 48 class BGridView; 49 class BGroupLayout; 50 class BGroupView; 51 class BPopUpMenu; 52 class BMenuBar; 53 54 namespace BPrivate { 55 56 class BNavigator; 57 class BPoseView; 58 class DraggableContainerIcon; 59 class ModelMenuItem; 60 class AttributeStreamNode; 61 class BackgroundImage; 62 class Model; 63 class ModelNodeLazyOpener; 64 class BorderedView; 65 class SelectionWindow; 66 67 68 #define kDefaultFolderTemplate "DefaultFolderTemplate" 69 70 71 extern const char* kAddOnsMenuName; 72 73 const window_feel kPrivateDesktopWindowFeel = window_feel(1024); 74 const window_look kPrivateDesktopWindowLook = window_look(4); 75 // this is a mirror of an app server private values 76 77 78 enum { 79 // flags that describe opening of the window 80 kRestoreWorkspace = 0x1, 81 kIsHidden = 0x2, 82 // set when opening a window during initial Tracker start 83 kRestoreDecor = 0x4 84 }; 85 86 87 struct AddonShortcut { 88 Model* model; 89 char key; 90 char defaultKey; 91 uint32 modifiers; 92 }; 93 94 95 class BContainerWindow : public BWindow { 96 public: 97 BContainerWindow(LockingList<BWindow>* windowList, 98 uint32 containerWindowFlags, 99 window_look look = B_DOCUMENT_WINDOW_LOOK, 100 window_feel feel = B_NORMAL_WINDOW_FEEL, 101 uint32 flags = B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION, 102 uint32 workspace = B_CURRENT_WORKSPACE, bool useLayouts = true, 103 bool isDeskWindow = false); 104 105 virtual ~BContainerWindow(); 106 107 virtual void Init(const BMessage* message = NULL); 108 virtual void InitLayout(); 109 110 static BRect InitialWindowRect(window_feel); 111 112 virtual void Minimize(bool minimize); 113 virtual void Quit(); 114 virtual bool QuitRequested(); 115 116 virtual void UpdateIfTrash(Model*); 117 118 virtual void CreatePoseView(Model*); 119 120 virtual void ShowContextMenu(BPoint, const entry_ref*, BView*); 121 virtual uint32 ShowDropContextMenu(BPoint); 122 virtual void MenusBeginning(); 123 virtual void MenusEnded(); 124 virtual void MessageReceived(BMessage*); 125 virtual void FrameResized(float, float); 126 virtual void FrameMoved(BPoint); 127 virtual void Zoom(BPoint, float, float); 128 virtual void WorkspacesChanged(uint32, uint32); 129 130 // virtuals that control setup of window 131 virtual bool ShouldAddMenus() const; 132 virtual bool ShouldAddScrollBars() const; 133 134 virtual void CheckScreenIntersect(); 135 136 bool IsTrash() const; 137 bool InTrash() const; 138 bool IsPrintersDir() const; 139 140 virtual bool IsShowing(const node_ref*) const; 141 virtual bool IsShowing(const entry_ref*) const; 142 143 void ResizeToFit(); 144 145 Model* TargetModel() const; 146 BPoseView* PoseView() const; 147 BNavigator* Navigator() const; 148 149 virtual void SelectionChanged(); 150 virtual void ViewModeChanged(uint32 oldMode, uint32 newMode); 151 152 virtual void RestoreState(); 153 virtual void RestoreState(const BMessage &); 154 void RestoreStateCommon(); 155 virtual void SaveState(bool hide = true); 156 virtual void SaveState(BMessage &) const; 157 void UpdateTitle(); 158 159 bool StateNeedsSaving() const; 160 bool SaveStateIsEnabled() const; 161 void SetSaveStateEnabled(bool); 162 163 void UpdateBackgroundImage(); 164 165 static status_t GetLayoutState(BNode*, BMessage*); 166 static status_t SetLayoutState(BNode*, const BMessage*); 167 // calls for inheriting window size, attribute layout, etc. 168 // deprecated 169 170 virtual void AddMimeTypesToMenu(BMenu*); 171 void AddMimeTypesToMenu(); 172 virtual void MarkAttributeMenu(BMenu*); 173 void MarkAttributeMenu(); 174 void MarkArrangeByMenu(BMenu*); 175 BMenuItem* NewAttributeMenuItem(const char* label, const char* name, 176 int32 type, float width, int32 align, bool editable, 177 bool statField); 178 BMenuItem* NewAttributeMenuItem(const char* label, const char* name, 179 int32 type, const char* displayAs, float width, int32 align, 180 bool editable, bool statField); 181 virtual void NewAttributeMenu(BMenu*); 182 183 void HideAttributeMenu(); 184 void ShowAttributeMenu(); 185 PiggybackTaskLoop* DelayedTaskLoop(); 186 // use for RunLater queueing 187 void PulseTaskLoop(); 188 // called by some view that has pulse, either BackgroundView 189 // or BPoseView 190 191 static bool DefaultStateSourceNode(const char* name, BNode* result, 192 bool createNew = false, bool createFolder = true); 193 194 // add-on iteration 195 void EachAddon(bool (*)(const Model*, const char*, uint32 shortcut, 196 uint32 modifiers, bool primary, void*), void*, BStringList&); 197 198 BPopUpMenu* ContextMenu(); 199 200 // drag&drop support 201 status_t DragStart(const BMessage*); 202 void DragStop(); 203 bool Dragging() const; 204 BMessage* DragMessage() const; 205 206 void ShowSelectionWindow(); 207 208 void ShowNavigator(bool); 209 void SetSingleWindowBrowseShortcuts(bool); 210 211 void SetPathWatchingEnabled(bool); 212 bool IsPathWatchingEnabled(void) const; 213 214 protected: 215 virtual BPoseView* NewPoseView(Model*, uint32); 216 // instantiate a different flavor of BPoseView for different 217 // ContainerWindows 218 219 virtual void RestoreWindowState(AttributeStreamNode*); 220 virtual void RestoreWindowState(const BMessage &); 221 virtual void SaveWindowState(AttributeStreamNode*); 222 virtual void SaveWindowState(BMessage&) const; 223 224 virtual bool NeedsDefaultStateSetup(); 225 virtual void SetUpDefaultState(); 226 // these two virtuals control setting up a new folder that 227 // does not have any state settings yet with the default 228 229 virtual void AddMenus(); 230 virtual void AddShortcuts(); 231 // add equivalents of the menu shortcuts to the menuless 232 // desktop window 233 virtual void AddFileMenu(BMenu* menu); 234 virtual void AddWindowMenu(BMenu* menu); 235 236 virtual void AddContextMenus(); 237 238 virtual void AddFileContextMenus(BMenu*); 239 virtual void AddWindowContextMenus(BMenu*); 240 virtual void AddVolumeContextMenus(BMenu*); 241 virtual void AddDropContextMenus(BMenu*); 242 virtual void AddTrashContextMenus(BMenu*); 243 244 virtual void RepopulateMenus(); 245 void PopulateArrangeByMenu(BMenu*); 246 247 virtual void SetCutItem(BMenu*); 248 virtual void SetCopyItem(BMenu*); 249 virtual void SetPasteItem(BMenu*); 250 virtual void SetArrangeMenu(BMenu*); 251 virtual void SetCloseItem(BMenu*); 252 virtual void SetupNavigationMenu(const entry_ref*, BMenu*); 253 virtual void SetupMoveCopyMenus(const entry_ref*, BMenu*); 254 virtual void PopulateMoveCopyNavMenu(BNavMenu*, uint32, 255 const entry_ref*, bool); 256 257 virtual void SetupOpenWithMenu(BMenu*); 258 virtual void SetUpEditQueryItem(BMenu*); 259 virtual void SetUpDiskMenu(BMenu*); 260 261 virtual void BuildAddOnMenu(BMenu*); 262 void BuildMimeTypeList(BStringList& mimeTypes); 263 264 enum UpdateMenuContext { 265 kMenuBarContext, 266 kPosePopUpContext, 267 kWindowPopUpContext 268 }; 269 270 virtual void UpdateMenu(BMenu* menu, UpdateMenuContext context); 271 272 BMenu* AddMimeMenu(const BMimeType& mimeType, bool isSuperType, 273 BMenu* menu, int32 start); 274 275 BHandler* ResolveSpecifier(BMessage*, int32, BMessage*, int32, 276 const char*); 277 278 bool EachAddon(BPath &path, 279 bool (*)(const Model*, const char*, uint32, bool, void*), 280 BObjectList<Model>*, void*, BStringList&); 281 void LoadAddOn(BMessage*); 282 283 bool fUseLayouts; 284 BGroupLayout* fRootLayout; 285 BGroupView* fMenuContainer; 286 BGridView* fPoseContainer; 287 BorderedView* fBorderedView; 288 BGroupView* fVScrollBarContainer; 289 BGroupView* fCountContainer; 290 291 BPopUpMenu* fFileContextMenu; 292 BPopUpMenu* fWindowContextMenu; 293 BPopUpMenu* fDropContextMenu; 294 BPopUpMenu* fVolumeContextMenu; 295 BPopUpMenu* fTrashContextMenu; 296 BSlowContextMenu* fDragContextMenu; 297 BMenuItem* fMoveToItem; 298 BMenuItem* fCopyToItem; 299 BMenuItem* fCreateLinkItem; 300 BMenuItem* fOpenWithItem; 301 ModelMenuItem* fNavigationItem; 302 BMenuBar* fMenuBar; 303 DraggableContainerIcon* fDraggableIcon; 304 BNavigator* fNavigator; 305 BPoseView* fPoseView; 306 LockingList<BWindow>* fWindowList; 307 BMenu* fAttrMenu; 308 BMenu* fWindowMenu; 309 BMenu* fFileMenu; 310 BMenu* fArrangeByMenu; 311 312 SelectionWindow* fSelectionWindow; 313 314 PiggybackTaskLoop* fTaskLoop; 315 316 bool fIsTrash; 317 bool fInTrash; 318 bool fIsPrinters; 319 bool fIsDesktop; 320 321 uint32 fContainerWindowFlags; 322 BackgroundImage* fBackgroundImage; 323 324 static LockingList<struct AddonShortcut>* fAddonsList; 325 326 private: 327 BRect fSavedZoomRect; 328 BRect fPreviousBounds; 329 330 static BRect sNewWindRect; 331 332 BPopUpMenu* fContextMenu; 333 BMessage* fDragMessage; 334 BObjectList<BString>* fCachedTypesList; 335 bool fWaitingForRefs; 336 337 bool fStateNeedsSaving; 338 bool fSaveStateIsEnabled; 339 340 bool fIsWatchingPath; 341 342 typedef BWindow _inherited; 343 344 friend int32 show_context_menu(void*); 345 friend class BackgroundView; 346 347 void _UpdateSelectionMIMEInfo(); 348 void _AddFolderIcon(); 349 }; 350 351 352 class WindowStateNodeOpener { 353 // this class manages opening and closing the proper node for 354 // state restoring / saving; the constructor knows how to decide whether 355 // to use a special directory for root, etc. 356 // setter calls used when no attributes can be read from a node and 357 // defaults are to be substituted 358 public: 359 WindowStateNodeOpener(BContainerWindow* window, bool forWriting); 360 virtual ~WindowStateNodeOpener(); 361 362 void SetTo(const BDirectory*); 363 void SetTo(const BEntry* entry, bool forWriting); 364 void SetTo(Model*, bool forWriting); 365 366 AttributeStreamNode* StreamNode() const; 367 BNode* Node() const; 368 369 private: 370 ModelNodeLazyOpener* fModelOpener; 371 BNode* fNode; 372 AttributeStreamNode* fStreamNode; 373 }; 374 375 376 class BorderedView : public BGroupView { 377 public: 378 BorderedView(); 379 380 void PoseViewFocused(bool); 381 virtual void Pulse(); 382 383 void EnableBorderHighlight(bool); 384 385 protected: 386 virtual void WindowActivated(bool); 387 388 private: 389 bool fEnableBorderHighlight; 390 391 typedef BGroupView _inherited; 392 }; 393 394 395 int CompareLabels(const BMenuItem*, const BMenuItem*); 396 397 398 // inlines --------- 399 400 inline BNavigator* 401 BContainerWindow::Navigator() const 402 { 403 return fNavigator; 404 } 405 406 407 inline BPoseView* 408 BContainerWindow::PoseView() const 409 { 410 return fPoseView; 411 } 412 413 414 inline bool 415 BContainerWindow::IsTrash() const 416 { 417 return fIsTrash; 418 } 419 420 421 inline bool 422 BContainerWindow::InTrash() const 423 { 424 return fInTrash; 425 } 426 427 428 inline bool 429 BContainerWindow::IsPrintersDir() const 430 { 431 return fIsPrinters; 432 } 433 434 435 inline void 436 BContainerWindow::SetUpDiskMenu(BMenu*) 437 { 438 // nothing at this level 439 } 440 441 442 inline BPopUpMenu* 443 BContainerWindow::ContextMenu() 444 { 445 return fContextMenu; 446 } 447 448 449 inline bool 450 BContainerWindow::Dragging() const 451 { 452 return fDragMessage && fCachedTypesList; 453 } 454 455 456 inline BMessage* 457 BContainerWindow::DragMessage() const 458 { 459 return fDragMessage; 460 } 461 462 463 inline bool 464 BContainerWindow::SaveStateIsEnabled() const 465 { 466 return fSaveStateIsEnabled; 467 } 468 469 470 inline void 471 BContainerWindow::SetSaveStateEnabled(bool value) 472 { 473 fSaveStateIsEnabled = value; 474 } 475 476 477 inline bool 478 BContainerWindow::IsPathWatchingEnabled() const 479 { 480 return fIsWatchingPath; 481 } 482 483 484 filter_result ActivateWindowFilter(BMessage* message, BHandler** target, 485 BMessageFilter* messageFilter); 486 487 } // namespace BPrivate 488 489 using namespace BPrivate; 490 491 492 #endif // _CONTAINER_WINDOW_H 493