Exemplo n.º 1
0
LONG CAddTracksDialog::UpdateItem(int i, CMediaClip * pClip)
{
    LVITEM item;
    LPCTSTR pszPath;
    EFileLocation eLocation;

    pszPath   = pClip->GetPath();
    eLocation = pClip->GetLocation();

    item.mask     = LVIF_TEXT | LVIF_DI_SETITEM | LVIF_IMAGE;
    item.iItem    = i;
    item.iSubItem = 0;
    item.pszText  = (LPTSTR)pszPath;
    item.iImage   = (int)eLocation;

    ListView_InsertItem(m_hwndTrackList, &item);

    //
    // Get the text size
    //
    HDC  hdc;
    LONG cx = 0;
    SIZE size;

    hdc = ::GetDC(m_hwndDlg);

    if (GetTextExtentExPoint(hdc, item.pszText, _tcslen(item.pszText), 0, NULL, NULL, &size))
    {
        cx = size.cx;
    }

    ::ReleaseDC(m_hwndDlg, hdc);

    return cx;
}
Exemplo n.º 2
0
void DrawEllipsisText(CDC& dc,LPCTSTR sText,int n,LPRECT prc,bool bHorizontal)
{
	assert(n>0);
	long width=bHorizontal ? prc->right - prc->left : prc->bottom - prc->top;
	CSize size;
	std::basic_string<TCHAR> sTmp;
	bool bRes=(GetTextExtentPoint32(dc, sText, n,&size)!=FALSE);
	assert(bRes);
	if(width<size.cx)
	{
		const std::basic_string<TCHAR> sEllipsis=_T("...");
		sTmp.reserve(sEllipsis.size()+n);
		sTmp.append(sEllipsis);
		sTmp.append(sText, n);
		bRes=(GetTextExtentExPoint(dc,sTmp.c_str(),sTmp.size(),width,&n,NULL,&size)!=FALSE);
		if(bRes)
		{
			if(n<static_cast<int>(sEllipsis.size()+1))
				n=sEllipsis.size()+1;
			sTmp.assign(sText, n-sEllipsis.size());
			sTmp.append(sEllipsis);
			sText=sTmp.c_str();
		}
	}	

//	UINT prevAlign=dc.SetTextAlign(TA_LEFT | TA_TOP | TA_NOUPDATECP);
	CPoint pt(prc->left,prc->top);
	if(bHorizontal)
		pt.y = (prc->bottom - prc->top-size.cy)/2+prc->top;
	else
		pt.x = prc->right-(prc->right - prc->left-size.cy)/2;
	dc.ExtTextOut(pt.x,pt.y,ETO_CLIPPED,prc,sText,n,NULL);
//	dc.SetTextAlign(prevAlign);
}
Exemplo n.º 3
0
int cgraphics_canvas_text_display_count( widget_t *widget, const char *text, int width )
{
	canvas_widget_t *cw = (canvas_widget_t *)widget;
	SIZE sz;
	int chars;
	
	cgraphics_canvas_selectfont( cw );
	
	GetTextExtentExPoint( cw->surfdata, text, strlen( text ), width, &chars, NULL, &sz );
	
	return chars;
}
Exemplo n.º 4
0
int cgraphics_canvas_text_width( widget_t *widget, const char *text, int len )
{
	canvas_widget_t *cw = (canvas_widget_t *)widget;
	SIZE sz;
	int chars;
	
	cgraphics_canvas_selectfont( cw );
	
	//GetTextExtentPoint32( cw->surfdata, text, len, &sz );
	GetTextExtentExPoint( cw->surfdata, text, len, 0, NULL, NULL, &sz );
	
	return sz.cx;
}
Exemplo n.º 5
0
void CInspectorTreeCtrl::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult) 
{
    TV_DISPINFO * pTVDispInfo = reinterpret_cast <TV_DISPINFO *> (pNMHDR);

    CTreeListItem * tli = reinterpret_cast <CTreeListItem *> (pTVDispInfo->item.lParam);
    if(tli)
    {
        static char nameBuffer[256];

        IPropertyTree * ppTree = tli->getType() == TLT_root ? NULL : GetTreeListItem(GetParentItem(pTVDispInfo->item.hItem))->queryPropertyTree();
        int origlen = tli->getDisplayName(ppTree, nameBuffer , sizeof(nameBuffer));
        
        HTREEITEM parent = NULL;
        CDC * dc = GetDC();
        dc->SetViewportOrg(0, 0);
        dc->SelectObject(GetFont());
        int fit;
        CSize sz;
        CRect rect;
        if(GetItemRect(pTVDispInfo->item.hItem, &rect, TRUE))
        {
            rect.right = getColumnWidth(0);
            GetTextExtentExPoint(dc->m_hDC, nameBuffer, origlen, rect.Width() - 2, &fit, NULL, &sz);

            if(fit < origlen)
            {
                if(fit > 3)
                {
                    strcpy(&nameBuffer[fit - 3], "...");
                    pTVDispInfo->item.pszText = nameBuffer;
                }
                else
                {
                    pTVDispInfo->item.pszText = NULL;
                }
            }
            else
            {
                pTVDispInfo->item.pszText = nameBuffer; 
            }
        }
        else
        {
            pTVDispInfo->item.pszText = NULL;   
        }
        ReleaseDC(dc);
    }
    *pResult = 0;
}
Exemplo n.º 6
0
int CorrectFitSpaceString(HDC hdc, char const *strSrc, int maxLength, char *strDst)
{	
    int strSrcLength = strlen(strSrc);
		 
	int count;
	SIZE sz;
    SIZE dot3sz;
	if(GetTextExtentExPoint(hdc, strSrc,strSrcLength,maxLength,&count,NULL,&sz)!=0){
		if(count < strSrcLength){	
            if(count>0){
                GetTextExtentPoint32(hdc, TEXT("..."), strlen(TEXT("...")), &dot3sz);
                int pointsWidth = dot3sz.cx;
				if(GetTextExtentExPoint(hdc,strSrc,strSrcLength,max(0,maxLength-pointsWidth),&count,NULL,&sz)==0) return FALSE;
                memcpy(strDst, strSrc, count);
                strncpy(strDst + count, TEXT("..."), maxLength - count - 1);
			}
			else
				strncpy(strDst, TEXT("..."), maxLength - 1);
			return TRUE;
		}
	}
		 
	return FALSE;
}
Exemplo n.º 7
0
static bool nsfont_position_in_string(const plot_font_style_t *style,
		const char *string, size_t length,
		int x, size_t *char_offset, int *actual_x)
{
	HDC hdc = GetDC(NULL);
	HFONT font = get_font(style);
	HFONT fontbak = SelectObject(hdc, font);
	SIZE s;
	int offset;
	GetTextExtentExPoint(hdc, string, length, x, &offset, NULL, &s);
	*char_offset = (size_t)offset;
	nsfont_width(style, string, *char_offset, actual_x);

	font = SelectObject(hdc, fontbak);
	DeleteObject(font);
	ReleaseDC(NULL, hdc);
	
	return true;
}
Exemplo n.º 8
0
//************************************************************************
// CLCDGfx::DrawText
//************************************************************************
void CLCDGfx::DrawText(int nX,int nY,int nWidth,tstring strText)
{
	SIZE sizeLine =  {0, 0};
	SIZE sizeCutOff = {0, 0};

	GetTextExtentPoint(GetHDC(),_T("..."),3,&sizeCutOff);

	int *piWidths = new int[strText.length()];
	int iMaxChars = 0;

	GetTextExtentExPoint(GetHDC(), strText.c_str(), (int)strText.length(), nWidth, &iMaxChars, piWidths, &sizeLine);

	if(iMaxChars < strText.length()) {
		for(iMaxChars--;iMaxChars>0;iMaxChars--)
			if(piWidths[iMaxChars] + sizeCutOff.cx <= nWidth)
				break;

		DrawText(nX,nY,(strText.substr(0,iMaxChars) + _T("...")).c_str());
	}
	else DrawText(nX,nY,strText.c_str());
	delete[] piWidths;
}
Exemplo n.º 9
0
//==========================================================================*
// Function: CalculateStatusColumnWidth
//
// Purpose:  Calculate the with of state column
//           
// Arguments: 
//     [IN] psInfo  - pointer to the WLAN_INFO structure
//
// Return Values:
//     return the width of the column
//==========================================================================*
INT CalculateStatusColumnWidth(PWLAN_INFO psInfo)
{
    HRESULT hr;
    LPTSTR  pszStatus;
    SIZE    size;
    HFONT   hFont, hFontOld;
    HDC     hDC = GetDC(psInfo->hDlg);
    INT     nWidth = 0, i;

    // Get font from the list view
    hFont = (HFONT)SendMessage(psInfo->hwndNetList, WM_GETFONT, 0, 0);
    CWR(hFont);

    hFontOld = (HFONT)SelectObject(hDC, hFont);

    for (i = IDS_WZC_STATUS_FIRST; i <= IDS_WZC_STATUS_LAST; i++)
    {
        pszStatus = (LPTSTR)LoadString(HINST_RESDLL, i, NULL, 0);
        if (pszStatus)
        {
            // Get the length of the text
            GetTextExtentExPoint(hDC, pszStatus, _tcslen(pszStatus), 0, NULL, NULL, &size);

            if (size.cx > nWidth)
            {
                nWidth = size.cx;
            }
        }
    }

    SelectObject(hDC, hFontOld);

    nWidth += AM_NETUI_WZCLISTVIEWMARGIN_CX;

Error:
    ReleaseDC(psInfo->hDlg, hDC);
    return nWidth;
}
Exemplo n.º 10
0
void DrawEllipsisText(CDC& dc,LPCTSTR sText,int n,LPRECT prc,bool bHorizontal)
{
	assert(n>0);
	long width=bHorizontal ? prc->right - prc->left : prc->bottom - prc->top;
	CSize size;
	LPTSTR sTmp=0;
	bool bRes=(GetTextExtentPoint32(dc, sText, n,&size)!=FALSE);
	assert(bRes);
	if(width<size.cx)
	{
		LPCTSTR sEllipsis=_T("...");
		const int ellipsisLen=sizeof(sEllipsis)-1;
		sTmp=new TCHAR[ellipsisLen+n];
		_tcscpy(sTmp,_T("..."));
		_tcsncpy(sTmp+ellipsisLen,sText,n);
		bRes=(GetTextExtentExPoint(dc,sTmp,ellipsisLen+n,width,&n,NULL,&size)!=FALSE);
		if(bRes)
		{
			if(n<ellipsisLen+1)
				n=ellipsisLen+1;
			_tcsncpy(sTmp,sText,n-ellipsisLen);
			_tcsncpy(sTmp+(n-ellipsisLen),sEllipsis,ellipsisLen);
			sText=sTmp;
		}
	}	

//	UINT prevAlign=dc.SetTextAlign(TA_LEFT | TA_TOP | TA_NOUPDATECP);
	CPoint pt(prc->left,prc->top);
	if(bHorizontal)
		pt.y = (prc->bottom - prc->top-size.cy)/2+prc->top;
	else
		pt.x = prc->right-(prc->right - prc->left-size.cy)/2;
	dc.ExtTextOut(pt.x,pt.y,ETO_CLIPPED,prc,sText,n,NULL);
//	dc.SetTextAlign(prevAlign);
	delete [] sTmp;
}
Exemplo n.º 11
0
void DrawEllipsisText(CDC& dc,LPCTSTR sText,int n,LPRECT prc,bool bHorizontal)
{
	assert(n>0);
	long width=bHorizontal ? prc->right - prc->left : prc->bottom - prc->top;
	CSize size;
	LPTSTR sTmp=0;
	bool bRes=(GetTextExtentPoint32(dc, sText, n,&size)!=FALSE);
	assert(bRes);
	if(width<size.cx)
	{
		LPCTSTR sEllipsis=_T("...");
      int ellipsisLen = 3;
      CString sTmp(sEllipsis);
      sTmp.Append(sText, n);

      bRes=(GetTextExtentExPoint(dc,sTmp,sTmp.GetLength(),width,&n,NULL,&size)!=FALSE);
		if(bRes)
		{
			if(n<ellipsisLen+1)
				n=ellipsisLen+1;
         sTmp.SetString(sTmp, n-ellipsisLen);
         sTmp += sEllipsis;
			sText=sTmp;
		}
	}	

//	UINT prevAlign=dc.SetTextAlign(TA_LEFT | TA_TOP | TA_NOUPDATECP);
	CPoint pt(prc->left,prc->top);
	if(bHorizontal)
		pt.y = (prc->bottom - prc->top-size.cy)/2+prc->top;
	else
		pt.x = prc->right-(prc->right - prc->left-size.cy)/2;
	dc.ExtTextOut(pt.x,pt.y,ETO_CLIPPED,prc,sText,n,NULL);
//	dc.SetTextAlign(prevAlign);
	delete [] sTmp;
}
int CXTPSyntaxEditDrawTextProcessor::DrawRowPart(CDC* pDC, int nRow, LPCTSTR pcszText, int nchCount)
{
	if (m_nDrawingRow != nRow)
	{
		if (nRow >= 0) // the new row started
			ResetRowInfo(nRow);

		m_nDrawingRow = nRow;
		m_nNextRowPosX = 0;
	}

	if (nRow == -1)
		return 0;


	//--------------------------------------------------------
	int nTextLen = 0;

	if (nchCount < 0)
	{
		nchCount = (int) _tcsclen(pcszText);
		nTextLen = (int) _tcslen(pcszText);
	}
	else
	{
#ifdef XTP_FIXED
// "nchCount" meen byte length.
// so, need not translate form TextLength to ByteLength.
		nTextLen = nchCount;
#else
		nTextLen = (int) _tcsnbcnt(pcszText, nchCount);
#endif
	}
//  ASSERT(nchCount <= (int) _tcsclen(pcszText));

	//--------------------------------------------------------
	int nY = m_rcTextRect.top + nRow * m_nRowHeight;
	int nX = m_rcTextRect.left - m_nScrollXOffset + m_nNextRowPosX;

	CRect rcText = m_rcTextRect;
	rcText.left = max(rcText.left, nX); // ENSURE THE TEXT IS CLIPPED APPROPRIATELY
	pDC->ExtTextOut(nX, nY, ETO_CLIPPED, &rcText, pcszText, nTextLen, NULL);

	//--------------------------------------------------------
	if (m_arBuf_aDx.GetSize() < nTextLen)
		m_arBuf_aDx.SetSize(nTextLen + 100);

	int nMaxExtent = m_rcTextRect.Width() + m_nScrollXOffset - m_nNextRowPosX + 30; // 30 is a gap to be sure
	nMaxExtent = max(nMaxExtent, 30);

	int nFit = 0;
	LPINT alpDx = (int*)m_arBuf_aDx.GetData();
	CSize szText(0, 0);

	BOOL bResExt = GetTextExtentExPoint(pDC->m_hAttribDC, pcszText, nTextLen,
										0,      // nMaxExtent,
										NULL,   // &nFit,
										alpDx,  // array of partial string widths
										&szText // string dimensions
									);
	nFit = nTextLen;

	VERIFY(bResExt);

	CXTPRowInfo* pRI = GetRowInfo(nRow);
	if (pRI)
	{
		if (nFit >= 0 && nFit <= nTextLen)
		{
			int i;

			LPCTSTR p = pcszText;
			LPCTSTR p_prev = pcszText;
			for (i = 0; i < nFit; i++)
			{
				pRI->arCharsEnds.AddData(m_nNextRowPosX + alpDx[i]);

				p_prev = p;
				p = _tcsinc(p);
				int nCharLen = int(p - p_prev);
#ifdef XTP_FIXED
				if (nCharLen > 1)
					pRI->arCharsEnds.AddData(m_nNextRowPosX + alpDx[i]);
				// ASSERT( nCharLen > 2 );
#endif
				i += nCharLen - 1; // skip second byte for MBCS chars.
			}
		}
		else
		{
			ASSERT(FALSE);
		}

		pRI->nMaxWidth += szText.cx;
	}

	m_nNextRowPosX += szText.cx;

	return m_nNextRowPosX;
}
Exemplo n.º 13
0
MOZCE_SHUNT_API BOOL GetTextExtentExPointI( HDC hdc, LPWORD pgiIn, int cgi,int nMaxExtent, LPINT lpnFit, LPINT alpDx, LPSIZE lpSize)
{
	return GetTextExtentExPoint(hdc, pgiIn, cgi, nMaxExtent, lpnFit, alpDx, lpSize);
}
Exemplo n.º 14
0
void
vardlg_config(HWND hwnd, WORD width, const char *banner, WORD num_prompts,
	      krb5_prompt *prompts, WORD id)
{
	int         n;
	WORD        cid;
	HDC         hdc;
	SIZE        csize;
	SIZE        maxsize;
	LONG        cx, cy;
	LONG        ccx, ccy;
	LONG        space_x, space_y;
	LONG        max_x, max_y;
	LONG        banner_y;
	RECT        rect;
	int         done;
	const char *p;

	/*
	 * First, set the banner's text.
	 */
	Static_SetText(GetDlgItem(hwnd, id), banner);

	/*
	 * Next, run through the items and set their static text.
	 * Also, set the corresponding edit string and set the
	 * maximum input length.
	 */
	cid = (id + 1);

	for (n = 0 ; n < num_prompts ; n++) {
		Static_SetText(GetDlgItem(hwnd, cid), prompts[n].prompt);
		cid++;
		Edit_SetText(GetDlgItem(hwnd, cid), "");
		Edit_LimitText(GetDlgItem(hwnd, cid), prompts[n].reply->length);
		cid++;
	}

	/*
	 * Now run through the entry fields and find the longest string.
	 */
	maxsize.cx = maxsize.cy = 0;
	cid = (id + 1);
	hdc = GetDC(GetDlgItem(hwnd, cid)); /* assume one label is the same as all the others */

	for (n = 0 ; n < num_prompts ; n++) {
		GetTextExtentPoint32(hdc, prompts[n].prompt, (int)strlen(prompts[n].prompt), &csize);
		if (csize.cx > maxsize.cx)
			maxsize.cx = csize.cx;
		if (csize.cy > maxsize.cy)
			maxsize.cy = csize.cy;
	}

#if 0
	/*
	 * convert the maximum values into pixels.  Ugh.
	 */
	rect.left = 0;
	rect.top = 0;
	rect.right = maxsize.cx;
	rect.bottom = maxsize.cy;
	MapDialogRect(hwnd, &rect);

	max_x = rect.right;
	max_y = rect.bottom;
#else
	max_x = maxsize.cx;
	max_y = (long)(((double)maxsize.cy) * 1.5);
#endif

	/*
	 * convert the spacing values, too.  Ugh.  Ugh.
	 */
	rect.left = 0;
	rect.top = 0;
	rect.right = SPACE_X;
	rect.bottom = SPACE_Y;
	MapDialogRect(hwnd, &rect);

	space_x = rect.right;
	space_y = rect.bottom;

	/*
	 * Now we know the maximum length of the string for the entry labels.  Guestimate
	 * that the entry fields should be ENTRY_PX pixels long and resize the dialog
	 * window to fit the longest string plus the entry fields (plus a little for the
	 * spacing between the edges of the windows and the static and edit fields, and
	 * between the static and edit fields themselves.)
	 */
	cx = max_x + ENTRY_PX + (space_x * 3);
	cy = (max_y + space_y) * num_prompts;

	/*
	 * resize the dialog box itself (take 1)
	 */
	SetWindowPos(hwnd, HWND_TOPMOST,
		0, 0,
		cx + 10, cy + 30,
		SWP_NOMOVE);

	/*
	 * position the dialog items.  First, the banner. (take 1)
	 */
	SetWindowPos(GetDlgItem(hwnd, id), HWND_BOTTOM,
		space_x, space_y,
		(cx - space_x * 2), max_y,
		0);

	/*
	 * Now that the window for the banner is in place, convert the width into logical units
	 * and find out how many lines we need to reserve room for.
	 */
	done = 0;
	p = banner;
	banner_y = 0;

	do {
		int nFit;
		int pDx[128];

		hdc = GetDC(GetDlgItem(hwnd, id));

		GetTextExtentExPoint(hdc, p, (int)strlen(p), cx, &nFit,
			pDx, &csize);

		banner_y += csize.cy;

		p += nFit;

	} while (*p != 0);

	banner_y += space_y;

	/*
	 * position the banner (take 2)
	 */
	SetWindowPos(GetDlgItem(hwnd, id), HWND_BOTTOM,
		space_x, space_y,
		(cx - space_x * 2), banner_y,
		0);

	/*
	 * Don't forget to include the banner estimate and the buttons, too.  Once again,
	 * assume the buttons are BUTTON_PY pixels high.  The extra three space_y's are
	 * for between the top of the dialog and the banner, between the banner and the
	 * first label, and between the buttons and the bottom of the screen.
	 */
	cy += banner_y + BUTTON_PY + (space_y * 3);

	/*
	 * resize the dialog box itself (Again...  ugh!)
	 */
	SetWindowPos(hwnd, HWND_TOPMOST,
		0, 0,
		cx + 10, cy + 30,
		SWP_NOMOVE);

	cid = (id + 1);
	ccy = banner_y + (space_y * 2);
	ccx = max_x + (space_x * 2);  /* where the edit fields start */

	for (n = 0 ; n < num_prompts ; n++) {
		SetWindowPos(GetDlgItem(hwnd, cid), HWND_BOTTOM,
			space_x, ccy,
			max_x, max_y, 0);
		cid++;
		SetWindowPos(GetDlgItem(hwnd, cid), HWND_BOTTOM,
			ccx, ccy,
			ENTRY_PX, max_y - 3, 0);
		cid++;
		ccy += (max_y + space_y);
	}

	/*
	 * Now the buttons.  If there are any entries we will have both an OK and a
	 * Cancel button.  If we don't have any entries, we will have only an OK.
	 */
	if (num_prompts == 0) {
		SetWindowPos(GetDlgItem(hwnd, IDOK), HWND_BOTTOM,
			(cx / 2), cy - space_y - BUTTON_PY,
			BUTTON_PX, BUTTON_PY, 0);
	} else {
		SetWindowPos(GetDlgItem(hwnd, IDOK), HWND_BOTTOM,
			space_x, cy - space_y - BUTTON_PY,
			BUTTON_PX, BUTTON_PY, 0);
		SetWindowPos(GetDlgItem(hwnd, IDCANCEL), HWND_BOTTOM,
			cx - space_x - BUTTON_PX, cy - space_y - BUTTON_PY,
			BUTTON_PX, BUTTON_PY, 0);
	}

	return;
}
Exemplo n.º 15
0
//************************************************************************
// CLCDInput::UpdateOffsets
//************************************************************************
void CLCDInput::UpdateOffsets(int iModified)
{
	if(m_vLineOffsets.size() == 0 && m_strText.empty())
		return;

	HDC hDC = CreateCompatibleDC(NULL);
	if(NULL == hDC)
		return;
	
	// Reset the marker
	m_Marker[0].iXLine = 0;
	m_Marker[0].iXWidth = 1;
	
	// Initialize variables
	int iLen = (int)m_strText.length();
	int *piWidths = new int[iLen];
	TCHAR *pszText = (TCHAR*)m_strText.c_str();
	tstring::size_type pos = 0;
	int iMaxChars = 0;

	SIZE sizeWord = {0, 0};
	SIZE sizeChar = {0, 0};
	SIZE sizeLine =  {0, 0};
	SelectObject(hDC, m_hFont);   

	int iLine = -1;
	// Find the first line to update
	for(int i = (int)m_vLineOffsets.size()-1; i >= 0; i--)
		if(m_vLineOffsets[i].iOffset <= m_Marker[0].iPosition)
		{
			iLine = i;
			break;
		}

	if(iModified < 0 && iLine-1 >= 0)
		iLine--;

	bool bLineClosed = false;
		
	// TRACE(_T("InputText: Begin Update at #%i\n"),iLine);
	for(;iLine<m_vLineOffsets.size();iLine++)
	{
		bLineClosed = false;

		int iChar = m_vLineOffsets[iLine].iOffset;
		int iWordOffset = iChar;
		
		if(!(iLen == 0) && iChar > iLen)
		{
			// TRACE(_T("InputText: Deleted offset #%i\n"),iLine);	
			m_vLineOffsets.erase(m_vLineOffsets.begin()+iLine);
			continue;
		}
		
		sizeLine.cx = 0;
		sizeWord.cx = 0;
		iWordOffset = iChar+1;

		while(iChar<iLen)
		{
			iWordOffset= iChar;

			GetTextExtentExPoint(hDC,pszText+iChar,iLen-iChar,GetWidth(),&iMaxChars,piWidths,&sizeLine);
			pos = m_strText.find(_T("\n"),iChar);
			// check for linebreaks
			if(pos != tstring::npos && pos >= iChar && pos <= iChar + iMaxChars)
			{
				iWordOffset = (int)pos + 1;
				iMaxChars = (int)pos - iChar;
			}
			// if the string doesnt fit, try to wrap the last word to the next line
			else
			{
				// find the last space in the line
				pos = m_strText.rfind(_T(" "),iChar + iMaxChars);
				if(pos != tstring::npos && pos >= iChar)
					iWordOffset = (int)pos +1;
				else
					iWordOffset = iChar+iMaxChars;
			}

			if(m_Marker[0].iPosition >= iChar && m_Marker[0].iPosition <= iChar + iMaxChars)
			{
				if(m_Marker[0].iPosition > iChar)
				{
					m_Marker[0].iXLine = piWidths[m_Marker[0].iPosition -1 - iChar];
					if(m_strText[m_Marker[0].iPosition -1] == '\n' )
 						m_Marker[0].iXLine = 0;
				}
				if(m_Marker[0].iPosition < iChar + iMaxChars)
				{
					if(m_strText[m_Marker[0].iPosition] > 0x001F)
						m_Marker[0].iXWidth = piWidths[m_Marker[0].iPosition - iChar]-m_Marker[0].iXLine;
				}
			}
		
			//iChar += iMaxChars;

			if(m_strText[iChar] == '\n' || sizeLine.cx > GetWidth())
			{
				
				bLineClosed = true;

				int iDistance = INFINITE;

				
				// Check if a matching offset already exists
				for(int iLine2 = iLine+1;iLine2<m_vLineOffsets.size();iLine2++)
				{
					if(m_vLineOffsets[iLine2].bLineBreak == (m_strText[iChar] == '\n'))
					{
						iDistance =  iChar - (m_vLineOffsets[iLine2].iOffset-1);
						if(m_vLineOffsets[iLine2].iOffset == iWordOffset || iDistance == iModified)	
						{
							// if there are other offsets in front of this one, delete them
							if(iLine2 != iLine + 1 )
							{						
								// TRACE(_T("InputText: Deleted offsets #%i to #%i\n"),iLine+1,iLine2-1);	
								m_vLineOffsets.erase(m_vLineOffsets.begin()+iLine+1,m_vLineOffsets.begin()+iLine2);
							}
							break;
						}
					}
				}
				// A matching offset was found
				if(iDistance == iModified)
				{
					if(iModified != 0)
					{
						// Update line's width
						if(iMaxChars > 0)
						{
							if(m_strText[iChar] == '\n' && iMaxChars >= 2)
								m_vLineOffsets[iLine].iWidth = piWidths[iMaxChars-2];
							else
								m_vLineOffsets[iLine].iWidth = piWidths[iMaxChars-1];
						}
						else
							m_vLineOffsets[iLine].iWidth = 0;

						// TRACE(_T("InputText: shifted offsets #%i to end %i position(s)\n"),iLine+1,iDistance);
						for(iLine++;iLine<m_vLineOffsets.size();iLine++)
							m_vLineOffsets[iLine].iOffset += iDistance;
						
						goto finished;
					}
				}
				// if no matching offset was found, a new one has to be created
				else if(iDistance != 0)
				{
					SLineEntry offset;
					offset.bLineBreak = (m_strText[iChar] == '\n');
					offset.iOffset = iWordOffset;
					if(iLine == m_vLineOffsets.size()-1)
						m_vLineOffsets.push_back(offset);
					else
						m_vLineOffsets.insert(m_vLineOffsets.begin()+iLine+1,offset);
					
					// TRACE(_T("InputText: Inserted new  %soffset at #%i\n"),m_strText[iChar] == '\n'?_T("linebreak "):_T(""),iLine+1);	
				}
				break;
			}

			iChar += iMaxChars;
		}
		// Update line's width
		if(iMaxChars > 0)
		{
			if(m_strText[iChar-1] == '\n' && iMaxChars >= 2)
				m_vLineOffsets[iLine].iWidth = piWidths[iMaxChars-2];
			else
				m_vLineOffsets[iLine].iWidth = piWidths[iMaxChars-1];
		}
		else
			m_vLineOffsets[iLine].iWidth = 0;

		if(iLine != m_vLineOffsets.size() - 1 && !bLineClosed)
		{
			// TRACE(_T("InputText: Deleted offsets #%i to #%i\n"),iLine+1,m_vLineOffsets.size()-1);	
			m_vLineOffsets.erase(m_vLineOffsets.begin()+iLine+1,m_vLineOffsets.end());
		}
		
	}

finished:
	delete[] piWidths;
	DeleteObject(hDC);
	
	if(m_pScrollbar)
		m_pScrollbar->SetRange(0, (int)m_vLineOffsets.size()-1);
}
Exemplo n.º 16
0
//************************************************************************
// CLCDInput::MoveMarker
//************************************************************************
void CLCDInput::MoveMarker(int iDir,int iMove,bool bShift)
{
	// Just cursor
	if(!bShift)
	{
		m_lBlinkTimer = GetTickCount();
		m_bShowMarker = true;

		if(iDir == MARKER_HORIZONTAL)
		{
			m_Marker[0].iPosition += iMove;
		
		}
		if(iDir == MARKER_VERTICAL)
		{
			if(iMove < 0 && m_Marker[0].iLine == 0)
				return;
			if(iMove > 0 && m_Marker[0].iLine == m_vLineOffsets.size()-1)
				return;

			m_Marker[0].iLine += iMove;

			int iX = 0,iX2 = 0;

			SIZE sizeChar = {0,0};
			int iBegin = m_vLineOffsets[m_Marker[0].iLine].iOffset;
			int iLen = 0;
			if(m_Marker[0].iLine < m_vLineOffsets.size() -1)
				iLen = m_vLineOffsets[m_Marker[0].iLine+1].iOffset - m_vLineOffsets[m_Marker[0].iLine].iOffset;
			else
				iLen = (int)m_strText.length() - m_vLineOffsets[m_Marker[0].iLine].iOffset;
			
			HDC hDC = CreateCompatibleDC(NULL);
			if(NULL == hDC)
				return;
			SelectObject(hDC, m_hFont);   
			m_Marker[0].iXWidth = 1;
			m_Marker[0].iPosition = -1;

			int *piWidths = new int[iLen];
			int iMaxChars;
			int iChar=iBegin;

			GetTextExtentExPoint(hDC,m_strText.c_str() + iBegin,iLen,GetWidth(),&iMaxChars,piWidths,&sizeChar);
			for(;iChar<iBegin+iMaxChars;iChar++)
			{
				iX2 = iX;
				iX = piWidths[iChar-iBegin];

				if(m_Marker[0].iPosition >= 0 &&
					iChar >= m_Marker[0].iPosition)
				{
					m_Marker[0].iXWidth = sizeChar.cx;
					break;
				}

				if(iX >= m_Marker[0].iXLine || (iChar < iBegin+iLen -1 && m_strText[iChar+1] == 10))
				{
					if( m_Marker[0].iXLine - iX2 <= iX - m_Marker[0].iXLine)
					{
						m_Marker[0].iPosition = iChar;
						m_Marker[0].iXLine = iX2;
						m_Marker[0].iXWidth = sizeChar.cx;
						break;
					}
					else
					{
						m_Marker[0].iPosition = iChar+1;
						m_Marker[0].iXLine = iX;
					}
				}
			}
			
			delete[] piWidths;

			if(m_Marker[0].iPosition == -1)
			{
				m_Marker[0].iPosition = iChar;
				m_Marker[0].iXLine = iX;
			}
			DeleteObject(hDC);
		}

		for(int i=0;i<2;i++)
		{
			if(m_Marker[i].iPosition < 0)
				m_Marker[i].iPosition = 0;
			else if(m_Marker[i].iPosition > m_strText.length()  )
				m_Marker[i].iPosition = (int)m_strText.length();
		}
		if(m_Marker[0].iPosition > 0 && m_strText[m_Marker[0].iPosition-1] == '\r')
			m_Marker[0].iPosition+= (iDir == MARKER_HORIZONTAL && iMove>0)?1:-1;

	}
}
Exemplo n.º 17
0
//************************************************************************
// updates the cutoff index
//************************************************************************
void CLCDLabel::UpdateCutOffIndex()
{
	int iLen = m_strText.length();
	
	m_vLines.clear();

	if(iLen <= 0)
	{
		m_strCutOff = _T("");
		m_iCutOffIndex = 0;
		return;
	}
	// variables
	
	HDC hDC = CreateCompatibleDC(NULL);
	SelectObject(hDC, m_hFont);   
    
	if(NULL == hDC)
		return;

	int iWidth = GetWidth();
	SIZE sizeChar = {0, 0};
	SIZE sizeLine =  {0, 0};
	SIZE sizeWord = {0,0};
	SIZE sizeCutOff = {0, 0};

	int iAvailableLines = GetHeight()/m_iFontHeight;
	// unitialized or too small labels need to be handled
	if(iAvailableLines <= 0)
		iAvailableLines = 1;

	// process wordwrapping
	int i = 0;
	if(m_bWordWrap && GetWidth() > 0)
	{
		int *piExtents = new int[m_strText.length()];
		TCHAR *szString = (TCHAR*)m_strText.c_str();
		int iMaxChars = 0;
		tstring::size_type pos = 0;

		while(i<iLen && m_vLines.size() < iAvailableLines)
		{
			GetTextExtentExPoint(hDC,szString+i,m_strText.length()-i,GetWidth(),&iMaxChars,piExtents,&sizeLine);
			
			// filter out spaces or line breaks at the beginning of a new line
			if(m_strText[i] == '\n' || m_strText[i] == ' ')
				i++;

			pos = m_strText.find(_T("\n"),i);
			// check for linebreaks
			if(pos != tstring::npos && pos != i && pos >= i && pos != i+iMaxChars)
				iMaxChars = 1 + pos - i;
			// if the string doesnt fit, try to wrap the last word to the next line
			else if(iMaxChars < iLen - i || sizeLine.cx >= GetWidth())
			{
				// find the last space in the line ( substract -1 from offset to ignore spaces as last chars )
				pos = m_strText.rfind(_T(" "),i + iMaxChars -1 );
				if(pos != tstring::npos && pos != i && pos >= i & pos != i+iMaxChars)
					iMaxChars = 1 + pos - i;
			}

			if(m_vLines.size() == iAvailableLines-1)
				iMaxChars = iLen - i;

			m_vLines.push_back(m_strText.substr(i,iMaxChars));
			i += iMaxChars;
		}
		free(piExtents);
	}
	else
		m_vLines.push_back(m_strText);

	// calculate the cutoff position

	GetTextExtentPoint(hDC,_T("..."),3,&sizeCutOff);

	int *piWidths = new int[(*--m_vLines.end()).length()];
	int iMaxChars = 0;

	GetTextExtentExPoint(hDC,(*--m_vLines.end()).c_str(),(*--m_vLines.end()).length(),iWidth,&iMaxChars,piWidths,&sizeLine);
	
	if(iMaxChars < (*--m_vLines.end()).length())
	{
		for(iMaxChars--;iMaxChars>0;iMaxChars--)
		{	
			if(piWidths[iMaxChars] + sizeCutOff.cx <= iWidth)
				break;
		}
		(*--m_vLines.end()) = (*--m_vLines.end()).substr(0,iMaxChars) + _T("...");
	}
	free(piWidths);

	DeleteObject(hDC);

	//if(GetWidth() == 0)
		m_iLineCount = 1;
	//else
	//	m_iLineCount = ceil((double)(sizeLine.cx + sizeCutOff.cx)/GetWidth());

	//if(m_iLineCount > GetHeight()/m_iFontHeight)
	//	m_iLineCount = GetHeight()/m_iFontHeight;
}
Exemplo n.º 18
0
    hr = StringCchCopy(pszReversedInput, cchReversedInput, pszInput);
    CHR(hr);
    
    // Reverse the string
    _tcsrev(pszReversedInput);

    // Get extent of ellipsis
    VBR(GetTextExtentPoint(hdcScreen, c_szEllipsis,
            cchEllipsis, &size));

    // Subtract space used up by ellipsis from width available for display string
    cxpEllipsizedExtent = (int)cxpExtent - size.cx;

    // Get number of chars of the reversed display string that fit in available space
    VBR(GetTextExtentExPoint(hdcScreen, pszReversedInput,
                cchInput, cxpEllipsizedExtent, (LPINT)&cchFit, NULL,
                &size));

    // Check if string needs to be truncated and ellipsized
    if (size.cx > (int)cxpExtent)
    {
        // Theres a problem in GetTextExtentExPoint() in that 
        // it tells us we can fit an extra character when we can't. 
        // Subtract one to be safe until this is fixed.
        cchFit--;
        
        // The original string wouldn't have fit in the space available
        // Truncate it at cchFit and concatenate an ellipsis
        pszReversedInput[cchFit] = 0;
        hr = StringCchCat(pszReversedInput, cchReversedInput, c_szEllipsis);
        CHR(hr); 
int CXTPSyntaxEditDrawTextProcessor::PrintRowPart(CDC* pDC, int nRow, int nPosY, UINT nFlags,
												  LPCTSTR pcszText, int nchCount, int *pnPrintedTextLen)
{
	if (pnPrintedTextLen)
		*pnPrintedTextLen = 0;

	if (m_nPrintingRow != nRow)
	{
		m_nPrintingRow = nRow;
		m_ptNextPrintPos = CPoint(0, 0);
	}

	if (nRow == -1)
		return 0;

	//--------------------------------------------------------
	int nTextLen = 0;

	if (nchCount < 0)
	{
		nchCount = (int)_tcsclen(pcszText);
		nTextLen = (int)_tcslen(pcszText);
	}
	else
	{
		nTextLen = (int)_tcsnbcnt(pcszText, nchCount);
	}
	ASSERT(nchCount <= (int)_tcsclen(pcszText));

	//--------------------------------------------------------
	if (m_arBuf_aDx.GetSize() < nTextLen)
		m_arBuf_aDx.SetSize(nTextLen + 100);

	LPINT alpDx = (int*)m_arBuf_aDx.GetData();

	//--------------------------------------------------------
	CRect rcText = m_rcTextRect;
	int nTextLen_rest = nTextLen;
	LPCTSTR pTxt = NULL;

	for (pTxt = pcszText; nTextLen_rest;)
	{
		int nY = m_rcTextRect.top + nPosY + m_ptNextPrintPos.y;
		int nX = m_rcTextRect.left + m_ptNextPrintPos.x;

		if (nY + GetRowHeight() > m_rcTextRect.bottom)
			break;

		//--------------------------------------------------------
		int nMaxExtent = max(0, rcText.right - nX - 20);
		int nFit = 0;

		CSize szText(0, 0);

		BOOL bResExt = GetTextExtentExPoint(
						m_bUseOutputDC ? pDC->m_hDC : pDC->m_hAttribDC,  // HDC hdc, // handle to DC
						pTxt,               // LPCTSTR lpString,         // character string
						nTextLen_rest,      // int nCount,               // number of characters
						nMaxExtent,         // maximum extent for string
						&nFit,              // LPINT lpnFit,    // maximum number of characters
						alpDx,     // array of partial string widths
						&szText //LPSIZE lpSize    // string dimensions
					);
		VERIFY(bResExt);

		//nFit = min(nFit, nTextLen_rest);

		LPCTSTR pTextToDtaw = pTxt;
		BOOL bAllTextDrawn = (nFit == nTextLen_rest);

		if (nFit > 0 && nFit <= nTextLen_rest)
		{
			CString strSeps = _T(" .,!?)-+=;\\"); //_T(" .,!?)-+=*&^%$#@~`:;\\|/");
			int nFit_wb = 0;
			int nTextLen_wb = nTextLen_rest;
			LPCTSTR pTxt_wb = pTxt;

			LPCTSTR p_prev = NULL;
			int i = 0;
			for (i = 0; i < nFit; i++)
			{
				p_prev = pTxt;
				pTxt = _tcsinc(pTxt);
				int nCharLen = int(pTxt - p_prev);
				i += nCharLen - 1; // skip second byte for MBCS chars.

				nTextLen_rest--;

				if ((nFlags & DT_WORDBREAK) && strSeps.Find(*p_prev, 0) >= 0)
				{
					nFit_wb = i+1;
					nTextLen_wb = nTextLen_rest;
					pTxt_wb = pTxt;
				}
			}

			if (!bAllTextDrawn && (nFlags & DT_WORDBREAK))
			{
				if (nFit_wb >= 0)
				{
					nFit = nFit_wb;
					nTextLen_rest = nTextLen_wb;
					pTxt = pTxt_wb;
				}
			}

			if (nFit)
			{
				m_ptNextPrintPos.x += alpDx[nFit - 1] + 1;
			}
		}

		// Draw text (if need)
		if (nFit && (nFlags & DT_CALCRECT) == 0)
		{
			rcText.left = max(rcText.left, nX); // ENSURE THE TEXT IS CLIPPED APPROPRIATELY
			pDC->ExtTextOut(nX, nY, ETO_CLIPPED, &rcText, pTextToDtaw, nFit, NULL);
		}

		CXTPRowInfo* pRI = GetRowInfo(nRow);
		if (pRI)
			pRI->nMaxWidth = m_ptNextPrintPos.x;

		// Move point to the next line (if need)
		if (!bAllTextDrawn && (nFlags & DT_SINGLELINE) == 0)
		{
			int nIconX = m_rcTextRect.left + m_ptNextPrintPos.x + 3;
			int nIconY = m_rcTextRect.top + nPosY + m_ptNextPrintPos.y;

			int nDelta = GetRowHeight() - GetRowHeight()/4;

			CPen pen1(PS_SOLID, 1, RGB(0,0,0));
			CPen pen2(PS_SOLID, 2, RGB(0,0,0));

			CPen* pPen_old = pDC->SelectObject(&pen1);

			pDC->MoveTo(nIconX, nIconY + nDelta/2);
			pDC->LineTo(nIconX, nIconY + nDelta);
			pDC->LineTo(nIconX + nDelta/2 - 1, nIconY + nDelta);

			pDC->SelectObject(&pen2);
			pDC->MoveTo(nIconX + 1, nIconY + nDelta - 1);
			pDC->LineTo(nIconX + nDelta/2, nIconY + nDelta/2);

			pDC->SelectObject(pPen_old);

			int nSublineOffsetX = m_tmText.tmAveCharWidth * 3;
			m_ptNextPrintPos.y += GetRowHeight();
			m_ptNextPrintPos.x = nSublineOffsetX;

			if (pRI)
				pRI->nMaxWidth = m_ptNextPrintPos.x;
		}
		else
		{
			break;
		}
	}

	if (pnPrintedTextLen)
	{
		int nLen0 = int(pTxt - pcszText);
		*pnPrintedTextLen = (int)_tcsnccnt(pcszText, nLen0);
	}

	return m_ptNextPrintPos.y + GetRowHeight();
}
CString CWaitDlg::GetTextWithEllipsis(CDC* pDC, CString& szString, CRect& Rect)
{
    SIZE    Size;
    int     nFit;
    int     nWidth = Rect.right-Rect.left;
    CString  EllipsisString;
    BOOL    fSuccess = FALSE;

    // Get how many chars will fit.
    fSuccess = GetTextExtentExPoint( pDC->GetSafeHdc(), 
        szString, 
        szString.GetLength(), 
        nWidth, 
        &nFit, 
        NULL, 
        &Size);
        
    // Get the dimensions of the full string.
    if(fSuccess)
        fSuccess = GetTextExtentExPoint( pDC->GetSafeHdc(), 
            szString, 
            szString.GetLength(), 
            nWidth, 
            NULL, 
            NULL, 
            &Size);
        
	if(fSuccess && nFit<szString.GetLength()) {
		// Copy to our working buffer.
		int nStart = nFit/2;
		int nRest = nFit-nStart;

        // If we need Ellipsis'.
        while(Size.cx > nWidth && fSuccess) {
			// Add them to what will fit and try again.
			EllipsisString = szString.Left(nStart);
			EllipsisString += "...";
			EllipsisString += szString.Right(nRest);
            fSuccess = GetTextExtentExPoint( pDC->GetSafeHdc(), 
					EllipsisString, 
                    EllipsisString.GetLength(), 
                    nWidth, 
                    NULL, 
                    NULL, 
                    &Size);
            nStart--; // Decrement in case we need another pass.
			nRest--;

            // Rectangle too small.
            if (nStart<=0 && nRest<=0)
				fSuccess = FALSE;
		}
		// if no success - return an empty string
		if(!fSuccess) EllipsisString = "";
        // Working buffer now contains the string with Ellipsis'.
	} else {  // Else no rectangle so return the same string we received as an input.
		EllipsisString = szString;
	}

    return EllipsisString;
}
Exemplo n.º 21
0
HRESULT IsNetworkSecure(__in __opt LPCTSTR pszSSID, BOOL fUse8021x,
        DWORD dwAuthentication, DWORD dwEncryption,
        __out __opt LPTSTR *ppszSSIDDisplay, DWORD cxpExtent, BOOL fEscapeHtml)
{
    HRESULT hr = S_FALSE;
    BOOL fSecure;
    HDC hdcScreen = NULL;

    // if 802.1x or NOT open and unencrypted then it's secure
    fSecure = fUse8021x || !( (Ndis802_11AuthModeOpen == dwAuthentication) &&
        !CWZCManagerWireless::IsEncrypted(dwEncryption) );
    
    hr = fSecure ? S_OK : S_FALSE;

    if (NULL != ppszSSIDDisplay)
    {
        TCHAR szSSIDEllipsized[MAX_SSID_LEN + ARRAYSIZE(c_szEllipsis)];
        LPVOID rgpvArgs[] = {szSSIDEllipsized};
        int cchTry, cchSSID, cchFit;
        SIZE  size;

        CPREx(pszSSID, E_INVALIDARG);

        // caller wants the string

        *ppszSSIDDisplay = NULL;
        hdcScreen = GetDC(NULL);
        cchSSID = lstrlen(pszSSID);

        // work backwards from the full string less one char
        for (cchTry = cchSSID; cchTry >= 0; cchTry--)
        {
            hr = StringCchCopyN(szSSIDEllipsized,
                ARRAYSIZE(szSSIDEllipsized), pszSSID, cchTry);
            CHR(hr);
            if (cchTry < cchSSID)
            {
                // second and successive times, ellipsize
                hr = StringCchCat(szSSIDEllipsized,
                    ARRAYSIZE(szSSIDEllipsized), c_szEllipsis);
                VHR(hr);
            }
            LocalFree(*ppszSSIDDisplay);

            CWR(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
                (LPTSTR)LoadString(HINST_RESDLL,
                fSecure ? IDS_WZC_NETSEL_FORMAT_SECURE_NETWORK :
                IDS_WZC_NETSEL_FORMAT_OPEN_NETWORK, NULL, 0), 0, 0,
                (LPTSTR)ppszSSIDDisplay, 0, (va_list *)rgpvArgs));
            VBR(GetTextExtentExPoint(hdcScreen, *ppszSSIDDisplay,
                lstrlen(*ppszSSIDDisplay), cxpExtent, &cchFit, NULL,
                &size));
            // need to continue lopping?
            if (size.cx <= (int)cxpExtent)
            {
                if (fEscapeHtml)
                {
                    // Create the escaped version of the SSID
                    hr = EscapeHtmlString(szSSIDEllipsized, ARRAYSIZE(szSSIDEllipsized));
                    CHR(hr);

                    CWR(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                        FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
                        (LPTSTR)LoadString(HINST_RESDLL,
                        fSecure ? IDS_WZC_NETSEL_FORMAT_SECURE_NETWORK :
                        IDS_WZC_NETSEL_FORMAT_OPEN_NETWORK, NULL, 0), 0, 0,
                        (LPTSTR)ppszSSIDDisplay, 0, (va_list *)rgpvArgs));
                }
                break;
            }
            
        }
        ASSERT(cchTry >= 0);

    }

Error:
    if (FAILED(hr) && (NULL != ppszSSIDDisplay) && (NULL != *ppszSSIDDisplay))
    {
        LocalFree(*ppszSSIDDisplay);
        *ppszSSIDDisplay = NULL;
    }

    if (NULL != hdcScreen)
    {
        ReleaseDC(NULL, hdcScreen);
    }

    return hr;
}