OSDN Git Service

Fix crash when input character at filter box
[tortoisegit/TortoiseGitJp.git] / src / TortoiseIDiff / PicWindow.h
1 // TortoiseIDiff - an image diff viewer in TortoiseSVN\r
2 \r
3 // Copyright (C) 2006-2009 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 #include "commctrl.h"\r
21 #include "BaseWindow.h"\r
22 #include "TortoiseIDiff.h"\r
23 #include "Picture.h"\r
24 #include "NiceTrackbar.h"\r
25 \r
26 #define HEADER_HEIGHT 30\r
27 \r
28 #define ID_ANIMATIONTIMER 100\r
29 #define TIMER_ALPHASLIDER 101\r
30 #define ID_ALPHATOGGLETIMER 102\r
31 \r
32 #define LEFTBUTTON_ID                   101\r
33 #define RIGHTBUTTON_ID                  102\r
34 #define PLAYBUTTON_ID                   103\r
35 #define ALPHATOGGLEBUTTON_ID    104\r
36 #define BLENDALPHA_ID                   105\r
37 #define BLENDXOR_ID                             106\r
38 \r
39 #define TRACKBAR_ID 101\r
40 #define SLIDER_HEIGHT 30\r
41 #define SLIDER_WIDTH 30\r
42 \r
43 \r
44 #ifndef GET_X_LPARAM\r
45 #define GET_X_LPARAM(lp)                        ((int)(short)LOWORD(lp))\r
46 #endif\r
47 #ifndef GET_Y_LPARAM\r
48 #define GET_Y_LPARAM(lp)                        ((int)(short)HIWORD(lp))\r
49 #endif\r
50 \r
51 /**\r
52  * \ingroup TortoiseIDiff\r
53  * The image view window.\r
54  * Shows an image and provides methods to scale the image or alpha blend it\r
55  * over another image.\r
56  */\r
57 class CPicWindow : public CWindow\r
58 {\r
59 public:\r
60         CPicWindow(HINSTANCE hInst, const WNDCLASSEX* wcx = NULL) : CWindow(hInst, wcx)\r
61                 , bValid(false)\r
62                 , nHScrollPos(0)\r
63                 , nVScrollPos(0)\r
64                 , picscale(1.0)\r
65                 , transparentColor(::GetSysColor(COLOR_WINDOW))\r
66                 , pSecondPic(NULL)\r
67                 , blendAlpha(0.5f)\r
68                 , bShowInfo(false)\r
69                 , nDimensions(0)\r
70                 , nCurrentDimension(1)\r
71                 , nFrames(0)\r
72                 , nCurrentFrame(1)\r
73                 , bPlaying(false)\r
74                 , pTheOtherPic(NULL)\r
75                 , bLinkedPositions(true)\r
76                 , bFitSizes(false)\r
77                 , m_blend(BLEND_ALPHA)\r
78                 , bMainPic(false)\r
79         { \r
80                 SetWindowTitle(_T("Picture Window"));\r
81                 m_lastTTPos.x = 0;\r
82                 m_lastTTPos.y = 0;\r
83         };\r
84 \r
85         enum BlendType\r
86         {\r
87                 BLEND_ALPHA,\r
88                 BLEND_XOR,\r
89         };\r
90         /// Registers the window class and creates the window\r
91         bool RegisterAndCreateWindow(HWND hParent);\r
92 \r
93         /// Sets the image path and title to show\r
94         void SetPic(tstring path, tstring title, bool bFirst);\r
95         /// Returns the CPicture image object. Used to get an already loaded image\r
96         /// object without having to load it again.\r
97         CPicture * GetPic() {return &picture;}\r
98         /// Sets the path and title of the second image which is alpha blended over the original\r
99         void SetSecondPic(CPicture * pPicture = NULL, const tstring& sectit = _T(""), const tstring& secpath = _T(""), int hpos = 0, int vpos = 0)\r
100         {\r
101                 pSecondPic = pPicture;\r
102                 pictitle2 = sectit;\r
103                 picpath2 = secpath;\r
104                 nVSecondScrollPos = vpos;\r
105                 nHSecondScrollPos = hpos;\r
106         }\r
107 \r
108         void StopTimer() {KillTimer(*this, ID_ANIMATIONTIMER);}\r
109         \r
110         /// Returns the currently used alpha blending value (0.0-1.0)\r
111         float GetBlendAlpha() const { return blendAlpha; }\r
112         /// Sets the alpha blending value\r
113         void SetBlendAlpha(BlendType type, float a) \r
114         {\r
115                 m_blend = type;\r
116                 blendAlpha = a;\r
117                 if (m_AlphaSlider.IsValid())\r
118                         SendMessage(m_AlphaSlider.GetWindow(), TBM_SETPOS, (WPARAM)1, (LPARAM)(a*16.0f));\r
119                 PositionTrackBar();\r
120                 InvalidateRect(*this, NULL, FALSE);\r
121         }\r
122         /// Toggle the alpha blending value\r
123         void ToggleAlpha()\r
124         {\r
125                 if( 0.0f != GetBlendAlpha() )\r
126                         SetBlendAlpha(m_blend, 0.0f);\r
127                 else\r
128                         SetBlendAlpha(m_blend, 1.0f);\r
129         }\r
130 \r
131         /// Set the color that this PicWindow will display behind transparent images.\r
132         void SetTransparentColor(COLORREF back) { transparentColor = back; InvalidateRect(*this, NULL, false); }\r
133 \r
134         /// Resizes the image to fit into the window. Small images are not enlarged.\r
135         void FitImageInWindow();\r
136         /// center the image in the view\r
137         void CenterImage();\r
138         /// Makes both images the same size, fitting into the window\r
139         void FitSizes(bool bFit);\r
140         /// Sets the zoom factor of the image\r
141         void SetZoom(double dZoom, bool centermouse);\r
142         /// Returns the currently used zoom factor in which the image is shown.\r
143         double GetZoom() {return picscale;}\r
144         /// Zooms in (true) or out (false) in nice steps\r
145         void Zoom(bool in, bool centermouse);\r
146         /// Sets the 'Other' pic window\r
147         void SetOtherPicWindow(CPicWindow * pWnd) {pTheOtherPic = pWnd;}\r
148         /// Links/Unlinks the two pic windows\r
149         void LinkPositions(bool bLink) {bLinkedPositions = bLink;}\r
150 \r
151         void ShowInfo(bool bShow = true) {bShowInfo = bShow; InvalidateRect(*this, NULL, false);}\r
152         /// Sets up the scrollbars as needed\r
153         void SetupScrollBars();\r
154 \r
155         bool HasMultipleImages();\r
156 \r
157         int GetHPos() {return nHScrollPos;}\r
158         int GetVPos() {return nVScrollPos;}\r
159         void SetZoomValue(double z) {picscale = z; InvalidateRect(*this, NULL, FALSE);}\r
160 \r
161         /// Handles the mouse wheel\r
162         void                            OnMouseWheel(short fwKeys, short zDelta);\r
163 protected:\r
164         /// the message handler for this window\r
165         LRESULT CALLBACK        WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
166         /// Draws the view title bar\r
167         void                            DrawViewTitle(HDC hDC, RECT * rect);\r
168         /// Creates the image buttons\r
169         bool                            CreateButtons();\r
170         /// Handles vertical scrolling\r
171         void                            OnVScroll(UINT nSBCode, UINT nPos);\r
172         /// Handles horizontal scrolling\r
173         void                            OnHScroll(UINT nSBCode, UINT nPos);\r
174         /// Returns the client rectangle, without the scrollbars and the view title.\r
175         /// Basically the rectangle the image can use.\r
176         void                            GetClientRect(RECT * pRect);\r
177         /// Returns the client rectangle, without the view title but with the scrollbars\r
178         void                            GetClientRectWithScrollbars(RECT * pRect);\r
179         /// the WM_PAINT function\r
180         void                            Paint(HWND hwnd);\r
181         /// Draw pic to hdc, with a border, scaled by scale.\r
182         void                            ShowPicWithBorder(HDC hdc, const RECT &bounds, CPicture &pic, double scale);\r
183         /// Positions the buttons\r
184         void                            PositionChildren();\r
185         /// Rounds a double to a given precision\r
186         double                          RoundDouble(double doValue, int nPrecision);\r
187         /// advance to the next image in the file\r
188         void                            NextImage();\r
189         /// go back to the previous image in the file\r
190         void                            PrevImage();\r
191         /// starts/stops the animation\r
192         void                            Animate(bool bStart);\r
193         /// Creates the trackbar (the alpha blending slider control)\r
194         void                            CreateTrackbar(HWND hwndParent);\r
195         /// Moves the alpha slider trackbar to the correct position\r
196         void                            PositionTrackBar();\r
197         /// creates the info string used in the info box and the tooltips\r
198         void                            BuildInfoString(TCHAR * buf, int size, bool bTooltip);\r
199 \r
200         tstring                 picpath;                        ///< the path to the image we show\r
201         tstring                 pictitle;                       ///< the string to show in the image view as a title\r
202         CPicture                        picture;                        ///< the picture object of the image\r
203         bool                            bValid;                         ///< true if the picture object is valid, i.e. if the image could be loaded and can be shown\r
204         double                          picscale;                       ///< the scale factor of the image\r
205         COLORREF                        transparentColor;       ///< the color to draw under the images\r
206         bool                            bFirstpaint;            ///< true if the image is painted the first time. Used to initialize some stuff when the window is valid for sure.\r
207         CPicture *                      pSecondPic;                     ///< if set, this is the picture to draw transparently above the original\r
208         CPicWindow *            pTheOtherPic;           ///< pointer to the other picture window. Used for "linking" the two windows when scrolling/zooming/...\r
209         bool                            bMainPic;                       ///< if true, this is the first image\r
210         bool                            bLinkedPositions;       ///< if true, the two image windows are linked together for scrolling/zooming/...\r
211         bool                            bFitSizes;              ///< if true, the two image windows are always zoomed so they match their size\r
212         BlendType                       m_blend;                        ///< type of blending to use\r
213         tstring                         pictitle2;                      ///< the title of the second picture\r
214         tstring                         picpath2;                       ///< the path of the second picture\r
215         float                           blendAlpha;                     ///<the alpha value for transparency blending\r
216         bool                            bShowInfo;                      ///< true if the info rectangle of the image should be shown\r
217         TCHAR                           m_wszTip[8192];\r
218         char                            m_szTip[8192];\r
219         POINT                           m_lastTTPos;\r
220         HWND                            hwndTT;\r
221         // scrollbar info\r
222         int                                     nVScrollPos;            ///< vertical scroll position\r
223         int                                     nHScrollPos;            ///< horizontal scroll position\r
224         int                                     nVSecondScrollPos;      ///< vertical scroll position of second pic at the moment of enabling overlap mode\r
225         int                                     nHSecondScrollPos;      ///< horizontal scroll position of second pic at the moment of enabling overlap mode\r
226         POINT                           ptPanStart;                     ///< the point of the last mouse click\r
227         int                                     startVScrollPos;        ///< the vertical scroll position when panning starts\r
228         int                                     startHScrollPos;        ///< the horizontal scroll position when panning starts\r
229         int                                     startVSecondScrollPos;  ///< the vertical scroll position of the second pic when panning starts\r
230         int                                     startHSecondScrollPos;  ///< the horizontal scroll position of the second pic when panning starts\r
231         // image frames/dimensions\r
232         UINT                            nDimensions;\r
233         UINT                            nCurrentDimension;\r
234         UINT                            nFrames;\r
235         UINT                            nCurrentFrame;\r
236 \r
237         // controls\r
238         HWND                            hwndLeftBtn;\r
239         HWND                            hwndRightBtn;\r
240         HWND                            hwndPlayBtn;\r
241         CNiceTrackbar           m_AlphaSlider;\r
242         HWND                            hwndAlphaToggleBtn;\r
243         HICON                           hLeft;\r
244         HICON                           hRight;\r
245         HICON                           hPlay;\r
246         HICON                           hStop;\r
247         HICON                           hAlphaToggle;\r
248         bool                            bPlaying;\r
249         RECT                            m_inforect;\r
250 };\r
251 \r
252 \r
253 \r
254 \r