home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / dynamicp / bclipbrd / clpmnuev.c < prev   
Text File  |  1997-04-02  |  10KB  |  211 lines

  1. /*====START_GENERATED_PROLOG======================================
  2.  */
  3. /*
  4.  *   COMPONENT_NAME: oddynamicpart
  5.  *
  6.  *   CLASSES: none
  7.  *
  8.  *   ORIGINS: 82,27
  9.  *
  10.  *
  11.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12.  *   All Rights Reserved
  13.  *   Licensed Materials - Property of IBM
  14.  *   US Government Users Restricted Rights - Use, duplication or
  15.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16.  *
  17.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23.  *   OR PERFORMANCE OF THIS SOFTWARE.
  24.  */
  25. /*====END_GENERATED_PROLOG========================================
  26.  */
  27. /* @(#) 1.4 com/src/samples/dynamicp/bclipbrd/clpmnuev.c, oddynamicpart, od96os2, odos29712d 2/18/97 14:00:00 [3/21/97 17:48:06]
  28. *******************************************************************
  29. ** Name: ODBoolean HandleMenuEvent
  30. **
  31. ** Description:  Handle user requests for clipboard copy and paste.
  32. **
  33. *******************************************************************
  34. */
  35. {
  36. #ifdef _PLATFORM_OS2_
  37.    ODCommandID command = LONGFROMMP(event->mp1);
  38. #elif defined(_PLATFORM_WIN32_)
  39.    ODCommandID command = LOWORD(event->wParam);
  40. #endif
  41.    switch (command) {
  42.    case EDIT_COPY:
  43.    {
  44.      // copy contents to clipboard
  45.       ODClipboard   *clipboard      = _fSession->GetClipboard(ev);
  46.       ODArbitrator  *arbitrator     = _fSession->GetArbitrator( ev );
  47.       ODTypeToken    clipboardFocus = _fSession->Tokenize( ev, kODClipboardFocus );
  48.       // request the clipboard focus
  49.       if (arbitrator->RequestFocus( ev, clipboardFocus, FocusFrame ))
  50.       {
  51.          clipboard->Clear( ev );
  52.          ODStorageUnit* clipRootSU = clipboard->GetContentStorageUnit(ev);
  53.  
  54.          ODDraft* fromDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  55.          ODDraft* toDraft   = clipRootSU->GetDraft(ev);
  56.  
  57.          // modify clipboard
  58.  
  59.          // Initiate the cloning operation.
  60.          ODDraftKey key  = fromDraft->BeginClone(ev, toDraft, kODNULL, kODCloneCopy);
  61.          // now clone self into the clipboard.  This should be done throught the draft object.
  62.          fromDraft->Clone(ev, key, somSelf->GetID(ev), clipRootSU->GetID(ev), FocusFrame->GetID(ev));
  63.          // commit the cloning operation.
  64.          fromDraft->EndClone(ev, key);
  65.  
  66.          // put OpenDoc clipboard data into the system clipboard.
  67.          clipboard->ExportClipboard( ev);
  68.  
  69.          // finished with clipboard focus.
  70.          arbitrator->RelinquishFocus( ev, clipboardFocus, FocusFrame );
  71.       }
  72.  
  73.       handled = kODTrue;
  74.       }
  75.       break;
  76.    case EDIT_PASTE:
  77.       {
  78.       // paste from clipboard.
  79.       ODClipboard*   clipboard = _fSession->GetClipboard(ev);
  80.       ODArbitrator  *arbitrator     = _fSession->GetArbitrator( ev );
  81.       ODTypeToken    clipboardFocus = _fSession->Tokenize( ev, kODClipboardFocus );
  82.       if (arbitrator->RequestFocus( ev, clipboardFocus, FocusFrame )) {
  83.          ODStorageUnit* su = clipboard->GetContentStorageUnit( ev );
  84.          if (su->Exists(ev, kODPropContents, kKindTestDynamicPart, 0) ) {
  85.            // Clipboard contains a DynamicPart, so internalize that part's data.
  86.            // This code is similar to the code used in InitPartFromStorage,  but
  87.            // contains some slight differences to account for timers, etc.
  88.            su->Focus(ev, kODPropContents, kODPosUndefined, kKindTestDynamicPart, 0, kODPosUndefined);
  89.            _scrollTimerRate  = ODGetSLongProp(ev, su, kODNULL, kODNULL);
  90.            _rotateTimerRate  = ODGetSLongProp(ev, su, kODNULL, kODNULL);
  91.            _JumpRate         = ODGetSLongProp(ev, su, kODNULL, kODNULL);
  92.            _ScrollPos        = ODGetSLongProp(ev, su, kODNULL, kODNULL);
  93.            _fFrameNegotiated = ODGetBooleanProp(ev, su, kODNULL, kODNULL);
  94.          // saved color attributes.
  95.            ODSByte colorMix = 0;
  96.            _customBackground = ODGetBooleanProp(ev, su, kODNULL, kODNULL);
  97.            if (_customBackground) {
  98.              StorageUnitGetValue(su, ev, sizeof(colorMix), &colorMix); _BackColor.setRed(colorMix);
  99.              StorageUnitGetValue(su, ev, sizeof(colorMix), &colorMix); _BackColor.setGreen(colorMix);
  100.              StorageUnitGetValue(su, ev, sizeof(colorMix), &colorMix); _BackColor.setBlue(colorMix);
  101.            } /* endif */
  102.            _customTextColor  = ODGetBooleanProp(ev, su, kODNULL, kODNULL);
  103.            if (_customTextColor) {
  104.              StorageUnitGetValue(su, ev, sizeof(colorMix), &colorMix); _TextColor.setRed(colorMix);
  105.              StorageUnitGetValue(su, ev, sizeof(colorMix), &colorMix); _TextColor.setGreen(colorMix);
  106.              StorageUnitGetValue(su, ev, sizeof(colorMix), &colorMix); _TextColor.setBlue(colorMix);
  107.            } /* endif */
  108.          // saved angles in degrees -- must convert to radians for c trig functions.
  109.            ODSLong degrees = 0;
  110.            degrees = ODGetSLongProp(ev, su, kODNULL, kODNULL);
  111.            ODFloat xRotAngle = degrees * pi / 180;
  112.            degrees = ODGetSLongProp(ev, su, kODNULL, kODNULL);
  113.            ODFloat xAngleDelta = degrees * pi / 180;
  114.            degrees = ODGetSLongProp(ev, su, kODNULL, kODNULL);
  115.            ODFloat hShearAngle = degrees * pi / 180;
  116.            degrees = ODGetSLongProp(ev, su, kODNULL, kODNULL);
  117.            ODFloat vShearAngle = degrees * pi / 180;
  118.  
  119.          // are we scrolling/rotating
  120.            somSelf->_set_scrolling(ev, ODGetBooleanProp(ev, su, kODNULL, kODNULL));
  121.            somSelf->_set_xRotateActive(ev, ODGetBooleanProp(ev, su, kODNULL, kODNULL));
  122.            somSelf->_set_hShearActive(ev, ODGetBooleanProp(ev, su, kODNULL, kODNULL));
  123.            somSelf->_set_vShearActive(ev, ODGetBooleanProp(ev, su, kODNULL, kODNULL));
  124.          // which directions
  125.            somSelf->_set_xRotateClockwise(ev, ODGetBooleanProp(ev, su, kODNULL, kODNULL));
  126.            somSelf->_set_hShearRight(ev, ODGetBooleanProp(ev, su, kODNULL, kODNULL));
  127.            somSelf->_set_vShearUp(ev, ODGetBooleanProp(ev, su, kODNULL, kODNULL));
  128.  
  129.          // now get the font
  130.            _customFont = ODGetBooleanProp(ev, su, kODNULL, kODNULL);
  131.            if (_customFont) {
  132.              ODULong fontNameLength = 0;
  133.              char *fontName = NULL;
  134.              fontName = ODGetISOStrProp(ev, su, kODPropContents, kODISOStr, fontName, &fontNameLength);
  135.              if (fontName) {
  136.                 _Font->setName(fontName);
  137.                 _Message->setFont(*_Font);
  138.                 // memory was allocated by ODGetISOStrProp, so use SOMFree to free it.
  139.                 SOMFree(fontName);
  140.              } /* endif */
  141.            } /* endif */
  142.  
  143.          // now get the text value
  144.            ODULong msgLength = 0;
  145.            char *msgText = NULL;
  146.            msgText = ODGetISOStrProp(ev, su, kODPropContents, kODISOStr, msgText, &msgLength);
  147.            if (msgText) {
  148.               _Message->setText(msgText);
  149.               // memory was allocated by ODGetISOStrProp, so use SOMFree to free it.
  150.               SOMFree(msgText);
  151.            } else {
  152.              // couldn't read the text, so turn off scrolling
  153.              _scrolling = kODFalse;
  154.            } /* endif */
  155.            msgText = NULL;
  156.            somSelf->_set_xRotAngle(ev, xRotAngle);
  157.            somSelf->_set_xAngleDelta(ev, xAngleDelta);
  158.            somSelf->_set_hShearAngle(ev, hShearAngle);
  159.            somSelf->_set_vShearAngle(ev, vShearAngle);
  160.          //somSelf->RotateContent(ev, 0.0);
  161.          //somSelf->SetInternalXform(ev, FocusFrame);
  162.          } /* endif */
  163.  
  164.          // get a text value if one exists
  165.          if (su->Exists(ev, kODPropContents, kODISOStr, 0) ) {
  166.            ODULong msgLength = 0;
  167.            char *msgText = NULL;
  168.            msgText = ODGetISOStrProp(ev, su, kODPropContents, kODISOStr, msgText, &msgLength);
  169.            if (msgText) {
  170.               IString message(msgText);
  171.               message.strip();
  172.               // be sure message ends with a single space
  173.               message += " ";
  174.               _Message->setText(message);
  175.               // memory was allocated by ODGetISOStrProp, so use SOMFree to free it.
  176.               SOMFree(msgText);
  177.            } /* endif */
  178.            msgText = NULL;
  179.          } else {
  180.            // try for a native clipboard text format.
  181.            ODValueType textType = _fSession->GetTranslation(ev)->
  182.                                  GetISOTypeFromPlatformType(ev, CF_TEXT, kODPlatformDataType);
  183.            if (su->Exists(ev, kODPropContents, textType, 0) ) {
  184.              ODULong msgLength = 0;
  185.              char *msgText = NULL;
  186.              msgText = ODGetISOStrProp(ev, su, kODPropContents, textType, msgText, &msgLength);
  187.              if (msgText) {
  188.                  IString message(msgText);
  189.                  message.strip();
  190.                  // be sure message ends with a single space
  191.                  message += " ";
  192.                 _Message->setText(message);
  193.                 // memory was allocated by ODGetISOStrProp, so use SOMFree to free it.
  194.                 SOMFree(msgText);
  195.              } /* endif */
  196.              msgText = NULL;
  197.            } /* endif */
  198.          } /* endif */
  199.       } /* endif */
  200.       arbitrator->RelinquishFocus( ev, clipboardFocus, FocusFrame );
  201.       somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  202.       ODUpdateID updateID = _fSession->UniqueUpdateID(ev);
  203.       FocusFrame->ContentUpdated (ev, updateID);
  204.       handled = kODTrue;
  205.       }
  206.       break;
  207.    default:
  208.       break;
  209.    } /* endswitch */
  210. }
  211.