Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

285 lines
7.3 KiB

  1. #include "stdafx.h"
  2. #include "global.h"
  3. #include "pbrush.h"
  4. #include "pbrusdoc.h"
  5. #include "pbrusfrm.h"
  6. #include "pbrusvw.h"
  7. #include "docking.h"
  8. #include "minifwnd.h"
  9. #include "bmobject.h"
  10. #include "colorsrc.h"
  11. #include "imgsuprt.h"
  12. #include "imgwnd.h"
  13. #include "cmpmsg.h"
  14. #include "imgdlgs.h"
  15. #include "ferr.h"
  16. #include <colordlg.h>
  17. #include <direct.h>
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22. #include "memtrace.h"
  23. CSize NEAR g_defaultTileGridSize(16, 15);
  24. BOOL NEAR g_bDefaultTileGrid = FALSE;
  25. BEGIN_MESSAGE_MAP(C3dDialog, CDialog)
  26. ON_COMMAND(IDOK, OnRobustOK)
  27. ON_WM_CTLCOLOR()
  28. END_MESSAGE_MAP()
  29. C3dDialog::C3dDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
  30. : CDialog(lpszTemplateName, pParentWnd)
  31. {
  32. }
  33. C3dDialog::C3dDialog(UINT nTemplateID, CWnd* pParentWnd)
  34. : CDialog(nTemplateID, pParentWnd)
  35. {
  36. }
  37. BOOL C3dDialog::OnInitDialog()
  38. {
  39. // automatically center the dialog relative to it's parent
  40. CenterWindow(CmpCenterParent());
  41. return CDialog::OnInitDialog();
  42. }
  43. void C3dDialog::OnRobustOK()
  44. {
  45. OnOK(); // ok to call "real" OnOK
  46. }
  47. HBRUSH C3dDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  48. {
  49. HBRUSH hbrush = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  50. return hbrush;
  51. }
  52. BEGIN_MESSAGE_MAP(CImgGridDlg, C3dDialog)
  53. ON_BN_CLICKED(IDC_PIXELGRID, OnClickPixelGrid)
  54. ON_BN_CLICKED(IDC_TILEGRID, OnClickTileGrid)
  55. END_MESSAGE_MAP()
  56. CImgGridDlg::CImgGridDlg() : C3dDialog(IDD_IMGGRIDOPT)
  57. {
  58. m_bPixelGrid = theApp.m_bShowGrid;
  59. m_bTileGrid = g_bDefaultTileGrid;
  60. m_nWidth = g_defaultTileGridSize.cx;
  61. m_nHeight = g_defaultTileGridSize.cy;
  62. }
  63. BOOL CImgGridDlg::OnInitDialog()
  64. {
  65. C3dDialog::OnInitDialog();
  66. CheckDlgButton(IDC_PIXELGRID, m_bPixelGrid);
  67. CheckDlgButton(IDC_TILEGRID, m_bTileGrid);
  68. SetDlgItemInt(IDC_WIDTH, m_nWidth, FALSE);
  69. SetDlgItemInt(IDC_HEIGHT, m_nHeight, FALSE);
  70. GetDlgItem(IDC_TILEGRID)->EnableWindow(m_bPixelGrid);
  71. GetDlgItem(IDC_WIDTH)->EnableWindow(m_bPixelGrid && m_bTileGrid);
  72. GetDlgItem(IDC_HEIGHT)->EnableWindow(m_bPixelGrid && m_bTileGrid);
  73. return TRUE;
  74. }
  75. void CImgGridDlg::OnClickPixelGrid()
  76. {
  77. m_bPixelGrid = !m_bPixelGrid;
  78. CheckDlgButton(IDC_PIXELGRID, m_bPixelGrid);
  79. GetDlgItem(IDC_TILEGRID)->EnableWindow(m_bPixelGrid);
  80. GetDlgItem(IDC_WIDTH)->EnableWindow(m_bPixelGrid);
  81. GetDlgItem(IDC_HEIGHT)->EnableWindow(m_bPixelGrid);
  82. }
  83. void CImgGridDlg::OnClickTileGrid()
  84. {
  85. m_bTileGrid = !m_bTileGrid;
  86. CheckDlgButton(IDC_TILEGRID, m_bTileGrid);
  87. GetDlgItem(IDC_WIDTH)->EnableWindow(m_bTileGrid);
  88. GetDlgItem(IDC_HEIGHT)->EnableWindow(m_bTileGrid);
  89. }
  90. void CImgGridDlg::OnOK()
  91. {
  92. m_bPixelGrid = IsDlgButtonChecked(IDC_PIXELGRID);
  93. m_bTileGrid = IsDlgButtonChecked(IDC_TILEGRID);
  94. if (m_bTileGrid)
  95. {
  96. BOOL bTranslated;
  97. if (GetDlgItem(IDC_WIDTH)->GetWindowTextLength() == 0)
  98. {
  99. m_nWidth = 1;
  100. }
  101. else
  102. {
  103. m_nWidth = GetDlgItemInt(IDC_WIDTH, &bTranslated, FALSE);
  104. if (!bTranslated || m_nWidth < GRIDMIN || m_nWidth > GRIDMAX)
  105. {
  106. CmpMessageBoxPrintf(IDS_ERROR_GRIDRANGE, AFX_IDS_APP_TITLE,
  107. MB_OK | MB_ICONEXCLAMATION, GRIDMIN, GRIDMAX); // LOCALIZATION
  108. GetDlgItem(IDC_WIDTH)->SetFocus();
  109. return;
  110. }
  111. }
  112. if (GetDlgItem(IDC_HEIGHT)->GetWindowTextLength() == 0)
  113. {
  114. m_nHeight = 1;
  115. }
  116. else
  117. {
  118. m_nHeight = GetDlgItemInt(IDC_HEIGHT, &bTranslated, FALSE);
  119. if (!bTranslated || m_nHeight < GRIDMIN || m_nHeight > GRIDMAX)
  120. {
  121. CmpMessageBoxPrintf(IDS_ERROR_GRIDRANGE, AFX_IDS_APP_TITLE,
  122. MB_OK | MB_ICONEXCLAMATION, GRIDMIN, GRIDMAX); // LOCALIZATION
  123. GetDlgItem(IDC_HEIGHT)->SetFocus();
  124. return;
  125. }
  126. }
  127. g_defaultTileGridSize.cx = m_nWidth;
  128. g_defaultTileGridSize.cy = m_nHeight;
  129. }
  130. g_bDefaultTileGrid = m_bTileGrid;
  131. C3dDialog::OnOK();
  132. }
  133. /***************************************************************************/
  134. // CColorTable dialog
  135. CColorTable::CColorTable( CWnd* pParent /*=NULL*/ )
  136. : CDialog( CColorTable::IDD, pParent )
  137. {
  138. m_bLeft = TRUE;
  139. m_iColor = 0;
  140. }
  141. /***************************************************************************/
  142. void CColorTable::DoDataExchange( CDataExchange* pDX )
  143. {
  144. CDialog::DoDataExchange( pDX );
  145. }
  146. /***************************************************************************/
  147. BEGIN_MESSAGE_MAP(CColorTable, CDialog)
  148. //{{AFX_MSG_MAP(CColorTable)
  149. ON_WM_DRAWITEM()
  150. ON_WM_MEASUREITEM()
  151. ON_LBN_DBLCLK(IDC_COLORLIST, OnDblclkColorlist)
  152. //}}AFX_MSG_MAP
  153. END_MESSAGE_MAP()
  154. /***************************************************************************/
  155. // CColorTable message handlers
  156. void CColorTable::OnDrawItem( int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct )
  157. {
  158. if ((int) lpDrawItemStruct->itemID >= 0)
  159. {
  160. CDC dcCombo;
  161. CBrush brColor;
  162. CPalette* pPalOld = NULL;
  163. CRect rect = lpDrawItemStruct->rcItem;
  164. dcCombo.Attach( lpDrawItemStruct->hDC );
  165. if (theApp.m_pPalette)
  166. {
  167. pPalOld = dcCombo.SelectPalette( theApp.m_pPalette, FALSE );
  168. dcCombo.RealizePalette();
  169. }
  170. brColor.CreateSolidBrush( (COLORREF)lpDrawItemStruct->itemData );
  171. if ((lpDrawItemStruct->itemState & ODS_SELECTED) == ODS_SELECTED)
  172. {
  173. dcCombo.FillRect( &(lpDrawItemStruct->rcItem), &brColor );
  174. rect.InflateRect( -theApp.m_cxFrame, -theApp.m_cyFrame );
  175. }
  176. dcCombo.FillRect( &(lpDrawItemStruct->rcItem), &brColor );
  177. brColor.DeleteObject();
  178. if ((lpDrawItemStruct->itemState & ODS_FOCUS) == ODS_FOCUS)
  179. dcCombo.DrawFocusRect( &(lpDrawItemStruct->rcItem) );
  180. if (pPalOld != NULL)
  181. dcCombo.SelectPalette( pPalOld, FALSE );
  182. }
  183. CDialog::OnDrawItem( nIDCtl, lpDrawItemStruct );
  184. }
  185. /***************************************************************************/
  186. BOOL CColorTable::OnInitDialog()
  187. {
  188. CDialog::OnInitDialog();
  189. int iColorCnt = g_pColors->GetColorCount();
  190. CListBox* pList = (CListBox*)GetDlgItem( IDC_COLORLIST );
  191. for (int iLoop = 0; iLoop < iColorCnt; iLoop++)
  192. {
  193. pList->AddString( TEXT("") );
  194. pList->SetItemData( iLoop, g_pColors->GetColor( iLoop ) );
  195. }
  196. return TRUE; // return TRUE unless you set the focus to a control
  197. }
  198. /***************************************************************************/
  199. void CColorTable::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  200. {
  201. lpMeasureItemStruct->itemHeight = theApp.m_cyCaption;
  202. CDialog::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
  203. }
  204. /***************************************************************************/
  205. void CColorTable::OnDblclkColorlist()
  206. {
  207. }
  208. /***************************************************************************/
  209. void CColorTable::OnOK()
  210. {
  211. // m_iColor = ;
  212. CDialog::OnOK();
  213. }
  214. /***************************************************************************/