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.

2021 lines
54 KiB

  1. // pbrusvw.cpp : implementation of the CPBView class
  2. //
  3. #include "stdafx.h"
  4. #include "global.h"
  5. #include "pbrush.h"
  6. #include "pbrusdoc.h"
  7. #include "pbrusfrm.h"
  8. #include "pbrusvw.h"
  9. #include "ipframe.h"
  10. #include "minifwnd.h"
  11. #include "bmobject.h"
  12. #include "imgsuprt.h"
  13. #include "imgwnd.h"
  14. #include "imgcolor.h"
  15. #include "imgbrush.h"
  16. #include "imageatt.h"
  17. #include "undo.h"
  18. #include "props.h"
  19. #include "imgwell.h"
  20. #include "imgtools.h"
  21. #include "imgdlgs.h"
  22. #include "toolbox.h"
  23. #include "thumnail.h"
  24. #include "t_text.h"
  25. #include "cmpmsg.h"
  26. #include "printres.h"
  27. #include "settings.h"
  28. #include "colorsrc.h"
  29. #include "cderr.h"
  30. #include "srvritem.h"
  31. #include <regstr.h>
  32. #ifdef USE_PRINTDLGEX
  33. #include <afxprntx.h>
  34. #include <dlgprnt2.cpp>
  35. #endif //USE_PRINTDLGEX
  36. #if 0 // THIS_FILE is already declared in dlgprnt2.cpp
  37. #ifdef _DEBUG
  38. #undef THIS_FILE
  39. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  40. #endif
  41. #endif
  42. IMPLEMENT_DYNCREATE(CPBView, CView)
  43. #include "memtrace.h"
  44. /***************************************************************************/
  45. // CPBView
  46. BEGIN_MESSAGE_MAP(CPBView, CView)
  47. //{{AFX_MSG_MAP(CPBView)
  48. ON_WM_CREATE()
  49. ON_WM_SIZE()
  50. ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  51. ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
  52. ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  53. ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  54. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  55. ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  56. ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
  57. ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
  58. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
  59. ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
  60. ON_COMMAND(ID_VIEW_ZOOM_100, OnViewZoom100)
  61. ON_COMMAND(ID_VIEW_ZOOM_400, OnViewZoom400)
  62. ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOM_100, OnUpdateViewZoom100)
  63. ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOM_400, OnUpdateViewZoom400)
  64. ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
  65. ON_COMMAND(ID_IMAGE_INVERT_COLORS, OnImageInvertColors)
  66. ON_UPDATE_COMMAND_UI(ID_IMAGE_INVERT_COLORS, OnUpdateImageInvertColors)
  67. ON_COMMAND(IDM_TGLOPAQUE, OnTglopaque)
  68. ON_UPDATE_COMMAND_UI(IDM_TGLOPAQUE, OnUpdateTglopaque)
  69. ON_COMMAND(ID_IMAGE_ATTRIBUTES, OnImageAttributes)
  70. ON_COMMAND(IDMX_SEL2BSH, OnSel2bsh)
  71. ON_COMMAND(IDMX_LARGERBRUSH, OnLargerbrush)
  72. ON_COMMAND(IDMX_SMALLERBRUSH, OnSmallerbrush)
  73. ON_COMMAND(ID_VIEW_ZOOM, OnViewZoom)
  74. ON_COMMAND(ID_IMAGE_FLIP_ROTATE, OnImageFlipRotate)
  75. ON_UPDATE_COMMAND_UI(ID_IMAGE_FLIP_ROTATE, OnUpdateImageFlipRotate)
  76. ON_COMMAND(IDM_EDITCOLORS, OnEditcolors)
  77. ON_UPDATE_COMMAND_UI(IDM_EDITCOLORS, OnUpdateEditcolors)
  78. #if 0
  79. ON_COMMAND(IDM_LOADCOLORS, OnLoadcolors)
  80. ON_UPDATE_COMMAND_UI(IDM_LOADCOLORS, OnUpdateLoadcolors)
  81. ON_COMMAND(IDM_SAVECOLORS, OnSavecolors)
  82. ON_UPDATE_COMMAND_UI(IDM_SAVECOLORS, OnUpdateSavecolors)
  83. #endif
  84. ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  85. ON_COMMAND(ID_EDIT_PASTE_FROM, OnEditPasteFrom)
  86. ON_COMMAND(ID_EDIT_COPY_TO, OnEditCopyTo)
  87. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY_TO, OnUpdateEditCopyTo)
  88. ON_COMMAND(ID_IMAGE_STRETCH_SKEW, OnImageStretchSkew)
  89. ON_UPDATE_COMMAND_UI(ID_IMAGE_STRETCH_SKEW, OnUpdateImageStretchSkew)
  90. ON_COMMAND(ID_VIEW_VIEW_PICTURE, OnViewViewPicture)
  91. ON_UPDATE_COMMAND_UI(ID_VIEW_VIEW_PICTURE, OnUpdateViewViewPicture)
  92. ON_COMMAND(ID_VIEW_TEXT_TOOLBAR, OnViewTextToolbar)
  93. ON_UPDATE_COMMAND_UI(ID_VIEW_TEXT_TOOLBAR, OnUpdateViewTextToolbar)
  94. ON_COMMAND(ID_FILE_SETASWALLPAPER_T, OnFileSetaswallpaperT)
  95. ON_UPDATE_COMMAND_UI(ID_FILE_SETASWALLPAPER_T, OnUpdateFileSetaswallpaperT)
  96. ON_COMMAND(ID_FILE_SETASWALLPAPER_C, OnFileSetaswallpaperC)
  97. ON_UPDATE_COMMAND_UI(ID_FILE_SETASWALLPAPER_C, OnUpdateFileSetaswallpaperC)
  98. ON_COMMAND(ID_VIEW_THUMBNAIL, OnViewThumbnail)
  99. ON_UPDATE_COMMAND_UI(ID_VIEW_THUMBNAIL, OnUpdateViewThumbnail)
  100. ON_UPDATE_COMMAND_UI(ID_IMAGE_ATTRIBUTES, OnUpdateImageAttributes)
  101. ON_COMMAND(ID_ESCAPE, OnEscape)
  102. ON_COMMAND(ID_ESCAPE_SERVER, OnEscapeServer)
  103. ON_WM_SHOWWINDOW()
  104. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditSelection)
  105. ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditClearSel)
  106. ON_COMMAND(ID_FILE_PAGE_SETUP, OnFilePageSetup)
  107. ON_COMMAND(ID_IMAGE_CLEAR_IMAGE, OnImageClearImage)
  108. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditClearSel)
  109. ON_UPDATE_COMMAND_UI(ID_IMAGE_CLEAR_IMAGE, OnUpdateImageClearImage)
  110. //}}AFX_MSG_MAP
  111. ON_WM_DESTROY()
  112. // Standard printing commands
  113. ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
  114. ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
  115. END_MESSAGE_MAP()
  116. /***************************************************************************/
  117. // CPBView construction/destruction
  118. CPBView::CPBView()
  119. {
  120. m_pImgWnd = NULL;
  121. m_pwndThumbNailFloat = NULL;
  122. m_pwndThumbNailView = NULL;
  123. }
  124. /***************************************************************************/
  125. CPBView::~CPBView()
  126. {
  127. // reset the toolbar
  128. if (g_pImgToolWnd && g_pImgToolWnd->m_hWnd &&
  129. IsWindow(g_pImgToolWnd->m_hWnd) )
  130. {
  131. g_pImgToolWnd->SelectTool( IDMB_ARROW );
  132. g_pImgToolWnd->InvalidateOptions();
  133. }
  134. DestroyThumbNailView();
  135. if (m_pImgWnd)
  136. {
  137. delete m_pImgWnd;
  138. m_pImgWnd = NULL;
  139. }
  140. }
  141. /***************************************************************************/
  142. BOOL CPBView::PreCreateWindow( CREATESTRUCT& cs )
  143. {
  144. cs.style |= WS_CLIPCHILDREN;
  145. cs.dwExStyle |= WS_EX_CLIENTEDGE;
  146. return CView::PreCreateWindow( cs );
  147. }
  148. /***************************************************************************/
  149. BOOL CPBView::PreTranslateMessage(MSG *pMsg)
  150. {
  151. // Handle a bug in MFC regarding enabling of accelerators on Popup menus.
  152. if ( pMsg->message == WM_KEYDOWN )
  153. {
  154. // Find the app menu for this window.
  155. CWnd *pWnd = this;
  156. CMenu *pMenu = NULL;
  157. while( pWnd )
  158. {
  159. if ( (pMenu = pWnd->GetMenu()) && IsMenu(pMenu->m_hMenu) )
  160. break;
  161. else
  162. pMenu = NULL;
  163. pWnd = pWnd->GetParent();
  164. }
  165. if ( pMenu )
  166. {
  167. pMenu->EnableMenuItem( ID_VIEW_ZOOM_100, MF_BYCOMMAND |
  168. (m_pImgWnd && m_pImgWnd->GetZoom() != 1 ? MF_ENABLED : MF_DISABLED) );
  169. pMenu->EnableMenuItem( ID_VIEW_ZOOM_400, MF_BYCOMMAND |
  170. (m_pImgWnd && m_pImgWnd->GetZoom() != 4 ? MF_ENABLED : MF_DISABLED) );
  171. pMenu->EnableMenuItem( ID_VIEW_GRID, MF_BYCOMMAND |
  172. (m_pImgWnd && m_pImgWnd->GetZoom() > 2 ? MF_ENABLED : MF_DISABLED) );
  173. }
  174. }
  175. return CView::PreTranslateMessage(pMsg);
  176. }
  177. /***************************************************************************/
  178. // CPBView drawing
  179. void CPBView::OnDraw( CDC* pDC )
  180. {
  181. if (m_pImgWnd)
  182. {
  183. CRect rectPaint;
  184. CPalette* ppal = m_pImgWnd->SetImgPalette( pDC, FALSE );
  185. // if the dc passed in is a CPaint DC use the rcPaint rect to optimize
  186. // painting to only paint the invalid area. ELSE use the whole image
  187. // size.
  188. if (pDC->IsKindOf( RUNTIME_CLASS( CPaintDC ) ) )
  189. {
  190. rectPaint = ((CPaintDC *)pDC)->m_ps.rcPaint;
  191. if ( theApp.m_bEmbedded )
  192. m_pImgWnd->Invalidate();
  193. }
  194. else
  195. {
  196. m_pImgWnd->GetImageRect( rectPaint );
  197. }
  198. m_pImgWnd->DrawImage( pDC, &rectPaint );
  199. if (ppal)
  200. pDC->SelectPalette( ppal, FALSE );
  201. }
  202. }
  203. /***************************************************************************/
  204. // CPBView printing
  205. BOOL CPBView::GetPrintToInfo(CPrintInfo* pInfo)
  206. {
  207. ASSERT(pInfo != NULL);
  208. ASSERT(pInfo->m_pPD != NULL);
  209. if (theApp.m_strPrinterName.IsEmpty())
  210. return FALSE;
  211. ASSERT(pInfo->m_pPD->m_pd.hDC == NULL);
  212. pInfo->m_pPD->m_pd.hDC = ::CreateDC(NULL,
  213. theApp.m_strPrinterName,
  214. NULL, NULL);
  215. // set up From and To page range from Min and Max
  216. pInfo->m_pPD->m_pd.nFromPage = (WORD)pInfo->GetMinPage();
  217. pInfo->m_pPD->m_pd.nToPage = (WORD)pInfo->GetMaxPage();
  218. ASSERT(pInfo->m_pPD != NULL);
  219. ASSERT(pInfo->m_pPD->m_pd.hDC != NULL);
  220. pInfo->m_nNumPreviewPages = theApp.m_nNumPreviewPages;
  221. VERIFY(pInfo->m_strPageDesc.LoadString(AFX_IDS_PREVIEWPAGEDESC));
  222. return TRUE;
  223. }
  224. BOOL CPBView::OnPreparePrinting( CPrintInfo* pInfo )
  225. {
  226. #ifdef USE_PRINTDLGEX
  227. //
  228. // Create a C_PrintDialogEx structure to replace the PrintDialog in the
  229. // CPrintInfo
  230. //
  231. m_pdRestore= pInfo->m_pPD;
  232. m_pdexSub = new C_PrintDialogEx (FALSE, PD_RETURNDC |
  233. PD_ALLPAGES | PD_NOCURRENTPAGE | PD_NOPAGENUMS |
  234. PD_NOSELECTION | PD_USEDEVMODECOPIESANDCOLLATE);
  235. pInfo->m_pPD = m_pdexSub;
  236. // These next 2 lines copied from mfc42 source to initialize the printdialog
  237. //
  238. pInfo->SetMinPage (1);
  239. pInfo->SetMaxPage (0xffff);
  240. pInfo->m_pPD->m_pd.nFromPage = 1;
  241. pInfo->m_pPD->m_pd.nToPage = 1;
  242. #endif //USE_PRINTDLGEX
  243. new CPrintResObj( this, pInfo );
  244. if (pInfo->m_lpUserData == NULL)
  245. return FALSE;
  246. if (theApp.m_bPrintOnly)
  247. {
  248. if (GetPrintToInfo(pInfo))
  249. {
  250. return(TRUE);
  251. }
  252. if (! theApp.GetPrinterDeviceDefaults( &pInfo->m_pPD->m_pd ))
  253. {
  254. // bring up dialog to alert the user they need to install a printer.
  255. if (theApp.DoPrintDialog( pInfo->m_pPD ) != IDOK)
  256. return FALSE;
  257. }
  258. if (! pInfo->m_pPD->m_pd.hDC)
  259. {
  260. // call CreatePrinterDC if DC was not created by above
  261. if (! pInfo->m_pPD->CreatePrinterDC())
  262. return FALSE;
  263. }
  264. // set up From and To page range from Min and Max
  265. pInfo->m_pPD->m_pd.nFromPage = (WORD)pInfo->GetMinPage();
  266. pInfo->m_pPD->m_pd.nToPage = (WORD)pInfo->GetMaxPage();
  267. pInfo->m_nNumPreviewPages = theApp.m_nNumPreviewPages;
  268. return TRUE;
  269. }
  270. // default preparation
  271. if (! DoPreparePrinting( pInfo ))
  272. {
  273. ((CPrintResObj*)pInfo->m_lpUserData)->EndPrinting( NULL, pInfo );
  274. pInfo->m_lpUserData = NULL;
  275. return FALSE;
  276. }
  277. return TRUE;
  278. }
  279. /***************************************************************************/
  280. void CPBView::OnBeginPrinting( CDC* pDC, CPrintInfo* pInfo )
  281. {
  282. if (pInfo != NULL
  283. && pInfo->m_lpUserData != NULL)
  284. ((CPrintResObj*)pInfo->m_lpUserData)->BeginPrinting( pDC, pInfo );
  285. else
  286. CView::OnBeginPrinting( pDC, pInfo );
  287. }
  288. /***************************************************************************/
  289. void CPBView::OnPrepareDC( CDC* pDC, CPrintInfo* pInfo )
  290. {
  291. #ifdef USE_MIRRORING
  292. //
  293. // Disable RTL mirroring
  294. //
  295. if (PBGetLayout(pDC->GetSafeHdc()) & LAYOUT_RTL)
  296. {
  297. PBSetLayout(pDC->GetSafeHdc(), 0);
  298. }
  299. #endif
  300. CView::OnPrepareDC( pDC, pInfo );
  301. if (pInfo != NULL
  302. && pInfo->m_lpUserData != NULL)
  303. ((CPrintResObj*)pInfo->m_lpUserData)->PrepareDC( pDC, pInfo );
  304. }
  305. /***************************************************************************/
  306. void CPBView::OnPrint( CDC* pDC, CPrintInfo* pInfo )
  307. {
  308. BOOL bProcessed = FALSE;
  309. if (pInfo != NULL
  310. && pInfo->m_lpUserData != NULL)
  311. bProcessed = ((CPrintResObj*)pInfo->m_lpUserData)->PrintPage( pDC, pInfo );
  312. if (! bProcessed)
  313. CView::OnPrint( pDC, pInfo );
  314. }
  315. /***************************************************************************/
  316. void CPBView::OnEndPrinting( CDC* pDC, CPrintInfo* pInfo )
  317. {
  318. if (pInfo == NULL)
  319. return;
  320. if (pInfo->m_lpUserData != NULL)
  321. {
  322. ((CPrintResObj*)pInfo->m_lpUserData)->EndPrinting( pDC, pInfo );
  323. pInfo->m_lpUserData = NULL;
  324. }
  325. #ifdef USE_PRINTDLGEX
  326. //
  327. // Restore the original dialog pointer
  328. //
  329. pInfo->m_pPD = m_pdRestore;
  330. delete m_pdexSub;
  331. #endif //USE_PRINTDLGEX
  332. }
  333. /******************************************************************************/
  334. // CPBView diagnostics
  335. #ifdef _DEBUG
  336. void CPBView::AssertValid() const
  337. {
  338. CView::AssertValid();
  339. }
  340. /***************************************************************************/
  341. void CPBView::Dump( CDumpContext& dc ) const
  342. {
  343. CView::Dump( dc );
  344. }
  345. /***************************************************************************/
  346. CPBDoc* CPBView::GetDocument() // non-debug version is inline
  347. {
  348. ASSERT( m_pDocument->IsKindOf( RUNTIME_CLASS( CPBDoc ) ) );
  349. return (CPBDoc*)m_pDocument;
  350. }
  351. #endif //_DEBUG
  352. /***************************************************************************/
  353. // CPBView message handlers
  354. int CPBView::OnCreate( LPCREATESTRUCT lpCreateStruct )
  355. {
  356. if (CView::OnCreate( lpCreateStruct ) == -1)
  357. return -1;
  358. #ifdef USE_MIRRORING
  359. //
  360. // Disable RTL mirroring on client drawing area. [samera]
  361. //
  362. if (lpCreateStruct->dwExStyle & WS_EX_LAYOUTRTL)
  363. {
  364. SetWindowLong( GetSafeHwnd(), GWL_EXSTYLE, lpCreateStruct->dwExStyle & ~WS_EX_LAYOUTRTL );
  365. }
  366. #endif
  367. return 0;
  368. }
  369. /***************************************************************************/
  370. void CPBView::OnShowWindow( BOOL bShow, UINT nStatus )
  371. {
  372. if (theApp.m_bPrintOnly)
  373. return;
  374. CView::OnShowWindow( bShow, nStatus );
  375. }
  376. /***************************************************************************/
  377. void CPBView::OnDestroy()
  378. {
  379. // reset the toolbar
  380. if (g_pImgToolWnd && g_pImgToolWnd->m_hWnd &&
  381. IsWindow(g_pImgToolWnd->m_hWnd) )
  382. {
  383. g_pImgToolWnd->SelectTool( IDMB_ARROW );
  384. g_pImgToolWnd->InvalidateOptions();
  385. }
  386. DestroyThumbNailView();
  387. if (m_pImgWnd)
  388. {
  389. if ( ::IsWindow(m_pImgWnd->m_hWnd) )
  390. m_pImgWnd->DestroyWindow();
  391. delete m_pImgWnd;
  392. m_pImgWnd = NULL;
  393. }
  394. CView::OnDestroy();
  395. }
  396. /***************************************************************************/
  397. void CPBView::OnInitialUpdate( void )
  398. {
  399. CPBDoc* pDoc = GetDocument();
  400. if (SetObject())
  401. {
  402. if (theApp.m_bPrintOnly)
  403. {
  404. if (pDoc->m_bObjectLoaded)
  405. {
  406. OnFilePrint();
  407. GetParentFrame()->PostMessage( WM_CLOSE );
  408. return;
  409. }
  410. theApp.m_bPrintOnly = FALSE;
  411. }
  412. theUndo.SetMaxLevels( 3 );
  413. SetTools();
  414. }
  415. else
  416. {
  417. if (pDoc->m_pBitmapObjNew != NULL)
  418. {
  419. delete pDoc->m_pBitmapObjNew;
  420. pDoc->m_pBitmapObjNew = NULL;
  421. }
  422. TRACE( TEXT("OnInitialUpdate SetObject Failed!\n") );
  423. }
  424. }
  425. /***************************************************************************/
  426. void CPBView::OnActivateView( BOOL bActivate, CView* pActivateView,
  427. CView* pDeactiveView )
  428. {
  429. CView::OnActivateView( bActivate, pActivateView, pDeactiveView );
  430. }
  431. /***************************************************************************/
  432. BOOL CPBView::OnCmdMsg( UINT nID, int nCode, void* pExtra,
  433. AFX_CMDHANDLERINFO* pHandlerInfo )
  434. {
  435. if (nCode == CN_COMMAND)
  436. {
  437. if (m_pImgWnd
  438. && m_pImgWnd->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ))
  439. return TRUE;
  440. }
  441. return CView::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
  442. }
  443. /***************************************************************************/
  444. void CPBView::OnSize(UINT nType, int cx, int cy)
  445. {
  446. CView::OnSize( nType, cx, cy );
  447. // TODO: Add your message handler code here
  448. if (m_pImgWnd)
  449. m_pImgWnd->MoveWindow( 0, 0, cx, cy );
  450. }
  451. /***************************************************************************/
  452. BOOL CPBView::SetObject()
  453. {
  454. CPBDoc* pDoc = GetDocument();
  455. ASSERT( pDoc );
  456. ASSERT( pDoc->m_pBitmapObjNew );
  457. if (! pDoc || ! pDoc->m_pBitmapObjNew)
  458. return FALSE;
  459. CBitmapObj* pBitmapObj = pDoc->m_pBitmapObjNew;
  460. // see if a bad file was loaded, but not an empty file, which is OK
  461. if (! pDoc->m_bObjectLoaded
  462. && ! pBitmapObj->m_bTempName
  463. && pBitmapObj->m_hThing
  464. && pBitmapObj->m_lMemSize)
  465. {
  466. delete pBitmapObj;
  467. pBitmapObj = NULL;
  468. CString strDocName;
  469. CString strFilterExt;
  470. if (! pDoc->GetDocTemplate()->GetDocString( strDocName, CDocTemplate::docName )
  471. || strDocName.IsEmpty())
  472. // use generic 'untitled'
  473. VERIFY( strDocName.LoadString( AFX_IDS_UNTITLED ) );
  474. if (! pDoc->GetDocTemplate()->GetDocString( strFilterExt, CDocTemplate::filterExt )
  475. || strFilterExt.IsEmpty())
  476. pDoc->SetPathName( strDocName );
  477. else
  478. pDoc->SetPathName( strDocName + strFilterExt );
  479. // do settitle after setpathname.
  480. pDoc->SetTitle( strDocName );
  481. pDoc->m_sName.Empty();
  482. pDoc->m_bNewDoc = TRUE;
  483. if (! pDoc->CreateNewDocument())
  484. return FALSE;
  485. pBitmapObj = pDoc->m_pBitmapObjNew;
  486. }
  487. if (! pBitmapObj->m_pImg
  488. && ! pBitmapObj->CreateImg())
  489. return FALSE;
  490. if (pBitmapObj->m_pImg->cxWidth < 1
  491. || pBitmapObj->m_pImg->cyHeight < 1)
  492. {
  493. CmpMessageBox( IDS_ERROR_BITMAPSIZE, AFX_IDS_APP_TITLE, MB_OK | MB_ICONEXCLAMATION );
  494. return FALSE;
  495. }
  496. CleanupImgUndo();
  497. CleanupImgRubber();
  498. if (! SetView( pBitmapObj ))
  499. return FALSE;
  500. if (pDoc->m_pBitmapObj)
  501. {
  502. delete pDoc->m_pBitmapObj;
  503. pDoc->m_pBitmapObj = NULL;
  504. }
  505. pDoc->m_pBitmapObj = pBitmapObj;
  506. pDoc->m_pBitmapObjNew = NULL;
  507. return TRUE;
  508. }
  509. /***************************************************************************/
  510. BOOL CPBView::SetView( CBitmapObj* pBitmapObj )
  511. {
  512. IMG* pImg = pBitmapObj->m_pImg;
  513. ASSERT( pImg );
  514. CImgWnd* pImgWnd = new CImgWnd( pImg );
  515. if (pImgWnd == NULL)
  516. {
  517. theApp.SetMemoryEmergency();
  518. TRACE( TEXT("Create CImgWnd faild\n") );
  519. return FALSE;
  520. }
  521. RECT rectPos;
  522. GetClientRect( &rectPos );
  523. if (! pImgWnd->Create( WS_CHILD | WS_VISIBLE, rectPos, this ))
  524. {
  525. TRACE( TEXT("Create img wnd failed\n") );
  526. return FALSE;
  527. }
  528. if (m_pImgWnd)
  529. {
  530. if ( ::IsWindow( m_pImgWnd->m_hWnd) )
  531. m_pImgWnd->DestroyWindow();
  532. delete m_pImgWnd;
  533. m_pImgWnd = NULL;
  534. }
  535. m_pImgWnd = pImgWnd;
  536. if (m_pwndThumbNailView != NULL)
  537. {
  538. m_pImgWnd->SetThumbnailView( m_pwndThumbNailView );
  539. m_pwndThumbNailView->UpdateThumbNailView();
  540. }
  541. m_pImgWnd->SetZoom( 1 );
  542. // m_pImgWnd->SetFocus(); // Commented out to prevent focus problems w/OLE
  543. return TRUE;
  544. }
  545. /***************************************************************************/
  546. int CPBView::SetTools()
  547. {
  548. CFrameWnd* pOwnerWindow = GetParentFrame();
  549. CFrameWnd* pParentWindow = pOwnerWindow;
  550. BOOL bRestoreState = FALSE;
  551. ASSERT( pOwnerWindow != NULL );
  552. if (! theApp.m_bLinked && theApp.m_pwndInPlaceFrame != NULL)
  553. {
  554. pOwnerWindow = theApp.m_pwndInPlaceFrame;
  555. if (theApp.m_hwndInPlaceApp != NULL)
  556. pParentWindow = (CFrameWnd*)CFrameWnd::FromHandle( theApp.m_hwndInPlaceApp );
  557. }
  558. ASSERT(g_pStatBarWnd);
  559. ASSERT(g_pImgToolWnd);
  560. ASSERT(g_pImgColorsWnd);
  561. // Create the status bar
  562. if ( !g_pStatBarWnd->m_hWnd )
  563. {
  564. if ( g_pStatBarWnd->Create(pParentWindow) )
  565. {
  566. if (theApp.m_fntStatus.m_hObject != NULL)
  567. g_pStatBarWnd->SetFont( &theApp.m_fntStatus, FALSE );
  568. g_pStatBarWnd->SetOwner(pOwnerWindow);
  569. ShowStatusBar(TRUE);
  570. bRestoreState = TRUE;
  571. }
  572. else
  573. {
  574. TRACE0("Failed to create status bar\n");
  575. return -1;
  576. }
  577. }
  578. pParentWindow->EnableDocking(CBRS_ALIGN_ANY);
  579. // Create and dock the tool bar
  580. if ( !g_pImgToolWnd->m_hWnd || !IsWindow(g_pImgToolWnd->m_hWnd) )
  581. {
  582. CString strToolWnd;
  583. strToolWnd.LoadString(IDS_PAINT_TOOL);
  584. if ( g_pImgToolWnd->Create( strToolWnd,
  585. WS_CHILD|WS_VISIBLE|CBRS_LEFT,
  586. CRect(0, 0, 0, 0),
  587. CPoint(25, 25),
  588. 2,
  589. pParentWindow ) )
  590. {
  591. g_pImgToolWnd->SetOwner(pOwnerWindow);
  592. g_pImgToolWnd->EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT);
  593. pParentWindow->DockControlBar(g_pImgToolWnd,
  594. AFX_IDW_DOCKBAR_LEFT);
  595. bRestoreState = TRUE;
  596. }
  597. else
  598. {
  599. TRACE0("Failed to create toolbar\n");
  600. return -1;
  601. }
  602. }
  603. // Create and dock the color bar
  604. if ( !g_pImgColorsWnd->m_hWnd || !IsWindow(g_pImgColorsWnd->m_hWnd) )
  605. {
  606. CString strColorsWnd;
  607. strColorsWnd.LoadString(IDS_COLORS);
  608. if ( g_pImgColorsWnd->Create(strColorsWnd,
  609. WS_CHILD|WS_VISIBLE|CBRS_BOTTOM,
  610. pParentWindow) )
  611. {
  612. g_pImgColorsWnd->SetOwner(pOwnerWindow);
  613. g_pImgColorsWnd->EnableDocking(CBRS_ALIGN_BOTTOM|CBRS_ALIGN_TOP);
  614. pParentWindow->DockControlBar(g_pImgColorsWnd,
  615. AFX_IDW_DOCKBAR_BOTTOM);
  616. bRestoreState = TRUE;
  617. }
  618. else
  619. {
  620. TRACE0("Failed to create colorbar\n");
  621. return -1;
  622. }
  623. }
  624. if ( bRestoreState && !theApp.m_bLinked && !theApp.m_bEmbedded && !theApp.m_pwndInPlaceFrame )
  625. pOwnerWindow->LoadBarState(TEXT("General")); // Dangerous in-place!
  626. pOwnerWindow->DelayRecalcLayout( TRUE );
  627. return 0;
  628. }
  629. /******************************************************************************/
  630. BOOL CPBView::DestroyThumbNailView()
  631. {
  632. BOOL bResult = FALSE;
  633. BOOL bOriginalSetting = theApp.m_bShowThumbnail;
  634. theApp.m_bShowThumbnail = FALSE;
  635. if (m_pwndThumbNailFloat != NULL)
  636. {
  637. if ( ::IsWindow(m_pwndThumbNailFloat->m_hWnd) )
  638. m_pwndThumbNailFloat->DestroyWindow();
  639. delete m_pwndThumbNailFloat;
  640. m_pwndThumbNailFloat = NULL;
  641. bResult = TRUE;
  642. }
  643. theApp.m_bShowThumbnail = bOriginalSetting;
  644. m_pwndThumbNailView = NULL;
  645. if (m_pImgWnd)
  646. m_pImgWnd->SetThumbnailView( NULL );
  647. return bResult;
  648. }
  649. BOOL CPBView::CreateThumbNailView()
  650. {
  651. if (m_pImgWnd == NULL)
  652. return FALSE;
  653. DestroyThumbNailView();
  654. m_pwndThumbNailFloat = new CFloatThumbNailView( m_pImgWnd );
  655. if (m_pwndThumbNailFloat != NULL)
  656. {
  657. if (m_pwndThumbNailFloat->Create( this ))
  658. m_pwndThumbNailView = m_pwndThumbNailFloat->GetThumbNailView();
  659. if (m_pwndThumbNailView)
  660. {
  661. m_pImgWnd->SetThumbnailView( m_pwndThumbNailView );
  662. m_pwndThumbNailFloat->ShowWindow( SW_SHOWNOACTIVATE );
  663. }
  664. else
  665. {
  666. delete m_pwndThumbNailFloat;
  667. m_pwndThumbNailFloat = NULL;
  668. }
  669. }
  670. if (m_pwndThumbNailView == NULL)
  671. {
  672. theApp.m_bShowThumbnail = FALSE;
  673. theApp.SetMemoryEmergency();
  674. TRACE( TEXT("Create CThumbNailView failed\n") );
  675. return FALSE;
  676. }
  677. m_pwndThumbNailView->ShowWindow( SW_SHOWNOACTIVATE );
  678. m_pwndThumbNailView->UpdateWindow();
  679. UpdateWindow();
  680. return TRUE;
  681. }
  682. /***************************************************************************/
  683. void CPBView::ToggleThumbNailVisibility( void )
  684. {
  685. theApp.m_bShowThumbnail = !IsThumbNailVisible();
  686. if ( theApp.m_bShowThumbnail )
  687. ShowThumbNailView();
  688. else if (m_pwndThumbNailView)
  689. HideThumbNailView();
  690. }
  691. /***************************************************************************/
  692. void CPBView::HideThumbNailView(void)
  693. {
  694. if (IsThumbNailVisible())
  695. {
  696. if (m_pwndThumbNailFloat)
  697. m_pwndThumbNailFloat->ShowWindow( SW_HIDE );
  698. theApp.m_bShowThumbnail = FALSE;
  699. }
  700. }
  701. /***************************************************************************/
  702. void CPBView::ShowThumbNailView(void)
  703. {
  704. if ( theApp.m_bShowThumbnail
  705. && !IsThumbNailVisible() )
  706. {
  707. if ( m_pwndThumbNailView )
  708. {
  709. if (m_pwndThumbNailFloat)
  710. m_pwndThumbNailFloat->ShowWindow( SW_SHOWNOACTIVATE );
  711. }
  712. else
  713. CreateThumbNailView();
  714. }
  715. }
  716. /***************************************************************************/
  717. BOOL CPBView::IsThumbNailVisible(void)
  718. {
  719. BOOL bVisible = FALSE;
  720. if (m_pwndThumbNailFloat != NULL)
  721. bVisible = m_pwndThumbNailFloat->IsWindowVisible();
  722. return bVisible;
  723. }
  724. /***************************************************************************/
  725. CPoint CPBView::GetDockedPos( DOCKERS tool, CSize& sizeTool )
  726. {
  727. CPoint pt;
  728. CRect rectClient;
  729. CRect rectView;
  730. CFrameWnd* pFrame = GetParentFrame();
  731. pFrame->GetClientRect( &rectClient );
  732. pFrame->NegotiateBorderSpace( CFrameWnd::borderGet, &rectView );
  733. switch (tool)
  734. {
  735. case toolbox:
  736. ASSERT(0);
  737. break;
  738. case colorbox:
  739. ASSERT(0);
  740. break;
  741. }
  742. pt = rectView.TopLeft();
  743. pFrame->ClientToScreen( &pt );
  744. return pt;
  745. }
  746. /***************************************************************************/
  747. void CPBView::GetFloatPos( DOCKERS tool, CRect& rectPos )
  748. {
  749. // removed docked thumbnail code
  750. }
  751. /***************************************************************************/
  752. void CPBView::SetFloatPos( DOCKERS tool, CRect& rectPos )
  753. {
  754. //removed docked thumbnail code
  755. }
  756. /***************************************************************************/
  757. void CPBView::OnViewThumbnail()
  758. {
  759. ToggleThumbNailVisibility();
  760. }
  761. /***************************************************************************/
  762. void CPBView::OnUpdateViewThumbnail(CCmdUI* pCmdUI)
  763. {
  764. BOOL bEnable = FALSE;
  765. if (m_pImgWnd != NULL
  766. && m_pImgWnd->GetZoom() > 1)
  767. {
  768. bEnable = TRUE;
  769. }
  770. pCmdUI->Enable( bEnable );
  771. pCmdUI->SetCheck( theApp.m_bShowThumbnail );
  772. }
  773. /***************************************************************************/
  774. void CPBView::OnEditUndo()
  775. {
  776. if (!TextToolProcessed( ID_EDIT_UNDO ))
  777. {
  778. CancelToolMode(FALSE);
  779. CommitSelection(TRUE);
  780. theUndo.DoUndo();
  781. DirtyImg (m_pImgWnd->m_pImg);
  782. }
  783. }
  784. /***************************************************************************/
  785. void CPBView::OnEditRedo()
  786. {
  787. CancelToolMode(FALSE);
  788. theUndo.DoRedo();
  789. DirtyImg (m_pImgWnd->m_pImg);
  790. }
  791. /***************************************************************************/
  792. void CPBView::OnEditCut()
  793. {
  794. m_pImgWnd->CmdCut();
  795. }
  796. /***************************************************************************/
  797. void CPBView::OnEditClear()
  798. {
  799. m_pImgWnd->CmdClear();
  800. }
  801. /***************************************************************************/
  802. void CPBView::OnEditCopy()
  803. {
  804. m_pImgWnd->CmdCopy();
  805. }
  806. /***************************************************************************/
  807. void CPBView::OnEditPaste()
  808. {
  809. m_pImgWnd->CmdPaste();
  810. }
  811. /***************************************************************************/
  812. void CPBView::OnUpdateEditUndo(CCmdUI* pCmdUI)
  813. {
  814. // the text tool has no idea if it can undo and neither do we
  815. pCmdUI->Enable(IsUserEditingText() || theUndo.CanUndo());
  816. }
  817. /***************************************************************************/
  818. void CPBView::OnUpdateEditRedo(CCmdUI* pCmdUI)
  819. {
  820. // the text tool does not have a redo stack
  821. pCmdUI->Enable(!IsUserEditingText() && theUndo.CanRedo());
  822. }
  823. /***************************************************************************/
  824. void CPBView::OnUpdateEditSelection(CCmdUI* pCmdUI)
  825. {
  826. BOOL bEnable = FALSE;
  827. if (m_pImgWnd != NULL)
  828. {
  829. bEnable = m_pImgWnd->IsSelectionAvailable();
  830. }
  831. pCmdUI->Enable( bEnable );
  832. }
  833. /***************************************************************************/
  834. void CPBView::OnUpdateEditClearSel(CCmdUI* pCmdUI)
  835. {
  836. BOOL bEnable = FALSE;
  837. if (m_pImgWnd != NULL)
  838. bEnable = m_pImgWnd->IsSelectionAvailable();
  839. pCmdUI->Enable( bEnable );
  840. }
  841. /***************************************************************************/
  842. void CPBView::OnUpdateEditPaste(CCmdUI* pCmdUI)
  843. {
  844. BOOL bEnable = FALSE;
  845. if (m_pImgWnd != NULL)
  846. {
  847. bEnable = m_pImgWnd->IsPasteAvailable();
  848. }
  849. pCmdUI->Enable( bEnable );
  850. }
  851. /***************************************************************************/
  852. void CPBView::OnViewGrid()
  853. {
  854. m_pImgWnd->CmdShowGrid();
  855. }
  856. /***************************************************************************/
  857. void CPBView::OnViewZoom100()
  858. {
  859. if (m_pImgWnd->GetZoom() != 1)
  860. {
  861. m_pImgWnd->SetZoom ( 1 );
  862. m_pImgWnd->CheckScrollBars();
  863. }
  864. }
  865. /***************************************************************************/
  866. void CPBView::OnViewZoom400()
  867. {
  868. if (m_pImgWnd->GetZoom() != 4)
  869. {
  870. m_pImgWnd->SetZoom ( 4 );
  871. m_pImgWnd->CheckScrollBars();
  872. }
  873. }
  874. /***************************************************************************/
  875. void CPBView::OnViewZoom()
  876. {
  877. CZoomViewDlg dlg;
  878. dlg.m_nCurrent = m_pImgWnd->GetZoom();
  879. if (dlg.DoModal() != IDOK)
  880. return;
  881. m_pImgWnd->SetZoom( dlg.m_nCurrent );
  882. m_pImgWnd->CheckScrollBars();
  883. }
  884. /***************************************************************************/
  885. void CPBView::OnUpdateViewZoom100(CCmdUI* pCmdUI)
  886. {
  887. BOOL bEnable = FALSE;
  888. if (m_pImgWnd)
  889. bEnable = (m_pImgWnd->GetZoom() != 1);
  890. pCmdUI->Enable( bEnable );
  891. }
  892. /***************************************************************************/
  893. void CPBView::OnUpdateViewZoom400(CCmdUI* pCmdUI)
  894. {
  895. BOOL bEnable = FALSE;
  896. if (m_pImgWnd)
  897. bEnable = (m_pImgWnd->GetZoom() != 4);
  898. pCmdUI->Enable( bEnable );
  899. }
  900. /***************************************************************************/
  901. void CPBView::OnUpdateViewGrid(CCmdUI* pCmdUI)
  902. {
  903. BOOL bCheck = FALSE;
  904. BOOL bEnable = FALSE;
  905. if (m_pImgWnd)
  906. {
  907. bEnable = (m_pImgWnd->GetZoom() > 2);
  908. bCheck = m_pImgWnd->IsGridVisible();
  909. }
  910. pCmdUI->Enable ( bEnable );
  911. pCmdUI->SetCheck( bCheck );
  912. }
  913. /***************************************************************************/
  914. void CPBView::OnImageInvertColors()
  915. {
  916. CancelToolMode(TRUE);
  917. m_pImgWnd->CmdInvertColors();
  918. }
  919. /***************************************************************************/
  920. // Don't show the Invert Colors menu item if we're using a palette
  921. void CPBView::OnUpdateImageInvertColors(CCmdUI* pCmdUI)
  922. {
  923. BOOL bEnable = FALSE;
  924. if (m_pImgWnd)
  925. {
  926. bEnable = (!theApp.m_bPaletted);
  927. }
  928. pCmdUI->Enable ( bEnable );
  929. }
  930. /***************************************************************************/
  931. void CPBView::OnTglopaque()
  932. {
  933. m_pImgWnd->CmdTglOpaque();
  934. }
  935. /***************************************************************************/
  936. void CPBView::OnUpdateTglopaque(CCmdUI* pCmdUI)
  937. {
  938. pCmdUI->Enable( m_pImgWnd != NULL );
  939. pCmdUI->SetCheck( theImgBrush.m_bOpaque );
  940. }
  941. /***************************************************************************/
  942. void CPBView::OnImageAttributes()
  943. {
  944. CancelToolMode(FALSE);
  945. CPBDoc* pDoc = GetDocument();
  946. ASSERT( pDoc );
  947. ASSERT( m_pImgWnd );
  948. CBitmapObj* pBitmapRes = pDoc->m_pBitmapObj;
  949. CImageAttr dlg;
  950. BOOL bMono = (pBitmapRes->m_pImg->cPlanes == 1
  951. && pBitmapRes->m_pImg->cBitCount == 1);
  952. dlg.m_bMonochrome = bMono;
  953. dlg.SetWidthHeight( pBitmapRes->m_pImg->cxWidth,
  954. pBitmapRes->m_pImg->cyHeight,
  955. pBitmapRes->m_pImg->cXPelsPerMeter,
  956. pBitmapRes->m_pImg->cYPelsPerMeter);
  957. if (dlg.DoModal() != IDOK)
  958. return;
  959. CSize size = dlg.GetWidthHeight();
  960. if (size.cx != pBitmapRes->m_pImg->cxWidth
  961. || size.cy != pBitmapRes->m_pImg->cyHeight)
  962. {
  963. theUndo.BeginUndo( TEXT("Property Edit") );
  964. BOOL bSuccess = pBitmapRes->SetSizeProp( P_Size, size );
  965. theUndo.EndUndo();
  966. if (bSuccess)
  967. theApp.m_sizeBitmap = size;
  968. }
  969. if (dlg.m_bMonochrome != bMono
  970. && (!dlg.m_bMonochrome
  971. || AfxMessageBox(IDS_WARNING_MONO, MB_YESNO|MB_ICONEXCLAMATION)==IDYES))
  972. {
  973. theUndo.BeginUndo( TEXT("Property Edit") );
  974. pBitmapRes->SetIntProp( P_Colors, dlg.m_bMonochrome );
  975. theUndo.EndUndo();
  976. }
  977. }
  978. /***************************************************************************/
  979. void CPBView::OnImageClearImage()
  980. {
  981. CancelToolMode(FALSE);
  982. m_pImgWnd->CmdClear();
  983. }
  984. /***************************************************************************/
  985. void CPBView::OnFilePrint()
  986. {
  987. CancelToolMode(FALSE);
  988. CView::OnFilePrint();
  989. }
  990. /***************************************************************************/
  991. void CPBView::OnFilePrintPreview()
  992. {
  993. CancelToolMode(FALSE);
  994. CView::OnFilePrintPreview();
  995. }
  996. /***************************************************************************/
  997. void CPBView::OnUpdateImageClearImage( CCmdUI* pCmdUI )
  998. {
  999. BOOL bEnable = FALSE;
  1000. if (m_pImgWnd)
  1001. bEnable = (CImgTool::GetCurrentID() != IDMX_TEXTTOOL
  1002. && ! m_pImgWnd->IsSelectionAvailable() );
  1003. pCmdUI->Enable( bEnable );
  1004. }
  1005. /***************************************************************************/
  1006. void CPBView::OnSel2bsh()
  1007. {
  1008. m_pImgWnd->CmdSel2Bsh();
  1009. }
  1010. /***************************************************************************/
  1011. void CPBView::OnLargerbrush()
  1012. {
  1013. m_pImgWnd->CmdLargerBrush();
  1014. }
  1015. /***************************************************************************/
  1016. void CPBView::OnSmallerbrush()
  1017. {
  1018. m_pImgWnd->CmdSmallerBrush();
  1019. }
  1020. /***************************************************************************/
  1021. void CPBView::OnImageFlipRotate()
  1022. {
  1023. CancelToolMode(TRUE);
  1024. CFlipRotateDlg dlg;
  1025. if (dlg.DoModal() != IDOK)
  1026. return;
  1027. if (dlg.m_bAngle)
  1028. {
  1029. switch (dlg.m_nAngle)
  1030. {
  1031. case 90:
  1032. m_pImgWnd->CmdRot90();
  1033. break;
  1034. case 180:
  1035. theUndo.BeginUndo( TEXT("Rotate 180") );
  1036. m_pImgWnd->CmdFlipBshH();
  1037. m_pImgWnd->CmdFlipBshV();
  1038. theUndo.EndUndo();
  1039. break;
  1040. case 270:
  1041. theUndo.BeginUndo( TEXT("Rotate 270") );
  1042. m_pImgWnd->CmdRot90();
  1043. m_pImgWnd->CmdFlipBshH();
  1044. m_pImgWnd->CmdFlipBshV();
  1045. theUndo.EndUndo();
  1046. break;
  1047. }
  1048. }
  1049. else
  1050. if (dlg.m_bHorz)
  1051. m_pImgWnd->CmdFlipBshH();
  1052. else
  1053. m_pImgWnd->CmdFlipBshV();
  1054. }
  1055. /***************************************************************************/
  1056. void CPBView::OnUpdateImageFlipRotate(CCmdUI* pCmdUI)
  1057. {
  1058. pCmdUI->Enable( m_pImgWnd != NULL );
  1059. }
  1060. /***************************************************************************/
  1061. void CPBView::OnEditcolors()
  1062. {
  1063. g_pColors->CmdEditColor();
  1064. }
  1065. /***************************************************************************/
  1066. void CPBView::OnUpdateEditcolors(CCmdUI* pCmdUI)
  1067. {
  1068. pCmdUI->Enable( g_pColors != NULL );
  1069. }
  1070. /***************************************************************************/
  1071. #if 0
  1072. void CPBView::OnLoadcolors()
  1073. {
  1074. CancelToolMode(FALSE);
  1075. g_pColors->CmdLoadColors();
  1076. }
  1077. /***************************************************************************/
  1078. void CPBView::OnUpdateLoadcolors(CCmdUI* pCmdUI)
  1079. {
  1080. BOOL bEnable = FALSE;
  1081. if (g_pColors && m_pImgWnd && m_pImgWnd->m_pImg &&
  1082. m_pImgWnd->m_pImg->m_pBitmapObj)
  1083. {
  1084. // not allowed except on 24 bit images
  1085. bEnable = ( m_pImgWnd->m_pImg->m_pBitmapObj->m_nColors == 3 );
  1086. }
  1087. pCmdUI->Enable( bEnable );
  1088. }
  1089. /***************************************************************************/
  1090. void CPBView::OnSavecolors()
  1091. {
  1092. g_pColors->CmdSaveColors();
  1093. }
  1094. /***************************************************************************/
  1095. void CPBView::OnUpdateSavecolors(CCmdUI* pCmdUI)
  1096. {
  1097. pCmdUI->Enable( g_pColors != NULL );
  1098. }
  1099. /***************************************************************************/
  1100. #endif
  1101. void CPBView::OnEditSelectAll()
  1102. {
  1103. if (m_pImgWnd)
  1104. {
  1105. if (!TextToolProcessed( ID_EDIT_SELECT_ALL ))
  1106. {
  1107. IMG *img = m_pImgWnd? m_pImgWnd->GetImg() : NULL;
  1108. if (img)
  1109. {
  1110. CImgTool::Select(IDMB_PICKTOOL);
  1111. m_pImgWnd->MakeBrush( img->hDC,
  1112. CRect( 0, 0, img->cxWidth, img->cyHeight ) );
  1113. }
  1114. }
  1115. }
  1116. }
  1117. /***************************************************************************/
  1118. void CPBView::OnEditPasteFrom()
  1119. {
  1120. CBitmapObj *pResObject = new CBitmapObj();
  1121. ASSERT(pResObject != NULL);
  1122. if (pResObject != NULL)
  1123. {
  1124. ASSERT( m_pImgWnd != NULL );
  1125. pResObject->MakeEmpty();
  1126. CString newName;
  1127. int iColor = 0;
  1128. if (theApp.DoPromptFileName( newName, IDS_EDIT_PASTE_FROM,
  1129. OFN_PATHMUSTEXIST, TRUE, iColor, FALSE ))
  1130. {
  1131. if (pResObject->Import( newName ))
  1132. {
  1133. LPSTR lpDib = (LPSTR) GlobalLock(pResObject->m_hThing);
  1134. m_pImgWnd->PasteImageFile( lpDib );
  1135. GlobalUnlock(pResObject->m_hThing);
  1136. }
  1137. }
  1138. pResObject->m_pImg = NULL;
  1139. delete pResObject;
  1140. pResObject = NULL;
  1141. }
  1142. }
  1143. /***************************************************************************/
  1144. BOOL FillBitmapObj(CImgWnd* pImgWnd, CBitmapObj* pResObject, IMG* pImgStruct,
  1145. int iColor)
  1146. {
  1147. ASSERT(pImgWnd != NULL);
  1148. pResObject->MakeEmpty();
  1149. if (pImgWnd->m_pImg == NULL
  1150. || pImgWnd->m_pImg->m_pBitmapObj == NULL
  1151. || pImgWnd->m_pImg->m_pBitmapObj->m_pImg == NULL)
  1152. {
  1153. return(FALSE);
  1154. }
  1155. if (iColor < 0)
  1156. {
  1157. iColor = pImgWnd->m_pImg->m_pBitmapObj->m_nColors;
  1158. }
  1159. if (theImgBrush.m_bFirstDrag)
  1160. {
  1161. PickupSelection();
  1162. }
  1163. *pImgStruct = *theImgBrush.m_pImg;
  1164. pImgStruct->hDC = theImgBrush.m_dc.GetSafeHdc();
  1165. pImgStruct->hBitmap = (HBITMAP)theImgBrush.m_bitmap.GetSafeHandle();
  1166. pImgStruct->hBitmapOld = theImgBrush.m_hbmOld;
  1167. pImgStruct->bDirty = TRUE;
  1168. pImgStruct->m_pPalette = theApp.m_pPalette;
  1169. pImgStruct->cxWidth = theImgBrush.m_size.cx;
  1170. pImgStruct->cyHeight = theImgBrush.m_size.cy;
  1171. if (iColor < 4 && iColor >= 0)
  1172. {
  1173. pResObject->m_nSaveColors = iColor;
  1174. }
  1175. #ifdef PCX_SUPPORT
  1176. pResObject->m_bPCX = (iColor == 4);
  1177. #endif
  1178. #ifdef ICO_SUPPORT
  1179. pResObject->m_bSaveIcon = (iColor == 5);
  1180. #endif
  1181. pResObject->m_nWidth = pImgStruct->cxWidth;
  1182. pResObject->m_nHeight = pImgStruct->cyHeight;
  1183. pResObject->m_nColors = pImgWnd->m_pImg->m_pBitmapObj->m_nColors;
  1184. pResObject->m_bCompressed = pImgWnd->m_pImg->m_pBitmapObj->m_bCompressed;
  1185. pResObject->m_pImg = pImgStruct;
  1186. return(TRUE);
  1187. }
  1188. void CPBView::OnEditCopyTo()
  1189. {
  1190. CString newName;
  1191. int iColor = m_pImgWnd->m_pImg->m_pBitmapObj->m_nColors;
  1192. if (theApp.DoPromptFileName( newName, IDS_EDIT_COPY_TO,
  1193. OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, iColor, TRUE ))
  1194. {
  1195. BeginWaitCursor();
  1196. CBitmapObj cResObject;
  1197. IMG imgStruct;
  1198. if (!FillBitmapObj(m_pImgWnd, &cResObject, &imgStruct, iColor))
  1199. {
  1200. // FEATURE: Need an error message
  1201. // Actually, can this ever happen?
  1202. return;
  1203. }
  1204. cResObject.SaveResource( FALSE );
  1205. cResObject.Export( newName );
  1206. EndWaitCursor();
  1207. // Don't delete this on destructor
  1208. cResObject.m_pImg = NULL;
  1209. }
  1210. }
  1211. /***************************************************************************/
  1212. void CPBView::OnUpdateEditCopyTo(CCmdUI* pCmdUI)
  1213. {
  1214. BOOL bEnable = FALSE;
  1215. if (CImgTool::GetCurrentID() == IDMB_PICKTOOL
  1216. || CImgTool::GetCurrentID() == IDMB_PICKRGNTOOL)
  1217. {
  1218. ASSERT( m_pImgWnd != NULL );
  1219. if (m_pImgWnd != NULL)
  1220. {
  1221. if (m_pImgWnd->m_pImg != NULL)
  1222. {
  1223. if (m_pImgWnd->m_pImg == theImgBrush.m_pImg)
  1224. {
  1225. bEnable = TRUE;
  1226. }
  1227. }
  1228. }
  1229. }
  1230. pCmdUI->Enable( bEnable );
  1231. }
  1232. /***************************************************************************/
  1233. void CPBView::OnImageStretchSkew()
  1234. {
  1235. CancelToolMode(TRUE);
  1236. CStretchSkewDlg dlg;
  1237. if (dlg.DoModal() != IDOK)
  1238. return;
  1239. int iStretchHorz = dlg.GetStretchHorz();
  1240. int iStretchVert = dlg.GetStretchVert();
  1241. if (iStretchVert
  1242. || iStretchHorz)
  1243. {
  1244. CPBDoc* pDoc = GetDocument();
  1245. ASSERT( pDoc );
  1246. int iWidthImg = pDoc->m_pBitmapObj->m_pImg->cxWidth;
  1247. int iHeightImg = pDoc->m_pBitmapObj->m_pImg->cyHeight;
  1248. if (theImgBrush.m_pImg == NULL)
  1249. {
  1250. int lX = iWidthImg + (iWidthImg * iStretchHorz) / 100;
  1251. int lY = iHeightImg + (iHeightImg * iStretchVert) / 100;
  1252. CBitmap bmWork;
  1253. CDC dcWork;
  1254. CDC* pdcImg = CDC::FromHandle( pDoc->m_pBitmapObj->m_pImg->hDC );
  1255. CSize sizeBMP( (UINT)lX, (UINT)lY );
  1256. CRect rect( 0, 0, lX, lY );
  1257. if (! dcWork.CreateCompatibleDC ( pdcImg )
  1258. || ! bmWork.CreateCompatibleBitmap( pdcImg, iWidthImg, iHeightImg ))
  1259. {
  1260. theApp.SetGdiEmergency( TRUE );
  1261. return;
  1262. }
  1263. CBitmap* pbmOld = dcWork.SelectObject( &bmWork );
  1264. CPalette* ppalOld = m_pImgWnd->SetImgPalette( &dcWork, FALSE );
  1265. BeginWaitCursor();
  1266. dcWork.BitBlt( 0, 0, iWidthImg, iHeightImg, pdcImg, 0, 0, SRCCOPY );
  1267. theUndo.BeginUndo( TEXT("Property Edit") );
  1268. pDoc->m_pBitmapObj->SetSizeProp( P_Size, sizeBMP );
  1269. StretchCopy( pdcImg->m_hDC, 0, 0, lX, lY,
  1270. dcWork.m_hDC, 0, 0, iWidthImg, iHeightImg );
  1271. InvalImgRect ( m_pImgWnd->m_pImg, NULL );
  1272. CommitImgRect( m_pImgWnd->m_pImg, NULL );
  1273. theUndo.EndUndo();
  1274. DirtyImg(m_pImgWnd->m_pImg);
  1275. dcWork.SelectObject( pbmOld );
  1276. bmWork.DeleteObject();
  1277. if (ppalOld)
  1278. dcWork.SelectPalette( ppalOld, FALSE );
  1279. dcWork.DeleteDC();
  1280. theApp.m_sizeBitmap = sizeBMP;
  1281. EndWaitCursor();
  1282. }
  1283. else
  1284. {
  1285. CRect rect = theImgBrush.m_rcSelection;
  1286. long lX = theImgBrush.m_size.cx;
  1287. long lY = theImgBrush.m_size.cy;
  1288. lX += (lX * iStretchHorz) / 100;
  1289. lY += (lY * iStretchVert) / 100;
  1290. rect.right = rect.left + (UINT)lX;
  1291. rect.bottom = rect.top + (UINT)lY;
  1292. // If the image is a bitmap and the bitmap in the clipboard is larger,
  1293. // then give the suer the option2 of growing the image...
  1294. // if (lX > iWidthImg || lY > iHeightImg)
  1295. // {
  1296. // switch (AfxMessageBox( IDS_ENLAGEBITMAPFORSTRETCH,
  1297. // MB_YESNOCANCEL | MB_ICONQUESTION ))
  1298. // {
  1299. // default:
  1300. // return;
  1301. // break;
  1302. // case IDYES:
  1303. // {
  1304. // CSize size( max( lX, iWidthImg ),
  1305. // max( lY, iHeightImg ) );
  1306. // theUndo.BeginUndo( "Resize Bitmap" );
  1307. // VERIFY( pDoc->m_pBitmapObj->SetSizeProp( P_Size, size ) );
  1308. // theUndo.EndUndo();
  1309. // }
  1310. // break;
  1311. // case IDNO:
  1312. // break;
  1313. // }
  1314. // }
  1315. m_pImgWnd->PrepareForBrushChange();
  1316. HideBrush();
  1317. theImgBrush.SetSize( CSize( (UINT)lX, (UINT)lY ) );
  1318. SetCombineMode( combineColor );
  1319. InvalImgRect( theImgBrush.m_pImg, NULL ); // draw selection tracker
  1320. m_pImgWnd->MoveBrush( rect );
  1321. }
  1322. }
  1323. int wSkewHorz = (int)dlg.GetSkewHorz();
  1324. int wSkewVert = (int)dlg.GetSkewVert();
  1325. if (wSkewHorz)
  1326. m_pImgWnd->CmdSkewBrush( wSkewHorz, TRUE );
  1327. if (wSkewVert)
  1328. m_pImgWnd->CmdSkewBrush( wSkewVert, FALSE );
  1329. }
  1330. /***************************************************************************/
  1331. void CPBView::OnUpdateImageStretchSkew(CCmdUI* pCmdUI)
  1332. {
  1333. pCmdUI->Enable( m_pImgWnd != NULL );
  1334. }
  1335. /***************************************************************************/
  1336. void CPBView::OnViewViewPicture()
  1337. {
  1338. CPBDoc *pDoc;
  1339. CString strCaption;
  1340. ASSERT(! theApp.m_bEmbedded);
  1341. pDoc = GetDocument();
  1342. CFullScreenThumbNailView *pcThumbNailView = new CFullScreenThumbNailView( m_pImgWnd );
  1343. if ( pcThumbNailView == NULL
  1344. || ! pcThumbNailView->Create((LPCTSTR)pDoc->GetPathName()))
  1345. {
  1346. theApp.SetMemoryEmergency();
  1347. TRACE( TEXT("Create CThumbNailView faild\n") );
  1348. }
  1349. }
  1350. /***************************************************************************/
  1351. void CPBView::OnUpdateViewViewPicture(CCmdUI* pCmdUI)
  1352. {
  1353. pCmdUI->Enable( m_pImgWnd != NULL );
  1354. }
  1355. /***************************************************************************/
  1356. void CPBView::OnViewTextToolbar()
  1357. {
  1358. ASSERT( CImgTool::GetCurrentID() == IDMX_TEXTTOOL );
  1359. CTextTool* pTextTool = (CTextTool*)CImgTool::GetCurrent();
  1360. ASSERT( pTextTool->IsKindOf( RUNTIME_CLASS( CTextTool ) ) );
  1361. pTextTool->ToggleFontPalette();
  1362. }
  1363. /***************************************************************************/
  1364. void CPBView::OnUpdateViewTextToolbar(CCmdUI* pCmdUI)
  1365. {
  1366. BOOL bEnable = FALSE;
  1367. if (CImgTool::GetCurrentID() == IDMX_TEXTTOOL)
  1368. {
  1369. CTextTool* pTextTool = (CTextTool*)CImgTool::GetCurrent();
  1370. ASSERT( pTextTool );
  1371. ASSERT( pTextTool->IsKindOf( RUNTIME_CLASS( CTextTool ) ) );
  1372. if (pTextTool
  1373. && pTextTool->IsSlectionVisible())
  1374. bEnable = TRUE;
  1375. }
  1376. pCmdUI->SetCheck( theApp.m_bShowTextToolbar );
  1377. pCmdUI->Enable ( bEnable );
  1378. }
  1379. /***************************************************************************/
  1380. void CPBView::OnFileSetaswallpaperT()
  1381. {
  1382. SetTheWallpaper( TRUE );
  1383. }
  1384. /***************************************************************************/
  1385. void CPBView::OnUpdateFileSetaswallpaperT( CCmdUI* pCmdUI )
  1386. {
  1387. pCmdUI->Enable( CanSetWallpaper() );
  1388. }
  1389. /***************************************************************************/
  1390. void CPBView::OnFileSetaswallpaperC()
  1391. {
  1392. SetTheWallpaper( FALSE );
  1393. }
  1394. /***************************************************************************/
  1395. void CPBView::OnUpdateFileSetaswallpaperC(CCmdUI* pCmdUI)
  1396. {
  1397. pCmdUI->Enable( CanSetWallpaper() );
  1398. }
  1399. /***************************************************************************/
  1400. BOOL CPBView::CanSetWallpaper()
  1401. {
  1402. BOOL bEnable = FALSE;
  1403. if (m_pImgWnd != NULL)
  1404. {
  1405. CPBDoc* pDoc = GetDocument();
  1406. ASSERT( pDoc );
  1407. bEnable = (! pDoc->GetPathName().IsEmpty() || pDoc->IsModified());
  1408. // read the user policy key to see whether we should disable wallpaper setting
  1409. if (bEnable)
  1410. {
  1411. HKEY hKey = 0;
  1412. if (RegOpenKeyEx( HKEY_CURRENT_USER, REGSTR_PATH_POLICIES _T("\\ActiveDesktop"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
  1413. {
  1414. BOOL bNoChangingWallpaper = FALSE;
  1415. DWORD cbData = sizeof(bNoChangingWallpaper);
  1416. if (RegQueryValueEx(hKey, _T("NoChangingWallpaper"), 0, 0, (PBYTE) &bNoChangingWallpaper, &cbData) == ERROR_SUCCESS)
  1417. {
  1418. bEnable = !bNoChangingWallpaper;
  1419. }
  1420. RegCloseKey(hKey);
  1421. }
  1422. }
  1423. }
  1424. return bEnable;
  1425. }
  1426. /***************************************************************************/
  1427. void CPBView::SetTheWallpaper( BOOL bTiled /* = FALSE */ )
  1428. {
  1429. CPBDoc* pDoc = GetDocument();
  1430. ASSERT( pDoc != NULL );
  1431. CString cStrFileName = pDoc->GetPathName();
  1432. BOOL bSetWallpaper = ! (cStrFileName.IsEmpty() || pDoc->IsModified() || pDoc->m_bNonBitmapFile);
  1433. if (! bSetWallpaper)
  1434. switch (AfxMessageBox( IDS_MUST_SAVE_WALLPAPER, MB_OKCANCEL | MB_ICONEXCLAMATION ))
  1435. {
  1436. case IDOK:
  1437. // If so, either Save or Update, as appropriate
  1438. bSetWallpaper = pDoc->SaveTheDocument();
  1439. cStrFileName = pDoc->GetPathName();
  1440. break;
  1441. case IDCANCEL:
  1442. break;
  1443. default:
  1444. theApp.SetMemoryEmergency();
  1445. break;
  1446. }
  1447. if (bSetWallpaper)
  1448. {
  1449. DWORD dwDisp;
  1450. HKEY hKey = 0;
  1451. if (RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"),
  1452. REG_OPTION_RESERVED, TEXT(""),
  1453. REG_OPTION_NON_VOLATILE,
  1454. KEY_ALL_ACCESS, NULL, &hKey, &dwDisp ) == ERROR_SUCCESS)
  1455. {
  1456. RegSetValueEx( hKey, TEXT("TileWallpaper"), 0, REG_SZ,
  1457. (BYTE *)(bTiled? TEXT("1"): TEXT("0")), 2*sizeof(TCHAR) );
  1458. RegCloseKey( hKey );
  1459. }
  1460. SystemParametersInfo( SPI_SETDESKWALLPAPER, bTiled? 1: 0,
  1461. (LPVOID)(cStrFileName.GetBuffer( cStrFileName.GetLength() )),
  1462. SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );
  1463. cStrFileName.ReleaseBuffer();
  1464. }
  1465. }
  1466. /***************************************************************************/
  1467. void CPBView::OnPaletteChanged(CWnd* pFocusWnd)
  1468. {
  1469. // If this application did not change the palette, select
  1470. // and realize this application's palette
  1471. if ((pFocusWnd != m_pImgWnd)
  1472. && (m_pImgWnd != NULL)
  1473. && (m_pImgWnd->m_pImg != NULL))
  1474. {
  1475. if (theApp.m_pPalette)
  1476. {
  1477. // Redraw the entire client area
  1478. m_pImgWnd->InvalidateRect(NULL);
  1479. m_pImgWnd->UpdateWindow();
  1480. if (g_pImgColorsWnd && g_pImgColorsWnd->m_hWnd && IsWindow(g_pImgColorsWnd->m_hWnd))
  1481. {
  1482. InvalColorWnd();
  1483. // g_pImgColorsWnd->UpdateWindow();
  1484. }
  1485. }
  1486. }
  1487. }
  1488. /***************************************************************************/
  1489. BOOL CPBView::OnQueryNewPalette()
  1490. {
  1491. HPALETTE hOldPal = NULL;
  1492. if (m_pImgWnd && ::IsWindow(m_pImgWnd->m_hWnd)
  1493. && m_pImgWnd->m_pImg)
  1494. {
  1495. if (theApp.m_pPalette)
  1496. {
  1497. // Redraw the entire client area
  1498. m_pImgWnd->InvalidateRect(NULL);
  1499. m_pImgWnd->UpdateWindow();
  1500. if (g_pImgColorsWnd && g_pImgColorsWnd->m_hWnd && IsWindow(g_pImgColorsWnd->m_hWnd))
  1501. {
  1502. InvalColorWnd();
  1503. g_pImgColorsWnd->UpdateWindow();
  1504. }
  1505. }
  1506. }
  1507. return TRUE;
  1508. }
  1509. /***************************************************************************/
  1510. void CPBView::OnUpdateImageAttributes( CCmdUI* pCmdUI )
  1511. {
  1512. BOOL bEnable = (m_pImgWnd != NULL);
  1513. pCmdUI->Enable( bEnable );
  1514. }
  1515. /***************************************************************************/
  1516. void CPBView::OnEscape()
  1517. {
  1518. if (m_pImgWnd != NULL)
  1519. {
  1520. m_pImgWnd->CmdCancel();
  1521. }
  1522. OnCancelMode();
  1523. }
  1524. /***************************************************************************/
  1525. void CPBView::OnEscapeServer()
  1526. {
  1527. CImgTool* pImgTool = CImgTool::GetCurrent();
  1528. if (pImgTool->IsToolModal())
  1529. {
  1530. OnEscape();
  1531. return;
  1532. }
  1533. else
  1534. {
  1535. // Tell the OLE client (if there is one) we are all done
  1536. GetDocument()->OnDeactivateUI(FALSE);
  1537. }
  1538. }
  1539. /***************************************************************************/