⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generic.cpp

📁 MicroStation源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

/*----------------------------------------------------------------------+
|									|
|  Copyright (c) 1985-91;  Bentley Systems, Inc., All rights reserved.	|
|									|
| "MicroStation", "MDL", and "MicroCSL" are trademarks of Bentley	|
|  Systems, Inc. and/or Intergraph Corporation. 			|
|									|
|  This program is proprietary and unpublished property of Bentley    	|
|  Systems Inc. It may NOT be copied in part or in whole on any medium,	|
|  either electronic or printed, without the express written consent	|
|  of Bentley Systems, Inc.						|
|									|
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
|									|
|   generic.mc -- Generic Item Dialog Box Examples			|
|									|
+----------------------------------------------------------------------*/

/*----------------------------------------------------------------------+
|									|
|   Include Files   							|
|									|
+----------------------------------------------------------------------*/
#include <mdl.h>    
#include <dlogitem.h>
#include <cexpr.h>
#include <mselems.h>    
#include <tcb.h>
#include <dlogman.fdf>
#include <cmdlist.h>


#include "generic.h"

/*----------------------------------------------------------------------+
|									|
|   Local Function Declarations						|
|									|
+----------------------------------------------------------------------*/
void	imageItem_genericHook ();
void    text_stringJustGenericHook ();// 调整
void	text_stringJustMenuHook ();
void	text_scaleTextHook ();
void    text_lockGenericHook ();
void    GenericDialog ();
// hook函数
void text_drawLock(DialogItemMessage *dimP,int topTextID,int botTextID);
void text_invertPart(DialogBox *db,Rectangle *rect,int row,int col);
void text_displayFont(DialogItemMessage *dimP,int eraseFirst);
void text_drawCross(DialogBox *db,int x,int y);

/*----------------------------------------------------------------------+
|									|
| name		fontDialog_displayElement				|
|									|
| author	RBB					7/90		|
|									|
+----------------------------------------------------------------------*/
Public void fontDialog_displayElement //在控件上绘制文本要素
(
DialogBox	*dbP,
MSElementUnion	*u,
Rectangle	*displayRectP
)
    {
    MSElementDescr  *edP;
    Dpoint3d	    origin, extent;

    origin.x = origin.y = origin.z = fc_zero;
    
    extent.x = displayRectP->corner.x - displayRectP->origin.x;//计算矩形的宽度
    extent.y = displayRectP->corner.y - displayRectP->origin.y;//计算矩形的高度
    extent.z = fc_1000;
    
    mdlElmdscr_new (&edP, NULL, u);//创建文本元素描述符
    mdlElmdscr_displayToWindow (dbP, displayRectP, NULL, edP, NULL,
				&origin, &extent, tcb->ndices==3, 
				BLACK_INDEX);//在窗口绘制文本元素描述符
    
    mdlElmdscr_freeAll (&edP);
    }

/*----------------------------------------------------------------------+
|									|
| name		imageItem_genericHook					|
|									|
| author	RBB				 	 11/91		|
|									|
+----------------------------------------------------------------------*/
Private void imageItem_genericHook
(
DialogItemMessage	    *dimP
)    
    {
    dimP->msgUnderstood = TRUE;
    
    switch (dimP->messageType)
	{
	case DITEM_MESSAGE_CREATE:
	    {
	    char	    fullFileSpec[MAXFILELENGTH];
	    byte	    *rgbBufferP;
	    Point2d	    itemSize;
	    DialogItem  *diP = dimP->dialogItemP;

	    itemSize.x = diP->rect.corner.x - diP->rect.origin.x + 1;
	    itemSize.y = diP->rect.corner.y - diP->rect.origin.y + 1;
/*
		在.r文件中通过labelP记录了图像文件名,
		函数mdlFile_find只是在系统变量定义的路径下查找组成的文件名,
		如果没有找到将返回最后的查找结果
*/
	    if (! mdlFile_find (fullFileSpec, diP->rawItemP->labelP, 
			"d:\\lg_app_mdl\\GENERIC\\",".jpg"))
		{
		if (! mdlImage_readFileToRGB (&rgbBufferP, NULL, fullFileSpec,
				-1,&itemSize, NULL))//从图像文件fullFileSpec中读取图像数据
		    mdlDialog_userDataPtrSet (dimP->db, rgbBufferP);//设置对话框的用户数据指针
		}
//		printf("diP->rawItemP->labelP = %s\n",diP->rawItemP->labelP);
//		printf("fullFileSpec = %s\n",fullFileSpec);
	    break;
	    }
	
	case DITEM_MESSAGE_DRAW:
	    {
	    int		    i, rowLength;
	    byte	    *redP, *greenP, *blueP;
	    DialogItem	    *diP = dimP->dialogItemP;

	    if (redP = mdlDialog_userDataPtrGet (dimP->db))//获取在创建阶段设置的用户数据指针
		{
		rowLength = diP->rect.corner.x - diP->rect.origin.x + 1;
		greenP = redP  + rowLength;
		blueP  = greenP + rowLength;

		for (i=diP->rect.origin.y; i <= diP->rect.corner.y; i++)
		    {
		    mdlDither_drawRow (dimP->db, diP->rect.origin.x, 
					         diP->rect.corner.x, i,
					         redP, greenP, blueP);//逐行在控件中绘制图像
		    redP   += 3 * rowLength;
		    greenP += 3 * rowLength;
		    blueP  += 3 * rowLength;
		    }
		}
    
	    mdlDialog_rectDrawEdge (dimP->db, &diP->rect, TRUE);//绘制控件的边界(矩形)
	    break;
	    }

	case DITEM_MESSAGE_DESTROY:
	    {
	    byte    *tempBufferP;
	    
	    if (tempBufferP = mdlDialog_userDataPtrGet (dimP->db))
		free (tempBufferP);//销毁用户数据指针
	    break;
	    }
		
	default:
	    dimP->msgUnderstood = FALSE;
	    break;
	}
    }

/*----------------------------------------------------------------------+
|									|
| name		text_scaleTextHook					|
|									|
| author	BSI					8/90		|
|									|
+----------------------------------------------------------------------*/
Public void text_scaleTextHook
(
DialogItemMessage   *dimP
)
	{
	DialogItem	*diP;
    //过滤了所有非DITEM_MESSAGE_STATECHANGED消息
	if (dimP->messageType != DITEM_MESSAGE_STATECHANGED)
		{
		dimP->msgUnderstood = TRUE;
		return;
		}

	dimP->msgUnderstood = TRUE;

	diP = mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_Generic,
					GENERICID_Lock, 0);//获取GENERICID_Lock的指针
	if (!diP) return;
    
	if (diP->rawItemP->userDataP)//判断userDataP,即lock的标识
		if (dimP->dialogItemP->id == TEXTID_Width)
	    	{
			tcb->chheight = tcb->chwidth;
			mdlDialog_itemSynch (dimP->db, dimP->itemIndex -1);//强制同步
			}
		else
			{
			tcb->chwidth = tcb->chheight;
			mdlDialog_itemSynch (dimP->db, dimP->itemIndex +1);//强制同步
			}
	}

/*----------------------------------------------------------------------+
|                                                                       |
| name          text_lockGenericHook					|
|                                                                       |
| author        BSI                                     8/90            |
|                                                                       |
+----------------------------------------------------------------------*/
Public void text_lockGenericHook
(
DialogItemMessage   *dimP
)
    {
   dimP->msgUnderstood = TRUE;
    
    switch (dimP->messageType)
		{
		case DITEM_MESSAGE_CREATE:
	    	dimP->dialogItemP->attributes.acceptsKeystrokes = FALSE;
			break;

		case DITEM_MESSAGE_BUTTON:
			if (dimP->u.button.buttonTrans == BUTTONTRANS_UP)//设置响应模式为鼠标键弹起
				{
				int	*lockClosed;
				lockClosed = &dimP->dialogItemP->rawItemP->userDataP;
/*
				使用userDataP来记录lockclosed的信息
				使用*lockClosed来取代dimP->dialogItemP->rawItemP->userDataP
*/
				*lockClosed = !(*lockClosed);//非运算lockClosed
				}
		    
		case DITEM_MESSAGE_DRAW:
			text_drawLock (dimP, TEXTID_Height, TEXTID_Width);//绘制图标
			break;
			
		default:
			dimP->msgUnderstood = FALSE;
			break;
		}
    }

/*----------------------------------------------------------------------+
|                                                                       |
| name          text_stringJustButton   				|
|									|
| author        BSI					8/90		|
|									|
+----------------------------------------------------------------------*/
Private void text_stringJustButton (newPt)
Point2d	    *newPt;
	{
    Point2d		localPt;
    DialogItem	*diP, *menuDiP;
    int			newJust;
    DialogBox	*db;
    int			col, row;
    double		partSize;
    
    db = (DialogBox *)mdlDialog_find (DIALOGID_GenericDialog, NULL);
    diP = mdlDialog_itemGetByTypeAndId (db, RTYPE_Generic,
					GENERICID_StringJust, 0);
    mdlWindow_pointToLocal (&localPt, db, newPt);
/*
	鼠标坐标转换为对话框中的坐标
	DialogBox和MSWindow是一样的结构
*/
    
    if (localPt.x > diP->rect.corner.x-1)
	localPt.x = diP->rect.corner.x -1;
    if (localPt.y > diP->rect.corner.y-1)
	localPt.y = diP->rect.corner.y -1;
    if (localPt.x < diP->rect.origin.x)
	localPt.x = diP->rect.origin.x;
    if (localPt.y < diP->rect.origin.y)
	localPt.y = diP->rect.origin.y;
	// 去除非法的数据   
    partSize = (double)(diP->rect.corner.y - diP->rect.origin.y)/3.0;//将控件区域分为9部分(控件为正方行)
	// 判断鼠标点在控件中的位置,并计算编号newJust
	col = (int)((localPt.x - diP->rect.origin.x) / partSize); 
    row = (int)((localPt.y - diP->rect.origin.y) / partSize); 
    newJust = col*6 + row;
    
    if (newJust == tcb->txtjust)//如若和tcb结构中的值相同则txtjust为tcb中的结构调整值
	return;
    
    mdlWindow_cursorTurnOff ();
	// 关闭鼠标,在MS中在绘图之前必须关闭鼠标,但在重新获得鼠标数据后MS会自动开启鼠标

    col = tcb->txtjust / 6;
    row = tcb->txtjust - 6*col;
    text_invertPart (db, &diP->rect, row, col);// 按照系统txtjust反转颜色
    
    col = newJust / 6;
    row = newJust - 6*col;
    text_invertPart (db, &diP->rect, row, col);// 按照调整后的newJust反转颜色
    tcb->txtjust = newJust;
	//强制控件同步
    menuDiP = mdlDialog_itemGetByTypeAndId (db, RTYPE_OptionButton,
					OPTIONBUTTONID_TextStringVerJust, 0);
    mdlDialog_itemSynch (db, menuDiP->itemIndex);//强制控件同步
    menuDiP = mdlDialog_itemGetByTypeAndId (db, RTYPE_OptionButton,
					OPTIONBUTTONID_TextStringHorJust,0);
    mdlDialog_itemSynch (db, menuDiP->itemIndex);//强制控件同步
	}

/*----------------------------------------------------------------------+
|                                                                       |
| name          text_stringJustGenericHook				|
|                                                                       |
| author        BSI                                     8/90            |
|                                                                       |
+----------------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -