632 lines
15 KiB
C++
632 lines
15 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "GlobalUnit.h"
|
|
#include "HelpPanelUnit.h"
|
|
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
|
|
const static COLORREF clrEnter = clHighlight,//RGB( 100,180,236 ),
|
|
clrLeave = clBlue;//RGB( 67,117,233 );
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
__fastcall HelpPanelUnit::TPanel::TPanel(TComponent* AOwner)
|
|
: Vcl::Extctrls::TPanel(AOwner)
|
|
{
|
|
m_sbVert = NULL;
|
|
|
|
m_nLeftBound = 15;
|
|
m_nRightBound = 48;
|
|
m_nTopBound = 15;
|
|
m_nBottomBound = 45;
|
|
|
|
m_nRowWidth = 0;
|
|
m_nRowHight = 22;
|
|
|
|
m_iMode = 0;
|
|
m_nBeginShowRow = 0;
|
|
|
|
for( int i=0; i<MODE_NUM; i++ ){
|
|
m_aFirstRow[i] = m_aFirstTitle[i] = 0;
|
|
}
|
|
|
|
m_lblCoinPage = NULL;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall HelpPanelUnit::TPanel::CreateWnd(void)
|
|
{
|
|
Vcl::Extctrls::TPanel::CreateWnd();
|
|
|
|
if( !ParentBackground ){
|
|
if( m_imgBackground ) return;
|
|
|
|
m_sbVert = new TSkinScrollBar(this);
|
|
m_sbVert->Parent = this;
|
|
m_sbVert->m_pWndCtrl = this;
|
|
m_sbVert->Visible = false;
|
|
m_sbVert->Left = ClientWidth - m_sbVert->Width - 1;
|
|
m_sbVert->Top = 1;
|
|
m_sbVert->Height = ClientHeight-2;
|
|
|
|
CalcViewArea();
|
|
|
|
m_imgBackground = new TBitmap();
|
|
m_imgBackground->LoadFromResourceName(int(HInstance), L"CustomPanelBackground");
|
|
|
|
m_lblCoinPage = new TLabel( NULL );
|
|
m_lblCoinPage->Visible = false;
|
|
m_lblCoinPage->Transparent = true;
|
|
m_lblCoinPage->Parent = this;
|
|
m_lblCoinPage->Font->Name = "Tahoma";
|
|
// m_lblCoinPage->Font->Size = int(11 * 96.0 / g_yDpi + 0.5);
|
|
m_lblCoinPage->Font->Style = TFontStyles()<<fsUnderline;
|
|
m_lblCoinPage->Font->Color = clrLeave;
|
|
m_lblCoinPage->Caption = "官网详细说明";
|
|
m_lblCoinPage->OnClick = LinkClick;
|
|
m_lblCoinPage->OnMouseEnter = LinkMouseEnter;
|
|
m_lblCoinPage->OnMouseLeave = LinkMouseLeave;
|
|
|
|
m_lblCoinPage->Left = m_nLeftBound + 20;
|
|
}
|
|
else{
|
|
m_imgBackground = NULL;
|
|
m_imgBarTitle = NULL;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
__fastcall HelpPanelUnit::TPanel::~TPanel()
|
|
{
|
|
if( m_imgBackground )
|
|
delete m_imgBackground;
|
|
|
|
if( m_sbVert )
|
|
delete m_sbVert;
|
|
|
|
while( !m_lstLines.empty() ){
|
|
delete m_lstLines[0];
|
|
m_lstLines.erase(m_lstLines.begin());
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void HelpPanelUnit::TPanel::InitialVars()
|
|
{
|
|
RefreshTextLines();
|
|
CalcViewArea();
|
|
Invalidate();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void HelpPanelUnit::TPanel::SetTextFontSize(int size)
|
|
{
|
|
if( m_lblCoinPage )
|
|
m_lblCoinPage->Font->Size = size;
|
|
|
|
Canvas->Font->Size = size;// int(11 * 96.0 / g_yDpi + 0.5); //字母字体大小
|
|
Canvas->Font->Quality = TFontQuality::fqClearTypeNatural;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void HelpPanelUnit::TPanel::ScrollView( int nPos, bool bRedraw )
|
|
{
|
|
if( m_nBeginShowRow!=nPos ){
|
|
m_nBeginShowRow = nPos;
|
|
|
|
Invalidate();
|
|
}
|
|
|
|
if( bRedraw ){
|
|
m_sbVert->SetPosition( nPos );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void HelpPanelUnit::TPanel::CalcViewArea()
|
|
{
|
|
if( !m_sbVert )
|
|
return;
|
|
|
|
m_nRowNum = m_lstLines.size();
|
|
|
|
if( m_nRowNum>0 ){
|
|
int iFirstRow = m_aFirstRow[m_iMode];
|
|
if( iFirstRow<0 ){
|
|
int iFirstTitle = m_aFirstTitle[m_iMode];
|
|
for( iFirstRow=0; iFirstRow<m_nRowNum && iFirstTitle>0; iFirstRow++ ){
|
|
if( m_lstLines[iFirstRow]->strText.empty() ){
|
|
iFirstTitle--;
|
|
}
|
|
}
|
|
}
|
|
|
|
m_nBeginShowRow = iFirstRow;
|
|
}
|
|
|
|
if( m_nRowNum>m_nRowShow ){ //显示滚动条
|
|
m_sbVert->Visible = true;
|
|
m_sbVert->SetRange( 0, m_nRowNum-1 );
|
|
m_sbVert->SetPageSize( m_nRowShow );
|
|
m_sbVert->SetPosition( 0 );
|
|
|
|
//计算显示的第一行
|
|
|
|
int iRowScroll = 0;
|
|
if( m_nBeginShowRow>0 ){
|
|
iRowScroll = min( m_nBeginShowRow, m_nRowNum-m_nRowShow );
|
|
if( iRowScroll<0 ){
|
|
iRowScroll = 0;
|
|
}
|
|
}
|
|
|
|
ScrollView( iRowScroll );
|
|
}
|
|
else{
|
|
m_nBeginShowRow = 0;
|
|
m_sbVert->Visible = false;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall HelpPanelUnit::TPanel::Paint()
|
|
{
|
|
if( !ParentBackground && !m_lstLines.empty() ){
|
|
int xPos = m_nLeftBound,
|
|
yPos = m_nTopBound;
|
|
TColor clrOld = Canvas->Font->Color;
|
|
Canvas->Brush->Style = bsClear;
|
|
|
|
int flag = 0;
|
|
for( int i=0; i<m_lstLines.size(); i++ ){
|
|
TLineString* pLine = m_lstLines[i];
|
|
if( pLine->flag>0 && pLine->flag!=flag ){
|
|
flag = pLine->flag;
|
|
if( flag==1 ){
|
|
Canvas->Font->Color = COLOR_QUESTION;
|
|
|
|
if( m_iMode<2 )
|
|
Canvas->Font->Style = TFontStyles()<<fsBold;
|
|
}
|
|
else{
|
|
Canvas->Font->Color = COLOR_ANSWER;
|
|
Canvas->Font->Style = TFontStyles();
|
|
}
|
|
}
|
|
|
|
if( i>=m_nBeginShowRow ){
|
|
char strFlag[10];
|
|
if( pLine->flag==1 ){
|
|
if( m_iMode<2 )
|
|
strcpy( strFlag, "Q:" );
|
|
else{
|
|
strcpy( strFlag, "△" );
|
|
}
|
|
|
|
Canvas->TextOut( xPos, yPos, strFlag );
|
|
}
|
|
else if( pLine->flag==2 ){
|
|
if( m_iMode<2 )
|
|
strcpy( strFlag, "A:" );
|
|
else{
|
|
strcpy( strFlag, " " );
|
|
}
|
|
|
|
Canvas->TextOut( xPos, yPos, strFlag );
|
|
}
|
|
else if(pLine->flag == 3)
|
|
{
|
|
strcpy( strFlag, "●" );
|
|
Canvas->Font->Color = RGB(255, 0, 0);
|
|
Canvas->Font->Style = TFontStyles() << fsBold;
|
|
Canvas->TextOut( xPos, yPos, strFlag );
|
|
//Canvas->Font->Color = RGB(0, 0, 255);
|
|
}
|
|
|
|
Canvas->TextOut( xPos+20, yPos, pLine->strText.c_str() );
|
|
|
|
yPos += m_nRowHight;
|
|
}
|
|
|
|
if( i-m_nBeginShowRow >= m_nRowShow ){
|
|
break;
|
|
}
|
|
}
|
|
|
|
Canvas->Font->Color = clrOld;
|
|
Canvas->Font->Style = TFontStyles();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall HelpPanelUnit::TPanel::WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message)
|
|
{
|
|
if( m_imgBackground ){
|
|
TCanvas* tempCanvas = new TCanvas;
|
|
tempCanvas->Handle = Message.DC;
|
|
|
|
//绘制底图
|
|
int cx = ClientWidth/m_imgBackground->Width + 1;
|
|
int cy = ClientHeight/m_imgBackground->Height + 1;
|
|
for (int i=0; i<cx; i++)
|
|
for (int j=0; j<cy; j++)
|
|
tempCanvas->Draw(i*m_imgBackground->Width,
|
|
j*m_imgBackground->Height,
|
|
m_imgBackground);
|
|
|
|
//绘制外边框
|
|
tempCanvas->Brush->Color = COLOR_BORDER;
|
|
TRect rect = GetClientRect();
|
|
tempCanvas->FrameRect(rect);
|
|
|
|
delete tempCanvas;
|
|
|
|
Message.Result = true;
|
|
}
|
|
else{
|
|
DefaultHandler( &Message );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall HelpPanelUnit::TPanel::WMSize(Winapi::Messages::TWMSize &Message)
|
|
{
|
|
DefaultHandler( &Message );
|
|
|
|
if( ParentBackground )
|
|
return;
|
|
|
|
if( m_sbVert ){
|
|
m_sbVert->Left = ClientWidth - m_sbVert->Width - 1;
|
|
m_sbVert->Top = 1;
|
|
m_sbVert->Height = ClientHeight - 2;
|
|
}
|
|
|
|
m_nRowWidth = ClientWidth - m_nLeftBound - m_nRightBound;
|
|
m_nRowShow = (ClientHeight - m_nTopBound - m_nBottomBound) / m_nRowHight;
|
|
|
|
SaveFirstRow();
|
|
for(int i=0; i<MODE_NUM; i++ ){
|
|
m_aFirstRow[i] = -1; //第一行无效
|
|
}
|
|
// m_iFirstRowMode0 = m_iFirstRowMode1 = -1;
|
|
|
|
RefreshTextLines();
|
|
CalcViewArea();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall HelpPanelUnit::TPanel::WMVScroll(Winapi::Messages::TWMScroll &Message)
|
|
{
|
|
int minpos, maxpos, page, curpos;
|
|
m_sbVert->GetScrollRange(&minpos, &maxpos);
|
|
page = m_sbVert->GetPageSize();
|
|
// Get the current position of scroll box.
|
|
curpos = m_sbVert->GetScrollPos();
|
|
|
|
// Determine the new position of scroll box.
|
|
switch (Message.ScrollCode)
|
|
{
|
|
case SB_TOP: // Scroll to far top.
|
|
curpos = minpos;
|
|
break;
|
|
|
|
case SB_BOTTOM: // Scroll to far bottom.
|
|
curpos = maxpos-page+1;
|
|
break;
|
|
|
|
case SB_ENDSCROLL: // End scroll.
|
|
break;
|
|
|
|
case SB_LINEUP: // Scroll left.
|
|
if (curpos > minpos)
|
|
curpos--;
|
|
break;
|
|
|
|
case SB_LINEDOWN: // Scroll right.
|
|
if (curpos < maxpos-page+1)
|
|
curpos++;
|
|
break;
|
|
|
|
case SB_PAGEUP: // Scroll one page left.
|
|
if (curpos > minpos)
|
|
curpos = (minpos > curpos-page) ? minpos : curpos-page;
|
|
//max(minpos, curpos-page);
|
|
break;
|
|
|
|
case SB_PAGEDOWN: // Scroll one page right.
|
|
if( curpos<maxpos )
|
|
curpos = (maxpos-page+1 < curpos+page) ? maxpos-page+1 : curpos+page;
|
|
//min(maxpos-page+1, curpos+page);
|
|
break;
|
|
|
|
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
|
|
curpos = Message.Pos; // of the scroll box at the end of the drag operation.
|
|
break;
|
|
|
|
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
|
|
curpos = Message.Pos; // position that the scroll box has been dragged to.
|
|
break;
|
|
}
|
|
|
|
// Set the new position of the thumb (scroll box).
|
|
if( Message.ScrollBar!=m_sbVert->Handle )
|
|
m_sbVert->SetPosition(curpos);
|
|
|
|
ScrollView(curpos, FALSE);
|
|
|
|
Message.Result = true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall HelpPanelUnit::TPanel::WMMouseWheel(TWMMouseWheel &Message)
|
|
{
|
|
if( m_sbVert->Visible ){
|
|
UINT nSBCode;
|
|
|
|
if( Message.WheelDelta>0 ) nSBCode = SB_LINEUP;
|
|
else nSBCode = SB_LINEDOWN;
|
|
|
|
Perform( WM_VSCROLL, MAKELONG(nSBCode,0), NULL );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void HelpPanelUnit::TPanel::SetMode( int iMode )
|
|
{
|
|
if( m_iMode != iMode ){
|
|
SaveFirstRow();
|
|
|
|
if( iMode==0 || iMode==3){
|
|
m_nTopBound = 15;
|
|
}
|
|
else if( iMode==2 ){
|
|
m_nTopBound = 60;
|
|
}
|
|
else{
|
|
m_nTopBound = 160;
|
|
}
|
|
|
|
m_nRowShow = (ClientHeight - m_nTopBound - m_nBottomBound) / m_nRowHight;
|
|
|
|
m_iMode = iMode;
|
|
|
|
RefreshTextLines();
|
|
CalcViewArea();
|
|
|
|
Invalidate();
|
|
}
|
|
|
|
m_lblCoinPage->Visible = m_iMode==3;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void HelpPanelUnit::TPanel::RefreshTextLines()
|
|
{
|
|
int i;
|
|
//清空列表
|
|
for( i=0; i<m_lstLines.size(); i++ ){
|
|
delete m_lstLines[i];
|
|
}
|
|
|
|
m_lstLines.clear();
|
|
|
|
//读取字符串
|
|
int idUser = g_bLogon ? g_infoUser.accountInfo.ID : 0;
|
|
int num = 0;
|
|
|
|
if( m_iMode==0 )
|
|
f_CS_GetQnA( num, NULL, false, 0 );
|
|
else if( m_iMode==1 )
|
|
f_CS_GetQnA( num, NULL, true, idUser );
|
|
// else if( m_iMode==2 )
|
|
// f_CS_GetNotice( num, NULL, 0 );
|
|
else if( m_iMode==2 && idUser )
|
|
f_CS_GetNotice( num, NULL, idUser );
|
|
else if(m_iMode == 3)
|
|
ReadData();
|
|
|
|
if( num>0 ){
|
|
TSTRINGPAIR* arrString = new TSTRINGPAIR[num];
|
|
bool bRevert = true;
|
|
|
|
if( m_iMode==0 ){
|
|
f_CS_GetQnA( num, arrString, false, 0 );
|
|
bRevert = false;
|
|
}
|
|
else if( m_iMode==1 )
|
|
f_CS_GetQnA( num, arrString, true, idUser );
|
|
// else if( m_iMode==2 )
|
|
// f_CS_GetNotice( num, arrString, 0 );
|
|
else if( m_iMode==2 )
|
|
f_CS_GetNotice( num, arrString, idUser );
|
|
|
|
for( i=(bRevert?num-1:0); bRevert?i>=0:i<num; bRevert?i--:i++ ){
|
|
//处理提问
|
|
wstring strQ = str2wstr( UTF8ToMBCS( arrString[i].str1 ) );
|
|
TLineString * pLine = new TLineString;
|
|
pLine->flag = 1; //question
|
|
int nWidth = 0;
|
|
int iStart = 0;
|
|
for(int j=0; j<strQ.size(); j++ ){
|
|
nWidth += Canvas->TextWidth( strQ[j] );
|
|
if( nWidth>=m_nRowWidth || strQ[j]=='\n' ){
|
|
pLine->strText = strQ.substr( iStart, j-iStart );
|
|
|
|
if( strQ[j]=='\n' ) j++;
|
|
|
|
iStart = j;
|
|
nWidth = 0;
|
|
|
|
m_lstLines.push_back( pLine );
|
|
|
|
if( iStart<strQ.size() ){
|
|
pLine = new TLineString;
|
|
}
|
|
}
|
|
}
|
|
|
|
if( iStart<strQ.size() ){
|
|
pLine->strText = strQ.substr( iStart, strQ.size()-iStart );
|
|
m_lstLines.push_back( pLine );
|
|
}
|
|
|
|
wstring strA;
|
|
if( m_iMode==2 ){
|
|
AnsiString strSpace= L" ";
|
|
AnsiString anStr = arrString[i].str2;
|
|
int pos = 0;
|
|
while( pos = anStr.Pos( strSpace ) ){
|
|
anStr.Delete( pos, strSpace.Length() );
|
|
anStr.Insert( L" ", pos );
|
|
}
|
|
strA = str2wstr( UTF8ToMBCS( anStr.c_str() ) );
|
|
}
|
|
else{
|
|
strA = str2wstr( UTF8ToMBCS( arrString[i].str2 ) );
|
|
}
|
|
|
|
pLine = new TLineString;
|
|
pLine->flag = 2; //answer
|
|
if( strA.size()>0 ){
|
|
nWidth = 0;
|
|
iStart = 0;
|
|
for(int j=0; j<strA.size(); j++ ){
|
|
nWidth += Canvas->TextWidth( strA[j] );
|
|
if( nWidth>=m_nRowWidth || strA[j]=='\n' ){
|
|
pLine->strText = strA.substr( iStart, j-iStart );
|
|
|
|
if( strA[j]=='\n' ) j++;
|
|
|
|
iStart = j;
|
|
nWidth = 0;
|
|
|
|
m_lstLines.push_back( pLine );
|
|
|
|
if( iStart<strA.size() ){
|
|
pLine = new TLineString;
|
|
}
|
|
}
|
|
}
|
|
|
|
if( iStart<strA.size() ){
|
|
pLine->strText = strA.substr( iStart, strA.size()-iStart );
|
|
m_lstLines.push_back( pLine );
|
|
}
|
|
}
|
|
else{
|
|
pLine->strText = L"暂时还没有答复";
|
|
m_lstLines.push_back( pLine );
|
|
}
|
|
|
|
if( bRevert ? i>0 : i<num-1 ){ //break
|
|
pLine = new TLineString;
|
|
m_lstLines.push_back( pLine );
|
|
}
|
|
}
|
|
|
|
delete[] arrString;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void HelpPanelUnit::TPanel::AddFeedback( wstring str )
|
|
{
|
|
RefreshTextLines();
|
|
m_nBeginShowRow = 0;
|
|
CalcViewArea();
|
|
Invalidate();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void HelpPanelUnit::TPanel::SaveFirstRow()
|
|
{
|
|
int iFirstRow = m_nBeginShowRow;
|
|
int iFirstTitle = 0;
|
|
|
|
for( int i=0; i<m_lstLines.size() && i<=iFirstRow; i++ ){
|
|
if( m_lstLines[i]->strText.empty() ){
|
|
iFirstTitle++;
|
|
}
|
|
}
|
|
|
|
m_aFirstRow[m_iMode] = iFirstRow;
|
|
m_aFirstTitle[m_iMode] = iFirstTitle;
|
|
}
|
|
|
|
void HelpPanelUnit::TPanel::ReadData()
|
|
{
|
|
String str = L"@说明:\n 唱作音符是唱作网的虚拟货币,在唱作魔方软件使用中会\
|
|
用到唱作音符。\n@获取途径:\n 唱作音符主要来源于充值兑换,在唱作网的\
|
|
活动中也可获取。\n 另外,注册用户时也会赠予一定音符。\n";
|
|
|
|
wchar_t *data = str.c_str();
|
|
|
|
TLineString *pLine = new TLineString;
|
|
|
|
int nWidth = 0;
|
|
int iStart = 0;
|
|
|
|
for(int i = 0; i < str.Length(); i++)
|
|
{
|
|
nWidth += Canvas->TextWidth(String(data[i]));
|
|
|
|
if(nWidth >= m_nRowWidth || data[i] == '\n')
|
|
{
|
|
if(data[iStart] == L'@')
|
|
{
|
|
pLine->strText = (str.SubString(iStart + 2, i - iStart + 1)).c_str();
|
|
pLine->flag = 3;
|
|
}
|
|
else
|
|
{
|
|
pLine->flag = 4;
|
|
pLine->strText = (str.SubString(iStart, i - iStart + 1)).c_str();
|
|
}
|
|
|
|
|
|
if(data[i] == '\n')
|
|
{
|
|
i++;
|
|
}
|
|
|
|
iStart = i;
|
|
|
|
nWidth = 0;
|
|
m_lstLines.push_back(pLine);
|
|
pLine = new TLineString;
|
|
}
|
|
}
|
|
|
|
pLine->strText = (str.SubString(iStart, str.Length() - iStart + 1)).c_str();
|
|
pLine->flag = 4;
|
|
m_lstLines.push_back(pLine);
|
|
|
|
m_lblCoinPage->Top = m_nTopBound + ( m_lstLines.size() + 1 ) * m_nRowHight;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall HelpPanelUnit::TPanel::LinkClick(TObject *Sender)
|
|
{
|
|
char strURL[256];
|
|
f_CS_GetWebPageURL( URL_COINSPEC, strURL );
|
|
|
|
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall HelpPanelUnit::TPanel::LinkMouseEnter(TObject *Sender)
|
|
{
|
|
((TLabel*)Sender)->Font->Color = clrEnter;
|
|
Screen->Cursor = crHandPoint;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall HelpPanelUnit::TPanel::LinkMouseLeave(TObject *Sender)
|
|
{
|
|
((TLabel*)Sender)->Font->Color = clrLeave;
|
|
Screen->Cursor = crDefault;
|
|
}
|
|
//---------------------------------------------------------------------------
|