Prepare release and bump version numbers to 2.13.0
[TortoiseGit.git] / src / TortoiseIDiff / MainWindow.h
blob23a4101c692cfbe8f24e47bb9320edc812a95cf1
1 // TortoiseIDiff - an image diff viewer in TortoiseSVN
3 // Copyright (C) 2015-2016 - TortoiseGit
4 // Copyright (C) 2006-2007, 2009, 2011-2013, 2015-2016, 2020 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "BaseWindow.h"
22 #include "PicWindow.h"
23 #include "TortoiseIDiff.h"
25 #include <map>
26 #include <CommCtrl.h>
28 #define SPLITTER_BORDER 2
30 #define WINDOW_MINHEIGHT 200
31 #define WINDOW_MINWIDTH 200
33 enum FileType
35 FileTypeMine = 1,
36 FileTypeTheirs = 2,
37 FileTypeBase = 3,
40 /**
41 * \ingroup TortoiseIDiff
42 * The main window of TortoiseIDiff.
43 * Hosts the two image views, the menu, toolbar, slider, ...
45 class CMainWindow : public CWindow
47 public:
48 CMainWindow(HINSTANCE hInstance, const WNDCLASSEX* wcx = nullptr) : CWindow(hInstance, wcx)
49 , picWindow1(hInstance)
50 , picWindow2(hInstance)
51 , picWindow3(hInstance)
52 , oldx(-4)
53 , oldy(-4)
54 , bMoved(false)
55 , bDragMode(false)
56 , bDrag2(false)
57 , nSplitterPos(100)
58 , nSplitterPos2(200)
59 , bOverlap(false)
60 , bShowInfo(false)
61 , bVertical(false)
62 , bLinkedPositions(true)
63 , bFitWidths(false)
64 , bFitHeights(false)
65 , transparentColor(::GetSysColor(COLOR_WINDOW))
66 , m_BlendType(CPicWindow::BLEND_ALPHA)
67 , hwndTB(0)
68 , hToolbarImgList(nullptr)
69 , bSelectionMode(false)
70 , m_themeCallbackId(0)
71 , resolveMsgWnd(nullptr)
72 , resolveMsgLParam(0)
73 , resolveMsgWParam(0)
75 SetWindowTitle(static_cast<LPCWSTR>(ResString(hResource, IDS_APP_TITLE)));
78 /**
79 * Registers the window class and creates the window.
81 bool RegisterAndCreateWindow();
83 /**
84 * Sets the image path and title for the left image view.
86 void SetLeft(const std::wstring& leftpath, const std::wstring& lefttitle)
88 leftpicpath = leftpath;
89 leftpictitle = lefttitle;
91 /**
92 * Sets the image path and the title for the right image view.
94 void SetRight(const std::wstring& rightpath, const std::wstring& righttitle)
96 rightpicpath = rightpath;
97 rightpictitle = righttitle;
101 * Sets the image path and title for selection mode. In selection mode, the images
102 * are shown side-by-side for the user to chose one of them. The chosen image is
103 * saved at the path for \b FileTypeResult (if that path has been set) and the
104 * process return value is the chosen FileType.
106 void SetSelectionImage(FileType ft, const std::wstring& path, const std::wstring& title);
107 void SetSelectionResult(const std::wstring& path) { selectionResult = path; }
109 protected:
110 /// the message handler for this window
111 LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) override;
112 /// Handles all the WM_COMMAND window messages (e.g. menu commands)
113 LRESULT DoCommand(int id, LPARAM lParam);
115 /// Positions the child windows. Call this after the window sizes/positions have changed.
116 void PositionChildren(RECT* clientrect = nullptr);
117 /// Shows the "Open images" dialog where the user can select the images to diff
118 bool OpenDialog();
119 static BOOL CALLBACK OpenDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);
120 static bool AskForFile(HWND owner, wchar_t* path);
122 // splitter methods
123 void DrawXorBar(HDC hdc, int x1, int y1, int width, int height);
124 LRESULT Splitter_OnLButtonDown(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
125 LRESULT Splitter_OnLButtonUp(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
126 LRESULT Splitter_OnMouseMove(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
127 void Splitter_CaptureChanged();
129 void SetTheme(bool bDark);
130 int m_themeCallbackId;
131 // toolbar
132 bool CreateToolbar();
133 HWND hwndTB;
134 HIMAGELIST hToolbarImgList;
136 // command line params
137 static std::wstring leftpicpath;
138 static std::wstring leftpictitle;
140 static std::wstring rightpicpath;
141 static std::wstring rightpictitle;
143 // image data
144 CPicWindow picWindow1;
145 CPicWindow picWindow2;
146 CPicWindow picWindow3;
147 bool bShowInfo;
148 COLORREF transparentColor;
150 // splitter data
151 int oldx;
152 int oldy;
153 bool bMoved;
154 bool bDragMode;
155 bool bDrag2;
156 int nSplitterPos;
157 int nSplitterPos2;
159 // one/two pane view
160 bool bSelectionMode;
161 bool bOverlap;
162 bool bVertical;
163 bool bLinkedPositions;
164 bool bFitWidths;
165 bool bFitHeights;
166 CPicWindow::BlendType m_BlendType;
168 // selection mode data
169 std::map<FileType, std::wstring> selectionPaths;
170 std::map<FileType, std::wstring> selectionTitles;
171 std::wstring selectionResult;
173 public:
174 HWND resolveMsgWnd;
175 WPARAM resolveMsgWParam;
176 LPARAM resolveMsgLParam;