//--------------------------------------------------------------------------- #include #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; iParent = 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()<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; iFirstRow0; 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; iflag>0 && pLine->flag!=flag ){ flag = pLine->flag; if( flag==1 ){ Canvas->Font->Color = COLOR_QUESTION; if( m_iMode<2 ) Canvas->Font->Style = TFontStyles()<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; iDraw(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; iGetScrollRange(&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( curposHandle ) 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; i0 ){ 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:iflag = 1; //question int nWidth = 0; int iStart = 0; for(int j=0; jTextWidth( 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( iStartstrText = 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; jTextWidth( 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( iStartstrText = strA.substr( iStart, strA.size()-iStart ); m_lstLines.push_back( pLine ); } } else{ pLine->strText = L"暂时还没有答复"; m_lstLines.push_back( pLine ); } if( bRevert ? i>0 : istrText.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; } //---------------------------------------------------------------------------