home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk21 / dir03 / f017970.re_ / f017970.re
Text File  |  1996-04-02  |  18KB  |  560 lines

  1. /*----------------------------------------------------------------------+
  2. |                                    |
  3. |  Copyright (1993-95) Bentley Systems, Inc., All rights reserved.         |
  4. |                                    |
  5. |  "MicroStation" is a registered trademark and "MDL" and "MicroCSL"    |
  6. |  are trademarks of Bentley Systems, Inc.                    |
  7. |                                    |
  8. |  Limited permission is hereby granted to reproduce and modify this    |
  9. |  copyrighted material provided that the resulting code is used only     |
  10. |  in conjunction with Bentley Systems products under the terms of the    |
  11. |  license agreement provided therein, and that this notice is retained    |
  12. |  in its entirety in any such reproduction or modification.        |
  13. |                                    |
  14. +----------------------------------------------------------------------*/
  15. /*----------------------------------------------------------------------+
  16. |                                    |
  17. |   $Workfile:   ntcbtext.mc  $
  18. |   $Revision:   5.4  $
  19. |       $Date:   26 Jul 1995 11:17:16  $
  20. |                                    |
  21. +----------------------------------------------------------------------*/
  22. /*----------------------------------------------------------------------+
  23. |                                    |
  24. |   Function -                                |
  25. |                                    |
  26. |    Clipboard hook for Windows NT                    |
  27. |                                    |
  28. |    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    |
  29. |                                    |
  30. |   Public Routine Summary -                        |
  31. |                                    |
  32. |                                    |
  33. +----------------------------------------------------------------------*/
  34. /*----------------------------------------------------------------------+
  35. |                                    |
  36. |   Include Files                               |
  37. |                                    |
  38. +----------------------------------------------------------------------*/
  39. #include    <mdl.h>
  40. #include    <dlogitem.h>
  41. #include    <clipbrd.h>
  42. #include    <wnclpext.h>
  43. #include    <tcb.h>
  44. #include    <stdarg.h>
  45. #include    <stdlib.h>
  46. #include    <string.h>
  47. #include    <stdio.h>
  48.  
  49. #include    "ntcbtext.h"
  50.  
  51. #include    <msrsrc.fdf>
  52. #include    <msrmatrx.fdf>
  53. #include    <mstmatrx.fdf>
  54. #include    <msstate.fdf>
  55. #include    <mselemen.fdf>
  56. #include    <mselmdsc.fdf>
  57. #include    <msmisc.fdf>
  58. #include    <msinput.fdf>
  59. #include    <msclipbd.fdf>
  60.  
  61. /*----------------------------------------------------------------------+
  62. |                                    |
  63. |   Private Global variables                        |
  64. |                                    |
  65. +----------------------------------------------------------------------*/
  66. Private MSClipboard   msClipboardBase;
  67.  
  68. /*----------------------------------------------------------------------+
  69. |                                    |
  70. |   Public Global variables                        |
  71. |                                    |
  72. +----------------------------------------------------------------------*/
  73. Public MSClipboard  *clipboardP;
  74.  
  75. /*----------------------------------------------------------------------+
  76. |                                    |
  77. |   Prototypes                                |
  78. |                                    |
  79. +----------------------------------------------------------------------*/
  80. Private int    ntcbtext_newData
  81. (
  82. int            *numResponsesP,
  83. ClipboardResponse   *crP,
  84. ClipboardFormatInfo *cfiP,
  85. int             numFormats
  86. );
  87.  
  88. /*======================================================================+
  89. |                                    |
  90. |   Private Utility Routines                        |
  91. |                                    |
  92. +======================================================================*/
  93. /*----------------------------------------------------------------------+
  94. |                                    |
  95. | name        ntcbtext_getPasteTransform                |
  96. |                                    |
  97. | author    BSI                          12/91        |
  98. |                                    |
  99. +----------------------------------------------------------------------*/
  100. Private void    ntcbtext_getPasteTransform
  101. (
  102. Transform      *transformP,
  103. Dpoint3d       *pointP,
  104. int        view
  105. )
  106.     {
  107.     RotMatrix  vuMatrix, invMatrix;
  108.     Transform  invTransform, angleTransform;
  109.  
  110.     mdlRMatrix_fromView (&vuMatrix, view, TRUE);
  111.     mdlRMatrix_invert (&invMatrix, &vuMatrix);
  112.     mdlTMatrix_getIdentity (&invTransform);
  113.     mdlTMatrix_rotateByRMatrix (&invTransform, &invTransform, &invMatrix);
  114.  
  115.     mdlTMatrix_getIdentity (&angleTransform);
  116.     mdlTMatrix_rotateByAngles (&angleTransform, &angleTransform,
  117.                    0.0, 0.0, tcb->actangle*fc_piover180);
  118.  
  119.     mdlTMatrix_getIdentity (transformP);
  120.     mdlTMatrix_translate (transformP, transformP, pointP->x, pointP->y, pointP->z);
  121.     mdlTMatrix_multiply (transformP, transformP, &invTransform);
  122.     mdlTMatrix_multiply (transformP, transformP, &angleTransform);
  123.     mdlTMatrix_scale (transformP, transformP, tcb->xactscle, tcb->yactscle, tcb->zactscle);
  124.     }
  125.  
  126. /*----------------------------------------------------------------------+
  127. |                                                                       |
  128. |   Name    cbRscPrintf                        |
  129. |                                                                       |
  130. |   Author    BSI                    7/93        |
  131. |                                                                       |
  132. +----------------------------------------------------------------------*/
  133. Private void cbRscPrintf
  134. (
  135. long    msgId,
  136. ...
  137. )
  138.     {
  139.     va_list ap;
  140.     char    format[256];
  141.  
  142.     if (mdlResource_loadFromStringList (format, NULL, MESSAGELISTID_Msgs,
  143.                     msgId))
  144.     return;
  145.  
  146.     va_start (ap, msgId);
  147.     vprintf (format, ap);
  148.     va_end (ap);
  149.     }
  150.  
  151. /*======================================================================+
  152. |                                    |
  153. |   Clipboard I/O section                           |
  154. |                                    |
  155. +======================================================================*/
  156. /*----------------------------------------------------------------------+
  157. |                                                                       |
  158. | name          ntcbtext_pasteTextToDialog                              |
  159. |                                                                       |
  160. | author        BSI                        10/92           |
  161. |                                                                       |
  162. +----------------------------------------------------------------------*/
  163. Private void    ntcbtext_pasteTextToDialog
  164. (
  165. void
  166. )
  167.     {
  168.     char    *cbDataP;
  169.     char    *cP;
  170.  
  171.     cbDataP = (char *) mdlClipboard_getClipboardData (CF_TEXT);
  172.     if (NULL != cbDataP)
  173.     {
  174.     for (cP=cbDataP; *cP; cP++)
  175.         mdlInput_sendKeystroke (*cP, 0, -1, NULL);
  176.  
  177.     free (cbDataP);
  178.     }
  179.     }
  180.  
  181. /*----------------------------------------------------------------------+
  182. |                                                                       |
  183. | name          ntcbtext_pasteUnicodeTextToDebugWindow                  |
  184. |                                                                       |
  185. | author        BSI                        10/92           |
  186. |                                                                       |
  187. +----------------------------------------------------------------------*/
  188. Private void    ntcbtext_pasteUnicodeTextToDebugWindow
  189. (
  190. void
  191. )
  192.     {
  193.     short   *cbDataP;
  194.     short   *cP;
  195.     char    buffer[50];
  196.  
  197.     cbDataP = (short *) mdlClipboard_getClipboardData (CF_UNICODETEXT);
  198.     if (NULL != cbDataP)
  199.     {
  200.     mdlResource_loadFromStringList (buffer, NULL, MESSAGELISTID_Msgs,
  201.                MSG_CFUNICODETEXT);
  202.     printf (buffer);
  203.     for (cP=cbDataP; *cP; cP++)
  204.         printf (" %04x  '%c'\n", *cP, *cP);
  205.  
  206.     free (cbDataP);
  207.     }
  208.     }
  209.  
  210. /*----------------------------------------------------------------------+
  211. |                                                                       |
  212. | name          ntcbtext_pasteOEMTextToDebugWindow                      |
  213. |                                                                       |
  214. | author        BSI                        10/92           |
  215. |                                                                       |
  216. +----------------------------------------------------------------------*/
  217. Private void    ntcbtext_pasteOEMTextToDebugWindow
  218. (
  219. void
  220. )
  221.     {
  222.     char    *cbDataP;
  223.     char    buffer[50];
  224.  
  225.     cbDataP = (char *) mdlClipboard_getClipboardData (CF_OEMTEXT);
  226.     if (NULL != cbDataP)
  227.     {
  228.     mdlResource_loadFromStringList (buffer, NULL, MESSAGELISTID_Msgs,
  229.                MSG_CFOEMTEXT);
  230.     printf (buffer);
  231.     printf (" '%s'\n", cbDataP);
  232.     free (cbDataP);
  233.     }
  234.     }
  235.  
  236.  
  237. /*----------------------------------------------------------------------+
  238. |                                    |
  239. | name        ntcbtext_getWinClipboardText                |
  240. |                                    |
  241. | author    BSI                    1/93        |
  242. |                                    |
  243. +----------------------------------------------------------------------*/
  244. Private int    ntcbtext_getWinClipboardText
  245. (
  246. void
  247. )
  248.     {
  249.     int            fSize;
  250.     char       *textP;
  251.     char       *unexpandedTextP;
  252.     char       *soFarP;
  253.     int            rtn;
  254.     int            lines, i;
  255.     char      **lineV, **tempLineV;
  256.     MSElementDescr *outDscrP = NULL;
  257.  
  258.     /*-------------------------------------------------------------------
  259.      Get the raw clipboard text
  260.     -------------------------------------------------------------------*/
  261.     unexpandedTextP = (char *) mdlClipboard_getClipboardData (CF_TEXT);
  262.     if (NULL == unexpandedTextP)
  263.     return -10;
  264.  
  265.     fSize = strlen(unexpandedTextP);
  266.     if (0 == fSize)
  267.     return 0;
  268.  
  269.  
  270.     /*-------------------------------------------------------------------
  271.      Convert <tabs> to <spaces> as needed.
  272.     -------------------------------------------------------------------*/
  273.     textP = calloc(1, fSize*8);        /* Fix me later!!!!!!*/
  274.     soFarP = textP;
  275.  
  276.     mdlText_expandTabs (textP, unexpandedTextP, 8 * fSize - 1, 8);
  277.  
  278.     free (unexpandedTextP);
  279.  
  280.  
  281.     /*-------------------------------------------------------------------
  282.      Remove line feeds.
  283.     -------------------------------------------------------------------*/
  284.     for (soFarP = strchr (textP, '\n'), lines = 1; soFarP; lines++)
  285.     {
  286.     *soFarP = '\0';
  287.     soFarP = strchr (soFarP + 1, '\n');
  288.     }
  289.  
  290.     /*-------------------------------------------------------------------
  291.      Create "lineV" as an array of (char*) with each element pointing
  292.      to the beginning of each logical line.
  293.      Run through the text strings removing CR's and LF's other characters
  294.      may be significant.
  295.     -------------------------------------------------------------------*/
  296.     tempLineV = lineV = calloc (1, sizeof (char *) * lines);
  297.  
  298.     for (*tempLineV = textP, i = 1; i < lines; i++, tempLineV++)
  299.     {
  300.     int thisLen;
  301.     int skipCrLf;
  302.  
  303.     thisLen = strlen (*tempLineV);
  304.     if (thisLen && '\r' == (*tempLineV)[thisLen-1])
  305.         {
  306.         (*tempLineV)[thisLen-1] = '\0';
  307.         }
  308.  
  309.     *(tempLineV + 1) = *tempLineV + thisLen + 1;
  310.     }
  311.  
  312.     /*-------------------------------------------------------------------
  313.      Replace MicroStation's clipboard contents with this new text array.
  314.     -------------------------------------------------------------------*/
  315.     if (clipboardP->edP)
  316.         mdlElmdscr_freeAll (&clipboardP->edP);
  317.  
  318.     mdlTextNode_createWithStrings (&outDscrP, NULL, NULL, NULL, NULL, NULL,
  319.         NULL, lineV, lines, NULL);
  320.  
  321.     clipboardP->edP      = outDscrP;
  322.     clipboardP->isThreeD = 0;
  323.     clipboardP->count++;
  324.  
  325.  
  326.     /*-------------------------------------------------------------------
  327.      Good programming hygine.
  328.     -------------------------------------------------------------------*/
  329.     free (textP);
  330.     free (lineV);
  331.  
  332.     return 0;
  333.     }
  334.  
  335.  
  336.  
  337. /*======================================================================+
  338. |                                    |
  339. |   Paste Dynamics section                           |
  340. |                                    |
  341. +======================================================================*/
  342.  
  343. /*----------------------------------------------------------------------+
  344. |                                    |
  345. | name        ntcbtext_acceptPaste                    |
  346. |                                    |
  347. | author    BSI                       12/91        |
  348. |                                    |
  349. +----------------------------------------------------------------------*/
  350. Private void    ntcbtext_acceptPaste
  351. (
  352. Dpoint3d       *pointP,
  353. int        view
  354. )
  355.     {
  356.     Transform        transform;
  357.     MSElementDescr    *edP, *tmpEdP;
  358.     int            first = TRUE;
  359.  
  360.     ntcbtext_getPasteTransform (&transform, pointP, view);
  361.  
  362.     for (edP=clipboardP->edP; edP; edP=edP->h.next)
  363.     {
  364.     mdlElmdscr_duplicateSingle (&tmpEdP, edP);
  365.     mdlElmdscr_transform (tmpEdP, &transform);
  366.     mdlElmdscr_display (tmpEdP, 0, NORMALDRAW);
  367.  
  368.     mdlElmdscr_validate (tmpEdP, MASTERFILE);
  369.     mdlElmdscr_add (tmpEdP);
  370.     mdlElmdscr_freeAll (&tmpEdP);
  371.     }
  372.  
  373.     mdlState_startDefaultCommand ();
  374.     }
  375.  
  376.  
  377. /*----------------------------------------------------------------------+
  378. |                                    |
  379. | name        ntcbtext_pasteDynamics                    |
  380. |                                    |
  381. | author    BSI                          12/91        |
  382. |                                    |
  383. +----------------------------------------------------------------------*/
  384. Private void    ntcbtext_pasteDynamics
  385. (
  386. Dpoint3d       *pointP,
  387. int        view
  388. )
  389.     {
  390.     Transform        transform;
  391.  
  392.     ntcbtext_getPasteTransform (&transform, pointP, view);
  393.     mdlElement_transform (dgnBuf, dgnBuf, &transform);
  394.     }
  395.  
  396.  
  397. /*----------------------------------------------------------------------+
  398. |                                    |
  399. | name        ntcbtext_resetPaste                    |
  400. |                                    |
  401. | author    BSI                    1/93        |
  402. |                                    |
  403. +----------------------------------------------------------------------*/
  404. Private void    ntcbtext_resetPaste
  405. (
  406. void
  407. )
  408.     {
  409.     mdlState_startDefaultCommand ();
  410.     }
  411.  
  412.  
  413. /*----------------------------------------------------------------------+
  414. |                                    |
  415. | name        ntcbtext_pasteWithDynamics                |
  416. |                                    |
  417. | author    BSI                        4/92        |
  418. |                                    |
  419. +----------------------------------------------------------------------*/
  420. Private void    ntcbtext_pasteWithDynamics
  421. (
  422. void
  423. )
  424.     {
  425.     MSElementDescr  *dynamicEdP;
  426.  
  427.     mdlState_startPrimitive (ntcbtext_acceptPaste,
  428.                  ntcbtext_resetPaste, 0,0);
  429.  
  430.     mdlElmdscr_duplicate (&dynamicEdP, clipboardP->edP);
  431.     mdlDynamic_setElmDescr (dynamicEdP);
  432.     mdlState_dynamicUpdate (ntcbtext_pasteDynamics, FALSE);
  433.     }
  434.  
  435.  /*----------------------------------------------------------------------+
  436. |                                                                       |
  437. | name          ntcbtext_pasteTextToDgnFile                             |
  438. |                                                                       |
  439. | author        BSI                        10/92           |
  440. |                                                                       |
  441. | Called when the user selects Edit->Paste->Text to Dialog        |
  442. |                                                                       |
  443. +----------------------------------------------------------------------*/
  444. Private void    ntcbtext_pasteTextToDgnFile
  445. (
  446. void
  447. )
  448.     {
  449.     ntcbtext_getWinClipboardText();
  450.     ntcbtext_pasteWithDynamics ();
  451.     }
  452.  
  453.  
  454. /*----------------------------------------------------------------------+
  455. |                                                                       |
  456. | name          ntcbtext_newData                                        |
  457. |                                                                       |
  458. | author        BSI                        11/92           |
  459. |                                                                       |
  460. | Called when the user selects Edit->Paste->Text to Design File        |
  461. |                                                                       |
  462. +----------------------------------------------------------------------*/
  463. Private int    ntcbtext_newData
  464. (
  465. int            *numResponsesP,
  466. ClipboardResponse   *crP,
  467. ClipboardFormatInfo *cfiP,
  468. int             numFormats
  469. )
  470.     {
  471.     int iFormat;
  472.  
  473.     *numResponsesP = 0;
  474.  
  475.     for (iFormat=0; iFormat<numFormats; iFormat++, cfiP++)
  476.     {
  477.     switch (cfiP->formatNum)
  478.         {
  479.         case CF_TEXT:
  480.         crP->formatNum       = cfiP->formatNum;
  481.         crP->handlerQuality  = CLIPBOARD_FORMAT_IDEALHANDLER;
  482.         crP->userDataP       = NULL;
  483.         crP->handlerFunction = ntcbtext_pasteTextToDgnFile;
  484.         mdlResource_loadFromStringList (crP->menuName, NULL,
  485.                         MESSAGELISTID_Msgs,
  486.                         MSG_TextToDesignFile);
  487.         crP++;
  488.         (*numResponsesP)++;
  489.  
  490.         crP->formatNum       = cfiP->formatNum;
  491.         crP->handlerQuality  = CLIPBOARD_FORMAT_IDEALHANDLER;
  492.         crP->userDataP       = NULL;
  493.         crP->handlerFunction = ntcbtext_pasteTextToDialog;
  494.         mdlResource_loadFromStringList (crP->menuName, NULL,
  495.                         MESSAGELISTID_Msgs,
  496.                         MSG_TextToDialogBox);
  497.         crP++;
  498.         (*numResponsesP)++;
  499.         break;
  500.  
  501.         case CF_UNICODETEXT:
  502.         crP->formatNum       = cfiP->formatNum;
  503.         crP->handlerQuality  = CLIPBOARD_FORMAT_IDEALHANDLER;
  504.         crP->userDataP       = NULL;
  505.         crP->handlerFunction = ntcbtext_pasteUnicodeTextToDebugWindow;
  506.         mdlResource_loadFromStringList (crP->menuName, NULL,
  507.                         MESSAGELISTID_Msgs,
  508.                         MSG_TextUnicodeToDebugWindow);
  509.         crP++;
  510.         (*numResponsesP)++;
  511.         break;
  512.  
  513.         case CF_OEMTEXT:
  514.         crP->formatNum       = cfiP->formatNum;
  515.         crP->handlerQuality  = CLIPBOARD_FORMAT_IDEALHANDLER;
  516.         crP->userDataP       = NULL;
  517.         crP->handlerFunction = ntcbtext_pasteOEMTextToDebugWindow;
  518.         mdlResource_loadFromStringList (crP->menuName, NULL,
  519.                         MESSAGELISTID_Msgs,
  520.                         MSG_TextOEMToDebugWindow);
  521.         crP++;
  522.         (*numResponsesP)++;
  523.         break;
  524.  
  525.  
  526.         /* Put other Clipboard formats here */
  527.  
  528.         default:
  529.         break;
  530.         }
  531.     }
  532.     return 0;
  533.     }
  534.  
  535. /*======================================================================+
  536. |                                    |
  537. |   Major Public Code Section                        |
  538. |                                    |
  539. +======================================================================*/
  540. /*----------------------------------------------------------------------+
  541. |                                                                       |
  542. | name          ntcbtext   main                        |
  543. |                                                                       |
  544. | author        BSI                        11/92           |
  545. |                                                                       |
  546. +----------------------------------------------------------------------*/
  547. Public void    main
  548. (
  549. void
  550. )
  551.     {
  552.     RscFileHandle   rscHandle;
  553.  
  554.     mdlResource_openFile (&rscHandle, 0, FALSE);
  555.     clipboardP = &msClipboardBase;
  556.  
  557.     mdlClipboard_setFunction (CLIPBOARD_SET_PASTE, ntcbtext_newData);
  558.     }
  559.  
  560.