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*), void*, BStringList&); 193 194 BPopUpMenu* ContextMenu(); 195 196 // drag&drop support 197 status_t DragStart(const BMessage*); 198 void DragStop(); 199 bool Dragging() const; 200 BMessage* DragMessage() const; 201 202 void ShowSelectionWindow(); 203 204 void ShowNavigator(bool); 205 void SetSingleWindowBrowseShortcuts(bool); 206 207 void SetPathWatchingEnabled(bool); 208 bool IsPathWatchingEnabled(void) const; 209 210 protected: 211 virtual BPoseView* NewPoseView(Model*, uint32); 212 // instantiate a different flavor of BPoseView for different 213 // ContainerWindows 214 215 virtual void RestoreWindowState(AttributeStreamNode*); 216 virtual void RestoreWindowState(const BMessage &); 217 virtual void SaveWindowState(AttributeStreamNode*); 218 virtual void SaveWindowState(BMessage&) const; 219 220 virtual bool NeedsDefaultStateSetup(); 221 virtual void SetUpDefaultState(); 222 // these two virtuals control setting up a new folder that 223 // does not have any state settings yet with the default 224 225 virtual void AddMenus(); 226 virtual void AddShortcuts(); 227 // add equivalents of the menu shortcuts to the menuless 228 // desktop window 229 virtual void AddFileMenu(BMenu* menu); 230 virtual void AddWindowMenu(BMenu* menu); 231 232 virtual void AddContextMenus(); 233 234 virtual void AddFileContextMenus(BMenu*); 235 virtual void AddWindowContextMenus(BMenu*); 236 virtual void AddVolumeContextMenus(BMenu*); 237 virtual void AddDropContextMenus(BMenu*); 238 virtual void AddTrashContextMenus(BMenu*); 239 240 virtual void RepopulateMenus(); 241 void PopulateArrangeByMenu(BMenu*); 242 243 virtual void SetCutItem(BMenu*); 244 virtual void SetCopyItem(BMenu*); 245 virtual void SetPasteItem(BMenu*); 246 virtual void SetArrangeMenu(BMenu*); 247 virtual void SetCloseItem(BMenu*); 248 virtual void SetupNavigationMenu(const entry_ref*, BMenu*); 249 virtual void SetupMoveCopyMenus(const entry_ref*, BMenu*); 250 virtual void PopulateMoveCopyNavMenu(BNavMenu*, uint32, 251 const entry_ref*, bool); 252 253 virtual void SetupOpenWithMenu(BMenu*); 254 virtual void SetUpEditQueryItem(BMenu*); 255 virtual void SetUpDiskMenu(BMenu*); 256 257 virtual void BuildAddOnMenu(BMenu*); 258 void BuildMimeTypeList(BStringList& mimeTypes); 259 260 enum UpdateMenuContext { 261 kMenuBarContext, 262 kPosePopUpContext, 263 kWindowPopUpContext 264 }; 265 266 virtual void UpdateMenu(BMenu* menu, UpdateMenuContext context); 267 268 BMenu* AddMimeMenu(const BMimeType& mimeType, bool isSuperType, 269 BMenu* menu, int32 start); 270 271 BHandler* ResolveSpecifier(BMessage*, int32, BMessage*, int32, 272 const char*); 273 274 bool EachAddon(BPath &path, 275 bool (*)(const Model*, const char*, uint32, bool, void*), 276 BObjectList<Model>*, void*, BStringList&); 277 void LoadAddOn(BMessage*); 278 279 bool fUseLayouts; 280 BGroupLayout* fRootLayout; 281 BGroupView* fMenuContainer; 282 BGridView* fPoseContainer; 283 BorderedView* fBorderedView; 284 BGroupView* fVScrollBarContainer; 285 BGroupView* fCountContainer; 286 287 BPopUpMenu* fFileContextMenu; 288 BPopUpMenu* fWindowContextMenu; 289 BPopUpMenu* fDropContextMenu; 290 BPopUpMenu* fVolumeContextMenu; 291 BPopUpMenu* fTrashContextMenu; 292 BSlowContextMenu* fDragContextMenu; 293 BMenuItem* fMoveToItem; 294 BMenuItem* fCopyToItem; 295 BMenuItem* fCreateLinkItem; 296 BMenuItem* fOpenWithItem; 297 ModelMenuItem* fNavigationItem; 298 BMenuBar* fMenuBar; 299 DraggableContainerIcon* fDraggableIcon; 300 BNavigator* fNavigator; 301 BPoseView* fPoseView; 302 LockingList<BWindow>* fWindowList; 303 BMenu* fAttrMenu; 304 BMenu* fWindowMenu; 305 BMenu* fFileMenu; 306 BMenu* fArrangeByMenu; 307 308 SelectionWindow* fSelectionWindow; 309 310 PiggybackTaskLoop* fTaskLoop; 311 312 bool fIsTrash; 313 bool fInTrash; 314 bool fIsPrinters; 315 bool fIsDesktop; 316 317 uint32 fContainerWindowFlags; 318 BackgroundImage* fBackgroundImage; 319 320 static LockingList<struct AddonShortcut>* fAddonsList; 321 322 private: 323 BRect fSavedZoomRect; 324 BRect fPreviousBounds; 325 326 static BRect sNewWindRect; 327 328 BPopUpMenu* fContextMenu; 329 BMessage* fDragMessage; 330 BObjectList<BString>* fCachedTypesList; 331 bool fWaitingForRefs; 332 333 bool fStateNeedsSaving; 334 bool fSaveStateIsEnabled; 335 336 bool fIsWatchingPath; 337 338 typedef BWindow _inherited; 339 340 friend int32 show_context_menu(void*); 341 friend class BackgroundView; 342 343 void _UpdateSelectionMIMEInfo(); 344 void _AddFolderIcon(); 345 }; 346 347 348 class WindowStateNodeOpener { 349 // this class manages opening and closing the proper node for 350 // state restoring / saving; the constructor knows how to decide whether 351 // to use a special directory for root, etc. 352 // setter calls used when no attributes can be read from a node and 353 // defaults are to be substituted 354 public: 355 WindowStateNodeOpener(BContainerWindow* window, bool forWriting); 356 virtual ~WindowStateNodeOpener(); 357 358 void SetTo(const BDirectory*); 359 void SetTo(const BEntry* entry, bool forWriting); 360 void SetTo(Model*, bool forWriting); 361 362 AttributeStreamNode* StreamNode() const; 363 BNode* Node() const; 364 365 private: 366 ModelNodeLazyOpener* fModelOpener; 367 BNode* fNode; 368 AttributeStreamNode* fStreamNode; 369 }; 370 371 372 class BorderedView : public BGroupView { 373 public: 374 BorderedView(); 375 376 void PoseViewFocused(bool); 377 virtual void Pulse(); 378 379 void EnableBorderHighlight(bool); 380 381 protected: 382 virtual void WindowActivated(bool); 383 384 private: 385 bool fEnableBorderHighlight; 386 387 typedef BGroupView _inherited; 388 }; 389 390 391 int CompareLabels(const BMenuItem*, const BMenuItem*); 392 393 394 // inlines --------- 395 396 inline BNavigator* 397 BContainerWindow::Navigator() const 398 { 399 return fNavigator; 400 } 401 402 403 inline BPoseView* 404 BContainerWindow::PoseView() const 405 { 406 return fPoseView; 407 } 408 409 410 inline bool 411 BContainerWindow::IsTrash() const 412 { 413 return fIsTrash; 414 } 415 416 417 inline bool 418 BContainerWindow::InTrash() const 419 { 420 return fInTrash; 421 } 422 423 424 inline bool 425 BContainerWindow::IsPrintersDir() const 426 { 427 return fIsPrinters; 428 } 429 430 431 inline void 432 BContainerWindow::SetUpDiskMenu(BMenu*) 433 { 434 // nothing at this level 435 } 436 437 438 inline BPopUpMenu* 439 BContainerWindow::ContextMenu() 440 { 441 return fContextMenu; 442 } 443 444 445 inline bool 446 BContainerWindow::Dragging() const 447 { 448 return fDragMessage && fCachedTypesList; 449 } 450 451 452 inline BMessage* 453 BContainerWindow::DragMessage() const 454 { 455 return fDragMessage; 456 } 457 458 459 inline bool 460 BContainerWindow::SaveStateIsEnabled() const 461 { 462 return fSaveStateIsEnabled; 463 } 464 465 466 inline void 467 BContainerWindow::SetSaveStateEnabled(bool value) 468 { 469 fSaveStateIsEnabled = value; 470 } 471 472 473 inline bool 474 BContainerWindow::IsPathWatchingEnabled() const 475 { 476 return fIsWatchingPath; 477 } 478 479 480 filter_result ActivateWindowFilter(BMessage* message, BHandler** target, 481 BMessageFilter* messageFilter); 482 483 } // namespace BPrivate 484 485 using namespace BPrivate; 486 487 488 #endif // _CONTAINER_WINDOW_H 489