📄 stylebar.cpp
字号:
// StyleBar.cpp : implementation file
//
#include "stdafx.h"
#include "MtextDlg.h"
#include "StyleBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
#include "icad.h"
#include "icadapi.h"
#include "gr.h"
#include "DoFont.h"
#include "truetypeutils.h"
/////////////////////////////////////////////////////////////////////////////
// CMTextStyleBar
class CMTextDlg;
//#define IDC_FONTNAMES 1005
//#define IDC_FONTSIZES 1006
//#define IDC_Color 1008
BEGIN_MESSAGE_MAP(CMTextStyleBar, CToolBar)
//{{AFX_MSG_MAP(CMTextStyleBar)
ON_WM_CREATE()
ON_WM_ACTIVATE()
//}}AFX_MSG_MAP
ON_CBN_SELENDOK (IDC_ComBox_FontName, OnSelectFont)
ON_CBN_SELENDOK (IDC_ComBox_FontSize, OnSelectSize)
ON_CBN_SELENDOK (IDC_ComBox_FontColor, OnSelectColor)
ON_CBN_SELENDOK (IDC_ComBox_FontStyle, OnSelectStyle)
ON_CBN_CLOSEUP (IDC_ComBox_FontName, OnCloseUp)
ON_CBN_CLOSEUP (IDC_ComBox_FontSize, OnCloseUp)
ON_CBN_CLOSEUP (IDC_ComBox_FontColor, OnCloseUp)
ON_CBN_SELENDOK (IDC_ComBox_FontStyle, OnCloseUp)
ON_CBN_SETFOCUS (IDC_ComBox_FontSize, OnSetFocusComboSize)
ON_CBN_KILLFOCUS(IDC_ComBox_FontSize, OnKillFocusComboSize)
ON_CBN_DROPDOWN (IDC_ComBox_FontSize, OnDropdownComboSize)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMTextStyleBar message handlers
int CMTextStyleBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CHARFORMAT cf;
CMTextDlg*p=(CMTextDlg*)GetParent();
int mmmm=p->m_ctlRichText.IsBold();
m_FontSizeScale=1.0;
static int nFontSizes[] = {1.5000};
/*
static CString strColor[] = {_T("随层 256"),_T("随块 0"),_T("红色 1"),_T("黄色 2"),_T("绿色 3"),
_T("青色 4"),_T("蓝色 5"),_T("品红 6"),_T("黑白 7"),_T("选择颜色....") };
#ifdef T_L
static CString strColor[] = {_T("随层"),_T("红色"),_T("黄色"),_T("绿色"),
_T("青色"),_T("蓝色"),_T("品色"),_T("黑白"),_T("选择颜色....")};
#endif
*/
if (CToolBar::OnCreate(lpCreateStruct) == -1)
return -1;
if (!LoadToolBar (IDR_STYLE_BAR))
return -1;
CClientDC dc (this);
m_font.CreatePointFont (80, _T ("MS Sans Serif"));
CFont* pOldFont = dc.SelectObject (&m_font);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
int cxChar = tm.tmAveCharWidth;
int cyChar = tm.tmHeight + tm.tmExternalLeading;
dc.SelectObject (pOldFont);
CRect rect;
/////////////////////////////////////////////////////////////////////////
SetButtonInfo (0, IDC_ComBox_FontStyle, TBBS_SEPARATOR, cxChar * 18);
GetItemRect (0, &rect);
rect.bottom = rect.top + (cyChar * 16);
if (!m_wndFontStyle.Create (WS_VISIBLE | WS_VSCROLL |
CBS_DROPDOWNLIST | CBS_SORT, rect, this, IDC_ComBox_FontStyle))
return -1;
//rect.InflateRect(0,-1,0,100);
m_wndFontStyle.MoveWindow(rect);
m_wndFontStyle.SetFont (&m_font);
m_wndFontStyle.FillStyleComboBox();
///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
SetButtonInfo (1, IDC_ComBox_FontName, TBBS_SEPARATOR, cxChar * 27);
GetItemRect (1, &rect);
rect.bottom = rect.top + (cyChar * 16);
if (!m_wndFontNames.Create (WS_VISIBLE | WS_VSCROLL |
CBS_DROPDOWNLIST | CBS_SORT, rect, this, IDC_ComBox_FontName))
return -1;
//rect.InflateRect(0,-1,0,100);
m_wndFontNames.MoveWindow(rect);
m_wndFontNames.SetFont (&m_font);
//InitTypefaceList (&dc);
///////////////////////////////////////////////////////////////////////////
SetButtonInfo (2, IDC_ComBox_FontColor, TBBS_SEPARATOR, cxChar * 20);
m_iColorIndex=256;
GetItemRect (2, &rect);
rect.bottom = rect.top + (cyChar * 16);
if (!m_wndColor.Create (WS_CHILD | WS_VISIBLE | WS_VSCROLL |
CBS_DROPDOWNLIST|CBS_OWNERDRAWVARIABLE|WS_BORDER|WS_HSCROLL|CBS_HASSTRINGS
, rect, this, IDC_ComBox_FontColor))
return -1;
/*
for(int i=0;i<10;i++)
{
m_wndColor.AddString(strColor[i]);
}*/
LoadColorString();
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
m_wndColor.SetFont (&m_font);
m_wndColor.SetCurSel(0);
////////////////////////////////////////////////////////////////////////
SetButtonInfo (3, IDC_ComBox_FontSize, TBBS_SEPARATOR, cxChar * 15);
GetItemRect (3, &rect);
rect.bottom = rect.top + (cyChar * 14);
if (!m_wndFontSizes.Create (WS_VISIBLE | WS_VSCROLL |
CBS_DROPDOWN, rect, this, IDC_ComBox_FontSize))
return -1;
m_wndFontSizes.SetFont (&m_font);
///////////////////////////////////////////////////////////////////////
//字体大小对话筐
/*
CString string;
int index;
double realSize;
CMTextDlg::ConvertTwipsToTextHeight(realSize,Mid_FontTwips);
string.Format (_T ("%.4lf"), realSize);
index=m_wndFontSizes.AddString (string);
m_wndFontSizes.SetItemData(index,Mid_FontTwips);
m_BoxTwipToEditTwip[Mid_FontTwips]=Mid_FontTwips/m_FontSizeScale;*/
////////////////////////////////////////////////////////////////////////
mmmm=p->m_ctlRichText.IsBold();
p->m_ctlRichText.GetDefaultCharFormat(cf);
// m_wndFontNames.AddString(cf.szFaceName);
isBoldUp=TRUE;
isUnderlineUp=TRUE;
isItalicUp=TRUE;
isFoucsInComBoxSize=FALSE;
isComBoxSizeDropDown=FALSE;
return 0;
}
void CMTextStyleBar::OnSelectFont ()
{
/*
TCHAR szFaceName[LF_FACESIZE];
int nIndex = m_wndFontNames.GetCurSel();
m_wndFontNames.GetLBText (nIndex, szFaceName);
CMTextDlg*p=(CMTextDlg*)GetParent();
p->m_ctlRichText.ChangeFont(szFaceName);
CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask =CFM_FACE;
p->UpdateStackOnChange(cf);*/
CMTextDlg*p=(CMTextDlg*)GetParent();
CHARFORMAT cf;
p->m_ctlRichText.GetSelectionCharFormat(cf);
cf.dwMask = CFM_FACE | CFM_BOLD | CFM_ITALIC ;//| CFM_CHARSET;
_tcscpy(cf.szFaceName, m_wndFontNames.GetFontItem()->fontName);
//cf.bCharSet = GetSystemCharSet(); // Use system character set.
//cf.bCharSet = m_font.GetFontItem()->fontInfo()->lfCharSet;
if(m_wndFontNames.GetFontType() == SHX_FONTTYPE || m_wndFontNames.GetFontType() == SHP_FONTTYPE || m_wndFontNames.GetFontType() == SHX_BIGFONTTYPE)
{
if (cf.dwEffects & CFE_BOLD)
{
cf.dwEffects ^= CFE_BOLD;
}
if (cf.dwEffects & CFE_ITALIC)
{
cf.dwEffects ^= CFE_ITALIC;
}
CString strTTF;
CString strCAD;
strCAD=cf.szFaceName;
if(IsInFontMap(strCAD,strTTF,TRUE))
_tcscpy(cf.szFaceName,strTTF);
}
p->m_ctlRichText.SetSelectionCharFormat(cf);
p->UpdateStackOnChange(cf);
}
void CMTextStyleBar::OnSelectStyle()
{
UpdateStyle();
CMTextDlg*p=(CMTextDlg*)GetParent();
CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_SIZE|CFM_FACE;
p->m_ctlRichText.SetSel(0,-1);
p->UpdateStackOnChange(cf);
p->m_ctlRichText.SetSel(p->m_ctlRichText.GetTextLength(),p->m_ctlRichText.GetTextLength());
}
void CMTextStyleBar::OnSelectColor()
{
/*
static CString strColor[] = {_T("随层"),_T("红色"),_T("黄色"),_T("绿色"),
_T("青色"),_T("蓝色"),_T("品色"),_T("黑白"),_T("选择颜色....") };*/
int nIndex = m_wndColor.GetCurSel();
COLORREF rgbcolor;
rgbcolor=m_wndColor.GetItemData(nIndex);
if(rgbcolor==300)
{
if(m_iColorIndex==-1) {
SDS_GetColorDialog(258,&m_iColorIndex,2);
}else{
SDS_GetColorDialog(m_iColorIndex,&m_iColorIndex,2);
}
if(m_iColorIndex==258) m_iColorIndex=-1;
UpdateColorBox(m_iColorIndex);
nIndex=m_wndColor.GetCurSel();
rgbcolor=m_wndColor.GetItemData(nIndex);
}
CMTextDlg*p=(CMTextDlg*)GetParent();
p->m_ctlRichText.SetTextColor(rgbcolor);
p->m_ctlRichText.SetFocus();
}
void CMTextStyleBar::OnKillFocusComboSize()
{
if(isFoucsInComBoxSize&&!isComBoxSizeDropDown)
{
if(OnSelectSize ())
{
isFoucsInComBoxSize=FALSE;
isComBoxSizeDropDown=FALSE;
}
else
{
isFoucsInComBoxSize=TRUE;
}
}
isComBoxSizeDropDown=FALSE;
}
void CMTextStyleBar::OnDropdownComboSize()
{
isComBoxSizeDropDown=TRUE;
}
BOOL CMTextStyleBar::OnSelectSize()
{
// AfxMessageBox("On");
// TCHAR szSize[8];
// int nIndex = m_wndFontSizes.GetCurSel ();
// m_wndFontSizes.GetLBText (nIndex, szSize);
//
// int nSize = atoi (szSize) *20; // Need twips
// CMTextDlg*p=(CMTextDlg*)GetParent();
// p->m_ctlRichText.ChangeFontSize(nSize);
///////////////////////////////////////////////////
CMTextDlg*p=(CMTextDlg*)GetParent();
CString text;
LONG Twips;
double SizeFromComboBox;
if(isFoucsInComBoxSize&&!isComBoxSizeDropDown)
{
m_wndFontSizes.GetWindowText(text);
SizeFromComboBox = atof(text);
CMTextDlg::ConvertTextHeightToTwips(SizeFromComboBox,Twips);
}
else
{
m_wndFontSizes.GetLBText(m_wndFontSizes.GetCurSel(),text);
SizeFromComboBox = atof(text);
Twips=m_wndFontSizes.GetItemData(m_wndFontSizes.GetCurSel());
}
CHARFORMAT cf;
CString message;
LONG m_beginA;
LONG m_endA;
p->m_ctlRichText.GetSel(m_begin,m_end);
p->m_ctlRichText.SetSel(0,-1);
p->m_ctlRichText.GetSel(m_beginA,m_endA);
p->m_ctlRichText.SetSel(m_begin,m_end);
p->m_ctlRichText.GetSelectionCharFormat(cf);
sds_real realSizeMax;
sds_real realSizeMin;
CMTextDlg::ConvertTwipsToTextHeight(realSizeMax,Max_FontTwips*m_FontSizeScale);
CMTextDlg::ConvertTwipsToTextHeight(realSizeMin,Min_FontTwips*m_FontSizeScale);
TRACE("---m_begin: %ld|m_end: %ld|textLong: %ld ---",m_begin,m_end,p->m_ctlRichText.GetTextLength());
if ((m_begin!=0||m_end+1<m_endA)&&p->m_ctlRichText.GetTextLength()>0)
{
if (SizeFromComboBox>realSizeMax+0.0001)
{
// CMTextDlg::ConvertTwipsToTextHeight(realSize,Max_FontTwips*m_FontSizeScale);
message.Format(ResourceString(IDC_MTEXTTEXTTABDIA_TOO_LARGE,
"This value is too large in relationship to the rest of the text. The largest value you can enter is %.4lf. You may change the text size without limits by selecting the entire text."),
realSizeMax);
MessageBox( message,
ResourceString(DNT_ICADAPP_INTELLICAD_1, "IntelliCAD"),
MB_OK | MB_SETFOREGROUND);
message.Format(_T ("%.4lf"), realSizeMax);
SizeFromComboBox=realSizeMax;
Twips=Max_FontTwips*m_FontSizeScale;
m_wndFontSizes.SetWindowText(message);
//m_wndFontSizes.SetFocus();
//return FALSE;
}
if (SizeFromComboBox<realSizeMin-0.0001)
{
// CMTextDlg::ConvertTwipsToTextHeight(realSize,Min_FontTwips*m_FontSizeScale);
message.Format(ResourceString(IDC_MTEXTTEXTTABDIA_TOO_SMALL,
"This value is too small in relationship to the rest of the text. The smallest value you can enter is %.4lf. You may change the text size without limits by selecting the entire text."),
realSizeMin);
MessageBox( message,
ResourceString(DNT_ICADAPP_INTELLICAD_1, "IntelliCAD"),
MB_OK | MB_SETFOREGROUND);
message.Format(_T ("%.4lf"), realSizeMin);
SizeFromComboBox=realSizeMin;
Twips=Min_FontTwips*m_FontSizeScale;
m_wndFontSizes.SetWindowText(message);
// m_wndFontSizes.SetFocus();
// return FALSE;
}
}
else
{
if(Twips>Max_FontTwips*m_FontSizeScale||Twips<Min_FontTwips*m_FontSizeScale)
{
m_FontSizeScale=double(Twips)/Mid_FontTwips;
p->SetLineLength(p->m_dBoxWidth);
}
}
// Bugzilla No. 78034; 23-12-2002 [
cf.dwMask = CFM_SIZE;
//DP: old realization commented
//cf.yHeight = (int) ((size / 0.2) * 200 + 0.5); // .2 is default fontsize in the combo box. 200 is
//CMTextDlg::ConvertTextHeightToTwips(SizeFromComboBox, cf.yHeight); // the actual default fontsize, plus .5 to
// offset a small rounding error.
message.Format (_T("%.4lf"), SizeFromComboBox);
int index;
index=-1;//m_wndFontSizes.FindString(-1, message);
for(int i=0;i<m_wndFontSizes.GetCount();i++)
{
if(Twips==m_wndFontSizes.GetItemData(i))
{
index=i;
m_BoxTwipToEditTwip[Twips]=LONG(double(Twips+0.0001)/m_FontSizeScale);
break;
}
}
if( index== -1)
{
index = m_wndFontSizes.AddString (message);
m_wndFontSizes.SetItemData(index,Twips);
m_BoxTwipToEditTwip[Twips]=LONG(double(Twips+0.0001)/m_FontSizeScale);
}
m_wndFontSizes.SetCurSel(index);
// Bugzilla No. 78034; 23-12-2002 ]
cf.yHeight=LONG(double(Twips+0.0001)/m_FontSizeScale);
p->m_ctlRichText.SetSel(m_begin,m_end);
p->m_ctlRichText.SetSelectionCharFormat(cf);
///////////////////////////////////////////////////
isFoucsInComBoxSize =FALSE;
isComBoxSizeDropDown=FALSE;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_SIZE;
p->UpdateStackOnChange(cf);
return TRUE;
}
void CMTextStyleBar::OnSetFocusComboSize()
{
isFoucsInComBoxSize=TRUE;
}
void CMTextStyleBar::InitTypefaceList (CDC* pDC)
{
::EnumFontFamilies (pDC->m_hDC, NULL,
(FONTENUMPROC) EnumFontNameProc, (LPARAM) this);
}
int CALLBACK CMTextStyleBar::EnumFontNameProc (ENUMLOGFONT* lpelf,
NEWTEXTMETRIC* lpntm, int nFontType, LPARAM lParam)
{
CMTextStyleBar* pWnd = (CMTextStyleBar*) lParam;
int i=pWnd->m_wndFontNames.GetCount();
if (nFontType & TRUETYPE_FONTTYPE)
{
// pWnd->m_wndFontNames.InsertString(i,lpelf->elfLogFont.lfFaceName);
pWnd->m_wndFontNames.AddString(lpelf->elfLogFont.lfFaceName);
// pWnd->m_FontMap[i]=*lpelf;
}
return 1;
}
void CMTextStyleBar::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CToolBar::OnActivate(nState, pWndOther, bMinimized);
// TODO: Add your message handler code here
}
void CMTextStyleBar::IniFont()
{
this->OnSelectFont();
}
void CMTextStyleBar::OnUpdateCmdUI(CFrameWnd*pTarget,BOOL bDisableIfNoHndler)
{
// CToolBar::OnUpdateCmdUI(pTarget,bDisableIfNoHndler);
CWnd*pWnd=GetFocus();
if((pWnd==&m_wndFontNames)||(pWnd==&m_wndFontSizes)||(pWnd==&m_wndColor))
return;
if(m_wndColor.GetDroppedState())
return;
int nTwips;
TCHAR szFaceName[LF_FACESIZE];
COLORREF color;
COLORREF boxcolor;
CString strColor;
CMTextDlg*pEdit=(CMTextDlg*)GetParent();
pEdit->m_ctlRichText.GetFontInfo(szFaceName,nTwips,color);
for(int ii=m_wndColor.GetCount()-1;ii>-1;ii--)
{
boxcolor=m_wndColor.GetItemData(ii);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -