Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15498060
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: C/C++

2007-09-15 19:34:46

MultiEdit作为文本浏览器的几处修改
<1>首先在MultiEdit.c文件中添加下面这两个函数,GUI_KEY_UP和GUI_KEY_DOWN按1/3页翻转移动
//2007-09-14 gliethttp
//CacheFirstVisibleLine为不可见的行数,也就是第1个可见的行号

void _Go2PrevLineShow(MULTIEDIT_HANDLE hObj, MULTIEDIT_OBJ* pObj)
{
    if (pObj->hText)
    {int NumVisLines= _GetNumVisLines(hObj, pObj);
     int YDist      = GUI_GetYDistOfFont(pObj->pFont);
     int NumLines   = _GetNumLines(hObj, pObj);
     int the_line;int yPos;
        the_line = pObj->CacheFirstVisibleLine;
        if(the_line == 0)the_line = NumLines+1;
        else
            {
                the_line -= NumVisLines / 3 + 1;
                if(the_line < 0)the_line = 0;
            }
        yPos = the_line * YDist;
        _SetCursorXY(hObj, pObj, 0, yPos);
        _InvalidateTextArea(hObj);
    }
}
void _Go2NextLineShow(MULTIEDIT_HANDLE hObj, MULTIEDIT_OBJ* pObj)
{
    if (pObj->hText)
    {int NumVisLines= _GetNumVisLines(hObj, pObj);
     int YDist      = GUI_GetYDistOfFont(pObj->pFont);
     int NumLines   = _GetNumLines(hObj, pObj);
     int the_line;int yPos;
     the_line = pObj->CacheFirstVisibleLine + NumVisLines + NumVisLines / 3;
        if(pObj->CacheLineNumber >= (NumLines-1))the_line = 0;
        yPos = the_line * YDist;
        _SetCursorXY(hObj, pObj, 0, yPos);
        _InvalidateTextArea(hObj);
    }
}

<2>MultiEdit被WM_SET_FOCUS之后,即刻显示出scrollbar
//在MultiEdit.c文件中添加下面这个函数
void _SetMultiEdit_ScrollBarVis(MULTIEDIT_HANDLE hObj)
{MULTIEDIT_OBJ* pObj;
      pObj = MULTIEDIT_H2P(hObj);
    _MoveCursor2LinePos1(hObj, pObj);
    _InvalidateTextArea(hObj);
}
<3>对于MULTIEDIT_SetText()函数使用之后不能自动显示srollbar的修正
//修改对于MULTIEDIT_SetText函数
void MULTIEDIT_SetText(MULTIEDIT_HANDLE hObj, const char* pNew) {
  if (hObj) {
    ......
    if (_IsCharsAvailable(pObj, NumCharsNew - NumCharsOld)) {
      if (_IsSpaceInBuffer(pObj, NumBytesNew - NumBytesOld)) {
        pText = (char*) GUI_ALLOC_h2p(pObj->hText);
        pText += GUI_UC__NumChars2NumBytes(pText, pObj->NumCharsPrompt);
        if (pNew) {
          strcpy(pText, pNew);
        } else {
          *pText = 0;
        }
        _SetCursorPos(hObj, pObj, pObj->NumCharsPrompt);
        _InvalidateTextArea(hObj);
        _InvalidateNumChars(pObj);
        _InvalidateNumLines(pObj);
        _InvalidateTextSizeX(pObj);
      }
    }
    
//2007-09-14 gliethttp
    _SetMultiEdit_ScrollBarVis(hObj);
    WM_UNLOCK();
  }
}
<4>把MultiEdit中的光标去掉
//去掉MultiEdit.c文件中_MULTIEDIT_Paint()函数中的几行代码
static void _MULTIEDIT_Paint(MULTIEDIT_HANDLE hObj, MULTIEDIT_OBJ * pObj) {
  ......
  
//注释掉下面的程序
  
//2007-09-14 gliethttp
  
/*
  if (WM_HasFocus(hObj)) {
    _GetCursorXY(hObj, pObj, &x, &y);
    r.x0 = x + xOff;
    r.y0 = y + yOff;
    r.x1 = r.x0 + _GetCursorSizeX(hObj, pObj) - 1;
    r.y1 = r.y0 + FontSizeY - 1;
    GUI_InvertRect(r.x0, r.y0, r.x1, r.y1);
  }
  */

  ......
}
<5>自定义MultiEdit回调处理函数
static WM_CALLBACK* _cbCallback_show_multieditT;
static void _cbCallback_show_multiedit(WM_MESSAGE * pMsg)
{MULTIEDIT_OBJ* pObj;
 MULTIEDIT_HANDLE hObj;
     
    switch (pMsg->MsgId)
    {
        case WM_SET_FOCUS:
            _SetMultiEdit_ScrollBarVis(pMsg->hWin);
            break;
        case WM_KEY:
            if (((const WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt >0)
            {int Key = ((const WM_KEY_INFO*)(pMsg->Data.p))->Key;
                 hObj = pMsg->hWin;
                 pObj = MULTIEDIT_H2P(hObj);
                switch(Key)
                {
                    case GUI_KEY_LEFT:
                    case GUI_KEY_UP:_Go2PrevLineShow(hObj, pObj);return;
                    case GUI_KEY_RIGHT:
                    case GUI_KEY_ENTER:
                    case GUI_KEY_DOWN:_Go2NextLineShow(hObj, pObj);return;
                }
            }
            break;
    }
    _cbCallback_show_multieditT(pMsg);
}
<6>在建立的MultiEdit对象实例中,设置消息回调函数
...
_cbCallback_show_multieditT = WM_SetCallback(_hMEdit,_cbCallback_show_multiedit);;
...

PS:

文件: MultiEdit控件--中英文混合显示修改源文件.rar
大小: 10KB
下载: 下载

阅读(3173) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~