OSDN Git Service

Git Rebase Dialog Resize and modify split position okay
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RebaseDlg.cpp
1 // RebaseDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "RebaseDlg.h"\r
7 \r
8 \r
9 // CRebaseDlg dialog\r
10 \r
11 IMPLEMENT_DYNAMIC(CRebaseDlg, CResizableStandAloneDialog)\r
12 \r
13 CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/)\r
14         : CResizableStandAloneDialog(CRebaseDlg::IDD, pParent)\r
15     , m_bPickAll(FALSE)\r
16     , m_bSquashAll(FALSE)\r
17     , m_bEditAll(FALSE)\r
18 {\r
19 \r
20 }\r
21 \r
22 CRebaseDlg::~CRebaseDlg()\r
23 {\r
24 }\r
25 \r
26 void CRebaseDlg::DoDataExchange(CDataExchange* pDX)\r
27 {\r
28     CDialog::DoDataExchange(pDX);\r
29     DDX_Control(pDX, IDC_REBASE_PROGRESS, m_ProgressBar);\r
30     DDX_Control(pDX, IDC_STATUS_STATIC, m_CtrlStatusText);\r
31     DDX_Check(pDX, IDC_PICK_ALL, m_bPickAll);\r
32     DDX_Check(pDX, IDC_SQUASH_ALL, m_bSquashAll);\r
33     DDX_Check(pDX, IDC_EDIT_ALL, m_bEditAll);\r
34         DDX_Control(pDX, IDC_REBASE_SPLIT, m_wndSplitter);\r
35         DDX_Control(pDX,IDC_COMMIT_LIST,m_CommitList);\r
36 }\r
37 \r
38 \r
39 BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)\r
40     ON_BN_CLICKED(IDC_PICK_ALL, &CRebaseDlg::OnBnClickedPickAll)\r
41     ON_BN_CLICKED(IDC_SQUASH_ALL, &CRebaseDlg::OnBnClickedSquashAll)\r
42     ON_BN_CLICKED(IDC_EDIT_ALL, &CRebaseDlg::OnBnClickedEditAll)\r
43     ON_BN_CLICKED(IDC_REBASE_SPLIT, &CRebaseDlg::OnBnClickedRebaseSplit)\r
44         ON_WM_SIZE()\r
45 END_MESSAGE_MAP()\r
46 \r
47 void CRebaseDlg::AddRebaseAnchor()\r
48 {\r
49         AddAnchor(IDC_REBASE_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
50         AddAnchor(IDC_COMMIT_LIST,TOP_LEFT, TOP_RIGHT);\r
51         AddAnchor(IDC_REBASE_SPLIT,TOP_LEFT, TOP_RIGHT);\r
52         AddAnchor(IDC_STATUS_STATIC, BOTTOM_LEFT,BOTTOM_RIGHT);\r
53         AddAnchor(IDC_REBASE_CONTINUE,BOTTOM_RIGHT);\r
54         AddAnchor(IDC_REBASE_ABORT, BOTTOM_RIGHT);\r
55         AddAnchor(IDC_REBASE_PROGRESS,BOTTOM_LEFT, BOTTOM_RIGHT);\r
56         AddAnchor(IDC_PICK_ALL,TOP_LEFT);\r
57         AddAnchor(IDC_SQUASH_ALL,TOP_LEFT);\r
58         AddAnchor(IDC_EDIT_ALL,TOP_LEFT);\r
59         \r
60 }\r
61 \r
62 BOOL CRebaseDlg::OnInitDialog()\r
63 {\r
64         CResizableStandAloneDialog::OnInitDialog();\r
65 \r
66         CRect rectDummy;\r
67         //IDC_REBASE_DUMY_TAB\r
68         \r
69         GetClientRect(m_DlgOrigRect);\r
70         m_CommitList.GetClientRect(m_CommitListOrigRect);\r
71 \r
72         CWnd *pwnd=this->GetDlgItem(IDC_REBASE_DUMY_TAB);\r
73         pwnd->GetWindowRect(&rectDummy);\r
74 \r
75         rectDummy.top-=20;\r
76         rectDummy.bottom-=20;\r
77 \r
78         rectDummy.left-=5;\r
79         rectDummy.right-=5;\r
80         \r
81         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_REBASE_TAB))\r
82         {\r
83                 TRACE0("Failed to create output tab window\n");\r
84                 return FALSE;      // fail to create\r
85         }\r
86         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
87         // Create output panes:\r
88         //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
89         const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
90 \r
91         if (! this->m_FileListCtrl.Create(dwStyle,rectDummy,&this->m_ctrlTabCtrl,0) )\r
92         {\r
93                 TRACE0("Failed to create output windows\n");\r
94                 return FALSE;      // fail to create\r
95         }\r
96 \r
97         if( ! this->m_LogMessageCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) )\r
98         {\r
99                 TRACE0("Failed to create log message control");\r
100                 return FALSE;\r
101         }\r
102 \r
103         m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS , _T("RebaseDlg"));\r
104 \r
105         m_ctrlTabCtrl.AddTab(&m_FileListCtrl,_T("Modified File"));\r
106         m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl,_T("Log Message"),1);\r
107         AddRebaseAnchor();\r
108 \r
109 \r
110         EnableSaveRestore(_T("RebaseDlg"));\r
111 \r
112         DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
113         RECT rcDlg, rcLogMsg, rcFileList;\r
114         GetClientRect(&rcDlg);\r
115         m_CommitList.GetWindowRect(&rcLogMsg);\r
116         ScreenToClient(&rcLogMsg);\r
117         this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);\r
118         ScreenToClient(&rcFileList);\r
119         if (yPos)\r
120         {\r
121                 RECT rectSplitter;\r
122                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
123                 ScreenToClient(&rectSplitter);\r
124                 int delta = yPos - rectSplitter.top;\r
125                 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))\r
126                 {\r
127                         m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);\r
128                         DoSize(delta);\r
129                 }\r
130         }\r
131 \r
132 \r
133         return TRUE;\r
134 }\r
135 // CRebaseDlg message handlers\r
136 \r
137 void CRebaseDlg::OnBnClickedPickAll()\r
138 {\r
139     // TODO: Add your control notification handler code here\r
140 }\r
141 \r
142 void CRebaseDlg::OnBnClickedSquashAll()\r
143 {\r
144     // TODO: Add your control notification handler code here\r
145 }\r
146 \r
147 void CRebaseDlg::OnBnClickedEditAll()\r
148 {\r
149     // TODO: Add your control notification handler code here\r
150 }\r
151 \r
152 void CRebaseDlg::OnBnClickedRebaseSplit()\r
153 {\r
154     // TODO: Add your control notification handler code here\r
155 }\r
156 \r
157 LRESULT CRebaseDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
158 {\r
159         switch (message) {\r
160         case WM_NOTIFY:\r
161                 if (wParam == IDC_REBASE_SPLIT)\r
162                 { \r
163                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
164                         DoSize(pHdr->delta);\r
165                 }\r
166                 break;\r
167         }\r
168 \r
169         return __super::DefWindowProc(message, wParam, lParam);\r
170 }\r
171 \r
172 void CRebaseDlg::DoSize(int delta)\r
173 {\r
174         \r
175         this->RemoveAllAnchors();\r
176 \r
177         CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST), delta, CW_TOPALIGN);\r
178         //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);\r
179         CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB), -delta, CW_BOTTOMALIGN);\r
180         //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);\r
181         CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL),0,delta);\r
182         CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL),0,delta);\r
183         CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL),0,delta);\r
184         \r
185         this->AddRebaseAnchor();\r
186         // adjust the minimum size of the dialog to prevent the resizing from\r
187         // moving the list control too far down.\r
188         CRect rcLogMsg;\r
189         m_CommitList.GetClientRect(rcLogMsg);\r
190         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_CommitListOrigRect.Height()+rcLogMsg.Height()));\r
191 \r
192         SetSplitterRange();\r
193 //      m_CommitList.Invalidate();\r
194 \r
195 //      GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
196 \r
197         this->m_ctrlTabCtrl.Invalidate();\r
198         this->m_CommitList.Invalidate();\r
199         this->m_FileListCtrl.Invalidate();\r
200         this->m_LogMessageCtrl.Invalidate();\r
201 \r
202 }\r
203 \r
204 void CRebaseDlg::SetSplitterRange()\r
205 {\r
206         if ((m_CommitList)&&(m_ctrlTabCtrl))\r
207         {\r
208                 CRect rcTop;\r
209                 m_CommitList.GetWindowRect(rcTop);\r
210                 ScreenToClient(rcTop);\r
211                 CRect rcMiddle;\r
212                 m_ctrlTabCtrl.GetWindowRect(rcMiddle);\r
213                 ScreenToClient(rcMiddle);\r
214                 if (rcMiddle.Height() && rcMiddle.Width())\r
215                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
216         }\r
217 }\r
218 \r
219 void CRebaseDlg::OnSize(UINT nType,int cx, int cy)\r
220 {\r
221          // first, let the resizing take place\r
222     __super::OnSize(nType, cx, cy);\r
223 \r
224     //set range\r
225     SetSplitterRange();\r
226 }\r
227 \r
228 void CRebaseDlg::SaveSplitterPos()\r
229 {\r
230         if (!IsIconic())\r
231         {\r
232                 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
233                 RECT rectSplitter;\r
234                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
235                 ScreenToClient(&rectSplitter);\r
236                 regPos = rectSplitter.top;\r
237         }\r
238 }