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

📄 atlautosizedlg.h

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 H
📖 第 1 页 / 共 5 页
字号:
							ATLTRACE(_T("Rows can be equal only to preceeding rows. Flag in row: %d ignored. Auto-row set.\n"), iRow);
							ppiRowBegin[iRow][1] = WMSRC_AUTO|iStyle;
							piRowAuto[iRow] = 0;
							iRowDef = iRow;

							_SetVariableMinMax(iRow, ppiRowBegin[iRow] + 1);
						} else {
							iRowDef = iVal;
							while (piRowAuto[iRowDef] < 0 && piRowAuto[iRowDef] != INT_MIN) {
								iRowDef = -piRowAuto[iRowDef] - 1;
							}

							int iTypeDef, iStyleDef, iValDef;
							_TypeVal(ppiRowBegin[iRowDef][1], iTypeDef, iStyleDef, iValDef);

							_CheckEqualMinMax(iRow, ppiRowBegin[iRow] + 1);

							if (iTypeDef == WMSRC_AUTO) {
								piRowAuto[iRow] = -(iRowDef + 1);
							} else if (iTypeDef == WMSRC_EXPANDABLE) {
								piRowAuto[iRow] = INT_MIN;

								iRowExpand += iValDef;
							} else if (iTypeDef == WMSRC_CONTRACTABLE) {
								piRowAuto[iRow] = INT_MIN;

								iRowContract += iValDef;
							} else if (iTypeDef == WMSRC_GAP) {
								piRowAuto[iRow] = INT_MIN;

								int iHeight = pmargins->m_iYGap;
								if (iValDef > 0) {
									iHeight += ::MulDiv(iValDef, lYUnits, 8);
								} else {
									iHeight += (-iValDef);
								}
							} else if (iTypeDef == WMSRC_GAPM) {
								piRowAuto[iRow] = INT_MIN;

								int iHeight = pmargins->m_iYGap;
								if (iValDef > 0) {
									iHeight -= ::MulDiv(iValDef, lYUnits, 8);
								} else {
									iHeight -= (-iValDef);
								}

								if (iHeight < 0) {
									iHeight = 0;
								}
							} else {
								piRowAuto[iRow] = INT_MIN;

								int iHeight;
								if (iValDef > 0) {
									iHeight = ::MulDiv(iValDef, lYUnits, 8);
								} else {
									iHeight = -iValDef;
								}
							}
						}
					} else if (iType == WMSRC_GAP) {
						piRowAuto[iRow] = INT_MIN;
						iRowDef = iRow;

						int iHeight = pmargins->m_iYGap;
						if (iVal > 0) {
							iHeight += ::MulDiv(iVal, lYUnits, 8);
						} else {
							iHeight += (-iVal);
						}

						_CheckFixedMinMax(iRow, ppiRowBegin[iRow] + 1, lYUnits, 8, iHeight);
					} else if (iType == WMSRC_GAPM) {
						piRowAuto[iRow] = INT_MIN;
						iRowDef = iRow;

						int iHeight = pmargins->m_iYGap;
						if (iVal > 0) {
							iHeight -= ::MulDiv(iVal, lYUnits, 8);
						} else {
							iHeight -= (-iVal);
						}

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

						_CheckFixedMinMax(iRow, ppiRowBegin[iRow] + 1, lYUnits, 8, iHeight);
					} else {
						iRowDef = iRow;
						if (iVal > 0) {
							if (iType) {
								ATLTRACE(_T("Wrong flag in row: %d. Ignored. Auto-row set.\n"), iRow);
								ppiRowBegin[iRow][1] = WMSRC_AUTO|iStyle;
								piRowAuto[iRow] = 0;

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

								int iHeight = ::MulDiv(iVal, lYUnits, 8);

								_CheckFixedMinMax(iRow, ppiRowBegin[iRow] + 1, lYUnits, 8, iHeight);
							}
						} else {
							piRowAuto[iRow] = INT_MIN;

							int iHeight = -iVal;

							_CheckFixedMinMax(iRow, ppiRowBegin[iRow] + 1, lYUnits, 8, iHeight);
						}
					}

					piCell += 4;

					int iCol = 0, iColDef = 0;
					while (*piCell != WMR_END && *piCell != WM_END) {
						if (iCol < pheader->m_iNumCols) {
							iColDef = (piColAuto[iCol] == INT_MIN || piColAuto[iCol] >= 0 ? iCol: -piColAuto[iCol] - 1);

							if (*piCell != WMH_BEGIN && *piCell != WMSCTRL_EMPTY && *piCell != WMSCTRL_EXPDOWN && *piCell != WMSCTRL_EXPRIGHT) {
								iNumCtrls++;
								if (piColAuto[iColDef] != INT_MIN || piRowAuto[iRowDef] != INT_MIN || 
									piHeadCols[iColDef * 3 + 1] & WMSRCMM_NEEDCALC || piHeadCols[iColDef * 3 + 2] & WMSRCMM_NEEDCALC || 
									ppiRowBegin[iRowDef][2] & WMSRCMM_NEEDCALC || ppiRowBegin[iRowDef][3] & WMSRCMM_NEEDCALC) {

									HWND hWnd = pT->GetDlgItem(*piCell);
									if (!hWnd) {
										ATLTRACE(_T("Inexistant ctrl in row: %d, col: %d. Ignored.\n"), iRow, iCol);
									} else {
										const MINMAXINFO mmOrig = {0, 0, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX};
										MINMAXINFO mm = mmOrig;

										::SendMessage(hWnd, WM_GETMINMAXINFO, 0, (LPARAM)&mm);
										if (::memcmp(&mm, &mmOrig, sizeof(MINMAXINFO)) != 0) {
											_CalcAuto(piColAuto[iColDef], mm.ptMinTrackSize.x);
											_CalcMinMaxAuto(piHeadCols + iColDef * 3, mm.ptMinTrackSize.x, mm.ptMaxTrackSize.x);

											_CalcAuto(piRowAuto[iRowDef], mm.ptMinTrackSize.y);
											_CalcMinMaxAuto(ppiRowBegin[iRowDef] + 1, mm.ptMinTrackSize.y, mm.ptMaxTrackSize.y);
										} else {
											RECT rect = {0};
											ATLVERIFY(::GetWindowRect(hWnd, &rect));

											int iWidth = rect.right - rect.left;
											_CalcAuto(piColAuto[iColDef], iWidth);

											int iHeight = rect.bottom - rect.top;
											_CalcAuto(piRowAuto[iRowDef], iHeight);
										}
									}
								}
							} else if (*piCell == WMH_BEGIN) {
								CCtrlGroup *pheaderNew = (CCtrlGroup*)piCell; 
								if (_CtrlsInitialize(pheaderNew, pmargins, lXUnits, lYUnits, FALSE)) {
									_CalcAuto(piColAuto[iColDef], pheaderNew->m_iColWidthMin);
									_CalcMinMaxAuto(piHeadCols + iColDef * 3, pheaderNew->m_iColWidthMin, pheaderNew->m_iColWidthMax);

									_CalcAuto(piRowAuto[iRowDef], pheaderNew->m_iRowHeightMin);
									_CalcMinMaxAuto(ppiRowBegin[iRowDef] + 1, pheaderNew->m_iRowHeightMin, pheaderNew->m_iRowHeightMax);

									iNumCtrls += pheaderNew->m_iNumCtrls;

									piCell += piCell[1];
								} else {
									return FALSE;
								}
							}
						} else {
							ATLTRACE(_T("Too many columns. Row: %d, col: %d ignored.\n"), iRow, iCol);

							if (*piCell == WMH_BEGIN) {
								piCell += piCell[1];
							}
						}

						iCol++;
						piCell++;
					}

					if (*piCell == WM_END) {
						ATLTRACE(_T("Malformed endrow in row: %d. Ignored.\n"), iRow);
					} 
				} else {
					ATLTRACE(_T("Malformed row: %d. Skipped. \n"), iRow);
					while (*piCell != WMR_END && *piCell != WM_END) {
						piCell++;
					}

					piRowAuto[iRow] = INT_MIN;
				}

				iRow++;

				if (*piCell != WM_END) {
					piCell++;
				}
			}

#ifdef TRACEAUTOSIZE
			ATLTRACE("Rows: ");
#endif 
			for (int i = 0; i < iRow; i++) {
				if (piRowAuto[i] != INT_MIN) {
					if (piRowAuto[i] >= 0) {
						_CheckAutoMinMax(ppiRowBegin[i] + 1, piRowAuto[i]);
						int iType = ppiRowBegin[i][1] & WMSRC_TYPEMASK;
						_AddMinMax(i, ppiRowBegin[i] + 1, lYUnits, 8, iRowHeightFixed, iType, iRowHeightMin, iRowHeightMax);
						_SetAuto(ppiRowBegin[i] + 1, lYUnits, 8, piRowAuto[i]);
					} else {
						int iDef = -piRowAuto[i] - 1;
						int iType = ppiRowBegin[iDef][1] & WMSRC_TYPEMASK;
						_AddMinMax(i, ppiRowBegin[iDef] + 1, lYUnits, 8, iRowHeightFixed, iType, iRowHeightMin, iRowHeightMax);
					}
				} else {
					int iType = ppiRowBegin[i][1] & WMSRC_TYPEMASK;
					_AddMinMax(i, ppiRowBegin[i] + 1, lYUnits, 8, iRowHeightFixed, iType, iRowHeightMin, iRowHeightMax);
				}

#ifdef TRACEAUTOSIZE
				int iTypeMin, iTypeMax;
				int iMinPix, iMaxPix;
				_LoadMinMax(ppiRowBegin[i] + 1, lYUnits, 8, iTypeMin, iMinPix, iTypeMax, iMaxPix);
				ATLTRACE("%d-%d ", iMinPix, iMaxPix);
#endif
			}
		}

#ifdef TRACEAUTOSIZE
		ATLTRACE("\nCols: ");
#endif
		for (int i = 0; i < pheader->m_iNumCols; i++) {
			if (piColAuto[i] != INT_MIN) {
				if (piColAuto[i] >= 0) {
					_CheckAutoMinMax(piHeadCols + i * 3, piColAuto[i]);
					int iType = piHeadCols[i * 3] & WMSRC_TYPEMASK;
					_AddMinMax(i, piHeadCols + i * 3, lXUnits, 4, iColWidthFixed, iType, iColWidthMin, iColWidthMax);
					_SetAuto(piHeadCols + i * 3, lXUnits, 4, piColAuto[i]);
				} else {
					int iDef = -piColAuto[i] - 1;
					int iType = piHeadCols[iDef * 3] & WMSRC_TYPEMASK;
					_AddMinMax(i, piHeadCols + iDef * 3, lXUnits, 4, iColWidthFixed, iType, iColWidthMin, iColWidthMax);
				}
			} else {
				int iType = piHeadCols[i * 3] & WMSRC_TYPEMASK;
				_AddMinMax(i, piHeadCols + i * 3, lXUnits, 4, iColWidthFixed, iType, iColWidthMin, iColWidthMax);
			}

#ifdef TRACEAUTOSIZE
			int iTypeMin, iTypeMax;
			int iMinPix, iMaxPix;
			_LoadMinMax(piHeadCols + i * 3, lXUnits, 4, iTypeMin, iMinPix, iTypeMax, iMaxPix);
			ATLTRACE("%d-%d ", iMinPix, iMaxPix);
#endif
		}

#ifdef TRACEAUTOSIZE
		ATLTRACE("\n");
#endif

		if (iRow != pheader->m_iNumRows) {
			ATLTRACE(_T("Number of rows incorrect. Fixed.\n"));
			pheader->m_iNumRows = iRow;
		}

		pheader->m_iNumCtrls = iNumCtrls;
		pheader->m_iColWidthFixed = iColWidthFixed;
		pheader->m_iColWidthMin = iColWidthMin;
		pheader->m_iColWidthMax = iColWidthMax;
		pheader->m_iColExpand = iColExpand;
		pheader->m_iColContract = iColContract;

		pheader->m_iRowHeightFixed = iRowHeightFixed;
		pheader->m_iRowHeightMin = iRowHeightMin;
		pheader->m_iRowHeightMax = iRowHeightMax;
		pheader->m_iRowExpand = iRowExpand;
		pheader->m_iRowContract = iRowContract;

#ifdef TRACEAUTOSIZE
		ATLTRACE("Fixed: %d, %d. Min: %d, %d. Max: %d, %d\n", iColWidthFixed, iRowHeightFixed, iColWidthMin, iRowHeightMin, iColWidthMax, iRowHeightMax);
#endif

		ATLASSERT(*piCell == WM_END);
		return TRUE;
	}

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

		int *piHeadCols = pheader->m_iCtrls;

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

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

		if (pheader->m_iNumRows) {
			int iColTrueMin = pheader->m_iColWidthMin;
			int iColTrueMax = pheader->m_iColWidthMax;

			int iRowTrueMin = pheader->m_iRowHeightMin;
			int iRowTrueMax = pheader->m_iRowHeightMax;

			int iWidth = pRectWindow->right - pRectWindow->left;
			int iTotalColContract;

			if (iWidth < iColTrueMin) {
				ATLTRACE(_T("Width too small! Needed %d more pixels.\n"), iColTrueMin - iWidth);
				iTotalColContract = 0;
			} else if (iWidth >= iColTrueMin && iWidth <= iColTrueMax) {
				iTotalColContract = 0;
			} else {
				iTotalColContract = iWidth - iColTrueMax;
				iWidth = iColTrueMax;
			}

			int iHeight = pRectWindow->bottom - pRectWindow->top;
			int iTotalRowContract;

			if (iHeight < iRowTrueMin) {
				ATLTRACE(_T("Height too small! Needed %d more pixels.\n"), iRowTrueMin - iHeight);
				iTotalRowContract = 0;
			} else if (iHeight >= iRowTrueMin && iHeight <= iRowTrueMax) {
				iTotalRowContract = 0;
			} else {
				iTotalRowContract = iHeight - iRowTrueMax;
				iHeight = iRowTrueMax;
			}

#ifdef TRACEAUTOSIZE2
			ATLTRACE("Rect: %d, %d\n", iWidth, iHeight);
#endif

			int iTotalColExpand = (iWidth > iColTrueMin ? iWidth - pheader->m_iColWidthFixed : 0);
			int iColExpand = pheader->m_iColExpand, iColContract = pheader->m_iColContract;

			int iTotalRowExpand = (iHeight > iRowTrueMin ? iHeight - pheader->m_iRowHeightFixed : 0);
			int iRowExpand = pheader->m_iRowExpand, iRowContract = pheader->m_iRowContract;

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

			int iWidthTotal = pRectWindow->left;
			if (bMain) {
				iWidthTotal += pmargins->m_iLeftRight;
			}

#ifdef TRACEAUTOSIZE2
			ATLTRACE("Cols: ");
#endif

			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)) {
					iWidthTotal += pmargins->m_iXGap;
				}

				if (iWidthTotal > pRectWindow->right) {
					iWidthTotal = pRectWindow->right;
				}

				int iTypeMin, iTypeMax;
				int iMinPix, iMaxPix;
				_LoadMinMax(piHeadCols + i * 3, lXUnits, 4, iTypeMin, iMinPix, iTypeMax, iMaxPix);

				if (iType == WMSRC_AUTO) {
					piWidthCol[i] = iVal;
				} else if (iType == WMSRC_EXPANDABLE) {
					piWidthCol[i] = ::MulDiv(iTotalColExpand, iVal, iColExpand);
					_NormalizeColRow(piWidthCol[i], iMinPix, iMaxPix);
					iColExpand -= iVal;
					iTotalColExpand = (iTotalColExpand > piWidthCol[i] ? iTotalColExpand - piWidthCol[i] : 0);
				} else if (iType == WMSRC_CONTRACTABLE) {
					piWidthCol[i] = ::MulDiv(iTotalColContract, iVal, iColContract);
					_NormalizeColRow(piWidthCol[i], iMinPix, iMaxPix);
					iColContract -= iVal;
					iTotalColContract = (iTotalColContract > piWidthCol[i] ? iTotalColContract - piWidthCol[i] : 0);
				} else if (iType == WMSRC_EQUAL) {
					int iColDef = iVal;
					int iTypeDef, iStyleDef, iValDef;
					do {
						_TypeVal(piHeadCols[iColDef * 3], iTypeDef, iStyleDef, iValDef);
					} while (iTypeDef == WMSRC_EQUAL && (iColDef = iValDef) == iColDef);

					int iTypeMinDef, iTypeMaxDef;
					int iMinPixDef, iMaxPixDef;
					_LoadMinMax(piHeadCols + iColDef * 3, lXUnits, 4, iTypeMinDef, iMinPixDef, iTypeMaxDef, iMaxPixDef);

⌨️ 快捷键说明

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