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 <utility>
24 
25 #include <WPFTEncodingDialog.hxx>
26 
27 namespace writerperfect
28 {
29 namespace
30 {
31 std::pair<OUStringLiteral, OUStringLiteral> const s_encodings[]
32     = { { "MacArabic", "Arabic (Apple Macintosh)" },
33         { "CP864", "Arabic (DOS/OS2-864)" },
34         { "CP1006", "Arabic (IBM-1006)" },
35         { "CP1256", "Arabic (Windows-1256)" },
36         { "CP775", "Baltic (DOS/OS2-775)" },
37         { "CP1257", "Baltic (Windows-1257)" },
38         { "MacCeltic", "Celtic (Apple Macintosh)" },
39         { "MacCyrillic", "Cyrillic (Apple Macintosh)" },
40         { "CP855", "Cyrillic (DOS/OS2-855)" },
41         { "CP866", "Cyrillic (DOS/OS2-866/Russian)" },
42         { "CP1251", "Cyrillic (Windows-1251)" },
43         { "MacCEurope", "Eastern Europe (Apple Macintosh)" },
44         { "MacCroatian", "Eastern Europe (Apple Macintosh/Croatian)" },
45         { "MacRomanian", "Eastern Europe (Apple Macintosh/Romanian)" },
46         { "CP852", "Eastern Europe (DOS/OS2-852)" },
47         { "CP1250", "Eastern Europe (Windows-1250/WinLatin 2)" },
48         { "MacGreek", "Greek (Apple Macintosh)" },
49         { "CP737", "Greek (DOS/OS2-737)" },
50         { "CP869", "Greek (DOS/OS2-869/Greek-2)" },
51         { "CP875", "Greek (DOS/OS2-875)" },
52         { "CP1253", "Greek (Windows-1253)" },
53         { "MacHebrew", "Hebrew (Apple Macintosh)" },
54         { "CP424", "Hebrew (DOS/OS2-424)" },
55         { "CP856", "Hebrew (DOS/OS2-856)" },
56         { "CP862", "Hebrew (DOS/OS2-862)" },
57         { "CP1255", "Hebrew (Windows-1255)" },
58         { "CP500", "International (DOS/OS2-500)" },
59         { "CP932", "Japanese (Windows-932)" },
60         { "MacThai", "Thai (Apple Macintosh)" },
61         { "CP874", "Thai (DOS/OS2-874)" },
62         { "CP950", "Traditional Chinese (Windows-950)" },
63         { "MacTurkish", "Turkish (Apple Macintosh)" },
64         { "CP857", "Turkish (DOS/OS2-857)" },
65         { "CP1026", "Turkish (DOS/OS2-1026)" },
66         { "CP1254", "Turkish (Windows-1254)" },
67         { "CP1258", "Vietnamese (Windows-1258)" },
68         { "MacRoman", "Western Europe (Apple Macintosh)" },
69         { "MacIceland", "Western Europe (Apple Macintosh/Icelandic)" },
70         { "CP037", "Western Europe (DOS/OS2-037/US-Canada)" },
71         { "CP437", "Western Europe (DOS/OS2-437/US)" },
72         { "CP850", "Western Europe (DOS/OS2-850)" },
73         { "CP860", "Western Europe (DOS/OS2-860/Portuguese)" },
74         { "CP861", "Western Europe (DOS/OS2-861/Icelandic)" },
75         { "CP863", "Western Europe (DOS/OS2-863/French)" },
76         { "CP865", "Western Europe (DOS/OS2-865/Nordic)" },
77         { "CP1252", "Western Europe (Windows-1252/WinLatin 1)" } };
78 
79 std::size_t const numEncodings = SAL_N_ELEMENTS(s_encodings);
80 
81 void insertEncodings(weld::ComboBoxText& box)
82 {
83     for (std::size_t i = 0; i < numEncodings; ++i)
84         box.append(s_encodings[i].first, s_encodings[i].second);
85 }
86 
87 void selectEncoding(weld::ComboBoxText& box, const OUString& encoding)
88 {
89     box.set_active_id(encoding);
90 }
91 
92 OUString getEncoding(const weld::ComboBoxText& box) { return box.get_active_id(); }
93 }
94 
95 WPFTEncodingDialog::WPFTEncodingDialog(weld::Window* pParent, const OUString& title,
96                                        const OUString& encoding)
97     : GenericDialogController(pParent, "writerperfect/ui/wpftencodingdialog.ui",
98                               "WPFTEncodingDialog")
99     , m_userHasCancelled(false)
100     , m_xLbCharset(m_xBuilder->weld_combo_box_text("comboboxtext"))
101     , m_xBtnOk(m_xBuilder->weld_button("ok"))
102     , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
103 {
104     m_xBtnCancel->connect_clicked(LINK(this, WPFTEncodingDialog, CancelHdl));
105 
106     insertEncodings(*m_xLbCharset);
107     m_xLbCharset->make_sorted();
108     selectEncoding(*m_xLbCharset, encoding);
109 
110     m_xDialog->set_title(title);
111 }
112 
113 WPFTEncodingDialog::~WPFTEncodingDialog() {}
114 
115 OUString WPFTEncodingDialog::GetEncoding() const { return getEncoding(*m_xLbCharset); }
116 
117 IMPL_LINK_NOARG(WPFTEncodingDialog, CancelHdl, weld::Button&, void)
118 {
119     m_userHasCancelled = true;
120     m_xDialog->response(RET_CANCEL);
121 }
122 }
123 
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
125