Hello,
Recently I found this great library, many thanks to Francisco Campos for it and also thanks for good examples.
I came across one problem. In my application I would like to use CGuiTabWnd class for multiple views and align tabs at the top of the window. Aligning tabs at the bottom was perfect but at the top... After looking to the source I found that aligning at the top was intended. So I tried to fix it. You can found the full listing of the source code below.
Also I've added a small feature, when user selects some tab the text in the caption of the tab becomes bold (like tabs in VS .NET). A bold caption is enabled by default, but you can disable it, just add the next line in any place of your code:
m_MyTabWindow.SetBoldText( FALSE );
To align tabs at the top of the window add this line:
m_MyTabWindow.SetALingTabs( CGuiTabWnd::ALN_TOP );
Changes:
Add the following to the GuiTabWnd.h
public:<br />
void SetBoldText(BOOL bBold=TRUE);<br />
<br />
protected:<br />
BOOL m_bBold;
And here is a full GuiTabWnd.cpp:
<br />
#include "stdafx.h"<br />
<br />
#include "GuiTabWnd.h"<br />
#include "GuiBasetab.h"<br />
#include "resource.h"<br />
<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif<br />
<br />
<br />
#define SPACE_TAB 4<br />
#define DEFAULT_FLAT 18<br />
<br />
CGuiTabWnd::CGuiTabWnd()<br />
{<br />
m_rectCliente.SetRectEmpty();<br />
m_rectTab.SetRectEmpty();<br />
m_ActualVar=0;<br />
m_Numtabs=0;<br />
m_iSelectTab=0;<br />
m_sizeImag=CSize(15,15);<br />
m_pArray.RemoveAll();<br />
m_iMinValRec=0;
m_cfont.CreateFont(-11,0,0,0,400,0,0,0,RUSSIAN_CHARSET ,1,2,1,34,"MS Sans Serif");<br />
m_cfontBold.CreateFont(-11,2,0,0,FW_BOLD,0,0,0,RUSSIAN_CHARSET,1,2,1,34,"MS Sans Serif");<br />
m_style=S3D;<br />
m_ActualTitle=TRUE;<br />
m_alnTab=ALN_BOTTOM;<br />
m_TypeTab=TYPE_NORMAL;<br />
m_StyleDisplay=GUISTYLE_XP;<br />
m_bBold = TRUE;<br />
}<br />
<br />
CGuiTabWnd::~CGuiTabWnd()<br />
{<br />
m_pArray.RemoveAll();<br />
}<br />
<br />
<br />
BEGIN_MESSAGE_MAP(CGuiTabWnd, CWnd)<br />
ON_WM_ERASEBKGND()<br />
ON_WM_PAINT()<br />
ON_WM_CREATE()<br />
ON_WM_SIZE()<br />
ON_WM_LBUTTONDOWN()<br />
ON_WM_SYSCOLORCHANGE()<br />
ON_WM_RBUTTONDOWN()<br />
ON_WM_DESTROY()<br />
END_MESSAGE_MAP()<br />
<br />
<br />
BOOL CGuiTabWnd::PreTranslateMessage(MSG* pMsg) <br />
{<br />
if (pMsg->message == WM_MOUSEMOVE)<br />
CToolTip.RelayEvent(pMsg);<br />
<br />
return CWnd::PreTranslateMessage(pMsg);<br />
}<br />
<br />
void CGuiTabWnd::OnSysColorChange( )<br />
{<br />
CWnd::OnSysColorChange( );<br />
<br />
}<br />
<br />
void CGuiTabWnd::SetTypeTab(TypeTab Type)<br />
{<br />
m_TypeTab=Type;<br />
}<br />
BOOL CGuiTabWnd::OnEraseBkgnd(CDC* pDC) <br />
{<br />
if (m_Numtabs == 0)<br />
{<br />
CBrush cbr;<br />
cbr.CreateSysColorBrush(GuiDrawLayer::GetRGBColorFace(m_StyleDisplay));<br />
CRect m_rect;<br />
GetClientRect(m_rect);<br />
pDC->FillRect(m_rect,&cbr);<br />
cbr.DeleteObject();<br />
<br />
}<br />
return TRUE;<br />
}<br />
<br />
void CGuiTabWnd::SetActualTitle(BOOL bActual)<br />
{<br />
m_ActualTitle=bActual;<br />
}<br />
<br />
void CGuiTabWnd::SetALingTabs(AlingTab alnTab)<br />
{<br />
m_alnTab=alnTab;<br />
Invalidate();<br />
UpdateWindow();<br />
}<br />
<br />
void CGuiTabWnd::OnPaint() <br />
{<br />
<br />
CPaintDC dc(this);
if (m_Numtabs <=0) return;<br />
CBrush cbr;<br />
CRect m_rectDraw;<br />
CGuiTab* ct=(CGuiTab*) m_pArray[m_iSelectTab];<br />
<br />
cbr.CreateSolidBrush((GuiDrawLayer::m_Style== GUISTYLE_XP)?GuiDrawLayer::GetRGBColorTabs(): ct->m_clrHtab);<br />
GetClientRect(m_rectCliente);<br />
m_rectTab=m_rectCliente;<br />
m_rectDraw=m_rectCliente;<br />
if (m_alnTab==ALN_BOTTOM)<br />
{<br />
m_rectDraw.bottom=m_rectCliente.bottom-(m_sizeImag.cy+SPACE_TAB+2); <br />
}<br />
else<br />
{<br />
m_rectDraw.top=m_rectCliente.top+(m_sizeImag.cy+SPACE_TAB+2);<br />
}<br />
<br />
<br />
dc.FillRect(m_rectTab,&cbr);<br />
m_rectDraw.left+=1;<br />
dc.Draw3dRect(m_rectDraw,GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style),GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style));<br />
if (GuiDrawLayer::m_Style!= GUISTYLE_XP)<br />
{<br />
m_rectDraw.top=m_rectDraw.bottom-1;<br />
m_rectDraw.left+=1;<br />
m_rectDraw.right-=1;<br />
dc.Draw3dRect(m_rectDraw,ct->m_clrHtab,ct->m_clrHtab);<br />
<br />
}<br />
m_rectDraw.left-=1;<br />
<br />
cbr.DeleteObject ();<br />
Drawtabs(&dc);<br />
}<br />
<br />
<br />
<br />
BOOL CGuiTabWnd::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID) <br />
{<br />
pParent= pParentWnd;<br />
return CWnd::Create(NULL, _T(""), dwStyle |WS_CLIPSIBLINGS|WS_CLIPCHILDREN, rect, pParentWnd, nID);<br />
}<br />
<br />
int CGuiTabWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) <br />
{<br />
if (CWnd::OnCreate(lpCreateStruct) == -1)<br />
return -1;<br />
CToolTip.Create(this,TTS_ALWAYSTIP);<br />
CToolTip.Activate(TRUE);<br />
CToolTip.BringWindowToTop();<br />
<br />
return 0;<br />
}<br />
<br />
<br />
void CGuiTabWnd::RecalLayout()<br />
{<br />
GetClientRect(m_rectCliente);<br />
m_rectCliente.DeflateRect(1,1);<br />
<br />
if (m_style == S3D)<br />
{<br />
if (m_alnTab==ALN_BOTTOM)<br />
m_rectCliente.bottom=m_rectCliente.bottom-(m_sizeImag.cy+SPACE_TAB+1);<br />
else<br />
{<br />
m_rectCliente.top=m_rectCliente.top+(m_sizeImag.cy+SPACE_TAB+2);<br />
m_rectCliente.bottom=m_rectCliente.bottom-(DEFAULT_FLAT+4);
}<br />
<br />
}<br />
else<br />
{<br />
if (m_alnTab==ALN_BOTTOM)<br />
m_rectCliente.bottom=m_rectCliente.bottom-(m_sizeImag.cy+SPACE_TAB+1);<br />
else<br />
{<br />
m_rectCliente.top+=DEFAULT_FLAT;<br />
m_rectCliente.bottom=m_rectCliente.bottom-(DEFAULT_FLAT+4);
}<br />
}<br />
<br />
for (int iCont=0; iCont< m_Numtabs;iCont++)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[iCont];<br />
CWnd* m_tempWin= ct->pParent;<br />
ASSERT_VALID(m_tempWin);<br />
if (m_style == S3D)<br />
{<br />
m_tempWin->SetWindowPos(NULL,m_rectCliente.left+(SPACE_TAB-2),<br />
m_rectCliente.top+(SPACE_TAB/2),m_rectCliente.right-(SPACE_TAB+1),<br />
m_rectCliente.bottom-(SPACE_TAB+(m_alnTab==ALN_BOTTOM?2:0)),SWP_NOACTIVATE|SWP_NOZORDER);<br />
}<br />
else<br />
{<br />
if (m_alnTab==ALN_BOTTOM)<br />
{<br />
m_tempWin->SetWindowPos(NULL,m_rectCliente.left+(SPACE_TAB-2),<br />
m_rectCliente.top+(SPACE_TAB/2),m_rectCliente.right-(SPACE_TAB+1),<br />
m_rectCliente.bottom-(SPACE_TAB+2),SWP_NOACTIVATE|SWP_NOZORDER);<br />
}<br />
else<br />
{ <br />
if (m_TypeTab == TYPE_NORMAL)<br />
{<br />
m_tempWin->SetWindowPos(NULL,m_rectCliente.left+(SPACE_TAB-2),<br />
m_rectCliente.top+(SPACE_TAB+2),m_rectCliente.right-(SPACE_TAB+1),<br />
m_rectCliente.bottom-SPACE_TAB,SWP_NOACTIVATE|SWP_NOZORDER);<br />
}<br />
}<br />
}<br />
}<br />
AjustTabs();<br />
Invalidate();<br />
UpdateWindow();<br />
}<br />
<br />
<br />
void CGuiTabWnd::AjustTabs()<br />
{<br />
int m_iSizeAct=0;<br />
m_iMinValRec=4;<br />
CClientDC dc(this);<br />
GetClientRect(m_rectCliente);<br />
if (m_alnTab==ALN_BOTTOM)<br />
m_rectCliente.bottom=m_rectCliente.bottom-(m_sizeImag.cy+SPACE_TAB+1);<br />
else<br />
m_rectCliente.bottom=m_rectCliente.top+(m_sizeImag.cy+SPACE_TAB+1);<br />
<br />
CFont* m_fontOld;<br />
for (int iCont=0; iCont< m_Numtabs;iCont++)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[iCont];<br />
<br />
if (iCont != m_iSelectTab || m_bBold == FALSE )<br />
m_fontOld=dc.SelectObject(&m_cfont);<br />
else<br />
m_fontOld=dc.SelectObject(&m_cfontBold);<br />
<br />
CRect m_Arect;<br />
CSize m_sChar=dc.GetTextExtent(ct->lpMsg);<br />
m_Arect.left=m_iMinValRec+1;<br />
m_iMinValRec += m_sizeImag.cx+2+m_sChar.cx+14;<br />
if(m_alnTab==ALN_BOTTOM)<br />
{<br />
m_Arect.top=m_rectCliente.bottom;<br />
m_Arect.right=m_iMinValRec;<br />
m_Arect.bottom=m_rectCliente.bottom+4+m_sizeImag.cy;<br />
}<br />
else<br />
{<br />
m_Arect.top=m_rectCliente.top+3;<br />
m_Arect.right=m_iMinValRec;<br />
m_Arect.bottom=m_rectCliente.top+6+m_sizeImag.cy;<br />
}<br />
ct->rect= m_Arect;<br />
dc.SelectObject(m_fontOld);<br />
}<br />
int m_NewResize=4;<br />
if (m_iMinValRec > m_rectCliente.Width()-4)<br />
{<br />
m_iSizeAct=(m_rectCliente.Width()-12)/m_Numtabs;<br />
for (int iCont=0; iCont< m_Numtabs;iCont++)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[iCont];<br />
CRect m_Arect;<br />
m_Arect.left=m_NewResize;<br />
if(m_alnTab==ALN_BOTTOM)<br />
{<br />
m_Arect.right=m_NewResize+m_iSizeAct;<br />
m_Arect.top=m_rectCliente.bottom;<br />
m_Arect.bottom=m_rectCliente.bottom+4+m_sizeImag.cy;<br />
}<br />
else<br />
{<br />
m_Arect.right=m_NewResize+m_iSizeAct;<br />
m_Arect.top=m_rectCliente.top + 3;<br />
m_Arect.bottom=m_rectCliente.top+6+m_sizeImag.cy;<br />
}<br />
m_NewResize+=m_iSizeAct+1;<br />
ct->rect= m_Arect;<br />
} <br />
}<br />
<br />
}<br />
<br />
void CGuiTabWnd::Drawtabs(CDC* dc)<br />
{<br />
CPen light(PS_SOLID,1,GetSysColor(COLOR_BTNHIGHLIGHT));<br />
CPen Dark(PS_SOLID,1,GuiDrawLayer::GetRGBColorShadow(m_StyleDisplay));<br />
CPen Black(PS_SOLID,1,GetSysColor(BLACK_PEN)); <br />
CPen pPress(PS_SOLID,1,GuiDrawLayer::GetRGBCaptionXP());<br />
CRect rectText;<br />
CFont* m_fontOld;<br />
CPen* oldPen= dc->SelectObject(&light);<br />
CString szStrPoints=_T("...");<br />
CRect rcClient;<br />
GetClientRect(rcClient);<br />
m_rectTab = rcClient;<br />
if(m_StyleDisplay== GUISTYLE_2003)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[m_iSelectTab];<br />
<br />
CGradient M( CSize( m_rectTab.Width(),ct->rect.Height()+(m_alnTab==ALN_BOTTOM?1:2) ) ); <br />
M.PrepareReverseVertTab(dc,m_StyleDisplay);<br />
if( m_alnTab==ALN_BOTTOM )<br />
M.Draw(dc,0,m_rectTab.bottom-ct->rect.Height(),0,0,<br />
m_rectTab.Width(),ct->rect.Height(),SRCCOPY);<br />
else<br />
M.Draw(dc,0,0,0,0,<br />
m_rectTab.Width(),m_rectTab.Height()+2,SRCCOPY);<br />
dc->LineTo(m_rectTab.left, m_rectTab.bottom+3);<br />
dc->MoveTo(m_rectTab.right, m_rectTab.bottom+3);<br />
}<br />
for (int iCont=0; iCont< m_Numtabs;iCont++)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[iCont];<br />
<br />
if ( iCont !=m_iSelectTab || m_bBold == FALSE )<br />
m_fontOld=dc->SelectObject(&m_cfont);<br />
else<br />
m_fontOld=dc->SelectObject(&m_cfontBold);<br />
<br />
if(m_StyleDisplay== GUISTYLE_2003)<br />
{<br />
CRect m_rectTabAux=ct->rect;<br />
CGradient M(CSize(m_rectTabAux.Width(),m_rectTabAux.Height())); <br />
if( m_alnTab==ALN_BOTTOM )<br />
{<br />
M.PrepareReverseColorTab(dc,GUISTYLE_2003,ct->m_clrHtab,ct->m_clrLTab);
M.Draw(dc,m_rectTabAux.left+1,m_rectTabAux.top,0,0,m_rectTabAux.Width()-1,m_rectTabAux.Height()-1,SRCCOPY);<br />
}<br />
else<br />
{<br />
M.PrepareReverseColorTab( dc, GUISTYLE_2003, ct->m_clrLTab, ct->m_clrHtab );
M.Draw(dc,m_rectTabAux.left+1,m_rectTabAux.top,0,0,m_rectTabAux.Width()-1,m_rectTabAux.Height(),SRCCOPY);<br />
}<br />
CPen* pOldPen=dc->SelectObject(&Dark);<br />
if(iCont ==0)<br />
{<br />
dc->MoveTo(m_rectTabAux.left, m_rectTabAux.top);<br />
if( m_alnTab==ALN_BOTTOM )<br />
{<br />
dc->LineTo(m_rectTabAux.left, m_rectTabAux.bottom-2);<br />
<br />
dc->SetPixel(rcClient.left+1, m_rectTabAux.top-2, GuiDrawLayer::GetRGBColorShadow(m_StyleDisplay) );<br />
}<br />
else<br />
dc->LineTo(m_rectTabAux.left, m_rectTabAux.bottom);<br />
}<br />
if( m_alnTab==ALN_BOTTOM )<br />
{<br />
dc->MoveTo(m_rectTabAux.left, m_rectTabAux.bottom-2);<br />
dc->LineTo(m_rectTabAux.left+1, m_rectTabAux.bottom-1);<br />
<br />
dc->MoveTo(m_rectTabAux.left+1, m_rectTabAux.bottom-1);<br />
dc->LineTo(m_rectTabAux.right-2,m_rectTabAux.bottom-1 );<br />
<br />
dc->MoveTo(m_rectTabAux.right-2,m_rectTabAux.bottom-1 );<br />
dc->LineTo(m_rectTabAux.right, m_rectTabAux.bottom-3);<br />
<br />
dc->MoveTo(m_rectTabAux.right, m_rectTabAux.bottom-3);<br />
dc->LineTo(m_rectTabAux.right, m_rectTabAux.top-1);<br />
}<br />
else<br />
{<br />
dc->MoveTo( m_rectTabAux.left+1, m_rectTabAux.top-1 );
dc->LineTo( m_rectTabAux.right-1,m_rectTabAux.top-1 );<br />
<br />
dc->MoveTo(m_rectTabAux.right, m_rectTabAux.bottom-1 );
dc->LineTo(m_rectTabAux.right, m_rectTabAux.top );<br />
<br />
dc->MoveTo(m_rectTabAux.right-2,m_rectTabAux.top-1 );
dc->LineTo(m_rectTabAux.right+1, m_rectTabAux.top+2);<br />
<br />
if ( iCont )<br />
{<br />
dc->MoveTo(m_rectTabAux.left, m_rectTabAux.top );
dc->LineTo(m_rectTabAux.left+1, m_rectTabAux.top-1 );<br />
}<br />
}<br />
if (iCont == m_iSelectTab)<br />
{<br />
if( m_alnTab==ALN_BOTTOM )<br />
{<br />
dc->MoveTo(rcClient.left+1, m_rectTabAux.top-1);<br />
dc->LineTo(m_rectTabAux.left, m_rectTabAux.top-1);<br />
dc->MoveTo(m_rectTabAux.right, m_rectTabAux.top-1);<br />
dc->LineTo(rcClient.right, m_rectTabAux.top-1);<br />
}<br />
else<br />
{<br />
CPen pBott(PS_SOLID,1,ct->m_clrHtab);<br />
CPen* pOldPen2 = dc->SelectObject( &pBott );<br />
dc->MoveTo( m_rectTabAux.left+(iCont!=0?0:1), m_rectTabAux.bottom );<br />
dc->LineTo( m_rectTabAux.right, m_rectTabAux.bottom );<br />
dc->SelectObject( pOldPen2 );<br />
}<br />
}<br />
dc->SelectObject(pOldPen);<br />
}<br />
<br />
if(m_StyleDisplay== GUISTYLE_XP)<br />
{<br />
if (iCont ==m_iSelectTab)<br />
{<br />
CBrush cbr;<br />
CRect m_rectTabAux=ct->rect;<br />
m_rectTabAux.DeflateRect(1,1);<br />
m_rectTabAux.top-=4; <br />
m_rectTabAux.bottom=m_rectTabAux.top+4;<br />
cbr.CreateSysColorBrush(COLOR_BTNFACE);<br />
<br />
if( m_alnTab==ALN_TOP )<br />
{<br />
ct->rect.bottom += 2;<br />
ct->rect.right -= 1;<br />
}<br />
dc->FillRect(ct->rect,&cbr);<br />
dc->MoveTo(ct->rect.left,ct->rect.top-3);<br />
dc->LineTo(ct->rect.left,ct->rect.bottom);<br />
dc->FillRect(m_rectTabAux,&cbr);<br />
if( m_alnTab==ALN_TOP )<br />
{<br />
ct->rect.bottom -= 2;<br />
ct->rect.right += 1;<br />
}<br />
<br />
dc->SelectStockObject(BLACK_PEN);<br />
if( m_alnTab==ALN_BOTTOM )<br />
{<br />
dc->MoveTo(ct->rect.left,ct->rect.bottom-1);<br />
dc->LineTo(ct->rect.right,ct->rect.bottom-1);<br />
}<br />
else<br />
{<br />
CPen* pOldPen2 = dc->SelectObject( &light );<br />
dc->MoveTo(ct->rect.left,ct->rect.top-3);<br />
dc->LineTo(ct->rect.right,ct->rect.top-3);<br />
dc->SelectObject( pOldPen2 );<br />
}<br />
<br />
<br />
dc->SelectStockObject(BLACK_PEN);<br />
if( m_alnTab==ALN_BOTTOM )<br />
{<br />
dc->MoveTo(ct->rect.right-1,ct->rect.top-1);<br />
dc->LineTo(ct->rect.right-1,ct->rect.bottom-1);<br />
}<br />
else<br />
{<br />
dc->MoveTo(ct->rect.right-1,ct->rect.top-2);<br />
dc->LineTo(ct->rect.right-1,ct->rect.bottom);<br />
}<br />
cbr.DeleteObject();<br />
<br />
}<br />
else<br />
{<br />
<br />
if(m_StyleDisplay== GUISTYLE_XP)<br />
{<br />
if ((iCont+1) != m_iSelectTab)<br />
{<br />
CPen* pOldPen=dc->SelectObject(&Dark);<br />
dc->MoveTo(ct->rect.right-1,ct->rect.top+2);<br />
dc->LineTo(ct->rect.right-1,ct->rect.bottom-2);<br />
dc->SelectObject(pOldPen);<br />
}<br />
}<br />
<br />
} <br />
}<br />
int nMode = dc->SetBkMode(TRANSPARENT);<br />
CSize m_sChar=dc->GetTextExtent(ct->lpMsg,strlen(ct->lpMsg));<br />
COLORREF clrtext;<br />
if (iCont !=m_iSelectTab)<br />
clrtext=dc->SetTextColor(GuiDrawLayer::GetRGBColorGrayText());<br />
<br />
if (m_sizeImag.cx+m_sChar.cx < ct->rect.Width()-8) <br />
{<br />
Image.Draw(dc,ct->uIcon,CPoint(ct->rect.left+3,ct->rect.top),ILD_TRANSPARENT);<br />
rectText=ct->rect;<br />
rectText.top -= 2;<br />
rectText.left+=m_sizeImag.cx+8;<br />
rectText.right-=2;<br />
dc->DrawText(ct->lpMsg,rectText,DT_SINGLELINE|DT_LEFT|DT_VCENTER);<br />
CToolTip.SetToolRect(this,iCont+1,CRect(0,0,0,0));<br />
}<br />
else<br />
{<br />
if (m_sizeImag.cx < ct->rect.Width())<br />
{<br />
Image.Draw(dc,ct->uIcon,CPoint(ct->rect.left+3,ct->rect.top),ILD_TRANSPARENT);<br />
rectText=ct->rect;<br />
rectText.top -= 2;<br />
rectText.left+=m_sizeImag.cx+8;<br />
rectText.right-=5;<br />
CString m_cadBreak=ct->lpMsg;<br />
int c=0;<br />
int cont=m_cadBreak.GetLength();<br />
while(cont > 1 )<br />
{<br />
CString m_scadtemp=m_cadBreak+szStrPoints;<br />
CSize coor=dc->GetTextExtent(m_scadtemp,m_scadtemp.GetLength());<br />
if(coor.cx > rectText.Width())<br />
m_cadBreak=m_cadBreak.Left(m_cadBreak.GetLength()-1);<br />
else<br />
break;<br />
cont--;<br />
}<br />
m_cadBreak+=szStrPoints;<br />
rectText.right+=3;<br />
<br />
dc->DrawText(m_cadBreak,rectText,DT_SINGLELINE|DT_LEFT|DT_VCENTER);<br />
CToolTip.SetToolRect(this,iCont+1,&ct->rect);<br />
}<br />
}<br />
if (iCont !=m_iSelectTab)<br />
dc->SetTextColor(clrtext);<br />
dc->SetBkMode(nMode);<br />
dc->SelectObject(m_fontOld);<br />
} <br />
dc->SelectObject(oldPen);<br />
}<br />
<br />
void CGuiTabWnd::SetImageList(UINT nBitmapID, int cx, int nGrow, COLORREF crMask)<br />
{<br />
CBitmap cbmp;<br />
BITMAP bmp;<br />
Image.Create(nBitmapID,cx,nGrow,crMask);<br />
cbmp.LoadBitmap(nBitmapID);<br />
cbmp.GetBitmap(&bmp);<br />
Image.Add(&cbmp,crMask);<br />
m_sizeImag=CSize(cx,bmp.bmHeight); <br />
}<br />
<br />
CWnd* CGuiTabWnd::GetActiveWnd () const<br />
{<br />
return m_Numtabs == -1 ? NULL : <br />
((CGuiTab*) m_pArray [m_Numtabs])->pParent;<br />
}<br />
<br />
BOOL CGuiTabWnd::FindItem(HWND hWnd)<br />
{<br />
for (int iCont=0; iCont< m_Numtabs;iCont++)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[iCont];<br />
if (ct->pParent->GetSafeHwnd() == hWnd)<br />
return TRUE;<br />
}<br />
return FALSE;<br />
<br />
}<br />
<br />
CWnd* CGuiTabWnd::GetNumWnd(int m_numtab) const<br />
{<br />
if (m_numtab > m_Numtabs)<br />
return NULL;<br />
else<br />
{<br />
if (m_pArray.GetSize() < 1) return NULL;<br />
CWnd* pw=((CGuiTab*) m_pArray [m_numtab])->pParent;<br />
if (HIWORD(pw)== NULL) return NULL;<br />
else<br />
return ((CGuiTab*) m_pArray [m_numtab])->pParent;<br />
}<br />
}<br />
<br />
void CGuiTabWnd::UpdateCaption(CWnd* pWnd,CString m_Title)<br />
{<br />
for (int iCont=0; iCont< m_Numtabs;iCont++)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[iCont];<br />
if (ct->pParent->GetSafeHwnd() == pWnd->GetSafeHwnd())<br />
{<br />
CString x=ct->lpMsg;<br />
if(x!=m_Title)<br />
{<br />
ct->lpMsg=m_Title;<br />
GetParentFrame()->SendMessage(WM_SIZE);<br />
RecalLayout();<br />
Invalidate();<br />
UpdateWindow();<br />
}<br />
break;<br />
}<br />
}<br />
<br />
}<br />
void CGuiTabWnd::ShowTitle(CString m_Caption)<br />
{<br />
if (m_ActualTitle==TRUE)<br />
{<br />
CWnd* pParent=GetParent();<br />
pParent->SetWindowText(m_Caption);<br />
pParent->SendMessage(WM_COMMAND,WM_SHOWTITLE);<br />
}<br />
}<br />
<br />
<br />
void CGuiTabWnd::Addtab(CWnd *pParent, CString lpMsg, UINT uIcon)<br />
{<br />
ASSERT_VALID(pParent);<br />
m_pArray.SetAtGrow(m_Numtabs,new CGuiTab(pParent,lpMsg,uIcon));<br />
if (m_alnTab!=ALN_TOP || m_TypeTab == TYPE_NORMAL)<br />
{<br />
if (m_Numtabs==0)<br />
pParent->ShowWindow(SW_SHOW);<br />
else<br />
pParent->ShowWindow(SW_HIDE);<br />
m_iSelectTab=0;<br />
}<br />
else<br />
m_iSelectTab=m_Numtabs;<br />
<br />
m_Numtabs++;<br />
CGuiTab* ctn=(CGuiTab*) m_pArray[m_Numtabs-1]; <br />
GuiDrawLayer::GetNextColor(m_Numtabs,ctn->m_clrLTab,ctn->m_clrHtab);<br />
<br />
if (m_alnTab==ALN_TOP && m_TypeTab != TYPE_NORMAL)<br />
{<br />
pParent->ShowWindow(SW_SHOWMAXIMIZED);<br />
}<br />
<br />
if (m_style == S3D)<br />
CToolTip.AddTool(this,lpMsg,CRect(0,0,0,0),m_Numtabs);<br />
RecalLayout();<br />
}<br />
<br />
<br />
void CGuiTabWnd::DeleteTab(int m_numtab)<br />
{<br />
if (m_numtab < m_Numtabs)<br />
{<br />
CGuiTab* ctn=(CGuiTab*) m_pArray[m_numtab]; <br />
if (m_alnTab!=ALN_TOP)<br />
ASSERT_VALID(ctn->pParent);<br />
if (ctn)<br />
delete ctn;<br />
m_Numtabs--;<br />
m_pArray.RemoveAt(m_numtab,1);<br />
if (m_Numtabs >0)<br />
{<br />
if (m_iSelectTab == m_numtab)<br />
{<br />
m_iSelectTab=m_iSelectTab-1;<br />
if (m_iSelectTab< 0) m_iSelectTab=0;<br />
CGuiTab* ctn =(CGuiTab*) m_pArray[m_iSelectTab];<br />
CWnd* pParentNew=ctn->pParent;<br />
ASSERT_VALID(pParentNew);<br />
pParentNew->ShowWindow(SW_SHOW);<br />
}<br />
else<br />
{<br />
if (m_iSelectTab > m_numtab)<br />
{<br />
m_iSelectTab--;<br />
}<br />
}<br />
RecalLayout();<br />
}<br />
}<br />
}<br />
<br />
void CGuiTabWnd::OnSize(UINT nType, int cx, int cy) <br />
{<br />
CWnd::OnSize(nType, cx, cy);<br />
if (m_Numtabs > 0)<br />
RecalLayout();<br />
}<br />
<br />
<br />
void CGuiTabWnd::SetCurtab(int m_numtab)<br />
{<br />
if (m_numtab < m_Numtabs && m_numtab != m_iSelectTab )<br />
{<br />
CGuiTab* ctn=(CGuiTab*) m_pArray[m_numtab]; <br />
CWnd* pParentNew= ctn->pParent;<br />
CGuiTab* ct =(CGuiTab*) m_pArray[m_iSelectTab];<br />
CWnd* pParentActual=ct->pParent;<br />
ASSERT_VALID(pParentNew);<br />
ASSERT_VALID(pParentActual);<br />
if (m_alnTab==ALN_TOP && m_TypeTab != TYPE_NORMAL) <br />
{<br />
pParentNew->BringWindowToTop();<br />
}<br />
else<br />
{<br />
pParentActual->ShowWindow(SW_HIDE);<br />
pParentNew->ShowWindow(SW_SHOW);<br />
}<br />
<br />
m_iSelectTab=m_numtab;<br />
AjustTabs();<br />
Invalidate();<br />
UpdateWindow();<br />
}<br />
}<br />
<br />
int CGuiTabWnd::GetCurtab()<br />
{<br />
return m_iSelectTab;<br />
}<br />
<br />
<br />
void CGuiTabWnd::OnLButtonDown(UINT nFlags, CPoint point) <br />
{<br />
CWnd::OnLButtonDown(nFlags, point);<br />
for (int iCont=0; iCont< m_Numtabs;iCont++)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[iCont];<br />
if (ct->rect.PtInRect(point) != 0)<br />
{<br />
SetCurtab(iCont);<br />
ShowTitle(ct->lpMsg);<br />
m_InTab=TRUE;<br />
return;<br />
}<br />
}<br />
}<br />
<br />
void CGuiTabWnd::OnRButtonDown(UINT nFlags, CPoint point)<br />
{<br />
m_InTab=FALSE;<br />
OnLButtonDown(nFlags,point); <br />
<br />
if (((CGuiTab*)m_pArray[m_iSelectTab])->nMenu > 0 && m_InTab==TRUE)<br />
{<br />
CMenu m_menu;<br />
m_menu.LoadMenu(((CGuiTab*)m_pArray[m_iSelectTab])->nMenu);<br />
CMenu* m_SubMenu = m_menu.GetSubMenu(0);<br />
CRect rc=((CGuiTab*)m_pArray[m_iSelectTab])->rect;<br />
ClientToScreen(&point);<br />
m_SubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,<br />
point.x, point.y, AfxGetMainWnd(), &rc);<br />
}<br />
}<br />
<br />
void CGuiTabWnd::SetStyle(Style estyle)<br />
{<br />
m_style=estyle;<br />
}<br />
<br />
void CGuiTabWnd::OnDestroy()<br />
{<br />
for( int i=0; i<m_Numtabs; i++ )<br />
{<br />
CGuiTab *pTab = (CGuiTab*)m_pArray.GetAt(i);<br />
if( pTab )<br />
delete pTab;<br />
}<br />
CWnd::OnDestroy();<br />
<br />
}<br />
<br />
void CGuiTabWnd::SetTabsTitle(int iTabNr, CString sNewTitle)<br />
{<br />
CGuiTab* ct=(CGuiTab*) m_pArray[iTabNr];<br />
if (ct!=NULL)<br />
{<br />
ct->lpMsg=sNewTitle;<br />
m_pArray[iTabNr]=ct;<br />
AjustTabs();<br />
Invalidate();<br />
}<br />
}<br />
<br />
void CGuiTabWnd::SetTabMenu(UINT nMENU,int nNumTab)<br />
{<br />
if (m_Numtabs >0)<br />
((CGuiTab*)m_pArray[(nNumTab==0?m_Numtabs-1:nNumTab)])->AddMenu(nMENU);<br />
}<br />
<br />
<br />
BOOL CGuiTabWnd::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)<br />
{<br />
CWnd::OnNotify(wParam,lParam,pResult);<br />
CWnd* pParent= GetParent();<br />
<br />
if (pParent->GetSafeHwnd())<br />
pParent->SendMessage(WM_NOTIFY, wParam, lParam);<br />
<br />
return TRUE;<br />
}<br />
<br />
void CGuiTabWnd::SetBoldText(BOOL bBold)<br />
{<br />
m_bBold = bBold;<br />
Invalidate();<br />
}
|