ReportPictureProperties.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 15k
Category:

Graph program

Development Platform:

Visual C++

  1. /* ==========================================================================
  2. Class : CReportPictureProperties
  3. Author : Johan Rosengren, Abstrakt Mekanik AB
  4. Date : 2004-07-23
  5. Purpose : "CReportBoxProperties" is a "CDiagramPropertyDlg"-derived 
  6. class for setting properties to a "CReportEntityPicture" 
  7. object
  8. Description : This is a Wizard-created dialogbox class.
  9. Usage : See "CDiagramPropertyDlg".
  10.    ========================================================================*/
  11. #include "stdafx.h"
  12. #include "ReportPictureProperties.h"
  13. #include "ReportEntityPicture.h"
  14. #include "ReportEntitySettings.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. DocType doctypes[CMAX_IMAGE_FORMATS] =
  21. {
  22. { -1, TRUE, TRUE, "Supported files", "*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.ico;*.tif;*.tiff;*.tga;*.pcx;*.wbmp;*.wmf;*.emf;*.j2k;*.jp2;*.jbg;*.j2c;*.jpc;*.pgx;*.pnm;*.pgm;*.ppm;*.ras" },
  23. #if CXIMAGE_SUPPORT_BMP
  24. { CXIMAGE_FORMAT_BMP, TRUE, TRUE, "BMP files", "*.bmp" },
  25. #endif
  26. #if CXIMAGE_SUPPORT_GIF
  27. { CXIMAGE_FORMAT_GIF, TRUE, TRUE, "GIF files", "*.gif" },
  28. #endif
  29. #if CXIMAGE_SUPPORT_JPG
  30. { CXIMAGE_FORMAT_JPG, TRUE, TRUE, "JPG files", "*.jpg;*.jpeg" },
  31. #endif
  32. #if CXIMAGE_SUPPORT_PNG
  33. { CXIMAGE_FORMAT_PNG, TRUE, TRUE, "PNG files", "*.png" },
  34. #endif
  35. #if CXIMAGE_SUPPORT_MNG
  36. { CXIMAGE_FORMAT_MNG, TRUE, TRUE, "MNG files", "*.mng;*.jng;*.png" },
  37. #endif
  38. #if CXIMAGE_SUPPORT_ICO
  39. { CXIMAGE_FORMAT_ICO, TRUE, TRUE, "ICO CUR files", "*.ico;*.cur" },
  40. #endif
  41. #if CXIMAGE_SUPPORT_TIF
  42. { CXIMAGE_FORMAT_TIF, TRUE, TRUE, "TIF files", "*.tif;*.tiff" },
  43. #endif
  44. #if CXIMAGE_SUPPORT_TGA
  45. { CXIMAGE_FORMAT_TGA, TRUE, TRUE, "TGA files", "*.tga" },
  46. #endif
  47. #if CXIMAGE_SUPPORT_PCX
  48. { CXIMAGE_FORMAT_PCX, TRUE, TRUE, "PCX files", "*.pcx" },
  49. #endif
  50. #if CXIMAGE_SUPPORT_WBMP
  51. { CXIMAGE_FORMAT_WBMP, TRUE, TRUE, "WBMP files", "*.wbmp" },
  52. #endif
  53. #if CXIMAGE_SUPPORT_WMF
  54. { CXIMAGE_FORMAT_WMF, TRUE, FALSE, "WMF EMF files", "*.wmf;*.emf" },
  55. #endif
  56. #if CXIMAGE_SUPPORT_J2K
  57. { CXIMAGE_FORMAT_J2K, TRUE, TRUE, "J2K files", "*.j2k;*.jp2" },
  58. #endif
  59. #if CXIMAGE_SUPPORT_JBG
  60. { CXIMAGE_FORMAT_JBG, TRUE, TRUE, "JBG files", "*.jbg" },
  61. #endif
  62. #if CXIMAGE_SUPPORT_JP2
  63. { CXIMAGE_FORMAT_JP2, TRUE, TRUE, "JP2 files", "*.j2k;*.jp2" },
  64. #endif
  65. #if CXIMAGE_SUPPORT_JPC
  66. { CXIMAGE_FORMAT_JPC, TRUE, TRUE, "JPC files", "*.j2c;*.jpc" },
  67. #endif
  68. #if CXIMAGE_SUPPORT_PGX
  69. { CXIMAGE_FORMAT_PGX, TRUE, TRUE, "PGX files", "*.pgx" },
  70. #endif
  71. #if CXIMAGE_SUPPORT_RAS
  72. { CXIMAGE_FORMAT_RAS, TRUE, TRUE, "RAS files", "*.ras" },
  73. #endif
  74. #if CXIMAGE_SUPPORT_PNM
  75. { CXIMAGE_FORMAT_PNM, TRUE, TRUE, "PNM files", "*.pnm;*.pgm;*.ppm" }
  76. #endif
  77. };
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CReportPictureProperties dialog
  80. CReportPictureProperties::CReportPictureProperties(IThumbnailerStorage* pParent /*=NULL*/)
  81. : CDiagramPropertyDlg(CReportPictureProperties::IDD, pParent)
  82. /* ============================================================
  83. Function : CReportPictureProperties::CReportPictureProperties
  84. Description : Constructor
  85. Access : Public
  86. Return : void
  87. Parameters : CWnd* pParent - Parent window
  88. Usage :
  89.    ============================================================*/
  90. {
  91. //{{AFX_DATA_INIT(CReportPictureProperties)
  92. m_filename = _T("");
  93. m_borderThickness = 0;
  94. //}}AFX_DATA_INIT
  95. m_borderStyle = 0;
  96. m_otiFile = NULL;
  97. m_otiExistLeft = NULL;
  98. m_otiExistRight = NULL;
  99. m_otiExistTop = NULL;
  100. m_otiExistBottom= NULL;
  101. m_otiFrameColorCombo =NULL;
  102. m_otiFrameThicknessCombo = NULL;
  103. }
  104. void CReportPictureProperties::DoDataExchange(CDataExchange* pDX)
  105. /* ============================================================
  106. Function : CReportPictureProperties::DoDataExchange
  107. Description : MFC data exchange handler.
  108. Access : Protected
  109. Return : void
  110. Parameters : CDataExchange* pDX - Exchange object
  111. Usage : Called from MFC.
  112.    ============================================================*/
  113. {
  114. CDialog::DoDataExchange(pDX);
  115. //{{AFX_DATA_MAP(CReportPictureProperties)
  116. //}}AFX_DATA_MAP
  117. }
  118. BEGIN_MESSAGE_MAP(CReportPictureProperties, CDialog)
  119. //{{AFX_MSG_MAP(CReportPictureProperties)
  120. //}}AFX_MSG_MAP
  121. END_MESSAGE_MAP()
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CReportPictureProperties message handlers
  124. void CReportPictureProperties::OnOK() 
  125. /* ============================================================
  126. Function : CReportPictureProperties::OnOK
  127. Description : Handler for the dialog OK-button.
  128. Access : Protected
  129. Return : void
  130. Parameters : none
  131. Usage : Called from MFC.
  132.    ============================================================*/
  133. {
  134. CReportEntityPicture* pic = static_cast< CReportEntityPicture* >( GetEntity() );
  135. if (m_otiExistLeft->IsSelected())
  136. {
  137. m_otiExistLeft->CommitChanges();
  138. m_otiExistLeft->LostFocus();
  139. }
  140. if (m_otiExistRight->IsSelected())
  141. {
  142. m_otiExistRight->CommitChanges();
  143. m_otiExistRight->LostFocus();
  144. }
  145. if (m_otiExistTop->IsSelected())
  146. {
  147. m_otiExistTop->CommitChanges();
  148. m_otiExistTop->LostFocus();
  149. }
  150. if (m_otiExistBottom->IsSelected())
  151. {
  152. m_otiExistBottom->CommitChanges();
  153. m_otiExistBottom->LostFocus();
  154. }
  155. if (m_otiFrameColorCombo->IsSelected())
  156. {
  157. m_otiFrameColorCombo->CommitChanges();
  158. m_otiFrameColorCombo->LostFocus();
  159. }
  160. if (m_otiFrameThicknessCombo->IsSelected())
  161. {
  162. m_otiFrameThicknessCombo->CommitChanges();
  163. m_otiFrameThicknessCombo->LostFocus();
  164. }
  165. m_filename = m_otiFile->GetFileDir()+m_otiFile->GetFileName();
  166. pic->SetFilename( m_filename );
  167. //pic->AdjustSize();
  168. m_borderStyle = 0;
  169. if (m_otiExistLeft->GetCheck())
  170. m_borderStyle |= DIAGRAM_FRAME_STYLE_LEFT;
  171. if (m_otiExistRight->GetCheck())
  172. m_borderStyle |= DIAGRAM_FRAME_STYLE_RIGHT;
  173. if (m_otiExistTop->GetCheck())
  174. m_borderStyle |= DIAGRAM_FRAME_STYLE_TOP;
  175. if (m_otiExistBottom->GetCheck())
  176. m_borderStyle |= DIAGRAM_FRAME_STYLE_BOTTOM;
  177. m_borderColor = m_otiFrameColorCombo->GetCurColor();
  178. m_borderThickness = m_otiFrameThicknessCombo->GetLineThickness();
  179. pic->SetBorderColor( m_borderColor );
  180. pic->SetBorderThickness( m_borderThickness );
  181. pic->SetBorderStyle( m_borderStyle );
  182. CReportEntitySettings::GetRESInstance()->SetBorderColor( m_borderColor );
  183. CReportEntitySettings::GetRESInstance()->SetBorderThickness( m_borderThickness );
  184. CReportEntitySettings::GetRESInstance()->SetBorderStyle( m_borderStyle );
  185. ShowWindow( SW_HIDE );
  186. Redraw();
  187. }
  188. void CReportPictureProperties::OnCancel() 
  189. /* ============================================================
  190. Function : CReportPictureProperties::OnCancel
  191. Description : Handler for the dialog Cancel-button.
  192. Access : Protected
  193. Return : void
  194. Parameters : none
  195. Usage : Called from MFC.
  196.    ============================================================*/
  197. {
  198. if (m_otiExistLeft->IsSelected())
  199. {
  200. m_otiExistLeft->Select(FALSE);
  201. m_otiExistLeft->LostFocus();
  202. }
  203. if (m_otiExistRight->IsSelected())
  204. {
  205. m_otiExistRight->Select(FALSE);
  206. m_otiExistRight->LostFocus();
  207. }
  208. if (m_otiExistTop->IsSelected())
  209. {
  210. m_otiExistTop->Select(FALSE);
  211. m_otiExistTop->LostFocus();
  212. }
  213. if (m_otiExistBottom->IsSelected())
  214. {
  215. m_otiExistBottom->Select(FALSE);
  216. m_otiExistBottom->LostFocus();
  217. }
  218. if (m_otiFrameColorCombo->IsSelected())
  219. {
  220. m_otiFrameColorCombo->Select(FALSE);
  221. m_otiFrameColorCombo->LostFocus();
  222. }
  223. if (m_otiFrameThicknessCombo->IsSelected())
  224. {
  225. m_otiFrameThicknessCombo->Select(FALSE);
  226. m_otiFrameThicknessCombo->LostFocus();
  227. }
  228. ShowWindow( SW_HIDE );
  229. }
  230. static int GetIndexFromType(int nDocType, BOOL bOpenFileDialog)
  231. {
  232. int nCnt = 0;
  233. for (int i=0;i<CMAX_IMAGE_FORMATS;i++){
  234. if (bOpenFileDialog ? doctypes[i].bRead : doctypes[i].bWrite){
  235. if (doctypes[i].nID == nDocType) return nCnt;
  236. nCnt++;
  237. }
  238. }
  239. return -1;
  240. }
  241. static CString GetExtFromType(int nDocType)
  242. {
  243. for (int i=0;i<CMAX_IMAGE_FORMATS;i++){
  244. if (doctypes[i].nID == nDocType)
  245. return doctypes[i].ext;
  246. }
  247. return CString("");
  248. }
  249. static CString GetFileTypes(BOOL bOpenFileDialog)
  250. {
  251. CString str;
  252. for (int i=0;i<CMAX_IMAGE_FORMATS;i++){
  253. if (bOpenFileDialog && doctypes[i].bRead){
  254. str += doctypes[i].description;
  255. str += (TCHAR)'|';
  256. str += doctypes[i].ext;
  257. str += (TCHAR)'|';
  258. } else if (!bOpenFileDialog && doctypes[i].bWrite) {
  259. str += doctypes[i].description;
  260. str += (TCHAR)NULL;
  261. str += doctypes[i].ext;
  262. str += (TCHAR)NULL;
  263. }
  264. }
  265. return str;
  266. }
  267. void CReportPictureProperties::SetValues()
  268. /* ============================================================
  269. Function : CReportPictureProperties::SetValues
  270. Description : Sets the values of the property dialog
  271. Access : Public
  272. Return : void
  273. Parameters : none
  274. Usage : Call to set the property dialog values.
  275.    ============================================================*/
  276. {
  277. CReportEntityPicture* pic = static_cast< CReportEntityPicture* >( GetEntity() );
  278. m_filename = pic->GetFilename();
  279. m_borderColor = pic->GetBorderColor();
  280. m_borderStyle = pic->GetBorderStyle();
  281. m_borderThickness = pic->GetBorderThickness();
  282. if( m_otiFrameColorCombo )
  283. m_otiFrameColorCombo->SetCurColor( m_borderColor );
  284. if (m_otiFrameThicknessCombo)
  285. m_otiFrameThicknessCombo->SetLineThickness(m_borderThickness);
  286. if (m_otiExistLeft)
  287. m_otiExistLeft->SetCheck(m_borderStyle&DIAGRAM_FRAME_STYLE_LEFT);
  288. if (m_otiExistRight)
  289. m_otiExistRight->SetCheck((m_borderStyle&DIAGRAM_FRAME_STYLE_RIGHT)?TRUE:FALSE);
  290. if (m_otiExistTop)
  291. m_otiExistTop->SetCheck((m_borderStyle&DIAGRAM_FRAME_STYLE_TOP)?TRUE:FALSE);
  292. if (m_otiExistBottom)
  293. m_otiExistBottom->SetCheck((m_borderStyle&DIAGRAM_FRAME_STYLE_BOTTOM)?TRUE:FALSE);
  294. if (m_otiFile)
  295. m_otiFile->AddFileName(m_filename);
  296. }
  297. BOOL CReportPictureProperties::OnInitDialog() 
  298. /* ============================================================
  299. Function : CReportPictureProperties::OnInitDialog
  300. Description : Handler for the "WM_INITDIALOG" messag
  301. Access : Protected
  302. Return : BOOL - Always "TRUE"
  303. Parameters : none
  304. Usage : Called from MFC
  305.    ============================================================*/
  306. {
  307. CDialog::OnInitDialog();
  308. COptionTreeItem *otiRoot = NULL;
  309. COptionTreeItem *otiItem = NULL;
  310. CRect rcClient;
  311. DWORD dwStyle, dwOptions;
  312. LOGFONT lfFont, lfDefaultFont;
  313. // Get log fonts
  314. GetFont()->GetLogFont(&lfFont);
  315. GetFont()->GetLogFont(&lfDefaultFont);
  316. strcpy(lfDefaultFont.lfFaceName, _T("Arial"));
  317. // Get the clients rectangle
  318. GetClientRect(rcClient);
  319. // Setup the window style
  320. dwStyle = WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  321. // Setup the tree options 
  322. // OT_OPTIONS_SHOWINFOWINDOW
  323. dwOptions = OT_OPTIONS_SHADEEXPANDCOLUMN | OT_OPTIONS_SHADEROOTITEMS | OT_OPTIONS_SHOWINFOWINDOW;
  324. int  trBot=rcClient.bottom;
  325. if (GetDlgItem(IDOK))
  326. {
  327. CRect rrrr;
  328. GetDlgItem(IDOK)->GetWindowRect(rrrr);
  329. ScreenToClient(rrrr);
  330. trBot = rrrr.top -4;
  331. }
  332. // Create tree options
  333. CRect trR = rcClient;
  334. trR.bottom = trBot;
  335. if (m_otTree.Create(dwStyle, trR, this, dwOptions, 1004) == FALSE)
  336. {
  337. TRACE0("Failed to create options control.rn");
  338. return FALSE;
  339. }
  340. // Want to be notified
  341. m_otTree.SetNotify(TRUE, this);
  342. // -- Edit Items
  343. CString resStr;
  344. otiRoot = m_otTree.InsertItem(new COptionTreeItem());
  345. resStr.LoadString(IDS_REP_COMMON_PROPS);
  346. otiRoot->SetLabelText(resStr);
  347. resStr.LoadString(IDS_REP_FULL_COMMON_PROPS);
  348. otiRoot->SetInfoText(resStr);
  349. m_otiFile = (COptionTreeItemFile*)m_otTree.InsertItem(new COptionTreeItemFile(), otiRoot);
  350. resStr.LoadString(IDS_REP_PR_FILE);
  351. m_otiFile->SetLabelText(resStr);
  352. resStr.LoadString(IDS_REP_PR_FULL_FILE);
  353. m_otiFile->SetInfoText(resStr);
  354. if (m_otiFile->CreateFileItem("",GetExtFromType(0).Mid(2,3),GetFileTypes(TRUE),
  355. OT_FILE_OPENDIALOG | OT_FILE_SHOWFULLPATH, 
  356. OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY | OFN_FILEMUSTEXIST) == TRUE)
  357. {
  358. }
  359. otiRoot->Expand();
  360. otiRoot = m_otTree.InsertItem(new COptionTreeItem());
  361. resStr.LoadString(IDS_REP_PR_DL_FRAME);
  362. otiRoot->SetLabelText(resStr);
  363. resStr.LoadString(IDS_REP_PR_DL_FULL_FRAME);
  364. otiRoot->SetInfoText(resStr);
  365. CString yesS;
  366. yesS.LoadString(IDS_YES);
  367. CString noS;
  368. noS.LoadString(IDS_NO);
  369. m_otiExistLeft = (COptionTreeItemCheckBox*)m_otTree.InsertItem(new COptionTreeItemCheckBox(), otiRoot);
  370. resStr.LoadString(IDS_REP_PR_DL_LEFT);
  371. m_otiExistLeft->SetLabelText(resStr);
  372. resStr.LoadString(IDS_REP_PR_DL_FULL_LEFT);
  373. m_otiExistLeft->SetInfoText(resStr);
  374. if (m_otiExistLeft->CreateCheckBoxItem(m_borderStyle&DIAGRAM_FRAME_STYLE_LEFT, OT_CHECKBOX_SHOWCHECK) == TRUE)
  375. {
  376. m_otiExistLeft->SetCheckText(yesS, noS);
  377. }
  378. m_otiExistRight = (COptionTreeItemCheckBox*)m_otTree.InsertItem(new COptionTreeItemCheckBox(), otiRoot);
  379. resStr.LoadString(IDS_REP_PR_DL_RIGHT);
  380. m_otiExistRight->SetLabelText(resStr);
  381. resStr.LoadString(IDS_REP_PR_DL_FULL_RIGHT);
  382. m_otiExistRight->SetInfoText(resStr);
  383. if (m_otiExistRight->CreateCheckBoxItem(m_borderStyle&DIAGRAM_FRAME_STYLE_RIGHT, OT_CHECKBOX_SHOWCHECK) == TRUE)
  384. {
  385. m_otiExistRight->SetCheckText(yesS, noS);
  386. }
  387. m_otiExistTop = (COptionTreeItemCheckBox*)m_otTree.InsertItem(new COptionTreeItemCheckBox(), otiRoot);
  388. resStr.LoadString(IDS_REP_PR_DL_TOP);
  389. m_otiExistTop->SetLabelText(resStr);
  390. resStr.LoadString(IDS_REP_PR_DL_FULL_TOP);
  391. m_otiExistTop->SetInfoText(resStr);
  392. if (m_otiExistTop->CreateCheckBoxItem(m_borderStyle&DIAGRAM_FRAME_STYLE_TOP, OT_CHECKBOX_SHOWCHECK) == TRUE)
  393. {
  394. m_otiExistTop->SetCheckText(yesS, noS);
  395. }
  396. m_otiExistBottom = (COptionTreeItemCheckBox*)m_otTree.InsertItem(new COptionTreeItemCheckBox(), otiRoot);
  397. resStr.LoadString(IDS_REP_PR_DL_BOTTOM);
  398. m_otiExistBottom->SetLabelText(resStr);
  399. resStr.LoadString(IDS_REP_PR_DL_FULL_BOTTOM);
  400. m_otiExistBottom->SetInfoText(resStr);
  401. if (m_otiExistBottom->CreateCheckBoxItem(m_borderStyle&DIAGRAM_FRAME_STYLE_BOTTOM, OT_CHECKBOX_SHOWCHECK) == TRUE)
  402. {
  403. m_otiExistBottom->SetCheckText(yesS, noS);
  404. }
  405. m_otiFrameColorCombo = (COptionTreeItemColorComboBox*)m_otTree.InsertItem(new COptionTreeItemColorComboBox(), otiRoot);
  406. resStr.LoadString(IDS_PER_PR_DL_COL_FR);
  407. m_otiFrameColorCombo->SetLabelText(resStr);
  408. resStr.LoadString(IDS_PER_PR_DL_FULL_COL_FR);
  409. m_otiFrameColorCombo->SetInfoText(resStr);
  410. if (m_otiFrameColorCombo->CreateComboItem(NULL) == TRUE)
  411. {
  412. m_otiFrameColorCombo->SetCurColor(m_borderColor);
  413. }
  414. m_otiFrameThicknessCombo = (COptionTreeItemLineThikComboBox*)m_otTree.InsertItem(new COptionTreeItemLineThikComboBox(), otiRoot);
  415. resStr.LoadString(IDS_PER_PR_DL_TH_FR);
  416. m_otiFrameThicknessCombo->SetLabelText(resStr);
  417. resStr.LoadString(IDS_PER_PR_DL_FULL_TH_FR);
  418. m_otiFrameThicknessCombo->SetInfoText(resStr);
  419. if (m_otiFrameThicknessCombo->CreateComboItem(NULL) == TRUE)
  420. {
  421. m_otiFrameThicknessCombo->SetLineThickness(m_borderThickness);
  422. }
  423. otiRoot->Expand();
  424. return TRUE;
  425. }