Pass objects by const ref
[TortoiseGit.git] / src / TortoiseIDiff / MainWindow.h
blobe2da76bbcc27263a124807c805f46666c773db33
1 // TortoiseIDiff - an image diff viewer in TortoiseSVN
3 // Copyright (C) 2015 - TortoiseGit
4 // Copyright (C) 2006-2007, 2009, 2011-2013, 2015 - 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 = NULL) : 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(NULL)
69 , bSelectionMode(false)
70 , resolveMsgWnd(nullptr)
71 , resolveMsgLParam(NULL)
72 , resolveMsgWParam(NULL)
74 SetWindowTitle((LPCTSTR)ResString(hResource, IDS_APP_TITLE));
77 /**
78 * Registers the window class and creates the window.
80 bool RegisterAndCreateWindow();
82 /**
83 * Sets the image path and title for the left image view.
85 void SetLeft(const tstring& leftpath, const tstring& lefttitle) { leftpicpath = leftpath; leftpictitle = lefttitle; }
86 /**
87 * Sets the image path and the title for the right image view.
89 void SetRight(const tstring& rightpath, const tstring& righttitle) { rightpicpath = rightpath; rightpictitle = righttitle; }
91 /**
92 * Sets the image path and title for selection mode. In selection mode, the images
93 * are shown side-by-side for the user to chose one of them. The chosen image is
94 * saved at the path for \b FileTypeResult (if that path has been set) and the
95 * process return value is the chosen FileType.
97 void SetSelectionImage(FileType ft, const std::wstring& path, const std::wstring& title);
98 void SetSelectionResult(const std::wstring& path) { selectionResult = path; }
100 protected:
101 /// the message handler for this window
102 LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
103 /// Handles all the WM_COMMAND window messages (e.g. menu commands)
104 LRESULT DoCommand(int id, LPARAM lParam);
106 /// Positions the child windows. Call this after the window sizes/positions have changed.
107 void PositionChildren(RECT * clientrect = NULL);
108 /// Shows the "Open images" dialog where the user can select the images to diff
109 bool OpenDialog();
110 static BOOL CALLBACK OpenDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);
111 static bool AskForFile(HWND owner, TCHAR * path);
113 // splitter methods
114 void DrawXorBar(HDC hdc, int x1, int y1, int width, int height);
115 LRESULT Splitter_OnLButtonDown(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
116 LRESULT Splitter_OnLButtonUp(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
117 LRESULT Splitter_OnMouseMove(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
118 void Splitter_CaptureChanged();
120 // toolbar
121 bool CreateToolbar();
122 HWND hwndTB;
123 HIMAGELIST hToolbarImgList;
125 // command line params
126 static tstring leftpicpath;
127 static tstring leftpictitle;
129 static tstring rightpicpath;
130 static tstring rightpictitle;
132 // image data
133 CPicWindow picWindow1;
134 CPicWindow picWindow2;
135 CPicWindow picWindow3;
136 bool bShowInfo;
137 COLORREF transparentColor;
139 // splitter data
140 int oldx;
141 int oldy;
142 bool bMoved;
143 bool bDragMode;
144 bool bDrag2;
145 int nSplitterPos;
146 int nSplitterPos2;
148 // one/two pane view
149 bool bSelectionMode;
150 bool bOverlap;
151 bool bVertical;
152 bool bLinkedPositions;
153 bool bFitWidths;
154 bool bFitHeights;
155 CPicWindow::BlendType m_BlendType;
157 // selection mode data
158 std::map<FileType, std::wstring> selectionPaths;
159 std::map<FileType, std::wstring> selectionTitles;
160 std::wstring selectionResult;
162 public:
163 HWND resolveMsgWnd;
164 WPARAM resolveMsgWParam;
165 LPARAM resolveMsgLParam;