1 /* $Id: ptb_gui.cpp 383006 2012-12-11 15:51:23Z gouriano $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Andrei Gourianov
27 *
28 */
29
30 #include <ncbi_pch.hpp>
31 #include "proj_builder_app.hpp"
32 #include "ptb_gui.h"
33
34 BEGIN_NCBI_SCOPE
35
36 #if defined(NCBI_OS_MSWIN)
37
38 #define COMPILE_MULTIMON_STUBS
39 #include <multimon.h>
40
41 /////////////////////////////////////////////////////////////////////////////
42
43 void CenterWindow(HWND hWnd);
44 BOOL UpdateData(HWND hDlg, CProjBulderApp* pApp, BOOL bGet);
45 INT_PTR CALLBACK PtbConfigDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
46
47 /////////////////////////////////////////////////////////////////////////////
48
CenterWindow(HWND hWnd)49 void CenterWindow(HWND hWnd)
50 {
51 RECT rcWnd;
52 GetWindowRect(hWnd, &rcWnd);
53 MONITORINFO mi;
54 mi.cbSize = sizeof(mi);
55 GetMonitorInfo( MonitorFromWindow( hWnd, MONITOR_DEFAULTTOPRIMARY), &mi);
56 int xLeft = (mi.rcMonitor.left + mi.rcMonitor.right - rcWnd.right + rcWnd.left)/2;
57 int yTop = (mi.rcMonitor.top + mi.rcMonitor.bottom - rcWnd.bottom + rcWnd.top )/2;
58 SetWindowPos(hWnd, NULL, xLeft, yTop, -1, -1,
59 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
60 }
61
UpdateData(HWND hDlg,CProjBulderApp * pApp,BOOL bGet)62 BOOL UpdateData(HWND hDlg, CProjBulderApp* pApp, BOOL bGet)
63 {
64 if (bGet) {
65 char szBuf[MAX_PATH];
66
67 GetDlgItemTextA( hDlg,IDC_EDIT_ROOT, szBuf, sizeof(szBuf)); pApp->m_Root = szBuf;
68 GetDlgItemTextA( hDlg,IDC_EDIT_SUBTREE, szBuf, sizeof(szBuf)); pApp->m_Subtree = szBuf;
69 GetDlgItemTextA( hDlg,IDC_EDIT_SLN, szBuf, sizeof(szBuf)); pApp->m_Solution = szBuf;
70 GetDlgItemTextA( hDlg,IDC_EDIT_EXTROOT, szBuf, sizeof(szBuf)); pApp->m_BuildRoot = szBuf;
71 GetDlgItemTextA( hDlg,IDC_EDIT_PROJTAG, szBuf, sizeof(szBuf)); pApp->m_ProjTags = szBuf;
72
73 GetDlgItemTextA( hDlg,IDC_EDIT_3PARTY, szBuf, sizeof(szBuf));
74 pApp->m_CustomConfiguration.AddDefinition("ThirdPartyBasePath", szBuf);
75 GetDlgItemTextA( hDlg,IDC_EDIT_CNCBI, szBuf, sizeof(szBuf));
76 pApp->m_CustomConfiguration.AddDefinition("ThirdParty_C_ncbi", szBuf);
77
78 pApp->m_Dll = IsDlgButtonChecked(hDlg,IDC_CHECK_DLL) == BST_CHECKED;
79 pApp->m_BuildPtb = IsDlgButtonChecked(hDlg,IDC_CHECK_NOPTB) != BST_CHECKED;
80 pApp->m_AddMissingLibs = IsDlgButtonChecked(hDlg,IDC_CHECK_EXT) == BST_CHECKED;
81 pApp->m_ScanWholeTree = IsDlgButtonChecked(hDlg,IDC_CHECK_NWT) != BST_CHECKED;
82 pApp->m_TweakVTuneR = IsDlgButtonChecked(hDlg,IDC_CHECK_VTUNER) == BST_CHECKED;
83 pApp->m_TweakVTuneD = IsDlgButtonChecked(hDlg,IDC_CHECK_VTUNED) == BST_CHECKED;
84 } else {
85
86 SetDlgItemTextA( hDlg,IDC_EDIT_ROOT, pApp->m_Root.c_str());
87 SetDlgItemTextA( hDlg,IDC_EDIT_SUBTREE, pApp->m_Subtree.c_str());
88 SetDlgItemTextA( hDlg,IDC_EDIT_SLN, pApp->m_Solution.c_str());
89 SetDlgItemTextA( hDlg,IDC_EDIT_EXTROOT, pApp->m_BuildRoot.c_str());
90 SetDlgItemTextA( hDlg,IDC_EDIT_PROJTAG, pApp->m_ProjTags.c_str());
91
92 SetDlgItemTextA( hDlg,IDC_EDIT_PTBINI2, pApp->m_CustomConfFile.c_str());
93 string v;
94 if (pApp->m_CustomConfiguration.GetValue("ThirdPartyBasePath", v)) {
95 SetDlgItemTextA( hDlg,IDC_EDIT_3PARTY, v.c_str());
96 }
97 if (pApp->m_CustomConfiguration.GetValue("ThirdParty_C_ncbi", v)) {
98 SetDlgItemTextA( hDlg,IDC_EDIT_CNCBI, v.c_str());
99 }
100
101 CheckDlgButton( hDlg,IDC_CHECK_DLL, pApp->m_Dll);
102 CheckDlgButton( hDlg,IDC_CHECK_NOPTB, !pApp->m_BuildPtb);
103 CheckDlgButton( hDlg,IDC_CHECK_EXT, pApp->m_AddMissingLibs);
104 CheckDlgButton( hDlg,IDC_CHECK_NWT, !pApp->m_ScanWholeTree);
105 CheckDlgButton( hDlg,IDC_CHECK_VTUNER, pApp->m_TweakVTuneR);
106 CheckDlgButton( hDlg,IDC_CHECK_VTUNED, pApp->m_TweakVTuneD);
107 }
108 return TRUE;
109 }
110
PtbConfigDialog(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)111 INT_PTR CALLBACK PtbConfigDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
112 {
113 switch (uMsg) {
114 case WM_INITDIALOG:
115 SetWindowLongPtr( hDlg, DWLP_USER, lParam );
116 UpdateData( hDlg,(CProjBulderApp*)lParam,FALSE );
117 CenterWindow(hDlg);
118 SetFocus( GetDlgItem(hDlg,IDOK));
119 break;
120 case WM_COMMAND:
121 switch (wParam) {
122 case IDOK:
123 if (UpdateData( hDlg,(CProjBulderApp*)GetWindowLongPtr(hDlg,DWLP_USER),TRUE )) {
124 EndDialog(hDlg,IDOK);
125 }
126 break;
127 case IDCANCEL:
128 EndDialog(hDlg,IDCANCEL);
129 break;
130 default:
131 break;
132 }
133 break;
134 /*
135 case WM_NCHITTEST:
136 SetWindowLong(hDlg, DWL_MSGRESULT, HTCAPTION);
137 return TRUE;
138 */
139 default:
140 break;
141 }
142 return FALSE;
143 }
144
145 #endif
146
ConfirmConfiguration(void)147 bool CProjBulderApp::ConfirmConfiguration(void)
148 {
149 #if defined(NCBI_OS_MSWIN)
150 bool result = ( DialogBoxParam( GetModuleHandle(NULL),
151 MAKEINTRESOURCE(IDD_PTB_GUI_DIALOG),
152 NULL, PtbConfigDialog,
153 (LPARAM)(LPVOID)this) == IDOK);
154 if (result) {
155 m_CustomConfiguration.AddDefinition("__TweakVTuneR", m_TweakVTuneR ? "yes" : "no");
156 m_CustomConfiguration.AddDefinition("__TweakVTuneD", m_TweakVTuneD ? "yes" : "no");
157 m_CustomConfiguration.Save(m_CustomConfFile);
158 }
159 return result;
160 #else
161 return true;
162 #endif
163 }
164
Gui_ConfirmConfiguration(void)165 bool CProjBulderApp::Gui_ConfirmConfiguration(void)
166 {
167 if (CMsvc7RegSettings::GetMsvcPlatform() == CMsvc7RegSettings::eUnix) {
168 return true;
169 }
170
171 cout << "*PTBGUI{* custom" << endl;
172 list<string> skip;
173 skip.push_back("__AllowedProjects");
174 m_CustomConfiguration.Dump(cout, &skip);
175 cout << "*PTBGUI}* custom" << endl;
176
177 bool started = false;
178 char buf[512];
179 for (;;) {
180 cin.getline(buf, sizeof(buf));
181 string s(buf);
182 if (NStr::StartsWith(s, "*PTBGUI{*")) {
183 started = true;
184 continue;
185 }
186 if (NStr::StartsWith(s, "*PTBGUIabort*")) {
187 return false;
188 }
189 if (NStr::StartsWith(s, "*PTBGUI}*")) {
190 started = false;
191 break;;
192 }
193 if (started) {
194 string s1, s2;
195 if (NStr::SplitInTwo(s,"=", s1, s2)) {
196 NStr::TruncateSpacesInPlace(s1);
197 NStr::TruncateSpacesInPlace(s2);
198 m_CustomConfiguration.AddDefinition(s1, s2);
199 }
200 }
201 }
202 // m_CustomConfiguration.Save(m_CustomConfFile);
203 if (CMsvc7RegSettings::GetMsvcPlatform() < CMsvc7RegSettings::eUnix) {
204 string v;
205 if (m_CustomConfiguration.GetValue("__TweakVTuneR", v)) {
206 m_TweakVTuneR = NStr::StringToBool(v);
207 }
208 if (m_CustomConfiguration.GetValue("__TweakVTuneD", v)) {
209 m_TweakVTuneD = NStr::StringToBool(v);
210 }
211 m_AddUnicode = GetSite().IsProvided("Ncbi_Unicode", false) ||
212 GetSite().IsProvided("Ncbi-Unicode", false);
213 if ( m_MsvcRegSettings.get() ) {
214 GetBuildConfigs(&m_MsvcRegSettings->m_ConfigInfo);
215 }
216 }
217 return true;
218 }
219
Gui_ConfirmProjects(CProjectItemsTree & projects_tree)220 bool CProjBulderApp::Gui_ConfirmProjects(CProjectItemsTree& projects_tree)
221 {
222 string prjid;
223 cout << "*PTBGUI{* projects" << endl;
224 ITERATE(CProjectItemsTree::TProjects, p, projects_tree.m_Projects) {
225 /*
226 if (p->second.m_MakeType == eMakeType_Excluded ||
227 p->second.m_MakeType == eMakeType_ExcludedByReq) {
228 continue;
229 }
230 */
231 if (p->first.Type() == CProjKey::eDll ||
232 p->first.Type() == CProjKey::eDataSpec) {
233 continue;
234 }
235 prjid = CreateProjectName(p->first);
236 cout << prjid << ",";
237 if (p->first.Type() == CProjKey::eLib ||
238 p->first.Type() == CProjKey::eDll) {
239 cout << "lib";
240 } else if (p->first.Type() == CProjKey::eApp) {
241 cout << "app";
242 } else {
243 cout << "other";
244 }
245 cout << ",";
246
247 if (m_CustomConfiguration.DoesValueContain( "__AllowedProjects", prjid)) {
248 cout << "select";
249 } else {
250 cout << "unselect";
251 }
252 cout << "," << NStr::Replace(p->second.m_SourcesBaseDir,"\\","/");
253 cout << "," << NStr::Join(p->second.m_ProjTags,"/");
254 cout << endl;
255 }
256 cout << "*PTBGUI}* projects" << endl;
257
258 bool started = false;
259 char buf[512];
260 list<string> prj;
261 for (;;) {
262 cin.getline(buf, sizeof(buf));
263 string s(buf);
264 if (NStr::StartsWith(s, "*PTBGUI{*")) {
265 started = true;
266 continue;
267 }
268 if (NStr::StartsWith(s, "*PTBGUIabort*")) {
269 return false;
270 }
271 if (NStr::StartsWith(s, "*PTBGUI}*")) {
272 started = false;
273 break;;
274 }
275 if (started) {
276 NStr::TruncateSpacesInPlace(s);
277 prj.push_back(s);
278 }
279 }
280 m_CustomConfiguration.AddDefinition("__AllowedProjects", NStr::Join(prj," "));
281 m_CustomConfiguration.Save(m_CustomConfFile);
282 return true;
283 }
284
285
286 END_NCBI_SCOPE
287