LibreOffice Module writerperfect (master) 1
WPFTEncodingDialog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#include <cstddef>
23#include <string_view>
24#include <utility>
25
27
28namespace writerperfect
29{
30namespace
31{
32std::pair<std::u16string_view, std::u16string_view> const s_encodings[]
33 = { { u"MacArabic", u"Arabic (Apple Macintosh)" },
34 { u"CP864", u"Arabic (DOS/OS2-864)" },
35 { u"CP1006", u"Arabic (IBM-1006)" },
36 { u"CP1256", u"Arabic (Windows-1256)" },
37 { u"CP775", u"Baltic (DOS/OS2-775)" },
38 { u"CP1257", u"Baltic (Windows-1257)" },
39 { u"MacCeltic", u"Celtic (Apple Macintosh)" },
40 { u"MacCyrillic", u"Cyrillic (Apple Macintosh)" },
41 { u"CP855", u"Cyrillic (DOS/OS2-855)" },
42 { u"CP866", u"Cyrillic (DOS/OS2-866/Russian)" },
43 { u"CP1251", u"Cyrillic (Windows-1251)" },
44 { u"MacCEurope", u"Eastern Europe (Apple Macintosh)" },
45 { u"MacCroatian", u"Eastern Europe (Apple Macintosh/Croatian)" },
46 { u"MacRomanian", u"Eastern Europe (Apple Macintosh/Romanian)" },
47 { u"CP852", u"Eastern Europe (DOS/OS2-852)" },
48 { u"CP1250", u"Eastern Europe (Windows-1250/WinLatin 2)" },
49 { u"MacGreek", u"Greek (Apple Macintosh)" },
50 { u"CP737", u"Greek (DOS/OS2-737)" },
51 { u"CP869", u"Greek (DOS/OS2-869/Greek-2)" },
52 { u"CP875", u"Greek (DOS/OS2-875)" },
53 { u"CP1253", u"Greek (Windows-1253)" },
54 { u"MacHebrew", u"Hebrew (Apple Macintosh)" },
55 { u"CP424", u"Hebrew (DOS/OS2-424)" },
56 { u"CP856", u"Hebrew (DOS/OS2-856)" },
57 { u"CP862", u"Hebrew (DOS/OS2-862)" },
58 { u"CP1255", u"Hebrew (Windows-1255)" },
59 { u"CP500", u"International (DOS/OS2-500)" },
60 { u"CP932", u"Japanese (Windows-932)" },
61 { u"MacThai", u"Thai (Apple Macintosh)" },
62 { u"CP874", u"Thai (DOS/OS2-874)" },
63 { u"CP950", u"Traditional Chinese (Windows-950)" },
64 { u"MacTurkish", u"Turkish (Apple Macintosh)" },
65 { u"CP857", u"Turkish (DOS/OS2-857)" },
66 { u"CP1026", u"Turkish (DOS/OS2-1026)" },
67 { u"CP1254", u"Turkish (Windows-1254)" },
68 { u"CP1258", u"Vietnamese (Windows-1258)" },
69 { u"MacRoman", u"Western Europe (Apple Macintosh)" },
70 { u"MacIceland", u"Western Europe (Apple Macintosh/Icelandic)" },
71 { u"CP037", u"Western Europe (DOS/OS2-037/US-Canada)" },
72 { u"CP437", u"Western Europe (DOS/OS2-437/US)" },
73 { u"CP850", u"Western Europe (DOS/OS2-850)" },
74 { u"CP860", u"Western Europe (DOS/OS2-860/Portuguese)" },
75 { u"CP861", u"Western Europe (DOS/OS2-861/Icelandic)" },
76 { u"CP863", u"Western Europe (DOS/OS2-863/French)" },
77 { u"CP865", u"Western Europe (DOS/OS2-865/Nordic)" },
78 { u"CP1252", u"Western Europe (Windows-1252/WinLatin 1)" } };
79
80std::size_t const numEncodings = SAL_N_ELEMENTS(s_encodings);
81
82void insertEncodings(weld::ComboBox& box)
83{
84 for (std::size_t i = 0; i < numEncodings; ++i)
85 box.append(OUString(s_encodings[i].first), OUString(s_encodings[i].second));
86}
87
88void selectEncoding(weld::ComboBox& box, const OUString& encoding) { box.set_active_id(encoding); }
89
90OUString getEncoding(const weld::ComboBox& box) { return box.get_active_id(); }
91}
92
94 const OUString& encoding)
95 : GenericDialogController(pParent, "writerperfect/ui/wpftencodingdialog.ui",
96 "WPFTEncodingDialog")
97 , m_userHasCancelled(false)
98 , m_xLbCharset(m_xBuilder->weld_combo_box("comboboxtext"))
99 , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
100{
101 m_xBtnCancel->connect_clicked(LINK(this, WPFTEncodingDialog, CancelHdl));
102
103 insertEncodings(*m_xLbCharset);
104 m_xLbCharset->make_sorted();
105 selectEncoding(*m_xLbCharset, encoding);
106
107 m_xDialog->set_title(title);
108}
109
111
112OUString WPFTEncodingDialog::GetEncoding() const { return getEncoding(*m_xLbCharset); }
113
115{
116 m_userHasCancelled = true;
117 m_xDialog->response(RET_CANCEL);
118}
119}
120
121/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
virtual OUString get_active_id() const=0
virtual void set_active_id(const OUString &rStr)=0
void append(const weld::ComboBoxEntry &rItem)
std::shared_ptr< weld::Dialog > m_xDialog
std::unique_ptr< weld::Button > m_xBtnCancel
WPFTEncodingDialog(weld::Window *pParent, const OUString &title, const OUString &defEncoding)
std::unique_ptr< weld::ComboBox > m_xLbCharset
float u
#define SAL_N_ELEMENTS(arr)
int i
IMPL_LINK_NOARG(WPFTEncodingDialog, CancelHdl, weld::Button &, void)
RET_CANCEL