1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // client_configDlg.cpp : implementation file
21 #include "client_config.h"
22 #include "client_configDlg.h"
26 #include <nel/misc/debug.h>
27 #include <nel/misc/system_utils.h>
29 #define ICON_ZONE_WIDTH 128
31 #define LEFT_WIDTH 256
32 #define LEFT_HEIGHT 512
34 #define BAR_START_X (LEFT_WIDTH+ICON_ZONE_WIDTH)
37 #define TREE_ZONE_WIDTH 150
38 #define TREE_OFFSET_LEFT 10
39 #define TREE_OFFSET_TOP 10
42 #define LARGE_LABEL_HEIGHT -22
43 #define LARGE_LABEL_START_X (LEFT_WIDTH+TREE_ZONE_WIDTH)
44 #define LARGE_LABEL_START_Y (15)
45 #define LARGE_LABEL_END_X (LEFT_WIDTH+ICON_ZONE_WIDTH+BAR_WIDTH)
46 #define LARGE_LABEL_END_Y BAR_HEIGHT
50 #define ICON_HEIGHT 64
51 #define ICON_START_Y ((BAR_HEIGHT-ICON_HEIGHT)/2)
52 #define ICON_START_X (LEFT_WIDTH+ICON_START_Y)
53 #define ICON_START_Y ((BAR_HEIGHT-ICON_HEIGHT)/2)
55 // ***************************************************************************
56 // CAboutDlg dialog used for App About
57 // ***************************************************************************
59 class CAboutDlg
: public CDialog
65 //{{AFX_DATA(CAboutDlg)
66 enum { IDD
= IDD_ABOUTBOX
};
69 // ClassWizard generated virtual function overrides
70 //{{AFX_VIRTUAL(CAboutDlg)
72 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
77 //{{AFX_MSG(CAboutDlg)
78 virtual BOOL
OnInitDialog();
83 // ***************************************************************************
85 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD
)
87 //{{AFX_DATA_INIT(CAboutDlg)
91 // ***************************************************************************
93 void CAboutDlg::DoDataExchange(CDataExchange
* pDX
)
95 CDialog::DoDataExchange(pDX
);
96 //{{AFX_DATA_MAP(CAboutDlg)
100 // ***************************************************************************
102 BEGIN_MESSAGE_MAP(CAboutDlg
, CDialog
)
103 //{{AFX_MSG_MAP(CAboutDlg)
107 // ***************************************************************************
108 // CClient_configDlg dialog
109 // ***************************************************************************
111 CClient_configDlg::CClient_configDlg(CWnd
* pParent
/*=NULL*/)
112 : CDialog(CClient_configDlg::IDD
, pParent
)
114 //{{AFX_DATA_INIT(CClient_configDlg)
115 // NOTE: the ClassWizard will add member initialization here
117 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
118 m_hIcon
= AfxGetApp()->LoadIcon(IDR_MAINFRAME
);
120 // Init dialog pointers
121 Dialogs
[PageGeneral
] = &GeneralDlg
;
122 Dialogs
[PageDisplay
] = &DisplayDlg
;
123 Dialogs
[PageDisplayDetails
] = &DisplayDetailsDlg
;
124 Dialogs
[PageDisplayAdvanced
] = &DisplayAdvancedDlg
;
125 Dialogs
[PageDisplaySysInfo
] = &SystemInformationDlg
;
126 Dialogs
[PageDisplayOpenGLInfo
] = &DisplayInformationGLDlg
;
127 Dialogs
[PageDisplayOpenD3DInfo
] = &DisplayInformationD3DDlg
;
128 Dialogs
[PageSound
] = &SoundDlg
;
132 // ***************************************************************************
134 void CClient_configDlg::DoDataExchange(CDataExchange
* pDX
)
136 CDialog::DoDataExchange(pDX
);
137 //{{AFX_DATA_MAP(CClient_configDlg)
138 DDX_Control(pDX
, ID_APPLY
, ApplyCtrl
);
142 // ***************************************************************************
144 BEGIN_MESSAGE_MAP(CClient_configDlg
, CDialog
)
145 //{{AFX_MSG_MAP(CClient_configDlg)
148 ON_WM_QUERYDRAGICON()
149 ON_BN_CLICKED(ID_APPLY
, OnApply
)
150 ON_BN_CLICKED(ID_DEFAULT
, OnDefault
)
151 ON_BN_CLICKED(ID_LAUNCH
, OnLaunch
)
155 // ***************************************************************************
156 // CClient_configDlg message handlers
157 // ***************************************************************************
159 BOOL
CClient_configDlg::OnInitDialog()
161 CDialog::OnInitDialog();
163 // Add "About..." menu item to system menu.
165 // IDM_ABOUTBOX must be in the system command range.
166 ASSERT((IDM_ABOUTBOX
& 0xFFF0) == IDM_ABOUTBOX
);
167 ASSERT(IDM_ABOUTBOX
< 0xF000);
169 CMenu
* pSysMenu
= GetSystemMenu(FALSE
);
170 if (pSysMenu
!= NULL
)
172 CString strAboutMenu
= "uiConfigMenuAbout";
173 if (!strAboutMenu
.IsEmpty())
175 pSysMenu
->AppendMenu(MF_SEPARATOR
);
176 pSysMenu
->AppendMenu(MF_STRING
, IDM_ABOUTBOX
, strAboutMenu
);
180 // Set the icon for this dialog. The framework does this automatically
181 // when the application's main window is not a dialog
182 SetIcon(m_hIcon
, TRUE
); // Set big icon
183 SetIcon(m_hIcon
, FALSE
); // Set small icon
187 for (i
=0; i
<BitmapCount
; i
++)
189 Bitmaps
[i
].LoadBitmap (BitmapId
[i
].ResId
);
192 // Create others controls
193 nlverify (Left
.Create (NULL
, WS_CHILD
|WS_VISIBLE
|SS_BITMAP
, CRect (0, 0, LEFT_WIDTH
, LEFT_HEIGHT
), this));
194 Left
.SetBitmap (LoadBitmap (theApp
.m_hInstance
, MAKEINTRESOURCE (IDB_LEFT_0
)));
195 nlverify (Icon
.Create (NULL
, WS_CHILD
|WS_VISIBLE
|SS_BITMAP
, CRect (ICON_START_X
, ICON_START_Y
, ICON_START_X
+ICON_WIDTH
, ICON_START_Y
+ICON_HEIGHT
), this));
196 Icon
.SetBitmap (Bitmaps
[BitmapWelcome
]);
199 nlverify (Top
.Create (CRect (LEFT_WIDTH
, BAR_HEIGHT
, LEFT_WIDTH
+ICON_ZONE_WIDTH
+BAR_WIDTH
, BAR_HEIGHT
+1), this));
200 nlverify (Bottom
.Create (CRect (0, LEFT_HEIGHT
, LEFT_WIDTH
+ICON_ZONE_WIDTH
+BAR_WIDTH
, LEFT_HEIGHT
+1), this));
203 nlverify (Tree
.Create ( WS_CHILD
|WS_VISIBLE
|TVS_NOSCROLL
|TVS_TRACKSELECT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_SHOWSELALWAYS
,
204 CRect (LEFT_WIDTH
+TREE_OFFSET_LEFT
, BAR_HEIGHT
+2+TREE_OFFSET_TOP
,
205 LEFT_WIDTH
+TREE_ZONE_WIDTH
, BAR_HEIGHT
+LEFT_HEIGHT
-BAR_HEIGHT
), this, TreeId
));
206 Tree
.SetFont (GetFont ());
209 nlverify (BarFont
.CreateFont (LARGE_LABEL_HEIGHT
, 0, 0, 0, FW_BOLD
, TRUE
, FALSE
, 0, DEFAULT_CHARSET
, OUT_TT_PRECIS
, CLIP_DEFAULT_PRECIS
, ANTIALIASED_QUALITY
,
210 TMPF_TRUETYPE
| DEFAULT_PITCH
| FF_MODERN
, "Arial"));
213 for (i
=0; i
<PageCount
; i
++)
215 nlverify (Dialogs
[i
]->Create (Pages
[i
].ResId
, this));
216 nlverify (Dialogs
[i
]->SetWindowPos (NULL
, LEFT_WIDTH
+TREE_ZONE_WIDTH
, BAR_HEIGHT
+2, 0, 0, SWP_NOZORDER
|SWP_NOSIZE
));
220 CPage
*page
= Root
.Children
[0];
221 HTREEITEM parent
= TVI_ROOT
;
225 parent
= Tree
.InsertItem ("", parent
);
226 Tree
.SetItemData (parent
, page
->PageId
);
228 Tree
.SetItemState (parent
, TVIS_BOLD
, TVIS_BOLD
);
231 if (page
->Children
.size ())
232 page
= page
->Children
[0];
239 if (page
->ChildId
< page
->Parent
->Children
.size ()-1)
241 page
= page
->Parent
->Children
[page
->ChildId
+1];
242 parent
= Tree
.GetParentItem (parent
);
248 parent
= Tree
.GetParentItem (parent
);
249 Tree
.Expand (parent
, TVE_EXPAND
);
257 ApplyCtrl
.EnableWindow (FALSE
);
259 // Get from the config file
260 GetFromConfigFile ();
262 theApp
.Modified
= false;
264 // Build the localisation map
265 backupWindowHandleRec ();
267 // Localize the windows
268 changeLanguage (::GetIntForceLanguage()?"en" : ::GetString ("LanguageCode").c_str());
269 theApp
.Localized
= true;
272 Tree
.SelectItem(Tree
.GetChildItem (Tree
.GetRootItem()));
275 return TRUE
; // return TRUE unless you set the focus to a control
278 // ***************************************************************************
280 void CClient_configDlg::changeLanguage (const char *language
)
283 NLMISC::CI18N::load(language
);
285 localizeWindowsRec ();
288 // Set the general page
289 setPage (_CurrentPage
);
291 DisplayDlg
.updateState ();
292 DisplayDlg
.UpdateData (FALSE
);
293 DisplayDetailsDlg
.updateState ();
294 SoundDlg
.updateState ();
297 setWindowText(*this, (WCHAR
*)((NLMISC::CI18N::get ("uiConfigTitle") + (theApp
.Modified
?" *":"")).c_str()));
300 CMenu
* pSysMenu
= GetSystemMenu(FALSE
);
303 if (NLMISC::CSystemUtils::supportUnicode())
305 nlverify (::ModifyMenuW(*pSysMenu
, IDM_ABOUTBOX
, MF_BYCOMMAND
|MF_STRING
, IDM_ABOUTBOX
, (WCHAR
*)NLMISC::CI18N::get ("uiConfigMenuAbout").c_str()));
309 nlverify (::ModifyMenu(*pSysMenu
, IDM_ABOUTBOX
, MF_BYCOMMAND
|MF_STRING
, IDM_ABOUTBOX
, (LPCTSTR
)NLMISC::CI18N::get ("uiConfigMenuAbout").toString().c_str()));
314 // ***************************************************************************
316 void CClient_configDlg::translateTree ()
319 HTREEITEM item
= Tree
.GetRootItem ();
323 uint page
= (uint
)Tree
.GetItemData (item
);
324 ucstring name
= NLMISC::CI18N::get (Pages
[page
].Name
);
325 if (NLMISC::CSystemUtils::supportUnicode())
328 memset (&itemDesc
, 0, sizeof(TVITEMEXW
));
329 itemDesc
.hItem
= item
;
330 itemDesc
.mask
= TVIF_TEXT
;
331 itemDesc
.pszText
= (WCHAR
*)name
.c_str();
332 nlverify (SendMessageW (Tree
, TVM_SETITEMW
, 0, (LPARAM
)&itemDesc
));
337 memset (&itemDesc
, 0, sizeof(TVITEMEXA
));
338 itemDesc
.hItem
= item
;
339 itemDesc
.mask
= TVIF_TEXT
;
340 std::string tmpStr
= name
.toString();
341 itemDesc
.pszText
= (LPSTR
) tmpStr
.c_str();
342 nlverify (::SendMessageA(Tree
, TVM_SETITEMA
, 0 , (LPARAM
)&itemDesc
));
345 HTREEITEM old
= item
;
346 item
= Tree
.GetChildItem (item
);
349 // No more child, try a brother
350 item
= Tree
.GetNextSiblingItem (old
);
354 // No more brother, try an oncle
355 item
= Tree
.GetParentItem (old
);
357 item
= Tree
.GetNextSiblingItem (item
);
362 // ***************************************************************************
364 void CClient_configDlg::OnSysCommand(UINT nID
, LPARAM lParam
)
366 if ((nID
& 0xFFF0) == IDM_ABOUTBOX
)
373 CDialog::OnSysCommand(nID
, lParam
);
377 // ***************************************************************************
379 // If you add a minimize button to your dialog, you will need the code below
380 // to draw the icon. For MFC applications using the document/view model,
381 // this is automatically done for you by the framework.
383 void CClient_configDlg::OnPaint()
387 CPaintDC
dc(this); // device context for painting
389 SendMessage(WM_ICONERASEBKGND
, (WPARAM
) dc
.GetSafeHdc(), 0);
391 // Center icon in client rectangle
392 int cxIcon
= GetSystemMetrics(SM_CXICON
);
393 int cyIcon
= GetSystemMetrics(SM_CYICON
);
395 GetClientRect(&rect
);
396 int x
= (rect
.Width() - cxIcon
+ 1) / 2;
397 int y
= (rect
.Height() - cyIcon
+ 1) / 2;
400 dc
.DrawIcon(x
, y
, m_hIcon
);
405 CPaintDC
dc(this); // device context for painting
406 dc
.FillSolidRect( LEFT_WIDTH
, BAR_HEIGHT
+2, TREE_ZONE_WIDTH
, LEFT_HEIGHT
-BAR_HEIGHT
-2, GetSysColor (COLOR_WINDOW
));
409 dc
.FillSolidRect( LEFT_WIDTH
, 0, ICON_ZONE_WIDTH
, BAR_HEIGHT
, RGB (255,255,255));
411 bitmapDC
.CreateCompatibleDC (&dc
);
412 bitmapDC
.SelectObject (&Bitmaps
[BitmapTopRight
]);
413 nlverify (dc
.BitBlt( LEFT_WIDTH
+ ICON_ZONE_WIDTH
, 0, BAR_WIDTH
, BAR_HEIGHT
, &bitmapDC
, 0, 0, SRCCOPY
));
416 dc
.SetBkMode (TRANSPARENT
);
417 dc
.SelectObject (&BarFont
);
418 CRect
labelRect (LARGE_LABEL_START_X
, LARGE_LABEL_START_Y
, LARGE_LABEL_END_X
, LARGE_LABEL_END_Y
);
419 DrawTextW (&(*dc
), (WCHAR
*)TopLargeLabel
.c_str (), (sint
)TopLargeLabel
.size (), &labelRect
, DT_LEFT
|DT_TOP
);
425 // ***************************************************************************
427 HCURSOR
CClient_configDlg::OnQueryDragIcon()
429 return (HCURSOR
) m_hIcon
;
432 // ***************************************************************************
434 void CClient_configDlg::setPage (uint pageId
)
436 CPage
&page
= Pages
[pageId
];
437 Icon
.SetBitmap (Bitmaps
[page
.Icon
]);
438 TopLargeLabel
= NLMISC::CI18N::get (std::string(page
.Name
));
440 // Hide all the dialog
442 for (i
=0; i
<PageCount
; i
++)
443 Dialogs
[i
]->ShowWindow (SW_HIDE
);
446 Dialogs
[pageId
]->ShowWindow (SW_SHOW
);
450 _CurrentPage
= pageId
;
453 // ***************************************************************************
455 BOOL
CClient_configDlg::OnNotify(WPARAM wParam
, LPARAM lParam
, LRESULT
* pResult
)
457 // TODO: Add your specialized code here and/or call the base class
458 int idCtrl
= (int) wParam
;
459 LPNMHDR pnmh
= (LPNMHDR
) lParam
;
470 HTREEITEM item
= Tree
.GetSelectedItem ();
474 uint pageId
= (uint
)Tree
.GetItemData (item
);
484 return CDialog::OnNotify(wParam
, lParam
, pResult
);
487 // ***************************************************************************
489 void CClient_configDlg::InvalidateBar ()
491 CRect
rect (BAR_START_X
, 0, BAR_START_X
+BAR_WIDTH
, BAR_HEIGHT
);
492 InvalidateRect (&rect
);
495 // ***************************************************************************
497 BOOL
CClient_configDlg::UpdateData ( BOOL bSaveAndValidate
)
501 for (i
=0; i
<PageCount
; i
++)
503 Dialogs
[i
]->UpdateData (bSaveAndValidate
);
506 return CDialog::UpdateData ( bSaveAndValidate
);
509 // ***************************************************************************
511 void CClient_configDlg::OnApply()
513 // Update config file
516 // Save the config file
520 theApp
.Modified
= false;
521 ApplyCtrl
.EnableWindow (FALSE
);
524 setWindowText(*this, (WCHAR
*)NLMISC::CI18N::get ("uiConfigTitle").c_str());
527 // ***************************************************************************
529 void CClient_configDlg::OnCancel()
534 // Quit without saving ?
535 if (theApp
.yesNo (NLMISC::CI18N::get ("uiConfigQuitWithoutSaving")))
544 // ***************************************************************************
546 void CClient_configDlg::OnOK()
550 // Update config file
553 // Save the config file
557 theApp
.Modified
= false;
563 // ***************************************************************************
565 void CClient_configDlg::OnDefault()
567 /* Yoyo: Don't use the preset dlg for now cause doesn't work everywhere
568 // Open the preset dialog
570 if (preset.DoModal () == IDOK)
572 // Reset the CFG to default
579 GetFromConfigFile ();
582 // Quit without saving ?
583 if (theApp
.yesNo (NLMISC::CI18N::get ("uiConfigRestaureDefault")))
585 // Reset the CFG to default
586 ResetConfigFileToDefault();
592 GetFromConfigFile ();
596 // ***************************************************************************
598 void CClient_configDlg::OnLaunch()
602 // Update config file
605 // Save the config file
609 theApp
.Modified
= false;
613 NLMISC::launchProgram("client_ryzom_rd.exe","");
618 // ***************************************************************************
620 BOOL
CAboutDlg::OnInitDialog()
622 CDialog::OnInitDialog();
624 localizeWindowsRec (this, false);
626 return TRUE
; // return TRUE unless you set the focus to a control
627 // EXCEPTION: OCX Property Pages should return FALSE