4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "FontEdit.hpp"
25 #include "Dialogs/WidgetDialog.hpp"
26 #include "Look/DialogLook.hpp"
27 #include "Widget/RowFormWidget.hpp"
28 #include "Form/ActionListener.hpp"
29 #include "Screen/Layout.hpp"
30 #include "Screen/Font.hpp"
31 #include "Screen/LargeTextWindow.hpp"
32 #include "Form/DataField/Enum.hpp"
33 #include "Form/DataField/Listener.hpp"
34 #include "Util/StringUtil.hpp"
35 #include "UIGlobals.hpp"
36 #include "Language/Language.hpp"
40 #include "Screen/OpenGL/Cache.hpp"
53 class FontEditWidget final
54 : public RowFormWidget
, public ActionListener
, DataFieldListener
57 const LOGFONT
&default_data
;
62 FontEditWidget(const LOGFONT
&_data
, const LOGFONT
&_default_data
)
63 :RowFormWidget(UIGlobals::GetDialogLook()),
64 data(_data
), default_data(_default_data
) {}
66 const LOGFONT
&GetData() const {
74 /* methods from Widget */
75 virtual void Prepare(ContainerWindow
&parent
, const PixelRect
&rc
) override
;
77 /* methods from ActionListener */
78 virtual void OnAction(int id
) override
;
81 /* methods from DataFieldListener */
82 virtual void OnModified(DataField
&df
) override
;
86 FontEditWidget::Load()
90 DataFieldEnum
&df
= (DataFieldEnum
&)GetDataField(FACE
);
91 df
.SetStringAutoAdd(data
.lfFaceName
);
92 GetControl(FACE
).RefreshDisplay();
96 LoadValue(HEIGHT
, (int)data
.lfHeight
);
97 LoadValue(WEIGHT
, data
.lfWeight
> 500);
98 LoadValue(ITALIC
, !!data
.lfItalic
);
104 FontEditWidget::SaveValues()
107 CopyString(data
.lfFaceName
, GetDataField(FACE
).GetAsString(), LF_FACESIZE
);
110 data
.lfHeight
= GetValueInteger(HEIGHT
);
111 data
.lfWeight
= GetValueBoolean(WEIGHT
) ? 700 : 500;
112 data
.lfItalic
= GetValueBoolean(ITALIC
);
116 FontEditWidget::UpdatePreview()
118 /* revert to default font first, to avoid freeing the Font while it
119 is still being referenced */
120 LargeTextWindow
&preview
= (LargeTextWindow
&)GetGeneric(PREVIEW
);
121 preview
.SetFont(*GetLook().text_font
);
129 if (font
.IsDefined()) {
130 preview
.SetFont(font
);
131 preview
.SetText(_T("Sample Text\n123"));
133 preview
.SetText(_("Font not found."));
138 FontEditWidget::Prepare(ContainerWindow
&parent
, const PixelRect
&rc
)
140 RowFormWidget::Prepare(parent
, rc
);
143 WndProperty
*wp
= AddEnum(_("Font face"), NULL
, this);
145 DataFieldEnum
&df
= *(DataFieldEnum
*)wp
->GetDataField();
146 df
.addEnumText(_T("Tahoma"));
147 df
.addEnumText(_T("TahomaBD"));
148 df
.addEnumText(_T("DejaVu Sans Condensed"));
151 /* we cannot obtain a list of fonts on SDL/OpenGL currently */
154 AddInteger(_("Height"), NULL
, _T("%d"), _T("%d"), 1, 200, 1, 0, this);
155 AddBoolean(_("Bold"), NULL
, false, this);
156 AddBoolean(_("Italic"), NULL
, false, this);
158 PixelRect preview_rc
{ 0, 0, Layout::Scale(250), Layout::Scale(100) };
159 LargeTextWindowStyle preview_style
;
160 preview_style
.Border();
161 LargeTextWindow
*preview
= new LargeTextWindow();
162 preview
->Create(*(ContainerWindow
*)GetWindow(), preview_rc
, preview_style
);
169 FontEditWidget::OnModified(DataField
&df
)
176 FontEditWidget::OnAction(int id
)
183 dlgFontEditShowModal(const TCHAR
*type
, LOGFONT
&data
,
184 const LOGFONT
&default_data
)
186 StaticString
<128> title
;
187 title
.Format(_T("%s: %s"), _("Edit Font"), type
);
189 FontEditWidget
*widget
=
190 new FontEditWidget(data
, default_data
);
192 WidgetDialog
dialog(UIGlobals::GetDialogLook());
193 dialog
.CreateAuto(UIGlobals::GetMainWindow(), title
, widget
);
194 dialog
.AddButton(_("OK"), mrOK
);
195 dialog
.AddButton(_("Reset"), *widget
, 1);
196 dialog
.AddButton(_("Cancel"), mrCancel
);
198 if (dialog
.ShowModal() != mrOK
)
201 data
= widget
->GetData();