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.

264 lines
8.0 KiB

  1. #ifndef __IMGWND_H__
  2. #define __IMGWND_H__
  3. #include "tracker.h"
  4. // #define GRIDOPTIONS
  5. class CBitmapObj;
  6. // helper fns
  7. BOOL IsUserEditingText();
  8. BOOL TextToolProcessed( UINT nMessage );
  9. // Mouse Tracking Information
  10. typedef struct _mti
  11. {
  12. CPoint ptDown;
  13. CPoint ptPrev;
  14. CPoint pt;
  15. BOOL fLeft;
  16. BOOL fRight;
  17. BOOL fCtrlDown;
  18. } MTI;
  19. class CImgWnd;
  20. class CThumbNailView;
  21. // Image
  22. struct IMG
  23. {
  24. class CImgWnd* m_pFirstImgWnd;
  25. CBitmapObj* m_pBitmapObj;
  26. BOOL bDirty;
  27. HDC hDC;
  28. HDC hMaskDC; // May be NULL (for normal bitmaps)
  29. // These are usually selected into hDC and hMaskDC respecively
  30. HBITMAP hBitmap;
  31. HBITMAP hBitmapOld;
  32. HBITMAP hMaskBitmap;
  33. HBITMAP hMaskBitmapOld;
  34. CPalette* m_pPalette;
  35. HPALETTE m_hPalOld;
  36. int cxWidth;
  37. int cyHeight;
  38. int cPlanes;
  39. int cBitCount;
  40. int cXPelsPerMeter;
  41. int cYPelsPerMeter;
  42. int nResType;
  43. int m_nLastChanged;
  44. BOOL m_bTileGrid;
  45. int m_cxTile;
  46. int m_cyTile;
  47. };
  48. // Image Editor Window
  49. class CImgWnd : public CWnd
  50. {
  51. protected:
  52. static CImgWnd* c_pImgWndCur;
  53. static CDragger* c_pResizeDragger;
  54. static CTracker::STATE c_dragState;
  55. DECLARE_DYNAMIC( CImgWnd )
  56. public:
  57. CImgWnd( IMG* pImg );
  58. CImgWnd( CImgWnd *pImgWnd );
  59. ~CImgWnd();
  60. BOOL Create( DWORD dwStyle, const RECT& rect,
  61. CWnd* pParentWnd, UINT nID = 0 );
  62. BOOL OnCmdMsg( UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo );
  63. void ClientToImage(CPoint& point );
  64. void ClientToImage(CRect& rect );
  65. void ImageToClient(CPoint& point );
  66. void ImageToClient(CRect& rect );
  67. IMG* m_pImg;
  68. inline IMG* GetImg() { return m_pImg; }
  69. void SetImg( IMG* pImg );
  70. inline CSize GetScrollPos() { return CSize( m_xScroll, m_yScroll ); }
  71. void SetScroll( int xScroll, int yScroll );
  72. void ShowBrush( CPoint ptHandle );
  73. void PrepareForBrushChange( BOOL bPickup = TRUE, BOOL bErase = TRUE );
  74. inline int GetZoom() { return m_nZoom; }
  75. inline int GetPrevZoom() const { return m_nZoomPrev; }
  76. void SetZoom( int nZoom );
  77. BOOL MakeBrush( HDC hSourceDC, CRect rcSource );
  78. void UpdPos(const CPoint& pt) { m_ptDispPos = pt; }
  79. inline BOOL IsGridVisible() { return theApp.m_bShowGrid && m_nZoom > 3; }
  80. void FinishUndo( const CRect& rect );
  81. void RubberBandRect( HDC hDC, MTI* pmti, BOOL bErase );
  82. void EraseTracker();
  83. void CheckScrollBars();
  84. void GetImageRect( CRect& rect );
  85. CPalette* SetImgPalette( CDC* pdc, BOOL bForce = FALSE );
  86. HPALETTE SetImgPalette( HDC hdc, BOOL bForce = FALSE );
  87. CPalette* FixupDibPalette( LPSTR lpDib, CPalette* ppalDib );
  88. BOOL IsSelectionAvailable( void );
  89. BOOL IsPasteAvailable( void );
  90. CRect GetDrawingRect( void );
  91. static void SetToolCursor();
  92. static inline CImgWnd* GetCurrent() { return c_pImgWndCur; }
  93. BOOL PtInTracker(CPoint cptLocation);
  94. protected:
  95. void RubberMouse (unsigned code, MTI* pmti);
  96. void OnRButtonDownInSel (CPoint *pcPointDown);
  97. void ZoomedInDP ( unsigned code, unsigned mouseKeys, CPoint newPt );
  98. void StartSelectionDrag ( unsigned code, CPoint newPt );
  99. void CancelSelectionDrag ();
  100. void SelectionDragHandler( unsigned code, CPoint newPt );
  101. void ResizeMouseHandler ( unsigned code, CPoint newPt );
  102. void EndResizeOperation ();
  103. void MoveBrush ( const CRect& newSelRect );
  104. void OnScroll ( BOOL bVert, UINT nSBCode, UINT nPos );
  105. BOOL OnMouseDown ( UINT nFlags );
  106. BOOL OnMouseMessage ( UINT nFlags );
  107. void CancelPainting ();
  108. afx_msg int OnCreate ( LPCREATESTRUCT lpCreateStruct );
  109. #if 0
  110. afx_msg void OnDestroy ();
  111. #endif
  112. afx_msg void OnSetFocus ( CWnd* pOldWnd );
  113. afx_msg void OnKillFocus ( CWnd* pNewWnd );
  114. afx_msg void OnSize ( UINT nType, int cx, int cy );
  115. afx_msg void OnLButtonDown ( UINT nFlags, CPoint point );
  116. afx_msg void OnLButtonDblClk( UINT nFlags, CPoint point );
  117. afx_msg void OnLButtonUp ( UINT nFlags, CPoint point );
  118. afx_msg void OnRButtonDown ( UINT nFlags, CPoint point );
  119. afx_msg void OnRButtonDblClk( UINT nFlags, CPoint point );
  120. afx_msg void OnRButtonUp ( UINT nFlags, CPoint point );
  121. afx_msg void OnKeyDown ( UINT nChar, UINT nRepCnt, UINT nFlags );
  122. afx_msg void OnKeyUp ( UINT nChar, UINT nRepCnt, UINT nFlags );
  123. afx_msg void OnMouseMove ( UINT nFlags, CPoint point );
  124. afx_msg void OnTimer ( UINT nIDEvent );
  125. afx_msg void OnVScroll ( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar );
  126. afx_msg void OnHScroll ( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar );
  127. afx_msg void OnPaint ();
  128. afx_msg void OnCancelMode ();
  129. afx_msg void OnWindowPosChanging( WINDOWPOS FAR* lpwndpos );
  130. afx_msg void OnDestroyClipboard();
  131. afx_msg void OnPaletteChanged(CWnd *);
  132. afx_msg BOOL OnSetCursor (CWnd *pWnd, UINT nHitTest, UINT message);
  133. afx_msg BOOL OnMouseWheel (UINT nFlags, short zDelta, CPoint pt);
  134. void CmdSmallBrush();
  135. void CmdSmallerBrush();
  136. void CmdLargerBrush();
  137. void CmdClearImage();
  138. void CmdShowGrid();
  139. #ifdef GRIDOPTIONS
  140. void CmdGridOptions();
  141. void CmdShowTileGrid();
  142. #endif // GRIDOPTIONS
  143. void CmdInvMode();
  144. void CmdTransMode();
  145. void CmdCopy();
  146. void CmdCut();
  147. void CmdPaste();
  148. void CmdClear();
  149. void CmdInvertColors();
  150. void CmdTglOpaque();
  151. void CmdFlipBshH();
  152. void CmdFlipBshV();
  153. void CmdRot90();
  154. void CmdSkewBrush( int wAngle, BOOL bHorz );
  155. void CmdDoubleBsh();
  156. void CmdHalfBsh();
  157. void CmdSel2Bsh();
  158. void CmdExport();
  159. void CmdCancel();
  160. void CmdOK();
  161. void GetDrawRects(const CRect* pPaintRect, const CRect* pReqDestRect,
  162. CRect& srcRect, CRect& destRect);
  163. void DrawGrid(CDC* pDC, const CRect& srcRect, CRect& destRect);
  164. void DrawBackground(CDC* pDC, const CRect* pPaintRect = NULL);
  165. void DrawTracker(CDC* pDC = NULL, const CRect* pPaintRect = NULL);
  166. void DrawImage(CDC* pDC, const CRect* pPaintRect,
  167. CRect* pDestRect = NULL, BOOL bDoGrid = TRUE);
  168. void SetThumbnailView( CThumbNailView* pwndNewThumbnailView )
  169. { m_pwndThumbNailView = pwndNewThumbnailView; }
  170. BOOL PasteImageClip();
  171. BOOL PasteImageFile( LPSTR lpDib );
  172. HBITMAP CopyDC( CDC* pImgDC, CRect* prcClip );
  173. void CopyBMAndPal(HBITMAP *pBM, CPalette ** ppPal);
  174. CImgWnd* m_pNextImgWnd; // next viewer link
  175. int m_nZoom;
  176. int m_nZoomPrev;
  177. int m_xScroll;
  178. int m_yScroll;
  179. int m_LineX; // this is 1/32 of the bitmap height
  180. int m_LineY; // this is 1/32 of the bitmap width
  181. CPoint m_ptDispPos;
  182. WORD m_wClipboardFormat;
  183. HGLOBAL m_hPoints;
  184. CThumbNailView* m_pwndThumbNailView;
  185. DECLARE_MESSAGE_MAP()
  186. friend class CPBFrame;
  187. friend class CPBView;
  188. friend class CBitmapObj;
  189. friend class CSelectTool;
  190. friend class CTextTool;
  191. friend class CCurveTool;
  192. friend class CTedit;
  193. friend class CAttrEdit;
  194. friend class CImgToolWnd; // for key message forwarding
  195. friend class CImgColorsWnd;
  196. friend class CCursorIconToolWnd;
  197. friend BOOL SetImgSize(IMG*, CSize, BOOL);
  198. friend void SetDrawColor(COLORREF);
  199. friend void SetEraseColor(COLORREF);
  200. friend void SetTransColor(COLORREF);
  201. friend void FreeImg(IMG* pImg);
  202. friend void AddImgWnd(IMG*, CImgWnd*);
  203. friend void InvalImgRect(IMG* pImg, CRect* prc);
  204. friend void CommitSelection(BOOL);
  205. private:
  206. short m_WheelDelta;
  207. };
  208. BOOL FillBitmapObj(CImgWnd* pImgWnd, CBitmapObj* pResObject, IMG* pImgStruct,
  209. int iColor = -1);
  210. extern CImgWnd* g_pMouseImgWnd;
  211. extern CImgWnd* g_pDragBrushWnd;
  212. extern CRect rcDragBrush;
  213. #endif // __IMGWND_H__