void TPeopleApp::RefsReceived(BMessage* message) { int32 index = 0; while (message->HasRef("refs", index)) { entry_ref ref; message->FindRef("refs", index++, &ref); PersonWindow* window = _FindWindow(ref); if (window != NULL) { window->Activate(true); } else { BFile* file = new BFile(&ref, B_READ_WRITE); if (file->InitCheck() == B_OK) _NewWindow(&ref, file); } } }
PersonWindow* TPeopleApp::_NewWindow(const entry_ref* ref, BFile* file) { BRawContact* rawContact; if (file == NULL) rawContact = new BRawContact(B_CONTACT_FORMAT); else rawContact = new BRawContact(B_CONTACT_ANY, file); BContact* contact = new BContact(rawContact); if (contact->InitCheck() != B_OK) { BAlert *alert = new BAlert("Alert", B_TRANSLATE("Contact initialization failed!."),"OK"); alert->Go(); return NULL; } PersonWindow* window = new PersonWindow(fPosition, B_TRANSLATE("New contact"), ref, file, contact); window->Show(); window->Activate(true); fWindowCount++; // Offset the position for the next window which will be opened and // reset it if it would open outside the screen bounds. fPosition.OffsetBy(20, 20); BScreen screen(window); if (fPosition.bottom > screen.Frame().bottom) fPosition.OffsetTo(fPosition.left, TITLE_BAR_HEIGHT); if (fPosition.right > screen.Frame().right) fPosition.OffsetTo(6, fPosition.top); return window; }