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 74 enum { 75 // flags that describe opening of the window 76 kRestoreWorkspace = 0x1, 77 kIsHidden = 0x2, 78 // set when opening a window during initial Tracker start 79 kRestoreDecor = 0x4 80 }; 81 82 83 struct AddonShortcut { 84 Model* model; 85 char key; 86 char defaultKey; 87 uint32 modifiers; 88 }; 89 90 91 class BContainerWindow : public BWindow { 92 public: 93 BContainerWindow(LockingList<BWindow>* windowList, 94 uint32 containerWindowFlags, 95 window_look look = B_DOCUMENT_WINDOW_LOOK, 96 window_feel feel = B_NORMAL_WINDOW_FEEL, 97 uint32 flags = B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION, 98 uint32 workspace = B_CURRENT_WORKSPACE, bool useLayouts = true, 99 bool isDeskWindow = false); 100 101 virtual ~BContainerWindow(); 102 103 virtual void Init(const BMessage* message = NULL); 104 virtual void InitLayout(); 105 106 static BRect InitialWindowRect(window_feel); 107 108 virtual void Minimize(bool minimize); 109 virtual void Quit(); 110 virtual bool QuitRequested(); 111 112 virtual void UpdateIfTrash(Model*); 113 114 virtual void CreatePoseView(Model*); 115 116 virtual void ShowContextMenu(BPoint, const entry_ref*, BView*); 117 virtual uint32 ShowDropContextMenu(BPoint); 118 virtual void MenusBeginning(); 119 virtual void MenusEnded(); 120 virtual void MessageReceived(BMessage*); 121 virtual void FrameResized(float, float); 122 virtual void FrameMoved(BPoint); 123 virtual void Zoom(BPoint, float, float); 124 virtual void WorkspacesChanged(uint32, uint32); 125 126 // virtuals that control setup of window 127 virtual bool ShouldAddMenus() const; 128 virtual bool ShouldAddScrollBars() const; 129 130 virtual void CheckScreenIntersect(); 131 132 bool IsTrash() const; 133 bool InTrash() const; 134 bool IsPrintersDir() const; 135 136 virtual bool IsShowing(const node_ref*) const; 137 virtual bool IsShowing(const entry_ref*) const; 138 139 void ResizeToFit(); 140 141 Model* TargetModel() const; 142 BPoseView* PoseView() const; 143 BNavigator* Navigator() const; 144 145 virtual void SelectionChanged(); 146 virtual void ViewModeChanged(uint32 oldMode, uint32 newMode); 147 148 virtual void RestoreState(); 149 virtual void RestoreState(const BMessage &); 150 void RestoreStateCommon(); 151 virtual void SaveState(bool hide = true); 152 virtual void SaveState(BMessage &) const; 153 void UpdateTitle(); 154 155 bool StateNeedsSaving() const; 156 bool SaveStateIsEnabled() const; 157 void SetSaveStateEnabled(bool); 158 159 void UpdateBackgroundImage(); 160 161 static status_t GetLayoutState(BNode*, BMessage*); 162 static status_t SetLayoutState(BNode*, const BMessage*); 163 // calls for inheriting window size, attribute layout, etc. 164 // deprecated 165 166 virtual void AddMimeTypesToMenu(BMenu*); 167 void AddMimeTypesToMenu(); 168 virtual void MarkAttributeMenu(BMenu*); 169 void MarkAttributeMenu(); 170 void MarkArrangeByMenu(BMenu*); 171 BMenuItem* NewAttributeMenuItem(const char* label, const char* name, 172 int32 type, float width, int32 align, bool editable, 173 bool statField); 174 BMenuItem* NewAttributeMenuItem(const char* label, const char* name, 175 int32 type, const char* displayAs, float width, int32 align, 176 bool editable, bool statField); 177 virtual void NewAttributeMenu(BMenu*); 178 179 void HideAttributeMenu(); 180 void ShowAttributeMenu(); 181 PiggybackTaskLoop* DelayedTaskLoop(); 182 // use for RunLater queueing 183 void PulseTaskLoop(); 184 // called by some view that has pulse, either BackgroundView 185 // or BPoseView 186 187 static bool DefaultStateSourceNode(const char* name, BNode* result, 188 bool createNew = false, bool createFolder = true); 189 190 // add-on iteration 191 void EachAddon(bool (*)(const Model*, const char*, uint32 shortcut, 192 uint32 modifiers, bool primary, void*, BContainerWindow*, BMenu*), 193 void*, BStringList&, BMenu*); 194 195 BMessage* AddOnMessage(int32); 196 entry_ref GetCurrentDirRef(); 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 fStateNeedsSaving; 317 318 bool fIsTrash; 319 bool fInTrash; 320 bool fIsPrinters; 321 bool fIsDesktop; 322 323 uint32 fContainerWindowFlags; 324 BackgroundImage* fBackgroundImage; 325 326 static LockingList<struct AddonShortcut>* fAddonsList; 327 328 private: 329 BRect fSavedZoomRect; 330 BRect fPreviousBounds; 331 332 static BRect sNewWindRect; 333 334 BPopUpMenu* fContextMenu; 335 BMessage* fDragMessage; 336 BObjectList<BString>* fCachedTypesList; 337 bool fWaitingForRefs; 338 339 bool fSaveStateIsEnabled; 340 341 bool fIsWatchingPath; 342 343 typedef BWindow _inherited; 344 345 friend int32 show_context_menu(void*); 346 friend class BackgroundView; 347 348 void _UpdateSelectionMIMEInfo(); 349 void _AddFolderIcon(); 350 void _PassMessageToAddOn(BMessage*); 351 }; 352 353 354 class WindowStateNodeOpener { 355 // this class manages opening and closing the proper node for 356 // state restoring / saving; the constructor knows how to decide whether 357 // to use a special directory for root, etc. 358 // setter calls used when no attributes can be read from a node and 359 // defaults are to be substituted 360 public: 361 WindowStateNodeOpener(BContainerWindow* window, bool forWriting); 362 virtual ~WindowStateNodeOpener(); 363 364 void SetTo(const BDirectory*); 365 void SetTo(const BEntry* entry, bool forWriting); 366 void SetTo(Model*, bool forWriting); 367 368 AttributeStreamNode* StreamNode() const; 369 BNode* Node() const; 370 371 private: 372 ModelNodeLazyOpener* fModelOpener; 373 BNode* fNode; 374 AttributeStreamNode* fStreamNode; 375 }; 376 377 378 class BorderedView : public BGroupView { 379 public: 380 BorderedView(); 381 382 void PoseViewFocused(bool); 383 virtual void Pulse(); 384 385 void EnableBorderHighlight(bool); 386 387 protected: 388 virtual void WindowActivated(bool); 389 390 private: 391 bool fEnableBorderHighlight; 392 393 typedef BGroupView _inherited; 394 }; 395 396 397 int CompareLabels(const BMenuItem*, const BMenuItem*); 398 399 400 // inlines --------- 401 402 inline BNavigator* 403 BContainerWindow::Navigator() const 404 { 405 return fNavigator; 406 } 407 408 409 inline BPoseView* 410 BContainerWindow::PoseView() const 411 { 412 return fPoseView; 413 } 414 415 416 inline bool 417 BContainerWindow::IsTrash() const 418 { 419 return fIsTrash; 420 } 421 422 423 inline bool 424 BContainerWindow::InTrash() const 425 { 426 return fInTrash; 427 } 428 429 430 inline bool 431 BContainerWindow::IsPrintersDir() const 432 { 433 return fIsPrinters; 434 } 435 436 437 inline void 438 BContainerWindow::SetUpDiskMenu(BMenu*) 439 { 440 // nothing at this level 441 } 442 443 444 inline BPopUpMenu* 445 BContainerWindow::ContextMenu() 446 { 447 return fContextMenu; 448 } 449 450 451 inline bool 452 BContainerWindow::Dragging() const 453 { 454 return fDragMessage && fCachedTypesList; 455 } 456 457 458 inline BMessage* 459 BContainerWindow::DragMessage() const 460 { 461 return fDragMessage; 462 } 463 464 465 inline bool 466 BContainerWindow::SaveStateIsEnabled() const 467 { 468 return fSaveStateIsEnabled; 469 } 470 471 472 inline void 473 BContainerWindow::SetSaveStateEnabled(bool value) 474 { 475 fSaveStateIsEnabled = value; 476 } 477 478 479 inline bool 480 BContainerWindow::IsPathWatchingEnabled() const 481 { 482 return fIsWatchingPath; 483 } 484 485 486 filter_result ActivateWindowFilter(BMessage* message, BHandler** target, 487 BMessageFilter* messageFilter); 488 489 } // namespace BPrivate 490 491 using namespace BPrivate; 492 493 494 #endif // _CONTAINER_WINDOW_H 495