⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atlautosizedlg.h

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 H
📖 第 1 页 / 共 5 页
字号:
		} else {
			return FALSE;
		}
	}

	/// Arranges the ctrls of the window. Initializes the window if necessary
	/** \param piCtrls Ctrls map
	 *  \return TRUE if successful, FALSE if failure
	 */
	BOOL CtrlsArrange(CWindowMapStruct *piCtrls = T::GetWindowMap())
	{
		T* pT = static_cast<T*>(this);

		if (!pT->CtrlsInitialize(piCtrls)) {
			ATLTRACE(_T("Not initialized.\n"));
			return FALSE;
		}

		RECT rectUnits = {4, 8, 0, 0};
		ATLVERIFY(pT->MapDialogRect(&rectUnits));
		LONG lXUnits = rectUnits.left, lYUnits = rectUnits.top;

		RECT rect;
		ATLVERIFY(pT->GetClientRect(&rect));

		CMargins marginsPix;
		_CheckMargins(lXUnits, 4, lYUnits, 8, &piCtrls->m_margins, &marginsPix);

		rect.right = (rect.right > marginsPix.m_iLeftRight ? rect.right - marginsPix.m_iLeftRight : 0);
		rect.bottom = (rect.bottom > marginsPix.m_iTopBottom ? rect.bottom - marginsPix.m_iTopBottom : 0);

		CCtrlGroup *pheader = &piCtrls->m_header;

		if (rect.right < pheader->m_iColWidthMin) {
			rect.right = pheader->m_iColWidthMin;
		}

		if (rect.bottom < pheader->m_iRowHeightMin) {
			rect.bottom = pheader->m_iRowHeightMin;
		}

		HDWP hdwp;
		ATLVERIFY((hdwp = ::BeginDeferWindowPos(pheader->m_iNumCtrls)) != NULL);
		if (!hdwp) {
			return FALSE;
		}

		BOOL bRes;
		ATLVERIFY((bRes = _CtrlsArrange(hdwp, pheader, &marginsPix, lXUnits, lYUnits, &rect)) != FALSE);

		ATLVERIFY(::EndDeferWindowPos(hdwp));

		return bRes;
	}

	/// Gets the minimum size of the window. Initializes the window if necessary
	/** \param sizeMin This variable will contain the minimum size of the window
	 *  \param piCtrls Ctrls map
	 *  \return TRUE if successful, FALSE if failure
	 */
	BOOL GetMinSize(SIZE &sizeMin, CWindowMapStruct *piCtrls = T::GetWindowMap())
	{
		SIZE sz;
		return GetMinMaxSize(sizeMin, sz, piCtrls);
	}

	/// Gets the maximum size of the window. Initializes the window if necessary
	/** \param sizeMax This variable will contain the maximum size of the window
	 *  \param piCtrls Ctrls map
	 *  \return TRUE if successful, FALSE if failure
	 */
	BOOL GetMaxSize(SIZE &sizeMax, CWindowMapStruct *piCtrls = T::GetWindowMap())
	{
		SIZE sz;
		return GetMinMaxSize(sz, sizeMax, piCtrls);
	}

	/// Gets the minimum and maximum size of the window. Initializes the window if necessary
	/** \param sizeMin This variable will contain the minimum size of the window
	 *  \param sizeMax This variable will contain the maximum size of the window
	 *  \param piCtrls Ctrls map
	 *  \return TRUE if successful, FALSE if failure
	 */
	BOOL GetMinMaxSize(SIZE &sizeMin, SIZE &sizeMax, CWindowMapStruct *piCtrls = T::GetWindowMap())
	{
		if (!CtrlsInitialize(piCtrls)) {
			ATLTRACE(_T("Not initialized.\n"));
			return FALSE;
		}

		T* pT = static_cast<T*>(this);

		RECT rectUnits = {4, 8, 0, 0};
		ATLVERIFY(pT->MapDialogRect(&rectUnits));
		LONG lXUnits = rectUnits.left, lYUnits = rectUnits.top;

		CMargins marginsPix;
		_CheckMargins(lXUnits, 4, lYUnits, 8, &piCtrls->m_margins, &marginsPix);

		CCtrlGroup *pheader = &piCtrls->m_header;
		sizeMin.cx = pheader->m_iColWidthMin + marginsPix.m_iLeftRight;
		sizeMin.cy = pheader->m_iRowHeightMin + marginsPix.m_iTopBottom;

		if (pheader->m_iColWidthMax != INT_MAX) {
			sizeMax.cx = pheader->m_iColWidthMax + marginsPix.m_iLeftRight;
		} else {
			sizeMax.cx = INT_MAX;
		}

		if (pheader->m_iRowHeightMax != INT_MAX) {
			sizeMax.cy = pheader->m_iRowHeightMax + marginsPix.m_iTopBottom;
		} else {
			sizeMax.cy = INT_MAX;
		}

		return TRUE;
	}

	/// Does the paint work. You can override it, but remember to call this method in the end, otherwise Transparent ctrls won't be painted.
	/** \param dc The hDC to paint to
	 */
	void DoPaint(WTL::CDCHandle dc)
	{
		T* pT = static_cast<T*>(this);
		ATLVERIFY(pT->HandleTransparentMap(dc));
	}

protected:
	BOOL _CtrlsInitialize(CCtrlGroup *pheader, CMargins *pmargins, LONG lXUnits, LONG lYUnits, BOOL bMain = TRUE)
	{
		if (pheader->m_iSignature != WMH_BEGIN) {
			ATLTRACE(_T("Wrong header format. Aborted.\n"));
			return FALSE;
		}

		int *piHeadCols = pheader->m_iCtrls;

		if (piHeadCols[pheader->m_iNumCols * 3] != WMH_END) {
			ATLTRACE(_T("Wrong header format. Aborted.\n"));
			return FALSE;
		}

		if (*((int*)pheader + pheader->m_iSize) != WM_END) {
			ATLTRACE(_T("Wrong header format. Aborted.\n"));
			return FALSE;
		}

		int *piCell = piHeadCols + pheader->m_iNumCols * 3 + 1;

		if (*piCell != WMR_BEGIN && *piCell != WM_END) {
			ATLTRACE(_T("Malformed endrow in header.\n"));
			return FALSE;
		}

		T* pT = static_cast<T*>(this);

		int iColWidthFixed = 0;
		int iColWidthMin = 0;
		int_no iColWidthMax = 0;
		int iColExpand = 0;
		int iColContract = 0;

		int *piColAuto = (int*)_alloca(pheader->m_iNumCols * sizeof(int));

		if (bMain) {
			iColWidthFixed += pmargins->m_iLeftRight;
			iColWidthMin += pmargins->m_iLeftRight;
			iColWidthMax += pmargins->m_iLeftRight;
		}

		for (int i = 0; i < pheader->m_iNumCols; i++) {
			int iType, iStyle, iVal;
			_TypeVal(piHeadCols[i * 3], iType, iStyle, iVal);

			if (i && !(iStyle & WMSRC_NOGAP)) {
				iColWidthFixed += pmargins->m_iXGap;
				iColWidthMin += pmargins->m_iXGap;
				iColWidthMax += pmargins->m_iXGap;
			}

			if (iType == WMSRC_AUTO) {
				piColAuto[i] = 0;

				piHeadCols[i * 3] = iType|iStyle;

				_SetVariableMinMax(i, piHeadCols + i * 3);
			} else if (iType == WMSRC_EXPANDABLE) {
				piColAuto[i] = INT_MIN;

				if (iVal > 0) {
					iColExpand += iVal;
				} else if (iVal == 0) {
					piHeadCols[i * 3] |= WMSRC_DEFEXPANDABLEVAL;
					iColExpand += WMSRC_DEFEXPANDABLEVAL;
				} else {
					ATLTRACE(_T("Wrong value in column: %d. Ignored.\n"), i);
					piHeadCols[i * 3] = iType|iStyle|WMSRC_DEFEXPANDABLEVAL;
					iColExpand += WMSRC_DEFEXPANDABLEVAL;
				}

				_SetVariableMinMax(i, piHeadCols + i * 3);
			} else if (iType == WMSRC_CONTRACTABLE) {
				piColAuto[i] = INT_MIN;

				if (iVal > 0) {
					iColContract += iVal;
				} else if (iVal == 0) {
					piHeadCols[i * 3] |= WMSRC_DEFCONTRACTABLEVAL;
					iColContract += WMSRC_DEFCONTRACTABLEVAL;
				} else {
					ATLTRACE(_T("Wrong value in column: %d. Ignored.\n"), i);
					piHeadCols[i * 3] = iType|iStyle|WMSRC_DEFCONTRACTABLEVAL;
					iColContract += WMSRC_DEFCONTRACTABLEVAL;
				}

				_SetVariableMinMax(i, piHeadCols + i * 3);
			} else if (iType == WMSRC_EQUAL) {
				if (iVal >= i || iVal < 0) {
					ATLTRACE(_T("Columns can be equal only to preceeding columns. Flag in column: %d ignored. Auto-column set.\n"), i);
					piHeadCols[i * 3] = WMSRC_AUTO|iStyle;
					piColAuto[i] = 0;

					_SetVariableMinMax(i, piHeadCols + i * 3);
				} else {
					int iColDef = iVal;
					while (piColAuto[iColDef] < 0 && piColAuto[iColDef] != INT_MIN) {
						iColDef = -piColAuto[iColDef] - 1;
					}

					int iTypeDef, iStyleDef, iValDef;
					_TypeVal(piHeadCols[iColDef * 3], iTypeDef, iStyleDef, iValDef);

					_CheckEqualMinMax(i, piHeadCols + i * 3);

					piColAuto[i] = -(iColDef + 1);

					if (iTypeDef == WMSRC_AUTO) {
					} else if (iTypeDef == WMSRC_EXPANDABLE) {
						iColExpand += iValDef;
					} else if (iTypeDef == WMSRC_CONTRACTABLE) {
						iColContract += iValDef;
					} else if (iTypeDef == WMSRC_GAP) {
						int iWidth = pmargins->m_iXGap;
						if (iValDef > 0) {
							iWidth += ::MulDiv(iValDef, lXUnits, 4);
						} else {
							iWidth += (-iValDef);
						}
					} else if (iTypeDef == WMSRC_GAPM) {
						int iWidth = pmargins->m_iXGap;
						if (iValDef > 0) {
							iWidth -= ::MulDiv(iValDef, lXUnits, 4);
						} else {
							iWidth -= (-iValDef);
						}

						if (iWidth < 0) {
							iWidth = 0;
						}
					} else {
						int iWidth;
						if (iValDef > 0) {
							iWidth = ::MulDiv(iValDef, lXUnits, 4);
						} else {
							iWidth = -iValDef;
						}
					}
				}
			} else if (iType == WMSRC_GAP) {
				piColAuto[i] = INT_MIN;

				int iWidth = pmargins->m_iXGap;
				if (iVal > 0) {
					iWidth += ::MulDiv(iVal, lXUnits, 4);
				} else {
					iWidth += (-iVal);
				}

				_CheckFixedMinMax(i, piHeadCols + i * 3, lXUnits, 4, iWidth);
			} else if (iType == WMSRC_GAPM) {
				piColAuto[i] = INT_MIN;

				int iWidth = pmargins->m_iXGap;
				if (iVal > 0) {
					iWidth -= ::MulDiv(iVal, lXUnits, 4);
				} else {
					iWidth -= (-iVal);
				}

				if (iWidth < 0) {
					iWidth = 0;
				}

				_CheckFixedMinMax(i, piHeadCols + i * 3, lXUnits, 4, iWidth);
			} else {
				if (iVal > 0) {
					if (iType) {
						ATLTRACE(_T("Wrong flag in column: %d. Ignored. Auto-column set.\n"), i);
						piHeadCols[i * 3] = WMSRC_AUTO|iStyle;
						piColAuto[i] = 0;

						_SetVariableMinMax(i, piHeadCols + i * 3);
					} else {
						piColAuto[i] = INT_MIN;

						int iWidth = ::MulDiv(iVal, lXUnits, 4);

						_CheckFixedMinMax(i, piHeadCols + i * 3, lXUnits, 4, iWidth);
					}
				} else {
					piColAuto[i] = INT_MIN;

					int iWidth = -iVal;

					_CheckFixedMinMax(i, piHeadCols + i * 3, lXUnits, 4, iWidth);
				}
			}
		}

		int iNumCtrls = 0;

		int iRow = 0, iRowDef = 0;
		int iRowHeightFixed = 0;
		int iRowHeightMin = 0;
		int_no iRowHeightMax = 0;
		int iRowExpand = 0;
		int iRowContract = 0;

		if (pheader->m_iNumRows) {
			int *piRowAuto = (int*)_alloca(pheader->m_iNumRows * sizeof(int));
			int **ppiRowBegin = (int**)_alloca(pheader->m_iNumRows * sizeof(int*));

			if (bMain) {
				iRowHeightFixed += pmargins->m_iTopBottom;
				iRowHeightMin += pmargins->m_iTopBottom;
				iRowHeightMax += pmargins->m_iTopBottom;
			}

			while (*piCell != WM_END) {
				ppiRowBegin[iRow] = piCell;

				if (ppiRowBegin[iRow][0] == WMR_BEGIN) {
					int iType, iStyle, iVal;
					_TypeVal(ppiRowBegin[iRow][1], iType, iStyle, iVal);

					if (iRow && !(iStyle & WMSRC_NOGAP)) {
						iRowHeightFixed += pmargins->m_iYGap;
						iRowHeightMin += pmargins->m_iYGap;
						iRowHeightMax += pmargins->m_iYGap;
					}

					if (iType == WMSRC_AUTO) {
						piRowAuto[iRow] = 0;
						iRowDef = iRow;

						ppiRowBegin[iRow][1] = iType|iStyle;

						_SetVariableMinMax(iRow, ppiRowBegin[iRow] + 1);
					} else if (iType == WMSRC_EXPANDABLE) {
						piRowAuto[iRow] = INT_MIN;
						iRowDef = iRow;

						if (iVal > 0) {
							iRowExpand += iVal;
						} else if (iVal == 0) {
							ppiRowBegin[iRow][1] |= WMSRC_DEFEXPANDABLEVAL;
							iRowExpand += WMSRC_DEFEXPANDABLEVAL;
						} else {
							ATLTRACE(_T("Wrong value in row: %d. Ignored.\n"), iRow);
							ppiRowBegin[iRow][1] = iType|iStyle|WMSRC_DEFEXPANDABLEVAL;
							iRowExpand += WMSRC_DEFEXPANDABLEVAL;
						}

						_SetVariableMinMax(iRow, ppiRowBegin[iRow] + 1);
					} else if (iType == WMSRC_CONTRACTABLE) {
						piRowAuto[iRow] = INT_MIN;
						iRowDef = iRow;

						if (iVal > 0) {
							iRowContract += iVal;
						} else if (iVal == 0) {
							ppiRowBegin[iRow][1] |= WMSRC_DEFCONTRACTABLEVAL;
							iRowContract += WMSRC_DEFCONTRACTABLEVAL;
						} else {
							ATLTRACE(_T("Wrong value in row: %d. Ignored.\n"), iRow);
							ppiRowBegin[iRow][1] = iType|iStyle|WMSRC_DEFCONTRACTABLEVAL;
							iRowContract += WMSRC_DEFCONTRACTABLEVAL;
						}

						_SetVariableMinMax(iRow, ppiRowBegin[iRow] + 1);
					} else if (iType == WMSRC_EQUAL) {
						if (iVal >= iRow || iVal < 0) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -