home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk21
/
dir03
/
f017970.re_
/
f017970.re
Wrap
Text File
|
1996-04-02
|
18KB
|
560 lines
/*----------------------------------------------------------------------+
| |
| Copyright (1993-95) Bentley Systems, Inc., All rights reserved. |
| |
| "MicroStation" is a registered trademark and "MDL" and "MicroCSL" |
| are trademarks of Bentley Systems, Inc. |
| |
| Limited permission is hereby granted to reproduce and modify this |
| copyrighted material provided that the resulting code is used only |
| in conjunction with Bentley Systems products under the terms of the |
| license agreement provided therein, and that this notice is retained |
| in its entirety in any such reproduction or modification. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| $Workfile: ntcbtext.mc $
| $Revision: 5.4 $
| $Date: 26 Jul 1995 11:17:16 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Function - |
| |
| Clipboard hook for Windows NT |
| |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| |
| Public Routine Summary - |
| |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mdl.h>
#include <dlogitem.h>
#include <clipbrd.h>
#include <wnclpext.h>
#include <tcb.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "ntcbtext.h"
#include <msrsrc.fdf>
#include <msrmatrx.fdf>
#include <mstmatrx.fdf>
#include <msstate.fdf>
#include <mselemen.fdf>
#include <mselmdsc.fdf>
#include <msmisc.fdf>
#include <msinput.fdf>
#include <msclipbd.fdf>
/*----------------------------------------------------------------------+
| |
| Private Global variables |
| |
+----------------------------------------------------------------------*/
Private MSClipboard msClipboardBase;
/*----------------------------------------------------------------------+
| |
| Public Global variables |
| |
+----------------------------------------------------------------------*/
Public MSClipboard *clipboardP;
/*----------------------------------------------------------------------+
| |
| Prototypes |
| |
+----------------------------------------------------------------------*/
Private int ntcbtext_newData
(
int *numResponsesP,
ClipboardResponse *crP,
ClipboardFormatInfo *cfiP,
int numFormats
);
/*======================================================================+
| |
| Private Utility Routines |
| |
+======================================================================*/
/*----------------------------------------------------------------------+
| |
| name ntcbtext_getPasteTransform |
| |
| author BSI 12/91 |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_getPasteTransform
(
Transform *transformP,
Dpoint3d *pointP,
int view
)
{
RotMatrix vuMatrix, invMatrix;
Transform invTransform, angleTransform;
mdlRMatrix_fromView (&vuMatrix, view, TRUE);
mdlRMatrix_invert (&invMatrix, &vuMatrix);
mdlTMatrix_getIdentity (&invTransform);
mdlTMatrix_rotateByRMatrix (&invTransform, &invTransform, &invMatrix);
mdlTMatrix_getIdentity (&angleTransform);
mdlTMatrix_rotateByAngles (&angleTransform, &angleTransform,
0.0, 0.0, tcb->actangle*fc_piover180);
mdlTMatrix_getIdentity (transformP);
mdlTMatrix_translate (transformP, transformP, pointP->x, pointP->y, pointP->z);
mdlTMatrix_multiply (transformP, transformP, &invTransform);
mdlTMatrix_multiply (transformP, transformP, &angleTransform);
mdlTMatrix_scale (transformP, transformP, tcb->xactscle, tcb->yactscle, tcb->zactscle);
}
/*----------------------------------------------------------------------+
| |
| Name cbRscPrintf |
| |
| Author BSI 7/93 |
| |
+----------------------------------------------------------------------*/
Private void cbRscPrintf
(
long msgId,
...
)
{
va_list ap;
char format[256];
if (mdlResource_loadFromStringList (format, NULL, MESSAGELISTID_Msgs,
msgId))
return;
va_start (ap, msgId);
vprintf (format, ap);
va_end (ap);
}
/*======================================================================+
| |
| Clipboard I/O section |
| |
+======================================================================*/
/*----------------------------------------------------------------------+
| |
| name ntcbtext_pasteTextToDialog |
| |
| author BSI 10/92 |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_pasteTextToDialog
(
void
)
{
char *cbDataP;
char *cP;
cbDataP = (char *) mdlClipboard_getClipboardData (CF_TEXT);
if (NULL != cbDataP)
{
for (cP=cbDataP; *cP; cP++)
mdlInput_sendKeystroke (*cP, 0, -1, NULL);
free (cbDataP);
}
}
/*----------------------------------------------------------------------+
| |
| name ntcbtext_pasteUnicodeTextToDebugWindow |
| |
| author BSI 10/92 |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_pasteUnicodeTextToDebugWindow
(
void
)
{
short *cbDataP;
short *cP;
char buffer[50];
cbDataP = (short *) mdlClipboard_getClipboardData (CF_UNICODETEXT);
if (NULL != cbDataP)
{
mdlResource_loadFromStringList (buffer, NULL, MESSAGELISTID_Msgs,
MSG_CFUNICODETEXT);
printf (buffer);
for (cP=cbDataP; *cP; cP++)
printf (" %04x '%c'\n", *cP, *cP);
free (cbDataP);
}
}
/*----------------------------------------------------------------------+
| |
| name ntcbtext_pasteOEMTextToDebugWindow |
| |
| author BSI 10/92 |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_pasteOEMTextToDebugWindow
(
void
)
{
char *cbDataP;
char buffer[50];
cbDataP = (char *) mdlClipboard_getClipboardData (CF_OEMTEXT);
if (NULL != cbDataP)
{
mdlResource_loadFromStringList (buffer, NULL, MESSAGELISTID_Msgs,
MSG_CFOEMTEXT);
printf (buffer);
printf (" '%s'\n", cbDataP);
free (cbDataP);
}
}
/*----------------------------------------------------------------------+
| |
| name ntcbtext_getWinClipboardText |
| |
| author BSI 1/93 |
| |
+----------------------------------------------------------------------*/
Private int ntcbtext_getWinClipboardText
(
void
)
{
int fSize;
char *textP;
char *unexpandedTextP;
char *soFarP;
int rtn;
int lines, i;
char **lineV, **tempLineV;
MSElementDescr *outDscrP = NULL;
/*-------------------------------------------------------------------
Get the raw clipboard text
-------------------------------------------------------------------*/
unexpandedTextP = (char *) mdlClipboard_getClipboardData (CF_TEXT);
if (NULL == unexpandedTextP)
return -10;
fSize = strlen(unexpandedTextP);
if (0 == fSize)
return 0;
/*-------------------------------------------------------------------
Convert <tabs> to <spaces> as needed.
-------------------------------------------------------------------*/
textP = calloc(1, fSize*8); /* Fix me later!!!!!!*/
soFarP = textP;
mdlText_expandTabs (textP, unexpandedTextP, 8 * fSize - 1, 8);
free (unexpandedTextP);
/*-------------------------------------------------------------------
Remove line feeds.
-------------------------------------------------------------------*/
for (soFarP = strchr (textP, '\n'), lines = 1; soFarP; lines++)
{
*soFarP = '\0';
soFarP = strchr (soFarP + 1, '\n');
}
/*-------------------------------------------------------------------
Create "lineV" as an array of (char*) with each element pointing
to the beginning of each logical line.
Run through the text strings removing CR's and LF's other characters
may be significant.
-------------------------------------------------------------------*/
tempLineV = lineV = calloc (1, sizeof (char *) * lines);
for (*tempLineV = textP, i = 1; i < lines; i++, tempLineV++)
{
int thisLen;
int skipCrLf;
thisLen = strlen (*tempLineV);
if (thisLen && '\r' == (*tempLineV)[thisLen-1])
{
(*tempLineV)[thisLen-1] = '\0';
}
*(tempLineV + 1) = *tempLineV + thisLen + 1;
}
/*-------------------------------------------------------------------
Replace MicroStation's clipboard contents with this new text array.
-------------------------------------------------------------------*/
if (clipboardP->edP)
mdlElmdscr_freeAll (&clipboardP->edP);
mdlTextNode_createWithStrings (&outDscrP, NULL, NULL, NULL, NULL, NULL,
NULL, lineV, lines, NULL);
clipboardP->edP = outDscrP;
clipboardP->isThreeD = 0;
clipboardP->count++;
/*-------------------------------------------------------------------
Good programming hygine.
-------------------------------------------------------------------*/
free (textP);
free (lineV);
return 0;
}
/*======================================================================+
| |
| Paste Dynamics section |
| |
+======================================================================*/
/*----------------------------------------------------------------------+
| |
| name ntcbtext_acceptPaste |
| |
| author BSI 12/91 |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_acceptPaste
(
Dpoint3d *pointP,
int view
)
{
Transform transform;
MSElementDescr *edP, *tmpEdP;
int first = TRUE;
ntcbtext_getPasteTransform (&transform, pointP, view);
for (edP=clipboardP->edP; edP; edP=edP->h.next)
{
mdlElmdscr_duplicateSingle (&tmpEdP, edP);
mdlElmdscr_transform (tmpEdP, &transform);
mdlElmdscr_display (tmpEdP, 0, NORMALDRAW);
mdlElmdscr_validate (tmpEdP, MASTERFILE);
mdlElmdscr_add (tmpEdP);
mdlElmdscr_freeAll (&tmpEdP);
}
mdlState_startDefaultCommand ();
}
/*----------------------------------------------------------------------+
| |
| name ntcbtext_pasteDynamics |
| |
| author BSI 12/91 |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_pasteDynamics
(
Dpoint3d *pointP,
int view
)
{
Transform transform;
ntcbtext_getPasteTransform (&transform, pointP, view);
mdlElement_transform (dgnBuf, dgnBuf, &transform);
}
/*----------------------------------------------------------------------+
| |
| name ntcbtext_resetPaste |
| |
| author BSI 1/93 |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_resetPaste
(
void
)
{
mdlState_startDefaultCommand ();
}
/*----------------------------------------------------------------------+
| |
| name ntcbtext_pasteWithDynamics |
| |
| author BSI 4/92 |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_pasteWithDynamics
(
void
)
{
MSElementDescr *dynamicEdP;
mdlState_startPrimitive (ntcbtext_acceptPaste,
ntcbtext_resetPaste, 0,0);
mdlElmdscr_duplicate (&dynamicEdP, clipboardP->edP);
mdlDynamic_setElmDescr (dynamicEdP);
mdlState_dynamicUpdate (ntcbtext_pasteDynamics, FALSE);
}
/*----------------------------------------------------------------------+
| |
| name ntcbtext_pasteTextToDgnFile |
| |
| author BSI 10/92 |
| |
| Called when the user selects Edit->Paste->Text to Dialog |
| |
+----------------------------------------------------------------------*/
Private void ntcbtext_pasteTextToDgnFile
(
void
)
{
ntcbtext_getWinClipboardText();
ntcbtext_pasteWithDynamics ();
}
/*----------------------------------------------------------------------+
| |
| name ntcbtext_newData |
| |
| author BSI 11/92 |
| |
| Called when the user selects Edit->Paste->Text to Design File |
| |
+----------------------------------------------------------------------*/
Private int ntcbtext_newData
(
int *numResponsesP,
ClipboardResponse *crP,
ClipboardFormatInfo *cfiP,
int numFormats
)
{
int iFormat;
*numResponsesP = 0;
for (iFormat=0; iFormat<numFormats; iFormat++, cfiP++)
{
switch (cfiP->formatNum)
{
case CF_TEXT:
crP->formatNum = cfiP->formatNum;
crP->handlerQuality = CLIPBOARD_FORMAT_IDEALHANDLER;
crP->userDataP = NULL;
crP->handlerFunction = ntcbtext_pasteTextToDgnFile;
mdlResource_loadFromStringList (crP->menuName, NULL,
MESSAGELISTID_Msgs,
MSG_TextToDesignFile);
crP++;
(*numResponsesP)++;
crP->formatNum = cfiP->formatNum;
crP->handlerQuality = CLIPBOARD_FORMAT_IDEALHANDLER;
crP->userDataP = NULL;
crP->handlerFunction = ntcbtext_pasteTextToDialog;
mdlResource_loadFromStringList (crP->menuName, NULL,
MESSAGELISTID_Msgs,
MSG_TextToDialogBox);
crP++;
(*numResponsesP)++;
break;
case CF_UNICODETEXT:
crP->formatNum = cfiP->formatNum;
crP->handlerQuality = CLIPBOARD_FORMAT_IDEALHANDLER;
crP->userDataP = NULL;
crP->handlerFunction = ntcbtext_pasteUnicodeTextToDebugWindow;
mdlResource_loadFromStringList (crP->menuName, NULL,
MESSAGELISTID_Msgs,
MSG_TextUnicodeToDebugWindow);
crP++;
(*numResponsesP)++;
break;
case CF_OEMTEXT:
crP->formatNum = cfiP->formatNum;
crP->handlerQuality = CLIPBOARD_FORMAT_IDEALHANDLER;
crP->userDataP = NULL;
crP->handlerFunction = ntcbtext_pasteOEMTextToDebugWindow;
mdlResource_loadFromStringList (crP->menuName, NULL,
MESSAGELISTID_Msgs,
MSG_TextOEMToDebugWindow);
crP++;
(*numResponsesP)++;
break;
/* Put other Clipboard formats here */
default:
break;
}
}
return 0;
}
/*======================================================================+
| |
| Major Public Code Section |
| |
+======================================================================*/
/*----------------------------------------------------------------------+
| |
| name ntcbtext main |
| |
| author BSI 11/92 |
| |
+----------------------------------------------------------------------*/
Public void main
(
void
)
{
RscFileHandle rscHandle;
mdlResource_openFile (&rscHandle, 0, FALSE);
clipboardP = &msClipboardBase;
mdlClipboard_setFunction (CLIPBOARD_SET_PASTE, ntcbtext_newData);
}