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.

1066 lines
33 KiB

  1. // imageatt.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "pbrush.h"
  5. #include "imageatt.h"
  6. #include "hlpcntxt.h"
  7. #include "pbrusdoc.h"
  8. #include "bmobject.h"
  9. #include "imgsuprt.h" // for InvalColorWnd()
  10. #include "image.h"
  11. #ifndef UNICODE
  12. #include <sys\stat.h>
  13. #endif
  14. #include <wchar.h>
  15. #include <tchar.h>
  16. #include <winnls.h>
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21. #include "memtrace.h"
  22. #define FIXED_FLOATPT_MULTDIV 1000
  23. #define DECIMAL_POSITIONS 2
  24. /************************* CImageAttr dialog *******************************/
  25. /*
  26. There are a few things to note about the way this object/dialog functions.
  27. It tries not to convert the currently displayed value unless it notices the
  28. user has modified it. In all other cases, it works with PIXELS, the value
  29. passed in. If the user modified the width or height, it does 1 conversion and
  30. then works with pixels.
  31. For the conversion to display the different unit values, it uses the saved
  32. pixel value.
  33. The reason for all of this is due to only n decimal place of accuracy in the
  34. display
  35. The member Vars m_lWidth and m_lHeight are in the current units (store in
  36. the member variable m_eUnitsCurrent).
  37. The member Vars m_lWidthPixels and m_lHeightPixels are always in Pixels and
  38. these are what are used to convert for the display when changing the units.
  39. */
  40. CImageAttr::CImageAttr(CWnd* pParent /*=NULL*/)
  41. : CDialog(CImageAttr::IDD, pParent)
  42. {
  43. //{{AFX_DATA_INIT(CImageAttr)
  44. m_cStringWidth = TEXT("");
  45. m_cStringHeight = TEXT("");
  46. //}}AFX_DATA_INIT
  47. m_eUnitsCurrent = (eUNITS)theApp.m_iCurrentUnits;
  48. bEditFieldModified = FALSE;
  49. m_bMonochrome = FALSE;
  50. m_ulHeightPixels = 0;
  51. m_ulWidthPixels = 0;
  52. m_ulHeight = 0;
  53. m_ulWidth = 0;
  54. m_cXPelsPerMeter = 0;
  55. m_cYPelsPerMeter = 0;
  56. }
  57. /***************************************************************************/
  58. void CImageAttr::DoDataExchange(CDataExchange* pDX)
  59. {
  60. // saving must be done before the generic dodataexchange below.
  61. if (! pDX->m_bSaveAndValidate) // saving to dialog
  62. {
  63. FixedFloatPtToString( m_cStringWidth, m_ulWidth );
  64. FixedFloatPtToString( m_cStringHeight, m_ulHeight );
  65. }
  66. CDialog::DoDataExchange( pDX );
  67. //{{AFX_DATA_MAP(CImageAttr)
  68. DDX_Text(pDX, IDC_WIDTH, m_cStringWidth);
  69. DDV_MaxChars(pDX, m_cStringWidth, 5);
  70. DDX_Text(pDX, IDC_HEIGHT, m_cStringHeight);
  71. DDV_MaxChars(pDX, m_cStringHeight, 5);
  72. //}}AFX_DATA_MAP
  73. if (pDX->m_bSaveAndValidate) // retrieving from dialog
  74. {
  75. m_ulWidth = StringToFixedFloatPt( m_cStringWidth );
  76. m_ulHeight = StringToFixedFloatPt( m_cStringHeight );
  77. }
  78. }
  79. /***************************************************************************/
  80. ULONG CImageAttr::StringToFixedFloatPt( CString& sString )
  81. {
  82. ULONG iInteger = 0;
  83. ULONG iDecimal = 0;
  84. TCHAR chDecimal[2] = TEXT("."); // default to period in case GetLocaleInfo
  85. // messes up somehow
  86. GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, chDecimal, 2);
  87. if (! sString.IsEmpty())
  88. {
  89. int iPos = sString.Find( chDecimal[0] );
  90. LPTSTR szTmp = sString.GetBuffer( 1 );
  91. iInteger = FIXED_FLOATPT_MULTDIV * Atoi( szTmp );
  92. if (iPos++ >= 0)
  93. {
  94. LPTSTR szDecimal = szTmp + iPos;
  95. if (lstrlen( szDecimal ) > DECIMAL_POSITIONS)
  96. szDecimal[DECIMAL_POSITIONS] = 0;
  97. iDecimal = Atoi( szDecimal ) * 10;
  98. for (int i = lstrlen( szDecimal ); i < DECIMAL_POSITIONS; ++i)
  99. iDecimal *= 10;
  100. }
  101. }
  102. return ( iInteger + iDecimal );
  103. }
  104. /***************************************************************************/
  105. void CImageAttr::FixedFloatPtToString( CString& sString, ULONG ulFixedFloatPt )
  106. {
  107. ULONG iInteger = (ulFixedFloatPt + 5) / FIXED_FLOATPT_MULTDIV;
  108. ULONG iDecimal = ((ulFixedFloatPt + 5) % FIXED_FLOATPT_MULTDIV) / 10;
  109. TCHAR chDecimal[2] = TEXT("."); // default to period in case GetLocaleInfo
  110. // messes up somehow
  111. GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, chDecimal, 2);
  112. LPTSTR psz = sString.GetBufferSetLength( 24 );
  113. if (iDecimal)
  114. wsprintf( psz, TEXT("%u%s%02u"), iInteger, chDecimal,iDecimal );
  115. else
  116. wsprintf( psz, TEXT("%u"), iInteger );
  117. sString.ReleaseBuffer();
  118. }
  119. /***************************************************************************/
  120. BEGIN_MESSAGE_MAP(CImageAttr, CDialog)
  121. ON_MESSAGE(WM_HELP, OnHelp)
  122. ON_MESSAGE(WM_CONTEXTMENU, OnContextMenu)
  123. //{{AFX_MSG_MAP(CImageAttr)
  124. ON_BN_CLICKED(IDC_INCHES, OnInches)
  125. ON_BN_CLICKED(IDC_CENTIMETERS, OnCentimeters)
  126. ON_BN_CLICKED(IDC_PIXELS, OnPixels)
  127. ON_EN_CHANGE(IDC_HEIGHT, OnChangeHeight)
  128. ON_EN_CHANGE(IDC_WIDTH, OnChangeWidth)
  129. ON_BN_CLICKED(IDC_DEFAULT, OnDefault)
  130. ON_BN_CLICKED(IDC_USE_TRANS, OnUseTrans)
  131. ON_BN_CLICKED(IDC_SELECT_COLOR, OnSelectColor)
  132. ON_WM_PAINT()
  133. //}}AFX_MSG_MAP
  134. END_MESSAGE_MAP()
  135. /************************ CImageAttr message handlers **********************/
  136. static DWORD ImageAttrHelpIds[] =
  137. {
  138. IDC_WIDTH_STATIC, IDH_PAINT_IMAGE_ATTR_WIDTH,
  139. IDC_WIDTH, IDH_PAINT_IMAGE_ATTR_WIDTH,
  140. IDC_HEIGHT_STATIC, IDH_PAINT_IMAGE_ATTR_HEIGHT,
  141. IDC_HEIGHT, IDH_PAINT_IMAGE_ATTR_HEIGHT,
  142. IDC_UNITS_GROUP, IDH_COMM_GROUPBOX,
  143. IDC_INCHES, IDH_PAINT_IMAGE_ATTR_UNITS_INCHES,
  144. IDC_CENTIMETERS, IDH_PAINT_IMAGE_ATTR_UNITS_CM,
  145. IDC_PIXELS, IDH_PAINT_IMAGE_ATTR_UNITS_PELS,
  146. IDC_COLORS_GROUP, IDH_COMM_GROUPBOX,
  147. IDC_MONOCHROME, IDH_PAINT_IMAGE_ATTR_COLORS_BW,
  148. IDC_COLORS, IDH_PAINT_IMAGE_ATTR_COLORS_COLORS,
  149. IDC_DEFAULT, IDH_PAINT_IMAGE_ATTR_DEFAULT,
  150. IDC_FILEDATE_STATIC, IDH_PAINT_IMAGE_ATTR_LASTSAVED,
  151. IDC_FILESIZE_STATIC, IDH_PAINT_IMAGE_ATTR_SIZE,
  152. IDC_USE_TRANS, IDH_PAINT_IMAGE_ATTR_USE_TRANSP,
  153. IDC_SELECT_COLOR, IDH_PAINT_IMAGE_ATTR_SEL_COLOR,
  154. IDC_TRANS_PAINT, IDH_PAINT_IMAGE_ATTR_PREVIEW,
  155. 0, 0
  156. };
  157. /***************************************************************************/
  158. LONG
  159. CImageAttr::OnHelp(WPARAM wParam, LPARAM lParam)
  160. {
  161. LONG lResult = 0;
  162. ::WinHelp((HWND)(((LPHELPINFO)lParam)->hItemHandle), TEXT("mspaint.hlp"),
  163. HELP_WM_HELP, (ULONG_PTR)(LPTSTR)ImageAttrHelpIds);
  164. return lResult;
  165. }
  166. /***************************************************************************/
  167. LONG
  168. CImageAttr::OnContextMenu(WPARAM wParam, LPARAM lParam)
  169. {
  170. LONG lResult = 0;
  171. ::WinHelp((HWND)wParam, TEXT("mspaint.hlp"),
  172. HELP_CONTEXTMENU,(ULONG_PTR)(LPVOID)ImageAttrHelpIds);
  173. return lResult;
  174. }
  175. /***************************************************************************/
  176. void CImageAttr::PaintTransBox( COLORREF cr )
  177. {
  178. CWnd * pWnd = GetDlgItem(IDC_TRANS_PAINT);
  179. CDC * pDC = pWnd->GetDC();
  180. RECT rect;
  181. pWnd->GetClientRect( &rect );
  182. CBrush newBrush( m_crTrans & 0xFFFFFF); // disregard palette-relative
  183. pDC->FillRect (&rect, &newBrush);
  184. // CBrush * pOldBrush = pDC->SelectObject( &newBrush );
  185. // pDC->Rectangle( &rect );
  186. // DeleteObject( pDC->SelectObject( pOldBrush ) );
  187. pWnd->ReleaseDC( pDC );
  188. }
  189. /***************************************************************************/
  190. #define MAX_SEP_LEN 6
  191. #define MAX_INT_LEN 16
  192. // convert a number into a string with commas in the right place
  193. CString CImageAttr::ReformatSizeString(DWORD dwNumber)
  194. {
  195. NUMBERFMT nmf;
  196. CString strRet;
  197. TCHAR szSep[MAX_SEP_LEN];
  198. TCHAR szDec[MAX_SEP_LEN];
  199. CString sNumber;
  200. TCHAR szInt[MAX_INT_LEN];
  201. ZeroMemory (&nmf, sizeof(nmf));
  202. //
  203. // Fill in the NUMBERFMT with defaults for the user locale,
  204. // except for "fractional digits" being 0
  205. //
  206. GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ILZERO,
  207. szInt, MAX_INT_LEN);
  208. nmf.LeadingZero = _ttol (szInt);
  209. nmf.Grouping = 3;
  210. nmf.lpDecimalSep = (LPTSTR)szDec;
  211. nmf.lpThousandSep = (LPTSTR)szSep;
  212. GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, nmf.lpDecimalSep,
  213. MAX_SEP_LEN);
  214. GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, nmf.lpThousandSep,
  215. MAX_SEP_LEN);
  216. GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_INEGNUMBER,
  217. szInt,MAX_INT_LEN);
  218. nmf.NegativeOrder = _ttol (szInt);
  219. _ltot(dwNumber, sNumber.GetBuffer(20), 10);
  220. sNumber.ReleaseBuffer();
  221. int nChar = GetNumberFormat (LOCALE_USER_DEFAULT, 0, sNumber,
  222. &nmf, (LPTSTR)NULL, 0);
  223. if (nChar)
  224. {
  225. GetNumberFormat (LOCALE_USER_DEFAULT, 0, sNumber,
  226. &nmf, strRet.GetBuffer(nChar), nChar);
  227. strRet.ReleaseBuffer();
  228. return strRet;
  229. }
  230. return CString(TEXT("0"));
  231. }
  232. /***************************************************************************/
  233. void CImageAttr::UpdateResolutionString()
  234. {
  235. CString cstrResolution;
  236. if (m_cXPelsPerMeter == 0 || m_cYPelsPerMeter == 0)
  237. {
  238. VERIFY(cstrResolution.LoadString(IDS_RESOLUTION_NA));
  239. }
  240. else
  241. {
  242. CString cstrResolutionFormat;
  243. VERIFY(cstrResolutionFormat.LoadString(IDS_RESOLUTION));
  244. cstrResolution.Format(cstrResolutionFormat,
  245. MulDiv(m_cXPelsPerMeter, 254, 10000),
  246. MulDiv(m_cYPelsPerMeter, 254, 10000));
  247. }
  248. CWnd *pResolution = GetDlgItem(IDC_RESOLUTION_STATIC);
  249. pResolution->SetWindowText(cstrResolution);
  250. }
  251. /***************************************************************************/
  252. BOOL CImageAttr::OnInitDialog()
  253. {
  254. CDialog::OnInitDialog();
  255. CWnd * pFileDate = GetDlgItem(IDC_FILEDATE_STATIC);
  256. CWnd * pFileSize = GetDlgItem(IDC_FILESIZE_STATIC);
  257. CString cstrFileDate;
  258. CString cstrFileSize;
  259. if (((CPBApp *)AfxGetApp())->m_sCurFile.IsEmpty())
  260. {
  261. VERIFY(cstrFileDate.LoadString(IDS_FILEDATE_NA));
  262. VERIFY(cstrFileSize.LoadString(IDS_FILESIZE_NA));
  263. pFileDate->SetWindowText(cstrFileDate);
  264. pFileSize->SetWindowText(cstrFileSize);
  265. }
  266. else
  267. {
  268. DWORD dwSize = 0L;
  269. CString fn = ((CPBApp *)AfxGetApp())->m_sCurFile;
  270. HANDLE hFile;
  271. CString date;
  272. CString time;
  273. SYSTEMTIME sysTime;
  274. FILETIME ftSaved;
  275. FILETIME ftLocal;
  276. int dSize;
  277. //
  278. // Open a handle to the file, use GetFileTime to
  279. // get the FILETIME, convert to a SYSTEMTIME and
  280. // call GetDateFormat and GetTimeFormat
  281. //
  282. hFile = ::CreateFile (fn,GENERIC_READ,
  283. FILE_SHARE_READ | FILE_SHARE_WRITE,
  284. NULL,OPEN_EXISTING,
  285. 0,NULL);
  286. if (INVALID_HANDLE_VALUE != hFile)
  287. {
  288. // If your bitmap is bigger than 2GB, too bad.
  289. dwSize = ::GetFileSize (hFile, NULL);
  290. ::GetFileTime (hFile, NULL, NULL, &ftSaved);
  291. ::FileTimeToLocalFileTime (&ftSaved, &ftLocal);
  292. ::FileTimeToSystemTime (&ftLocal, &sysTime);
  293. dSize = ::GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, &sysTime, NULL,
  294. NULL, 0);
  295. ::GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, &sysTime, NULL,
  296. date.GetBuffer (dSize), dSize);
  297. dSize = ::GetTimeFormat (LOCALE_USER_DEFAULT, TIME_NOSECONDS, &sysTime, NULL,
  298. NULL, 0);
  299. ::GetTimeFormat (LOCALE_USER_DEFAULT, TIME_NOSECONDS, &sysTime, NULL,
  300. time.GetBuffer (dSize), dSize);
  301. date.ReleaseBuffer();
  302. time.ReleaseBuffer();
  303. VERIFY(cstrFileDate.LoadString(IDS_FILEDATE));
  304. VERIFY(cstrFileSize.LoadString(IDS_FILESIZE));
  305. TCHAR szFileDate[96];
  306. TCHAR szFileSize[64];
  307. // Display the date, followed by the time
  308. date+=TEXT(" ");
  309. date+=time;
  310. ::wsprintf( szFileDate, cstrFileDate, date );
  311. ::wsprintf( szFileSize, cstrFileSize, ReformatSizeString(dwSize) );
  312. ::CloseHandle (hFile);
  313. pFileDate->SetWindowText(szFileDate);
  314. pFileSize->SetWindowText(szFileSize);
  315. }
  316. else
  317. {
  318. VERIFY(cstrFileDate.LoadString(IDS_FILEDATE_NA));
  319. VERIFY(cstrFileSize.LoadString(IDS_FILESIZE_NA));
  320. pFileDate->SetWindowText(cstrFileDate);
  321. pFileSize->SetWindowText(cstrFileSize);
  322. }
  323. }
  324. UpdateResolutionString();
  325. int idButton = IDC_PIXELS;
  326. if (m_eUnitsCurrent != ePIXELS)
  327. idButton = (m_eUnitsCurrent == eINCHES)? IDC_INCHES: IDC_CENTIMETERS;
  328. CheckRadioButton( IDC_INCHES, IDC_PIXELS, idButton );
  329. CheckRadioButton( IDC_MONOCHROME, IDC_COLORS,
  330. (m_bMonochrome? IDC_MONOCHROME: IDC_COLORS) );
  331. //
  332. // We enable the transparent color UI only if modifying a GIF
  333. //
  334. GetDlgItem (IDC_USE_TRANS )->EnableWindow (WiaImgFmt_GIF == theApp.m_guidFltTypeUsed );
  335. CheckDlgButton( IDC_USE_TRANS, g_bUseTrans);
  336. CWnd* pSelectColorButton = GetDlgItem(IDC_SELECT_COLOR);
  337. pSelectColorButton->EnableWindow(g_bUseTrans);
  338. m_crTrans = crTrans;
  339. return TRUE; // return TRUE unless you set the focus to a control
  340. }
  341. /***************************************************************************/
  342. void CImageAttr::OnOK()
  343. {
  344. ConvertWidthHeight();
  345. theApp.m_iCurrentUnits = m_eUnitsCurrent;
  346. m_bMonochrome = (GetCheckedRadioButton( IDC_MONOCHROME, IDC_COLORS )
  347. == IDC_MONOCHROME);
  348. if (g_bUseTrans = IsDlgButtonChecked( IDC_USE_TRANS ))
  349. {
  350. crTrans = m_crTrans;
  351. }
  352. InvalColorWnd();
  353. CDialog::OnOK();
  354. }
  355. /***************************************************************************/
  356. void CImageAttr::OnDefault()
  357. {
  358. int nWidth, nHeight;
  359. PBGetDefDims(nWidth, nHeight);
  360. SetWidthHeight( nWidth, nHeight, 0, 0 );
  361. }
  362. /***************************************************************************/
  363. void CImageAttr::SetWidthHeight(ULONG nWidthPixels, ULONG nHeightPixels, ULONG cXPelsPerMeter, ULONG cYPelsPerMeter)
  364. {
  365. m_ulWidthPixels = nWidthPixels * FIXED_FLOATPT_MULTDIV;
  366. m_ulHeightPixels = nHeightPixels * FIXED_FLOATPT_MULTDIV;
  367. m_cXPelsPerMeter = cXPelsPerMeter;
  368. m_cYPelsPerMeter = cYPelsPerMeter;
  369. if (m_cXPelsPerMeter == 0)
  370. {
  371. m_cXPelsPerMeter = theApp.ScreenDeviceInfo.ixPelsPerDM * 10;
  372. }
  373. if (m_cYPelsPerMeter == 0)
  374. {
  375. m_cYPelsPerMeter = theApp.ScreenDeviceInfo.iyPelsPerDM * 10;
  376. }
  377. PelsToCurrentUnit();
  378. // only call updatedata if dialog exists...
  379. if (m_hWnd && ::IsWindow( m_hWnd ))
  380. {
  381. UpdateData( FALSE );
  382. UpdateResolutionString();
  383. }
  384. }
  385. /***************************************************************************/
  386. void CImageAttr::ConvertWidthHeight(void)
  387. {
  388. // if user modified the edit field Width/Height then get new data and
  389. // convert to pixel format. Else use stored pixel format.
  390. if (bEditFieldModified)
  391. {
  392. UpdateData( TRUE );
  393. switch (m_eUnitsCurrent)
  394. {
  395. case eINCHES:
  396. m_ulWidthPixels = MulDiv(m_ulWidth, m_cXPelsPerMeter * 254, 10000);
  397. m_ulHeightPixels = MulDiv(m_ulHeight, m_cYPelsPerMeter * 254, 10000);
  398. break;
  399. case eCM:
  400. m_ulWidthPixels = MulDiv(m_ulWidth, m_cXPelsPerMeter, 100);
  401. m_ulHeightPixels = MulDiv(m_ulHeight, m_cYPelsPerMeter, 100);
  402. break;
  403. case ePIXELS:
  404. default: // ePIXELS and all other assumed to be pixel
  405. m_ulWidthPixels = m_ulWidth;
  406. m_ulHeightPixels = m_ulHeight;
  407. break;
  408. }
  409. bEditFieldModified = FALSE;
  410. }
  411. }
  412. /***************************************************************************/
  413. void CImageAttr::PelsToCurrentUnit()
  414. {
  415. switch (m_eUnitsCurrent)
  416. {
  417. case eINCHES:
  418. m_ulWidth = MulDiv(m_ulWidthPixels, 10000, m_cXPelsPerMeter * 254);
  419. m_ulHeight = MulDiv(m_ulHeightPixels, 10000, m_cYPelsPerMeter * 254);
  420. break;
  421. case eCM:
  422. m_ulWidth = MulDiv(m_ulWidthPixels, 100, m_cXPelsPerMeter);
  423. m_ulHeight = MulDiv(m_ulHeightPixels, 100, m_cYPelsPerMeter);
  424. break;
  425. case ePIXELS:
  426. default:
  427. //Pixels cannot be partial
  428. //make sure whole number when converted to string (truncate! now).
  429. m_ulWidth = (m_ulWidthPixels / FIXED_FLOATPT_MULTDIV) * FIXED_FLOATPT_MULTDIV;
  430. m_ulHeight = (m_ulHeightPixels / FIXED_FLOATPT_MULTDIV) * FIXED_FLOATPT_MULTDIV;
  431. break;
  432. }
  433. }
  434. /***************************************************************************/
  435. CSize CImageAttr::GetWidthHeight(void)
  436. {
  437. return CSize( (int)(( m_ulWidthPixels + (FIXED_FLOATPT_MULTDIV / 2)) / FIXED_FLOATPT_MULTDIV),
  438. (int)((m_ulHeightPixels + (FIXED_FLOATPT_MULTDIV / 2)) / FIXED_FLOATPT_MULTDIV));
  439. }
  440. /***************************************************************************/
  441. void CImageAttr::OnInches()
  442. {
  443. SetNewUnits( eINCHES );
  444. }
  445. /***************************************************************************/
  446. void CImageAttr::OnCentimeters()
  447. {
  448. SetNewUnits( eCM );
  449. }
  450. /***************************************************************************/
  451. void CImageAttr::OnPixels()
  452. {
  453. SetNewUnits( ePIXELS );
  454. }
  455. /***************************************************************************/
  456. void CImageAttr::SetNewUnits( eUNITS NewUnit )
  457. {
  458. if (NewUnit == m_eUnitsCurrent)
  459. return;
  460. // must call getwidthheight before setting to new mode
  461. ConvertWidthHeight(); // get in a common form of pixels.
  462. m_eUnitsCurrent = NewUnit;
  463. PelsToCurrentUnit();
  464. UpdateData( FALSE );
  465. }
  466. /***************************************************************************/
  467. void CImageAttr::OnChangeHeight()
  468. {
  469. bEditFieldModified = TRUE;
  470. }
  471. /***************************************************************************/
  472. void CImageAttr::OnChangeWidth()
  473. {
  474. bEditFieldModified = TRUE;
  475. }
  476. /************************ CZoomViewDlg dialog ******************************/
  477. CZoomViewDlg::CZoomViewDlg(CWnd* pParent /*=NULL*/)
  478. : CDialog(CZoomViewDlg::IDD, pParent)
  479. {
  480. //{{AFX_DATA_INIT(CZoomViewDlg)
  481. //}}AFX_DATA_INIT
  482. m_nCurrent = 0;
  483. }
  484. /***************************************************************************/
  485. void CZoomViewDlg::DoDataExchange(CDataExchange* pDX)
  486. {
  487. CDialog::DoDataExchange(pDX);
  488. //{{AFX_DATA_MAP(CZoomViewDlg)
  489. //}}AFX_DATA_MAP
  490. }
  491. /***************************************************************************/
  492. BEGIN_MESSAGE_MAP(CZoomViewDlg, CDialog)
  493. ON_MESSAGE(WM_HELP, OnHelp)
  494. ON_MESSAGE(WM_CONTEXTMENU, OnContextMenu)
  495. //{{AFX_MSG_MAP(CZoomViewDlg)
  496. //}}AFX_MSG_MAP
  497. END_MESSAGE_MAP()
  498. /************************ CZoomViewDlg message handlers **********************/
  499. static DWORD ZoomViewHelpIds[] =
  500. {
  501. IDC_CURRENT_ZOOM_STATIC, IDH_PAINT_ZOOM_CURRENT,
  502. IDC_CURRENT_ZOOM, IDH_PAINT_ZOOM_CURRENT,
  503. IDC_ZOOM_GROUP, IDH_PAINT_ZOOM_SET_GROUP,
  504. IDC_ZOOM_100, IDH_PAINT_ZOOM_SET_GROUP,
  505. IDC_ZOOM_200, IDH_PAINT_ZOOM_SET_GROUP,
  506. IDC_ZOOM_400, IDH_PAINT_ZOOM_SET_GROUP,
  507. IDC_ZOOM_600, IDH_PAINT_ZOOM_SET_GROUP,
  508. IDC_ZOOM_800, IDH_PAINT_ZOOM_SET_GROUP,
  509. 0, 0
  510. };
  511. /***************************************************************************/
  512. LONG
  513. CZoomViewDlg::OnHelp(WPARAM wParam, LPARAM lParam)
  514. {
  515. LONG lResult = 0;
  516. ::WinHelp((HWND)(((LPHELPINFO)lParam)->hItemHandle), TEXT("mspaint.hlp"),
  517. HELP_WM_HELP, (ULONG_PTR)(LPTSTR)ZoomViewHelpIds);
  518. return lResult;
  519. }
  520. /***************************************************************************/
  521. LONG
  522. CZoomViewDlg::OnContextMenu(WPARAM wParam, LPARAM lParam)
  523. {
  524. LONG lResult = 0;
  525. ::WinHelp((HWND)wParam, TEXT("mspaint.hlp"),
  526. HELP_CONTEXTMENU,(ULONG_PTR)(LPVOID)ZoomViewHelpIds);
  527. return lResult;
  528. }
  529. /***************************************************************************/
  530. BOOL CZoomViewDlg::OnInitDialog()
  531. {
  532. CDialog::OnInitDialog();
  533. TCHAR* pZoom = TEXT("100%");
  534. UINT nButton = IDC_ZOOM_100;
  535. if (m_nCurrent < 8)
  536. if (m_nCurrent < 6)
  537. if (m_nCurrent < 4)
  538. if (m_nCurrent < 2)
  539. ;
  540. else
  541. {
  542. pZoom = TEXT("200%");
  543. nButton = IDC_ZOOM_200;
  544. }
  545. else
  546. {
  547. pZoom = TEXT("400%");
  548. nButton = IDC_ZOOM_400;
  549. }
  550. else
  551. {
  552. pZoom = TEXT("600%");
  553. nButton = IDC_ZOOM_600;
  554. }
  555. else
  556. {
  557. pZoom = TEXT("800%");
  558. nButton = IDC_ZOOM_800;
  559. }
  560. SetDlgItemText( IDC_CURRENT_ZOOM, pZoom );
  561. CheckRadioButton( IDC_ZOOM_100, IDC_ZOOM_800, nButton );
  562. return TRUE; // return TRUE unless you set the focus to a control
  563. }
  564. /***************************************************************************/
  565. void CZoomViewDlg::OnOK()
  566. {
  567. m_nCurrent = GetCheckedRadioButton( IDC_ZOOM_100, IDC_ZOOM_800 ) - IDC_ZOOM_100;
  568. if (m_nCurrent < 1)
  569. m_nCurrent = 1;
  570. else
  571. m_nCurrent *= 2;
  572. CDialog::OnOK();
  573. }
  574. /************************ CFlipRotateDlg dialog ****************************/
  575. CFlipRotateDlg::CFlipRotateDlg(CWnd* pParent /*=NULL*/)
  576. : CDialog(CFlipRotateDlg::IDD, pParent)
  577. {
  578. //{{AFX_DATA_INIT(CFlipRotateDlg)
  579. // NOTE: the ClassWizard will add member initialization here
  580. //}}AFX_DATA_INIT
  581. m_bHorz = TRUE;
  582. m_bAngle = FALSE;
  583. m_nAngle = 90;
  584. }
  585. /***************************************************************************/
  586. void CFlipRotateDlg::DoDataExchange(CDataExchange* pDX)
  587. {
  588. CDialog::DoDataExchange(pDX);
  589. //{{AFX_DATA_MAP(CFlipRotateDlg)
  590. // NOTE: the ClassWizard will add DDX and DDV calls here
  591. //}}AFX_DATA_MAP
  592. }
  593. /***************************************************************************/
  594. BEGIN_MESSAGE_MAP(CFlipRotateDlg, CDialog)
  595. ON_MESSAGE(WM_HELP, OnHelp)
  596. ON_MESSAGE(WM_CONTEXTMENU, OnContextMenu)
  597. //{{AFX_MSG_MAP(CFlipRotateDlg)
  598. ON_BN_CLICKED(IDC_BY_ANGLE, OnByAngle)
  599. ON_BN_CLICKED(IDC_HORIZONTAL, OnNotByAngle)
  600. ON_BN_CLICKED(IDC_VERTICAL, OnNotByAngle)
  601. //}}AFX_MSG_MAP
  602. END_MESSAGE_MAP()
  603. /************************ CFlipRotateDlg message handlers **********************/
  604. static DWORD FlipRotateHelpIds[] =
  605. {
  606. IDC_PAINT_FLIP_GROUP, IDH_COMM_GROUPBOX,
  607. IDC_HORIZONTAL, IDH_PAINT_IMAGE_FLIP_HORIZ,
  608. IDC_VERTICAL, IDH_PAINT_IMAGE_FLIP_VERT,
  609. IDC_BY_ANGLE, IDH_PAINT_IMAGE_FLIP_ROTATE,
  610. IDC_90_DEG, IDH_PAINT_IMAGE_FLIP_ROTATE,
  611. IDC_180_DEG, IDH_PAINT_IMAGE_FLIP_ROTATE,
  612. IDC_270_DEG, IDH_PAINT_IMAGE_FLIP_ROTATE,
  613. 0, 0
  614. };
  615. /***************************************************************************/
  616. LONG
  617. CFlipRotateDlg::OnHelp(WPARAM wParam, LPARAM lParam)
  618. {
  619. LONG lResult = 0;
  620. ::WinHelp((HWND)(((LPHELPINFO)lParam)->hItemHandle), TEXT("mspaint.hlp"),
  621. HELP_WM_HELP, (ULONG_PTR)(LPTSTR)FlipRotateHelpIds);
  622. return lResult;
  623. }
  624. /***************************************************************************/
  625. LONG
  626. CFlipRotateDlg::OnContextMenu(WPARAM wParam, LPARAM lParam)
  627. {
  628. LONG lResult = 0;
  629. ::WinHelp((HWND)wParam, TEXT("mspaint.hlp"),
  630. HELP_CONTEXTMENU,(ULONG_PTR)(LPVOID)FlipRotateHelpIds);
  631. return lResult;
  632. }
  633. /***************************************************************************/
  634. BOOL CFlipRotateDlg::OnInitDialog()
  635. {
  636. CDialog::OnInitDialog();
  637. CheckRadioButton( IDC_90_DEG, IDC_270_DEG, IDC_90_DEG );
  638. UINT uButton = (m_bAngle? IDC_BY_ANGLE: (m_bHorz? IDC_HORIZONTAL: IDC_VERTICAL));
  639. CheckRadioButton( IDC_HORIZONTAL, IDC_BY_ANGLE, uButton );
  640. if (uButton != IDC_BY_ANGLE)
  641. OnNotByAngle();
  642. return TRUE; // return TRUE unless you set the focus to a control
  643. }
  644. /***************************************************************************/
  645. void CFlipRotateDlg::OnByAngle()
  646. {
  647. GetDlgItem( IDC_90_DEG )->EnableWindow( TRUE );
  648. GetDlgItem( IDC_180_DEG )->EnableWindow( TRUE );
  649. GetDlgItem( IDC_270_DEG )->EnableWindow( TRUE );
  650. }
  651. /***************************************************************************/
  652. void CFlipRotateDlg::OnNotByAngle()
  653. {
  654. GetDlgItem( IDC_90_DEG )->EnableWindow( FALSE );
  655. GetDlgItem( IDC_180_DEG )->EnableWindow( FALSE );
  656. GetDlgItem( IDC_270_DEG )->EnableWindow( FALSE );
  657. }
  658. /***************************************************************************/
  659. void CFlipRotateDlg::OnOK()
  660. {
  661. UINT uButton = GetCheckedRadioButton( IDC_HORIZONTAL, IDC_BY_ANGLE );
  662. m_bHorz = (uButton == IDC_HORIZONTAL);
  663. m_bAngle = (uButton == IDC_BY_ANGLE);
  664. switch (GetCheckedRadioButton( IDC_90_DEG, IDC_270_DEG ))
  665. {
  666. case IDC_90_DEG:
  667. m_nAngle = 90;
  668. break;
  669. case IDC_180_DEG:
  670. m_nAngle = 180;
  671. break;
  672. case IDC_270_DEG:
  673. m_nAngle = 270;
  674. break;
  675. }
  676. CDialog::OnOK();
  677. }
  678. /************************* CStretchSkewDlg dialog **************************/
  679. CStretchSkewDlg::CStretchSkewDlg(CWnd* pParent /*=NULL*/)
  680. : CDialog(CStretchSkewDlg::IDD, pParent)
  681. {
  682. //{{AFX_DATA_INIT(CStretchSkewDlg)
  683. m_wSkewHorz = 0;
  684. m_wSkewVert = 0;
  685. m_iStretchVert = 100;
  686. m_iStretchHorz = 100;
  687. //}}AFX_DATA_INIT
  688. //m_bStretchHorz = TRUE;
  689. //m_bSkewHorz = TRUE;
  690. }
  691. /***************************************************************************/
  692. void CStretchSkewDlg::DoDataExchange(CDataExchange* pDX)
  693. {
  694. CDialog::DoDataExchange(pDX);
  695. //{{AFX_DATA_MAP(CStretchSkewDlg)
  696. DDX_Text(pDX, IDC_STRETCH_VERT_PERCENT, m_iStretchVert);
  697. DDV_MinMaxInt(pDX, m_iStretchVert, 1, 500);
  698. DDX_Text(pDX, IDC_STRETCH_HORZ_PERCENT, m_iStretchHorz);
  699. DDV_MinMaxInt(pDX, m_iStretchHorz, 1, 500);
  700. DDX_Text(pDX, IDC_SKEW_HORZ_DEGREES, m_wSkewHorz);
  701. DDV_MinMaxInt(pDX, m_wSkewHorz, -89, 89);
  702. DDX_Text(pDX, IDC_SKEW_VERT_DEGREES, m_wSkewVert);
  703. DDV_MinMaxInt(pDX, m_wSkewVert, -89, 89);
  704. //}}AFX_DATA_MAP
  705. }
  706. /***************************************************************************/
  707. BEGIN_MESSAGE_MAP(CStretchSkewDlg, CDialog)
  708. ON_MESSAGE(WM_HELP, OnHelp)
  709. ON_MESSAGE(WM_CONTEXTMENU, OnContextMenu)
  710. //{{AFX_MSG_MAP(CStretchSkewDlg)
  711. /*
  712. ON_BN_CLICKED(IDC_SKEW_HORZ, OnSkewHorz)
  713. ON_BN_CLICKED(IDC_SKEW_VERT, OnSkewVert)
  714. ON_BN_CLICKED(IDC_STRETCH_HORZ, OnStretchHorz)
  715. ON_BN_CLICKED(IDC_STRETCH_VERT, OnStretchVert)
  716. */
  717. //}}AFX_MSG_MAP
  718. END_MESSAGE_MAP()
  719. /************************ CStretchSkewDlg message handlers **********************/
  720. static DWORD StretchSkewHelpIds[] =
  721. {
  722. IDC_STRETCH_GROUP, IDH_COMM_GROUPBOX,
  723. IDC_STRETCH_HORZ_ICON, IDH_PAINT_IMAGE_STRETCH_HORIZ,
  724. IDC_STRETCH_HORZ, IDH_PAINT_IMAGE_STRETCH_HORIZ,
  725. IDC_STRETCH_HORZ_PERCENT, IDH_PAINT_IMAGE_STRETCH_HORIZ,
  726. IDC_STRETCH_HORZ_SUFFIX, IDH_PAINT_IMAGE_STRETCH_HORIZ,
  727. IDC_STRETCH_VERT_ICON, IDH_PAINT_IMAGE_STRETCH_VERT,
  728. IDC_STRETCH_VERT, IDH_PAINT_IMAGE_STRETCH_VERT,
  729. IDC_STRETCH_VERT_PERCENT, IDH_PAINT_IMAGE_STRETCH_VERT,
  730. IDC_STRETCH_VERT_SUFFIX, IDH_PAINT_IMAGE_STRETCH_VERT,
  731. IDC_SKEW_GROUP, IDH_COMM_GROUPBOX,
  732. IDC_SKEW_HORZ_ICON, IDH_PAINT_IMAGE_SKEW_HOR,
  733. IDC_SKEW_HORZ, IDH_PAINT_IMAGE_SKEW_HOR,
  734. IDC_SKEW_HORZ_DEGREES, IDH_PAINT_IMAGE_SKEW_HOR,
  735. IDC_SKEW_HORZ_SUFFIX, IDH_PAINT_IMAGE_SKEW_HOR,
  736. IDC_SKEW_VERT_ICON, IDH_PAINT_IMAGE_SKEW_VERT,
  737. IDC_SKEW_VERT, IDH_PAINT_IMAGE_SKEW_VERT,
  738. IDC_SKEW_VERT_DEGREES, IDH_PAINT_IMAGE_SKEW_VERT,
  739. IDC_SKEW_VERT_SUFFIX, IDH_PAINT_IMAGE_SKEW_VERT,
  740. 0, 0
  741. };
  742. /***************************************************************************/
  743. LONG
  744. CStretchSkewDlg::OnHelp(WPARAM wParam, LPARAM lParam)
  745. {
  746. LONG lResult = 0;
  747. ::WinHelp((HWND)(((LPHELPINFO)lParam)->hItemHandle), TEXT("mspaint.hlp"),
  748. HELP_WM_HELP, (ULONG_PTR)(LPTSTR)StretchSkewHelpIds);
  749. return lResult;
  750. }
  751. /***************************************************************************/
  752. LONG
  753. CStretchSkewDlg::OnContextMenu(WPARAM wParam, LPARAM lParam)
  754. {
  755. LONG lResult = 0;
  756. ::WinHelp((HWND)wParam, TEXT("mspaint.hlp"),
  757. HELP_CONTEXTMENU,(ULONG_PTR)(LPVOID)StretchSkewHelpIds);
  758. return lResult;
  759. }
  760. /***************************************************************************/
  761. BOOL CStretchSkewDlg::OnInitDialog()
  762. {
  763. CDialog::OnInitDialog();
  764. CheckRadioButton( IDC_STRETCH_HORZ, IDC_STRETCH_VERT, IDC_STRETCH_HORZ );
  765. CheckRadioButton( IDC_SKEW_HORZ , IDC_SKEW_VERT , IDC_SKEW_HORZ );
  766. /* GetDlgItem( IDC_STRETCH_HORZ_PERCENT )->EnableWindow( m_iStretchHorz );
  767. GetDlgItem( IDC_STRETCH_VERT_PERCENT )->EnableWindow( ! m_iStretchHorz );
  768. GetDlgItem( IDC_SKEW_HORZ_DEGREES )->EnableWindow( m_bSkewHorz );
  769. GetDlgItem( IDC_SKEW_VERT_DEGREES )->EnableWindow( ! m_bSkewHorz );
  770. */
  771. return TRUE; // return TRUE unless you set the focus to a control
  772. }
  773. /***************************************************************************/
  774. void CStretchSkewDlg::OnStretchHorz()
  775. {
  776. m_bStretchHorz = TRUE;
  777. GetDlgItem( IDC_STRETCH_HORZ_PERCENT )->EnableWindow( TRUE );
  778. GetDlgItem( IDC_STRETCH_VERT_PERCENT )->EnableWindow( FALSE );
  779. CheckRadioButton( IDC_STRETCH_HORZ, IDC_STRETCH_VERT, IDC_STRETCH_HORZ );
  780. }
  781. /***************************************************************************/
  782. void CStretchSkewDlg::OnStretchVert()
  783. {
  784. m_bStretchHorz = FALSE;
  785. GetDlgItem( IDC_STRETCH_HORZ_PERCENT )->EnableWindow( FALSE );
  786. GetDlgItem( IDC_STRETCH_VERT_PERCENT )->EnableWindow( TRUE );
  787. CheckRadioButton( IDC_STRETCH_HORZ, IDC_STRETCH_VERT, IDC_STRETCH_VERT );
  788. }
  789. /***************************************************************************/
  790. void CStretchSkewDlg::OnSkewHorz()
  791. {
  792. m_bSkewHorz = TRUE;
  793. GetDlgItem( IDC_SKEW_HORZ_DEGREES )->EnableWindow( TRUE );
  794. GetDlgItem( IDC_SKEW_VERT_DEGREES )->EnableWindow( FALSE );
  795. CheckRadioButton( IDC_SKEW_HORZ, IDC_SKEW_VERT, IDC_SKEW_HORZ );
  796. }
  797. /***************************************************************************/
  798. void CStretchSkewDlg::OnSkewVert()
  799. {
  800. m_bSkewHorz = FALSE;
  801. GetDlgItem( IDC_SKEW_HORZ_DEGREES )->EnableWindow( FALSE );
  802. GetDlgItem( IDC_SKEW_VERT_DEGREES )->EnableWindow( TRUE );
  803. CheckRadioButton( IDC_SKEW_HORZ, IDC_SKEW_VERT, IDC_SKEW_VERT );
  804. }
  805. /***************************************************************************/
  806. void CStretchSkewDlg::OnOK()
  807. {
  808. if (GetCheckedRadioButton( IDC_STRETCH_HORZ, IDC_STRETCH_VERT )
  809. == IDC_STRETCH_HORZ)
  810. m_iStretchVert = 0;
  811. else
  812. m_iStretchHorz = 0;
  813. if (GetCheckedRadioButton( IDC_SKEW_HORZ, IDC_SKEW_VERT )
  814. == IDC_SKEW_HORZ)
  815. m_wSkewVert = 0;
  816. else
  817. m_wSkewHorz = 0;
  818. CDialog::OnOK();
  819. }
  820. /***************************************************************************/
  821. void CImageAttr::OnUseTrans()
  822. {
  823. CWnd* pSelectColorButton = GetDlgItem(IDC_SELECT_COLOR);
  824. pSelectColorButton->EnableWindow(IsDlgButtonChecked(IDC_USE_TRANS));
  825. }
  826. extern INT_PTR CALLBACK AfxDlgProc(HWND, UINT, WPARAM, LPARAM);
  827. static UINT_PTR CALLBACK /*LPCCHOOKPROC*/
  828. SelectColorHook(HWND hColorDlg, UINT nMessage, WPARAM wParam, LPARAM lParam)
  829. {
  830. // Are we initializing the dialog window?
  831. if ( nMessage == WM_INITDIALOG )
  832. {
  833. // Reset the common dialog title
  834. CString strDialogTitle;
  835. VERIFY(strDialogTitle.LoadString(IDS_SELECT_COLOR));
  836. SetWindowText( hColorDlg, strDialogTitle );
  837. }
  838. // Pass All Messages Along to Common Dialog
  839. return (UINT)AfxDlgProc(hColorDlg, nMessage, wParam, lParam );
  840. }
  841. void CImageAttr::OnSelectColor()
  842. {
  843. // for default color selection, disregard palette-relative
  844. CColorDialog dlg( m_crTrans & 0xFFFFFF, CC_FULLOPEN );
  845. dlg.m_cc.lpfnHook = SelectColorHook;
  846. if (dlg.DoModal() != IDOK)
  847. return;
  848. PaintTransBox( m_crTrans = dlg.GetColor() );
  849. }
  850. void CImageAttr::OnPaint()
  851. {
  852. CPaintDC dc(this); // device context for painting
  853. if (m_crTrans != TRANS_COLOR_NONE) // not default
  854. PaintTransBox( m_crTrans );
  855. }