📄 atlautosizedlg.h
字号:
/** \mainpage
* \subpage atlautosizedlg See atlautosizedlg for infos and the license of atlautosizedlg.h\n
*/
/** \page atlautosizedlg atlautosizedlg.h
*
* \section License License
* Copyright (c) 2006 Massimiliano Alberti <xanatos@geocities.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated Subjectation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* \section VersionHistory Version History
* \li atlautosizedlg.h 1.0 Apr 2006 Initial Release
* \li atlautosizedlg.h 2.0 Jun 2006 Nearly rebuilt. Now supports multilevel
*
* \section TODO TODO
*
*/
/** \file
* This header contains classes useful to reorder controls in a window
*/
#pragma once
#ifndef __ATLAUTOSIZEDLG_H__
#define __ATLAUTOSIZEDLG_H__
#ifndef __ATLWIN_H__
#error atlautosizedlg.h requires atlwin.h to be included first
#endif
#define TRACEAUTOSIZE
//
namespace ATL
{
//
// #define TRACEAUTOSIZE ///< Define this to see in the Output window the tracing of the base size of the cols and rows
// #define TRACEAUTOSIZE2 ///< Define this to see in the Output window the tracing of the calced size of the cols and rows
//
/// \name Transparent ctrls (Group Boxes and Static Controls)
/*@{*/
/// This "facility" is used to make the redraw of transparent controls (only Group Boxes and Static Controls) smoother.
/** Simply list the IDs of the controls in the ... part of the TRANSPARENT_LIST()
* \param theClass Name of the class using the facility
* \param ... List of IDs of controls that are transparent. They'll be redrawn in a special way
*/
#define TRANSPARENT_LIST(theClass, ...) \
BOOL HandleTransparentMap(WTL::CDCHandle dc = NULL) \
{ \
int tcCtrls[] = {0, __VA_ARGS__, INT_MAX}; \
if (dc) { \
int *ptcCtrl = tcCtrls + 1; \
while (*ptcCtrl != INT_MAX) { \
DrawTransparentCtrl(dc, *ptcCtrl); \
ptcCtrl++; \
} \
} else { \
int *ptcCtrl = tcCtrls + 1; \
while (*ptcCtrl != INT_MAX) { \
InitializeTransparentCtrl(*ptcCtrl); \
ptcCtrl++; \
} \
} \
return TRUE; \
}
/// The main "facility" to control the positioning and sizing of the ctrls.
/** The BEGIN_WINDOW_MAP() MUST be paired by a END_WINDOW_MAP().
* \param theClass Name of the class using the facility
* \param ... In order: LeftRightBorder, TopBottomBorder, HorizontalGap, VerticalGap. Positive if DLGUnits, negative for Pixels
*/
#define BEGIN_WINDOW_MAP_INLINE(theClass, /*LeftRightBorder, TopBottomBorder, HGap, VGap*/...) \
ATLASSERT(sizeof(int) == sizeof(theClass::CCtrlCounter) && "\"Strange\" compiler. The library is not compatible"); \
CRowsIndex *p = NULL; p; \
const int _auto = WMSRC_AUTO, _exp = WMSRC_EXPANDABLE, _contr = WMSRC_CONTRACTABLE, _eq = WMSRC_EQUAL, _gap = WMSRC_GAP, _gapm = WMSRC_GAPM, _nog = WMSRC_NOGAP, _ = WMSCTRL_EMPTY, __ = WMSCTRL_EMPTY, _r = WMSCTRL_EXPRIGHT, _d = WMSCTRL_EXPDOWN; \
_auto; _exp; _contr; _eq; _gap, _gapm, _nog; _; __; _r; _d; \
static CCtrlCounter s_iCtrls[] = {0, _FirstParam(__VA_ARGS__), _SecondParam(__VA_ARGS__), _ThirdParam(__VA_ARGS__), _FourthParam(__VA_ARGS__),
#define BEGIN_WINDOW_MAP(theClass, /*LeftRightBorder, TopBottomBorder, HGap, VGap*/...) \
static CWindowMapStruct* GetWindowMap() \
{ \
ATLASSERT(sizeof(int) == sizeof(CCtrlCounter) && "\"Strange\" compiler. The library is not compatible"); \
CRowsIndex *p = NULL; p; \
const int _auto = WMSRC_AUTO, _exp = WMSRC_EXPANDABLE, _contr = WMSRC_CONTRACTABLE, _eq = WMSRC_EQUAL, _gap = WMSRC_GAP, _gapm = WMSRC_GAPM, _nog = WMSRC_NOGAP, _ = WMSCTRL_EMPTY, __ = WMSCTRL_EMPTY, _r = WMSCTRL_EXPRIGHT, _d = WMSCTRL_EXPDOWN; \
_auto; _exp; _contr; _eq; _gap, _gapm, _nog; _; __; _r; _d; \
static CCtrlCounter s_iCtrls[] = {0, _FirstParam(__VA_ARGS__), _SecondParam(__VA_ARGS__), _ThirdParam(__VA_ARGS__), _FourthParam(__VA_ARGS__),
/// "Footer" of the Window Map.
#define END_WINDOW_MAP_INLINE() \
}; ATLASSERT(!p); \
return (CWindowMapStruct*)s_iCtrls;
/// "Footer" of the Window Map.
#define END_WINDOW_MAP() \
}; ATLASSERT(!p); \
return (CWindowMapStruct*)s_iCtrls; \
}
/*@}*/
//
/// \name Ctrl group header and footer
/*@{*/
/// "Header" of a rect ctrl group. MUST be paired with a WMB_END()
/** \param ... List of WMB_COL() columns comma separated
*/
#define WMB_HEAD(...) (_Init(p, (CRowsIndex*)_alloca(sizeof(CRowsIndex))), _Init(p, (CRowsIndex*)_alloca(sizeof(CRowsIndex))), _Init(p, (CRowsIndex*)_alloca(sizeof(CRowsIndex))), WMH_BEGIN), \
CCtrlCounter(p->m_pPrev->m_pPrev) /* Size */, CCtrlCounter(p->m_pPrev) /* NumRows */, 0 /*NumCtrls*/, \
0 /*ColWidthFixed*/, 0 /*ColWidthMin*/, 0 /*ColWidthMax*/, 0 /*ColExpand*/, 0 /*ColContract*/, \
0 /*RowHeightFixed*/, 0 /*RowHeightMin*/, 0 /*RowHeightMax*/, 0 /*RowExpand*/, 0 /*RowContract*/, \
CCtrlCounter(p) /* NumCols */, __VA_ARGS__, CCtrlCounter(p, 1, 3, WMH_END)
/// "Footer" of a rect ctrl group. MUST be paired with a WMB_HEAD()
#define WMB_END() CCtrlCounter(p, -1, 1, _DeInit(p, WM_END))
/*@}*/
//
/// \name Ctrl group Cols
/*@{*/
/// Auto-min and auto-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
*/
#define WMB_COL(_size) _size, WMSRCMM_SIZECALC, WMSRCMM_SIZECALC
/// Fixed-min and auto-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _min Min-size of the column. Positive if DLGUnits, negative for Pixels
*/
#define WMB_COLMIN(_size, _min) _size, _min, WMSRCMM_SIZECALC
/// Auto-min and fixed-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _max Max-size of the column. Positive if DLGUnits, negative for Pixels
*/
#define WMB_COLMAX(_size, _max) _size, WMSRCMM_SIZECALC, _max
/// Fixed-min and fixed-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _min Min-size of the column. Positive if DLGUnits, negative for Pixels
* \param _max Max-size of the column. Positive if DLGUnits, negative for Pixels
*/
#define WMB_COLMINMAX(_size, _min, _max) _size, _min, _max
/// 0-min and auto-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
*/
#define WMB_COLNOMIN(_size) _size, 0, WMSRCMM_SIZECALC
/// Auto-min and infinite-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
*/
#define WMB_COLNOMAX(_size) _size, WMSRCMM_SIZECALC, WMSRCMM_MAXVAL
/// 0-min and infinite-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
*/
#define WMB_COLNOMINNOMAX(_size) _size, 0, WMSRCMM_MAXVAL
/// Fixed-min and infinite-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _min Min-size of the column. Positive if DLGUnits, negative for Pixels
*/
#define WMB_COLMINNOMAX(_size, _min) _size, _min, WMSRCMM_MAXVAL
/// 0-min and fixed-max column. To be used with WMB_HEAD()
/** \param _size The size and type of the column. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _max Max-size of the column. Positive if DLGUnits, negative for Pixels
*/
#define WMB_COLNOMINMAX(_size, _max) _size, 0, _max
/*@}*/
//
/// \name Ctrl group Rows
/*@{*/
/// Auto-min and auto-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROW(_size, ...) (_IncRow(p), WMR_BEGIN), _size, WMSRCMM_SIZECALC, WMSRCMM_SIZECALC, __VA_ARGS__, WMR_END
/// Fixed-min and auto-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _min Min-size of the row. Positive if DLGUnits, negative for Pixels
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROWMIN(_size, _min, ...) (_IncRow(p), WMR_BEGIN), _size, _min, WMSRCMM_SIZECALC, __VA_ARGS__, WMR_END
/// Auto-min and fixed-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _max Max-size of the row. Positive if DLGUnits, negative for Pixels
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROWMAX(_size, _max, ...) (_IncRow(p), WMR_BEGIN), _size, WMSRCMM_SIZECALC, _max, __VA_ARGS__, WMR_END
/// Fixed-min and fixed-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _min Min-size of the row. Positive if DLGUnits, negative for Pixels
* \param _max Max-size of the row. Positive if DLGUnits, negative for Pixels
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROWMINMAX(_size, _min, _max, ...) (_IncRow(p), WMR_BEGIN), _size, _min, _max, __VA_ARGS__, WMR_END
/// 0-min and auto-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROWNOMIN(_size, ...) (_IncRow(p), WMR_BEGIN), _size, 0, WMSRCMM_SIZECALC, __VA_ARGS__, WMR_END
/// Auto-min and infinite-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROWNOMAX(_size, ...) (_IncRow(p), WMR_BEGIN), _size, WMSRCMM_SIZECALC, WMSRCMM_MAXVAL, __VA_ARGS__, WMR_END
/// 0-min and infinite-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROWNOMINNOMAX(_size, ...) (_IncRow(p), WMR_BEGIN), _size, 0, WMSRCMM_MAXVAL, __VA_ARGS__, WMR_END
/// Fixed-min and infinite-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _min Min-size of the row. Positive if DLGUnits, negative for Pixels
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROWMINNOMAX(_size, _min, ...) (_IncRow(p), WMR_BEGIN), _size, _min, WMSRCMM_MAXVAL, __VA_ARGS__, WMR_END
/// 0-min and fixed-max row. To be used with WMB_HEAD()
/** \param _size The size and type of the row. For example WMSRC_AUTO/_auto or WMSRC_EXPANDABLE/_exp
* \param _max Max-size of the row. Positive if DLGUnits, negative for Pixels
* \param ... Comma separated list of IDs if ctrls (or WMB_HEAD()/WMB_END() ctrl groups, or WMSCTRL_EMPTY/_/__ or WMSCTRL_EXPRIGHT/_r or WMSCTRL_EXPDOWN/_d)
*/
#define WMB_ROWNOMINMAX(_size, _max, ...) (_IncRow(p), WMR_BEGIN), _size, 0, _max, __VA_ARGS__, WMR_END
/*@}*/
//
/// \name User constants (format of columns/rows)
/*@{*/
#define WMSRC_AUTO 0x40000000L ///< [_auto] Use the maximum width/height of the controls in the column/row as the size. No optional parameter
#define WMSRC_EXPANDABLE 0x30000000L ///< [_exp] The column/row will be proportionally expanded. Optional parameter: "weight" of the column/row (DEFAULT: 100)
#define WMSRC_CONTRACTABLE 0x20000000L ///< [_contr] If all the other rows/columns are already maxed out, the remaining space will be divided proportionally between Contractable columns. Optional parameter: "weight" of the column/row (DEFAULT: 100)
#define WMSRC_EQUAL 0x10000000L ///< [_eq] The column/row will have the same width/height and the same min/max width/height of another column/row. Necessary parameter: the number of the column/row (zero based. The first column/row is the number 0)
#define WMSRC_GAP 0x07000000L ///< [_gap] The column/row will be GAP wide (usefull for some tricks). Optional parameter: "extra" width/height ADDED to the column. Positive if DLGUnits, negative (remember the ^) for Pixels
#define WMSRC_GAPM 0x06000000L ///< [_gapm] The column/row will be GAP wide (usefull for some tricks). Optional parameter: "extra" width/height SUBTRACTED (minimum 0) to the column. Positive if DLGUnits, negative (remember the ^) for Pixels
#define WMSRC_FIXED 0x00000000L ///< [(nothing)] The width/height of the column is fixed. Necessary parameter: the width/height of the column/row. Positive if DLGUnits, negative (remember the ^) for Pixels. Note that you don't need to use WMSRC_FIXED because it's 0
#define WMSRC_NOGAP 0x08000000L ///< [_nog] (this is a special flag to add to the other flags). Do not prepend the usual gap before this column/row. The first column/row doesn't have a gap
/*@}*/
/// \name Internal constants (format of columns/rows)
/*@{*/
#define WMSRC_TYPEMASK 0x77000000L ///< Extracts the Type of a column/row descriptor
#define WMSRC_EXSTYLEMASK 0x08000000L ///< Extracts the Extended Style (WMSRC_NOGAP) of a column/row descriptor
#define WMSRC_VALMASK 0x80FFFFFFL ///< Extracts the Parameter of a column/row descriptor. Note that if the parameter is negative then extra care will be needed for the Type and ExStyle
//
#define WMSRCMM_SIZECALC 0x40000000L ///< The minimum and/or maximum width/height of a column/row will be auto-calced by the library
#define WMSRCMM_NEEDCALC 0x20000000L ///< Internally used!
#define WMSRCMM_TYPEMASK 0x70000000L ///< Extracts the Type of a min/max column/row descriptor
#define WMSRCMM_VALMASK 0x8FFFFFFFL ///< Extracts the Value of a min/max column/row descriptor. Positive if DLGUnits, negative (remember the ^) for Pixels
#define WMSRCMM_MAXVAL 0x0FFFFFFFL ///< The maximum width/height of a min/max column/row descriptor ("infinite" width/height)
//
#define WMSRC_DEFEXPANDABLEVAL 100 ///< The default Expandable "weight"
#define WMSRC_DEFCONTRACTABLEVAL 100 ///< The default Contractable "weight"
/*@}*/
//
/// \name Internally used signatures
/*@{*/
#define WMH_BEGIN 0xFFFFFFFFL ///< Header Begin
#define WMH_END 0xFFFFFFFEL ///< Header End
#define WMR_BEGIN 0xFFFFFFFDL ///< Row Begin
#define WMR_END 0xFFFFFFFCL ///< Row End
#define WM_END 0xFFFFFFFBL ///< Ctrl Group End
/*@}*/
//
/// \name User constants (cell format)
/*@{*/
#define WMSCTRL_EXPRIGHT 0x40000001L ///< [_r] The ctrl on the left of this cell will continue in this cell
#define WMSCTRL_EXPDOWN 0x40000002L ///< [_d] The ctrl on the top of this cell will continue in this cell
#define WMSCTRL_EMPTY 0x00000000L ///< [_ & __] The cell is empty (you could directly use 0, but it would be more ugly to debug)
/*@}*/
/// \name Internal constants (cell format)
/*@{*/
#define WMSCTRL_CONTINUEMASK 0x40000000L ///< "continue" mask (can be used to check for a continue)
#define WMSCTRL_TYPEMASK 0x70000000L ///< Extracts the Type of a ctrl
#define WMSCTRL_VALMASK 0x8FFFFFFFL ///< Extracts the ID of a ctrl
/*@}*/
//
/// A no overflow integer class
/** It's probably quite slow because I wasn't able to use the overflow
* flag of the processor so I had to use int64s. I hope the compiler
* will optimize it. The class has the same size as an int and is an int
* with some operators overloaded. Only sums, subtractions and comparisons
* are supported.
*/
class int_no
{
public:
int m_iVal; ///< The integer value
public:
/// Constructor
/** \param iVal Base value
*/
int_no(int iVal = 0) : m_iVal(iVal)
{
}
/// Pointer to the integer
operator int*()
{
return &m_iVal;
}
/// Reference to the integer
operator int&()
{
return m_iVal;
}
/// "=" operator
/** \param iVal New value
*/
int_no& operator=(int iVal)
{
m_iVal = iVal;
return *this;
}
/// Equal operator
/** \param iVal Value to be compared with
*/
bool operator ==(int iVal) const
{
return m_iVal == iVal;
}
/// Unequal operator
/** \param iVal Value to be compared with
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -