Esempio n. 1
0
 virtual void select()
 {
     std::cout << "Selection of item #" << selected() << " : \"" << selectedText() << "\" (" << *(int*)selectedData() << ")." << std::endl;
 }
Esempio n. 2
0
 virtual void enter()
 {
     std::cout << "Entered item #" << selected() << " : \"" << selectedText() << "\" (" << *(int*)selectedData() << ")." << std::endl;
 }
/*------------------------------------------------------------------------------
| ContainerCutPasteHandler::command                                            |
|                                                                              |
| Handle the command events associated with the clipboard (Cut, Copy,          |
| and Paste).                                                                  |
------------------------------------------------------------------------------*/
bool ContainerCutPasteHandler::command ( ICommandEvent& event)
{
  switch(event.commandId())
  {
    case MI_CUT           :
    case MI_COPY          :
    {

      // Create a clipboard object.
      IClipboard clipboard(event.controlWindow()->handle());


      // Find the cursored object in the container.
      Department* cursoredObject = (Department*)(container().cursoredObject());

      // If a Copy request, utilize delayed rendering to put the data of
      // of the private format on the clipboard. If a Cut request, put
      // the data directly on the clipboard since the object won't be
      // around later when the renderFormat code needs it.
      // We maintain an "objectList" collection to keep track of 
      // the objects copied onto the clipboard so that renderFormat
      // knows which objects to render.
      // We also store text data for the objects so that applications
      // that don't support the private format can paste the data into a
      // text editor.

      // Clear the collection used to keep track of clipboard objects.
      objectList->removeAll();

      // If the cursored object is selected, loop through all other
      // selected objects and store the objects in our set.
      if (container().isSelected(cursoredObject))
      {
        unsigned long count = 0;
        IString objectsAsText("\0");
        IContainerControl::ObjectCursor cursor(container(), IContainerObject::selected);
        for (cursor.setToFirst(); cursor.isValid(); cursor.setToNext())
        {
          count++;
          Department* selectedObject = (Department*)(container().objectAt(cursor));
          objectList->add(selectedObject);
          objectsAsText = objectsAsText +  selectedObject->text();
        }


        // Empty the clipboard to establish ownership
        clipboard.empty();

        // Put the data on the clipboard.  We put our private
        // format first since it has the most information.
        // We use 0 for the data on a Copy request because
        // we want to delay the rendering until
        // the paste operation.
        // If this is a Cut, put the data on the clipboard
        // instead of using delayed rendering because we delete
        // the object.

        if (event.commandId() == MI_CUT)
        {
          IString string = selectedData();
          clipboard.setData(Department::renderedFormat, (const char*)string, string.length()+1);
          objectList->removeAll();
          container().deleteSelectedObjects();
        }
        else
          clipboard.setData(Department::renderedFormat, 0, 0);
        
        clipboard.setText(objectsAsText);
      }
      else
      {
        // If the object is not selected, repeat the above procedure
        // for the cursored object.
        objectList->add(cursoredObject);

        // Empty the clipboard to establish ownership
        clipboard.empty();

        // Put the data on the clipboard (using
        // delayed rendering for a Copy. Delete the object
        // if a Cut request.
        IString objectAsText = cursoredObject->text();
        if (event.commandId() == MI_CUT)
        {
           IString string = selectedData();
           clipboard.setData(Department::renderedFormat, (const char*)string, string.length()+1);
           objectList->removeAll();
           container().removeObject(cursoredObject);
           delete cursoredObject;
        }
        else
          clipboard.setData(Department::renderedFormat, 0,0);

        clipboard.setText(objectAsText);
      }
      return true;
    }
    case MI_PASTE         :
    {
      IClipboard clipboard(event.controlWindow()->handle());

      // If the clipboard has data of the private format,
      // get the data and build objects from it.
      // Note:  To see the text format of the data, paste
      // from the clipboard using any text editor that
      // supports the clipboard.
      if (clipboard.hasData(Department::renderedFormat))
      {
         IString strCount, strObject, objectsAsString;

         // Query the data on the clipboard.
         char* data = (char*)clipboard.data(Department::renderedFormat);

         // Parse the string into our data fields.
         data >> strCount >> separator >> objectsAsString;

         // Extract the number of objects stored in the string.
         unsigned long count = strCount.asUnsigned();

         // Turn refresh off to eliminate multiple painting.
         container().setRefreshOff();

         // Construct new objects from the data.
         for( int i=0; i<count; i++)
         {
           objectsAsString >> strObject >> separator >> objectsAsString;
           Department* department = new Department();
           department->initializeFromString(strObject);
           container().addObject(department);
         }

         // Enable refresh and refresh the container.
         container().setRefreshOn();
         container().refresh();
      }
      return true;
    }
  }