?? customtabctrl.h
字號:
#ifndef __CUSTOMTABCTRL_H__
#define __CUSTOMTABCTRL_H__
#pragma once
/////////////////////////////////////////////////////////////////////////////
// CCustomTabCtrl - A base class to help implement
// Tab Controls with different appearances
//
// Original work by Bjarke Viksoe (bjarke@viksoe.dk)
// Revised version by Daniel Bowen (dbowen@es.com).
// Copyright (c) 2001-2002 Bjarke Viksoe.
// Copyright (c) 2002-2004 Daniel Bowen.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to you or your
// computer whatsoever. It's free, so don't hassle me about it.
//
// Beware of bugs.
//
// History (Date/Author/Description):
// ----------------------------------
//
// 2005/07/13: Daniel Bowen
// - Namespace qualify the use of more ATL and WTL classes.
//
// 2005/03/14: Daniel Bowen
// - Fix warnings when compiling for 64-bit.
//
// 2004/06/28: Daniel Bowen
// - More ATLASSERTs
// - Clean up warnings on level 4
// - Fix "FindItem" so you can search on more than 1 criteria at a time
// (like it was intended to work). Use #define for flags now
// instead of enumeration (CTFI_TABVIEW instead of eCustomTabItem_TabView).
//
// 2004/06/21: Peter Carlson
// - "CanClose" for items.
// - HighlightItem - "SetHighlighted" on item, then InvalidateRect for the item
//
// 2004/05/10: Peter Carlson
// - Middle mouse button notifications
//
// 2004/04/29: Daniel Bowen
// - Suport for a new CTCS_DRAGREARRANGE style. If you set this style,
// a tab item can be dragged to another position within the
// same tab control. Along with this are the new notifications
// CTCN_BEGINITEMDRAG
// CTCN_ACCEPTITEMDRAG
// CTCN_CANCELITEMDRAG
// If CTCS_SCROLL is also set, then the tabs will scroll when
// you get near the left or the right edge of the tab control.
// The drag rearrange methods are all overrideable, so a more
// derived class could do a different UI for the drag and drop.
// The current implementation roughly mimics dragging
// MDI tabs in Visual Studio (with the exceptions of
// supporting scrolling, and not moving the tab until the
// cursor is past the half-way point of an adjacent tab).
// - Remove m_idDlgCtrl, and just use GetDlgCtrlID where needed.
// This way, you can change the ID after the window is created.
// - Move shutdown code that was in OnDestroy to "Uninitialize".
// Call Uninitialize from both OnDestroy and UnsubclassWindow
// (UnsubclassWindow wasn't previously being overriden like it should).
// - With "Mouse Down" state flags, specify Left or Right to be
// more specific. Currently, the right mouse button state flags
// are not being set.
// - On a left and right button down, don't take the focus when
// clicking on a tab item.
// - You can now change the definition of the scroll speed specified by
// CTCSR_NONE
// CTCSR_SLOW
// CTCSR_NORMAL
// CTCSR_FAST
// As long as you #define these before including this header file.
// - Support for highlighting items.
// Add CCustomTabItem::IsHighlighted/SetHighlighted.
// Uses the custom draw state CDIS_MARKED.
//
// 2003/06/27: Daniel Bowen
// - Update comment referencing DECLARE_WND_CLASS to be DECLARE_WND_CLASS_EX instead
// - If the creation of the window fails, don't try to initialize.
//
// 2003/06/03: Daniel Bowen
// - Fix compile errors for VC 7.1
//
// 2003/01/07: Daniel Bowen
// - Destroy or detach tooltip control when handling WM_DESTROY
//
// 2002/12/05: Daniel Bowen
// - Handle WM_SYSCOLORCHANGE in case its broadcast to us
// from a top-level window. Call OnSettingChange.
//
// 2002/11/13: Daniel Bowen
// - New CTCS_FLATEDGE style. Tab controls derived from
// CCustomTabCtrl can use this style to determine whether
// to draw the outline of the control with a flat look.
// - New CalcSize_NonClient. UpdateLayout will now call
// this overrideable method before calling any other
// CalcSize_* methods, so that you can adjust the client
// RECT to account for non-client areas.
//
// 2002/10/21: Daniel Bowen
// - NMCTCITEM and NMCTC2ITEMS actually have "pt" in client
// coordinates, not screen coordinates. Change the comment.
// - Notifications using NMCTCITEM and NMCTC2ITEMS
// (NM_CLICK, et. al) were incorrectly initialing "pt".
// - Remove some some unnecessary ATLASSERT(::IsWindow(m_hWnd))
// (if the method doesn't depend on a valid m_hWnd)
// - Add some additional casting when dealing with current selection
// - DeleteItem - after sending CTCN_DELETEITEM, re-get
// the count of items in case its changed
// - Change a couple of ASSERTs and parameter checks that deal
// with size_t variables to not needlessly check for < 0
// - Change SetCurSel to take an int instead of a size_t.
// Passing an int < 0 will clear the current selection
// - CCustomTabCtrl::SetImageList - Should be
// CImageList imageListOld = m_imageList;
// instead of
// CImageList& imageListOld = m_imageList;
//
// 2002/07/16: Daniel Bowen
// - Ensure that any place doing anything with m_tooltip
// first checks if(m_tooltip.IsWindow()).
// - Update DeleteAllItems to turn off redrawing while
// the delete happens.
// - DeleteAllItems now takes an optional boolean to
// specify whether or not to redraw after the deletion
// - Handle WM_SETREDRAW, but still allow the default handling.
// We'll track WM_SETREDRAW in our own state variable
// so that we can avoid doing UpdateLayout if
// someone has called WM_SETREDRAW with FALSE.
// When they call WM_SETREDRAW with TRUE to turn
// it back on, we'll UpdateLayout to be ready for the caller
// to do an InvalidateRect or RedrawWindow.
//
// 2002/06/20: Daniel Bowen
// - SetCurSel -
// * Added a new optional parameter "bNotify" that allows
// you to specify whether or not you want the parent
// to receive the notifications CTCN_SELCHANGING and
// CTCN_SELCHANGE.
// * Even if the newly requested selection index is
// the same index as the previous selection index,
// go through the whole SetCurSel process.
// Even though the index is the same, the item
// might be different (as in the case of
// InsertItem inserting a new item where the old
// selection used to be). EnsureVisible is also called,
// which in the CTCS_SCROLL case, you really want
// every time even if the item is the same.
//
// This is a change from previous versions,
// where if the index was the same as the current selection,
// the method returned immediately.
//
// - DeleteItem -
// * When bUpdateSelection is true:
// Now, when you delete the selected item, instead of
// selecting the 0-index item, it tries to leave the index
// of the selected item the same. If the selected item
// was the last item, the new last item is selected.
// If the selected item was the only remaining item,
// the selection is cleared.
//
//
// 2002/06/13: Daniel Bowen
// - Fix small bug with scroll-repeat when scrolling right.
//
// 2002/06/12: Daniel Bowen
// - Publish codeproject article. For history prior
// to the release of the article, please see the article
// and the section "Note to previous users"
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#ifndef __ATLAPP_H__
#error CustomTabCtrl.h requires atlapp.h to be included first
#endif
#ifndef __ATLCTRLS_H__
#error CustomTabCtrl.h requires atlctrls.h to be included first
#endif
#ifndef __ATLGDIX_H__
#error CustomTabCtrl.h requires atlgdix.h to be included first
#endif
// There are slightly different dependencies under VC 7 (ATL 7) vs. VC 6 (ATL 3)
#if (_ATL_VER >= 0x0700)
#if !defined(__ATLCOLL_H__)
#error CustomTabCtrl.h requires atlcoll.h (under VC 7).
#endif
#if !defined(__ATLSTR_H__)
#error CustomTabCtrl.h requires CString. In VC 7, include atlstr.h
#endif
#if defined(__ATLMISC_H__) && !defined(_WTL_NO_CSTRING)
#error In VC 7, please define _WTL_NO_CSTRING if you include atlmisc.h
#endif
#else
#if !defined(_WTL_USE_CSTRING)
#error CustomTabCtrl.h requires CString. In VC 6, be sure to include atlmisc.h.
#endif
#endif
#if (_WIN32_IE < 0x0400)
#error CustomTabCtrl.h requires _WIN32_IE >= 0x0400
#endif
// Window styles:
// NOTE: "CTCS" stands for "Custom tab control style"
#define CTCS_SCROLL 0x0001 // TCS_SCROLLOPPOSITE
#define CTCS_BOTTOM 0x0002 // TCS_BOTTOM
//#define CTCS_RIGHT 0x0002 // TCS_RIGHT
//#define CTCS_MULTISELECT 0x0004 // TCS_MULTISELECT
#define CTCS_CLOSEBUTTON 0x0008 // TCS_FLATBUTTONS
//#define CTCS_FORCEICONLEFT 0x0010 // TCS_FORCEICONLEFT
//#define CTCS_FORCELABELLEFT 0x0020 // TCS_FORCELABELLEFT
#define CTCS_HOTTRACK 0x0040 // TCS_HOTTRACK
//#define CTCS_VERTICAL 0x0080 // TCS_VERTICAL
//#define CTCS_TABS 0x0000 // TCS_TABS
#define CTCS_FLATEDGE 0x0100 // TCS_BUTTONS
//#define CTCS_SINGLELINE 0x0000 // TCS_SINGLELINE
//#define CTCS_MULTILINE 0x0200 // TCS_MULTILINE
//#define CTCS_RIGHTJUSTIFY 0x0000 // TCS_RIGHTJUSTIFY
#define CTCS_DRAGREARRANGE 0x0400 // TCS_FIXEDWIDTH
//#define CTCS_OLEDRAGDROP 0x0800 // TCS_RAGGEDRIGHT
//#define CTCS_FOCUSONBUTTONDOWN 0x1000 // TCS_FOCUSONBUTTONDOWN
#define CTCS_BOLDSELECTEDTAB 0x2000 // TCS_OWNERDRAWFIXED
#define CTCS_TOOLTIPS 0x4000 // TCS_TOOLTIPS
//#define CTCS_FOCUSNEVER 0x8000 // TCS_FOCUSNEVER
// Notifications:
#define CTCN_FIRST (0U-550U) // TCN_FIRST
#define CTCN_LAST (0U-580U) // TCN_LAST
#define CTCN_SELCHANGE (TCN_FIRST - 1) // TCN_SELCHANGE
#define CTCN_SELCHANGING (TCN_FIRST - 2) // TCN_SELCHANGING
//#define CTCN_GETOBJECT (TCN_FIRST - 3) // TCN_GETOBJECT
//#define CTCN_FOCUSCHANGE (TCN_FIRST - 4) // TCN_FOCUSCHANGE
//#define CTCN_INITIALIZE (TCN_FIRST - 10) // obsolete for now
#define CTCN_INSERTITEM (TCN_FIRST - 11)
#define CTCN_DELETEITEM (TCN_FIRST - 12)
#define CTCN_MOVEITEM (TCN_FIRST - 13)
#define CTCN_SWAPITEMPOSITIONS (TCN_FIRST - 14)
#define CTCN_CLOSE (TCN_FIRST - 15)
#define CTCN_BEGINITEMDRAG (TCN_FIRST - 21)
#define CTCN_ACCEPTITEMDRAG (TCN_FIRST - 22)
#define CTCN_CANCELITEMDRAG (TCN_FIRST - 23)
#define CTCN_MCLICK (TCN_FIRST - 24)
#define CTCN_MDBLCLK (TCN_FIRST - 25)
// Hit Test codes
#define CTCHT_NOWHERE 0x0001 // TCHT_NOWHERE
#define CTCHT_ONITEMICON 0x0002 // TCHT_ONITEMICON
#define CTCHT_ONITEMLABEL 0x0004 // TCHT_ONITEMLABEL
#define CTCHT_ONITEM (CTCHT_ONITEMICON | CTCHT_ONITEMLABEL)
#define CTCHT_ONCLOSEBTN 0x0010
#define CTCHT_ONSCROLLRIGHTBTN 0x0020
#define CTCHT_ONSCROLLLEFTBTN 0x0040
// Find Item flags
#define CTFI_NONE 0x0000
#define CTFI_RECT 0x0001
#define CTFI_IMAGE 0x0002
#define CTFI_TEXT 0x0004
#define CTFI_TOOLTIP 0x0008
#define CTFI_TABVIEW 0x0010
#define CTFI_HIGHLIGHTED 0x0020
#define CTFI_CANCLOSE 0x0040
#define CTFI_LAST CTFI_CANCLOSE
#define CTFI_ALL 0xFFFF
// Number of milliseconds for scroll repeat
#ifndef CTCSR_NONE
#define CTCSR_NONE 0
#endif
#ifndef CTCSR_SLOW
#define CTCSR_SLOW 100
#endif
#ifndef CTCSR_NORMAL
#define CTCSR_NORMAL 25
#endif
#ifndef CTCSR_FAST
#define CTCSR_FAST 10
#endif
// Drag and drop related constant
#ifndef CTCD_SCROLLZONEWIDTH
#define CTCD_SCROLLZONEWIDTH 20
#endif
// Structures
typedef struct tagNMCTCITEM
{
NMHDR hdr;
int iItem; // Item Index
POINT pt; // Client Coordinates
} NMCTCITEM, *LPNMCTCITEM;
typedef struct tagNMCTC2ITEMS
{
NMHDR hdr;
int iItem1; // First Item Index
int iItem2; // Second Item Index
POINT pt; // Client Coordinates
} NMCTC2ITEMS, *LPNMCTC2ITEMS;
typedef struct tagCTCHITTESTINFO
{
POINT pt; // Client Coordinates of point to test
UINT flags;
} CTCHITTESTINFO, *LPCTCHITTESTINFO;
typedef struct tagNMCTCCUSTOMDRAW
{
NMCUSTOMDRAW nmcd;
HFONT hFontInactive;
HFONT hFontSelected;
HBRUSH hBrushBackground;
COLORREF clrTextInactive;
COLORREF clrTextSelected;
COLORREF clrSelectedTab;
COLORREF clrBtnFace;
COLORREF clrBtnShadow;
COLORREF clrBtnHighlight;
COLORREF clrBtnText;
COLORREF clrHighlight;
COLORREF clrHighlightHotTrack;
COLORREF clrHighlightText;
} NMCTCCUSTOMDRAW, FAR * LPNMCTCCUSTOMDRAW;
typedef struct tagCTCSETTINGS
{
signed char iPadding;
signed char iMargin;
signed char iSelMargin;
signed char iIndent;
} CTCSETTINGS;
// Tab Item classes
class CCustomTabItem
{
// Member variables
protected:
RECT m_rcItem;
int m_nImage;
_CSTRING_NS::CString m_sText;
_CSTRING_NS::CString m_sToolTip;
bool m_bHighlighted;
bool m_bCanClose;
public:
// NOTE: These are here for backwards compatibility.
// Use the new CTFI_NONE, CTFI_RECT, etc.
typedef enum FieldFlags
{
eCustomTabItem_None = CTFI_NONE,
eCustomTabItem_Rect = CTFI_RECT,
eCustomTabItem_Image = CTFI_IMAGE,
eCustomTabItem_Text = CTFI_TEXT,
eCustomTabItem_ToolTip = CTFI_TOOLTIP,
eCustomTabItem_All = CTFI_ALL,
};
#if (_MSC_VER >= 1300)
#pragma deprecated(eCustomTabItem_None)
#pragma deprecated(eCustomTabItem_Rect)
#pragma deprecated(eCustomTabItem_Image)
#pragma deprecated(eCustomTabItem_Text)
#pragma deprecated(eCustomTabItem_ToolTip)
#pragma deprecated(eCustomTabItem_All)
#endif
// Constructors/Destructors
public:
CCustomTabItem() :
m_nImage(-1),
m_bHighlighted(false),
m_bCanClose(true)
{
::SetRectEmpty(&m_rcItem);
}
CCustomTabItem(const CCustomTabItem& rhs)
{
*this = rhs;
}
virtual ~CCustomTabItem()
{
}
const CCustomTabItem& operator=(const CCustomTabItem& rhs)
{
if(&rhs != this)
{
m_rcItem = rhs.m_rcItem;
m_nImage = rhs.m_nImage;
m_sText = rhs.m_sText;
m_sToolTip = rhs.m_sToolTip;
m_bHighlighted = rhs.m_bHighlighted;
m_bCanClose = rhs.m_bCanClose;
}
return *this;
}
// Accessors
public:
RECT GetRect() const
{
return m_rcItem;
}
LPCRECT GetRectRef() const
{
return &m_rcItem;
}
bool SetRect(RECT rcItem)
{
m_rcItem = rcItem;
return true;
}
int GetImageIndex() const
{
return m_nImage;
}
bool SetImageIndex(int nImage = -1)
{
m_nImage = nImage;
return true;
}
_CSTRING_NS::CString GetText() const
{
return m_sText;
}
LPCTSTR GetTextRef() const
{
return (LPCTSTR)m_sText;
}
bool SetText(LPCTSTR sNewText)
{
m_sText = sNewText;
return true;
}
_CSTRING_NS::CString GetToolTip() const
{
return m_sToolTip;
}
LPCTSTR GetToolTipRef() const
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -