1/* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6#include "SubWindow.h" 7 8#include <AutoLocker.h> 9 10#include "SubWindowManager.h" 11 12 13// #pragma mark - SubWindowKey 14 15 16SubWindowKey::~SubWindowKey() 17{ 18} 19 20 21// #pragma mark - ObjectSubWindowKey 22 23 24ObjectSubWindowKey::ObjectSubWindowKey(void* object) 25 : 26 fObject(object) 27{ 28} 29 30 31bool 32ObjectSubWindowKey::Equals(const SubWindowKey* other) const 33{ 34 if (this == other) 35 return true; 36 37 const ObjectSubWindowKey* key 38 = dynamic_cast<const ObjectSubWindowKey*>(other); 39 return key != NULL && fObject == key->fObject; 40} 41 42 43size_t 44ObjectSubWindowKey::HashCode() const 45{ 46 return (size_t)(addr_t)fObject; 47} 48 49 50// #pragma mark - SubWindow 51 52 53SubWindow::SubWindow(SubWindowManager* manager, BRect frame, const char* title, 54 window_type type, uint32 flags, uint32 workspace) 55 : 56 BWindow(frame, title, type, flags, workspace), 57 fSubWindowManager(manager), 58 fSubWindowKey(NULL) 59 60{ 61 fSubWindowManager->AcquireReference(); 62} 63 64 65SubWindow::~SubWindow() 66{ 67 RemoveFromSubWindowManager(); 68 fSubWindowManager->ReleaseReference(); 69} 70 71 72bool 73SubWindow::AddToSubWindowManager(SubWindowKey* key) 74{ 75 AutoLocker<SubWindowManager> locker(fSubWindowManager); 76 77 fSubWindowKey = key; 78 79 if (!fSubWindowManager->AddSubWindow(this)) { 80 fSubWindowKey = NULL; 81 return false; 82 } 83 84 return true; 85} 86 87 88bool 89SubWindow::RemoveFromSubWindowManager() 90{ 91 if (fSubWindowKey == NULL) 92 return false; 93 94 fSubWindowManager->RemoveSubWindow(this); 95 delete fSubWindowKey; 96 fSubWindowKey = NULL; 97 return true; 98} 99