- UID
- 39467
注册时间2007-12-3
阅读权限10
最后登录1970-1-1
周游历练
TA的每日心情 | 慵懒 2020-9-27 20:02 |
---|
签到天数: 7 天 [LV.3]偶尔看看II
|
本帖最后由 爱民 于 2012-4-7 11:27 编辑
- #include "FlatTab.h"
- namespace FreeCL
- {
- FlatPage::FlatPage() : mPropertyBegin(this)
- {
- mTag = 0;
- m_Index = -1;
- m_Image = -1;
- m_Owner = NULL;
- m_TextColor = (uint)::GetSysColor(COLOR_BTNTEXT);
- }
- FlatPage::~FlatPage()
- {
- while(m_ControlList.size() > 0)
- RemoveControl(m_ControlList.back());
- }
- sint FlatPage::GetIndex()
- {
- return m_Index;
- }
- void FlatPage::SetText(cstr name)
- {
- m_Name = name;
- m_Owner->UpdateLabelRect(m_Index);
- if(m_Owner->IsVisible())
- ::InvalidateRect(m_Owner->GetHandle(), NULL, TRUE);
- }
- cstr FlatPage::GetText()
- {
- return m_Name.c_str();
- }
- void FlatPage::SetImage(int image)
- {
- m_Image = image;
- if(m_Owner->IsVisible())
- ::InvalidateRect(m_Owner->GetHandle(), (const RECT*)&m_Rect, TRUE);
- }
- sint FlatPage::GetImage()
- {
- return m_Image;
- }
- void FlatPage::SetTextColor(uint color)
- {
- m_TextColor = color & 0x00ffffff;
- if(m_Owner->IsVisible())
- ::InvalidateRect(m_Owner->GetHandle(), (const RECT*)&m_Rect, TRUE);
- }
- uint FlatPage::GetTextColor()
- {
- return m_TextColor;
- }
- Rect FlatPage::GetRect()
- {
- return m_Rect;
- }
- FlatTab* FlatPage::GetParent()
- {
- return m_Owner;
- }
- WinControl* FlatPage::GetOwner()
- {
- return m_Owner;
- }
- bool FlatPage::IsClientEmpty()
- {
- return false;
- }
- void FlatPage::AddControl(WinControl* control)
- {
- if(!control || control->IsMenu() || control == m_Owner || control->m_SubRegion ||
- (control->GetParent() != m_Owner->GetParent() && control->GetParent() != m_Owner))
- {
- #ifdef _DEBUG
- ::DebugBreak();
- #endif
- return;
- }
- bool found = false;
- for(int i = 0; i < int(m_ControlList.size()); i++)
- {
- if(m_ControlList == control)
- {
- found = true;
- break;
- }
- }
- if(!found)
- {
- m_ControlList.push_back(control);
- control->m_SubRegion = this;
- if(m_Owner->GetSelectedPage() != this)
- control->Hide();
- if(control->IsWinControl())
- ((WinControl*)control)->InsertFront(m_Owner);
- }
- }
- void FlatPage::RemoveControl(WinControl* control)
- {
- for(int i = 0; i < int(m_ControlList.size()); i++)
- {
- if(m_ControlList == control)
- {
- if(this != m_Owner->GetSelectedPage())
- control->Show();
- control->m_SubRegion = NULL;
- m_ControlList.erase(m_ControlList.begin()+i);
- return;
- }
- }
- }
- void FlatPage::ShowAllControl()
- {
- for(uint i=0; i < m_ControlList.size(); i++)
- m_ControlList->Show();
- }
- void FlatPage::HideAllControl()
- {
- for(uint i=0; i < m_ControlList.size(); i++)
- m_ControlList->Hide();
- }
- //---------------------------------------------------------------------------------------------------------------------------------------
- FlatTab::FlatTab() : mEventBegin(this), mPropertyBegin(this)
- {
- m_ImageList = NULL;
- m_SelectedPage = NULL;
- }
- FlatTab::~FlatTab()
- {
- }
- bool FlatTab::CreateFlatTab(WinContainer* parent,int left,int top,int width,int height,FlatTabDesc& desc)
- {
- if(parent)
- {
- DWORD style = WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
- m_Handle = ::CreateWindowEx(WS_EX_CONTROLPARENT, "FreeCL_Common_Window", "", style,
- left, top, width, height, parent->GetHandle(), NULL, gModule, NULL);
- if(m_Handle)
- {
- m_Desc = desc;
- m_Parent = parent;
-
- m_OldLeft = left;
- m_OldTop = top;
- m_OldWidth = width;
- m_OldHeight = height;
- m_Left = left;
- m_Top = top;
- m_Width = width;
- m_Height = height;
- ::SendMessage(m_Handle, WM_SETFONT, (WPARAM)parent->GetFont(), FALSE);
- ::SetWindowLong(m_Handle, GWL_ID, (LONG)m_Id);
- m_Parent->AddWinControl(this);
- OnControlCreate();
- OnCreate();
- ::ShowWindow(m_Handle, SW_SHOW);
- return true;
- }
- #ifdef _DEBUG
- else
- ::DebugBreak();
- #endif
- }
- return false;
- }
- bool FlatTab::CreateControl(WinContainer* parent,int left,int top,int width,int height)
- {
- FlatTabDesc desc;
- return CreateFlatTab(parent,left,top,width,height,desc);
- }
- void FlatTab::DestroyControl()
- {
- DeleteAllPage();
- WinContainer::DestroyControl();
- m_ImageList = NULL;
- m_SelectedPage = NULL;
- m_Desc = FlatTabDesc();
- }
- cstr FlatTab::GetClass()
- {
- return "FlatTab";
- }
- bool FlatTab::IsFlatTab()
- {
- return true;
- }
- cstr FlatTab::GetCaption()
- {
- return "";
- }
- void FlatTab::SetCaption(cstr)
- {
- }
- void FlatTab::Hide()
- {
- WinContainer::Hide();
- int count = GetPageCount();
- for(int i = 0; i < count; i++)
- {
- FlatPage* page = GetPage(i);
- page->HideAllControl();
- }
- }
- void FlatTab::Show()
- {
- WinContainer::Show();
- int count = GetPageCount();
- for(int i = 0; i < count; i++)
- {
- FlatPage* page = GetPage(i);
- page->ShowAllControl();
- }
- }
- bool FlatTab::UseDoubleBuffer()
- {
- return true;
- }
- void FlatTab::OnCreate()
- {
- }
- HFONT FlatTab::GetFont()
- {
- return m_Parent->GetFont();
- }
- inline bool TestRect(const RECT& r1, const RECT& r2)
- {
- return bool(r2.right <= r1.left || r1.right <= r2.left || r2.bottom <= r1.top || r1.bottom <= r2.top);
- }
- void FlatTab::UpdateLabelRect(int index)
- { //重新计算指定标签及其后面的所有标签的矩形
- if(0 <= index && index < GetPageCount())
- {
- RECT cRect;
- ::GetClientRect(m_Handle, &cRect);
- int xOffset;
- if(index == 0)
- xOffset = 1;
- else
- {
- FlatPage* page = GetPage(index-1);
- if(page != GetSelectedPage())
- xOffset = page->GetRect().mRight;
- else
- xOffset = page->GetRect().mRight-1;
- }
- int iSpace = m_Desc.mSpace;
- HDC dc = ::GetDC(m_Handle);
- HGDIOBJ iFont = ::SelectObject(dc, m_Parent->GetFont());
- WinImageList* imageList = GetImageList();
- for(uint i = index; i < m_PageList.size(); i++)
- {
- FlatPage* page = GetPage(i);
- int iWidth = 2 + m_Desc.mMargin*2;
- if(imageList)
- iWidth += imageList->GetImageWidth() + iSpace;
- cstr iText = page->GetText();
- int iLen = strlen(iText);
- if(iLen > 0)
- {
- SIZE iSize;
- ::GetTextExtentPoint32(dc, iText, iLen, &iSize);
- iWidth += iSize.cx;
- }
- if(GetSelectedPage() != page)
- {
- page->m_Rect.mLeft = xOffset;
- page->m_Rect.mRight = xOffset + iWidth;
- if(!m_Desc.mBottom)
- {
- page->m_Rect.mTop = 1;
- page->m_Rect.mBottom = m_Desc.mTabHeight;
- }
- else
- {
- page->m_Rect.mTop = cRect.bottom - m_Desc.mTabHeight;
- page->m_Rect.mBottom = cRect.bottom - 1;
- }
- }
- else
- {
- page->m_Rect.mLeft = xOffset - 1;
- page->m_Rect.mRight = xOffset + iWidth + 1;
- if(!m_Desc.mBottom)
- {
- page->m_Rect.mTop = 0;
- page->m_Rect.mBottom = m_Desc.mTabHeight;
- }
- else
- {
- page->m_Rect.mTop = cRect.bottom - m_Desc.mTabHeight;
- page->m_Rect.mBottom = cRect.bottom;
- }
- }
- xOffset += iWidth;
- }
- ::SelectObject(dc, iFont);
- ::ReleaseDC(m_Handle, dc);
- }
- }
- void FlatTab::DrawTopTab(HDC dc, RECT rect)
- { //细节多得令人发指,累得满月眼冒金星
- int width = GetWidth();
- int height = GetHeight();
- RECT lRect;
- lRect.left = 0;
- lRect.right = 1;
- lRect.top = m_Desc.mTabHeight;
- lRect.bottom = height;
- ::FillRect(dc, &lRect, HBRUSH(COLOR_3DHIGHLIGHT+1)); //left line
- lRect.left = width-1;
- lRect.right = width;
- ::FillRect(dc, &lRect, HBRUSH(COLOR_3DSHADOW+1)); //right line
- lRect.left = 0;
- lRect.right = width;
- lRect.top = height-1;
- lRect.bottom = height;
- ::FillRect(dc, &lRect, HBRUSH(COLOR_3DSHADOW+1)); //bottom line
- int iMode = ::SetBkMode(dc, TRANSPARENT);
- HGDIOBJ iFont = ::SelectObject(dc, m_Parent->GetFont());
- int iSpace = m_Desc.mSpace; //图标与文本之间的间隔距离
- for(uint i = 0; i < m_PageList.size(); i++)
- {
- FlatPage* page = GetPage(i);
- Rect pRect = page->GetRect();
- WinImageList* imageList = GetImageList();
- if(page != GetSelectedPage())
- {
- RECT iRect = *(RECT*)&pRect;
- if(!TestRect(iRect, rect) && OnDrawPage(dc, pRect, page))
- {
- iRect.left = pRect.mLeft;
- iRect.right = pRect.mLeft + 1;
- iRect.top = pRect.mTop;
- iRect.bottom = pRect.mBottom;
- ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's left line
- iRect.left = pRect.mRight - 1;
- iRect.right = pRect.mRight;
- ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's right line
- iRect.left = pRect.mLeft + 1;
- iRect.right = pRect.mRight - 1;
- iRect.top = pRect.mTop;
- iRect.bottom = pRect.mTop + 1;
- ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's bottom line
-
- int image = imageList ? page->GetImage() : -1;
- if(image >= 0)
- {
- int iLeft = pRect.mLeft + 1 + m_Desc.mMargin;
- int iTop = (pRect.mTop+1) + (pRect.mBottom-pRect.mTop-2-imageList->GetImageHeight())/2;
- ::ImageList_DrawEx(imageList->GetHandle(), image, dc, iLeft, iTop,
- imageList->GetImageWidth(), imageList->GetImageHeight(), CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
- }
- cstr iText = page->GetText();
- int iLen = strlen(iText);
- if(iLen > 0)
- {
- COLORREF iColor = ::SetTextColor(dc, page->GetTextColor());
- iRect.left = pRect.mLeft + 1 + m_Desc.mMargin;
- if(imageList)
- iRect.left += imageList->GetImageWidth() + iSpace;
- iRect.right = pRect.mRight - 1;
- iRect.top = pRect.mTop + 1;
- iRect.bottom = pRect.mBottom - 1;
- ::DrawText(dc, iText, iLen, &iRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- ::SetTextColor(dc, iColor);
- }
- }
- }
- }
-
- FlatPage* sPage = GetSelectedPage();
- Rect spRect = sPage->GetRect();
- RECT sRect = *(RECT*)&spRect;
- if(!TestRect(rect, sRect) && OnDrawPage(dc, spRect, sPage))
- {
- sRect.left = spRect.mLeft;
- sRect.right = spRect.mLeft + 1;
- sRect.top = spRect.mTop;
- sRect.bottom = spRect.mBottom;
- ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's left line
- sRect.left = spRect.mRight - 1;
- sRect.right = spRect.mRight;
- ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's right line
- sRect.left = spRect.mLeft + 1;
- sRect.right = spRect.mRight - 1;
- sRect.bottom = spRect.mTop + 1;
- ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's top line
- WinImageList* imageList = GetImageList();
- int image = imageList ? sPage->GetImage() : -1;
- if(image >= 0)
- {
- int iLeft = spRect.mLeft + /*expand*/1 + /*line*/1 + m_Desc.mMargin - /*offset*/1;
- int iTop = (spRect.mTop + /*expand*/1 + /*line*/1) + (spRect.mBottom-spRect.mTop-3-imageList->GetImageHeight())/2 - /*offset*/1;
- ::ImageList_DrawEx(imageList->GetHandle(), image, dc, iLeft, iTop,
- imageList->GetImageWidth(), imageList->GetImageHeight(), CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
- }
- cstr iText = sPage->GetText();
- int iLen = strlen(iText);
- if(iLen > 0)
- {
- COLORREF iColor = ::SetTextColor(dc, sPage->GetTextColor());
- sRect.left = spRect.mLeft + /*expand*/1 + /*line*/1 + m_Desc.mMargin;
- if(imageList)
- sRect.left += imageList->GetImageWidth() + iSpace;
- sRect.right = spRect.mRight - /*expand*/1 - /*line*/1;
- sRect.top = spRect.mTop + /*expand*/1 + /*line*/1;
- sRect.bottom = spRect.mBottom - /*line*/1;
- ::OffsetRect(&sRect, -1, -1);
- ::DrawText(dc, iText, iLen, &sRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- ::SetTextColor(dc, iColor);
- }
- }
- RECT bRect;
- bRect.top = spRect.mBottom;
- bRect.bottom = spRect.mBottom + 1;
- bRect.left = 0;
- bRect.right = spRect.mLeft+1;
- ::FillRect(dc, &bRect, HBRUSH(1+COLOR_3DHIGHLIGHT));
- bRect.left = spRect.mRight;
- bRect.right = rect.right;
- if(bRect.right == width)
- bRect.right--;
- ::FillRect(dc, &bRect, HBRUSH(1+COLOR_3DHIGHLIGHT));
- ::SelectObject(dc,iFont);
- ::SetBkMode(dc, iMode);
- }
- void FlatTab::DrawBottomTab(HDC dc, RECT rect)
- {
- int width = GetWidth();
- int height = GetHeight();
- RECT lRect; //line's rect
- lRect.left = 0;
- lRect.right = 1;
- lRect.top = 0;
- lRect.bottom = height - m_Desc.mTabHeight;
- ::FillRect(dc, &lRect, HBRUSH(COLOR_3DHIGHLIGHT+1)); //left line
- lRect.left = width-1;
- lRect.right = width;
- ::FillRect(dc, &lRect, HBRUSH(COLOR_3DSHADOW+1)); //right line
- lRect.left = 1;
- lRect.right = width-1;
- lRect.bottom = lRect.top + 1;
- ::FillRect(dc, &lRect, HBRUSH(COLOR_3DHIGHLIGHT+1)); //top line
-
- int iMode = ::SetBkMode(dc, TRANSPARENT);
- HGDIOBJ iFont = ::SelectObject(dc, m_Parent->GetFont());
- int iSpace = m_Desc.mSpace; //图标与文本之间的间隔距离
- for(uint i = 0; i < m_PageList.size(); i++)
- {
- FlatPage* page = GetPage(i);
- Rect pRect = page->GetRect();
- if(page != GetSelectedPage())
- {
- RECT iRect = *(RECT*)&pRect;
- if(!TestRect(iRect, rect) && OnDrawPage(dc, pRect, page))
- {
- iRect.left = pRect.mLeft;
- iRect.right = pRect.mLeft + 1;
- iRect.top = pRect.mTop;
- iRect.bottom = pRect.mBottom-1;
- ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's left line
- iRect.left = pRect.mRight - 1;
- iRect.right = pRect.mRight;
- ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's right line
- iRect.left = pRect.mLeft;
- iRect.right = pRect.mRight;
- iRect.top = pRect.mBottom - 1;
- iRect.bottom = pRect.mBottom;
- ::FillRect(dc, &iRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's bottom line
- WinImageList* imageList = GetImageList();
- int image = imageList ? page->GetImage() : -1;
- if(image >= 0)
- {
- int iLeft = pRect.mLeft + 1 + m_Desc.mMargin;
- int iTop = (pRect.mTop+1) + (pRect.mBottom-pRect.mTop-2-imageList->GetImageHeight())/2;
- ::ImageList_DrawEx(imageList->GetHandle(), image, dc, iLeft, iTop,
- imageList->GetImageWidth(), imageList->GetImageHeight(), CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
- }
- cstr iText = page->GetText();
- int iLen = strlen(iText);
- if(iLen > 0)
- {
- COLORREF iColor = ::SetTextColor(dc, page->GetTextColor());
- iRect.left = pRect.mLeft + 1 + m_Desc.mMargin;
- if(imageList)
- iRect.left += imageList->GetImageWidth() + iSpace;
- iRect.right = pRect.mRight-1;
- iRect.top = pRect.mTop + 1;
- iRect.bottom = pRect.mBottom - 1;
- ::DrawText(dc, iText, iLen, &iRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- ::SetTextColor(dc, iColor);
- }
- }
- }
- }
- FlatPage* sPage = GetSelectedPage();
- Rect spRect = sPage->GetRect();
- RECT sRect = *(RECT*)&spRect;//selected label's rect
- if(!TestRect(rect, sRect) && OnDrawPage(dc, spRect, sPage))
- {
- sRect.left = spRect.mLeft;
- sRect.right = spRect.mLeft + 1;
- sRect.top = spRect.mTop;
- sRect.bottom = spRect.mBottom - 1;
- ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //Label's left line
- sRect.left = spRect.mRight - 1;
- sRect.right = spRect.mRight;
- ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's right line
- sRect.left = spRect.mLeft;
- sRect.right = spRect.mRight;
- sRect.top = spRect.mBottom-1;
- sRect.bottom = spRect.mBottom;
- ::FillRect(dc, &sRect, HBRUSH(1+COLOR_3DSHADOW)); //Label's bottom line
-
- FlatPage* page = GetSelectedPage();
- WinImageList* imageList = GetImageList();
- int image = imageList ? page->GetImage() : -1;
- if(image >= 0)
- {
- int iLeft = spRect.mLeft + /*expand*/1 + /*line*/1 + m_Desc.mMargin + /*Select offset*/1;
- int iTop = (spRect.mTop+1) + (spRect.mBottom-/*expand*/1-spRect.mTop-2-imageList->GetImageHeight())/2 + /*Select offset*/1;
- ::ImageList_DrawEx(imageList->GetHandle(), image, dc, iLeft, iTop,
- imageList->GetImageWidth(), imageList->GetImageHeight(), CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
- }
- cstr iText = page->GetText();
- int iLen = strlen(iText);
- if(iLen > 0)
- {
- COLORREF iColor = ::SetTextColor(dc, (COLORREF)(page->GetTextColor()));
- sRect.left = spRect.mLeft + /*expand*/1 + /*line*/1 + m_Desc.mMargin;
- if(imageList)
- sRect.left += imageList->GetImageWidth() + iSpace;
- sRect.right = spRect.mRight - /*expand*/1 - /*line*/1;
- sRect.top = (spRect.mTop + /*line*/1);
- sRect.bottom = spRect.mBottom - /*expand*/1 - /*line*/1;
- ::OffsetRect(&sRect, 1, 1);
- ::DrawText(dc, iText, iLen, &sRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- ::SetTextColor(dc, iColor);
- }
- }
- RECT bRect;
- bRect.top = spRect.mTop - 1;
- bRect.bottom = spRect.mTop;
- bRect.left = 0;
- bRect.right = spRect.mLeft;
- ::FillRect(dc, &bRect, HBRUSH(1+COLOR_3DSHADOW));
- bRect.left = spRect.mRight-1;
- bRect.right = rect.right;
- ::FillRect(dc, &bRect, HBRUSH(1+COLOR_3DSHADOW));
- ::SelectObject(dc,iFont);
- ::SetBkMode(dc, iMode);
- }
- void FlatTab::FlatTabPaint(HDC dc, RECT rect)
- {
- if(GetPageCount() > 0)
- {
- if(!m_Desc.mBottom)//Tab标签在顶部的情形
- DrawTopTab(dc, rect);
- else
- DrawBottomTab(dc, rect);
- }
- else
- {
- RECT cRect;
- ::GetClientRect(m_Handle, &cRect);
- RECT lRect;
- lRect.left = 0;
- lRect.right = 1;
- lRect.top = 0;
- lRect.bottom = cRect.bottom - 1;
- ::FillRect(dc, &lRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //LEFT
- lRect.right = cRect.right - 1;
- lRect.bottom = 1;
- ::FillRect(dc, &lRect, HBRUSH(1+COLOR_3DHIGHLIGHT)); //TOP
- lRect.left = cRect.right - 1;
- lRect.right = cRect.right;
- lRect.bottom = cRect.bottom;
- ::FillRect(dc, &lRect, HBRUSH(1+COLOR_3DSHADOW)); //RIGHT
- lRect.left = 0;
- lRect.top = cRect.bottom - 1;
- ::FillRect(dc, &lRect, HBRUSH(1+COLOR_3DSHADOW)); //BOTTOM
- }
- #ifdef __Design__
- if(mBoxList.size() > 0)
- {
- Rect bRect;
- ::GetClipBox(dc, (RECT*)&bRect);
- for(uint i = 0; i < mBoxList.size(); i++)
- {
- if(bRect.IntersectRect(Rect(mBoxList)))
- mBoxList.DrawBox(dc, HBRUSH(COLOR_HIGHLIGHT+1));
- }
- }
- #endif
- }
- FlatPage* FlatTab::AddPage()
- {
- if(m_Handle)
- {
- FlatPage* page = new FlatPage;
- page->m_Index = GetPageCount();
- page->m_Owner = this;
- m_PageList.push_back(page);
- UpdateLabelRect(page->m_Index);
- FlatPage* iPage = GetSelectedPage();
- if(!iPage)
- {
- m_SelectedPage = page;
- if(mOnSelectChanged != NULL)
- { //触发当前选择页改变事件
- if(!mOnSelectChanged.mThis)
- (GetParent()->*mOnSelectChanged)(this, iPage, page);
- else
- mOnSelectChanged(this, iPage, page);
- }
- }
- if(IsVisible())
- ::InvalidateRect(m_Handle, (const RECT*)&page->m_Rect, FALSE);
- return page;
- }
- return NULL;
- }
- void FlatTab::DeletePage(FlatPage* page)
- {
- if(!page)
- return;
- for(int i = 0; i < GetPageCount(); i++)
- {
- if(page == m_PageList)
- {
- DeletePage(i);
- return;
- }
- }
- }
- void FlatTab::DeletePage(int index)
- {
- if(0 <= index && index < GetPageCount())
- {
- FlatPage* dPage = m_PageList[index];
- m_PageList.erase(m_PageList.begin()+index);
- for(int i = index; i < GetPageCount(); i++)
- m_PageList->m_Index = i;
- UpdateLabelRect(index);
- if(m_SelectedPage == dPage)
- { //删除选择页
- if(m_PageList.size() == 0)
- m_SelectedPage = NULL;
- else
- {
- m_SelectedPage = m_PageList[0];
- m_SelectedPage->ShowAllControl();
- if(mOnSelectChanged != NULL)
- {
- if(!mOnSelectChanged.mThis)
- (GetParent()->*mOnSelectChanged)(this, dPage, m_SelectedPage);
- else
- mOnSelectChanged(this, dPage, m_SelectedPage);
- }
- }
- }
- delete dPage;
- if(IsVisible())
- ::InvalidateRect(m_Handle, NULL, TRUE);
- }
- }
- void FlatTab::DeleteAllPage()
- {
- if(m_PageList.size() == 0)
- return;
- SetRedraw(false);
- while(GetPageCount() > 0)
- {
- delete m_PageList.back();
- m_PageList.pop_back();
- }
- m_SelectedPage = NULL;
- SetRedraw(true);
- RedrawControl(false);
- }
- sint FlatTab::GetPageCount()
- {
- return sint(m_PageList.size());
- }
- void FlatTab::SetImageList(WinImageList* imageList)
- {
- if(imageList && imageList->GetHandle() == NULL)
- {
- #ifdef _DEBUG
- ::DebugBreak();
- #endif
- return;
- }
- if(m_Handle)
- {
- m_ImageList = imageList;
- if(GetPageCount() > 0 && IsVisible())
- ::InvalidateRect(m_Handle, NULL, TRUE);
- }
- }
- WinImageList* FlatTab::GetImageList()
- {
- return m_ImageList;
- }
- void FlatTab::SelectPage(FlatPage* page)
- {
- if(!page || page == m_SelectedPage)
- return;
- bool find = false;
- for(int i = 0; i < int(m_PageList.size()); i++)
- {
- if(page == m_PageList)
- {
- find = true;
- break;
- }
- }
- if(find)
- {
- bool may = true;
- if(mOnSelectChanging != NULL)
- {
- if(!mOnSelectChanging.mThis)
- may = (GetParent()->*mOnSelectChanging)(this, m_SelectedPage);
- else
- may = mOnSelectChanging(this, m_SelectedPage);
- }
- if(may)
- {
- Rect iRect, nRect;
- FlatPage* iPage = m_SelectedPage;
- iRect = iPage->GetRect();
- m_SelectedPage = page;
- iPage->HideAllControl();
- page->ShowAllControl();
- int iIndex = iPage->m_Index;
- int nIndex = page->m_Index;
- UpdateLabelRect(iIndex<nIndex ? iIndex : nIndex);
- nRect = page->GetRect();
- if(mOnSelectChanged != NULL)
- {
- if(!mOnSelectChanged.mThis)
- (GetParent()->*mOnSelectChanged)(this, iPage, page);
- else
- mOnSelectChanged(this, iPage, page);
- }
- if(IsVisible())
- {
- if(!m_Desc.mBottom)
- {
- iRect.mBottom++;
- nRect.mBottom++;
- }
- else
- {
- iRect.mTop--;
- nRect.mTop--;
- }
- ::InvalidateRect(m_Handle, (RECT*)&iRect, TRUE);
- ::InvalidateRect(m_Handle, (RECT*)&nRect, TRUE);
- }
- }
- }
- #ifdef _DEBUG
- else
- ::DebugBreak();//page不属于此控件!
- #endif
- }
- FlatPage* FlatTab::GetSelectedPage()
- {
- return m_SelectedPage;
- }
- FlatPage* FlatTab::GetPage(int index)
- {
- if(0 <= index && index < GetPageCount())
- return m_PageList[index];
- return NULL;
- }
- LRESULT FlatTab::WmEraseBkGnd(WPARAM wParam, LPARAM lParam)
- {
- HDC dc = (HDC)wParam;
- if(mOnDrawSkin != NULL)
- {
- bool bCode;
- FlatTabSkinData data;
- data.mDC = dc;
- data.mClientRect = this->GetClientRect();
- if(!mOnDrawSkin.mThis)
- bCode = (GetParent()->*mOnDrawSkin)(this, data);
- else
- bCode = mOnDrawSkin(this, data);
- if(!bCode)
- return TRUE;
- }
-
- DrawSkin((HDC)wParam, NULL);
- return TRUE;
- }
- LRESULT FlatTab::WmPaint(WPARAM wParam, LPARAM lParam)
- {
- if(m_Desc.mDoubleBuffer)
- {
- if(DoubleBufferPaint(wParam, lParam))
- {
- RECT uRect;
- HDC dc = (HDC)wParam;
- ::GetClipBox(dc, &uRect);
- FlatTabPaint((HDC)wParam, uRect);
- }
- }
- else
- {
- if(wParam == 0)
- {
- PAINTSTRUCT ps;
- HDC dc = ::BeginPaint(m_Handle, &ps);
- FlatTabPaint(dc, ps.rcPaint);
- ::EndPaint(m_Handle, &ps);
- }
- else
- {
- RECT uRect;
- HDC dc = (HDC)wParam;
- ::GetClipBox(dc, &uRect);
- FlatTabPaint((HDC)wParam, uRect);
- }
- }
- return 0;
- }
- LRESULT FlatTab::WmMove(WPARAM wParam, LPARAM lParam)
- {
- if(!m_MoveSize)
- { //系统可能会自动调整控件位置
- RECT wRect;
- ::GetWindowRect(m_Handle, &wRect);
- ::ScreenToClient(m_Parent->GetHandle(), (POINT*)&wRect);
- m_Left = wRect.left;
- m_Top = wRect.top;
- }
- OnContainerMove(m_Left, m_Top);
- if(mOnDrawSkin != NULL)
- RedrawControl(true);
- else if(m_ParentSkin)
- {
- SkinMode pMode = GetSkinMode();
- if(pMode == SkinMode_BitmapResource || pMode == SkinMode_BitmapFile || GetBrush() == NULL)
- RedrawControl(true);
- }
- return 0;
- }
- LRESULT FlatTab::WmSize(WPARAM wParam, LPARAM lParam)
- {
- if(!m_MoveSize)
- { //系统可能会自动调整控件尺寸
- RECT wRect;
- ::GetWindowRect(m_Handle, &wRect);
- m_OldWidth = m_Width;
- m_OldHeight = m_Height;
- m_Width = wRect.right - wRect.left;
- m_Height = wRect.bottom - wRect.top;
- }
- if(m_Width != m_OldHeight || m_Height != m_OldHeight)
- {
- if(m_Desc.mBottom && GetPageCount() > 0 && m_Height != m_OldHeight)
- UpdateLabelRect(0);
- OnContainerSize(m_Width, m_Height);
- if(IsVisible())
- {
- if(mOnDrawSkin != NULL)
- RedrawControl(true);
- else
- {
- int left = m_Width;
- if(m_Width != m_OldWidth)
- { //控件自身需要刷新
- RECT wRect;
- if(m_Width > m_OldWidth)
- {
- wRect.left = m_OldWidth - 1;
- wRect.right = m_Width;
- }
- else
- {
- wRect.left = m_Width - 1;
- wRect.right = m_Width;
- }
- wRect.top = 0;
- wRect.bottom = m_Height;
- ::InvalidateRect(m_Handle, &wRect, TRUE);
- ::UpdateWindow(m_Handle);
- left = wRect.left;
- }
- if(m_Height != m_OldHeight)
- {
- RECT hRect;
- if(m_Height > m_OldHeight)
- {
- if(!m_Desc.mBottom)
- hRect.top = m_OldHeight - 1;
- else
- hRect.top = m_OldHeight - m_Desc.mTabHeight - 1;
- hRect.bottom = m_Height;
- }
- else
- {
- if(!m_Desc.mBottom)
- hRect.top = m_Height - 1;
- else
- hRect.top = m_Height - m_Desc.mTabHeight - 1;
- hRect.bottom = m_Height;
- }
- hRect.left = 0;
- hRect.right = left;
- ::InvalidateRect(m_Handle, &hRect, TRUE);
- ::UpdateWindow(m_Handle);
- }
- }
- }
- }
- return 0;
- }
- LRESULT FlatTab::WmLButtonDown(WPARAM wParam, LPARAM lParam)
- {
- int xPos = (int)(short)(LOWORD(lParam));
- int yPos = (int)(short)(HIWORD(lParam));
- for(int i = 0; i < GetPageCount(); i++)
- {
- FlatPage* page = GetPage(i);
- Rect iRect = page->GetRect();
- if(iRect.InsideRect(xPos, yPos))
- {
- SelectPage(page);
- break;
- }
- }
- return 0;
- }
- LRESULT FlatTab::WmThemeChanged(WPARAM wParam, LPARAM lParam)
- {
- CallDefaultProc(WM_THEMECHANGED, wParam, lParam);
- FreeCL::InitTheme();
- ::SendMessage(m_Handle, WM_SETFONT, WPARAM(m_Parent->GetFont()), (LPARAM)TRUE);
- return 0;
- }
- bool FlatTab::OnDrawPage(HDC dc, const Rect& rect, FlatPage* page)
- {
- if(mOnDrawPage != NULL)
- {
- FlatPageDrawData data;
- data.mDC = dc;
- data.mRect = rect;
- if(!mOnDrawPage.mThis)
- return (GetParent()->*mOnDrawPage)(this, page, data);
- else
- return mOnDrawPage(this, page, data);
- }
- return true;
- }
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入我们
x
|