示例#1
0
bool WeaselPanel::_DrawPreedit(Text const& text, CDCHandle dc, CRect const& rc)
{
	bool drawn = false;
	wstring const& t = text.str;
	if (!t.empty())
	{
		weasel::TextRange range;
		vector<weasel::TextAttribute> const& attrs = text.attributes;
		for (size_t j = 0; j < attrs.size(); ++j)
			if (attrs[j].type == weasel::HIGHLIGHTED)
				range = attrs[j].range;

		if (range.start < range.end)
		{
			CSize selStart, selEnd;
			dc.GetTextExtent(t.c_str(), range.start, &selStart);
			dc.GetTextExtent(t.c_str(), range.end, &selEnd);
			int x = rc.left;
			if (range.start > 0)
			{
				// zzz
				std::wstring str_before(t.substr(0, range.start));
				CRect rc_before(x, rc.top, rc.left + selStart.cx, rc.bottom);
				_TextOut(dc, x, rc.top, rc_before, str_before.c_str(), str_before.length());
				x += selStart.cx + m_style.hilite_spacing;
			}
			else
			{
				x += m_style.hilite_padding;
			}
			{
				// zzz[yyy]
				std::wstring str_highlight(t.substr(range.start, range.end - range.start));
				CRect rc_hi(x, rc.top, x + (selEnd.cx - selStart.cx), rc.bottom);
				_HighlightText(dc, rc_hi, m_style.hilited_back_color);
				dc.SetTextColor(m_style.hilited_text_color);
				dc.SetBkColor(m_style.hilited_back_color);
				_TextOut(dc, x, rc.top, rc_hi, str_highlight.c_str(), str_highlight.length());
				dc.SetTextColor(m_style.text_color);
				dc.SetBkColor(m_style.back_color);
				x += (selEnd.cx - selStart.cx);
			}
			if (range.end < static_cast<int>(t.length()))
			{
				// zzz[yyy]xxx
				x += m_style.hilite_spacing;
				std::wstring str_after(t.substr(range.end));
				CRect rc_after(x, rc.top, rc.right, rc.bottom);
				_TextOut(dc, x, rc.top, rc_after, str_after.c_str(), str_after.length());
			}
		}
		else
		{
			CRect rcText(rc.left, rc.top, rc.right, rc.bottom);
			_TextOut(dc, rc.left, rc.top, rcText, t.c_str(), t.length());
		}
		drawn = true;
	}
	return drawn;
}
示例#2
0
int TextRenderer::Paragraph::doLayout(CDCHandle dc, int paragraphWidth) {
  dcassert(!words.empty());
  bool isFirstWord = true;
  HFONT lastFont = NULL;
  for (vector<Word>::iterator i = words.begin(); i != words.end(); ++i) {
    Word& w = *i;
    if (isFirstWord) {
      isFirstWord = false;
      dc.SelectFont(w.m_font);
      lastFont = w.m_font;
    }
    else if (lastFont != w.m_font) {
      dc.SelectFont(w.m_font);
      lastFont = w.m_font;
    }
    if (!w.m_text.empty()) {
      dc.GetTextExtent(w.m_text.c_str(), w.m_text.length(), &w.m_textSize);
    }
    else {
      dc.GetTextExtent(_T(" "), 1, &w.m_textSize);
      w.m_textSize.cx = 0;
    }
  }
  int x = 0;
  int y = 0;
  vector<Word*> currentWords;
  for (vector<Word>::iterator i = words.begin(); i != words.end(); ++i) {
    Word* w = &*i;
    if (!currentWords.empty() && (w->m_newLine || x + w->m_textSize.cx > paragraphWidth)) {
      // начинаем новую строку
      x = 0;
      y += layoutWords(currentWords, y);
      currentWords.clear();
    }
    w->m_location.x = x;
    x += w->m_textSize.cx + m_horizontalGap;
    currentWords.push_back(w);
  }
  return y + layoutWords(currentWords, y);
}
示例#3
0
CSeparator::CSeparator(HWND hParent, CPoint pt, int cx, const TCHAR *p)
{
   static int height;
   if (height == 0)
   {
      CDCHandle dc = ::GetDC(NULL);

      HFONT hOldFont = dc.SelectFont(Globals::Instance().sep.font);

      CSize textSize;
      dc.GetTextExtent(L"ABC", 3, &textSize);
      dc.SelectFont(hOldFont);
      height = textSize.cy;

      ::ReleaseDC(NULL, dc);
   }

	CRect rcSep(pt.x, pt.y, pt.x+cx, pt.y + (p && *p ? height : 5));
	Create(hParent, rcSep, nullptr, SS_GRAYFRAME | WS_CHILD | WS_VISIBLE);
	SetWindowText(p);
	ShowWindow(SW_SHOW);
}
示例#4
0
LRESULT CAnimMixer::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
  m_frameStep = 1.0f / 8.0f;

  const sChar* toggles[]={"Snap Left", "Snap Mid", "Snap Right", "Follow mode", 0}; // match this with bit order in flags
  for (m_cmdButtonCount = 0; toggles[m_cmdButtonCount]; m_cmdButtonCount++);

  CDCHandle dc = GetDC();
  CFontHandle oldFont = dc.SelectFont(AtlGetDefaultGuiFont());

  m_cmdButtons = new frButton[m_cmdButtonCount];

  sInt xpos = 4;
  for (sInt i = 0; i < m_cmdButtonCount; i++)
  {
    SIZE sz;
    dc.GetTextExtent(toggles[i], -1, &sz);

    const sInt width = sz.cx + 8;

    m_cmdButtons[i].Create(m_hWnd, CRect(xpos, 2, xpos+width, 22), toggles[i],
			WS_CHILD | WS_VISIBLE | FRBS_AUTO3D_SINGLE | FRBS_CHECK | FRBS_HOTTRACK | FRBS_SOLID | FRBS_AUTO, 0, i + 100);
    m_cmdButtons[i].SetFont(AtlGetDefaultGuiFont());
    m_cmdButtons[i].SetColorScheme(RGB(0, 0, 0), RGB(0, 0, 255), RGB(66, 65, 64), RGB(103, 99, 96),
      RGB(174, 169, 167), RGB(174, 169, 167), RGB(200, 198, 196));
		m_cmdButtons[i].SetCheck(m_flags & (1 << i));

    xpos += width + 1;
  }

  dc.SelectFont(oldFont);
  ReleaseDC(dc);

  bHandled = FALSE;
  return 0;
}
示例#5
0
void HorizontalLayout::DoLayout(CDCHandle dc)
{
	const std::vector<Text> &candidates(_context.cinfo.candies);
	const std::vector<Text> &comments(_context.cinfo.comments);
	const std::string &labels(_context.cinfo.labels);

	int width = 0, height = _style.margin_y;
	CSize size;

	/* Preedit */
	if (!_style.inline_preedit)
	{
		size = GetPreeditSize(dc);
		_preeditRect.SetRect(_style.margin_x, height, _style.margin_x + size.cx, height + size.cy);
		width = max(width, _style.margin_x + size.cx + _style.margin_x);
		height += size.cy + _style.spacing;
	}

	/* Auxiliary */
	if (!_context.aux.str.empty())
	{
		dc.GetTextExtent(_context.aux.str.c_str(), _context.aux.str.length(), &size);
		_auxiliaryRect.SetRect(_style.margin_x, height, _style.margin_x + size.cx, height + size.cy);
		width = max(width, _style.margin_x + size.cx + _style.margin_x);
		height += size.cy + _style.spacing;
	}

	/* Candidates */
	int w = _style.margin_x + _style.hilite_padding, h = 0;
	for (int i = 0; i < candidates.size(); i++)
	{
		/* Label */
		std::wstring label = GetLabelText(labels, i);
		dc.GetTextExtent(label.c_str(), label.length(), &size);
		_candidateLabelRects[i].SetRect(w, height, w + size.cx, height + size.cy);
		w += size.cx, h = max(h, size.cy);

		/* Text */
		const std::wstring& text = candidates.at(i).str;
		dc.GetTextExtent(text.c_str(), text.length(), &size);
		_candidateTextRects[i].SetRect(w, height, w + size.cx, height + size.cy);
		w += size.cx, h = max(h, size.cy);

		/* Comment */
		if (!comments.at(i).str.empty())
		{
			/* Add a space */
			dc.GetTextExtent(L" ", 1, &size);
			w += size.cx, h = max(h, size.cy);

			const std::wstring& comment = comments.at(i).str;
			dc.GetTextExtent(comment.c_str(), comment.length(), &size);
			_candidateCommentRects[i].SetRect(w, height, w + size.cx, height + size.cy);
			w += size.cx, h = max(h, size.cy);
		}
		else /* Used for highlighted candidate calculation below */
			_candidateCommentRects[i].SetRect(w, height, w, height + size.cy);
		w += _style.candidate_spacing;
	}
	w += _style.hilite_padding + _style.margin_x;

	/* Highlighted Candidate */
	int id = _context.cinfo.highlighted;
	_highlightRect.SetRect(
		_candidateLabelRects[id].left,
		height,
		_candidateCommentRects[id].right,
		height + h);

	width = max(width, w);
	height += h;

	if (candidates.size())
		height += _style.spacing;

	/* Trim the last spacing */
	if (height > 0)
		height -= _style.spacing;
	height += _style.margin_y;

	width = max(width, _style.min_width);
	height = max(height, _style.min_height);
	_contentSize.SetSize(width, height);
}
示例#6
0
void CDxDatePickerMonth::DrawDaysOfWeek(CDCHandle dc)
{
    if (m_rcDaysOfWeek.IsRectEmpty())
        return;

    // fill background
    dc.FillSolidRect(m_rcDaysOfWeek, m_clrDaysOfWeekBack);

    // draw days of week text
    dc.SetBkColor(m_clrDaysOfWeekBack);
    dc.SetTextColor(m_clrDaysOfWeekText);

    HFONT hFontOld = (HFONT)dc.SelectFont(CDxFontManager::GetSingleton().GetFont(DUIF_DEFAULTFONT));

    int nMaxX = 0;
    SIZE szText;

    dc.GetTextExtent(_T("XX"), 2, &szText);

    int nTwoLetterWidth = szText.cx;
    int nWholeLetterWidth = 0;

    for (int i = 0; i < XTP_WEEK_DAYS; i++)
    {
        CString strText(m_pControl->GetDayOfWeekName(i));

        dc.GetTextExtent(strText, strText.GetLength(), &szText);
        nWholeLetterWidth = max(nWholeLetterWidth, szText.cx);
    }

    for (int nDayDelta = 0; nDayDelta < XTP_WEEK_DAYS; nDayDelta++)
    {
        // calc item rect
        CDxDatePickerDay* pDay = GetDay(nDayDelta);
        CRect rcItem(pDay->GetRect());
        rcItem.top = m_rcDaysOfWeek.top;
        rcItem.bottom = m_rcDaysOfWeek.bottom - 2;
        nMaxX = rcItem.right;

        // get item text
        CString strText(m_pControl->GetDayOfWeekName(pDay->GetDate().GetDayOfWeek()));

        // Check if we can draw whole text
        if (nWholeLetterWidth + 4 <= rcItem.Width())
        {
            dc.DrawText(strText, strText.GetLength(), &rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
        }
        else if (nTwoLetterWidth + 4 <= rcItem.Width()) // Draw 2 letters
        {
            int nChrLen = (int)_tcsnbcnt(strText, 2);
            dc.DrawText(strText, nChrLen, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
        }
        else // Draw only first letter
        {
            int nChrLen = (int)_tcsnbcnt(strText, 1);
            dc.DrawText(strText, nChrLen, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
        }
    }

    // draw bottom line on days of the week
    CRect rcBottomLine(m_rcDaysOfWeek);
    rcBottomLine.bottom--;
    rcBottomLine.top = rcBottomLine.bottom - 1;
    rcBottomLine.left = m_rcWeekNumbers.right - 1;
    rcBottomLine.right = nMaxX;
    dc.FillSolidRect(rcBottomLine, m_clrMonthBorder);

    dc.SelectFont(hFontOld);
}