Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / leveldesign / georges_dll / header_dialog.cpp
bloba1443d8af2a6848a3a450f5d02c0c481dff0338c
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // header_dialog.cpp : implementation file
23 #include "stdafx.h"
24 #include "georges_edit.h"
25 #include "georges_edit_view.h"
26 #include "georges_edit_doc.h"
27 #include "header_dialog.h"
28 #include "action.h"
29 #include "left_view.h"
31 #include "nel/georges/type.h"
33 using namespace NLGEORGES;
34 using namespace NLMISC;
37 /////////////////////////////////////////////////////////////////////////////
38 // CHeaderDialog dialog
41 CHeaderDialog::CHeaderDialog () : CBaseDialog (IDR_MAINFRAME)
43 //{{AFX_DATA_INIT(CHeaderDialog)
44 // NOTE: the ClassWizard will add member initialization here
45 //}}AFX_DATA_INIT
46 View = NULL;
50 void CHeaderDialog::DoDataExchange(CDataExchange* pDX)
52 CDialog::DoDataExchange(pDX);
53 //{{AFX_DATA_MAP(CHeaderDialog)
54 // NOTE: the ClassWizard will add DDX and DDV calls here
55 //}}AFX_DATA_MAP
59 BEGIN_MESSAGE_MAP(CHeaderDialog, CDialog)
60 //{{AFX_MSG_MAP(CHeaderDialog)
61 ON_WM_SIZE()
62 //}}AFX_MSG_MAP
63 END_MESSAGE_MAP()
65 /////////////////////////////////////////////////////////////////////////////
66 // CHeaderDialog message handlers
68 void CHeaderDialog::OnSize(UINT nType, int cx, int cy)
70 CBaseDialog::OnSize(nType, cx, cy);
72 // TODO: Add your message handler code here
76 BOOL CHeaderDialog::OnInitDialog()
78 CBaseDialog::OnInitDialog();
80 // Refresh sizes
81 RECT viewRect;
82 View->GetClientRect (&viewRect);
83 uint virtualWidth = std::max ((uint)MinViewWidth, (uint)(viewRect.right-viewRect.left));
84 CBaseDialog::resizeWidgets (virtualWidth, 0);
86 // Get first item coordinate
87 RECT currentPos;
88 getFirstItemPos (currentPos);
90 // Create the version
91 setStaticSize (currentPos);
92 CString versionText;
93 versionText.Format(_T("Version %d.%d"), 0, 0);
94 LabelVersion.Create (versionText, WS_VISIBLE, currentPos, this);
95 initWidget (LabelVersion);
96 getNextPosLabel (currentPos);
98 setButtonSize (currentPos, SmallWidget);
99 IncrementVersion.Create (_T("Increment Version"), WS_VISIBLE|WS_TABSTOP, currentPos, this, BtIncrement);
100 initWidget (IncrementVersion);
101 getNextPos (currentPos);
103 // Create the state combo
104 setStaticSize (currentPos);
105 LabelState.Create (_T("State:"), WS_VISIBLE, currentPos, this);
106 initWidget (LabelState);
107 getNextPosLabel (currentPos);
109 setComboSize (currentPos, SmallWidget);
110 RECT pos = currentPos;
111 adjusteComboSize (pos);
112 ComboState.Create (WS_VISIBLE|CBS_DROPDOWNLIST|WS_TABSTOP, pos, this, CbState);
113 uint item;
114 for (item=0; item<CFileHeader::StateCount; item++)
115 ComboState.InsertString(-1, nlUtf8ToTStr(CFileHeader::getStateString((CFileHeader::TState)item)));
116 ComboState.SetCurSel (0);
117 initWidget (ComboState);
118 getNextPos (currentPos);
120 // Default value
121 setStaticSize (currentPos);
122 LabelComments.Create (_T("Comments:"), WS_VISIBLE, currentPos, this);
123 initWidget (LabelComments);
124 getNextPosLabel (currentPos);
126 setBigEditSize (currentPos, SmallWidget);
127 Comments.CreateEx (WS_EX_CLIENTEDGE, _T("EDIT"), _T(""), WS_VSCROLL|ES_OEMCONVERT|ES_MULTILINE|ES_WANTRETURN|WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL|ES_AUTOVSCROLL, currentPos, this, EdComments);
128 initWidget (Comments);
129 getNextPos (currentPos);
131 // Min value
132 setStaticSize (currentPos);
133 LabelLog.Create (_T("Log:"), WS_VISIBLE, currentPos, this);
134 initWidget (LabelLog);
135 getNextPosLabel (currentPos);
137 setBigEditSize (currentPos, SmallWidget);
138 Log.CreateEx (WS_EX_CLIENTEDGE, _T("EDIT"), _T(""), WS_VSCROLL|ES_READONLY|ES_MULTILINE|WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|ES_AUTOVSCROLL, currentPos, this, EdLog);
139 initWidget (Log);
140 getNextPos (currentPos);
142 registerLastControl ();
144 UpdateData (FALSE);
146 return TRUE; // return TRUE unless you set the focus to a control
147 // EXCEPTION: OCX Property Pages should return FALSE
150 void CHeaderDialog::resizeWidgets ()
152 RECT viewRect;
153 View->GetClientRect (&viewRect);
154 uint virtualWidth = std::max ((uint)MinViewWidth, (uint)(viewRect.right-viewRect.left));
156 // Refresh sizes
157 CBaseDialog::resizeWidgets (virtualWidth, 0);
159 // Get first item coordinate
160 RECT currentPos;
161 getFirstItemPos (currentPos);
162 setStaticSize (currentPos);
163 getNextPosLabel (currentPos);
164 setButtonSize (currentPos, SmallWidget);
165 getNextPos (currentPos);
166 setStaticSize (currentPos);
167 getNextPosLabel (currentPos);
168 setComboSize (currentPos, SmallWidget);
169 getNextPos (currentPos);
170 setStaticSize (currentPos);
171 getNextPosLabel (currentPos);
172 setBigEditSize (currentPos, Width, BigEditHeight);
173 getNextPos (currentPos);
174 setStaticSize (currentPos);
175 getNextPosLabel (currentPos);
176 setBigEditSize (currentPos, Width, BigEditHeight);
177 getNextPos (currentPos);
179 // Refresh sizes
180 CBaseDialog::resizeWidgets (virtualWidth, currentPos.bottom);
182 // Get first item coordinate
183 currentPos;
184 getFirstItemPos (currentPos);
186 uint adjust = AdjusteHeight / 2;
188 // Resize
189 setStaticSize (currentPos);
190 LabelVersion.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
191 currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
192 getNextPosLabel (currentPos);
194 // Resize
195 setButtonSize (currentPos, SmallWidget);
196 IncrementVersion.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
197 currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
198 getNextPos (currentPos);
200 // Resize
201 setStaticSize (currentPos);
202 LabelState.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
203 currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
204 getNextPosLabel (currentPos);
206 // Resize
207 setComboSize (currentPos, SmallWidget);
208 RECT pos = currentPos;
209 adjusteComboSize (pos);
210 ComboState.SetWindowPos (NULL, pos.left, pos.top, pos.right - pos.left,
211 pos.bottom - pos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
212 getNextPos (currentPos);
214 // Resize
215 setStaticSize (currentPos);
216 LabelComments.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
217 currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
218 getNextPosLabel (currentPos);
220 // Resize
221 setBigEditSize (currentPos, Width, BigEditHeight + adjust);
222 Comments.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
223 currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
224 getNextPos (currentPos);
226 // Resize
227 setStaticSize (currentPos);
228 LabelLog.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
229 currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
230 getNextPosLabel (currentPos);
232 // Resize
233 setBigEditSize (currentPos, Width, BigEditHeight + AdjusteHeight - adjust);
234 Log.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
235 currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
236 getNextPos (currentPos);
238 // Resize the current view
239 View->setViewSize (
240 virtualWidth,
241 currentPos.bottom+CGeorgesEditView::WidgetTopMargin+CGeorgesEditView::WidgetBottomMargin);
244 void CHeaderDialog::getFromDocument (const NLGEORGES::CFileHeader &header)
246 if (View)
248 // Nel standard version number
249 ComboState.SetCurSel (header.State);
250 CString name;
251 name.Format(_T("Version %d.%d"), header.MajorVersion, header.MinorVersion);
252 LabelVersion.SetWindowText (name);
254 // Set comments
255 setEditTextMultiLine (Comments, header.Comments.c_str());
257 // Set logs
258 setEditTextMultiLine (Log, header.Log.c_str());
262 void CHeaderDialog::setStateToDocument ()
264 CGeorgesEditDoc *doc = View->GetDocument ();
265 if (doc)
267 CGeorgesEditDocSub *current = doc->getSelectedObject ();
268 CFileHeader *header = doc->getHeaderPtr ();
269 doc->modify (new CActionString (IAction::HeaderState, toString ((int)(CFileHeader::TState)ComboState.GetCurSel ()).c_str (),
270 *doc, "", "", doc->getLeftView ()->getCurrentSelectionId (), 0), true, false);
274 void CHeaderDialog::setVersionToDocument ()
276 CGeorgesEditDoc *doc = View->GetDocument ();
277 if (doc)
279 uint v0, v1;
280 CString str;
281 LabelVersion.GetWindowText (str);
282 if (sscanf (tStrToUtf8(str).c_str(), "Version %d.%d", &v0, &v1)==2)
284 v0++;
285 v1=0;
286 CString name;
287 name.Format(_T("Version %d.%d"), v0, v1);
288 LabelVersion.SetWindowText (name);
290 // Modify docuemnt
291 doc->modify(new CActionString(IAction::HeaderVersion, tStrToUtf8(name).c_str(), *doc, "", "",
292 doc->getLeftView ()->getCurrentSelectionId (), 0));
297 void CHeaderDialog::setCommentsToDocument ()
299 CGeorgesEditDoc *doc = View->GetDocument ();
300 if (doc)
302 CGeorgesEditDocSub *current = doc->getSelectedObject ();
303 CString str;
304 Comments.GetWindowText (str);
305 doc->modify(new CActionString(IAction::HeaderComments, tStrToUtf8(str).c_str(), *doc, "", "",
306 doc->getLeftView ()->getCurrentSelectionId (), 0));
310 BOOL CHeaderDialog::OnCommand(WPARAM wParam, LPARAM lParam)
312 switch (HIWORD(wParam))
314 case EN_CHANGE:
316 // identifier
317 switch (LOWORD(wParam))
319 case EdComments:
320 setCommentsToDocument ();
321 break;
324 break;
325 case CBN_SELCHANGE:
327 // identifier
328 switch (LOWORD(wParam))
330 case CbState:
331 setStateToDocument ();
332 break;
335 break;
336 case BN_CLICKED:
338 // identifier
339 switch (LOWORD(wParam))
341 case BtIncrement:
342 setVersionToDocument ();
343 break;
348 return CWnd::OnCommand(wParam, lParam);
351 void CHeaderDialog::onFirstFocus ()
353 View->SetFocus ();
356 void CHeaderDialog::onLastFocus ()
358 View->setFocusLeftView ();