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

📄 paint.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 2 页
字号:
  {
    /* descent is usually (always?) 0 for graphics */
    PatBlt(c->hDC, x, y-run->nAscent, sz.cx, run->nAscent+run->nDescent, DSTINVERT);    
  }
}

static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para) {
  ME_Run *run = &rundi->member.run;
  int runofs = run->nCharOfs+para->nCharOfs;
  
  /* you can always comment it out if you need visible paragraph marks */
  if (run->nFlags & (MERF_ENDPARA|MERF_TAB)) 
    return;
  if (run->nFlags & MERF_GRAPHICS) {
    int blfrom, blto;
    ME_GetSelection(c->editor, &blfrom, &blto);
    ME_DrawGraphics(c, x, y, run, para, (runofs >= blfrom) && (runofs < blto));
  } else
  {
    int blfrom, blto;
    ME_DisplayItem *start = ME_FindItemBack(rundi, diStartRow);
    ME_GetSelection(c->editor, &blfrom, &blto);
    
    ME_DrawTextWithStyle(c, x, y, 
      run->strText->szData, ME_StrVLen(run->strText), run->style, NULL, 
        blfrom-runofs, blto-runofs, c->pt.y+start->member.row.nYPos, start->member.row.nHeight);
  }
}

COLORREF ME_GetBackColor(ME_TextEditor *editor)
{
/* Looks like I was seriously confused
    return GetSysColor((GetWindowLong(editor->hWnd, GWL_STYLE) & ES_READONLY) ? COLOR_3DFACE: COLOR_WINDOW);
*/
  if (editor->rgbBackColor == -1)
    return GetSysColor(COLOR_WINDOW);
  else
    return editor->rgbBackColor;
}

void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
  int align = SetTextAlign(c->hDC, TA_BASELINE);
  ME_DisplayItem *p;
  ME_Run *run;
  ME_Paragraph *para = NULL;
  RECT rc, rcPara;
  int y = c->pt.y;
  int height = 0, baseline = 0, no=0, pno = 0;
  int xs, xe;
  int visible = 0;
  int nMargWidth = 0;
  
  c->pt.x = c->rcView.left;
  rcPara.left = c->rcView.left;
  rcPara.right = c->rcView.right;
  for (p = paragraph; p!=paragraph->member.para.next_para; p = p->next) {
    switch(p->type) {
      case diParagraph:
        para = &p->member.para;
        break;
      case diStartRow:
        assert(para);
        nMargWidth = (pno==0?para->nFirstMargin:para->nLeftMargin);
        xs = c->rcView.left+nMargWidth;
        xe = c->rcView.right-para->nRightMargin;
        y += height;
        rcPara.top = y;
        rcPara.bottom = y+p->member.row.nHeight;
        visible = RectVisible(c->hDC, &rcPara);
        if (visible) {
          HBRUSH hbr;
          hbr = CreateSolidBrush(ME_GetBackColor(c->editor));
          /* left margin */
          rc.left = c->rcView.left;
          rc.right = c->rcView.left+nMargWidth;
          rc.top = y;
          rc.bottom = y+p->member.row.nHeight;
          FillRect(c->hDC, &rc, hbr/* c->hbrMargin */);
          /* right margin */
          rc.left = xe;
          rc.right = c->rcView.right;
          FillRect(c->hDC, &rc, hbr/* c->hbrMargin */);
          rc.left = c->rcView.left+nMargWidth;
          rc.right = xe;
          FillRect(c->hDC, &rc, hbr);
          DeleteObject(hbr);
        }
        if (me_debug)
        {
          const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
          WCHAR buf[128];
          POINT pt = c->pt;
          wsprintfW(buf, wszRowDebug, no);
          pt.y = 12+y;
          ME_DebugWrite(c->hDC, &pt, buf);
        }
        
        height = p->member.row.nHeight;
        baseline = p->member.row.nBaseline;
        pno++;
        break;
      case diRun:
        assert(para);
        run = &p->member.run;
        if (visible && me_debug) {
          rc.left = c->rcView.left+run->pt.x;
          rc.right = c->rcView.left+run->pt.x+run->nWidth;
          rc.top = c->pt.y+run->pt.y;
          rc.bottom = c->pt.y+run->pt.y+height;
          TRACE("rc = (%ld, %ld, %ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
          if (run->nFlags & MERF_SKIPPED)
            DrawFocusRect(c->hDC, &rc);
          else
            FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
        }
        if (visible)
          ME_DrawRun(c, run->pt.x, c->pt.y+run->pt.y+baseline, p, &paragraph->member.para);
        if (me_debug)
        {
          /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
          const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
          WCHAR buf[2560];
          POINT pt;
          pt.x = run->pt.x;
          pt.y = c->pt.y + run->pt.y;
          wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
          ME_DebugWrite(c->hDC, &pt, buf);
        }
        /* c->pt.x += p->member.run.nWidth; */
        break;
      default:
        break;
    }
    no++;
  }
  SetTextAlign(c->hDC, align);
}

void ME_Scroll(ME_TextEditor *editor, int cx, int cy)
{
  SCROLLINFO si;
  HWND hWnd = editor->hWnd;

  si.cbSize = sizeof(SCROLLINFO);
  si.fMask = SIF_POS;
  GetScrollInfo(hWnd, SB_VERT, &si);
  si.nPos = editor->nScrollPosY -= cy;
  SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
  if (editor->bRedraw)
  {
    if (abs(cy) > editor->sizeWindow.cy)
      InvalidateRect(editor->hWnd, NULL, TRUE);
    else
      ScrollWindowEx(hWnd, cx, cy, NULL, NULL, NULL, NULL, SW_ERASE|SW_INVALIDATE);
  }
}

void ME_UpdateScrollBar(ME_TextEditor *editor)
{
  HWND hWnd = editor->hWnd;
  SCROLLINFO si;
  int nOldLen = editor->nTotalLength;
  BOOL bScrollY = (editor->nTotalLength > editor->sizeWindow.cy);
  BOOL bUpdateScrollBars;
  si.cbSize = sizeof(si);
  si.fMask = SIF_POS | SIF_RANGE;
  GetScrollInfo(hWnd, SB_VERT, &si);
  bUpdateScrollBars = (bScrollY || editor->bScrollY)&& ((si.nMax != nOldLen) || (si.nPage != editor->sizeWindow.cy));
  
  if (bScrollY != editor->bScrollY)
  {
    si.fMask = SIF_RANGE | SIF_PAGE;
    si.nMin = 0;
    si.nPage = editor->sizeWindow.cy;
    if (bScrollY) {
      si.nMax = editor->nTotalLength;
    } else {
      si.nMax = 0;
    }
    SetScrollInfo(hWnd, SB_VERT, &si, FALSE);
    ME_MarkAllForWrapping(editor);
    editor->bScrollY = bScrollY;
    ME_WrapMarkedParagraphs(editor);
    bUpdateScrollBars = TRUE;
  }
  if (bUpdateScrollBars) {
    int nScroll = 0;
    si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
    if (editor->nTotalLength > editor->sizeWindow.cy) {
      si.nMax = editor->nTotalLength;
      si.nPage = editor->sizeWindow.cy;
      if (si.nPos > si.nMax-si.nPage) {
        nScroll = (si.nMax-si.nPage)-si.nPos;
        si.nPos = si.nMax-si.nPage;
      }
    }
    else {
      si.nMax = 0;
      si.nPage = 0;
      si.nPos = 0;
    }
    TRACE("min=%d max=%d page=%d pos=%d shift=%d\n", si.nMin, si.nMax, si.nPage, si.nPos, nScroll);
    editor->nScrollPosY = si.nPos;
    SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
    if (nScroll)
      ScrollWindow(hWnd, 0, -nScroll, NULL, NULL);
  }
}

int ME_GetYScrollPos(ME_TextEditor *editor)
{
  return editor->nScrollPosY;
}

void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun)
{
  ME_DisplayItem *pRow = ME_FindItemBack(pRun, diStartRow);
  ME_DisplayItem *pPara = ME_FindItemBack(pRun, diParagraph);
  int y, yrel, yheight, yold;
  HWND hWnd = editor->hWnd;
  
  assert(pRow);
  assert(pPara);
  
  y = pPara->member.para.nYPos+pRow->member.row.nYPos;
  yheight = pRow->member.row.nHeight;
  yold = ME_GetYScrollPos(editor);
  yrel = y - yold;
  if (yrel < 0) {
    editor->nScrollPosY = y;
    SetScrollPos(hWnd, SB_VERT, y, TRUE);
    if (editor->bRedraw)
    {
      ScrollWindow(hWnd, 0, -yrel, NULL, NULL);
      UpdateWindow(hWnd);
    }
  } else if (yrel + yheight > editor->sizeWindow.cy) {
    int newy = y+yheight-editor->sizeWindow.cy;
    editor->nScrollPosY = newy;
    SetScrollPos(hWnd, SB_VERT, newy, TRUE);
    if (editor->bRedraw)
    {
      ScrollWindow(hWnd, 0, -(newy-yold), NULL, NULL);
      UpdateWindow(hWnd);
    }
  }
}
        

BOOL
ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
{
  /* TODO: Zoom images and objects */

  if (numerator != 0)
  {
    if (denominator == 0)
      return FALSE;
    if (1.0 / 64.0 > (float)numerator / (float)denominator
        || (float)numerator / (float)denominator > 64.0)
      return FALSE;
  }
  
  editor->nZoomNumerator = numerator;
  editor->nZoomDenominator = denominator;
  
  ME_RewrapRepaint(editor);
  return TRUE;
}

⌨️ 快捷键说明

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