1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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
24 #include "georges_edit.h"
25 #include "georges_edit_view.h"
26 #include "georges_edit_doc.h"
27 #include "header_dialog.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
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
59 BEGIN_MESSAGE_MAP(CHeaderDialog
, CDialog
)
60 //{{AFX_MSG_MAP(CHeaderDialog)
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();
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
88 getFirstItemPos (currentPos
);
91 setStaticSize (currentPos
);
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
);
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
);
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
);
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
);
140 getNextPos (currentPos
);
142 registerLastControl ();
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 ()
153 View
->GetClientRect (&viewRect
);
154 uint virtualWidth
= std::max ((uint
)MinViewWidth
, (uint
)(viewRect
.right
-viewRect
.left
));
157 CBaseDialog::resizeWidgets (virtualWidth
, 0);
159 // Get first item coordinate
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
);
180 CBaseDialog::resizeWidgets (virtualWidth
, currentPos
.bottom
);
182 // Get first item coordinate
184 getFirstItemPos (currentPos
);
186 uint adjust
= AdjusteHeight
/ 2;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
241 currentPos
.bottom
+CGeorgesEditView::WidgetTopMargin
+CGeorgesEditView::WidgetBottomMargin
);
244 void CHeaderDialog::getFromDocument (const NLGEORGES::CFileHeader
&header
)
248 // Nel standard version number
249 ComboState
.SetCurSel (header
.State
);
251 name
.Format(_T("Version %d.%d"), header
.MajorVersion
, header
.MinorVersion
);
252 LabelVersion
.SetWindowText (name
);
255 setEditTextMultiLine (Comments
, header
.Comments
.c_str());
258 setEditTextMultiLine (Log
, header
.Log
.c_str());
262 void CHeaderDialog::setStateToDocument ()
264 CGeorgesEditDoc
*doc
= View
->GetDocument ();
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 ();
281 LabelVersion
.GetWindowText (str
);
282 if (sscanf (tStrToUtf8(str
).c_str(), "Version %d.%d", &v0
, &v1
)==2)
287 name
.Format(_T("Version %d.%d"), v0
, v1
);
288 LabelVersion
.SetWindowText (name
);
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 ();
302 CGeorgesEditDocSub
*current
= doc
->getSelectedObject ();
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
))
317 switch (LOWORD(wParam
))
320 setCommentsToDocument ();
328 switch (LOWORD(wParam
))
331 setStateToDocument ();
339 switch (LOWORD(wParam
))
342 setVersionToDocument ();
348 return CWnd::OnCommand(wParam
, lParam
);
351 void CHeaderDialog::onFirstFocus ()
356 void CHeaderDialog::onLastFocus ()
358 View
->setFocusLeftView ();