Exemplo n.º 1
0
void CStatusControl::CreateChildren() {
  // First create the two static labels.
  HGDIOBJ hGuiFont;
  hGuiFont = GetStockObject(DEFAULT_GUI_FONT);

  std::wstring strSpeedLabel(L"Speed:");
  std::wstring strAlphabetLabel(L"Alphabet:");

  // TODO: Wrap windows here in CWindow classes.
#ifndef _WIN32_WCE
  // TODO: Is this really needed?
  m_hSpeedLabel = CreateWindowEx(WS_EX_CONTROLPARENT, TEXT("STATIC"), strSpeedLabel.c_str(), 
      SS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, 0, 0, m_hWnd, NULL, WinHelper::hInstApp, NULL);
#else
  m_hSpeedLabel = CreateWindowEx(0, TEXT("STATIC"), strSpeedLabel.c_str(), 
      SS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, 0, 0, m_hWnd, NULL, WinHelper::hInstApp, NULL);
#endif

#ifndef _WIN32_WCE
  m_hAlphabetLabel = CreateWindowEx(WS_EX_CONTROLPARENT, TEXT("STATIC"), strAlphabetLabel.c_str(), 
      SS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, 0, 0, m_hWnd, NULL, WinHelper::hInstApp, NULL);
#else
  m_hAlphabetLabel = CreateWindowEx(0, TEXT("STATIC"), strAlphabetLabel.c_str(), 
      SS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, 0, 0, m_hWnd, NULL, WinHelper::hInstApp, NULL);
#endif

  SendMessage(m_hSpeedLabel, WM_SETFONT, (WPARAM) hGuiFont, true);
  SendMessage(m_hAlphabetLabel, WM_SETFONT, (WPARAM) hGuiFont, true);

  SIZE sSize;

  HDC hSpeedDC(::GetDC(m_hSpeedLabel));
  SelectObject(hSpeedDC, hGuiFont);
  GetTextExtentPoint32(hSpeedDC, strSpeedLabel.c_str(), strSpeedLabel.size(), &sSize);
  ::MoveWindow(m_hSpeedLabel, 0, 0, sSize.cx + 4, sSize.cy, false);
  ::ReleaseDC(m_hSpeedLabel, hSpeedDC);

  HDC hAlphabetDC(::GetDC(m_hAlphabetLabel));
  SelectObject(hAlphabetDC, hGuiFont);
  GetTextExtentPoint32(hAlphabetDC, strAlphabetLabel.c_str(), strAlphabetLabel.size(), &sSize);
  ::MoveWindow(m_hAlphabetLabel, 0, 0, sSize.cx + 4, sSize.cy, false);
  ::ReleaseDC(m_hAlphabetLabel, hAlphabetDC);

  // Next the edit box and up/down control
  m_hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_GROUP, 0, 0, 0, CW_USEDEFAULT, m_hWnd, NULL, WinHelper::hInstApp, NULL);
  SendMessage(m_hEdit, EM_LIMITTEXT, (WPARAM) 4, (LPARAM) 0);

  HDC hdc = ::GetDC(m_hEdit);
  TEXTMETRIC tmGui;
  GetTextMetrics(hdc, &tmGui);
  SendMessage(m_hEdit, WM_SETFONT, (WPARAM) hGuiFont, true);
  ::ReleaseDC(m_hEdit, hdc);

  m_iEditHeight = tmGui.tmHeight + (GetSystemMetrics(SM_CYEDGE) * 2);
  m_iEditWidth = tmGui.tmAveCharWidth * 7;
  ::MoveWindow(m_hEdit, 0, 0, m_iEditWidth, m_iEditHeight, false);
 
  m_hUpDown = CreateWindowEx(WS_EX_CLIENTEDGE, UPDOWN_CLASS, TEXT(""), UDS_ALIGNRIGHT | WS_CHILD  | WS_TABSTOP |WS_VISIBLE |  WS_GROUP, 0, 0, 16, 16, m_hWnd, NULL, WinHelper::hInstApp, NULL);
  SendMessage(m_hUpDown, UDM_SETRANGE, 0, (LPARAM) MAKELONG(800, 1));

  // And finally the combo box
  m_hCombo = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("COMBOBOX"), TEXT(""), CBS_DROPDOWNLIST | WS_CHILD | WS_TABSTOP | WS_VISIBLE |WS_GROUP | ES_READONLY, 0, 0, 128, 128, m_hWnd, NULL, WinHelper::hInstApp, NULL);
  SendMessage(m_hCombo, WM_SETFONT, (WPARAM) hGuiFont, true);

  DeleteObject(hGuiFont);

  // Set the height to what is finally required. The extra pixel is needed to get everything to line up nicely
  MoveWindow(0, 0, 0, m_iEditHeight+1, false);
}
Exemplo n.º 2
0
//测量位置
VOID CSkinMenuKernel::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
	//效验参数
	ASSERT(lpMeasureItemStruct->CtlType==ODT_MENU);
	if (lpMeasureItemStruct->CtlType!=ODT_MENU) return;

	//获取数据
	CSkinMenuItem * pSkinMenuItem=(CSkinMenuItem *)lpMeasureItemStruct->itemData;
	if (pSkinMenuItem==NULL)
	{
		//获取信息
		MENUITEMINFO MenuItemInfo;
		MenuItemInfo.cbSize=sizeof(MenuItemInfo);
		MenuItemInfo.fMask=MIIM_FTYPE|MIIM_STRING;
		GetMenuItemInfo(lpMeasureItemStruct->itemID,&MenuItemInfo);

		return;
	}

	//界面菜单
	switch (pSkinMenuItem->m_MenuItemType)
	{
	case MenuItemType_Image:		//图形菜单
		{
			//变量定义
			CSkinMenuImage * pSkinMenuImage=(CSkinMenuImage *)pSkinMenuItem;

			//获取信息
			BITMAP BitmapInfo;
			GetObject(pSkinMenuImage->m_hBitmap,sizeof(BitmapInfo),&BitmapInfo);

			//计算大小
			lpMeasureItemStruct->itemHeight=BitmapInfo.bmHeight+6;
			lpMeasureItemStruct->itemWidth=BitmapInfo.bmWidth+MENU_BAR_CX+SPACE_LEFT+SPACE_RIGHT;

			break;
		}
	case MenuItemType_String:		//字符菜单
		{
			//变量定义
			CSkinMenuString * pSkinMenuString=(CSkinMenuString *)pSkinMenuItem;

			//设置 DC
			HDC hDC=GetDC(NULL);
			SelectObject(hDC,CSkinResourceManager::GetInstance()->GetDefaultFont());

			//计算长度
			CSize SizeString;
			GetTextExtentPoint32(hDC,pSkinMenuString->m_strString,pSkinMenuString->m_strString.GetLength(),&SizeString);

			//计算位置
			lpMeasureItemStruct->itemHeight=MENU_ITEM_CY;
			lpMeasureItemStruct->itemWidth=SizeString.cx+MENU_BAR_CX+SPACE_LEFT+SPACE_RIGHT;

			//释放资源
			ReleaseDC(NULL,hDC);

			break;
		}
	case MenuItemType_Separator:	//拆分菜单
		{
			lpMeasureItemStruct->itemWidth=0;
			lpMeasureItemStruct->itemHeight=SEPARATOR_CY;

			break;
		}
	}

	return;
}
Exemplo n.º 3
0
//===========================================================================
ST void PaintToolbar(HDC hdc, RECT *rcPaint)
{
	RECT r;
	int i;
	const char *label = Toolbar_CurrentWindow;
	StyleItem *pSI;

#ifdef BBOPT_MEMCHECK
	// Display some statistics.
#pragma message("\n"__FILE__ "(397) : warning 0: MEMCHECK enabled.\n")
	/*
		if (NULL==Toolbar_hFont)
		{
			LOGFONT logFont;
			SystemParametersInfo(SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
			Toolbar_hFont = CreateFontIndirect(&logFont);
		}
	*/
	extern int g_menu_count;
	extern int g_menu_item_count;
	char temp[256];
	if (alloc_size && false == Toolbar_ShowingExternalLabel)
	{
		sprintf(temp,"Menus %d  MenuItems %d  Memory %d", g_menu_count, g_menu_item_count, alloc_size);
		label = temp;

	}
#endif

	int tbW = TBInfo.width;
	int tbH = TBInfo.height;
	HDC buf = CreateCompatibleDC(NULL);
	HGDIOBJ bufother = SelectObject(buf, CreateCompatibleBitmap(hdc, tbW, tbH));

	if (NULL==Toolbar_hFont) Toolbar_hFont = CreateStyleFont(&mStyle.Toolbar);
	HGDIOBJ other_font = SelectObject(buf, Toolbar_hFont);

	// Get width of clock...
	SIZE size;

	GetTextExtentPoint32(buf, Toolbar_CurrentTime, strlen(Toolbar_CurrentTime), &size);
	size.cx += 6;
	if (tbClockW < size.cx) tbClockW = size.cx + 6;

	GetTextExtentPoint32(buf, Toolbar_WorkspaceName, strlen(Toolbar_WorkspaceName), &size);
	int tbLabelW = size.cx + 6;

	// The widest sets the width!
	tbLabelW = tbClockW = imax(tbH * 2, imax(tbLabelW, tbClockW));

	int margin = tbMargin;
	int border = mStyle.Toolbar.borderWidth;
	int border_margin = margin + border;
	int button_padding = (tbH - tbButtonWH) / 2 - border;

	int tbLabelX = border_margin;
	int tbClockX = tbW - tbClockW - border_margin;
	int two_buttons = 2*tbButtonWH + 3*button_padding;
	int tbWinLabelX = tbLabelX + tbLabelW + two_buttons;
	int tbWinLabelW = tbClockX - tbWinLabelX - two_buttons;
	if (tbWinLabelW < 0) tbWinLabelW = 0;

	Toolbar_Button[0].r.left = tbLabelX + tbLabelW + button_padding;
	Toolbar_Button[1].r.left = Toolbar_Button[0].r.left + tbButtonWH + button_padding;
	Toolbar_Button[2].r.left = tbClockX - 2*tbButtonWH - 2*button_padding;
	Toolbar_Button[3].r.left = Toolbar_Button[2].r.left + tbButtonWH + button_padding;

	Toolbar_Button[4].r.left = tbClockX;
	for (i = 0; i<5; i++)
	{
		Toolbar_Button[i].r.top    = (tbH - tbButtonWH) / 2;
		Toolbar_Button[i].r.bottom = Toolbar_Button[i].r.top + tbButtonWH;
		Toolbar_Button[i].r.right  = Toolbar_Button[i].r.left + tbButtonWH;
	}
	Toolbar_Button[4].r.right = tbClockX + tbClockW;

	//====================

	// Paint toolbar Style
	r.left = r.top = 0;
	r.right = tbW;
	r.bottom = tbH;
	pSI = &mStyle.Toolbar;
	MakeStyleGradient(buf, &r, pSI, true);

	//====================
	// Paint unpressed workspace/task buttons...

	r.left = r.top = 0;
	r.right = r.bottom = tbButtonWH;
	{
		HPEN activePen   = CreatePen(PS_SOLID, 1, mStyle.ToolbarButtonPressed.picColor);
		HPEN inactivePen = CreatePen(PS_SOLID, 1, mStyle.ToolbarButton.picColor);
		HDC src = CreateCompatibleDC(NULL);
		HGDIOBJ srcother = SelectObject(src, CreateCompatibleBitmap(hdc, tbButtonWH, tbButtonWH));
		int yOffset = tbH / 2;
		int xOffset;
		int f1 = -1;
		for (i=0; i<4; i++)
		{
			int f2 = Toolbar_Button[i].pressed || (Toolbar_force_button_pressed && i&1);
			pSI = f2 ? &mStyle.ToolbarButtonPressed : &mStyle.ToolbarButton;

			if (pSI->parentRelative)
			{
				CreateBorder(buf, &r, pSI->borderColor, pSI->borderWidth);
			}
			else
			{
				if (f1 != f2)
					MakeStyleGradient(src, &r, pSI, pSI->bordered), f1 = f2;

				BitBlt(buf,
					   Toolbar_Button[i].r.left,
					   Toolbar_Button[i].r.top,
					   tbButtonWH, tbButtonWH, src, 0, 0, SRCCOPY
					  );
			}

			xOffset = Toolbar_Button[i].r.left + (tbButtonWH / 2);
			HGDIOBJ penother = SelectObject(buf, f2 ? activePen : inactivePen);
			arrow_bullet(buf, xOffset, yOffset, (i&1)*2-1);
			SelectObject(buf, penother);
		}

		DeleteObject(SelectObject(src, srcother));
		DeleteDC(src);
		DeleteObject(inactivePen);
		DeleteObject(activePen);
	}

	//====================

	r.top = (tbH - tbLabelH)/2;
	r.bottom = r.top + tbLabelH;
	SetBkMode(buf, TRANSPARENT);
	int justify = mStyle.Toolbar.Justify | (DT_VCENTER|DT_SINGLELINE|DT_WORD_ELLIPSIS|DT_NOPREFIX);

	// Paint workspaces background...
	r.right = (r.left = tbLabelX) + tbLabelW;
	pSI = &mStyle.ToolbarLabel;
	MakeStyleGradient(buf, &r, pSI, pSI->bordered);
	r.left  += 3;
	r.right -= 3;
	SetTextColor(buf, mStyle.ToolbarLabel.TextColor);
	BBDrawText(buf, Toolbar_WorkspaceName, -1, &r, justify, pSI);

	// Paint window label background...
	r.right = (r.left = tbWinLabelX) + tbWinLabelW;
	pSI = &mStyle.ToolbarWindowLabel;
	MakeStyleGradient(buf, &r, pSI, pSI->bordered);
	r.left  += 3;
	r.right -= 3;
	SetTextColor(buf, mStyle.ToolbarWindowLabel.TextColor);
	BBDrawText(buf, label, -1, &r, justify, pSI);

	// Paint clock background...
	r.right = (r.left = tbClockX) + tbClockW;
	pSI = &mStyle.ToolbarClock;
	MakeStyleGradient(buf, &r, pSI, pSI->bordered);
	r.left  += 3;
	r.right -= 3;
	SetTextColor(buf, mStyle.ToolbarClock.TextColor);
	BBDrawText(buf, Toolbar_CurrentTime, -1, &r, justify, pSI);

	//====================

	BitBltRect(hdc, buf, rcPaint);

	SelectObject(buf, other_font);
	DeleteObject(SelectObject(buf, bufother));
	DeleteDC(buf);
}
Exemplo n.º 4
0
int RTL_HitTest(HWND hwnd, struct ClcData *dat, int testx, int testy, struct ClcContact *hitcontact, DWORD *flags, int indent, int hit)
{
    RECT clRect;
    int right, checkboxWidth, cxSmIcon, i, width;
    DWORD style = GetWindowLong(hwnd, GWL_STYLE);
    SIZE textSize;
    HDC hdc;
    HFONT hFont;

    GetClientRect(hwnd, &clRect);
    right = clRect.right;

    // avatar check
    if(hitcontact->type == CLCIT_CONTACT && cfg::dat.dwFlags & CLUI_FRAME_AVATARS && hitcontact->ace != NULL && hitcontact->avatarLeft != -1) {
        if(testx < right - hitcontact->avatarLeft && testx > right - hitcontact->avatarLeft - cfg::dat.avatarSize) {
            if(flags)
                *flags |= CLCHT_ONAVATAR;
        }
    }
    if (testx > right - (dat->leftMargin + indent * dat->groupIndent)) {
        if (flags)
            *flags |= CLCHT_ONITEMINDENT;
        return hit;
    }
    checkboxWidth = 0;
    if (style & CLS_CHECKBOXES && hitcontact->type == CLCIT_CONTACT)
        checkboxWidth = dat->checkboxSize + 2;
    if (style & CLS_GROUPCHECKBOXES && hitcontact->type == CLCIT_GROUP)
        checkboxWidth = dat->checkboxSize + 2;
    if (hitcontact->type == CLCIT_INFO && hitcontact->flags & CLCIIF_CHECKBOX)
        checkboxWidth = dat->checkboxSize + 2;
    if (testx > right - (dat->leftMargin + indent * dat->groupIndent + checkboxWidth)) {
        if (flags)
            *flags |= CLCHT_ONITEMCHECK;
        return hit;
    }
    if (testx > right - (dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace)) {
        if (flags)
            *flags |= CLCHT_ONITEMICON;
        return hit;
    }
    cxSmIcon = GetSystemMetrics(SM_CXSMICON);
    for (i = 0; i< dat->extraColumnsCount; i++) {
        if (hitcontact->iExtraImage[i] == 0xFF)
            continue;
        if (testx >= dat->extraColumnSpacing * (dat->extraColumnsCount - i) && testx < dat->extraColumnSpacing * (dat->extraColumnsCount - i) + cxSmIcon) {
            if (flags)
                *flags |= CLCHT_ONITEMEXTRA | (i << 24);
            return hit;
        }
    }
    if(hitcontact->extraCacheEntry >= 0 && hitcontact->extraCacheEntry < cfg::nextCacheEntry && cfg::eCache[hitcontact->extraCacheEntry].iExtraValid) {
        int rightOffset = hitcontact->extraIconRightBegin;
        int images_present = 0;

        for (i = 5; i >= 0; i--) {
            if (cfg::eCache[hitcontact->extraCacheEntry].iExtraImage[i] == 0xFF)
                continue;
            if(!((1 << i) & cfg::eCache[hitcontact->extraCacheEntry].dwXMask))
                continue;
            images_present++;
            if (testx < right - (rightOffset - (cfg::dat.exIconScale + 2) * images_present) && testx > right - (rightOffset - (cfg::dat.exIconScale + 2) * images_present + (cfg::dat.exIconScale))) {
                if (flags)
                    *flags |= (CLCHT_ONITEMEXTRAEX | ((i + 1) << 24));
                return hit;
            }
        }
    }

    hdc = GetDC(hwnd);
    if (hitcontact->type == CLCIT_GROUP)
        hFont = reinterpret_cast<HFONT>(SelectObject(hdc, dat->fontInfo[FONTID_GROUPS].hFont));
    else
        hFont = reinterpret_cast<HFONT>(SelectObject(hdc, dat->fontInfo[FONTID_CONTACTS].hFont));
    GetTextExtentPoint32(hdc, hitcontact->szText, lstrlen(hitcontact->szText), &textSize);
    width = textSize.cx;
    if (hitcontact->type == CLCIT_GROUP) {
        char *szCounts;
        szCounts = pcli->pfnGetGroupCountsText(dat, hitcontact);
        if (szCounts[0]) {
            GetTextExtentPoint32A(hdc, " ", 1, &textSize);
            width += textSize.cx;
            SelectObject(hdc, dat->fontInfo[FONTID_GROUPCOUNTS].hFont);
            GetTextExtentPoint32A(hdc, szCounts, lstrlenA(szCounts), &textSize);
            width += textSize.cx;
        }
    }
    SelectObject(hdc, hFont);
    ReleaseDC(hwnd, hdc);
    if (testx > right - (dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace + width + 4 + (cfg::dat.dwFlags & CLUI_FRAME_AVATARS ? cfg::dat.avatarSize : 0))) {
        if (flags)
            *flags |= CLCHT_ONITEMLABEL;
        return hit;
    }
    if (cfg::dat.dwFlags & CLUI_FULLROWSELECT && !(GetKeyState(VK_SHIFT) & 0x8000) && testx < right - (dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace + width + 4 + (cfg::dat.dwFlags & CLUI_FRAME_AVATARS ? cfg::dat.avatarSize : 0))) {
        if (flags)
            *flags |= CLCHT_ONITEMSPACE;
        return hit;
    }
    if (flags)
        *flags |= CLCHT_NOWHERE;
    return -1;
}
Exemplo n.º 5
0
LRESULT DisViewBox_OnPaint(HWND hwnd, disview_struct *win, WPARAM wParam, LPARAM lParam)
{
        HDC          hdc;
        PAINTSTRUCT  ps;
        SIZE fontsize;
        TCHAR text[100];
        TCHAR txt[100];
        RECT rect;
        int lg;
        int ht;
        HDC mem_dc;
        HBITMAP mem_bmp;
        u32  nbligne;

        GetClientRect(hwnd, &rect);
        lg = rect.right - rect.left;
        ht = rect.bottom - rect.top;
        
        hdc = BeginPaint(hwnd, &ps);
        
        mem_dc = CreateCompatibleDC(hdc);
        mem_bmp = CreateCompatibleBitmap(hdc, lg, ht);
        SelectObject(mem_dc, mem_bmp);
        
        FillRect(mem_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
        
        SelectObject(mem_dc, GetStockObject(SYSTEM_FIXED_FONT));
        
        GetTextExtentPoint32(mem_dc, "0", 1, &fontsize);
        
        nbligne = ht/fontsize.cy;
        
        SetTextColor(mem_dc, RGB(0,0,0));
        
        if((win->mode==1) || ((win->mode==0) && (win->cpu->CPSR.bits.T == 0)))
        {
             u32 i;
             u32 adr;

             if (win->autoup||win->autogo)
				 win->curr_ligne = (win->cpu->instruct_adr >> 2);
             adr = win->curr_ligne*4;

             for(i = 0; i < nbligne; ++i)
             {
                  u32 ins = _MMU_read32(win->cpu->proc_ID, MMU_AT_DEBUG, adr);
                  des_arm_instructions_set[INDEX(ins)](adr, ins, txt);
                  sprintf(text, "%04X:%04X  %08X  %s", (int)(adr>>16), (int)(adr&0xFFFF), (int)ins, txt);
                  DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX);
                  rect.top+=fontsize.cy;
                  adr += 4;
             }
             
             
        
             if(((win->cpu->instruct_adr&0x0FFFFFFF) >= (win->curr_ligne<<2))&&((win->cpu->instruct_adr&0x0FFFFFFF) <= (win->curr_ligne+(nbligne<<2))))
             {
                  HBRUSH brjaune = CreateSolidBrush(RGB(255, 255, 0));
                  SetBkColor(mem_dc, RGB(255, 255, 0));
                  rect.top = (((win->cpu->instruct_adr&0x0FFFFFFF)>>2) - win->curr_ligne)*fontsize.cy;
                  rect.bottom = rect.top + fontsize.cy;
                  FillRect(mem_dc, &rect, brjaune);
                  des_arm_instructions_set[INDEX(win->cpu->instruction)](win->cpu->instruct_adr, win->cpu->instruction, txt);
                  sprintf(text, "%04X:%04X  %08X  %s", (int)((win->cpu->instruct_adr&0x0FFFFFFF)>>16), (int)(win->cpu->instruct_adr&0xFFFF), (int)win->cpu->instruction, txt);
                  DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX);
                  DeleteObject(brjaune);
             }
Exemplo n.º 6
0
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
    NPP instance = (NPP)GetWindowLongPtr(hWnd, GWLP_USERDATA);
    
    if (uiMsg == WM_PAINT)
    {
        InstanceData *data = (InstanceData *)instance->pdata;
        
        PAINTSTRUCT ps;
        HDC hDC = BeginPaint(hWnd, &ps);
        HBRUSH brushBg = CreateSolidBrush(COL_WINDOW_BG);
        HFONT hFont = GetSimpleFont(hDC, L"MS Shell Dlg", 14);
        bool isRtL = IsLanguageRtL(gTranslationIdx);
        
        // set up double buffering
        RectI rcClient = ClientRect(hWnd);
        DoubleBuffer buffer(hWnd, rcClient);
        HDC hDCBuffer = buffer.GetDC();
        
        // display message centered in the window
        FillRect(hDCBuffer, &rcClient.ToRECT(), brushBg);
        hFont = (HFONT)SelectObject(hDCBuffer, hFont);
        SetTextColor(hDCBuffer, RGB(0, 0, 0));
        SetBkMode(hDCBuffer, TRANSPARENT);
        DrawCenteredText(hDCBuffer, rcClient, data->message, isRtL);
        
        // draw a progress bar, if a download is in progress
        if (0 < data->progress && data->progress <= 1)
        {
            SIZE msgSize;
            RectI rcProgress = rcClient;
            
            HBRUSH brushProgress = CreateSolidBrush(RGB(0x80, 0x80, 0xff));
            GetTextExtentPoint32(hDCBuffer, data->message, (int)str::Len(data->message), &msgSize);
            rcProgress.Inflate(-(rcProgress.dx - msgSize.cx) / 2, -(rcProgress.dy - msgSize.cy) / 2 + 2);
            rcProgress.Offset(0, msgSize.cy + 4 + 2);
            FillRect(hDCBuffer, &rcProgress.ToRECT(), GetStockBrush(WHITE_BRUSH));
            RectI rcProgressAll = rcProgress;
            rcProgress.dx = (int)(data->progress * rcProgress.dx);
            FillRect(hDCBuffer, &rcProgress.ToRECT(), brushProgress);
            DeleteObject(brushProgress);
            
            ScopedMem<WCHAR> currSize(FormatSizeSuccint(data->currSize));
            if (0 == data->totalSize || data->currSize > data->totalSize)
            {
                // total size unknown or bogus => show just the current size
                DrawCenteredText(hDCBuffer, rcProgressAll, currSize, isRtL);
            }
            else
            {
                ScopedMem<WCHAR> totalSize(FormatSizeSuccint(data->totalSize));
                ScopedMem<WCHAR> s(str::Format(_TR("%s of %s"), currSize, totalSize));
                DrawCenteredText(hDCBuffer, rcProgressAll, s, isRtL);
            }
        }
        
        // draw the buffer on screen
        buffer.Flush(hDC);
        
        DeleteObject(SelectObject(hDCBuffer, hFont));
        DeleteObject(brushBg);
        EndPaint(hWnd, &ps);
        
        HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL);
        if (hChild)
            InvalidateRect(hChild, NULL, FALSE);
    }
    else if (uiMsg == WM_SIZE)
    {
        HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL);
        if (hChild)
        {
            ClientRect rcClient(hWnd);
            MoveWindow(hChild, rcClient.x, rcClient.y, rcClient.dx, rcClient.dy, FALSE);
        }
    }
    else if (uiMsg == WM_COPYDATA)
    {
        COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lParam;
        if (cds && 0x4C5255 /* URL */ == cds->dwData)
        {
            plogf("sp: NPN_GetURL %s", cds->dwData, (const char *)cds->lpData);
            gNPNFuncs.geturl(instance, (const char *)cds->lpData, "_blank");
            return TRUE;
        }
    }
    
    return DefWindowProc(hWnd, uiMsg, wParam, lParam);
}
Exemplo n.º 7
0
LRESULT CALLBACK
waoWC_button0Proc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    static TRACKMOUSEEVENT tME;
    switch( msg )
    {
        case WM_CREATE:
        {
            tME.cbSize = sizeof( TRACKMOUSEEVENT );
            //tME.dwFlags = TME_HOVER;
            tME.dwHoverTime = 0;
            SendMessage( GetParent (hwnd), WAOM_TBBTNCREATED,
                    MAKEWPARAM( WAOM_TBBTNCREATED_LW,
                            GetWindowLong( hwnd, GWL_ID ) ), ( LPARAM ) hwnd );
            return FALSE;
        }
        case WM_ENABLE:
            if( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CHECKED )
                SetWindowLong( hwnd, GWL_USERDATA,
                        wParam ? ( WAO_TBBS_NORMAL | WAO_TBBS_CHECKED ) :
                        ( WAO_TBBS_DISABLED | WAO_TBBS_CHECKED ) );
            else
                SetWindowLong( hwnd, GWL_USERDATA, wParam ? WAO_TBBS_NORMAL : WAO_TBBS_DISABLED );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            return FALSE;
        case WM_MOUSEMOVE:
            if( GetWindowLong( hwnd, GWL_USERDATA ) != WAO_TBBS_NORMAL )
                return FALSE;
            SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_HOVERED );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            tME.dwFlags = TME_LEAVE;
            tME.hwndTrack = hwnd;
            TrackMouseEvent( &tME );
            return FALSE;
        case WM_MOUSELEAVE:
            SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_NORMAL );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            return FALSE;
        case WM_RBUTTONDOWN:
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_RIGHTBUTTON )
            {
                long btnStt = GetWindowLong( hwnd, GWL_USERDATA );
                SetWindowLong( hwnd, GWL_USERDATA,
                               WAO_TBBS_CLICKED | ( btnStt & WAO_TBBS_CHECKED ) );
            }
            return FALSE;
        case WM_LBUTTONDOWN:
        {
            long btnStt = GetWindowLong( hwnd, GWL_USERDATA );
            SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_CLICKED | ( btnStt & WAO_TBBS_CHECKED ) );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_NOTIFY )
                SetTimer( hwnd, WAO_TMR_TBRPW, WAO_TBBN_RPWTIME, NULL );
            return FALSE;
        }
        case WM_LBUTTONUP:
            // should be clicked first:
            if( !( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CLICKED ) )
                return FALSE;
        case WM_CLEAR: // tweak to check with one internal message
        {
            SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_NORMAL );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            DLGPROC parProc = ( DLGPROC ) GetWindowLong ( GetParent( hwnd ), DWL_DLGPROC );
            if( msg != WM_CLEAR ) // what about making this a seperate thread?
                parProc( GetParent ( hwnd ), WM_COMMAND,
                         MAKEWPARAM( GetWindowLong( hwnd, GWL_ID ),
                         WAO_TBBN_LCLCKED ),
                         ( LPARAM ) hwnd );
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_NOTIFY )
            {
                KillTimer( hwnd, WAO_TMR_TBRPW );
                KillTimer( hwnd, WAO_TMR_TBRPT );
            }
            return FALSE;
        }
        case WM_RBUTTONUP:
            // should be clicked first:
            if( !( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CLICKED ) )
                return FALSE;
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_RIGHTBUTTON )
            {
                DLGPROC parProc = ( DLGPROC ) GetWindowLong( GetParent( hwnd ), DWL_DLGPROC );
                parProc( GetParent( hwnd ),
                         WM_COMMAND,
                         MAKEWPARAM( GetWindowLong ( hwnd, GWL_ID ), WAO_TBBN_RCLCKED ),
                         ( LPARAM ) hwnd );
            }
            return FALSE;
        case WM_TIMER:
        {
            if( wParam == WAO_TMR_TBRPW ) // repeat wait
            {
                KillTimer( hwnd, WAO_TMR_TBRPW );
                SetTimer( hwnd, WAO_TMR_TBRPT, WAO_TBBN_RPTTIME, NULL );
            }
            DLGPROC parProc = ( DLGPROC ) GetWindowLong( GetParent( hwnd ), DWL_DLGPROC );
            parProc( GetParent( hwnd ),
                     WM_COMMAND,
                     MAKEWPARAM( GetWindowLong( hwnd, GWL_ID ), WAO_TBBN_LCLCKED ),
                     ( LPARAM ) hwnd );
            return FALSE;
        }
        case WM_PAINT:
        {
            PAINTSTRUCT paintStruct;
            BeginPaint( hwnd, &paintStruct );
            RECT rcWnd;
            GetClientRect( hwnd, &rcWnd ); // should this be calculated every time?
            int btnStt = GetWindowLong( hwnd, GWL_USERDATA );

            if( btnStt & WAO_TBBS_CHECKED )
            {
                FillRect( paintStruct.hdc, &rcWnd, CreateSolidBrush( 0x99ffff ) );
                DrawEdge( paintStruct.hdc, &rcWnd, BDR_SUNKENOUTER, BF_RECT );
            }
            else if( btnStt == WAO_TBBS_CLICKED )
            {
                DrawEdge( paintStruct.hdc, &rcWnd, BDR_SUNKENOUTER, BF_RECT );
            }
            else if( btnStt == WAO_TBBS_HOVERED )
            {
                DrawEdge( paintStruct.hdc, &rcWnd, BDR_RAISEDINNER, BF_RECT );
            }
            // drawing icon
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_ICON ) // maybe later bitmap too
            {
                HICON hIco = LoadIcon( GetModuleHandle( NULL ),
                                       MAKEINTRESOURCE( GetWindowLong( hwnd, GWL_ID ) ) );

                DrawIconEx( paintStruct.hdc,
                            ( rcWnd.right - rcWnd.left - 16 ) / 2,
                            ( rcWnd.bottom - rcWnd.top - 16 ) / 2,
                            hIco, 16, 16, 0, NULL, DI_NORMAL );
            }
            // drawing text
            else
            {
                int tmpLen = GetWindowTextLength( hwnd );
                wchar_t buffer[ tmpLen + 1 ];
                SIZE tmpSze;
                GetWindowText( hwnd, buffer, tmpLen + 1 );
                SetBkMode( paintStruct.hdc, TRANSPARENT );
                SelectObject( paintStruct.hdc, GetStockObject( DEFAULT_GUI_FONT ) );

                GetTextExtentPoint32( paintStruct.hdc, buffer, tmpLen, &tmpSze );
                DrawState( paintStruct.hdc, NULL, NULL,
                         ( LPARAM ) buffer, tmpLen,
                         ( rcWnd.right-rcWnd.left-tmpSze.cx ) / 2,
                         ( rcWnd.bottom-rcWnd.top-tmpSze.cy ) / 2,
                         tmpSze.cx, tmpSze.cy, DST_TEXT|(
                                ( btnStt & WAO_TBBS_DISABLED ) ? DSS_DISABLED : 0 ) );
            }
            EndPaint( hwnd, &paintStruct );
            return FALSE;
        }
        default:
            return DefWindowProc( hwnd, msg, wParam, lParam );
    }
}
Exemplo n.º 8
0
void DockingCont::SelectTab(int iTab)
{
	if (iTab != -1)
	{
		TCHAR	*pszMaxTxt	= NULL;
		TCITEM	tcItem		= {0};
		SIZE	size		= {0};
		int		maxWidth	= 0;
		int		iItemCnt	= ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0);

		// get data of new active dialog
		tcItem.mask		= TCIF_PARAM;
		::SendMessage(_hContTab, TCM_GETITEM, iTab, (LPARAM)&tcItem);
		// show active dialog
		if (!tcItem.lParam)
			return;

		::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_SHOW);
		::SetFocus(((tTbData*)tcItem.lParam)->hClient);

		if ((unsigned int)iTab != _prevItem)
		{
			// hide previous dialog
			::SendMessage(_hContTab, TCM_GETITEM, _prevItem, (LPARAM)&tcItem);

			if (!tcItem.lParam)
				return;
			::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_HIDE);
		}

		// resize tab item

		// get at first largest item ...
		HDC		hDc	= ::GetDC(_hContTab);
		SelectObject(hDc, _hFont);

		for (int iItem = 0; iItem < iItemCnt; iItem++)
		{
			TCHAR *pszTabTxt = NULL;

			::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem);
			if (!tcItem.lParam)
				continue;
			pszTabTxt = ((tTbData*)tcItem.lParam)->pszName;

			// get current font width
			GetTextExtentPoint32(hDc, pszTabTxt, lstrlen(pszTabTxt), &size);

			if (maxWidth < size.cx) 
			{
				maxWidth	= size.cx;
				pszMaxTxt	= pszTabTxt;
			}
		}
		::ReleaseDC(_hSelf, hDc);

		tcItem.mask	= TCIF_TEXT;

		for (int iItem = 0; iItem < iItemCnt; iItem++)
		{
			generic_string szText(TEXT(""));
			if (iItem == iTab && pszMaxTxt)
			{
				// fake here an icon before text ...
				szText = TEXT("    ");
				szText += pszMaxTxt;
			}
			tcItem.pszText = (TCHAR *)szText.c_str();
			::SendMessage(_hContTab, TCM_SETITEM, iItem, (LPARAM)&tcItem);
		}

		// selects the pressed tab and store previous tab
		::SendMessage(_hContTab, TCM_SETCURSEL, iTab, 0);
		_prevItem = iTab;

		// update caption text
		updateCaption();

		onSize();
	}
}
Exemplo n.º 9
0
void DockingCont::drawCaptionItem(DRAWITEMSTRUCT *pDrawItemStruct)
{
	HBRUSH		bgbrush		= NULL;
	HFONT		hOldFont	= NULL;
	RECT		rc			= pDrawItemStruct->rcItem;
	HDC			hDc			= pDrawItemStruct->hDC;
	HPEN		hPen		= ::CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_BTNSHADOW));
	BITMAP		bmp			= {0};
	HBITMAP		hBmpCur		= NULL;
	HBITMAP		hBmpOld 	= NULL;
	HBITMAP		hBmpNew		= NULL;
	UINT		length  	= _pszCaption.length();

	int nSavedDC			= ::SaveDC(hDc);

	// begin with paint
	::SetBkMode(hDc, TRANSPARENT);

	if (_isActive == TRUE) {
		bgbrush = ::CreateSolidBrush(::GetSysColor(COLOR_ACTIVECAPTION));
		::SetTextColor(hDc, ::GetSysColor(COLOR_CAPTIONTEXT));
	} else {
		bgbrush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
	}

	// set text and/or caption grid
	if (_isTopCaption == TRUE)
	{
		if (_isActive == TRUE)
		{
			// fill background
			::FillRect(hDc, &rc, bgbrush);
			rc.right	-= 1;
			rc.bottom	-= 1;
		}
		else
		{
			// fill background
			rc.right	-= 1;
			rc.bottom	-= 1;
			::FillRect(hDc, &rc, bgbrush);

			// draw grid lines

			MoveToEx(hDc, rc.left , rc.top , NULL);
			LineTo  (hDc, rc.right, rc.top );
			LineTo  (hDc, rc.right, rc.bottom );
			LineTo  (hDc, rc.left , rc.bottom );
			LineTo  (hDc, rc.left , rc.top);
		}

		// draw text
		rc.left		+= 2;
		rc.top		+= 1;
		rc.right	-= 16;
		hOldFont = (HFONT)::SelectObject(hDc, _hFont);
		::DrawText(hDc, _pszCaption.c_str(), length, &rc, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX);

		// calculate text size and if its trankated...
		SIZE	size	= {0};
		GetTextExtentPoint32(hDc, _pszCaption.c_str(), length, &size);
		_bCaptionTT = (((rc.right - rc.left) < size.cx) ? TRUE : FALSE);

		::SelectObject(hDc, hOldFont);
	}
	else
	{
		// create local font for vertical draw
		HFONT	hFont;

		if (_isActive == TRUE)
		{
			// fill background
			::FillRect(hDc, &rc, bgbrush);
			rc.right	-= 1;
			rc.bottom	-= 1;
		}
		else
		{
			// fill background
			rc.right	-= 1;
			rc.bottom	-= 1;
			::FillRect(hDc, &rc, bgbrush);

			// draw grid lines
			MoveToEx(hDc, rc.left , rc.top , NULL);
			LineTo  (hDc, rc.right, rc.top );
			LineTo  (hDc, rc.right, rc.bottom );
			LineTo  (hDc, rc.left , rc.bottom );
			LineTo  (hDc, rc.left , rc.top);
		}

		// draw text
		rc.left		+= 1;
		rc.top		+= HIGH_CAPTION;
		// to make ellipsis working
		rc.right	= rc.bottom - rc.top;
		rc.bottom	+= 14;

		hFont = ::CreateFont(12, 0, 90 * 10, 0,
			 FW_NORMAL, FALSE, FALSE, FALSE,
			 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
			 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
			 DEFAULT_PITCH | FF_ROMAN,
			 TEXT("MS Shell Dlg"));

		hOldFont = (HFONT)::SelectObject(hDc, hFont);
		::DrawText(hDc, _pszCaption.c_str(), length, &rc, DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX);

		// calculate text size and if its trankated...
		SIZE	size	= {0};
		GetTextExtentPoint32(hDc, _pszCaption.c_str(), length, &size);
		_bCaptionTT = (((rc.bottom - rc.top) < size.cy) ? TRUE : FALSE);

		::SelectObject(hDc, hOldFont);
		::DeleteObject(hFont);
	}
	::DeleteObject(hPen);
	::DeleteObject(bgbrush);

	// draw button
	HDC			dcMem		= ::CreateCompatibleDC(NULL);

	// select correct bitmap
	if ((_isMouseOver == TRUE) && (_isMouseDown == TRUE))
		hBmpCur = ::LoadBitmap(_hInst, MAKEINTRESOURCE(IDB_CLOSE_DOWN));
	else
		hBmpCur = ::LoadBitmap(_hInst, MAKEINTRESOURCE(IDB_CLOSE_UP));

	// blit bitmap into the destination
	::GetObject(hBmpCur, sizeof(bmp), &bmp);
	hBmpOld = (HBITMAP)::SelectObject(dcMem, hBmpCur);
	hBmpNew = ::CreateCompatibleBitmap(dcMem, bmp.bmWidth, bmp.bmHeight);

	rc = pDrawItemStruct->rcItem;
	::SelectObject(hDc, hBmpNew);

	if (_isTopCaption == TRUE)
		::BitBlt(hDc, rc.right-bmp.bmWidth-CLOSEBTN_POS_LEFT, CLOSEBTN_POS_TOP, bmp.bmWidth, bmp.bmHeight, dcMem, 0, 0, SRCCOPY);
	else
		::BitBlt(hDc, CLOSEBTN_POS_LEFT, CLOSEBTN_POS_LEFT, bmp.bmWidth, bmp.bmHeight, dcMem, 0, 0, SRCCOPY);

	::SelectObject(dcMem, hBmpOld);
	::DeleteObject(hBmpCur);
	::DeleteObject(hBmpNew);
	::DeleteDC(dcMem);

	::RestoreDC(hDc, nSavedDC);
}
Exemplo n.º 10
0
/**
 * name:	PaintThemeButton
 * desc:	Draws the none themed button
 * param:	ctl			- BTNCTRL structure for the button
 *			hdcMem		- device context to draw to
 *			rcClient	- rectangle of the whole button
 * return:	nothing
 **/
static void __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient)
{
	RECT rcText = { 0, 0, 0, 0 };
	TCHAR szText[MAX_PATH] = { 0 };
	WORD ccText;

	// Draw the flat button
	if (ctl->dwStyle & MBS_FLAT) {
		HBRUSH hbr = NULL;
		
		if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT)
			hbr = GetSysColorBrush(COLOR_3DLIGHT);
		else {
			HDC dc;
			HWND hwndParent;

			hwndParent = GetParent(ctl->hwnd);
			if (dc = GetDC(hwndParent)) {
				hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent);
				ReleaseDC(hwndParent, dc);
			}
		}
		if (hbr) {
			FillRect(hdcMem, rcClient, hbr);
			DeleteObject(hbr);
		}
		if (ctl->stateId == PBS_HOT || ctl->bFocus) {
			if (ctl->pbState) DrawEdge(hdcMem, rcClient, EDGE_ETCHED, BF_RECT|BF_SOFT);
			else DrawEdge(hdcMem, rcClient, BDR_RAISEDOUTER, BF_RECT|BF_SOFT|BF_FLAT);
		}
		else
		if (ctl->stateId == PBS_PRESSED)
			DrawEdge(hdcMem, rcClient, BDR_SUNKENOUTER, BF_RECT|BF_SOFT);
	}
	else {
		UINT uState = DFCS_BUTTONPUSH|((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0)|((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0);
		if (ctl->defbutton&&ctl->stateId==PBS_NORMAL) uState |= DLGC_DEFPUSHBUTTON;
		DrawFrameControl(hdcMem, rcClient, DFC_BUTTON, uState);
		// Draw focus rectangle if button has focus
		if (ctl->bFocus) {
			RECT focusRect = *rcClient;
			InflateRect(&focusRect, -3, -3);
			DrawFocusRect(hdcMem, &focusRect);
		}
	}
	// calculate text rect
	{
		SIZE	sizeText;
		HFONT	hOldFont;

		ccText = GetWindowText(ctl->hwnd, szText, SIZEOF(szText));

		if (ccText > 0) {
			hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
			GetTextExtentPoint32(hdcMem, szText, ccText, &sizeText);
			if (ctl->cHot) {
				SIZE sizeHot;
				
				GetTextExtentPoint32A(hdcMem, "&", 1, &sizeHot);
				sizeText.cx -= sizeHot.cx;
			}
			SelectObject(hdcMem, hOldFont);

			rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - sizeText.cx) / 2;
			rcText.top = (rcClient->bottom - rcClient->top - sizeText.cy) / 2;
			rcText.right = rcText.left + sizeText.cx;
			rcText.bottom = rcText.top + sizeText.cy;
			if (ctl->stateId == PBS_PRESSED)
				OffsetRect(&rcText, 1, 1);
		}
	}
	PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText);

	// draw text
	if (ccText > 0) { 
		HFONT hOldFont;

		hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);

		SetBkMode(hdcMem, TRANSPARENT);
		SetTextColor(hdcMem, 
			IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton 
			? ctl->stateId == PBS_HOT
					? GetSysColor(COLOR_HOTLIGHT)
					: GetSysColor(COLOR_BTNTEXT) 
				: GetSysColor(COLOR_GRAYTEXT));

		DrawState(hdcMem, NULL, NULL, (LPARAM)szText, 0, 
			rcText.left, rcText.top, rcText.right - rcText.left, rcText.bottom - rcText.top,
			IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
		SelectObject(hdcMem, hOldFont);
	}
}
Exemplo n.º 11
0
void DockingCont::SelectTab(INT iTab)
{
	if (iTab != -1)
	{
		TCHAR	*pszMaxTxt	= NULL;
		TCITEM	tcItem		= {0};
		SIZE	size		= {0};
		INT		maxWidth	= 0;
		INT		iItemCnt	= ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0);

		// get data of new active dialog
		tcItem.mask		= TCIF_PARAM;
		::SendMessage(_hContTab, TCM_GETITEM, iTab, (LPARAM)&tcItem);

		// show active dialog
		::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_SHOW);
		::SetFocus(((tTbData*)tcItem.lParam)->hClient);

		if (iTab != _prevItem)
		{
			// hide previous dialog
			::SendMessage(_hContTab, TCM_GETITEM, _prevItem, (LPARAM)&tcItem);
			::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_HIDE);
		}

		// resize tab item

		// get at first largest item ...
		HDC		hDc	= ::GetDC(_hContTab);
		SelectObject(hDc, _hFont);

		for (INT iItem = 0; iItem < iItemCnt; iItem++)
		{
			TCHAR *pszTabTxt = NULL;

			::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem);
			pszTabTxt = ((tTbData*)tcItem.lParam)->pszName;

			// get current font width
			GetTextExtentPoint32(hDc, pszTabTxt, lstrlen(pszTabTxt), &size);

			if (maxWidth < size.cx) 
			{
				maxWidth	= size.cx;
				pszMaxTxt	= pszTabTxt;
			}
		}
		::ReleaseDC(_hSelf, hDc);

		tcItem.mask	= TCIF_TEXT;
		for (INT iItem = 0; iItem < iItemCnt; iItem++)
		{
			if (iItem == iTab)
			{
				// fake here an icon before text ...
				TCHAR	szText[64];

				lstrcpy(szText, TEXT("    "));
				lstrcat(szText, pszMaxTxt);
				tcItem.pszText		= szText;
				tcItem.cchTextMax	= lstrlen(szText);
			}
			else
			{
				// ... and resize old and new item
				tcItem.pszText		= TEXT("");
				tcItem.cchTextMax	= lstrlen(TEXT(""));
			}
			::SendMessage(_hContTab, TCM_SETITEM, iItem, (LPARAM)&tcItem);
		}

		// selects the pressed tab and store previous tab
		::SendMessage(_hContTab, TCM_SETCURSEL, iTab, 0);
		_prevItem = iTab;

		// update caption text
		updateCaption();

		onSize();
	}
}
Exemplo n.º 12
0
INT_PTR CALLBACK ProgressDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	static int fontHeight, listWidth;
	static int manualAbort;
	static HFONT hBoldFont = NULL;

	INT_PTR bReturn;
	if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
		return bReturn;

	switch (message) {
	case WM_INITDIALOG:
		EnableWindow(GetDlgItem(GetParent(hdlg), IDOK), FALSE);
		hdlgProgress = hdlg;
		hwndStatus = GetDlgItem(hdlg, IDC_STATUS);
		errorCount = 0;
		bShortModeDone = false;
		hwndBar = GetDlgItem(hdlg, IDC_PROGRESS);
		SendMessage(hwndBar, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
		{
			HDC hdc;
			HFONT hFont, hoFont;
			SIZE s;
			hdc = GetDC(NULL);
			hFont = (HFONT)SendMessage(hdlg, WM_GETFONT, 0, 0);
			hoFont = (HFONT)SelectObject(hdc, hFont);
			GetTextExtentPoint32(hdc, _T("x"), 1, &s);
			SelectObject(hdc, hoFont);
			ReleaseDC(NULL, hdc);
			fontHeight = s.cy;

			RECT rc;
			GetClientRect(GetDlgItem(hdlg, IDC_STATUS), &rc);
			listWidth = rc.right;

			LOGFONT lf;
			GetObject((HFONT)SendDlgItemMessage(hdlg, IDC_STATUS, WM_GETFONT, 0, 0), sizeof(lf), &lf);
			lf.lfWeight = FW_BOLD;
			hBoldFont = CreateFontIndirect(&lf);
		}
		manualAbort = 0;
		hEventRun = CreateEvent(NULL, TRUE, TRUE, NULL);
		hEventAbort = CreateEvent(NULL, TRUE, FALSE, NULL);
		TranslateDialogDefault(hdlg);
		_beginthread(WorkerThread, 0, NULL);
		return TRUE;

	case WM_MEASUREITEM:
		{
			LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT)lParam;
			mis->itemWidth = listWidth;
			mis->itemHeight = fontHeight;
		}
		return TRUE;

	case WM_DRAWITEM:
		TCHAR str[256];
		{
			LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
			int bold = 0;
			HFONT hoFont = NULL;
			if ((int)dis->itemID == -1) break;
			SendMessage(dis->hwndItem, LB_GETTEXT, dis->itemID, (LPARAM)str);
			switch (dis->itemData & STATUS_CLASSMASK) {
			case STATUS_MESSAGE:
				SetTextColor(dis->hDC, RGB(0, 0, 0));
				break;
			case STATUS_WARNING:
				SetTextColor(dis->hDC, RGB(192, 128, 0));
				break;
			case STATUS_ERROR:
				SetTextColor(dis->hDC, RGB(192, 0, 0));
				break;
			case STATUS_FATAL:
				bold = 1;
				SetTextColor(dis->hDC, RGB(192, 0, 0));
				break;
			case STATUS_SUCCESS:
				bold = 1;
				SetTextColor(dis->hDC, RGB(0, 192, 0));
				break;
			}
			if (bold) hoFont = (HFONT)SelectObject(dis->hDC, hBoldFont);
			ExtTextOut(dis->hDC, dis->rcItem.left, dis->rcItem.top, ETO_CLIPPED | ETO_OPAQUE, &dis->rcItem, str, (UINT)mir_tstrlen(str), NULL);
			if (bold) SelectObject(dis->hDC, hoFont);
		}
		return TRUE;

	case WM_PROCESSINGDONE:
		SetProgressBar(1000);
		if (bShortMode) {
			EnableWindow(GetDlgItem(GetParent(hdlg), IDC_BACK), FALSE);
			EnableWindow(GetDlgItem(GetParent(hdlg), IDOK), FALSE);
			SetDlgItemText(GetParent(hdlg), IDCANCEL, TranslateT("&Finish"));
			bShortModeDone = true;
			if (bAutoExit)
				PostMessage(GetParent(hdlg), WM_COMMAND, IDCANCEL, 0);
		}
		else {
			AddToStatus(STATUS_SUCCESS, TranslateT("Click Next to continue"));
			EnableWindow(GetDlgItem(GetParent(hdlg), IDOK), TRUE);
		}

		if (manualAbort == 1)
			EndDialog(GetParent(hdlg), 0);
		else if (manualAbort == 2) {
			if (opts.bCheckOnly)
				PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc);
			else {
				PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_CLEANING, (LPARAM)CleaningDlgProc);
				CloseHandle(opts.hOutFile);
				opts.hOutFile = NULL;
			}
			break;
		}
		break;

	case WZN_CANCELCLICKED:
		if (bShortModeDone) {
			if (!errorCount) {
				if (bLaunchMiranda)
					CallService(MS_DB_SETDEFAULTPROFILE, (WPARAM)opts.filename, 0);
				wizardResult = 1;
			}
			return TRUE;
		}

		ResetEvent(hEventRun);
		if (IsWindowEnabled(GetDlgItem(GetParent(hdlg), IDOK)))
			break;

		if (MessageBox(hdlg, TranslateT("Processing has not yet completed, if you cancel now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to cancel?"), TranslateT("Miranda Database Tool"), MB_YESNO) == IDYES) {
			manualAbort = 1;
			SetEvent(hEventAbort);
		}
		SetEvent(hEventRun);
		SetWindowLongPtr(hdlg, DWLP_MSGRESULT, TRUE);
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_BACK:
			ResetEvent(hEventRun);
			if (!IsWindowEnabled(GetDlgItem(GetParent(hdlg), IDOK))) {
				if (MessageBox(hdlg, TranslateT("Processing has not yet completed, if you go back now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to go back?"), TranslateT("Miranda Database Tool"), MB_YESNO) == IDYES) {
					manualAbort = 2;
					SetEvent(hEventAbort);
				}
				SetEvent(hEventRun);
				break;
			}
			SetEvent(hEventRun);
			if (opts.bCheckOnly)
				PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc);
			else
				PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_CLEANING, (LPARAM)CleaningDlgProc);
			break;

		case IDOK:
			PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_FINISHED, (LPARAM)FinishedDlgProc);
			break;
		}
		break;

	case WM_DESTROY:
		if (hEventAbort) {
			CloseHandle(hEventAbort);
			hEventAbort = NULL;
		}
		if (hEventRun) {
			CloseHandle(hEventRun);
			hEventRun = NULL;
		}
		if (hBoldFont) {
			DeleteObject(hBoldFont);
			hBoldFont = NULL;
		}
		break;
	}
	return FALSE;
}
Exemplo n.º 13
0
STDMETHODIMP CShellExt::Extract(LPCTSTR /*pszFile*/, UINT /*nIconIndex*/, HICON * phiconLarge, HICON * phiconSmall, UINT nIconSize)
{
	WORD sizeSmall = HIWORD(nIconSize);
	WORD sizeLarge = LOWORD(nIconSize);
	ICONINFO iconinfo;
	HRESULT hrSmall = S_OK, hrLarge = S_OK;

	if (phiconSmall)
		hrSmall = LoadShellIcon(sizeSmall, sizeSmall, phiconSmall);
	if (phiconLarge)
		hrLarge = LoadShellIcon(sizeLarge, sizeLarge, phiconLarge);

	if (FAILED(hrSmall) || FAILED(hrLarge))
	{
		InvalidateIcon(phiconSmall, phiconLarge);
		return S_FALSE;
	}

	if (!m_isDynamic || !phiconLarge || sizeLarge < 32) //No modifications required
		return S_OK;

	BOOL res = GetIconInfo(*phiconLarge, &iconinfo);
	if (!res)
		return S_OK; //abort, the icon is still valid

	res = DestroyIcon(*phiconLarge);
	if (!res)
		return S_OK;
	else
		*phiconLarge = NULL;

	HDC dcEditColor = CreateCompatibleDC(GetDC(0));
	HDC dcEditMask = CreateCompatibleDC(GetDC(0));
	HDC dcEditTemp = CreateCompatibleDC(GetDC(0));

	// Create temp bitmap to render rectangle to
	LPDWORD pPix;
	BITMAPINFO bmi;
	ZeroMemory(&bmi, sizeof(bmi));
	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmi.bmiHeader.biWidth = sizeLarge;
	bmi.bmiHeader.biHeight = sizeLarge;
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biBitCount = 32;
	bmi.bmiHeader.biCompression = BI_RGB;
	HBITMAP hbm = CreateDIBSection(dcEditTemp, &bmi, DIB_RGB_COLORS, (VOID**)&pPix, NULL, 0);
	memset(pPix, 0x00FFFFFF, sizeof(DWORD)*sizeLarge*sizeLarge); //initialize to white pixels, no alpha

	SelectObject(dcEditColor, iconinfo.hbmColor);
	SelectObject(dcEditMask, iconinfo.hbmMask);
	SelectObject(dcEditTemp, hbm);

	LONG calSize = (LONG)(sizeLarge*2/5);

	LOGFONT lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0}};
	lf.lfHeight = calSize;
	lf.lfWeight = FW_NORMAL;
	lf.lfCharSet = DEFAULT_CHARSET;
	lstrcpyn(lf.lfFaceName, TEXT("Courier New"), LF_FACESIZE);
	RECT rectText = {0, 0, 0, 0};
	RECT rectBox = {0, 0, 0, 0};
	COLORREF backGround = RGB(1, 1, 60);
	COLORREF textColor = RGB(250,250,250);

	HFONT font = CreateFontIndirect(&lf);
	HBRUSH brush = CreateSolidBrush(backGround);
	HPEN pen = CreatePen(PS_NULL, 0, backGround);
	SelectObject(dcEditTemp, font);
	SelectObject(dcEditTemp, brush);
	SelectObject(dcEditTemp, pen);
	SetBkMode(dcEditTemp, TRANSPARENT);	//dont clear background when drawing text
	SetBkColor(dcEditTemp,  backGround);
	SetTextColor(dcEditTemp, textColor);

	//Calculate size of the displayed string
	SIZE stringSize;
	GetTextExtentPoint32(dcEditTemp, m_szFilePath, m_nameLength, &stringSize);
	stringSize.cx = std::min(stringSize.cx, (LONG)sizeLarge-2);
	stringSize.cy = std::min(stringSize.cy, (LONG)sizeLarge-2);

	rectText.top = sizeLarge - stringSize.cy - 1;
	rectText.left = sizeLarge - stringSize.cx - 1;
	rectText.bottom = sizeLarge - 1;
	rectText.right = sizeLarge - 1;

	rectBox.top = sizeLarge - stringSize.cy - 2;
	rectBox.left = sizeLarge - stringSize.cx - 2;
	rectBox.bottom = sizeLarge;
	rectBox.right = sizeLarge;

	//Draw the background (rounded) rectangle
	int elipsSize = calSize/3;
	RoundRect(dcEditTemp, rectBox.left, rectBox.top, rectBox.right, rectBox.bottom, elipsSize, elipsSize);
	//Draw text in the rectangle
	DrawText(dcEditTemp, m_szFilePath, m_nameLength, &rectText, DT_BOTTOM|DT_SINGLELINE|DT_LEFT);

	//set alpha of non white pixels back to 255
	//premultiply alpha
	//Fill in the mask bitmap (anything not 100% alpha is transparent)
	int red, green, blue, alpha;
	for(int y = 0; y < sizeLarge; y++)
	{
		for(int x = 0; x < sizeLarge; x++)
		{
			DWORD * pix = pPix+(y*sizeLarge+x);
			red = *pix & 0xFF;
			green = *pix >> 8 & 0xFF;
			blue = *pix >> 16 & 0xFF;
			alpha = *pix >> 24 & 0xFF;
			if ((*pix << 8) == 0xFFFFFF00)
				alpha = 0x00;
			else
				alpha = 0xFF;
			red = (red*alpha)/0xFF;
			green = (green*alpha)/0xFF;
			blue = (blue*alpha)/0xFF;
			*pix = RGBA(red, green, blue, alpha);
		}
	}

	BLENDFUNCTION ftn = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA };
	int width = rectBox.right - rectBox.left;
	int height = rectBox.bottom - rectBox.top;
	AlphaBlend(dcEditColor, rectBox.left, rectBox.top, stringSize.cx, stringSize.cy, dcEditTemp, rectBox.left, rectBox.top, width, height, ftn);

	//Adjust the mask image: simply draw the rectangle to it
	backGround = RGB(0, 0, 0);
	DeleteBrush(brush);
	DeletePen(pen);
	brush = CreateSolidBrush(backGround);
	pen = CreatePen(PS_NULL, 0, backGround);
	SelectObject(dcEditMask, brush);
	SelectObject(dcEditMask, pen);
	RoundRect(dcEditMask, rectBox.left, rectBox.top, rectBox.right, rectBox.bottom, elipsSize, elipsSize);


	DeleteDC(dcEditColor);
	DeleteDC(dcEditMask);
	DeleteDC(dcEditTemp);
	DeleteBrush(brush);
	DeletePen(pen);
	DeleteFont(font);
	DeleteBitmap(hbm);

	*phiconLarge = CreateIconIndirect(&iconinfo);
	DeleteBitmap(iconinfo.hbmColor);
	DeleteBitmap(iconinfo.hbmMask);

	if (*phiconLarge == NULL)
	{
		InvalidateIcon(phiconSmall, phiconLarge);
		return S_FALSE;
	}

	return S_OK;
}
Exemplo n.º 14
0
VOID StatusBarUpdate(
    _In_ BOOLEAN ResetMaxWidths
    )
{
    static ULONG64 lastTickCount = 0;

    ULONG count;
    ULONG i;
    HDC hdc;
    BOOLEAN resetMaxWidths = FALSE;
    PPH_STRING text[MAX_STATUSBAR_ITEMS];
    ULONG widths[MAX_STATUSBAR_ITEMS];

    if (ResetMaxWidths)
        resetMaxWidths = TRUE;

    // TODO: Review
    if (!StatusBarItemList || StatusBarItemList->Count == 0)
    {
        // The status bar doesn't cope well with 0 parts.
        widths[0] = -1;
        SendMessage(StatusBarHandle, SB_SETPARTS, 1, (LPARAM)widths);
        SendMessage(StatusBarHandle, SB_SETTEXT, 0, (LPARAM)L"");
        return;
    }

    hdc = GetDC(StatusBarHandle);
    SelectObject(hdc, (HFONT)SendMessage(StatusBarHandle, WM_GETFONT, 0, 0));

    // Reset max. widths for Max. CPU Process and Max. I/O Process parts once in a while.
    {
        LARGE_INTEGER tickCount;

        PhQuerySystemTime(&tickCount);

        if (tickCount.QuadPart - lastTickCount >= 10 * PH_TICKS_PER_SEC)
        {
            resetMaxWidths = TRUE;
            lastTickCount = tickCount.QuadPart;
        }
    }

    count = 0;

    for (i = 0; i < StatusBarItemList->Count; i++)
    {
        SIZE size;
        ULONG width;
        PSTATUSBAR_ITEM statusItem;

        statusItem = StatusBarItemList->Items[i];

        switch (statusItem->Id)
        {
        case ID_STATUS_CPUUSAGE:
            {
                text[count] = PhFormatString(
                    L"CPU Usage: %.2f%%",
                    (SystemStatistics.CpuKernelUsage + SystemStatistics.CpuUserUsage) * 100
                    );
            }
            break;
        case ID_STATUS_COMMITCHARGE:
            {
                ULONG commitUsage = SystemStatistics.Performance->CommittedPages;
                FLOAT commitFraction = (FLOAT)commitUsage / SystemStatistics.Performance->CommitLimit * 100;

                text[count] = PhFormatString(
                    L"Commit Charge: %s (%.2f%%)",
                    PhaFormatSize(UInt32x32To64(commitUsage, PAGE_SIZE), -1)->Buffer,
                    commitFraction
                    );
            }
            break;
        case ID_STATUS_PHYSICALMEMORY:
            {
                ULONG physicalUsage = PhSystemBasicInformation.NumberOfPhysicalPages - SystemStatistics.Performance->AvailablePages;
                FLOAT physicalFraction = (FLOAT)physicalUsage / PhSystemBasicInformation.NumberOfPhysicalPages * 100;

                text[count] = PhFormatString(
                    L"Physical Memory: %s (%.2f%%)",
                    PhaFormatSize(UInt32x32To64(physicalUsage, PAGE_SIZE), -1)->Buffer,
                    physicalFraction
                    );
            }
            break;
        case ID_STATUS_FREEMEMORY:
            {
                ULONG physicalFree = SystemStatistics.Performance->AvailablePages;
                FLOAT physicalFreeFraction = (FLOAT)physicalFree / PhSystemBasicInformation.NumberOfPhysicalPages * 100;

                text[count] = PhFormatString(
                    L"Free Memory: %s (%.2f%%)",
                    PhaFormatSize(UInt32x32To64(physicalFree, PAGE_SIZE), -1)->Buffer,
                    physicalFreeFraction
                    );
            }
            break;
        case ID_STATUS_NUMBEROFPROCESSES:
            {
                text[count] = PhConcatStrings2(
                    L"Processes: ",
                    PhaFormatUInt64(SystemStatistics.NumberOfProcesses, TRUE)->Buffer
                    );
            }
            break;
        case ID_STATUS_NUMBEROFTHREADS:
            {
                text[count] = PhConcatStrings2(
                    L"Threads: ",
                    PhaFormatUInt64(SystemStatistics.NumberOfThreads, TRUE)->Buffer
                    );
            }
            break;
        case ID_STATUS_NUMBEROFHANDLES:
            {
                text[count] = PhConcatStrings2(
                    L"Handles: ",
                    PhaFormatUInt64(SystemStatistics.NumberOfHandles, TRUE)->Buffer
                    );
            }
            break;
        case ID_STATUS_IO_RO:
            {
                text[count] = PhConcatStrings2(
                    L"I/O R+O: ",
                    PhaFormatSize(SystemStatistics.IoReadDelta.Delta + SystemStatistics.IoOtherDelta.Delta, -1)->Buffer
                    );
            }
            break;
        case ID_STATUS_IO_W:
            {
                text[count] = PhConcatStrings2(
                    L"I/O W: ",
                    PhaFormatSize(SystemStatistics.IoWriteDelta.Delta, -1)->Buffer
                    );
            }
            break;
        case ID_STATUS_MAX_CPU_PROCESS:
            {
                PPH_PROCESS_ITEM processItem;

                if (SystemStatistics.MaxCpuProcessId && (processItem = PhReferenceProcessItem(SystemStatistics.MaxCpuProcessId)))
                {
                    if (!PH_IS_FAKE_PROCESS_ID(processItem->ProcessId))
                    {
                        text[count] = PhFormatString(
                            L"%s (%lu): %.2f%%",
                            processItem->ProcessName->Buffer,
                            HandleToUlong(processItem->ProcessId),
                            processItem->CpuUsage * 100
                            );
                    }
                    else
                    {
                        text[count] = PhFormatString(
                            L"%s: %.2f%%",
                            processItem->ProcessName->Buffer,
                            processItem->CpuUsage * 100
                            );
                    }

                    PhDereferenceObject(processItem);
                }
                else
                {
                    text[count] = PhCreateString(L"-");
                }
            }
            break;
        case ID_STATUS_MAX_IO_PROCESS:
            {
                PPH_PROCESS_ITEM processItem;

                if (SystemStatistics.MaxIoProcessId && (processItem = PhReferenceProcessItem(SystemStatistics.MaxIoProcessId)))
                {
                    if (!PH_IS_FAKE_PROCESS_ID(processItem->ProcessId))
                    {
                        text[count] = PhFormatString(
                            L"%s (%lu): %s",
                            processItem->ProcessName->Buffer,
                            HandleToUlong(processItem->ProcessId),
                            PhaFormatSize(processItem->IoReadDelta.Delta + processItem->IoWriteDelta.Delta + processItem->IoOtherDelta.Delta, -1)->Buffer
                            );
                    }
                    else
                    {
                        text[count] = PhFormatString(
                            L"%s: %s",
                            processItem->ProcessName->Buffer,
                            PhaFormatSize(processItem->IoReadDelta.Delta + processItem->IoWriteDelta.Delta + processItem->IoOtherDelta.Delta, -1)->Buffer
                            );
                    }

                    PhDereferenceObject(processItem);
                }
                else
                {
                    text[count] = PhCreateString(L"-");
                }
            }
            break;
        case ID_STATUS_NUMBEROFVISIBLEITEMS:
            {
                HWND tnHandle = NULL;

                tnHandle = GetCurrentTreeNewHandle();

                if (tnHandle)
                {
                    ULONG visibleCount = 0;

                    visibleCount = TreeNew_GetFlatNodeCount(tnHandle);

                    text[count] = PhFormatString(
                        L"Visible: %lu",
                        visibleCount
                        );
                }
                else
                {
                    text[count] = PhCreateString(
                        L"Visible: N/A"
                        );
                }
            }
            break;
        case ID_STATUS_NUMBEROFSELECTEDITEMS:
            {
                HWND tnHandle = NULL;

                tnHandle = GetCurrentTreeNewHandle();

                if (tnHandle)
                {
                    ULONG visibleCount = 0;
                    ULONG selectedCount = 0;

                    visibleCount = TreeNew_GetFlatNodeCount(tnHandle);

                    for (ULONG i = 0; i < visibleCount; i++)
                    {
                        if (TreeNew_GetFlatNode(tnHandle, i)->Selected)
                            selectedCount++;
                    }

                    text[count] = PhFormatString(
                        L"Selected: %lu",
                        selectedCount
                        );
                }
                else
                {
                    text[count] = PhCreateString(
                        L"Selected: N/A"
                        );
                }
            }
            break;
        case ID_STATUS_INTERVALSTATUS:
            {
                ULONG interval;

                interval = PhGetIntegerSetting(L"UpdateInterval");

                if (UpdateAutomatically)
                {
                    switch (interval)
                    {
                    case 500:
                        text[count] = PhCreateString(L"Interval: Fast");
                        break;
                    case 1000:
                        text[count] = PhCreateString(L"Interval: Normal");
                        break;
                    case 2000:
                        text[count] = PhCreateString(L"Interval: Below Normal");
                        break;
                    case 5000:
                        text[count] = PhCreateString(L"Interval: Slow");
                        break;
                    case 10000:
                        text[count] = PhCreateString(L"Interval: Very Slow");
                        break;
                    }
                }
                else
                {
                    text[count] = PhCreateString(L"Interval: Paused");
                }
            }
            break;
        }

        if (resetMaxWidths)
            StatusBarMaxWidths[count] = 0;

        if (!GetTextExtentPoint32(hdc, text[count]->Buffer, (ULONG)text[count]->Length / sizeof(WCHAR), &size))
            size.cx = 200;

        if (count != 0)
            widths[count] = widths[count - 1];
        else
            widths[count] = 0;

        width = size.cx + 10;

        if (width <= StatusBarMaxWidths[count])
        {
            width = StatusBarMaxWidths[count];
        }
        else
        {
            StatusBarMaxWidths[count] = width;
        }

        widths[count] += width;

        count++;
    }

    ReleaseDC(StatusBarHandle, hdc);

    SendMessage(StatusBarHandle, SB_SETPARTS, count, (LPARAM)widths);

    for (i = 0; i < count; i++)
    {
        SendMessage(StatusBarHandle, SB_SETTEXT, i, (LPARAM)text[i]->Buffer);
        PhDereferenceObject(text[i]);
    }
}
Exemplo n.º 15
0
VOID CDXCtrlTreeview::DrawText()
{
	TEXTMETRIC tm;
	LPD3DXFONT pFont;
	RECT rect, irect;
	PLISTITEM pItem;
	D3DCOLOR Color;
	DWORD dwIndex;
	DWORD dwIndexTextSize;
	SIZE size;
	char szBuff[8];
	if(m_pManager)
	{

		GetRect(&rect);
		pFont = m_pManager->GetFixedWidthFont();
		pFont->GetTextMetrics(&tm);
		
		GetTextExtentPoint32(pFont->GetDC(), "999", 3, &size);
		
		if(m_bShowIndex)
			dwIndexTextSize = size.cx;
		else
			dwIndexTextSize = 0;

		pItem = m_pList;
		for(dwIndex = 0; dwIndex < m_dwTopIndex; dwIndex++)
			pItem = pItem->link;
		rect.left += (5 * m_dwFrameWidth / 8) + tm.tmHeight;
		rect.top += (5 * m_dwFrameWidth / 8);
		rect.bottom -= (5 * m_dwFrameWidth / 8);
		rect.right -= ((5 * m_dwFrameWidth / 8) + 16 + dwIndexTextSize);
		for(; rect.top <= rect.bottom - tm.tmHeight && pItem; dwIndex++)
		{
			if(pItem->bGroup || pItem->bVisible)
			{
				if(dwIndex == m_dwSelectedIndex)
				{
					Color = m_SelectedColor;
				}
				else
				{
					if(pItem->bGroup)
						Color = m_GroupColor;
					else
						Color = m_ItemColor;
				}
				pFont->DrawTextA(m_pManager->GetFontSprite(), pItem->szText, -1, &rect, DT_TOP | DT_LEFT, Color);
				if(m_bShowIndex && pItem->bGroup == FALSE)
				{
					irect = rect;
					irect.left = irect.right;
					irect.right = irect.left + dwIndexTextSize;
					pFont->DrawTextA(m_pManager->GetFontSprite(), itoa(dwIndex, szBuff, 10), -1, &irect, DT_TOP | DT_RIGHT, Color);
				}
				rect.top += tm.tmHeight;
			}
			pItem = pItem->link;
		}
	}
}
Exemplo n.º 16
0
static void UpdateAboutLayoutInfo(HWND hwnd, HDC hdc, RectI *rect)
{
    ScopedFont fontLeftTxt(GetSimpleFont(hdc, LEFT_TXT_FONT, LEFT_TXT_FONT_SIZE));
    ScopedFont fontRightTxt(GetSimpleFont(hdc, RIGHT_TXT_FONT, RIGHT_TXT_FONT_SIZE));

    HGDIOBJ origFont = SelectObject(hdc, fontLeftTxt);

    /* calculate minimal top box size */
    SizeI headerSize = CalcSumatraVersionSize(hdc);

    /* calculate left text dimensions */
    SelectObject(hdc, fontLeftTxt);
    int leftLargestDx = 0;
    int leftDy = 0;
    for (AboutLayoutInfoEl *el = gAboutLayoutInfo; el->leftTxt; el++) {
        SIZE txtSize;
        GetTextExtentPoint32(hdc, el->leftTxt, (int)str::Len(el->leftTxt), &txtSize);
        el->leftPos.dx = txtSize.cx;
        el->leftPos.dy = txtSize.cy;

        if (el == &gAboutLayoutInfo[0])
            leftDy = el->leftPos.dy;
        else
            assert(leftDy == el->leftPos.dy);
        if (leftLargestDx < el->leftPos.dx)
            leftLargestDx = el->leftPos.dx;
    }

    /* calculate right text dimensions */
    SelectObject(hdc, fontRightTxt);
    int rightLargestDx = 0;
    int rightDy = 0;
    for (AboutLayoutInfoEl *el = gAboutLayoutInfo; el->leftTxt; el++) {
        SIZE txtSize;
        GetTextExtentPoint32(hdc, el->rightTxt, (int)str::Len(el->rightTxt), &txtSize);
        el->rightPos.dx = txtSize.cx;
        el->rightPos.dy = txtSize.cy;

        if (el == &gAboutLayoutInfo[0])
            rightDy = el->rightPos.dy;
        else
            assert(rightDy == el->rightPos.dy);
        if (rightLargestDx < el->rightPos.dx)
            rightLargestDx = el->rightPos.dx;
    }

    /* calculate total dimension and position */
    RectI minRect;
    minRect.dx = ABOUT_LEFT_RIGHT_SPACE_DX + leftLargestDx + ABOUT_LINE_SEP_SIZE + rightLargestDx + ABOUT_LEFT_RIGHT_SPACE_DX;
    if (minRect.dx < headerSize.dx)
        minRect.dx = headerSize.dx;
    minRect.dx += 2 * ABOUT_LINE_OUTER_SIZE + 2 * ABOUT_MARGIN_DX;

    minRect.dy = headerSize.dy;
    for (AboutLayoutInfoEl *el = gAboutLayoutInfo; el->leftTxt; el++)
        minRect.dy += rightDy + ABOUT_TXT_DY;
    minRect.dy += 2 * ABOUT_LINE_OUTER_SIZE + 4;

    ClientRect rc(hwnd);
    minRect.x = (rc.dx - minRect.dx) / 2;
    minRect.y = (rc.dy - minRect.dy) / 2;

    if (rect)
        *rect = minRect;

    /* calculate text positions */
    int linePosX = ABOUT_LINE_OUTER_SIZE + ABOUT_MARGIN_DX + leftLargestDx + ABOUT_LEFT_RIGHT_SPACE_DX;
    int currY = minRect.y + headerSize.dy + 4;
    for (AboutLayoutInfoEl *el = gAboutLayoutInfo; el->leftTxt; el++) {
        el->leftPos.x = minRect.x + linePosX - ABOUT_LEFT_RIGHT_SPACE_DX - el->leftPos.dx;
        el->leftPos.y = currY + (rightDy - leftDy) / 2;
        el->rightPos.x = minRect.x + linePosX + ABOUT_LEFT_RIGHT_SPACE_DX;
        el->rightPos.y = currY;
        currY += rightDy + ABOUT_TXT_DY;
    }

    SelectObject(hdc, origFont);
}
Exemplo n.º 17
0
/**
 * Below CheckMessageBoxProc adds everyones favorite "don't show again" checkbox to the dialog
 * much of the layout code (especially for XP and older windows versions) is copied with changes
 * from a GPL'ed project emabox at SourceForge.
 **/
LRESULT CALLBACK CheckMessageBoxProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_COMMAND:
		{
			if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == 2025)
			{
				const LRESULT res = SendMessage((HWND)lParam, BM_GETSTATE, 0, 0);
				bool bCheckedAfter = ((res & BST_CHECKED) == 0);
				
				// Update usedata
				ExMessageBox::SetUserData((void*)(bCheckedAfter ? BST_CHECKED : BST_UNCHECKED));
				
				SendMessage((HWND)lParam, BM_SETCHECK, bCheckedAfter ? BST_CHECKED : BST_UNCHECKED, 0);
			}
		}
		break;
		case WM_ERASEBKGND:
		{
			// Vista+ has grey strip
			if (WinUtil::getOsMajor() >= 6)
			{
				RECT rc = {0};
				HDC dc = (HDC)wParam;
				
				// Fill the entire dialog
				GetClientRect(hWnd, &rc);
				FillRect(dc, &rc, GetSysColorBrush(COLOR_WINDOW));
				
				// Calculate strip height
				RECT rcButton = {0};
				GetWindowRect(FindWindowEx(hWnd, NULL, L"BUTTON", NULL), &rcButton);
				int stripHeight = (rcButton.bottom - rcButton.top) + 24;
				
				// Fill the strip
				rc.top += (rc.bottom - rc.top) - stripHeight;
				FillRect(dc, &rc, GetSysColorBrush(COLOR_3DFACE));
				
				// Make a line
				HGDIOBJ oldPen = SelectObject(dc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DLIGHT)));
				MoveToEx(dc, rc.left - 1, rc.top, (LPPOINT)NULL);
				LineTo(dc, rc.right, rc.top);
				DeleteObject(SelectObject(dc, oldPen));
				return S_OK;
			}
		}
		break;
		case WM_CTLCOLORSTATIC:
		{
			// Vista+ has grey strip
			if ((WinUtil::getOsMajor() >= 6) && ((HWND)lParam == GetDlgItem(hWnd, 2025)))
			{
				HDC hdc = (HDC)wParam;
				SetBkMode(hdc, TRANSPARENT);
				return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
			}
		}
		break;
		case WM_INITDIALOG:
		{
			RECT rc = {0};
			HWND current = NULL;
			int iWindowWidthBefore;
			int iWindowHeightBefore;
			int iClientHeightBefore;
			int iClientWidthBefore;
			
			pair<LPCTSTR, UINT> checkdata = (*(pair<LPCTSTR, UINT>*)ExMessageBox::GetUserData());
			
			GetClientRect(hWnd, &rc);
			iClientHeightBefore = rc.bottom - rc.top;
			iClientWidthBefore = rc.right - rc.left;
			
			GetWindowRect(hWnd, &rc);
			iWindowWidthBefore = rc.right - rc.left;
			iWindowHeightBefore = rc.bottom - rc.top;
			
			// Create checkbox (resized and moved later)
			HWND check = CreateWindow(L"BUTTON", checkdata.first, WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_VCENTER | BS_CHECKBOX,
			                          CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			                          hWnd, (HMENU)2025, GetModuleHandle(NULL), NULL
			                         );
			                         
			// Assume checked by default
			SendMessage(check, BM_SETCHECK, checkdata.second, 0);
			ExMessageBox::SetUserData((void*)checkdata.second); 
			
			// Apply default font
			const int cyMenuSize = GetSystemMetrics(SM_CYMENUSIZE);
			const int cxMenuSize = GetSystemMetrics(SM_CXMENUSIZE);
			const HFONT hNewFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
			HFONT hOldFont;
			SIZE size;
			
			SendMessage(check, WM_SETFONT, (WPARAM)hNewFont, (LPARAM)TRUE);
			
			// Get the size of the checkbox
			HDC hdc = GetDC(check);
			hOldFont = (HFONT)SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));
			GetTextExtentPoint32(hdc, checkdata.first, wcslen(checkdata.first), &size);
			SelectObject(hdc, hOldFont);
			ReleaseDC(check, hdc);
			
			// Checkbox dimensions
			int iCheckboxWidth = cxMenuSize + size.cx + 1;
			int iCheckboxHeight = (cyMenuSize > size.cy) ? cyMenuSize : size.cy;
			
			// Vista+ has a different kind of layout altogether
			if (WinUtil::getOsMajor() >= 6)
			{
				// Align checkbox with buttons (aproximately)
				int iCheckboxTop = int(iClientHeightBefore - (iCheckboxHeight * 1.70));
				MoveWindow(check, 5, iCheckboxTop, iCheckboxWidth, iCheckboxHeight, FALSE);
				
				// Resize and re-center dialog
				int iWindowWidthAfter = iWindowWidthBefore + iCheckboxWidth;
				int iWindowLeftAfter = rc.left + (iWindowWidthBefore - iWindowWidthAfter) / 2;
				MoveWindow(hWnd, iWindowLeftAfter, rc.top, iWindowWidthAfter, iWindowHeightBefore, TRUE);
				
				// Go through the buttons and move them
				while ((current = FindWindowEx(hWnd, current, L"BUTTON", NULL)) != NULL)
				{
					if (current == check) continue;
					
					RECT rc;
					GetWindowRect(current, &rc);
					ScreenToClient(hWnd, &rc);
					MoveWindow(current, rc.left + iCheckboxWidth, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE);
				}
			}
			else
			{
				RECT rt = {0}, rb = {0};
				
				// Let's find us the label
				while ((current = FindWindowEx(hWnd, current, L"STATIC", NULL)) != NULL)
				{
					if (GetWindowTextLength(current) > 0)
					{
						GetWindowRect(current, &rt);
						ScreenToClient(hWnd, &rt);
						current = NULL;
						break;
					}
				}
				
				// For correcting width, here just to make lines shorter
				int iWidthAdjustment = (rt.left + iCheckboxWidth) - iWindowWidthBefore;
				
				// Go through the buttons and move them
				current = NULL;
				while ((current = FindWindowEx(hWnd, current, L"BUTTON", NULL)) != NULL)
				{
					if (current == check) continue;
					
					GetWindowRect(current, &rb);
					ScreenToClient(hWnd, &rb);
					MoveWindow(current, rb.left + (iWidthAdjustment > 0 ? (iWidthAdjustment + 15) / 2 : 0), rb.top + iCheckboxHeight, rb.right - rb.left, rb.bottom - rb.top, FALSE);
				}
				
				// Move the checkbox
				int iCheckboxTop = rt.top + (rt.bottom - rt.top) + ((rb.top - rt.bottom) / 2);
				MoveWindow(check, rt.left, iCheckboxTop, iCheckboxWidth, iCheckboxHeight, FALSE);
				
				// Resize and re-center dialog
				int iWindowHeightAfter = iWindowHeightBefore + iCheckboxHeight;
				int iWindowTopAfter = rc.top + (iWindowHeightBefore - iWindowHeightAfter) / 2;
				int iWindowWidthAfter = (iWidthAdjustment > 0) ? iWindowWidthBefore + iWidthAdjustment + 15 : iWindowWidthBefore;
				int iWindowLeftAfter = rc.left + (iWindowWidthBefore - iWindowWidthAfter) / 2;
				MoveWindow(hWnd, iWindowLeftAfter, iWindowTopAfter, iWindowWidthAfter, iWindowHeightAfter, TRUE);
			}
		}
		break;
	}
	
	return CallWindowProc(ExMessageBox::GetMessageBoxProc(), hWnd, uMsg, wParam, lParam);
}
Exemplo n.º 18
0
void DrawStartPage(WindowInfo& win, HDC hdc, FileHistory& fileHistory, COLORREF colorRange[2])
{
    HPEN penBorder = CreatePen(PS_SOLID, DOCLIST_SEPARATOR_DY, WIN_COL_BLACK);
    HPEN penThumbBorder = CreatePen(PS_SOLID, DOCLIST_THUMBNAIL_BORDER_W, WIN_COL_BLACK);
    HPEN penLinkLine = CreatePen(PS_SOLID, 1, COL_BLUE_LINK);

    ScopedFont fontSumatraTxt(GetSimpleFont(hdc, L"MS Shell Dlg", 24));
    ScopedFont fontLeftTxt(GetSimpleFont(hdc, L"MS Shell Dlg", 14));

    HGDIOBJ origFont = SelectObject(hdc, fontSumatraTxt); /* Just to remember the orig font */

    ClientRect rc(win.hwndCanvas);
    FillRect(hdc, &rc.ToRECT(), gBrushLogoBg);

    SelectObject(hdc, gBrushLogoBg);
    SelectObject(hdc, penBorder);

    bool isRtl = IsUIRightToLeft();

    /* render title */
    RectI titleBox = RectI(PointI(0, 0), CalcSumatraVersionSize(hdc));
    titleBox.x = rc.dx - titleBox.dx - 3;
    DrawSumatraVersion(hdc, titleBox);
    PaintLine(hdc, RectI(0, titleBox.dy, rc.dx, 0));

    /* render recent files list */
    SelectObject(hdc, penThumbBorder);
    SetBkMode(hdc, TRANSPARENT);
    SetTextColor(hdc, WIN_COL_BLACK);

    rc.y += titleBox.dy;
    rc.dy -= titleBox.dy;
    FillRect(hdc, &rc.ToRECT(), gBrushAboutBg);
    rc.dy -= DOCLIST_BOTTOM_BOX_DY;

    Vec<DisplayState *> list;
    fileHistory.GetFrequencyOrder(list);

    int width = limitValue((rc.dx - DOCLIST_MARGIN_LEFT - DOCLIST_MARGIN_RIGHT + DOCLIST_MARGIN_BETWEEN_X) / (THUMBNAIL_DX + DOCLIST_MARGIN_BETWEEN_X), 1, DOCLIST_MAX_THUMBNAILS_X);
    int height = min((rc.dy - DOCLIST_MARGIN_TOP - DOCLIST_MARGIN_BOTTOM + DOCLIST_MARGIN_BETWEEN_Y) / (THUMBNAIL_DY + DOCLIST_MARGIN_BETWEEN_Y), FILE_HISTORY_MAX_FREQUENT / width);
    PointI offset(rc.x + DOCLIST_MARGIN_LEFT + (rc.dx - width * THUMBNAIL_DX - (width - 1) * DOCLIST_MARGIN_BETWEEN_X - DOCLIST_MARGIN_LEFT - DOCLIST_MARGIN_RIGHT) / 2, rc.y + DOCLIST_MARGIN_TOP);
    if (offset.x < ABOUT_INNER_PADDING)
        offset.x = ABOUT_INNER_PADDING;
    else if (list.Count() == 0)
        offset.x = DOCLIST_MARGIN_LEFT;

    SelectObject(hdc, fontSumatraTxt);
    SIZE txtSize;
    const WCHAR *txt = _TR("Frequently Read");
    GetTextExtentPoint32(hdc, txt, (int)str::Len(txt), &txtSize);
    RectI headerRect(offset.x, rc.y + (DOCLIST_MARGIN_TOP - txtSize.cy) / 2, txtSize.cx, txtSize.cy);
    if (isRtl)
        headerRect.x = rc.dx - offset.x - headerRect.dx;
    DrawText(hdc, txt, -1, &headerRect.ToRECT(), (isRtl ? DT_RTLREADING : DT_LEFT) | DT_NOPREFIX);

    SelectObject(hdc, fontLeftTxt);
    SelectObject(hdc, GetStockBrush(NULL_BRUSH));

    win.staticLinks.Reset();
    for (int h = 0; h < height; h++) {
        for (int w = 0; w < width; w++) {
            if (h * width + w >= (int)list.Count()) {
                // display the "Open a document" link right below the last row
                height = w > 0 ? h + 1 : h;
                break;
            }
            DisplayState *state = list.At(h * width + w);

            RectI page(offset.x + w * (int)(THUMBNAIL_DX + DOCLIST_MARGIN_BETWEEN_X * win.uiDPIFactor),
                       offset.y + h * (int)(THUMBNAIL_DY + DOCLIST_MARGIN_BETWEEN_Y * win.uiDPIFactor),
                       THUMBNAIL_DX, THUMBNAIL_DY);
            if (isRtl)
                page.x = rc.dx - page.x - page.dx;
            bool loadOk = true;
            if (!state->thumbnail)
                loadOk = LoadThumbnail(*state);
            if (loadOk && state->thumbnail) {
                SizeI thumbSize = state->thumbnail->Size();
                if (thumbSize.dx != THUMBNAIL_DX || thumbSize.dy != THUMBNAIL_DY) {
                    page.dy = thumbSize.dy * THUMBNAIL_DX / thumbSize.dx;
                    page.y += THUMBNAIL_DY - page.dy;
                }
                HRGN clip = CreateRoundRectRgn(page.x, page.y, page.x + page.dx, page.y + page.dy, 10, 10);
                SelectClipRgn(hdc, clip);
                RenderedBitmap *clone = state->thumbnail->Clone();
                UpdateBitmapColorRange(clone->GetBitmap(), colorRange);
                clone->StretchDIBits(hdc, page);
                SelectClipRgn(hdc, NULL);
                DeleteObject(clip);
                delete clone;
            }
            RoundRect(hdc, page.x, page.y, page.x + page.dx, page.y + page.dy, 10, 10);

            int iconSpace = (int)(20 * win.uiDPIFactor);
            RectI rect(page.x + iconSpace, page.y + page.dy + 3, page.dx - iconSpace, iconSpace);
            if (isRtl)
                rect.x -= iconSpace;
            DrawText(hdc, path::GetBaseName(state->filePath), -1, &rect.ToRECT(), DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX | (isRtl ? DT_RIGHT : DT_LEFT));

            SHFILEINFO sfi;
            HIMAGELIST himl = (HIMAGELIST)SHGetFileInfo(state->filePath, 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
            ImageList_Draw(himl, sfi.iIcon, hdc,
                           isRtl ? page.x + page.dx - (int)(16 * win.uiDPIFactor) : page.x,
                           rect.y, ILD_TRANSPARENT);

            win.staticLinks.Append(StaticLinkInfo(rect.Union(page), state->filePath, state->filePath));
        }
    }

    /* render bottom links */
    rc.y += DOCLIST_MARGIN_TOP + height * THUMBNAIL_DY + (height - 1) * DOCLIST_MARGIN_BETWEEN_Y + DOCLIST_MARGIN_BOTTOM;
    rc.dy = DOCLIST_BOTTOM_BOX_DY;

    SetTextColor(hdc, COL_BLUE_LINK);
    SelectObject(hdc, penLinkLine);

    HIMAGELIST himl = (HIMAGELIST)SendMessage(win.hwndToolbar, TB_GETIMAGELIST, 0, 0);
    RectI rectIcon(offset.x, rc.y, 0, 0);
    ImageList_GetIconSize(himl, &rectIcon.dx, &rectIcon.dy);
    rectIcon.y += (rc.dy - rectIcon.dy) / 2;
    if (isRtl)
        rectIcon.x = rc.dx - offset.x - rectIcon.dx;
    ImageList_Draw(himl, 0 /* index of Open icon */, hdc, rectIcon.x, rectIcon.y, ILD_NORMAL);

    txt = _TR("Open a document...");
    GetTextExtentPoint32(hdc, txt, (int)str::Len(txt), &txtSize);
    RectI rect(offset.x + rectIcon.dx + 3, rc.y + (rc.dy - txtSize.cy) / 2, txtSize.cx, txtSize.cy);
    if (isRtl)
        rect.x = rectIcon.x - rect.dx - 3;
    DrawText(hdc, txt, -1, &rect.ToRECT(), isRtl ? DT_RTLREADING : DT_LEFT);
    PaintLine(hdc, RectI(rect.x, rect.y + rect.dy, rect.dx, 0));
    // make the click target larger
    rect = rect.Union(rectIcon);
    rect.Inflate(10, 10);
    win.staticLinks.Append(StaticLinkInfo(rect, SLINK_OPEN_FILE));

    rect = DrawBottomRightLink(win.hwndCanvas, hdc, _TR("Hide frequently read"));
    win.staticLinks.Append(StaticLinkInfo(rect, SLINK_LIST_HIDE));

    SelectObject(hdc, origFont);

    DeleteObject(penBorder);
    DeleteObject(penThumbBorder);
    DeleteObject(penLinkLine);
}
Exemplo n.º 19
0
/*
** This is cribbed from FX/fxwgl.c, and seems to implement support
** for bitmap fonts where the wglUseFontBitmapsA() code implements
** support for outline fonts.  In combination they hopefully give
** fairly generic support for fonts.
*/
static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar,
                                 DWORD numChars, DWORD listBase)
{
#define VERIFY(a) a

    TEXTMETRIC metric;
    BITMAPINFO *dibInfo;
    HDC bitDevice;
    COLORREF tempColor;
    int i;

    VERIFY(GetTextMetrics(fontDevice, &metric));

    dibInfo = (BITMAPINFO *) calloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1);
    dibInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    dibInfo->bmiHeader.biPlanes = 1;
    dibInfo->bmiHeader.biBitCount = 1;
    dibInfo->bmiHeader.biCompression = BI_RGB;

    bitDevice = CreateCompatibleDC(fontDevice);

    /* Swap fore and back colors so the bitmap has the right polarity */
    tempColor = GetBkColor(bitDevice);
    SetBkColor(bitDevice, GetTextColor(bitDevice));
    SetTextColor(bitDevice, tempColor);

    /* Place chars based on base line */
    VERIFY(SetTextAlign(bitDevice, TA_BASELINE) != GDI_ERROR ? 1 : 0);

    for(i = 0; i < (int)numChars; i++) {
        SIZE size;
        char curChar;
        int charWidth,charHeight,bmapWidth,bmapHeight,numBytes,res;
        HBITMAP bitObject;
        HGDIOBJ origBmap;
        unsigned char *bmap;

        curChar = (char)(i + firstChar);

        /* Find how high/wide this character is */
        VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size));

        /* Create the output bitmap */
        charWidth = size.cx;
        charHeight = size.cy;
        /* Round up to the next multiple of 32 bits */
        bmapWidth = ((charWidth + 31) / 32) * 32;
        bmapHeight = charHeight;
        bitObject = CreateCompatibleBitmap(bitDevice,
                                           bmapWidth,
                                           bmapHeight);
        /* VERIFY(bitObject); */

        /* Assign the output bitmap to the device */
        origBmap = SelectObject(bitDevice, bitObject);
        (void) VERIFY(origBmap);

        VERIFY( PatBlt( bitDevice, 0, 0, bmapWidth, bmapHeight,BLACKNESS ) );

        /* Use our source font on the device */
        VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice,OBJ_FONT)));

        /* Draw the character */
        VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1));

        /* Unselect our bmap object */
        VERIFY(SelectObject(bitDevice, origBmap));

        /* Convert the display dependant representation to a 1 bit deep DIB */
        numBytes = (bmapWidth * bmapHeight) / 8;
        bmap = malloc(numBytes);
        dibInfo->bmiHeader.biWidth = bmapWidth;
        dibInfo->bmiHeader.biHeight = bmapHeight;
        res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap,
                        dibInfo,
                        DIB_RGB_COLORS);
        /* VERIFY(res); */

        /* Create the GL object */
        glNewList(i + listBase, GL_COMPILE);
        glBitmap(bmapWidth, bmapHeight, 0.0, (GLfloat)metric.tmDescent,
                 (GLfloat)charWidth, 0.0,
                 bmap);
        glEndList();
        /* CheckGL(); */

        /* Destroy the bmap object */
        DeleteObject(bitObject);

        /* Deallocate the bitmap data */
        free(bmap);
    }

    /* Destroy the DC */
    VERIFY(DeleteDC(bitDevice));

    free(dibInfo);

    return TRUE;
#undef VERIFY
}
Exemplo n.º 20
0
void eFont::create(const eChar *fontFace, const eChar *letters, eU32 height, eColor color)
{
    LOGFONT lf;
    eMemSet(&lf, 0, sizeof(lf));
    eStrCopy(lf.lfFaceName, fontFace);
    lf.lfHeight = -(eInt)height; 
    lf.lfWeight = FW_NORMAL;
    lf.lfCharSet = DEFAULT_CHARSET; 
    lf.lfOutPrecision = OUT_TT_PRECIS; 
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; 
    lf.lfQuality = ANTIALIASED_QUALITY;
    lf.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
    HFONT font = CreateFontIndirect(&lf);
    eASSERT(font);

    HDC hdc = GetDC(nullptr);
    eASSERT(hdc);
    HDC compDc = CreateCompatibleDC(hdc);
    eASSERT(compDc);

    SetTextColor(compDc, RGB(color.b, color.g, color.r));
    SetBkMode(compDc,TRANSPARENT);
    SelectObject(compDc, font);

    TEXTMETRIC met;
    GetTextMetrics(compDc, &met);
    m_height = met.tmHeight;

    const eU32 border = 2;
    const eU32 numLetters = eStrLength(letters);
    const eF32 chrPerLine = eSqrt((eF32)numLetters);
    const eU32 texWidth = eNextPowerOf2(eFtoL((eF32)(met.tmAveCharWidth+border)*chrPerLine));
    const eU32 texHeight = eNextPowerOf2(eFtoL((eF32)(met.tmHeight+border)*chrPerLine));

    HBITMAP bmp = CreateCompatibleBitmap(hdc, texWidth, texHeight);
    eASSERT(bmp);
    SelectObject(compDc, bmp);

    m_bmp.resize(texWidth*texHeight);
    eMemSet(&m_bmp[0], 0, m_bmp.size()*sizeof(eColor));

    BITMAPINFO bmi;
    eMemSet(&bmi, 0, sizeof(bmi));
    bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
    bmi.bmiHeader.biWidth = texWidth;
    bmi.bmiHeader.biHeight = -(eInt)texHeight;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biCompression = BI_RGB;
    SetDIBits(compDc, bmp, 0, texHeight, &m_bmp[0],&bmi,DIB_RGB_COLORS);

    eU32 x = 0;
    eU32 y = 0;

    for (eU32 i=0; i<numLetters; i++)
    {
        const eChar c = letters[i];
        const eChar text[] = {c, '\0'};
        SIZE size;
        GetTextExtentPoint32(compDc, text, 1, &size);

        if (x+size.cx >= texWidth)
        {
            x = 0;
            y += met.tmHeight+border;
        }

        eFontLetter &l = m_letters[c];
        l.chr = c;
        l.width = size.cx;
        l.used = eTRUE;
        l.rect.set(x, y, x+l.width, y+met.tmHeight);
        l.uv.set((eF32)x/(eF32)texWidth, (eF32)y/(eF32)texHeight);

        ExtTextOut(compDc, x, y, 0, nullptr, text, 1, nullptr);
        x += l.width+border;
    }

    GetDIBits(compDc,bmp, 0, texHeight, &m_bmp[0], &bmi, DIB_RGB_COLORS);
    DeleteObject(font);
    DeleteObject(bmp);
    DeleteDC(compDc);
    DeleteDC(hdc);

    for (eU32 i=0; i<m_bmp.size(); i++)
        m_bmp[i].a = 255;

    if (!m_tex || m_tex->width != texWidth || m_tex->height != texHeight)
    {
        eGfx->removeTexture2d(m_tex);
        m_tex = eGfx->addTexture2d(texWidth, texHeight, eTEX_NOMIPMAPS, eTFO_ARGB8);
    }

    eGfx->updateTexture2d(m_tex, &m_bmp[0]);
}
Exemplo n.º 21
0
int HitTest(HWND hwnd, struct ClcData *dat, int testx, int testy, struct ClcContact **contact, struct ClcGroup **group, DWORD *flags)
{
    struct ClcContact *hitcontact;
    struct ClcGroup *hitgroup;
    int hit, indent, width, i, cxSmIcon;
    int checkboxWidth;
    SIZE textSize;
    HDC hdc;
    RECT clRect;
    HFONT hFont;
    DWORD style = GetWindowLong(hwnd, GWL_STYLE);
	BYTE mirror_mode = cfg::dat.bUseDCMirroring;

    if (flags)
        *flags = 0;
    GetClientRect(hwnd, &clRect);
    if (testx < 0 || testy < 0 || testy >= clRect.bottom || testx >= clRect.right) {
        if (flags) {
            if (testx < 0)
                *flags |= CLCHT_TOLEFT;
            else if (testx >= clRect.right)
                *flags |= CLCHT_TORIGHT;
            if (testy < 0)
                *flags |= CLCHT_ABOVE;
            else if (testy >= clRect.bottom)
                *flags |= CLCHT_BELOW;
        }
        return -1;
    }
    if (testx< dat->leftMargin) {
        if (flags)
            *flags |= CLCHT_INLEFTMARGIN | CLCHT_NOWHERE;
        return -1;
    }
   	hit = RowHeight::hitTest(dat, dat->yScroll + testy);
	if (hit != -1)
		hit = pcli->pfnGetRowByIndex(dat, hit, &hitcontact, &hitgroup);

    if (hit == -1) {
        if (flags)
            *flags |= CLCHT_NOWHERE | CLCHT_BELOWITEMS;
        return -1;
    }
    if (contact)
        *contact = hitcontact;
    if (group)
        *group = hitgroup;

    for (indent = 0; hitgroup->parent; indent++,hitgroup = hitgroup->parent) {
        ;
    }

    if(!dat->bisEmbedded) {
        if(hitcontact->type == CLCIT_CONTACT) {
            if(mirror_mode == 1 || (mirror_mode == 2 && cfg::eCache[hitcontact->extraCacheEntry].dwCFlags & ECF_RTLNICK))
                return RTL_HitTest(hwnd, dat, testx, testy, hitcontact, flags, indent, hit);
        }
        else if(hitcontact->type == CLCIT_GROUP) {
            if(cfg::dat.bGroupAlign == CLC_GROUPALIGN_RIGHT || (hitcontact->isRtl && cfg::dat.bGroupAlign == CLC_GROUPALIGN_AUTO))
                return RTL_HitTest(hwnd, dat, testx, testy, hitcontact, flags, indent, hit);
        }
    }

    // avatar check
    if(hitcontact->type == CLCIT_CONTACT && cfg::dat.dwFlags & CLUI_FRAME_AVATARS && hitcontact->ace != NULL && hitcontact->avatarLeft != -1) {
        if(testx >hitcontact->avatarLeft && testx < hitcontact->avatarLeft + cfg::dat.avatarSize) {
            if(flags)
                *flags |= CLCHT_ONAVATAR;
        }
    }
    if (testx< dat->leftMargin + indent * dat->groupIndent) {
        if (flags)
            *flags |= CLCHT_ONITEMINDENT;
        return hit;
    }
    checkboxWidth = 0;
    if (style & CLS_CHECKBOXES && hitcontact->type == CLCIT_CONTACT)
        checkboxWidth = dat->checkboxSize + 2;
    if (style & CLS_GROUPCHECKBOXES && hitcontact->type == CLCIT_GROUP)
        checkboxWidth = dat->checkboxSize + 2;
    if (hitcontact->type == CLCIT_INFO && hitcontact->flags & CLCIIF_CHECKBOX)
        checkboxWidth = dat->checkboxSize + 2;
    if (testx< dat->leftMargin + indent * dat->groupIndent + checkboxWidth) {
        if (flags)
            *flags |= CLCHT_ONITEMCHECK;
        return hit;
    }
    if (testx< dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace) {
        if (flags)
            *flags |= CLCHT_ONITEMICON;
        return hit;
    }
    cxSmIcon = GetSystemMetrics(SM_CXSMICON);
    for (i = 0; i< dat->extraColumnsCount; i++) {
        if (hitcontact->iExtraImage[i] == 0xFF)
            continue;
        if (testx >= clRect.right - dat->extraColumnSpacing * (dat->extraColumnsCount - i) && testx< clRect.right - dat->extraColumnSpacing * (dat->extraColumnsCount - i) + cxSmIcon) {
            if (flags)
                *flags |= CLCHT_ONITEMEXTRA | (i << 24);
            return hit;
        }
    }
    if(hitcontact->extraCacheEntry >= 0 && hitcontact->extraCacheEntry < cfg::nextCacheEntry && cfg::eCache[hitcontact->extraCacheEntry].iExtraValid) {
        //int rightOffset = clRect.right;
        int rightOffset = hitcontact->extraIconRightBegin;
        int images_present = 0;

        for (i = 5; i >= 0; i--) {
            if (cfg::eCache[hitcontact->extraCacheEntry].iExtraImage[i] == 0xFF)
                continue;
            if(!((1 << i) & cfg::eCache[hitcontact->extraCacheEntry].dwXMask))
                continue;
            images_present++;
            if (testx > (rightOffset - (cfg::dat.exIconScale + 2) * images_present) && testx < (rightOffset - (cfg::dat.exIconScale + 2) * images_present + (cfg::dat.exIconScale))) {
                if (flags)
                    *flags |= (CLCHT_ONITEMEXTRAEX | ((i + 1) << 24));
                return hit;
            }
        }
    }
    hdc = GetDC(hwnd);
    if (hitcontact->type == CLCIT_GROUP)
        hFont = reinterpret_cast<HFONT>(SelectObject(hdc, dat->fontInfo[FONTID_GROUPS].hFont));
    else
        hFont = reinterpret_cast<HFONT>(SelectObject(hdc, dat->fontInfo[FONTID_CONTACTS].hFont));
    GetTextExtentPoint32(hdc, hitcontact->szText, lstrlen(hitcontact->szText), &textSize);
    width = textSize.cx;
    if (hitcontact->type == CLCIT_GROUP) {
        char *szCounts;
        szCounts = pcli->pfnGetGroupCountsText(dat, hitcontact);
        if (szCounts[0]) {
            GetTextExtentPoint32A(hdc, " ", 1, &textSize);
            width += textSize.cx;
            SelectObject(hdc, dat->fontInfo[FONTID_GROUPCOUNTS].hFont);
            GetTextExtentPoint32A(hdc, szCounts, lstrlenA(szCounts), &textSize);
            width += textSize.cx;
        }
    }
    SelectObject(hdc, hFont);
    ReleaseDC(hwnd, hdc);
    if (cfg::dat.dwFlags & CLUI_FULLROWSELECT && !(GetKeyState(VK_SHIFT) & 0x8000) && testx > dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace + width + 4 + (cfg::dat.dwFlags & CLUI_FRAME_AVATARS ? cfg::dat.avatarSize : 0)) {
        if (flags)
            *flags |= CLCHT_ONITEMSPACE;
        return hit;
    }
    if (testx< dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace + width + 4 + (cfg::dat.dwFlags & CLUI_FRAME_AVATARS ? cfg::dat.avatarSize : 0)) {
        if (flags)
            *flags |= CLCHT_ONITEMLABEL;
        return hit;
    }
    if (flags)
        *flags |= CLCHT_NOWHERE;
    return -1;
}
Exemplo n.º 22
0
/****************************************************************************
 *                                                                          *
 * Function: CreateHypCtrl                                                  *
 *                                                                          *
 * Purpose : Create Hyperlink control.                                      *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/
HWND CreateHypCtrl(HWND hWndParent, HYPCTRL* pHc, int x, int y, int width, int height)
{
	HYPCTRL* pHcWnd;
	HWND hWndHyperlink;
	RECT rect;
	LOGFONT lf;
	HFONT hFontParent, hFontNormal, hFontHover;

	// some error checking
	if (hInst == NULL) return (HWND) NULL;
	if (hWndParent == NULL) return (HWND) NULL;

	if (pHc->cbFn == NULL) {
		// if the hyperlink opens a normal link, require the szLink member
		if (pHc->szLink == NULL) return (HWND) NULL;
	} else {
		// if the hyperlink calls a callback function, require the szText member
		if (pHc->szText == NULL) return (HWND) NULL;
	}

	hWndHyperlink = CreateWindow(lpszClassname,
						NULL,
						WS_CHILD,
						x, y, width, height,
						hWndParent,
						NULL,
						hInst,
						NULL);

	if (!hWndHyperlink) return (HWND) NULL;

	// alloc some space to hold all hyperlink stuff
	if ((pHcWnd = GlobalAllocPtr(GPTR, sizeof(HYPCTRL))) == NULL) {
		DestroyWindow(hWndHyperlink);
		return (HWND) NULL;
	}
	CopyMemory(pHcWnd, pHc, sizeof(HYPCTRL));

	// copy the text entries from HYPCTRL
	if (pHcWnd->cbFn == NULL) {
		if (pHcWnd->szLink != NULL) {
			if ((pHcWnd->szLink = (LPTSTR) GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szLink))) == NULL) {
				if (pHcWnd) GlobalFreePtr(pHcWnd);
				DestroyWindow(hWndHyperlink);
				return (HWND) NULL;
			}
			CopyMemory(pHcWnd->szLink, pHc->szLink, STRBYTESIZE(pHc->szLink));
		}
	}

	if (pHcWnd->szText != NULL) {
		if ((pHcWnd->szText = GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szText))) == NULL) {
			if (pHcWnd->szLink) GlobalFreePtr(pHcWnd->szLink);
			if (pHcWnd) GlobalFreePtr(pHcWnd);
			DestroyWindow(hWndHyperlink);
			return (HWND) NULL;
		}
		CopyMemory(pHcWnd->szText, pHc->szText, STRBYTESIZE(pHc->szText));
	} else {
		// no callback function and no szText given so we use szLink as text
		if(pHcWnd->cbFn == NULL) pHcWnd->szText = pHcWnd->szLink;
	}

	if (pHcWnd->szTooltip != NULL) {
		if ((pHcWnd->szTooltip = GlobalAllocPtr(GPTR, STRBYTESIZE(pHc->szTooltip))) == NULL) {
			if (pHcWnd->szLink) GlobalFreePtr(pHcWnd->szLink);
			if (pHcWnd->szText) GlobalFreePtr(pHcWnd->szText);
			if (pHcWnd) GlobalFreePtr(pHcWnd);
			DestroyWindow(hWndHyperlink);
			return (HWND) NULL;
		}
		CopyMemory(pHcWnd->szTooltip, pHc->szTooltip, STRBYTESIZE(pHc->szTooltip));
	}

	// save a pointer to the structure in the window extra space
	SetWindowLong(hWndHyperlink, WND_HYPSTRUCT, (LONG) (pHcWnd));
	SetWindowWord(hWndHyperlink, WND_ISHOVER, (WORD) FALSE);

	// create the fonts for the control
	hFontParent = (HFONT) SendMessage(GetParent(hWndHyperlink), WM_GETFONT, 0, 0);

	if (hFontParent != NULL) {
		GetObject(hFontParent, sizeof(LOGFONT), &lf);

		switch (pHcWnd->ulStyle) {
			case ulHover:
				hFontNormal = CreateFontIndirect(&lf);
				lf.lfUnderline = (BYTE) TRUE;
				hFontHover  = CreateFontIndirect(&lf);
				break;
			case ulAlways:
				lf.lfUnderline = (BYTE) TRUE;
				hFontNormal = CreateFontIndirect(&lf);
				hFontHover  = CreateFontIndirect(&lf);
				break;
			case ulNone:
				hFontNormal = CreateFontIndirect(&lf);
				hFontHover  = CreateFontIndirect(&lf);
				break;
			}
			// save the fonts in the window extra space
			SetWindowLong(hWndHyperlink, WND_FONTN, (LONG) hFontNormal);
			SetWindowLong(hWndHyperlink, WND_FONTH, (LONG) hFontHover);
	} else {
		// use the system font
		SetWindowLong(hWndHyperlink, WND_FONTN, (LONG) NULL);
		SetWindowLong(hWndHyperlink, WND_FONTH, (LONG) NULL);
	}

	GetClientRect(hWndHyperlink, &rect);

	// adjust window size to fit the text
	if (pHcWnd->bAutoSize) {
		PAINTSTRUCT ps;
		HDC hdc;
		SIZE size;

		hdc	= BeginPaint(hWndHyperlink, &ps);
 		SelectObject(hdc, (HFONT) GetWindowLong(hWndHyperlink, WND_FONTN));
		GetTextExtentPoint32(hdc, pHcWnd->szText, GetStringLength(pHcWnd->szText), &size);
		rect.right	= size.cx - rect.left;
		rect.bottom	= size.cy - rect.top;
		EndPaint(hWndHyperlink, &ps);

		SetWindowPos(hWndHyperlink,
			0,
			0, 0, size.cx, size.cy,
			SWP_NOMOVE | SWP_NOZORDER);
	}

	// save window size in the window extra space
	SetWindowLong(hWndHyperlink, WND_LEFT, (LONG) (rect.left));
	SetWindowLong(hWndHyperlink, WND_TOP, (LONG) (rect.top));
	SetWindowLong(hWndHyperlink, WND_RIGHT, (LONG) (rect.right));
	SetWindowLong(hWndHyperlink, WND_BOTTOM, (LONG) (rect.bottom));

	// create tooltip if requested
	if (pHcWnd->szTooltip != NULL) {
    	HWND hWndTT;
    	TOOLINFO ti;

    	hWndTT = CreateWindowEx(WS_EX_TOPMOST,
    		TOOLTIPS_CLASS,
    		NULL,
    		WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		hWndHyperlink,
    		NULL,
    		hInst,
    		NULL);
    				
    	if (!hWndTT) return FALSE;

    	SetWindowPos(hWndTT,
    		HWND_TOPMOST,
    		0, 0, 0, 0,
    		SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

    	ti.cbSize      = sizeof(TOOLINFO);
    	ti.uFlags      = TTF_SUBCLASS;
    	ti.hwnd        = hWndHyperlink;
    	ti.hinst       = hInst;
    	ti.uId         = 0;
    	ti.lpszText    = pHcWnd->szTooltip; // get text for tooltip
    	ti.rect.left   = (LONG) GetWindowLong(hWndHyperlink, WND_LEFT);
    	ti.rect.top    = (LONG) GetWindowLong(hWndHyperlink, WND_TOP);
    	ti.rect.right  = (LONG) GetWindowLong(hWndHyperlink, WND_RIGHT);
    	ti.rect.bottom = (LONG) GetWindowLong(hWndHyperlink, WND_BOTTOM);

    	// add tooltip
    	SendMessage(hWndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
	}

	// show the window
	ShowWindow(hWndHyperlink, SW_NORMAL);
	UpdateWindow(hWndHyperlink);

	return hWndHyperlink;
}
static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint)
{
    if (hdcPaint) {
        HDC hdcMem;
        HBITMAP hbmMem;
        HBITMAP hbmOld = 0;
        RECT rcClient;
        HFONT hOldFont = 0;
        int xOffset = 0;
        
        GetClientRect(ctl->hwnd, &rcClient);
        hdcMem = CreateCompatibleDC(hdcPaint);
        hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
        hbmOld = reinterpret_cast<HBITMAP>(SelectObject(hdcMem, hbmMem));

        hOldFont = reinterpret_cast<HFONT>(SelectObject(hdcMem, ctl->hFont));
    // If its a push button, check to see if it should stay pressed
        if (ctl->pushBtn && ctl->pbState)
            ctl->stateId = PBS_PRESSED;

    // Draw the flat button
        if (ctl->flatBtn) {
            if (ctl->hThemeToolbar && ctl->bThemed) {
                RECT rc = rcClient;
                int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
                SkinDrawBg(ctl->hwnd, hdcMem);
                if (API::pfnIsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
                    API::pfnDrawThemeParentBackground(ctl->hwnd, hdcMem, &rc);
                }
                API::pfnDrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rc, &rc);
            } else {
                HBRUSH hbr;
                RECT rc = rcClient;

                if(ctl->buttonItem) {
                    RECT rcParent;
                    POINT pt;
                    HWND hwndParent = pcli->hwndContactList;
                    ImageItem *imgItem = ctl->stateId == PBS_HOT ? ctl->buttonItem->imgHover : (ctl->stateId == PBS_PRESSED ? ctl->buttonItem->imgPressed : ctl->buttonItem->imgNormal);
                    LONG *glyphMetrics = ctl->stateId == PBS_HOT ? ctl->buttonItem->hoverGlyphMetrics : (ctl->stateId == PBS_PRESSED ? ctl->buttonItem->pressedGlyphMetrics : ctl->buttonItem->normalGlyphMetrics);

                    //if(ctl->stateId == PBS_HOT && glyphMetrics[2] <= 1 && glyphMetrics[3] <= 1)
                    //    glyphMetrics = ctl->lastGlyphMetrics;

                    GetWindowRect(ctl->hwnd, &rcParent);
                    pt.x = rcParent.left;
                    pt.y = rcParent.top;

                    ScreenToClient(pcli->hwndContactList, &pt);

                    BitBlt(hdcMem, 0, 0, rc.right, rc.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);
                    if(imgItem)
                        DrawAlpha(hdcMem, &rc, 0, 0, 0, 0, 0, 0, 0, imgItem);
                    if(g_glyphItem) {
                    	API::pfnAlphaBlend(hdcMem, (rc.right - glyphMetrics[2]) / 2, (rc.bottom - glyphMetrics[3]) / 2,
                                   glyphMetrics[2], glyphMetrics[3], g_glyphItem->hdc,
                                   glyphMetrics[0], glyphMetrics[1], glyphMetrics[2],
                                   glyphMetrics[3], g_glyphItem->bf);
                        //CopyMemory(ctl->lastGlyphMetrics, glyphMetrics, 4 * sizeof(LONG));
                    }
                }
                else if(ctl->bSkinned) {      // skinned
                    RECT rcParent;
                    POINT pt;
                    HWND hwndParent = pcli->hwndContactList;
                    StatusItems_t *item;
                    int item_id;
                    
                    GetWindowRect(ctl->hwnd, &rcParent);
                    pt.x = rcParent.left;
                    pt.y = rcParent.top;
                    
                    ScreenToClient(pcli->hwndContactList, &pt);
                    
                    if(HIWORD(ctl->bSkinned))
                        item_id = ctl->stateId == PBS_HOT ? ID_EXTBKTBBUTTONMOUSEOVER : (ctl->stateId == PBS_PRESSED ? ID_EXTBKTBBUTTONSPRESSED : ID_EXTBKTBBUTTONSNPRESSED);
                        //GetItemByStatus(ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : (ctl->stateId == PBS_PRESSED ? ID_EXTBKTBBUTTONSPRESSED : ID_EXTBKTBBUTTONSNPRESSED), &item);
                    else
                        item_id = ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : (ctl->stateId == PBS_PRESSED ? ID_EXTBKBUTTONSPRESSED : ID_EXTBKBUTTONSNPRESSED);
                    item = &StatusItems[item_id - ID_STATUS_OFFLINE];
                        //GetItemByStatus(ctl->stateId == PBS_PRESSED ? ID_EXTBKBUTTONSPRESSED : ID_EXTBKBUTTONSNPRESSED, &item);
                    SetTextColor(hdcMem, item->TEXTCOLOR);
                    if(item->IGNORED) {
                        if(pt.y < 10 || cfg::dat.bWallpaperMode)
                            //SkinDrawBg(ctl->hwnd, hdcMem);
                            BitBlt(hdcMem, 0, 0, rc.right, rc.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);
                        else
                            FillRect(hdcMem, &rc, GetSysColorBrush(COLOR_3DFACE));
                    }
                    else {
                        if(pt.y < 10 || cfg::dat.bWallpaperMode)
                            //SkinDrawBg(ctl->hwnd, hdcMem);
                            BitBlt(hdcMem, 0, 0, rc.right, rc.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);
                        else
                            FillRect(hdcMem, &rc, GetSysColorBrush(COLOR_3DFACE));
                        rc.top += item->MARGIN_TOP; rc.bottom -= item->MARGIN_BOTTOM;
                        rc.left += item->MARGIN_LEFT; rc.right -= item->MARGIN_RIGHT;
                        DrawAlpha(hdcMem, &rc, item->COLOR, item->ALPHA, item->COLOR2, item->COLOR2_TRANSPARENT, item->GRADIENT,
                                  item->CORNER, item->BORDERSTYLE, item->imageItem);
                    }
                }
                else {
                    if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT)
                        hbr = GetSysColorBrush(COLOR_3DFACE);
                    else {
                        HDC dc;
                        HWND hwndParent;

                        hwndParent = GetParent(ctl->hwnd);
                        dc = GetDC(hwndParent);
                        hbr = (HBRUSH) SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM) dc, (LPARAM) hwndParent);
                        ReleaseDC(hwndParent, dc);
                    }
                    if (hbr) {
                        FillRect(hdcMem, &rc, hbr);
                        DeleteObject(hbr);
                    }
                }
                if(!ctl->bSkinned && ctl->buttonItem == 0) {
                    if (ctl->stateId == PBS_HOT || ctl->focus) {
                        if (ctl->pbState)
                            DrawEdge(hdcMem, &rc, EDGE_ETCHED, BF_RECT | BF_SOFT);
                        else
                            DrawEdge(hdcMem, &rc, BDR_RAISEDOUTER, BF_RECT | BF_SOFT);
                    } else if (ctl->stateId == PBS_PRESSED)
                        DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT | BF_SOFT);
                }
            }
        } else {
    // Draw background/border
            if (ctl->hThemeButton && ctl->bThemed) {
                int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
                POINT pt;
                RECT rcParent;
                
                GetWindowRect(ctl->hwnd, &rcParent);
                pt.x = rcParent.left;
                pt.y = rcParent.top;
                ScreenToClient(pcli->hwndContactList, &pt);
                BitBlt(hdcMem, 0, 0, rcClient.right, rcClient.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);

                if (API::pfnIsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
                    API::pfnDrawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
                }
                API::pfnDrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient);
            } else {
                UINT uState = DFCS_BUTTONPUSH | ((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0) | ((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0);
                if (ctl->defbutton && ctl->stateId == PBS_NORMAL)
                    uState |= DLGC_DEFPUSHBUTTON;
                DrawFrameControl(hdcMem, &rcClient, DFC_BUTTON, uState);
            }

    // Draw focus rectangle if button has focus
            if (ctl->focus) {
                RECT focusRect = rcClient;
                InflateRect(&focusRect, -3, -3);
                DrawFocusRect(hdcMem, &focusRect);
            }
        }

    // If we have an icon or a bitmap, ignore text and only draw the image on the button
        if (ctl->hIcon || ctl->hIconPrivate || ctl->iIcon) {
            int ix = (rcClient.right - rcClient.left) / 2 - (g_cxsmIcon / 2);
            int iy = (rcClient.bottom - rcClient.top) / 2 - (g_cxsmIcon / 2);
            HICON hIconNew = ctl->hIconPrivate != 0 ? ctl->hIconPrivate : ctl->hIcon;
            if (lstrlen(ctl->szText) == 0) {
                if (ctl->iIcon)
                    ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, g_cxsmIcon, g_cysmIcon, CLR_NONE, CLR_NONE, ILD_NORMAL);
                else
                    DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
                ctl->sLabel.cx = ctl->sLabel.cy = 0;
            } else {
                GetTextExtentPoint32(hdcMem, ctl->szText, lstrlen(ctl->szText), &ctl->sLabel);

                if(g_cxsmIcon + ctl->sLabel.cx + 8 > rcClient.right - rcClient.left)
                    ctl->sLabel.cx = (rcClient.right - rcClient.left) - g_cxsmIcon - 8;
                else
                    ctl->sLabel.cx += 4;
                
                ix = (rcClient.right - rcClient.left) / 2 - ((g_cxsmIcon + ctl->sLabel.cx) / 2);
                if (ctl->iIcon)
                    ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, g_cxsmIcon, g_cysmIcon, CLR_NONE, CLR_NONE, ILD_NORMAL);
                else
                    DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
                xOffset = ix + g_cxsmIcon + 4;
            }
        } else if (ctl->hBitmap) {
            BITMAP bminfo;
            int ix, iy;

            GetObject(ctl->hBitmap, sizeof(bminfo), &bminfo);
            ix = (rcClient.right - rcClient.left) / 2 - (bminfo.bmWidth / 2);
            iy = (rcClient.bottom - rcClient.top) / 2 - (bminfo.bmHeight / 2);
            if (ctl->stateId == PBS_PRESSED) {
                ix++;
                iy++;
            }
            DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->hBitmap, 0, ix, iy, bminfo.bmWidth, bminfo.bmHeight, IsWindowEnabled(ctl->hwnd) ? DST_BITMAP : DST_BITMAP | DSS_DISABLED);
        }
        if (GetWindowTextLength(ctl->hwnd)) {
    // Draw the text and optinally the arrow
            RECT rcText;

            CopyRect(&rcText, &rcClient);
            SetBkMode(hdcMem, TRANSPARENT);
    // XP w/themes doesn't used the glossy disabled text.  Is it always using COLOR_GRAYTEXT?  Seems so.
            if(!ctl->bSkinned)
                SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_GRAYTEXT));
            if (ctl->arrow)
                DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->arrow, 0, rcClient.right - rcClient.left - 5 - g_cxsmIcon + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), (rcClient.bottom - rcClient.top) / 2 - g_cysmIcon / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON : DST_ICON | DSS_DISABLED);
            DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->szText, 0, xOffset + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), ctl->hThemeButton ? (rcText.bottom - rcText.top - ctl->sLabel.cy) / 2 + 1 : (rcText.bottom - rcText.top - ctl->sLabel.cy) / 2 + (ctl->stateId == PBS_PRESSED ? 1 : 0), ctl->sLabel.cx, ctl->sLabel.cy, IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
        }
        if (hOldFont)
            SelectObject(hdcMem, hOldFont);
        BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
        SelectObject(hdcMem, hbmOld);
        DeleteObject(hbmMem);
        DeleteDC(hdcMem);
        DeleteObject(hbmOld);
    }
}
BOOL CTextLayout::Layout(HDC hdc, const WCHAR *psz,  UINT nCnt)
{
    Clear();

    // Count Line
    UINT i = 0;
    BOOL bNewLine = TRUE;
    _nLineCnt = 0;
    for (i = 0; i < nCnt; i++)
    {
        switch (psz[i])
        {
            case 0x0d:
            case 0x0a:
                bNewLine = TRUE;
                break;
            default:
                if (bNewLine)
                    _nLineCnt++;
                bNewLine = FALSE;
                break;
        }
    }

    _prgLines = (LINEINFO *)LocalAlloc(LPTR, _nLineCnt * sizeof(LINEINFO));
    if (!_prgLines)
        return FALSE;

    // Count character of each line.
    bNewLine = TRUE;
    int nCurrentLine = -1;
    for (i = 0; i < nCnt; i++)
    {
        switch (psz[i])
        {
            case 0x0d:
            case 0x0a:
                bNewLine = TRUE;
                break;
            default:
                if (bNewLine)
                {
                    nCurrentLine++;
                    _prgLines[nCurrentLine].nPos = i;
                    _prgLines[nCurrentLine].nCnt = 1;
                }
                else
                {
                    _prgLines[nCurrentLine].nCnt++;
                }
                bNewLine = FALSE;
                break;
        }
    }

    TEXTMETRIC tm;
    GetTextMetrics(hdc, &tm);
    _nLineHeight = tm.tmHeight + tm.tmExternalLeading;

    POINT ptCurrent;
    ptCurrent.x = 0;
    ptCurrent.y = 0;

    // Get the rectangle of each characters.
    for (i = 0; i < _nLineCnt; i++)
    {
        _prgLines[i].prgCharInfo = NULL;

        if (_prgLines[i].nCnt)
        {
            _prgLines[i].prgCharInfo = (CHARINFO *)LocalAlloc(LPTR, _prgLines[i].nCnt * sizeof(CHARINFO));
            if (!_prgLines[i].prgCharInfo)
                return FALSE;

            UINT j;
            POINT ptPrev = ptCurrent;
            for (j = 0; j < _prgLines[i].nCnt; j++)
            {
                SIZE size;
                GetTextExtentPoint32(hdc, psz+_prgLines[i].nPos, j + 1, &size);
                ptCurrent.x = size.cx;
                _prgLines[i].prgCharInfo[j].rc.left = ptPrev.x;
                _prgLines[i].prgCharInfo[j].rc.top = ptPrev.y;
                _prgLines[i].prgCharInfo[j].rc.right = ptCurrent.x;
                _prgLines[i].prgCharInfo[j].rc.bottom = ptPrev.y + _nLineHeight;

                ptPrev = ptCurrent;
            }
        }

        ptCurrent.x = 0;
        ptCurrent.y += _nLineHeight;
    }
    return TRUE;
}
Exemplo n.º 25
0
static LRESULT MDescButton_OnPaint(HWND hwndDlg, MDescButtonCtrl *dat)
{
	PAINTSTRUCT ps;
	HDC hdc = BeginPaint(hwndDlg, &ps);
	HDC tempDC = CreateCompatibleDC(hdc);

	SIZE titleSize = { 0 };

	HBITMAP hBmp = CreateCompatibleBitmap(hdc, dat->width, dat->height);
	HBITMAP hOldBmp = (HBITMAP)SelectObject(tempDC, hBmp);

	RECT temprc;
	temprc.left = 0;
	temprc.right = dat->width;
	temprc.top = 0;

	// Draw background
	if (dat->bMouseInside || (GetFocus() == hwndDlg)) {
		MDescButton_FillRect(tempDC, 0, 0, dat->width, dat->height, dat->clSelBorder);
		MDescButton_DrawGradient(tempDC, 1, 1, dat->width - 2, dat->height - 2, &dat->rgbSelTop, &dat->rgbSelBottom);
		SetTextColor(tempDC, dat->clSelText);
	}
	else {
		MDescButton_FillRect(tempDC, 0, 0, dat->width, dat->height, dat->clBackground);
		SetTextColor(tempDC, dat->clText);
	}

	if (dat->hIcon)
		DrawIcon(tempDC, DBC_BORDER_SIZE, DBC_BORDER_SIZE, dat->hIcon);

	HFONT hfntSave = (HFONT)SelectObject(tempDC, dat->hFont);
	SetBkMode(tempDC, TRANSPARENT);

	if (dat->lpzTitle) {
		LOGFONT lf;
		GetObject(dat->hFont, sizeof(lf), &lf);
		lf.lfWeight = FW_BOLD;
		lf.lfHeight *= 1.5;
		HFONT hOldFont = (HFONT)SelectObject(tempDC, CreateFontIndirect(&lf));

		RECT textRect;
		textRect.left = DBC_BORDER_SIZE + (dat->hIcon ? 32 + DBC_VSPACING : 0);
		textRect.right = dat->width - DBC_BORDER_SIZE;
		textRect.top = DBC_BORDER_SIZE;
		textRect.bottom = dat->height - DBC_BORDER_SIZE;
		DrawText(tempDC, dat->lpzTitle, -1, &textRect, DT_TOP | DT_LEFT | DT_END_ELLIPSIS);
		GetTextExtentPoint32(tempDC, dat->lpzTitle, (int)mir_tstrlen(dat->lpzTitle), &titleSize);

		DeleteObject(SelectObject(tempDC, hOldFont));
	}

	if (dat->lpzDescription) {
		RECT textRect;
		textRect.left = DBC_BORDER_SIZE + (dat->hIcon ? 32 + DBC_VSPACING : 0);
		textRect.right = dat->width - DBC_BORDER_SIZE;
		textRect.top = DBC_BORDER_SIZE + titleSize.cy ? titleSize.cy + DBC_HSPACING : 0;
		textRect.bottom = dat->height - DBC_BORDER_SIZE;
		DrawText(tempDC, dat->lpzDescription, -1, &textRect, DT_TOP | DT_LEFT | DT_WORDBREAK | DT_END_ELLIPSIS);
		GetTextExtentPoint32(tempDC, dat->lpzTitle, (int)mir_tstrlen(dat->lpzTitle), &titleSize);
	}

	SelectObject(tempDC, hfntSave);

	//Copy to output
	BitBlt(hdc, dat->rc.left, dat->rc.top, dat->width, dat->height, tempDC, 0, 0, SRCCOPY);
	SelectObject(tempDC, hOldBmp);
	DeleteObject(hBmp);
	DeleteDC(tempDC);
	EndPaint(hwndDlg, &ps);

	return TRUE;
}
Exemplo n.º 26
0
/**
 * This is the message procedure for my nice looking message box
 *
 * @param	hDlg		- window handle
 * @param	uMsg		- message to handle
 * @param	wParam		- message specific parameter
 * @param	lParam		- message specific parameter
 *
 * @return	TRUE, FALSE, IDOK, IDYES, IDALL, IDNO or IDCANCEL
 **/
static INT_PTR CALLBACK MsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static int retOk = IDOK;
	static int retAll = IDALL;
	static int retNon = IDNONE;
	static int retCancel = IDCANCEL;

	switch (uMsg) {
	case WM_INITDIALOG:
		{
			LPMSGBOX pMsgBox = (LPMSGBOX)lParam;
			if (PtrIsValid(pMsgBox)) {
				int icoWidth = 0;
				int InfoBarHeight = 0;
				HFONT hNormalFont;

				hNormalFont = (HFONT)SendDlgItemMessage(hDlg, TXT_NAME, WM_GETFONT, 0, 0);
				if (pMsgBox->uType & MB_INFOBAR) {
					LOGFONT lf;

					// set bold font for name in description area
					GetObject(hNormalFont, sizeof(lf), &lf);
					lf.lfWeight = FW_BOLD;
					hNormalFont = CreateFontIndirect(&lf);

					// set infobar's textfont
					SendDlgItemMessage(hDlg, TXT_NAME, WM_SETFONT, (WPARAM)hNormalFont, 0);

					// set infobar's logo icon
					SendDlgItemMessage(hDlg, ICO_DLGLOGO, STM_SETIMAGE, IMAGE_ICON,
						(pMsgBox->hiLogo ? (LPARAM)pMsgBox->hiLogo : (LPARAM)IcoLib_GetIcon(ICO_DLG_DETAILS,TRUE)));

					// enable headerbar
					ShowWindow(GetDlgItem(hDlg, TXT_NAME), SW_SHOW);
					ShowWindow(GetDlgItem(hDlg, ICO_DLGLOGO), SW_SHOW);
				}
				else {
					RECT rc;
					GetClientRect(GetDlgItem(hDlg, TXT_NAME), &rc);
					InfoBarHeight = rc.bottom;

					if (pMsgBox->hiLogo)
						SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)pMsgBox->hiLogo);
				}

				// draw the desired status icon
				HICON hIcon = MsgLoadIcon(pMsgBox);
				if (hIcon)
					SendDlgItemMessage(hDlg, ICO_MSGDLG, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
				else {
					RECT ws;
					GetWindowRect(GetDlgItem(hDlg, ICO_MSGDLG), &ws);
					icoWidth = ws.right - ws.left;
					ShowWindow(GetDlgItem(hDlg, ICO_MSGDLG), SW_HIDE);
				}

				// resize the messagebox and reorganize the buttons
				if (HDC hDC = GetDC(hDlg)) {
					POINT mpt = { 0, 0 };
					RECT ws = { 0, 0, 0, 0 };
					int txtWidth=0, txtHeight=0, needX, needY;
					RECT rcDlg;
					SIZE ts;
					LPTSTR h, rs;

					SelectObject(hDC, hNormalFont);
					// get message text width and height
					if(pMsgBox->ptszMsg) for (rs=h=pMsgBox->ptszMsg; ; ++h) {
						if (*h=='\n' || !*h) {
							GetTextExtentPoint32(hDC, rs, h-rs, &ts);
							if (ts.cx > txtWidth)
								txtWidth = ts.cx;
							txtHeight += ts.cy;
							if (!*h)
								break;
							rs = h+1;
						}
					}
					// increase width if info text requires more
					if((pMsgBox->uType&MB_INFOBAR) && pMsgBox->ptszInfoText && *pMsgBox->ptszInfoText){
						//int multiline = 0;
						RECT rcico; GetClientRect(GetDlgItem(hDlg,ICO_DLGLOGO), &rcico);
						rcico.right = rcico.right*100/66; // padding
						for(rs=h=pMsgBox->ptszInfoText; ; ++h) {
							if (*h=='\n' || !*h) {
								GetTextExtentPoint32(hDC, rs, h-rs, &ts);
								ts.cx += rcico.right;
								if (ts.cx > txtWidth)
									txtWidth = ts.cx;
								if (!*h)
									break;
								rs = h+1;
								//++multiline;
							}
						}
						/* used by SendSS, disabled for UserInfoEx for now
						if(!multiline)
							SetWindowLongPtr(GetDlgItem(hDlg,TXT_NAME), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hDlg,TXT_NAME), GWL_STYLE)|SS_CENTERIMAGE); */
					}
					ReleaseDC(hDlg, hDC);

					// calc new dialog size
					GetWindowRect(hDlg, &rcDlg);
					GetWindowRect(GetDlgItem(hDlg, TXT_MESSAGE), &ws);
					needX = txtWidth - (ws.right - ws.left) - icoWidth;
					needY = max(0, txtHeight - (ws.bottom - ws.top) + 5);
					rcDlg.left -= needX/2; rcDlg.right += needX/2;
					rcDlg.top -= (needY-InfoBarHeight)/2; rcDlg.bottom += (needY-InfoBarHeight)/2;

					// resize dialog window
					MoveWindow(hDlg, rcDlg.left, rcDlg.top, rcDlg.right - rcDlg.left, rcDlg.bottom - rcDlg.top, FALSE);
					ClientToScreen(hDlg, &mpt);

					MoveCtrl(hDlg, STATIC_WHITERECT, -mpt.x, -mpt.y, needX, needY - InfoBarHeight);
					MoveCtrl(hDlg, TXT_NAME, -mpt.x, -mpt.y, needX, 0);
					MoveCtrl(hDlg, ICO_DLGLOGO, -mpt.x + needX, -mpt.y, 0, 0);
					MoveCtrl(hDlg, ICO_MSGDLG, -mpt.x, -mpt.y - InfoBarHeight, 0, 0);
					MoveCtrl(hDlg, TXT_MESSAGE, -mpt.x - icoWidth, -mpt.y - InfoBarHeight, needX, needY);
					MoveCtrl(hDlg, STATIC_LINE2, -mpt.x, -mpt.y + needY - InfoBarHeight, needX, 0);

					//
					// Do pushbutton positioning
					//
					RECT rcOk, rcAll, rcNone, rcCancel;

					// get button rectangles
					GetWindowRect(GetDlgItem(hDlg, IDOK), &rcOk);
					OffsetRect(&rcOk, -mpt.x, -mpt.y + needY - InfoBarHeight);

					GetWindowRect(GetDlgItem(hDlg, IDALL), &rcAll);
					OffsetRect(&rcAll, -mpt.x, -mpt.y + needY - InfoBarHeight);

					GetWindowRect(GetDlgItem(hDlg, IDNONE), &rcNone);
					OffsetRect(&rcNone, -mpt.x, -mpt.y + needY - InfoBarHeight);

					GetWindowRect(GetDlgItem(hDlg, IDCANCEL), &rcCancel);
					OffsetRect(&rcCancel, -mpt.x, -mpt.y + needY - InfoBarHeight);

					LONG okWidth = rcOk.right - rcOk.left;
					LONG allWidth = rcAll.right - rcAll.left;
					LONG noneWidth = rcNone.right - rcNone.left;
					LONG caWidth = rcCancel.right - rcCancel.left;
					LONG dlgMid = (rcDlg.right - rcDlg.left) / 2;

					// load button configuration
					switch (MB_TYPE(pMsgBox->uType)) {
					case MB_OK:
						rcOk.left = dlgMid - (okWidth / 2);
						rcOk.right = rcOk.left + okWidth;
						ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
						break;

					case MB_OKCANCEL:
						retOk = IDRETRY;
						SetDlgItemText(hDlg, IDOK, LPGENT("OK"));
						retCancel = IDCANCEL;
						SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel"));
						rcOk.left = dlgMid - okWidth - 10;
						rcOk.right = rcOk.left + okWidth;
						rcCancel.left = dlgMid + 10;
						rcCancel.right = rcCancel.left + caWidth;
						ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
						break;

					case MB_RETRYCANCEL:
						retOk = IDRETRY;
						SetDlgItemText(hDlg, IDOK, LPGENT("Retry"));
						retCancel = IDCANCEL;
						SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel"));
						rcOk.left = dlgMid - okWidth - 10;
						rcOk.right = rcOk.left + okWidth;
						rcCancel.left = dlgMid + 10;
						rcCancel.right = rcCancel.left + caWidth;
						ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
						break;

					case MB_YESNO:
						retOk = IDYES;
						SetDlgItemText(hDlg, IDOK, LPGENT("Yes"));
						retCancel = IDNO;
						SetDlgItemText(hDlg, IDCANCEL, LPGENT("No"));
						rcOk.left = dlgMid - okWidth - 10;
						rcOk.right = rcOk.left + okWidth;
						rcCancel.left = dlgMid + 10;
						rcCancel.right = rcCancel.left + caWidth;
						ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
						break;

					case MB_ABORTRETRYIGNORE:
						retOk = IDABORT;
						SetDlgItemText(hDlg, IDOK, LPGENT("Abort"));
						retAll = IDABORT;
						SetDlgItemText(hDlg, IDALL, LPGENT("Retry"));
						retCancel = IDCANCEL;
						SetDlgItemText(hDlg, IDCANCEL, LPGENT("Ignore"));
						rcAll.left = dlgMid - (allWidth / 2);
						rcAll.right = rcAll.left + allWidth;
						rcOk.left = rcAll.left - okWidth - 5;
						rcOk.right = rcOk.left + okWidth;
						rcCancel.left = rcAll.right + 5;
						rcCancel.right = rcCancel.left + caWidth;
						ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
						break;

					case MB_YESNOCANCEL:
						retOk = IDYES;
						SetDlgItemText(hDlg, IDOK, LPGENT("Yes"));
						retAll = IDNO;
						SetDlgItemText(hDlg, IDALL, LPGENT("No"));
						retCancel = IDCANCEL;
						SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel"));
						rcAll.left = dlgMid - (allWidth / 2);
						rcAll.right = rcAll.left + allWidth;
						rcOk.left = rcAll.left - okWidth - 5;
						rcOk.right = rcOk.left + okWidth;
						rcCancel.left = rcAll.right + 5;
						rcCancel.right = rcCancel.left + caWidth;
						ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
						break;

					case MB_YESALLNO:
						retOk = IDYES;
						SetDlgItemText(hDlg, IDOK, LPGENT("Yes"));
						retAll = IDALL;
						SetDlgItemText(hDlg, IDALL, LPGENT("All"));
						//retNon = IDNONE;
						SetDlgItemText(hDlg, IDNONE, LPGENT("None"));
						retCancel = IDNO;
						SetDlgItemText(hDlg, IDCANCEL, LPGENT("No"));
						rcCancel.right = rcDlg.right - rcDlg.left - 10;
						rcCancel.left = rcCancel.right - caWidth;
						rcNone.right = rcCancel.left - 5;
						rcNone.left = rcNone.right - noneWidth;
						rcAll.right = rcNone.left - 5;
						rcAll.left = rcAll.right - allWidth;
						rcOk.right = rcAll.left - 5;
						rcOk.left = rcOk.right - okWidth;
						// show buttons
						ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDNONE), SW_SHOW);
						ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
						break;

					default:
						rcOk.left = dlgMid - (okWidth / 2);
						rcOk.right = rcOk.left + okWidth;
					}

					MoveWindow(GetDlgItem(hDlg, IDOK), rcOk.left, rcOk.top, rcOk.right - rcOk.left, rcOk.bottom - rcOk.top, FALSE);
					MoveWindow(GetDlgItem(hDlg, IDALL), rcAll.left, rcAll.top, rcAll.right - rcAll.left, rcAll.bottom - rcAll.top, FALSE);
					MoveWindow(GetDlgItem(hDlg, IDNONE), rcNone.left, rcNone.top, rcNone.right - rcNone.left, rcNone.bottom - rcNone.top, FALSE);
					MoveWindow(GetDlgItem(hDlg, IDCANCEL), rcCancel.left, rcCancel.top, rcCancel.right - rcCancel.left, rcCancel.bottom - rcCancel.top, FALSE);
				}

				// set text's
				SetWindowText(hDlg, pMsgBox->ptszTitle);
				SetDlgItemText(hDlg, TXT_NAME, pMsgBox->ptszInfoText);
				SetDlgItemText(hDlg, TXT_MESSAGE, pMsgBox->ptszMsg);

				TranslateDialogDefault(hDlg);
				return TRUE;
			}
		}
		break;

	case WM_CTLCOLORSTATIC:
		switch (GetWindowLongPtr((HWND)lParam, GWLP_ID)) {
		case STATIC_WHITERECT:
		case ICO_DLGLOGO:
		case ICO_MSGDLG:
		case TXT_MESSAGE:
		case TXT_NAME:
			SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
			return GetSysColor(COLOR_WINDOW);
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDOK:
			EndDialog(hDlg, retOk);
			break;
		case IDCANCEL:
			EndDialog(hDlg, retCancel);
			break;
		case IDALL:
			EndDialog(hDlg, retAll);
			break;
		case IDNONE:
			EndDialog(hDlg, retNon);
		}
		break;

	case WM_DESTROY:
		DeleteObject((HFONT)SendDlgItemMessage(hDlg, TXT_NAME, WM_GETFONT, 0, 0));
		break;
	}
	return FALSE;
}
Exemplo n.º 27
0
LRESULT CLogListBox::OnDrawitem(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL& bHandled)
{
	LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lParam;
	if(!dis) return FALSE;
      
	LogListBoxItem * item = (LogListBoxItem *)dis->itemData;
	if(!item) return FALSE;
	
   CDCHandle dc = dis->hDC;

   if(dis->itemAction & (ODA_DRAWENTIRE|ODA_SELECT))
   {
		dc.SetBkColor(GetSysColor(COLOR_WINDOW));
		dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
      CRect r(dis->rcItem);
		if(!(dis->itemState & ODS_SELECTED ))
		{
			CBrush br;
			br.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
			dc.FillRect(r,br);
		}
		CRect rct;
      GetClientRect(&rct);

		if(dis->itemState & ODS_SELECTED )
		{
			CRect rd(dis->rcItem);
			GuiTools::FillRectGradient(dis->hDC,rd,0xEAE2D9, 0xD3C1AF, false);
		}
		else if(dis->itemID != GetCount()-1) // If it isn't last item
		{
			CPen pen;
			pen.CreatePen(PS_SOLID, 1, RGB(190,190,190));
			SelectObject(dc.m_hDC, pen);
			dc.MoveTo(rct.left, r.bottom-1);
			dc.LineTo(rct.right, r.bottom-1);
		}
			  
		SetBkMode(dc.m_hDC,TRANSPARENT);

		SIZE TimeLabelDimensions;
		SelectObject(dc.m_hDC, NormalFont);
		GetTextExtentPoint32(dc, item->Time, item->Time.GetLength(), &TimeLabelDimensions);
		
		// Writing error time
		
		ExtTextOutW(dc.m_hDC, rct.right-5-TimeLabelDimensions.cx, r.top + LLB_VertMargin, ETO_CLIPPED, r, item->Time, item->Time.GetLength(), 0);
		// Writing error title
		SelectObject(dc.m_hDC, UnderlineFont);
		ExtTextOutW(dc.m_hDC, r.left+56, r.top + LLB_VertMargin, ETO_CLIPPED, r, item->strTitle, wcslen(item->strTitle), 0);
		
		// Writing some info
		SelectObject(dc.m_hDC, NormalFont);
		RECT ItemRect={r.left+56, r.top + LLB_VertMargin + LLB_VertDivider + item->TitleHeight, 
							r.right - 10, r.bottom-LLB_VertMargin};
		dc.DrawText(item->Info, item->Info.GetLength() , &ItemRect, DT_NOPREFIX);
			
		// Writing error text with bold (explication of error)
		SelectObject(dc.m_hDC, BoldFont);
		RECT TextRect = {r.left+56, LLB_VertMargin +r.top+ item->TitleHeight+LLB_VertDivider+((item->Info.GetLength())?(item->InfoHeight+LLB_VertDivider):0), r.right - 10, r.bottom-LLB_VertMargin};
		dc.DrawText(item->strText,  wcslen(item->strText), &TextRect, DT_NOPREFIX);

		if(item->Type == logError)
			dc.DrawIcon(12,r.top+8,ErrorIcon);
		else if(item->Type == logWarning)
			dc.DrawIcon(12,r.top+8,WarningIcon);
	}
  
	bHandled = true;
	return 0;
}
Exemplo n.º 28
0
void IORegView_Paint(CIORegView* wnd, HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	HDC 			hDC; 
	PAINTSTRUCT 	ps;
	HDC 			hMemDC;
	HBITMAP			hMemBitmap;
	RECT			rc;
	HPEN 			pen;
	int				x, y, w, h;
	int				nameColWidth;
	int				curx, cury;
	SIZE			fontsize;
	IOReg			reg;
	char 			txt[80];

	GetClientRect(hWnd, &rc);
	x = 0;
	y = wnd->rebarHeight;
	w = rc.right - wnd->vsbWidth;
	h = rc.bottom - wnd->rebarHeight;
	curx = kXMargin; cury = wnd->yoff + kYMargin;

	hDC = BeginPaint(hWnd, &ps);

	hMemDC = CreateCompatibleDC(hDC);
	hMemBitmap = CreateCompatibleBitmap(hDC, w, h);
	SelectObject(hMemDC, hMemBitmap);

	pen = CreatePen(PS_SOLID, 1, RGB(210, 230, 255));
	SelectObject(hMemDC, pen);

	SelectObject(hMemDC, wnd->hFont);
	GetTextExtentPoint32(hMemDC, " ", 1, &fontsize);

	FillRect(hMemDC, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));

	reg = IORegs[wnd->CPU][wnd->Reg];
	if ((reg.type == AllRegs) || (reg.type == CatBegin))
	{
		nameColWidth = w - (kXMargin + (fontsize.cx*8) + kXMargin + 1 + kXMargin + kXMargin + 1 + kXMargin + (fontsize.cx*8) + kXMargin);

		DrawText(hMemDC, reg.name, curx, cury, w, fontsize.cy, DT_LEFT | DT_END_ELLIPSIS);
		cury += fontsize.cy + kYMargin;
		MoveToEx(hMemDC, 0, cury, NULL);
		LineTo(hMemDC, w, cury);
		cury ++;

		curx = kXMargin;
		DrawText(hMemDC, "Address", curx, cury+kYMargin, fontsize.cx*8, fontsize.cy, DT_LEFT);
		curx += (fontsize.cx*8) + kXMargin;
		MoveToEx(hMemDC, curx, cury, NULL);
		LineTo(hMemDC, curx, h);
		curx += 1 + kXMargin;
		DrawText(hMemDC, "Name", curx, cury+kYMargin, nameColWidth, fontsize.cy, DT_LEFT | DT_END_ELLIPSIS);
		curx += nameColWidth + kXMargin;
		MoveToEx(hMemDC, curx, cury, NULL);
		LineTo(hMemDC, curx, h);
		curx += 1 + kXMargin;
		DrawText(hMemDC, "Value", curx, cury+kYMargin, fontsize.cx*8, fontsize.cy, DT_RIGHT);

		cury += kYMargin + fontsize.cy + kYMargin;
		MoveToEx(hMemDC, 0, cury, NULL);
		LineTo(hMemDC, w, cury);
		cury += 1 + kYMargin;

		for (int i = wnd->Reg+1; ; i++)
		{
			IOReg curReg = IORegs[wnd->CPU][i];
			curx = kXMargin;

			if (curReg.type == CatBegin)
			{
				if (reg.type == AllRegs) continue;
				else break;
			}
			else if (curReg.type == ListEnd)
				break;
			else if (curReg.type == MMIOReg)
			{
				u32 val;

				sprintf(txt, "%08X", curReg.address);
				DrawText(hMemDC, txt, curx, cury, fontsize.cx*8, fontsize.cy, DT_LEFT);
				curx += (fontsize.cx*8) + kXMargin + 1 + kXMargin;

				DrawText(hMemDC, curReg.name, curx, cury, nameColWidth, fontsize.cy, DT_LEFT | DT_END_ELLIPSIS | DT_NOPREFIX);
				curx += nameColWidth + kXMargin + 1 + kXMargin;

				switch (curReg.size)
				{
				case 1:
					val = (u32)MMU_read8(wnd->CPU, curReg.address);
					sprintf(txt, "%02X", val);
					break;
				case 2:
					val = (u32)MMU_read16(wnd->CPU, curReg.address);
					sprintf(txt, "%04X", val);
					break;
				case 4:
					val = MMU_read32(wnd->CPU, curReg.address);
					sprintf(txt, "%08X", val);
					break;
				}
				DrawText(hMemDC, txt, curx, cury, fontsize.cx*8, fontsize.cy, DT_RIGHT);
			}

			cury += fontsize.cy + kYMargin;
			if (cury >= h) break;
			MoveToEx(hMemDC, 0, cury, NULL);
			LineTo(hMemDC, w, cury);
			cury += 1 + kYMargin;
		}
	}
	else
	{
		u32 val;
		nameColWidth = w - (kXMargin + (fontsize.cx*8) + kXMargin + 1 + kXMargin + kXMargin + 1 + kXMargin + (fontsize.cx*8) + kXMargin);

		sprintf(txt, "%08X - %s", reg.address, reg.name);
		DrawText(hMemDC, txt, curx, cury, w, fontsize.cy, DT_LEFT | DT_END_ELLIPSIS | DT_NOPREFIX);
		cury += fontsize.cy + kYMargin;
		MoveToEx(hMemDC, 0, cury, NULL);
		LineTo(hMemDC, w, cury);
		cury += 1 + kYMargin;

		switch (reg.size)
		{
		case 1:
			val = (u32)MMU_read8(wnd->CPU, reg.address);
			sprintf(txt, "Value:       %02X", val);
			break;
		case 2:
			val = (u32)MMU_read16(wnd->CPU, reg.address);
			sprintf(txt, "Value:     %04X", val);
			break;
		case 4:
			val = MMU_read32(wnd->CPU, reg.address);
			sprintf(txt, "Value: %08X", val);
			break;
		}
		DrawText(hMemDC, txt, curx, cury, w, fontsize.cy, DT_LEFT);
		cury += fontsize.cy + kYMargin;
		MoveToEx(hMemDC, 0, cury, NULL);
		LineTo(hMemDC, w, cury);
		cury ++;

		curx = kXMargin;
		DrawText(hMemDC, "Bits", curx, cury+kYMargin, fontsize.cx*8, fontsize.cy, DT_LEFT);
		curx += (fontsize.cx*8) + kXMargin;
		MoveToEx(hMemDC, curx, cury, NULL);
		LineTo(hMemDC, curx, h);
		curx += 1 + kXMargin;
		DrawText(hMemDC, "Description", curx, cury+kYMargin, nameColWidth, fontsize.cy, DT_LEFT | DT_END_ELLIPSIS);
		curx += nameColWidth + kXMargin;
		MoveToEx(hMemDC, curx, cury, NULL);
		LineTo(hMemDC, curx, h);
		curx += 1 + kXMargin;
		DrawText(hMemDC, "Value", curx, cury+kYMargin, fontsize.cx*8, fontsize.cy, DT_RIGHT);

		cury += kYMargin + fontsize.cy + kYMargin;
		MoveToEx(hMemDC, 0, cury, NULL);
		LineTo(hMemDC, w, cury);
		cury += 1 + kYMargin;

		for (int i = 0; i < reg.numBitfields; i++)
		{
			IORegBitfield bitfield = reg.bitfields[i];
			curx = kXMargin;

			if (bitfield.nbits > 1)
				sprintf(txt, "Bit%i-%i", bitfield.shift, bitfield.shift + bitfield.nbits - 1);
			else
				sprintf(txt, "Bit%i", bitfield.shift);
			DrawText(hMemDC, txt, curx, cury, fontsize.cx*8, fontsize.cy, DT_LEFT);
			curx += (fontsize.cx*8) + kXMargin + 1 + kXMargin;

			DrawText(hMemDC, bitfield.name, curx, cury, nameColWidth, fontsize.cy, DT_LEFT | DT_END_ELLIPSIS | DT_NOPREFIX);
			curx += nameColWidth + kXMargin + 1 + kXMargin;

			char bfpattern[8];
			sprintf(bfpattern, "%%0%iX", ((bitfield.nbits+3)&~3) >> 2);
			sprintf(txt, bfpattern, (val >> bitfield.shift) & ((1<<bitfield.nbits)-1));
			DrawText(hMemDC, txt, curx, cury, fontsize.cx*8, fontsize.cy, DT_RIGHT);

			cury += fontsize.cy + kYMargin;
			if (cury >= h) break;
			MoveToEx(hMemDC, 0, cury, NULL);
			LineTo(hMemDC, w, cury);
			cury += 1 + kYMargin;
		}
	}

	BitBlt(hDC, x, y, w, h, hMemDC, 0, 0, SRCCOPY);

	DeleteDC(hMemDC);
	DeleteObject(hMemBitmap);

	DeleteObject(pen);

	EndPaint(hWnd, &ps);
}
Exemplo n.º 29
0
tTVPCharacterData* GDIFontRasterizer::GetBitmap( const tTVPFontAndCharacterData & font, tjs_int aofsx, tjs_int aofsy ) {
	InitChAntialiasMethod();

	// setup GLYPHMETRICS and reveive buffer
	GLYPHMETRICS gm;
	ZeroMemory(&gm, sizeof(gm));
	static MAT2 no_transform_matrix = { {0,1}, {0,0}, {0,0}, {0,1} };
		// transformation matrix for intact conversion
		// | 1 0 |
		// | 0 1 |
	static MAT2 scale_4x_matrix = { {0,4}, {0,0}, {0,0}, {0,4} };
		// transformation matrix for 4x
		// | 4 0 |
		// | 0 4 |
	static MAT2 scale_8x_matrix = { {0,8}, {0,0}, {0,0}, {0,8} };
		// transformation matrix for 8x
		// | 8 0 |
		// | 0 8 |


	// determine format and transformation matrix
	tjs_int factor = 0;
	MAT2 *transmat;
	UINT format = font.Antialiased ? GGO_GRAY8_BITMAP : GGO_BITMAP;
	if(font.Antialiased)
	{
		switch(ChAntialiasMethod)
		{
		case camAPI:
			transmat = &no_transform_matrix;
			break;
		case camResample4:
			transmat = &scale_4x_matrix, factor = 2;
			format = GGO_BITMAP;
			break;
		case camSubpixelRGB:
		case camSubpixelBGR:
		case camResample8:
			transmat = &scale_8x_matrix, factor = 3;
			format = GGO_BITMAP;
			break;
		}
	}
	else
	{
		transmat = &no_transform_matrix;
	}


	// retrieve character code
	WORD code;
	// system supports UNICODE
	code = font.Character;

	// get buffer size and output dimensions
	int size = ::GetGlyphOutline( FontDC->GetDC(), code, format, &gm, 0, NULL, transmat);

	// set up structure's variables
	tTVPCharacterData * data = new tTVPCharacterData();

	{
		SIZE s;
		s.cx = 0;
		s.cy = 0;
		GetTextExtentPoint32( NonBoldFontDC->GetDC(), &font.Character, 1, &s);

		if(font.Font.Flags & TVP_TF_BOLD)
		{
			// calculate bold font width;
			// because sucking Win32 API returns different character size
			// between Win9x and WinNT, when we specified bold characters.
			// so we must alternatively calculate bold font size based on
			// non-bold font width.
			s.cx += (int)(s.cx / 50) + 1;
		}

		if(font.Font.Angle == 0)
		{
			data->Metrics.CellIncX = s.cx;
			data->Metrics.CellIncY = 0;
		}
		else if(font.Font.Angle == 2700)
		{
			data->Metrics.CellIncX = 0;
			data->Metrics.CellIncY = s.cx;
		}
		else
		{
			double angle = font.Font.Angle * (M_PI/1800);
			data->Metrics.CellIncX = static_cast<tjs_int>(  cos(angle) * s.cx);
			data->Metrics.CellIncY = static_cast<tjs_int>(- sin(angle) * s.cx);
		}
	}

	data->BlackBoxX = gm.gmBlackBoxX;
	data->BlackBoxY = gm.gmBlackBoxY;
	data->OriginX =
		(gm.gmptGlyphOrigin.x) +
		(aofsx<<factor);
	data->OriginY = -gm.gmptGlyphOrigin.y + (aofsy<<factor);

	data->Antialiased = font.Antialiased;

	data->FullColored = false;

	data->Blured = font.Blured;
	data->BlurWidth = font.BlurWidth;
	data->BlurLevel = font.BlurLevel;

	if(size == 0 || gm.gmBlackBoxY == 0)
	{
		data->BlackBoxX = 0;
		data->BlackBoxY = 0;
	}
	else
	{

		if(format == GGO_GRAY8_BITMAP)
		{
			data->Pitch = (size / gm.gmBlackBoxY) & ~0x03;
				// data is aligned to DWORD
			/*
				data->Pitch = (((gm.gmBlackBoxX -1)>>2)+1)<<2 seems to be proper,
				but does not work with some characters.
			*/
		}
		else
		{
			data->Pitch = (((gm.gmBlackBoxX -1)>>5)+1)<<2;
				// data is aligned to DWORD
		}

		data->Alloc(size);

		try
		{
			// draw to buffer
			::GetGlyphOutline( FontDC->GetDC(), code, format, &gm, size, data->GetData(), transmat);

			if( (ChUseResampling ) && (font.Font.Flags & TVP_TF_BOLD) ) {
				// our sucking win9x based OS cannot output bold characters
				// even if BOLD is specified.
				if(format == GGO_BITMAP)
					data->Bold2(font.Font.Height<<factor);
				else
					data->Bold(font.Font.Height<<factor);
					// so here we go a nasty way ...
			}

			if(!font.Antialiased)
			{
				// not antialiased
				data->Expand(); // nasty...
			}
			else
			{
				// antialiased
				switch(ChAntialiasMethod)
				{
				case camAPI:
					break;
				case camResample4:
					data->Resample4();
					break;
				case camResample8:
					data->Resample8();
					break;
				case camSubpixelRGB:
//						data->ResampleRGB();
					break;
				case camSubpixelBGR:
//						data->ResampleBGR();
					break;
				}
			}

			// apply blur
			if(font.Blured) data->Blur(); // nasty ...
		}
		catch(...)
		{
			data->Release();
			throw;
		}
	}
	if( font.Font.Flags & (TVP_TF_UNDERLINE|TVP_TF_STRIKEOUT) ) {
		OUTLINETEXTMETRIC otm = { sizeof(OUTLINETEXTMETRIC) };
		::GetOutlineTextMetrics( FontDC->GetDC(), otm.otmSize, &otm );
		tjs_int y = GetAscentHeight();
		if( font.Font.Flags & TVP_TF_UNDERLINE ) {
			tjs_int liney = y - otm.otmsUnderscorePosition;
			tjs_int height = otm.otmTextMetrics.tmHeight;
			tjs_int thickness = otm.otmsUnderscoreSize;
			if( liney >= height ) liney = height - 1;
			if( liney >= 0 && thickness > 0 ) {
				data->AddHorizontalLine( liney, thickness, 64 );
			}
		}
		if( font.Font.Flags & TVP_TF_STRIKEOUT ) {
			tjs_int liney = y - otm.otmsStrikeoutPosition;
			tjs_int thickness =  otm.otmsStrikeoutSize;
			if( liney >= 0 && thickness > 0 ) {
				data->AddHorizontalLine( liney, thickness, 64 );
			}
		}
	}
	return data;
}
Exemplo n.º 30
0
void UpdateSizeTip(HWND src, int cx, int cy)
{
    TCHAR str[32];

    if (!tip_enabled)
	return;

    if (!tip_wnd) {
	NONCLIENTMETRICS nci;

	/* First make sure the window class is registered */

	if (!tip_class) {
	    WNDCLASS wc;
	    wc.style = CS_HREDRAW | CS_VREDRAW;
	    wc.lpfnWndProc = SizeTipWndProc;
	    wc.cbClsExtra = 0;
	    wc.cbWndExtra = 0;
	    wc.hInstance = hinst;
	    wc.hIcon = NULL;
	    wc.hCursor = NULL;
	    wc.hbrBackground = NULL;
	    wc.lpszMenuName = NULL;
	    wc.lpszClassName = "SizeTipClass";

	    tip_class = RegisterClass(&wc);
	}
#if 0
	/* Default values based on Windows Standard color scheme */

	tip_font = GetStockObject(SYSTEM_FONT);
	tip_bg = RGB(255, 255, 225);
	tip_text = RGB(0, 0, 0);
#endif

	/* Prepare other GDI objects and drawing info */

	tip_bg = GetSysColor(COLOR_INFOBK);
	tip_text = GetSysColor(COLOR_INFOTEXT);

	memset(&nci, 0, sizeof(NONCLIENTMETRICS));
	nci.cbSize = sizeof(NONCLIENTMETRICS);
	SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
			     sizeof(NONCLIENTMETRICS), &nci, 0);
	tip_font = CreateFontIndirect(&nci.lfStatusFont);
    }

    /* Generate the tip text */

    sprintf(str, "%dx%d", cx, cy);

    if (!tip_wnd) {
	HDC hdc;
	SIZE sz;
	RECT wr;
	int ix, iy;

	/* calculate the tip's size */

	hdc = CreateCompatibleDC(NULL);
	GetTextExtentPoint32(hdc, str, (int)_tcslen(str), &sz);
	DeleteDC(hdc);

	GetWindowRect(src, &wr);

	ix = wr.left;
	if (ix < 16)
	    ix = 16;

	iy = wr.top - sz.cy;
	if (iy < 16)
	    iy = 16;

	/* Create the tip window */

	tip_wnd =
	    CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
			   MAKEINTRESOURCE(tip_class), str, WS_POPUP, ix,
			   iy, sz.cx, sz.cy, NULL, NULL, hinst, NULL);

	ShowWindow(tip_wnd, SW_SHOWNOACTIVATE);

    } else {

	/* Tip already exists, just set the text */

	SetWindowText(tip_wnd, str);
    }
}