Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Cyberdog Programmer's Kit / Part 2 - Programming in Cyberdog
Chapter 5 - Embedding a Cyberdog Display Part in a Navigator


Opening a New Cyberdog Item in the Same Navigator

Your embedded display part may need to open a Cyberdog item and display it in the same navigator that embeds your part. To handle this situation, you must pass a reference to the navigator when you call the Cyberdog item's Open method. You must choose the navigator to open the Cyberdog item in and a use parameter set to specify the navigator. Specify the parameter's key as kCDInitialOpenerPartKey.

Listing 5-4 shows an example from the embedded text-viewer's HandleMenuEvent method.

Listing 5-4 Opening a Cyberdog item from an embedded display part

{
   TempParameterSet params = kODNULL;

   // Create a Cyberdog item
   char* url = "http://www.Cyberdog.apple.com";
   TempCyberItem item 
            = GetCyberSession(ev)->CreateCyberItemFromURL(ev, url);
   
   // Find the navigator in which this part is embedded.
   ODPart* navPart = this->GetContainingNavigator(ev);
   if (navPart)
   {
      // Create and initialize a parameter set object.
      params = new ParameterSet;
      params->IParameterSet(ev);
      
      // Add the navigator to the parameter set as the 
      // "initial opener part."
      params->PutParameter(ev, kCDInitialOpenerPartKey, navPart, nil);
   }
      
   // Open the Cyberdog item.
   item->Open(ev, params);
}
Listing 5-5 shows the embedded text-viewer part's GetContainingNavigator method. The method iterates over its display frames and calls the Cyberdog session's AcquireContainingNavigatorPart method to determine if the frame is in a navigator. If so, the GetContainingNavigator method returns a reference to the navigator.

Listing 5-5 The GetContainingNavigator method of the embedded text-viewer part

ODPart*CybTxtNavViewer::GetContainingNavigator(Environment* ev)
{
   ODPart* navPart = kODNULL;
   CyberSession* cyberSession = GetCyberSession(ev);
   CListIterator fiter(fDisplayFrames);
   CFrameProxy* proxy;
   
   while ((proxy = (CFrameProxy*) fiter.Next()) != nil)
   {
      navPart = cyberSession->AcquireContainingNavigatorPart
                                 (ev, proxy->GetFrame(ev));
      if (navPart)
      {
         navPart->Release(ev);
         break;
      }
   }
   return navPart;
}

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996