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 35 #ifndef _CONTAINER_WINDOW_H 36 #define _CONTAINER_WINDOW_H 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 | B_NO_WORKSPACE_ACTIVATION, 82 uint32 workspace = B_CURRENT_WORKSPACE); 83 84 virtual ~BContainerWindow(); 85 86 virtual void Init(const BMessage *message = NULL); 87 88 static BRect InitialWindowRect(window_feel); 89 90 virtual void Minimize(bool minimize); 91 virtual void Quit(); 92 virtual bool QuitRequested(); 93 94 virtual void UpdateIfTrash(Model *); 95 96 virtual void CreatePoseView(Model *); 97 98 virtual void ShowContextMenu(BPoint, const entry_ref *, BView *); 99 virtual uint32 ShowDropContextMenu(BPoint); 100 virtual void MenusBeginning(); 101 virtual void MenusEnded(); 102 virtual void MessageReceived(BMessage *); 103 virtual void FrameResized(float, float); 104 virtual void FrameMoved(BPoint); 105 virtual void Zoom(BPoint, float, float); 106 virtual void WorkspacesChanged(uint32, uint32); 107 108 // virtuals that control setup of window 109 virtual bool ShouldAddMenus() const; 110 virtual bool ShouldAddScrollBars() const; 111 virtual bool ShouldAddCountView() const; 112 113 virtual void CheckScreenIntersect(); 114 115 bool IsTrash() const; 116 bool InTrash() const; 117 bool IsPrintersDir() const; 118 119 virtual bool IsShowing(const node_ref *) const; 120 virtual bool IsShowing(const entry_ref *) const; 121 122 void ResizeToFit(); 123 124 Model *TargetModel() const; 125 BPoseView *PoseView() const; 126 BNavigator *Navigator() const; 127 128 virtual void SelectionChanged(); 129 virtual void ViewModeChanged(uint32 oldMode, uint32 newMode); 130 131 virtual void RestoreState(); 132 virtual void RestoreState(const BMessage &); 133 void RestoreStateCommon(); 134 virtual void SaveState(bool hide = true); 135 virtual void SaveState(BMessage &) const; 136 void UpdateTitle(); 137 138 bool StateNeedsSaving() const; 139 bool SaveStateIsEnabled() const; 140 void SetSaveStateEnabled(bool); 141 142 void UpdateBackgroundImage(); 143 144 static status_t GetLayoutState(BNode *, BMessage *); 145 static status_t SetLayoutState(BNode *, const BMessage *); 146 // calls for inheriting window size, attribute layout, etc. 147 // deprecated 148 149 virtual void AddMimeTypesToMenu(BMenu *); 150 void AddMimeTypesToMenu(); 151 virtual void MarkAttributeMenu(BMenu *); 152 void MarkAttributeMenu(); 153 BMenuItem *NewAttributeMenuItem(const char *label, const char *name, 154 int32 type, float width, int32 align, bool editable, bool statField); 155 BMenuItem *NewAttributeMenuItem(const char *label, const char *name, 156 int32 type, const char* displayAs, float width, int32 align, 157 bool editable, bool statField); 158 virtual void NewAttributeMenu(BMenu *); 159 160 void HideAttributeMenu(); 161 void ShowAttributeMenu(); 162 PiggybackTaskLoop *DelayedTaskLoop(); 163 // use for RunLater queueing 164 void PulseTaskLoop(); 165 // called by some view that has pulse, either BackgroundView or BPoseView 166 167 static bool DefaultStateSourceNode(const char *name, BNode *result, 168 bool createNew = false, bool createFolder = true); 169 170 // add-on iteration 171 void EachAddon(bool(*)(const Model *, const char *, uint32 shortcut, bool primary, void *), void *); 172 173 BPopUpMenu *ContextMenu(); 174 175 // drag&drop support 176 status_t DragStart(const BMessage *); 177 void DragStop(); 178 bool Dragging() const; 179 BMessage *DragMessage() const; 180 181 void ShowSelectionWindow(); 182 183 void ShowNavigator(bool); 184 void SetSingleWindowBrowseShortcuts(bool); 185 186 void SetPathWatchingEnabled(bool); 187 bool IsPathWatchingEnabled(void) const; 188 189 protected: 190 virtual BPoseView *NewPoseView(Model *, BRect, uint32); 191 // instantiate a different flavor of BPoseView for different 192 // ContainerWindows 193 194 virtual void RestoreWindowState(AttributeStreamNode *); 195 virtual void RestoreWindowState(const BMessage &); 196 virtual void SaveWindowState(AttributeStreamNode *); 197 virtual void SaveWindowState(BMessage &) const; 198 199 virtual bool NeedsDefaultStateSetup(); 200 virtual void SetUpDefaultState(); 201 // these two virtuals control setting up a new folder that 202 // does not have any state settings yet with the default 203 204 virtual void AddMenus(); 205 virtual void AddShortcuts(); 206 // add equivalents of the menu shortcuts to the menuless desktop window 207 virtual void AddFileMenu(BMenu *menu); 208 virtual void AddWindowMenu(BMenu *menu); 209 210 virtual void AddContextMenus(); 211 212 virtual void AddFileContextMenus(BMenu *); 213 virtual void AddWindowContextMenus(BMenu *); 214 virtual void AddVolumeContextMenus(BMenu *); 215 virtual void AddDropContextMenus(BMenu *); 216 217 virtual void RepopulateMenus(); 218 219 virtual void SetCutItem(BMenu *); 220 virtual void SetCopyItem(BMenu *); 221 virtual void SetPasteItem(BMenu *); 222 virtual void SetCleanUpItem(BMenu *); 223 virtual void SetCloseItem(BMenu *); 224 virtual void SetupNavigationMenu(const entry_ref *, BMenu *); 225 virtual void SetupMoveCopyMenus(const entry_ref *, BMenu *); 226 virtual void PopulateMoveCopyNavMenu(BNavMenu *, uint32, const entry_ref *, bool); 227 228 virtual void SetupOpenWithMenu(BMenu *); 229 virtual void SetUpEditQueryItem(BMenu *); 230 virtual void SetUpDiskMenu(BMenu *); 231 232 virtual void BuildAddOnMenu(BMenu *); 233 234 enum UpdateMenuContext { 235 kMenuBarContext, 236 kPosePopUpContext, 237 kWindowPopUpContext 238 }; 239 240 virtual void UpdateMenu(BMenu *menu, UpdateMenuContext context); 241 242 BMenu* AddMimeMenu(const BMimeType& mimeType, bool isSuperType, 243 BMenu* menu, int32 start); 244 245 BHandler *ResolveSpecifier(BMessage *, int32, BMessage *, int32, 246 const char *); 247 248 bool EachAddon(BPath &path, bool(*)(const Model *, const char *, uint32, bool, void *), 249 BObjectList<Model> *, void *); 250 void LoadAddOn(BMessage *); 251 252 BPopUpMenu *fFileContextMenu; 253 BPopUpMenu *fWindowContextMenu; 254 BPopUpMenu *fDropContextMenu; 255 BPopUpMenu *fVolumeContextMenu; 256 BSlowContextMenu *fDragContextMenu; 257 BMenuItem *fMoveToItem; 258 BMenuItem *fCopyToItem; 259 BMenuItem *fCreateLinkItem; 260 BMenuItem *fOpenWithItem; 261 ModelMenuItem *fNavigationItem; 262 BMenuBar *fMenuBar; 263 BNavigator *fNavigator; 264 BPoseView *fPoseView; 265 LockingList<BWindow> *fWindowList; 266 BMenu *fAttrMenu; 267 BMenu *fWindowMenu; 268 BMenu *fFileMenu; 269 270 SelectionWindow *fSelectionWindow; 271 272 PiggybackTaskLoop *fTaskLoop; 273 274 bool fIsTrash; 275 bool fInTrash; 276 bool fIsPrinters; 277 278 uint32 fContainerWindowFlags; 279 BackgroundImage *fBackgroundImage; 280 281 private: 282 BRect fSavedZoomRect; 283 BRect fPreviousBounds; 284 285 static BRect sNewWindRect; 286 287 BPopUpMenu *fContextMenu; 288 BMessage *fDragMessage; 289 BObjectList<BString> *fCachedTypesList; 290 bool fWaitingForRefs; 291 292 bool fStateNeedsSaving; 293 bool fSaveStateIsEnabled; 294 295 bool fIsWatchingPath; 296 297 typedef BWindow _inherited; 298 299 friend int32 show_context_menu(void*); 300 friend class BackgroundView; 301 }; 302 303 class WindowStateNodeOpener { 304 // this class manages opening and closing the proper node for 305 // state restoring / saving; the constructor knows how to decide wether 306 // to use a special directory for root, etc. 307 // setter calls used when no attributes can be read from a node and defaults 308 // are to be substituted 309 public: 310 WindowStateNodeOpener(BContainerWindow *window, bool forWriting); 311 virtual ~WindowStateNodeOpener(); 312 313 void SetTo(const BDirectory *); 314 void SetTo(const BEntry *entry, bool forWriting); 315 void SetTo(Model *, bool forWriting); 316 317 AttributeStreamNode *StreamNode() const; 318 BNode *Node() const; 319 320 private: 321 ModelNodeLazyOpener *fModelOpener; 322 BNode *fNode; 323 AttributeStreamNode *fStreamNode; 324 }; 325 326 class BackgroundView : public BView { 327 // background view placed in a BContainerWindow, under the pose view 328 public: 329 BackgroundView(BRect); 330 virtual void AttachedToWindow(); 331 virtual void FrameResized(float, float); 332 virtual void Draw(BRect); 333 334 void PoseViewFocused(bool); 335 virtual void Pulse(); 336 337 protected: 338 virtual void WindowActivated(bool); 339 340 private: 341 typedef BView _inherited; 342 }; 343 344 int CompareLabels(const BMenuItem *, const BMenuItem *); 345 346 // inlines --------- 347 348 inline BNavigator * 349 BContainerWindow::Navigator() const 350 { 351 return fNavigator; 352 } 353 354 inline BPoseView * 355 BContainerWindow::PoseView() const 356 { 357 return fPoseView; 358 } 359 360 inline bool 361 BContainerWindow::IsTrash() const 362 { 363 return fIsTrash; 364 } 365 366 inline bool 367 BContainerWindow::InTrash() const 368 { 369 return fInTrash; 370 } 371 372 inline bool 373 BContainerWindow::IsPrintersDir() const 374 { 375 return fIsPrinters; 376 } 377 378 inline void 379 BContainerWindow::SetUpDiskMenu(BMenu *) 380 { 381 // nothing at this level 382 } 383 384 inline BPopUpMenu * 385 BContainerWindow::ContextMenu() 386 { 387 return fContextMenu; 388 } 389 390 inline bool 391 BContainerWindow::Dragging() const 392 { 393 return fDragMessage && fCachedTypesList; 394 } 395 396 inline BMessage * 397 BContainerWindow::DragMessage() const 398 { 399 return fDragMessage; 400 } 401 inline 402 bool 403 BContainerWindow::SaveStateIsEnabled() const 404 { 405 return fSaveStateIsEnabled; 406 } 407 408 inline 409 void 410 BContainerWindow::SetSaveStateEnabled(bool value) 411 { 412 fSaveStateIsEnabled = value; 413 } 414 415 inline 416 bool 417 BContainerWindow::IsPathWatchingEnabled() const 418 { 419 return fIsWatchingPath; 420 } 421 422 filter_result ActivateWindowFilter(BMessage *message, BHandler **target, 423 BMessageFilter *messageFilter); 424 425 } // namespace BPrivate 426 427 using namespace BPrivate; 428 429 #endif 430