Example #1
0
void NotificationWnd::UpdateWindowPosition(const WCHAR *message, bool init)
{
    // compute the length of the message
    RECT rc = ClientRect(self).ToRECT();
    HDC hdc = GetDC(self);
    HFONT oldfnt = SelectFont(hdc, font);
    DrawText(hdc, message, -1, &rc, DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX);
    SelectFont(hdc, oldfnt);
    ReleaseDC(self, hdc);

    RectI rectMsg = RectI::FromRECT(rc);
    if (hasCancel) {
        rectMsg.dy = max(rectMsg.dy, 16);
        rectMsg.dx += 20;
    }
    rectMsg.Inflate(PADDING, PADDING);

    // adjust the window to fit the message (only shrink the window when there's no progress bar)
    if (!hasProgress) {
        SetWindowPos(self, NULL, 0, 0, rectMsg.dx, rectMsg.dy, SWP_NOMOVE | SWP_NOZORDER);
    } else if (init) {
        RectI rect = WindowRect(self);
        rect.dx = max(progressWidth + 2 * PADDING, rectMsg.dx);
        rect.dy = rectMsg.dy + PROGRESS_HEIGHT + PADDING / 2;
        SetWindowPos(self, NULL, 0, 0, rect.dx, rect.dy, SWP_NOMOVE | SWP_NOZORDER);
    } else if (rectMsg.dx > progressWidth + 2 * PADDING) {
        SetWindowPos(self, NULL, 0, 0, rectMsg.dx, WindowRect(self).dy, SWP_NOMOVE | SWP_NOZORDER);
    }

    // move the window to the right for a right-to-left layout
    if (IsUIRightToLeft()) {
        HWND parent = GetParent(self);
        RectI rect = MapRectToWindow(WindowRect(self), HWND_DESKTOP, parent);
        rect.x = WindowRect(parent).dx - rect.dx - TL_MARGIN - GetSystemMetrics(SM_CXVSCROLL);
        SetWindowPos(self, NULL, rect.x, rect.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
    }
}
Example #2
0
void
text_copy_to_clipboard(TW *tw)
{
    int size, count;
    HGLOBAL hGMem;
    LPSTR cbuf, cp;
    TEXTMETRIC tm;
    UINT type;
    HDC hdc;
    int i;

    size = tw->ScreenSize.y * (tw->ScreenSize.x + 2) + 1;
    hGMem = GlobalAlloc(GHND | GMEM_SHARE, (DWORD)size);
    cbuf = cp = (LPSTR)GlobalLock(hGMem);
    if (cp == (LPSTR)NULL)
	return;
    
    for (i=0; i<tw->ScreenSize.y; i++) {
	count = tw->ScreenSize.x;
	memcpy(cp, tw->ScreenBuffer + tw->ScreenSize.x*i, count);
	/* remove trailing spaces */
	for (count=count-1; count>=0; count--) {
		if (cp[count]!=' ')
			break;
		cp[count] = '\0';
	}
	cp[++count] = '\r';
	cp[++count] = '\n';
	cp[++count] = '\0';
	cp += count;
    }
    size = strlen(cbuf) + 1;
    GlobalUnlock(hGMem);
    hGMem = GlobalReAlloc(hGMem, (DWORD)size, GHND | GMEM_SHARE);
    /* find out what type to put into clipboard */
    hdc = GetDC(tw->hwnd);
    SelectFont(hdc, tw->hfont);
    GetTextMetrics(hdc,(TEXTMETRIC FAR *)&tm);
    if (tm.tmCharSet == OEM_CHARSET)
	type = CF_OEMTEXT;
    else
	type = CF_TEXT;
    ReleaseDC(tw->hwnd, hdc);
    /* give buffer to clipboard */
    OpenClipboard(tw->hwnd);
    EmptyClipboard();
    SetClipboardData(type, hGMem);
    CloseClipboard();
}
Example #3
0
// 向表面输出文字
void CGDITextRender::TextOut(CGDISurface *pSurface, int x, int y, const char *szString, COLORREF c, int len)
{
    // 如果指定的字符串长度是0
    if (len == 0)
    {
        // 自动获取字符串长度
        len = (int)strlen(szString);
    }
	
    // 获得表面设备句柄
    HDC hdc = pSurface->GetDC();
	
    // 选择字体
    HFONT hOldFont = SelectFont(hdc, m_hFont);
	
    // 显示文字
    SetBkMode(hdc, TRANSPARENT);
    SetBkColor(hdc, RGB(0,0,0));
    SetTextColor(hdc, c);
    ::TextOut(hdc, x, y, szString, len);
	
    // 恢复字体
    SelectFont(hdc, hOldFont);
}
Example #4
0
void TextRenderGdi::Lock() {
    CrashIf(hdcGfxLocked);
    Region r;
    Status st = gfx->GetClip(&r); // must call before GetHDC(), which locks gfx
    CrashIf(st != Ok);
    HRGN hrgn = r.GetHRGN(gfx);

    hdcGfxLocked = gfx->GetHDC();
    SelectClipRgn(hdcGfxLocked, hrgn);
    DeleteObject(hrgn);

    SelectFont(hdcGfxLocked, currFont);
    ::SetTextColor(hdcGfxLocked, textColor.ToCOLORREF());
    ::SetBkColor(hdcGfxLocked, textBgColor.ToCOLORREF());
}
Example #5
0
/**
 * @brief 設定ダイアログ用メッセージ ハンドラ
 * @param hDlg : ウィンドウハンドル
 * @param message : メッセージ
 * @param wParam : メッセージのパラメータ
 * @param lParam : メッセージのパラメータ
 *
 * 設定ダイアログのウィンドウメッセージを処理する。
 */
static LRESULT CALLBACK
Setting(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UINT length;
    UINT chk;

    switch (message) {
    case WM_INITDIALOG:
        chk = (adjustwindow != 0) ? BST_CHECKED : BST_UNCHECKED;
        ::CheckDlgButton(hDlg, IDC_ADJUSTWINDOW, chk);
        ::SetDlgItemText(hDlg, IDC_HEADERS, setstr);
        return TRUE;

    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDOK:
            length =
                ::GetDlgItemText(hDlg, IDC_HEADERS, setstr, setsize);
            adjustwindow = ::IsDlgButtonChecked(hDlg, IDC_ADJUSTWINDOW);
            ::EndDialog(hDlg, LOWORD(wParam));
            return TRUE;
            break;
        case IDCANCEL:
            ::EndDialog(hDlg, LOWORD(wParam));
            return TRUE;
            break;
        case IDC_ABOUT:
            DoAbout(hInstance, hDlg);
            break;
        case IDC_FONT:
            SelectFont();
            break;
        case IDC_HEADERCOLOR:
            SelectHeaderColor();
            break;
        case IDC_NAMECOLOR:
            SelectNameColor();
            break;
        case IDC_BODYCOLOR:
            SelectBodyColor();
            break;
        }
        break;
    default:
        break;
    }
    return FALSE;
}
static void PASCAL GetFontMetrics (HFONT hFont, TEXTMETRIC *Metrics,
                                        char *FaceName)
/* If either Metrics of FaceName is NULL, the corresponding value is not
   returned. If not NULL, FaceName must point to a string containing at
   least LF_FACESIZE characters */
{
    HDC     hDC;
    HFONT   hPrevFont;

    hDC = GetDC (hFrameWnd);
    hPrevFont = SelectFont (hDC, hFont);
    if (Metrics) GetTextMetrics (hDC, Metrics);
    if (FaceName) GetTextFace (hDC, LF_FACESIZE, FaceName);
    SelectObject (hDC, hPrevFont);
    ReleaseDC (hFrameWnd, hDC);
} /* GetFontMetrics */
Example #7
0
/* Updates cursor position */
static void
text_update_text(TW *tw, int count)
{
HDC hdc;
int xpos, ypos;
	xpos = tw->CursorPos.x*tw->CharSize.x - tw->ScrollPos.x;
	ypos = tw->CursorPos.y*tw->CharSize.y - tw->ScrollPos.y;
	hdc = GetDC(tw->hwnd);
	SelectFont(hdc, tw->hfont);
	TextOut(hdc,xpos,ypos,
		(LPSTR)(tw->ScreenBuffer + tw->CursorPos.y*tw->ScreenSize.x 
		+ tw->CursorPos.x), count);
	(void)ReleaseDC(tw->hwnd,hdc);
	tw->CursorPos.x += count;
	if (tw->CursorPos.x >= tw->ScreenSize.x)
		text_new_line(tw);
}
Example #8
0
static PetscErrorCode PetscDrawStringVertical_Win32(PetscDraw draw,PetscReal x,PetscReal y,int color,const char *text)
{       
  PetscDraw_Win32 *windraw = (PetscDraw_Win32*)draw->data;
  RECT            r;
  HFONT           hfont;                                                                                    
  LOGFONT         logfont;
  int             x1,yone;
  HDC             hdc;
  
  PetscFunctionBegin;
  x1           = XTRANS(draw,windraw,x);
  yone           = YTRANS(draw,windraw,y);
  r.left       = x1;
  r.bottom     = yone + 30;
  r.right      = x1 + 1;
  r.top        = yone - 30;
  logfont.lfEscapement     = 2700; /* Causes verticle text drawing */
  logfont.lfHeight         = windraw->stringheight;
  logfont.lfWidth          = windraw->stringwidth;
  logfont.lfOrientation    = 0;
  logfont.lfCharSet        = DEFAULT_CHARSET;
  logfont.lfClipPrecision  = 0;
  logfont.lfItalic         = 0;
  logfont.lfOutPrecision   = 0;
  logfont.lfPitchAndFamily = DEFAULT_PITCH;
  logfont.lfQuality        = DEFAULT_QUALITY;
  logfont.lfStrikeOut      = 0;
  logfont.lfUnderline      = 0;
  logfont.lfWeight         = FW_NORMAL;
  hfont = CreateFontIndirect(&logfont);
  TranslateColor_Win32(draw,color);
  if(windraw->node->DoubleBuffered) {
    hdc = windraw->node->DoubleBuffer;
  } else {
    hdc = windraw->node->Buffer;
  }
  SelectFont(hdc,hfont);
  SetTextColor(hdc,windraw->currentcolor);
  DrawText(hdc,text,lstrlen(text),&r,DT_NOCLIP | DT_SINGLELINE );
  DeleteObject(hfont);
  /* Forces a WM_PAINT message and erases background */
  InvalidateRect(windraw->hWnd,NULL,TRUE);
  UpdateWindow(windraw->hWnd);
  PetscFunctionReturn(0);
}
Example #9
0
void OnPaint(HWND hwnd)
{
    static TEXTMETRIC tm;

    RECT rc;
    GetClientRect(hwnd, &rc);

    SYSTEMTIME tmNow;
    GetLocalTime(&tmNow);
    wchar_t wszBuf[128];
    wsprintf(wszBuf, L"%02d:%02d:%02d.%03d", tmNow.wHour, tmNow.wMinute, tmNow.wSecond, tmNow.wMilliseconds);

    SelectFont(g_app.hdcMem, g_app.hFont);
    SelectPen(g_app.hdcMem, g_app.hPen);
    SetBkMode(g_app.hdcMem, TRANSPARENT);
    SetTextColor(g_app.hdcMem, RGB(0x66, 0x00, 0x00));

    SIZE size;
    GetTextExtentPoint32(g_app.hdcMem, wszBuf, (int)wcslen(wszBuf), &size);

    if (!tm.tmHeight) {
        GetTextMetrics(g_app.hdcMem, &tm);
        g_app.nTx = 3;
    }

    g_app.rcText = rc;
    g_app.rcText.top = rc.bottom / 2 - tm.tmHeight / 2;
    g_app.rcText.left = rc.right / 2 - tm.tmAveCharWidth * 6;
    g_app.rcText.bottom = g_app.rcText.top + size.cy;
    g_app.rcText.right = g_app.rcText.left + size.cx;
    
    FillRect(g_app.hdcMem, &rc, GetStockBrush(BLACK_BRUSH));
    DrawText(g_app.hdcMem, wszBuf, (int)wcslen(wszBuf), &g_app.rcText, DT_LEFT);

    MoveToEx(g_app.hdcMem, g_app.rcText.left, g_app.rcText.bottom, NULL);
    LineTo(g_app.hdcMem, g_app.rcText.right, g_app.rcText.bottom);
    
    PAINTSTRUCT ps;
    HDC hdc = BeginPaint(hwnd, &ps);
    BitBlt(hdc, 0, 0, rc.right, rc.bottom, g_app.hdcMem, 0, 0, SRCCOPY);
    EndPaint(hwnd, &ps);
}
Example #10
0
LRESULT HyperlinkCtrl::WndProc(UINT message, WPARAM wparam, LPARAM lparam)
{
	switch(message) {
	  case PM_DISPATCH_CTLCOLOR: {
		if (!_hfont) {
			HFONT hfont = (HFONT) SendMessage(_hwnd, WM_GETFONT, 0, 0);
			LOGFONT lf; GetObject(hfont, sizeof(lf), &lf);
			lf.lfUnderline = TRUE;
			_hfont = CreateFontIndirect(&lf);
		}

		HDC hdc = (HDC) wparam;
		SetTextColor(hdc, _textColor);	//@@
		SelectFont(hdc, _hfont);
		SetBkMode(hdc, TRANSPARENT);
		return (LRESULT)GetStockObject(HOLLOW_BRUSH);
	  }

	  case WM_SETCURSOR:
		if (!_crsr_link)
			_crsr_link = LoadCursor(0, IDC_HAND);

		if (_crsr_link)
			SetCursor(_crsr_link);
		return 0;

	  case WM_NCHITTEST:
		return HTCLIENT;	// Aktivierung von Maus-Botschaften

	  case WM_LBUTTONDOWN:
		if (LaunchLink()) {
			_textColor = _colorVisited;
			InvalidateRect(_hwnd, NULL, FALSE);
		} else
			MessageBeep(0);
		return 0;

	  default:
		return super::WndProc(message, wparam, lparam);
	}
}
Example #11
0
void PrintLegend (HDC hDC, PGRAPHSTRUCT pGraph, HWND hWndLegend,
                  RECT rectLegend)
   {
   PLEGEND        pLegend ;
   int            yItemHeight ;
   HFONT          hFontItems ;
   PLINE          pLine ;
   int            iIndex ;
   int            iIndexNum ;


   pLegend = LegendData (hWndLegend) ;

   yItemHeight = pLegend->yItemHeight ;
   hFontItems = pLegend->hFontItems ;

   pLegend->hFontItems = hFontPrinterScales ;
   SelectFont (hDC, pLegend->hFontItems) ;

   pLegend->yItemHeight = FontHeight (hDC, TRUE) ;

   iIndexNum = LBNumItems (pLegend->hWndItems) ;
   for (iIndex = 0 ;
        iIndex < iIndexNum ;
        iIndex++)
      {  // for
      pLine = (PLINE) LBData (pLegend->hWndItems, iIndex) ;
      DrawLegendItem (pLegend, pLine, iIndex * pLegend->yItemHeight, hDC) ;
      }  // for

   pLegend->hFontItems = hFontItems ;
   pLegend->yItemHeight = yItemHeight ;


   SelectBrush (hDC, GetStockObject (HOLLOW_BRUSH)) ;
   SelectPen (hDC, GetStockObject (BLACK_PEN)) ;
   Rectangle (hDC, 0, 0, 
              rectLegend.right - rectLegend.left,
              rectLegend.bottom - rectLegend.top) ;
   }
Example #12
0
nglKernel::~nglKernel()
{
  Exit(0);
  SelectFont(mHDC, NULL);
  if (mSystemFont)
    DeleteFont(mSystemFont);

  if (mpDirect3D)
    mpDirect3D->Release();

  if (mHWnd) 
  {
    DestroyWindow(mHWnd);
  }
  mHWnd = NULL;
  mHDC = NULL;

  if (mHInstance)
  {
    UnregisterClass(NGL_CORE_CLASS, mHInstance);
  }
}
Example #13
0
static void	MyDrawStrings (SplashWindowInfoPtr pmInfo, HDC pmDisplayContext, 
			     HFONT pmFont, char *pmString[], int pmLines, 
			     int *pmY, BOOL pmDraw, BOOL pmOpaque)
{
    SIZE		mySize;
    int			myX, myWidth, cnt;
    
    SelectFont (pmDisplayContext, pmFont);
    GetTextExtentPoint32 (pmDisplayContext, pmString [0], strlen (pmString [0]), 
        &mySize);
    myWidth = mySize.cx;
    for (cnt = 1 ; cnt < pmLines ; cnt++)
    {
    	GetTextExtentPoint32 (pmDisplayContext, pmString [cnt],
	    strlen (pmString [cnt]), &mySize);
    	myWidth = max (myWidth, mySize.cx);
    }
    myX = (pmInfo -> windowWidth - myWidth) / 2;
    	
    for (cnt = 0 ; cnt < pmLines ; cnt++)
    {	
    	if (pmDraw)
    	{
    	    if (!pmOpaque)
    	    {
    	    	SetBkMode (pmDisplayContext, TRANSPARENT);
    	    }
    	    ExtTextOut (pmDisplayContext, myX, *pmY, 0, NULL, 
    	    	pmString [cnt], strlen (pmString [cnt]), NULL);
    	    if (!pmOpaque)
    	    {
    	    	SetBkMode (pmDisplayContext, OPAQUE);\
    	    }
    	}
    	*pmY = *pmY + mySize.cy;
    }
} // MyDrawStrings 
Example #14
0
/**
 * @param dwCachedLineNum - index of cached line.
 */
void CTextView::CacheLine(DWORD dwCachedLineNum)
{
	if (dwCachedLineNum >= m_dwFirstCachedLine && dwCachedLineNum < m_dwFirstCachedLine + m_dwNumCachedLines)
		return;

	HDC hdc = GetDC(m_hwnd);
	HFONT hOldFont = g_pResManager->m_hFixedFont ? SelectFont(hdc, g_pResManager->m_hFixedFont) : NULL;
	TEXTMETRIC tmetr;
	::GetTextMetrics(hdc, &tmetr);
	int nExtraWidth = tmetr.tmAveCharWidth + LOWORD(GetTabbedTextExtent(hdc, g_szEllipsis, g_dwEllipsisLength, 0, NULL));
	int nMaxLineWidth = 0;

	DWORD dwNumLines = m_arrLines.GetCount();
	_ASSERT(dwCachedLineNum < dwNumLines);
	// Put new line into the middle of cache
	const CLineInfo& rLineInfo = m_arrLines[(int)dwCachedLineNum];
	DWORD dwFirstCachedLine = dwCachedLineNum,
		  dwLastCachedLine = dwCachedLineNum,
		  dwTotalSize = rLineInfo.m_dwLength;
	BOOL bCanMoveFirstCachedLine = TRUE, bCanMoveLastCachedLine = TRUE;
	do
	{
		if (bCanMoveFirstCachedLine)
		{
			BOOL bLineNumberChanged = FALSE;
			if (dwFirstCachedLine > 0)
			{
				const CLineInfo& rLineInfo = m_arrLines[(int)(dwFirstCachedLine - 1)];
				if (dwTotalSize + rLineInfo.m_dwLength <= TEXT_CACHE_SIZE)
				{
					dwTotalSize += rLineInfo.m_dwLength;
					--dwFirstCachedLine;
					bLineNumberChanged = TRUE;
				}
			}
			bCanMoveFirstCachedLine = bLineNumberChanged;
		}
		if (bCanMoveLastCachedLine)
		{
			BOOL bLineNumberChanged = FALSE;
			if (dwLastCachedLine + 1 < dwNumLines)
			{
				const CLineInfo& rLineInfo = m_arrLines[(int)(dwLastCachedLine + 1)];
				if (dwTotalSize + rLineInfo.m_dwLength <= TEXT_CACHE_SIZE)
				{
					dwTotalSize += rLineInfo.m_dwLength;
					++dwLastCachedLine;
					bLineNumberChanged = TRUE;
				}
			}
			bCanMoveLastCachedLine = bLineNumberChanged;
		}
	}
	while (bCanMoveFirstCachedLine || bCanMoveLastCachedLine);

	DWORD dwNumCachedLines = dwLastCachedLine - dwFirstCachedLine + 1;
	DWORD dwFirstMappedLine, dwLastMappedLine, dwNumMappedLines, dwFirstLoadedLine, dwLastLoadedLine, dwNumLoadedLines, dwFromMemOffset, dwToMemOffset, dwLoadOffset, dwMemSize;
	if (m_dwFirstCachedLine <= dwFirstCachedLine && dwFirstCachedLine < m_dwFirstCachedLine + m_dwNumCachedLines)
	{
		dwFirstMappedLine = dwFirstCachedLine;
		dwNumMappedLines = m_dwNumCachedLines - (dwFirstCachedLine - m_dwFirstCachedLine);
		dwLastMappedLine = dwFirstMappedLine + dwNumMappedLines - 1;

		dwFirstLoadedLine = dwFirstMappedLine + dwNumMappedLines;
		dwNumLoadedLines = dwNumCachedLines - dwNumMappedLines;
		dwLastLoadedLine = dwFirstLoadedLine + dwNumLoadedLines - 1;

		const CLineInfo& rLineInfo1 = m_arrLines[(int)dwFirstMappedLine];
		const CLineInfo& rLineInfo2 = m_arrLines[(int)dwLastMappedLine];
		dwFromMemOffset = rLineInfo1.m_dwTextStart;
		dwToMemOffset = 0;
		dwLoadOffset = dwMemSize = rLineInfo2.m_dwTextStart + rLineInfo2.m_dwLength - rLineInfo1.m_dwTextStart;
	}
	else if (dwFirstCachedLine <= m_dwFirstCachedLine && m_dwFirstCachedLine < dwFirstCachedLine + dwNumCachedLines)
	{
		dwFirstMappedLine = m_dwFirstCachedLine;
		dwNumMappedLines = dwNumCachedLines - (m_dwFirstCachedLine - dwFirstCachedLine);
		dwLastMappedLine = dwFirstMappedLine + dwNumMappedLines - 1;

		dwFirstLoadedLine = dwFirstCachedLine;
		dwNumLoadedLines = dwNumCachedLines - dwNumMappedLines;
		dwLastLoadedLine = dwFirstLoadedLine + dwNumLoadedLines - 1;

		const CLineInfo& rLineInfo1 = m_arrLines[(int)dwFirstMappedLine];
		const CLineInfo& rLineInfo2 = m_arrLines[(int)dwLastMappedLine];
		dwFromMemOffset = rLineInfo1.m_dwTextStart;
		dwToMemOffset = 0;
		dwMemSize = rLineInfo2.m_dwTextStart + rLineInfo2.m_dwLength - rLineInfo1.m_dwTextStart;
		for (DWORD dwLineNum = dwFirstLoadedLine; dwLineNum <= dwLastLoadedLine; ++dwLineNum)
		{
			const CLineInfo& rLineInfo = m_arrLines[(int)dwLineNum];
			dwToMemOffset += rLineInfo.m_dwLength;
		}
		dwLoadOffset = 0;
	}
	else
	{
		dwFirstMappedLine = dwLastMappedLine = dwNumMappedLines = dwFromMemOffset = dwToMemOffset = dwMemSize = 0;

		dwFirstLoadedLine = dwFirstCachedLine;
		dwNumLoadedLines = dwNumCachedLines;
		dwLastLoadedLine = dwFirstLoadedLine + dwNumLoadedLines - 1;
		dwLoadOffset = 0;
	}

	_ASSERTE(m_pTextCache != NULL);
	if (dwNumMappedLines > 0)
	{
		MoveMemory(m_pTextCache + dwToMemOffset, m_pTextCache + dwFromMemOffset, dwMemSize * sizeof(TCHAR));
		for (DWORD dwLineNum = dwFirstMappedLine; dwLineNum <= dwLastMappedLine; ++dwLineNum)
		{
			CLineInfo& rLineInfo = m_arrLines[(int)dwLineNum];
			rLineInfo.m_dwTextStart = dwToMemOffset;
			dwToMemOffset += rLineInfo.m_dwLength;
		}
	}

	if (dwNumLoadedLines > 0)
	{
		DWORD dwLineBufferPos = 0, dwLineNum = dwFirstLoadedLine;
		const CLineInfo& rLineInfo = m_arrLines[(int)dwLineNum];
		SetFilePointer(m_hFile, rLineInfo.m_dwLineStart, NULL, FILE_BEGIN);
		while (dwLineNum <= dwLastLoadedLine)
		{
			DWORD dwNumRead = 0;
			if (! ReadFile(m_hFile, m_pLineBuffer + dwLineBufferPos, m_dwLineBufferSize - dwLineBufferPos, &dwNumRead, NULL))
				return;
			dwNumRead += dwLineBufferPos;
			dwLineBufferPos = 0;
			if (dwNumRead == 0)
				break;
			while (dwLineNum <= dwLastLoadedLine)
			{
				CLineInfo& rLineInfo = m_arrLines[(int)dwLineNum];
				DWORD dwLineSize;
				if (dwLineNum < dwLastLoadedLine)
				{
					const CLineInfo& rNextLineInfo = m_arrLines[(int)(dwLineNum + 1)];
					dwLineSize = rNextLineInfo.m_dwLineStart - rLineInfo.m_dwLineStart; // line size including line end
				}
				else
					dwLineSize = rLineInfo.m_dwSize;
				DWORD dwBytesLeft = dwNumRead - dwLineBufferPos;
				if (dwLineSize > dwBytesLeft)
				{
					MoveMemory(m_pLineBuffer, m_pLineBuffer + dwLineBufferPos, dwBytesLeft);
					dwLineBufferPos = dwBytesLeft;
					break;
				}
				m_pDecoder->DecodeString(m_pLineBuffer + dwLineBufferPos, rLineInfo.m_dwSize, m_pTextCache + dwLoadOffset, rLineInfo.m_dwLength);
				int nLineWidth = LOWORD(GetTabbedTextExtent(hdc, m_pTextCache + dwLoadOffset, rLineInfo.m_dwLength, 0, NULL));
				if (nMaxLineWidth < nLineWidth)
					nMaxLineWidth = nLineWidth;

				rLineInfo.m_dwTextStart = dwLoadOffset;
				dwLoadOffset += rLineInfo.m_dwLength;
				dwLineBufferPos += dwLineSize;
				++dwLineNum;
			}
		}
	}

	m_dwFirstCachedLine = dwFirstCachedLine;
	m_dwNumCachedLines = dwNumCachedLines;
	nMaxLineWidth += nExtraWidth;
	if (m_nMaxLineWidth < nMaxLineWidth)
	{
		m_nMaxLineWidth = nMaxLineWidth;
		SCROLLINFO sinfo;
		ZeroMemory(&sinfo, sizeof(sinfo));
		sinfo.cbSize = sizeof(sinfo);
		sinfo.fMask = SIF_RANGE;
		sinfo.nMin = 0;
		sinfo.nMax = nMaxLineWidth - 1;
		SetScrollInfo(m_hwnd, SB_HORZ, &sinfo, TRUE);
	}
	if (hOldFont)
		SelectFont(hdc, hOldFont);
	ReleaseDC(m_hwnd, hdc);
}
Example #15
0
void CTextView::LoadCache(void)
{
	_ASSERTE(m_hFile != INVALID_HANDLE_VALUE);
	m_dwFirstCachedLine = m_dwNumCachedLines = 0;
	m_nMaxLineWidth = 0;
	DWORD dwNumLines = m_arrLines.GetCount();
	if (dwNumLines > 0)
	{
		HDC hdc = GetDC(m_hwnd);
		HFONT hOldFont = g_pResManager->m_hFixedFont ? SelectFont(hdc, g_pResManager->m_hFixedFont) : NULL;
		TEXTMETRIC tmetr;
		::GetTextMetrics(hdc, &tmetr);
		int nExtraWidth = tmetr.tmAveCharWidth + LOWORD(GetTabbedTextExtent(hdc, g_szEllipsis, g_dwEllipsisLength, 0, NULL));

		if (m_pTextCache == NULL)
		{
			_ASSERTE(MAX_NUMBER_OF_SYMBOLS <= TEXT_CACHE_SIZE);
			m_pTextCache = new TCHAR[TEXT_CACHE_SIZE];
			if (m_pTextCache == NULL)
			{
				ResetFile();
				goto end;
			}
		}
		const CLineInfo& rLineInfo = m_arrLines[0];
		SetFilePointer(m_hFile, rLineInfo.m_dwLineStart, NULL, FILE_BEGIN);
		DWORD dwLineBufferPos = 0, dwTextCachePos = 0;
		for (;;)
		{
			DWORD dwNumRead = 0;
			if (! ReadFile(m_hFile, m_pLineBuffer + dwLineBufferPos, m_dwLineBufferSize - dwLineBufferPos, &dwNumRead, NULL))
				goto end;
			dwNumRead += dwLineBufferPos;
			dwLineBufferPos = 0;
			if (dwNumRead == 0)
				break;
			for (;;)
			{
				DWORD dwBytesLeft = dwNumRead - dwLineBufferPos;
				if (dwBytesLeft == 0)
				{
					dwLineBufferPos = 0;
					break;
				}
				CLineInfo& rLineInfo = m_arrLines[(int)m_dwNumCachedLines];
				if (dwTextCachePos + rLineInfo.m_dwLength > TEXT_CACHE_SIZE)
					goto end;
				DWORD dwLineSize;
				if (m_dwNumCachedLines + 1 < dwNumLines)
				{
					const CLineInfo& rNextLineInfo = m_arrLines[(int)(m_dwNumCachedLines + 1)];
					dwLineSize = rNextLineInfo.m_dwLineStart - rLineInfo.m_dwLineStart; // line size includes line end
				}
				else
					dwLineSize = rLineInfo.m_dwSize;
				if (dwLineSize > dwBytesLeft)
				{
					MoveMemory(m_pLineBuffer, m_pLineBuffer + dwLineBufferPos, dwBytesLeft);
					dwLineBufferPos = dwBytesLeft;
					break;
				}
				m_pDecoder->DecodeString(m_pLineBuffer + dwLineBufferPos, rLineInfo.m_dwSize, m_pTextCache + dwTextCachePos, rLineInfo.m_dwLength);
				int nLineWidth = LOWORD(GetTabbedTextExtent(hdc, m_pTextCache + dwTextCachePos, rLineInfo.m_dwLength, 0, NULL));
				if (m_nMaxLineWidth < nLineWidth)
					m_nMaxLineWidth = nLineWidth;

				rLineInfo.m_dwTextStart = dwTextCachePos;
				dwTextCachePos += rLineInfo.m_dwLength;
				dwLineBufferPos += dwLineSize;
				++m_dwNumCachedLines;
			}
		}
end:
		m_nMaxLineWidth += nExtraWidth;
		ResizeTextView(TRUE);
		if (hOldFont)
			SelectFont(hdc, hOldFont);
		ReleaseDC(m_hwnd, hdc);
	}
}
Example #16
0
/**
 * @param hdc - drawing context.
 * @param prcPaint - the rectangle in which the painting is requested.
 */
void CTextView::DrawTextView(HDC hdc, RECT* prcPaint)
{
	_ASSERTE(g_pResManager != NULL);
	if (prcPaint == NULL)
	{
		RECT rcClient;
		GetClientRect(m_hwnd, &rcClient);
		prcPaint = &rcClient;
	}
	if (IsRectEmpty(prcPaint))
		return;

#ifdef USE_MEM_DC
	int nClientWidth = prcPaint->right - prcPaint->left;
	int nClientHeight = prcPaint->bottom - prcPaint->top;
	HBITMAP hbmpMem;
	hbmpMem = CreateCompatibleBitmap(hdc, nClientWidth, nClientHeight);
	if (hbmpMem == NULL)
		return;
	HDC hdcMem;
	hdcMem = CreateCompatibleDC(hdc);
	if (hdcMem == NULL)
	{
		DeleteBitmap(hbmpMem);
		return;
	}
	SetViewportOrgEx(hdcMem, -prcPaint->left, -prcPaint->top, NULL);
	HBITMAP hbmpSafe = SelectBitmap(hdcMem, hbmpMem);
#else
	// CS_PARENTDC sets the clipping rectangle of the child window to that of the parent window
	// so that the child can draw on the parent. Text view inherits this style from sub-classed
	// static control. This causes problems with unclipped TabbedTextOut() output.
	HRGN hrgn = CreateRectRgnIndirect(prcPaint);
	SelectClipRgn(hdc, hrgn);
	DeleteRgn(hrgn);
	HDC hdcMem = hdc;
#endif

	FillRect(hdcMem, prcPaint, g_pResManager->m_hbrWindowBrush);

	COLORREF rgbOldTextColor = SetTextColor(hdcMem, GetSysColor(COLOR_WINDOWTEXT));
	COLORREF rgbOldBackground = SetBkColor(hdcMem, GetSysColor(COLOR_WINDOW));
	HFONT hOldFont = g_pResManager->m_hFixedFont ? SelectFont(hdcMem, g_pResManager->m_hFixedFont) : NULL;
	TEXTMETRIC tmetr;
	::GetTextMetrics(hdcMem, &tmetr);

	DWORD dwNumLines = m_arrLines.GetCount();
	DWORD dwTopLineNum = GetScrollPos(m_hwnd, SB_VERT);
	DWORD dwTopVisLineNum = dwTopLineNum + prcPaint->top / tmetr.tmHeight;

	if (dwTopVisLineNum < dwNumLines)
	{
		int nHorPos = tmetr.tmAveCharWidth - GetScrollPos(m_hwnd, SB_HORZ);
		int nVertPos = prcPaint->top - prcPaint->top % tmetr.tmHeight;
		DWORD dwNumVisLines = prcPaint->bottom / tmetr.tmHeight;
		if (prcPaint->bottom % tmetr.tmHeight)
			++dwNumVisLines;
		DWORD dwBottomVisLineNum = dwTopLineNum + dwNumVisLines - 1;
		if (dwBottomVisLineNum >= dwNumLines)
			dwBottomVisLineNum = dwNumLines - 1;

		for (DWORD dwLineNum = dwTopVisLineNum; dwLineNum <= dwBottomVisLineNum; ++dwLineNum)
		{
			CacheLine(dwLineNum);
			const CLineInfo& rLineInfo = m_arrLines[(int)dwLineNum];
			int nTextWidth = LOWORD(TabbedTextOut(hdcMem, nHorPos, nVertPos, m_pTextCache + rLineInfo.m_dwTextStart, rLineInfo.m_dwLength, 0, NULL, -nHorPos));
			if (rLineInfo.m_bTruncated)
				TextOut(hdcMem, nHorPos + nTextWidth, nVertPos, g_szEllipsis, g_dwEllipsisLength);
			nVertPos += tmetr.tmHeight;
		}
	}

	SetTextColor(hdcMem, rgbOldTextColor);
	SetBkColor(hdcMem, rgbOldBackground);
	if (hOldFont)
		SelectFont(hdcMem, hOldFont);

#ifdef USE_MEM_DC
	BitBlt(hdc, prcPaint->left, prcPaint->top, nClientWidth, nClientHeight, hdcMem, prcPaint->left, prcPaint->top, SRCCOPY);
	SelectBitmap(hdcMem, hbmpSafe);
	DeleteDC(hdcMem);
	DeleteBitmap(hbmpMem);
#endif
}
Example #17
0
BOOL CImportDlg::OnDrawRecord( HDC hdc, CUSTOM_LIST_DRAWITEM* di )
{

	DrawVGradient(hdc, di->rcItem, RGB(240, 240, 240), RGB(216, 216, 216), 255);

	LPCWSTR flds[] = 
	{
		L"phone1",
		L"phone2",
		L"email",
		L"emailadd",
		L"url",
		L"nickname",
		NULL
	};

	SetBkMode(hdc, TRANSPARENT);
	HFONT oldFnt = SelectFont(hdc, m_fntBold);

	if(m_actions[di->itemID])
	{
		SetTextColor(hdc, RGB(0, 0, 0));
	} else
	{
		SetTextColor(hdc, RGB(150, 150, 150));
	}

	int imgX = di->rcItem.left + 4;
	int imgY = di->rcItem.top  + 4;

/*
	CTxDIB* img = m_records[di->itemID]->GetPhoto(50, 50);
	if(img)
	{
		img->draw(hdc, imgX, imgY);
	} else
*/
	{
		m_engine->DrawImage(hdc, imgX, imgY, 50, 50, L"photomin.png");
	}

	int txtLeft = imgX + 50 + 4;
	int txtTop  = di->rcItem.top + 4;

	oldFnt = SelectFont(hdc, m_fntBold);

	RECT rcText;
	rcText.left		= di->rcItem.left + 58;
	rcText.right	= di->rcItem.right - m_linksWidth;
	rcText.top		= di->rcItem.top + 4;
	rcText.bottom	= rcText.top + m_captionHeight;

	std::wstring val = m_records[di->itemID]->GetFieldValue(L"displayname");
	if(!val.empty())
	{
		SelectFont(hdc, m_fntCaption);
		DrawText(hdc, val.c_str(), -1, &rcText, DT_LEFT | DT_BOTTOM | DT_NOPREFIX);
	}

	SelectFont(hdc, m_fntLinks);

	RECT rcLink = rcText;
	rcLink.left	 = di->rcItem.right - m_linksWidth;
	rcLink.right = di->rcItem.right;
	rcLink.bottom	= rcLink.top + m_linksHeight;

	SetTextColor(hdc, RGB(0, 0, 200));

	switch(m_actions[di->itemID])
	{
	case IMPORT_ACT_IMPORT:
		DrawText(hdc, m_engine->getStringDef(XUI_IMPORT_NEW), -1, &rcLink, DT_LEFT | DT_BOTTOM | DT_NOPREFIX);
		break;
	case IMPORT_ACT_UPDATE:
		DrawText(hdc, m_engine->getStringDef(XUI_IMPORT_UPDATE), -1, &rcLink, DT_LEFT | DT_BOTTOM | DT_NOPREFIX);
		break;
	case IMPORT_ACT_NONE:
		DrawText(hdc, m_engine->getStringDef(XUI_IMPORT_SKIP), -1, &rcLink, DT_LEFT | DT_BOTTOM | DT_NOPREFIX);
		break;
	}

	SelectFont(hdc, m_fntBold);

	if(m_actions[di->itemID])
	{
		SetTextColor(hdc, RGB(0, 0, 0));
	} else
	{
		SetTextColor(hdc, RGB(150, 150, 150));
	}

	rcText.top		= rcText.bottom;
	rcText.bottom += m_textHeight;
	rcText.right	= di->rcItem.right;

	for(int i = 0; flds[i]; i++)
	{
		val = m_records[di->itemID]->GetFieldValue(flds[i]);

		if(!val.empty())
		{
			std::wstring strLabel;
			if(i < 2)
			{
				if(!m_records[di->itemID]->GetFieldType(flds[i]).empty())
				{
					strLabel = m_records[di->itemID]->GetFieldLabel(m_records[di->itemID]->GetFieldType(flds[i]).c_str(), m_engine);
				} else
				{
					strLabel = m_records[di->itemID]->GetFieldLabel(flds[i], m_engine);
				}
			} else
			{
				strLabel = m_records[di->itemID]->GetFieldLabel(flds[i], m_engine);
			}
			strLabel += L":";

			rcText.left		= di->rcItem.left + 58;
			rcText.right	= rcText.left + m_labelsWidth;

			SelectFont(hdc, m_fntNormal);
			DrawText(hdc, strLabel.c_str(), -1, &rcText, DT_LEFT | DT_BOTTOM | DT_NOPREFIX);

			rcText.left		= rcText.right;
			rcText.right	= di->rcItem.right;

			SelectFont(hdc, m_fntBold);
			if(!val.empty())
			{
				DrawText(hdc, val.c_str(), -1, &rcText, DT_LEFT | DT_BOTTOM | DT_NOPREFIX);
			}

			rcText.top		= rcText.bottom;
			rcText.bottom += m_textHeight;
		}
		if(rcText.bottom > di->rcItem.bottom) break;
	}

	SelectFont(hdc, oldFnt);

	return TRUE;
}
Example #18
0
LRESULT threaded_process_v2_t::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{
	switch (msg)
	{
		case WM_TIMER:
			if (wp == 1)
			{
				ShowWindow(wnd, SW_SHOWNORMAL);
				KillTimer(wnd, 1);
				return 0;
			}
			else if (wp == 667)
			{
				KillTimer(wnd, 667);
				m_timer_active = false;
				RedrawWindow(wnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
				return 0;
			}
			break;
		case WM_NCCREATE:
			modeless_dialog_manager::g_add(wnd);
			break;
		case WM_SYSCOLORCHANGE:
		case WM_THEMECHANGED:
			refresh_title_font();
			resize();
			break;
		case WM_CREATE:
		{
			if (m_flags & flag_show_button)
			{
				m_textfont = uCreateIconFont();
				m_textfont_height = uGetFontHeight(m_titlefont);
			}
			if (m_flags & flag_show_text)
				refresh_title_font();

			uSetWindowText(wnd, m_title);
			//t_size y_progress = 11;
			//if (m_flags & flag_show_text)
			//	y_progress+=5+uGetFontHeight(m_titlefont);
			//RECT rc;
			//GetClientRect(wnd, &rc);
			//m_wnd_caption = CreateWindowEx(0, WC_STATIC, L"STATIC", WS_CHILD|WS_VISIBLE, 0, 0, 0, 0, wnd, (HMENU)1001, core_api::get_my_instance(), NULL);
			m_wnd_progress = CreateWindowEx(0, PROGRESS_CLASS, L"PROGRESS", WS_SYSMENU | WS_CHILD | WS_VISIBLE | ((m_flags & flag_progress_marquee) ? 0x08 : 0) | PBS_SMOOTH | WS_GROUP, 0, 0, 0, 0, wnd, (HMENU)1002, core_api::get_my_instance(), NULL);
			if (0 == (m_flags & flag_progress_marquee))
				SendMessage(m_wnd_progress, PBM_SETRANGE32, 0, progress_width/*m_range*/);
			else
				SendMessage(m_wnd_progress, WM_USER + 10, TRUE, 20);
			if (m_flags & flag_show_button)
			{
				m_wnd_button = CreateWindowEx(0, WC_BUTTON, L"Stop", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON | WS_GROUP, 0, 0, 0, 0, wnd, (HMENU)IDCANCEL, core_api::get_my_instance(), NULL);
				SendMessage(m_wnd_button, WM_SETFONT, (WPARAM)m_textfont.get(), MAKELPARAM(1, 0));
				//SetFocus(m_wnd_button);
			}
			else
			{
				HMENU menu = GetSystemMenu(wnd, FALSE);
				EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
			}
			resize();
			if (m_flags & flag_no_delay)
			{
				ShowWindow(wnd, SW_SHOWNORMAL);
			}
			else
			{
				SetTimer(wnd, 1, 300, NULL);
			}
			on_init();
		}
		return 0;
		case WM_SHOWWINDOW:
			if (wp == TRUE && lp == 0 && m_wnd_button)
				SetFocus(m_wnd_button);
			break;
		case WM_MOVING:
		{
			LPRECT lprc = (LPRECT)lp;
			lprc->right = lprc->left + m_window_cx;
			lprc->bottom = lprc->top + m_window_cy;
		}
		return TRUE;
		case DM_GETDEFID:
			if (m_flags & flag_show_button)
				return IDCANCEL | (DC_HASDEFID << 16);
			return 0;
		case WM_DESTROY:
			on_destroy_thread();
			m_textfont.release();
			m_titlefont.release();
			return 0;
		case WM_NCDESTROY:
			modeless_dialog_manager::g_remove(wnd);
			break;
		case WM_CLOSE:
			m_abort.abort();
			return 0;
		case WM_SETFOCUS:
			break;
		case WM_COMMAND:
			switch (wp)
			{
				case IDCANCEL:
					if (m_wnd_button)
						EnableWindow(m_wnd_button, FALSE);
					m_abort.abort();
					return 0;
			}
			break;
		case WM_PAINT:
		{
			pfc::string8 p_text;
			pfc::array_t<detail_entry> p_detail_entries;
			{
				insync(m_sync);
				p_text = m_text;
				p_detail_entries = m_detail_entries;
			}
			PAINTSTRUCT ps;
			HDC dc = BeginPaint(wnd, &ps);
			if (dc)
			{
				RECT rc_client, rc_button;
				GetClientRect(wnd, &rc_client);
				RECT rc_fill = rc_client;
				if (m_wnd_button)
				{
					GetWindowRect(m_wnd_button, &rc_button);
					rc_fill.bottom -= RECT_CY(rc_button) + 9;
					rc_fill.bottom -= 11;
				}

				FillRect(dc, &rc_fill, GetSysColorBrush(COLOR_WINDOW));

				if (m_wnd_button)
				{
					rc_fill.top = rc_fill.bottom;
					rc_fill.bottom += 1;
					FillRect(dc, &rc_fill, GetSysColorBrush(COLOR_3DLIGHT));
				}

				rc_fill.top = rc_fill.bottom;
				rc_fill.bottom = rc_client.bottom;
				if (rc_fill.top < rc_fill.bottom)
					FillRect(dc, &rc_fill, GetSysColorBrush(COLOR_3DFACE));

				if (m_flags & flag_show_text)
				{
					SetTextAlign(dc, TA_LEFT);
					SetBkMode(dc, TRANSPARENT);
					//SetTextColor(dc, m_titlecolour);
					RECT rc;
					GetClientRect(wnd, &rc);
					RECT rc2 = { 11 * 2, 11, RECT_CX(rc) - 11 * 2, m_titlefont_height + 11 };
					//FillRect(dc, &rc2, GetSysColorBrush(COLOR_BTNFACE));
					HFONT fnt_old = SelectFont(dc, m_titlefont);
					ui_helpers::text_out_colours_ellipsis(dc, p_text, p_text.get_length(), 0, 11, &rc2, false, false, m_titlecolour, ui_helpers::ALIGN_LEFT);
					//uExtTextOut(dc, 11*2, 11, ETO_CLIPPED, &rc2, m_text, m_text.get_length(), NULL);
					t_size detail_entry_count = 0;
					if (detail_entry_count = p_detail_entries.get_count())
					{
						RECT rc3 = rc2;
						rc3.top = rc2.bottom + 7;
						rc3.bottom = rc3.top + m_textfont_height;
						//SetTextColor(dc, GetSysColor(COLOR_BTNTEXT));
						SelectFont(dc, m_textfont);
						unsigned max_x = 0;
						for (t_size i = 0; i<detail_entry_count; i++)
						{
							unsigned last_x = 0;
							ui_helpers::text_out_colours_ellipsis(dc, p_detail_entries[i].m_label, p_detail_entries[i].m_label.get_length(), 0, rc3.top,
								&rc3, false, false, GetSysColor(COLOR_WINDOWTEXT), ui_helpers::ALIGN_LEFT, NULL, true, &last_x);
							max_x = max(last_x, max_x);
							rc3.top = rc3.bottom;
							rc3.bottom = rc3.top + m_textfont_height;
							//uExtTextOut(dc, 11*2, rc3.top, ETO_CLIPPED, &rc3, m_detail_entries[i].m_label, m_detail_entries[i].m_label.get_length(), NULL);
						}
						rc3.top = rc2.bottom + 7;
						rc3.bottom = rc3.top + m_textfont_height;
						rc3.left = max_x + 5;
						for (t_size i = 0; i<detail_entry_count; i++)
						{
							ui_helpers::text_out_colours_ellipsis(dc, p_detail_entries[i].m_value, p_detail_entries[i].m_value.get_length(), 0, rc3.top,
								&rc3, false, true, GetSysColor(COLOR_WINDOWTEXT), ui_helpers::ALIGN_LEFT);
							rc3.top = rc3.bottom;
							rc3.bottom = rc3.top + m_textfont_height;
						}
					}
					SelectFont(dc, fnt_old);
				}
				EndPaint(wnd, &ps);
			}
		}
		return 0;
		case MSG_REDRAW:
			resize();
			if (!m_timer_active)
			{
				LARGE_INTEGER current = { 0 }, freq = { 0 };
				QueryPerformanceCounter(&current);
				QueryPerformanceFrequency(&freq);
				t_uint64 tenth = 5;
				if (m_time_last_redraw.QuadPart)
				{
					tenth = (current.QuadPart - m_time_last_redraw.QuadPart) / (freq.QuadPart / 100);
				}
				if (tenth < 10)
				{
					SetTimer(get_wnd(), 667, 100 - t_uint32(tenth) * 10, NULL);
					m_timer_active = true;
				}
				else RedrawWindow(wnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
			}
			return 0;
		case MSG_UPDATE_PROGRESS:
			if (abs((int)(wp - SendMessage(m_wnd_progress, PBM_GETPOS, 0, 0))) > 0)
				SendMessage(m_wnd_progress, PBM_SETPOS, wp, 0);
			return 0;
		case MSG_END:
			destroy();
			on_exit();
			return 0;
	}
	return DefWindowProc(wnd, msg, wp, lp);
}
void DrawLayers(HDC hdc, int x, int y, int width, int height, int type)
{
	double maxHeight = CSnow::current()->getSnowHeight();
	double temperatureRange = 40;//max(abs(bottomTemperature - topTemperature), abs(topTemperature));
	if(temperatureRange == 0)temperatureRange = 1;

	if (maxHeight == 0)
		return;

	HBRUSH brush;
	int h;
	int topT, bottomT;
	int rightMargin = 40;
	RECT rect;
	CLayer *layer;

	
	HPEN pen = CreatePen(0, 1, 0);
	//HPEN boldPen = CreatePen(0, 3, 0);
	HPEN oldPen = (HPEN)SelectObject(hdc, pen);
	HPEN dotPen = CreatePen(PS_DASH, 1, RGB(0,0,0));

	LOGFONT lFont;
	ZeroMemory(&lFont, sizeof(lFont));
	lFont.lfHeight = 16;
	lFont.lfWeight = FW_BOLD;
	wcscpy_s(lFont.lfFaceName, WINDOW_FONT);
	HFONT font = CreateFontIndirect(&lFont);
	HFONT oldFont = SelectFont(hdc, font);
		
	SetBkMode(hdc, TRANSPARENT);

	int dy = 0;
	for (int l = 0; l < CSnow::current()->getLayersNum(); l++) {
		layer = CSnow::current()->getLayer(l);
		//if (type)h = height*CSnow::current()->getLayer(l)->GetHeight(t)/maxHeight;
		//else h = height*CSnow::current()->getLayer(l)->GetDensity(t)/maxHeight;
		h = (int)(height*layer->GetHeight()/maxHeight);

		if (h == 0)
			continue;

		//draw layer
		brush = CreateSolidBrush((type) ? layer->GetParticleColor() : layer->GetDensityColor());
		rect.left = x; rect.right = x + width - rightMargin;
		rect.top = y + height - dy - (int)h; rect.bottom = y + height - dy;
		FillRect(hdc, &rect, brush);
		DeleteObject(brush);

		//draw layer temperature
		topT = (int)((width - rightMargin)*layer->GetTopTemperature()/temperatureRange);
		bottomT = (int)((width - rightMargin)*layer->GetBottomTemperature()/temperatureRange);
		SelectObject(hdc, dotPen);
		SetBkMode(hdc, OPAQUE);
		MoveToEx(hdc, x + width - rightMargin + topT - 1, rect.top, NULL);
		LineTo(hdc, x + width - rightMargin + bottomT - 1, rect.bottom);
		SetBkMode(hdc, TRANSPARENT);
		SelectObject(hdc, pen);

		if(layer->GetSelection()) {
			HPEN boldPen = CreatePen(0, 3, ((type) ? layer->GetParticleSelectionColor() : 0));
			SelectObject(hdc, boldPen);
			MoveToEx(hdc, rect.left + 1, rect.top + 1, NULL);
			LineTo(hdc, rect.left + 1, rect.bottom - 1);
			LineTo(hdc, rect.right - 2, rect.bottom - 1);
			LineTo(hdc, rect.right - 2, rect.top + 1);
			LineTo(hdc, rect.left + 1, rect.top + 1);
			SelectObject(hdc, pen);
			DeleteObject(boldPen);
		}
		
		MoveToEx(hdc, x + width - rightMargin + 10, rect.top, NULL);
		LineTo(hdc, x + width - rightMargin + 10, rect.bottom);
		
		TEXTMETRIC tMetric;
		GetTextMetrics(hdc, &tMetric);
		if (h > tMetric.tmHeight/2) {
			SetTextAlign(hdc, TA_LEFT);
			SetTextColor(hdc, 0x0);
			TextOut(hdc, x + width - rightMargin + 14, (rect.bottom + rect.top)/2 - tMetric.tmHeight/2, layer->ToString(CLayer::HEIGHT, 4).c_str(), layer->ToString(CLayer::HEIGHT, 4).size());
			SetTextAlign(hdc, TA_CENTER);
			SetTextColor(hdc, 0xffffff);
			TextOut(hdc, (x + width - rightMargin)/2, (rect.bottom + rect.top)/2 - tMetric.tmHeight/2, layer->ToString((type) ? CLayer::PARTICLE : CLayer::DENSITY, 4).c_str(), layer->ToString((type) ? CLayer::PARTICLE : CLayer::DENSITY, 4).size());
		}
		
		dy += h;
		MoveToEx(hdc, x, y + height - dy, NULL);
		LineTo(hdc, x + width - rightMargin + 16, y + height - dy);

		//draw grid
		MoveToEx(hdc, x, y + height - dy + 3, NULL);
		LineTo(hdc, x, y + height - dy - 3);
		MoveToEx(hdc, x + (width - rightMargin)/4, y + height - dy + 3, NULL);
		LineTo(hdc, x + (width - rightMargin)/4, y + height - dy - 3);
		MoveToEx(hdc, x + (width - rightMargin)/2, y + height - dy + 3, NULL);
		LineTo(hdc, x + (width - rightMargin)/2, y + height - dy - 3);
		MoveToEx(hdc, x + (width - rightMargin)/4*3, y + height - dy +3, NULL);
		LineTo(hdc, x + (width - rightMargin)/4*3, y + height - dy - 3);
		MoveToEx(hdc, x + (width - rightMargin) - 1, y + height - dy + 3, NULL);
		LineTo(hdc, x + (width - rightMargin) - 1, y + height - dy - 3);
	}
	
	SelectObject(hdc, oldPen);
	SelectFont(hdc, &oldFont);
	DeleteObject(pen);
	DeleteObject(dotPen);
	DeleteFont(font);
}
Example #20
0
INT_PTR COptionDialog::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	static const int ICON_WIDTH=16,ICON_HEIGHT=16,LIST_MARGIN=1,ICON_TEXT_MARGIN=4;

	switch (uMsg) {
	case WM_INITDIALOG:
		{
			int i;

			COptions::ClearGeneralUpdateFlags();
			for (i=0;i<NUM_PAGES;i++) {
				m_PageList[i].pOptions->ClearUpdateFlags();
				DlgListBox_AddString(hDlg,IDC_OPTIONS_LIST,i);
			}
			if (m_StartPage>=0 && m_StartPage<NUM_PAGES)
				m_CurrentPage=m_StartPage;
			CreatePage(m_CurrentPage);
			m_PageList[m_CurrentPage].pOptions->SetVisible(true);
			DlgListBox_SetCurSel(hDlg,IDC_OPTIONS_LIST,m_CurrentPage);

			//m_Icons.Load(GetAppClass().GetResourceInstance(),IDB_OPTIONS);
			m_himlIcons=::ImageList_LoadImage(GetAppClass().GetResourceInstance(),
											  MAKEINTRESOURCE(IDB_OPTIONS),
											  16,1,0,IMAGE_BITMAP,LR_CREATEDIBSECTION);

			HFONT hfont=reinterpret_cast<HFONT>(::SendMessage(hDlg,WM_GETFONT,0,0));
			LOGFONT lf;
			::GetObject(hfont,sizeof(LOGFONT),&lf);
			lf.lfWeight=FW_BOLD;
			m_TitleFont.Create(&lf);

			m_fApplied=false;
		}
		return TRUE;

	/*
	case WM_MEASUREITEM:
		if (wParam==IDC_OPTIONS_LIST) {
			MEASUREITEMSTRUCT *pmis=reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);

			//pmis->itemHeight=ICON_HEIGHT+LIST_MARGIN*2;
			pmis->itemHeight=ICON_HEIGHT;
			return TRUE;
		}
	*/

	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT pdis=reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);

			if (wParam==IDC_OPTIONS_LIST) {
				const bool fSelected=(pdis->itemState&ODS_SELECTED)!=0;
				COLORREF crText,crOldText;
				int OldBkMode;
				RECT rc;

				if (fSelected) {
					rc=pdis->rcItem;
					rc.right=rc.left+LIST_MARGIN+ICON_WIDTH+ICON_TEXT_MARGIN/2;
					::FillRect(pdis->hDC,&rc,reinterpret_cast<HBRUSH>(COLOR_WINDOW+1));
					rc.left=rc.right;
					rc.right=pdis->rcItem.right;
					DrawUtil::FillGradient(pdis->hDC,&rc,
										   RGB(0,0,0),GetTitleColor((int)pdis->itemData));
					crText=RGB(255,255,255);
				} else {
					::FillRect(pdis->hDC,&pdis->rcItem,
							   reinterpret_cast<HBRUSH>(COLOR_WINDOW+1));
					crText=::GetSysColor(COLOR_WINDOWTEXT);
				}
				rc=pdis->rcItem;
				rc.left+=LIST_MARGIN;
				/*
				HDC hdcMem=::CreateCompatibleDC(pdis->hDC);
				if (hdcMem!=NULL) {
					HBITMAP hbmOld=static_cast<HBITMAP>(::SelectObject(hdcMem,m_Icons.GetHandle()));
					::GdiTransparentBlt(pdis->hDC,rc.left,rc.top,ICON_WIDTH,ICON_HEIGHT,
										hdcMem,(int)pdis->itemData*ICON_WIDTH,0,ICON_WIDTH,ICON_HEIGHT,RGB(255,255,255));
					::SelectObject(hdcMem,hbmOld);
					::DeleteDC(hdcMem);
				}
				*/
				::ImageList_Draw(m_himlIcons,(int)pdis->itemData,pdis->hDC,rc.left,rc.top,ILD_TRANSPARENT);
				if (fSelected)
					::ImageList_Draw(m_himlIcons,(int)pdis->itemData,pdis->hDC,rc.left,rc.top,ILD_TRANSPARENT);
				crOldText=::SetTextColor(pdis->hDC,crText);
				OldBkMode=::SetBkMode(pdis->hDC,TRANSPARENT);
				rc.left+=ICON_WIDTH+ICON_TEXT_MARGIN;
				::DrawText(pdis->hDC,m_PageList[pdis->itemData].pszTitle,-1,
						   &rc,DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
				::SetTextColor(pdis->hDC,crOldText);
				::SetBkMode(pdis->hDC,OldBkMode);
				if ((pdis->itemState & (ODS_FOCUS | ODS_NOFOCUSRECT))==ODS_FOCUS) {
					rc=pdis->rcItem;
					rc.left+=LIST_MARGIN+ICON_WIDTH+ICON_TEXT_MARGIN/2;
					::DrawFocusRect(pdis->hDC,&rc);
				}
			} else if (wParam==IDC_OPTIONS_TITLE) {
				HFONT hfontOld;
				COLORREF crOldText;
				int OldBkMode;
				RECT rc;

				DrawUtil::FillGradient(pdis->hDC,&pdis->rcItem,
									   RGB(0,0,0),GetTitleColor(m_CurrentPage));
				hfontOld=SelectFont(pdis->hDC,m_TitleFont.GetHandle());
				crOldText=::SetTextColor(pdis->hDC,RGB(255,255,255));
				OldBkMode=::SetBkMode(pdis->hDC,TRANSPARENT);
				rc.left=pdis->rcItem.left+2;
				rc.top=pdis->rcItem.top;
				rc.right=pdis->rcItem.right-2;
				rc.bottom=pdis->rcItem.bottom;
				::DrawText(pdis->hDC,m_PageList[m_CurrentPage].pszTitle,-1,
						   &rc,DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
				SelectFont(pdis->hDC,hfontOld);
				::SetTextColor(pdis->hDC,crOldText);
				::SetBkMode(pdis->hDC,OldBkMode);
			}
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_OPTIONS_LIST:
			if (HIWORD(wParam)==LBN_SELCHANGE) {
				int NewPage=(int)DlgListBox_GetCurSel(hDlg,IDC_OPTIONS_LIST);

				if (NewPage>=0)
					SetPage(NewPage);
			}
			return TRUE;

		case IDC_OPTIONS_HELP:
			GetAppClass().UICore.ShowHelpContent(m_PageList[m_CurrentPage].HelpID);
			return TRUE;

		case IDOK:
		case IDCANCEL:
			{
				HCURSOR hcurOld;
				NMHDR nmh;
				int i;

				hcurOld=::SetCursor(::LoadCursor(NULL,IDC_WAIT));
				nmh.code=LOWORD(wParam)==IDOK?PSN_APPLY:PSN_RESET;
				m_fSettingError=false;
				for (i=0;i<NUM_PAGES;i++) {
					if (m_PageList[i].pOptions->IsCreated()) {
						m_PageList[i].pOptions->SendMessage(WM_NOTIFY,0,reinterpret_cast<LPARAM>(&nmh));
						if (m_fSettingError) {
							::SetCursor(hcurOld);
							return TRUE;
						}
						if (LOWORD(wParam)==IDOK)
							m_fApplied=true;
					}
				}
				::SetCursor(hcurOld);
				::EndDialog(hDlg,m_fApplied?IDOK:IDCANCEL);
			}
			return TRUE;
		}
		return TRUE;

	case WM_DESTROY:
		//m_Icons.Destroy();
		if (m_himlIcons!=NULL) {
			::ImageList_Destroy(m_himlIcons);
			m_himlIcons=NULL;
		}
		m_TitleFont.Destroy();
		return TRUE;
	}

	return FALSE;
}
Example #21
0
void CImportDlg::calcItemHeight()
{
	HFONT fnt = GetStockFont(DEFAULT_GUI_FONT);
	LOGFONT lf;
	GetObject(fnt, sizeof(LOGFONT), &lf);

	lf.lfQuality = CLEARTYPE_QUALITY;

	lstrcpy(lf.lfFaceName, L"Verdana");

	m_fntNormal		= CreateFontIndirect(&lf);
	lf.lfUnderline	= TRUE;
	m_fntLinks		= CreateFontIndirect(&lf);
	lf.lfUnderline	= FALSE;
	lf.lfWeight		= FW_BOLD;
	m_fntBold		= CreateFontIndirect(&lf);
	lf.lfHeight		= (int) ((double) lf.lfHeight * 3.0 / 2.0);
	m_fntCaption	= CreateFontIndirect(&lf);

	HDC hdc = GetDC(m_hWnd);
	SIZE sz;

	HFONT oldFnt = SelectFont(hdc, m_fntCaption);
	GetTextExtentPoint32(hdc, L"QIqpti", 6, &sz);
	m_captionHeight = sz.cy + 4;

	SelectFont(hdc, m_fntBold);
	GetTextExtentPoint32(hdc, L"QIqpti", 6, &sz);
	m_textHeight = sz.cy + 4;

	SelectFont(hdc, m_fntNormal);

	struct
	{
		LPWSTR strID;
		LPWSTR attr;
		LPWSTR defText;
	} flds[] = 
	{
		{ XUI_FLD_PHONEWORK		},
		{ XUI_FLD_PHONEHOME		},
		{ XUI_FLD_PHONEFAX		},
		{ XUI_FLD_PHONEMOBILE	},
		{ XUI_FLD_PHONEPAGER	},
		{ XUI_FLD_PHONE			},
		{ XUI_FLD_EMAIL			},
		{ XUI_FLD_EMAILADD		},
		{ XUI_FLD_NICKNAME		},
		{ XUI_FLD_URL			},
		{ NULL, NULL, NULL		}
	};

	m_labelsWidth = 0;

	for(int i=0; flds[i].strID; i++)
	{
		SIZE sz;
		GetTextExtentPoint32(hdc, m_engine->getStringDef(flds[i].strID, NULL, flds[i].defText), lstrlen(m_engine->getStringDef(flds[i].strID, NULL, flds[i].defText)), &sz);
		if(sz.cx > m_labelsWidth)
		{
			m_labelsWidth = sz.cx;
		}
	}
	m_labelsWidth += 10;

	struct
	{
		LPWSTR strID;
		LPWSTR attr;
		LPWSTR defText;
	} links[] = 
	{
		{ XUI_IMPORT_SKIP		},
		{ XUI_IMPORT_NEW		},
		{ XUI_IMPORT_UPDATE		},
		{ NULL, NULL, NULL		}
	};

	m_linksWidth	= 0;
	m_linksHeight	= 0;

	for(int i=0; links[i].strID; i++)
	{
		SIZE sz;
		GetTextExtentPoint32(hdc, m_engine->getStringDef(links[i].strID, NULL, links[i].defText), lstrlen(m_engine->getStringDef(links[i].strID, NULL, links[i].defText)), &sz);
		if(sz.cx > m_linksWidth)
		{
			m_linksWidth = sz.cx;
		}
		if(sz.cy > m_linksHeight)
		{
			m_linksHeight = sz.cy;
		}
	}
	m_linksWidth += 10;


	m_itemHeight = m_textHeight * 3 + m_captionHeight;
	if(m_itemHeight < 50)
	{
		m_itemHeight = 50;
	}

	m_itemHeight += 8;

	SelectFont(hdc, oldFnt);
	ReleaseDC(m_hWnd, hdc);
}
Example #22
0
BOOL OnLegendCreate (HWND hWnd, LPCREATESTRUCT lpCS)
   {
   PLEGEND        pLegend ;
   HDC            hDC ;
   int            iCol ;
   BOOL           bChartLegend ;

   bChartLegend = (lpCS->lpCreateParams) == (LPVOID) TRUE ;

   pLegend = AllocateLegendData (hWnd, bChartLegend) ;

   if (!pLegend)
      return (FALSE) ;

   if (bChartLegend)
      {
      pLegend->iLineType = LineTypeChart ;
      }
   else
      {
      pLegend->iLineType = LineTypeAlert ;
      }

   pLegend->hFontItems = hFontScales ;
   pLegend->hFontLabels = hFontScalesBold ;
   hDC = GetDC (hWnd) ;

   //=============================//
   // Load Labels                 //
   //=============================//

   StringLoad (IDS_LABELCOLOR, pLegend->aCols[LegendColorCol].szLabel) ;
   if (pLegend->iLineType == LineTypeChart)
      StringLoad (IDS_LABELSCALE, 
                  pLegend->aCols[LegendScaleCol].szLabel) ;
   else
      StringLoad (IDS_LABELVALUE,
                  pLegend->aCols[LegendScaleCol].szLabel) ;
   StringLoad (IDS_LABELCOUNTER, pLegend->aCols[LegendCounterCol].szLabel) ;
   StringLoad (IDS_LABELINSTANCE, pLegend->aCols[LegendInstanceCol].szLabel) ;
   StringLoad (IDS_LABELPARENT, pLegend->aCols[LegendParentCol].szLabel) ;
   StringLoad (IDS_LABELOBJECT, pLegend->aCols[LegendObjectCol].szLabel) ;
   StringLoad (IDS_LABELSYSTEM, pLegend->aCols[LegendSystemCol].szLabel) ;


   //=============================//
   // Label dimensions            //
   //=============================//

   SelectFont (hDC, pLegend->hFontLabels) ;
   pLegend->yLabelHeight = FontHeight (hDC, TRUE) + 2 * LabelTopMargin () ;

   //=============================//
   // Column dimensions           //
   //=============================//

   for (iCol = 0 ;
        iCol < iLegendNumCols ;
        iCol++)
      {  // for
      pLegend->aCols[iCol].iOrientation = LEFTORIENTATION ;
      pLegend->aCols[iCol].xMinWidth = 
         TextWidth (hDC, pLegend->aCols[iCol].szLabel) + LegendHorzMargin () ;
      }  // for

   SelectFont (hDC, pLegend->hFontItems) ;
   pLegend->yItemHeight = FontHeight (hDC, TRUE) + 2 * LegendItemTopMargin () ;

   pLegend->aCols[LegendColorCol].xMaxWidth = max (3 * xScrollWidth,
      pLegend->aCols[LegendColorCol].xMinWidth) ;

   pLegend->aCols[LegendScaleCol].xMaxWidth = TextWidth (hDC, eScaleValueSpace) ;
   pLegend->aCols[LegendCounterCol].xMaxWidth = iLegendColMax ;
   pLegend->aCols[LegendInstanceCol].xMaxWidth = iLegendColMax ;
   pLegend->aCols[LegendParentCol].xMaxWidth = iLegendColMax ;
   pLegend->aCols[LegendObjectCol].xMaxWidth = iLegendColMax ;
   pLegend->aCols[LegendSystemCol].xMaxWidth = iLegendColMax ;
   
   pLegend->aCols[LegendColorCol].iOrientation = LEFTORIENTATION ;
   pLegend->aCols[LegendScaleCol].iOrientation = RIGHTORIENTATION ;

   ReleaseDC (hWnd, hDC) ;   

   //=============================//
   // Create Legend Items Listbox //
   //=============================//

   pLegend->hWndItems =
      CreateWindow (TEXT("ListBox"),               // window class
                    NULL,                          // window caption
                    dwGraphLegendItemsWindowStyle, // window style
                    0, 0, 0, 0,                    // window size and pos
                    hWnd,                          // parent window
                    NULL,                          // menu
                    hInstance,                     // program instance
                    (LPVOID) TRUE) ;               // user-supplied data

    return TRUE;
   }  // OnLegendCreate
Example #23
0
void
text_copy_to_clipboard(TW *tw)
{
    int size, count;
    HGLOBAL hGMem;
#ifdef WINDOWS_NO_UNICODE
    LPSTR cbuf, cp;
    HDC hdc;
    TEXTMETRIC tm;
#else
    LPWSTR cbuf, cp;
#endif
    UINT type;
    int i;

    size = tw->ScreenSize.y * (tw->ScreenSize.x + 2) + 1;
    size *= CHARSIZE;
    hGMem = GlobalAlloc(GHND | GMEM_SHARE, (DWORD)size);
#ifdef WINDOWS_NO_UNICODE
    cbuf = cp = (LPSTR)GlobalLock(hGMem);
#else
    cbuf = cp = (LPWSTR)GlobalLock(hGMem);
#endif
    if (cp == NULL)
        return;

    for (i=0; i<tw->ScreenSize.y; i++) {
        count = tw->ScreenSize.x;
        memcpy(cp, tw->ScreenBuffer + tw->ScreenSize.x*i, count*CHARSIZE);
        /* remove trailing spaces */
        for (count=count-1; count>=0; count--) {
                if (cp[count]!=' ')
                        break;
                cp[count] = '\0';
        }
        cp[++count] = '\r';
        cp[++count] = '\n';
        cp[++count] = '\0';
        cp += count;
    }
    /* Now remove completely empty trailing lines */
    while (cp >= cbuf+4) {
        if ((cp[-3] != '\n') || (cp[-4] != '\r'))
            break;
        cp -= 2;
        *cp = '\0';
    }
#ifdef WINDOWS_NO_UNICODE
    size = strlen(cbuf) + 1;
#else
    size = CHARSIZE*(wcslen(cbuf) + 1);
#endif
    GlobalUnlock(hGMem);
    hGMem = GlobalReAlloc(hGMem, (DWORD)size, GHND | GMEM_SHARE);
#ifdef WINDOWS_NO_UNICODE
    /* find out what type to put into clipboard */
    hdc = GetDC(tw->hwnd);
    SelectFont(hdc, tw->hfont);
    GetTextMetrics(hdc,(TEXTMETRIC FAR *)&tm);
    if (tm.tmCharSet == OEM_CHARSET)
        type = CF_OEMTEXT;
    else
        type = CF_TEXT;
    ReleaseDC(tw->hwnd, hdc);
#else
    type = CF_UNICODETEXT;
#endif
    /* give buffer to clipboard */
    OpenClipboard(tw->hwnd);
    EmptyClipboard();
    SetClipboardData(type, hGMem);
    CloseClipboard();
}
Example #24
0
void CDC::Font(HFONT hNewFont)
{
	ASSERT(hNewFont);
	
	SelectFont(m_hDC, hNewFont);
}
Example #25
0
void CDC::Font(int iObjectID)
{
	SelectFont(m_hDC, GetStockFont(iObjectID));
}
LRESULT CALLBACK NotificationWnd::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\
{
    NotificationWnd *wnd = (NotificationWnd *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
    if (WM_ERASEBKGND == message) {
        // do nothing, helps to avoid flicker
        return TRUE;
    }
    if (WM_TIMER == message && TIMEOUT_TIMER_ID == wParam) {
        if (wnd->notificationCb)
            wnd->notificationCb->RemoveNotification(wnd);
        else
            delete wnd;
        return 0;
    }
    if (WM_PAINT == message && wnd) {
        PAINTSTRUCT ps;
        HDC hdcWnd = BeginPaint(hwnd, &ps);

        ClientRect rect(hwnd);
        DoubleBuffer buffer(hwnd, rect);
        HDC hdc = buffer.GetDC();
        HFONT oldfnt = SelectFont(hdc, wnd->font);

        RECT rTmp = rect.ToRECT();
        DrawFrameControl(hdc, &rTmp, DFC_BUTTON, DFCS_BUTTONPUSH);
        if (wnd->highlight) {
            SetBkMode(hdc, OPAQUE);
            SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
            SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
        }
        else {
            SetBkMode(hdc, TRANSPARENT);
            SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
        }

        rect.Inflate(-PADDING, -PADDING);
        RectI rectMsg = rect;
        if (wnd->hasProgress)
            rectMsg.dy -= PROGRESS_HEIGHT + PADDING / 2;
        if (wnd->hasCancel)
            rectMsg.dx -= 20;
        ScopedMem<WCHAR> text(win::GetText(hwnd));
        rTmp = rectMsg.ToRECT();
        DrawText(hdc, text, -1, &rTmp, DT_SINGLELINE | DT_NOPREFIX);

        if (wnd->hasCancel) {
            rTmp = GetCancelRect(hwnd).ToRECT();
            DrawFrameControl(hdc, &rTmp, DFC_CAPTION, DFCS_CAPTIONCLOSE | DFCS_FLAT);
        }

        if (wnd->hasProgress) {
            rect.dx = wnd->progressWidth;
            rect.y += rectMsg.dy + PADDING / 2;
            rect.dy = PROGRESS_HEIGHT;
            PaintRect(hdc, rect);

            rect.x += 2;
            rect.dx = (wnd->progressWidth - 3) * wnd->progress / 100;
            rect.y += 2;
            rect.dy -= 3;

            HBRUSH brush = GetStockBrush(BLACK_BRUSH);
            rTmp = rect.ToRECT();
            FillRect(hdc, &rTmp, brush);
            DeleteObject(brush);
        }

        SelectFont(hdc, oldfnt);

        buffer.Flush(hdcWnd);
        EndPaint(hwnd, &ps);
        return 0;
    }
    if (WM_SETCURSOR == message && wnd->hasCancel) {
        POINT pt;
        if (GetCursorPosInHwnd(hwnd, pt) &&
            GetCancelRect(hwnd).Contains(PointI(pt.x, pt.y))) {
            SetCursor(LoadCursor(NULL, IDC_HAND));
            return TRUE;
        }
    }
    if (WM_LBUTTONUP == message && wnd->hasCancel) {
        if (GetCancelRect(hwnd).Contains(PointI(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)))) {
            if (wnd->notificationCb)
                wnd->notificationCb->RemoveNotification(wnd);
            else
                delete wnd;
            return 0;
        }
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}
Example #27
0
void DrawLegendLabel (PLEGEND pLegend,
                      HDC hDC,
                      HWND hWnd)
   {  // DrawLegendLabel
   int            i ;
   int            xPos ;
   RECT           rect ;
   RECT           rectLB ;
   INT            LocalThreeDPad = ThreeDPad - 1 ;

//   SetBkColor (hDC, crLightGray) ;
   SetBkColor (hDC, ColorBtnFace) ;

   SelectFont (hDC, pLegend->hFontLabels) ;

   GetClientRect (hWnd, &rect) ;
//   Fill (hDC, crLightGray, &rect) ;
   ExtTextOut (hDC, rect.left, rect.top,
      ETO_OPAQUE, &(rect), NULL, 0, NULL ) ;

   GetWindowRect (pLegend->hWndItems, &rectLB) ;
   ScreenRectToClient (hWnd, &rectLB) ;
   ThreeDConcave1 (hDC, 
                  rectLB.left - LocalThreeDPad,
                  rectLB.top - LocalThreeDPad,
                  rectLB.right + LocalThreeDPad,
                  rectLB.bottom + LocalThreeDPad) ;

   for (i = 0 ;
        i < iLegendNumCols ;
        i++)
      {  // for
      rect.left = pLegend->aCols[i].xPos ;
      rect.top = yBorderHeight ;
      rect.right = rect.left + pLegend->aCols[i].xWidth - LegendHorzMargin () ;
      rect.bottom = pLegend->yLabelHeight ;

      switch (pLegend->aCols[i].iOrientation)
         {  // switch
         case LEFTORIENTATION:
            SetTextAlign (hDC, TA_LEFT) ;
            xPos = rect.left ;
            break ;

         case CENTERORIENTATION:
            SetTextAlign (hDC, TA_CENTER) ;
            xPos = (rect.left + rect.right) / 2 ;
            break ;

         case RIGHTORIENTATION:
            SetTextAlign (hDC, TA_RIGHT) ;
            xPos = rect.right ;
            break ;

         default:
            xPos = rect.left ;
            break ;
         }  // switch

      ExtTextOut (hDC, 
                  xPos, rect.top, 
                  ETO_OPAQUE,
                  &rect,
                  pLegend->aCols[i].szLabel,
                  lstrlen (pLegend->aCols[i].szLabel),
                  NULL) ;
      }  // for
   }  // DrawLegendLabel
Example #28
0
static int boardwinproc(HWND  hWnd, int message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	char sstr[20];
	static char keyupFlag=0;
	int tmpvalue = 0;
	switch (message)
	{
		case MSG_CREATE:
			LoadBitmap(HDC_SCREEN,&smsshowbk,GetBmpPath("sms.jpg"));
			LoadBitmap(HDC_SCREEN,&barbmp, GetBmpPath("bar.bmp"));
			LoadBitmap(HDC_SCREEN,&smsshowbmp1,GetBmpPath("left2.gif"));
			LoadBitmap(HDC_SCREEN,&smsshowbmp2,GetBmpPath("right2.gif"));

			if (gfont==NULL)
			{
				smsshowfont = CreateLogFont (NULL,"fixed","GB2312",FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN, FONT_SETWIDTH_NORMAL,
						FONT_SPACING_CHARCELL, FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,10, 0);
				titlefont = CreateLogFont (NULL,"fixed","GB2312",FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN, FONT_SETWIDTH_NORMAL,
						FONT_SPACING_CHARCELL, FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,12, 0);
			}
			else
			{
				smsshowfont=gfont;
				titlefont=gfont1;
			}
			LoadsshowHint();
			InitWindow(hWnd);		//add controls
			curIdx=1;
			ShowMessage(hWnd,GetSmsPIN(curIdx));

			exitcount = 0;
#ifdef ZEM600
			SetTimer(hWnd,IDC_TIMERSMS,50);
#else
			SetTimer(hWnd,IDC_TIMERSMS,100);
#endif
			break;

		case MSG_PAINT:
			hdc=BeginPaint(hWnd);

			//write title
			SelectFont(hdc,titlefont);
			SetTextColor(hdc,PIXEL_lightwhite);
			tmpvalue = SetBkMode(hdc,BM_TRANSPARENT);
			memset(sstr,0,20);
			sprintf(sstr,"%s",sshowhint[0]);
			TextOut(hdc,140,15,sstr);

			//                        SetBkColor(hdc,0x00FFA2BE);
			//SelectFont(hdc,smsshowfont);
			SelectFont(hdc,titlefont);
			SetTextColor(hdc,PIXEL_lightwhite);

			memset(sstr,0,20);
			if (fromRight)
				sprintf(sstr,"%s",sshowhint[1]);
			else
				sprintf(sstr,"%s:",sshowhint[1]);
			TextOut(hdc,5,220,sstr);
			FillBoxWithBitmap (hdc, 65, 218,16, 16, &smsshowbmp1);

			memset(sstr,0,20);
			if (fromRight)
				sprintf(sstr,"%s",sshowhint[2]);
			else
				sprintf(sstr,"%s:",sshowhint[2]);
			TextOut(hdc,90,220,sstr);
			FillBoxWithBitmap (hdc, 140, 218,16, 16, &smsshowbmp2);

			memset(sstr,0,20);
			if (fromRight)
				sprintf(sstr,"%s%d:%s,%s%d:%s",sshowhint[3],bsmscount,sshowhint[4],sshowhint[5],curIdx,sshowhint[4]);
			else
				sprintf(sstr,"%s:%d%s,%s:%d%s",sshowhint[3],bsmscount,sshowhint[4],sshowhint[5],curIdx,sshowhint[4]);
			TextOut(hdc,170,220,sstr);

			EndPaint(hWnd,hdc);
			break;

		case MSG_ERASEBKGND:
			{
				HDC hdc = (HDC)wParam;
				const RECT* clip = (const RECT*)lParam;
				BOOL fGetDC = FALSE;
				RECT rcTemp;
				if(hdc == 0)
				{
					hdc = GetClientDC(hWnd);
					fGetDC = TRUE;
				}

				if(clip)
				{
					rcTemp = *clip;
					ScreenToClient(hWnd, &rcTemp.left, &rcTemp.top);
					ScreenToClient(hWnd,&rcTemp.right, &rcTemp.bottom);
					IncludeClipRect(hdc, &rcTemp);
				}

				FillBoxWithBitmap (hdc, 0, 0, gOptions.LCDWidth, gOptions.LCDHeight-30, &smsshowbk);
				FillBoxWithBitmap (hdc, 0, 210, gOptions.LCDWidth,30,&barbmp);

				if(fGetDC) ReleaseDC (hdc);
				break;
			}

		case MSG_KEYUP:
			if(3 == gOptions.TFTKeyLayout)
			{
				keyupFlag=1;
			}
			break;
		case MSG_KEYDOWN:
			SetMenuTimeOut(time(NULL));
			if(3 == gOptions.TFTKeyLayout)
			{
				if(1==keyupFlag)
					keyupFlag=0;
				else
					break;
			}
			exitcount=0;

			if ((LOWORD(wParam)==SCANCODE_ESCAPE))
				PostMessage(hWnd,MSG_CLOSE,0,0L);

			/*SMS快捷键查看,modify by yangxiaolong,start*/
			//del
			/*
			   if(LOWORD(wParam)==SCANCODE_CURSORBLOCKDOWN || LOWORD(wParam)==SCANCODE_CURSORBLOCKUP)
			   {
			   SendMessage(EdText,MSG_KEYDOWN,wParam,lParam);
			   }*/
			//add
			//快捷键查看SMS时,上下键翻动换行反应缓慢,调成翻页处理
			if(LOWORD(wParam)==SCANCODE_CURSORBLOCKDOWN)
			{
				SendMessage(EdText,MSG_KEYDOWN,SCANCODE_PAGEDOWN,lParam);
			}
			else if (LOWORD(wParam)==SCANCODE_CURSORBLOCKUP)
			{
				SendMessage(EdText,MSG_KEYDOWN,SCANCODE_PAGEUP,lParam);
			}
			/*SMS快捷键查看,modify by yangxiaolong,end*/	

			if(LOWORD(wParam)==SCANCODE_F11)
				SendMessage(EdText,MSG_KEYDOWN,SCANCODE_PAGEUP,lParam);
			if(LOWORD(wParam)==SCANCODE_F12)
				SendMessage(EdText,MSG_KEYDOWN,SCANCODE_PAGEDOWN,lParam);

			//if(LOWORD(wParam)==SCANCODE_CURSORBLOCKLEFT && bsmscount>1)
			if((LOWORD(wParam)==SCANCODE_CURSORBLOCKLEFT || (LOWORD(wParam)==SCANCODE_BACKSPACE && 3==gOptions.TFTKeyLayout)) && bsmscount>1)
			{
				if(--curIdx < 1) curIdx = bsmscount;
				ShowMessage(hWnd,GetSmsPIN(curIdx));
			}

			if(LOWORD(wParam)==SCANCODE_CURSORBLOCKRIGHT && bsmscount>1)
			{
				if(++curIdx > bsmscount) curIdx = 1;
				ShowMessage(hWnd,GetSmsPIN(curIdx));
			}

			break;

		case MSG_TIMER:
			if(wParam==IDC_TIMERSMS)
			{
				if(++exitcount>60) SendMessage(hWnd,MSG_CLOSE,0,0);
			}
			break;

		case MSG_CLOSE:
			UnloadBitmap(&smsshowbk);
			UnloadBitmap(&barbmp);
			UnloadBitmap(&smsshowbmp1);
			UnloadBitmap(&smsshowbmp2);
			if (gfont1==NULL)
			{
				DestroyLogFont(smsshowfont);
				DestroyLogFont(titlefont);
			}
			KillTimer(hWnd,IDC_TIMERSMS);
			freeList();
			DestroyMainWindow(hWnd);
			//hSMSWnd=NULL;
			break;

		default:
			return DefaultMainWinProc(hWnd,message,wParam,lParam);

	}
	return (0);

}
Example #29
0
void OnDrawLegendItem (HWND hWnd,
                        LPDRAWITEMSTRUCT lpDI)
   {  // OnDrawItem
   HFONT          hFontPrevious ;
   HDC            hDC ;
   PLEGEND        pLegend ;
   PLINESTRUCT    pLine ;
   int            iLBIndex ;
   COLORREF       preBkColor = 0;
   COLORREF       preTextColor = 0;
   BOOL           ResetColor = FALSE ;

   
   hDC = lpDI->hDC ;
   iLBIndex = DIIndex (lpDI) ;

   pLegend = LegendData (hWnd) ;

   if (iLBIndex == -1)
      pLine = NULL ;
   else
      pLine = (PLINESTRUCT) LBData (pLegend->hWndItems, iLBIndex) ;

   //=============================//
   // Set DC attributes           //
   //=============================//


   if (DISelected (lpDI) || pLine == NULL)
      {  // if
      preTextColor = SetTextColor (hDC, GetSysColor (COLOR_HIGHLIGHTTEXT)) ;
      preBkColor = SetBkColor (hDC, GetSysColor (COLOR_HIGHLIGHT)) ;
      ResetColor = TRUE ;
      }  // if
   ExtTextOut (hDC, lpDI->rcItem.left, lpDI->rcItem.top,
      ETO_OPAQUE, &(lpDI->rcItem), NULL, 0, NULL ) ;
   

   //=============================//
   // Draw Legend Item            //
   //=============================//

   hFontPrevious = SelectFont (hDC, pLegend->hFontItems) ;
   if (pLine)
      DrawLegendItem (pLegend, pLine, lpDI->rcItem.top, hDC) ;
   SelectFont (hDC, hFontPrevious) ;

   //=============================//
   // Draw Focus                  //
   //=============================//

   if (DIFocus (lpDI))
      DrawFocusRect (hDC, &(lpDI->rcItem)) ;


   if (ResetColor == TRUE)
      {  // if
      preTextColor = SetTextColor (hDC, preTextColor) ;
      preBkColor = SetBkColor (hDC, preBkColor) ;
      }  // if
   }  // OnDrawItem
    HRESULT Shape() {
        HRESULT rv;
        HDC shapeDC = nullptr;

        const PRUnichar *str = mAlternativeString ? mAlternativeString : mItemString;

        mScriptItem->a.fLogicalOrder = true; 
        SCRIPT_ANALYSIS sa = mScriptItem->a;

        while (true) {

            rv = ScriptShape(shapeDC, mShaper->ScriptCache(),
                             str, mItemLength,
                             mMaxGlyphs, &sa,
                             mGlyphs.Elements(), mClusters.Elements(),
                             mAttr.Elements(), &mNumGlyphs);

            if (rv == E_OUTOFMEMORY) {
                mMaxGlyphs *= 2;
                if (!mGlyphs.SetLength(mMaxGlyphs) ||
                    !mAttr.SetLength(mMaxGlyphs)) {
                    return E_OUTOFMEMORY;
                }
                continue;
            }

            // Uniscribe can't do shaping with some fonts, so it sets the 
            // fNoGlyphIndex flag in the SCRIPT_ANALYSIS structure to indicate
            // this.  This occurs with CFF fonts loaded with 
            // AddFontMemResourceEx but it's not clear what the other cases
            // are. We return an error so our caller can try fallback shaping.
            // see http://msdn.microsoft.com/en-us/library/ms776520(VS.85).aspx

            if (sa.fNoGlyphIndex) {
                return GDI_ERROR;
            }

            if (rv == E_PENDING) {
                if (shapeDC == mDC) {
                    // we already tried this once, something failed, give up
                    return E_PENDING;
                }

                SelectFont();

                shapeDC = mDC;
                continue;
            }

            // http://msdn.microsoft.com/en-us/library/dd368564(VS.85).aspx:
            // Uniscribe will return this if "the font corresponding to the
            // DC does not support the script required by the run...".
            // In this case, we'll set the script code to SCRIPT_UNDEFINED
            // and try again, so that we'll at least get glyphs even though
            // they won't necessarily have proper shaping.
            // (We probably shouldn't have selected this font at all,
            // but it's too late to fix that here.)
            if (rv == USP_E_SCRIPT_NOT_IN_FONT) {
                sa.eScript = SCRIPT_UNDEFINED;
                NS_WARNING("Uniscribe says font does not support script needed");
                continue;
            }

            // Prior to Windows 7, Uniscribe didn't support Ideographic Variation
            // Selectors. Replace the UVS glyph manually.
            if (mIVS) {
                uint32_t lastChar = str[mItemLength - 1];
                if (NS_IS_LOW_SURROGATE(lastChar)
                    && NS_IS_HIGH_SURROGATE(str[mItemLength - 2])) {
                    lastChar = SURROGATE_TO_UCS4(str[mItemLength - 2], lastChar);
                }
                uint16_t glyphId = mShaper->GetFont()->GetUVSGlyph(lastChar, mIVS);
                if (glyphId) {
                    mGlyphs[mNumGlyphs - 1] = glyphId;
                }
            }

            return rv;
        }
    }