fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / writerperfect / source / common / WPFTEncodingDialog.cxx
blobdec775b295ee9ae0e08a9ca418573367bc855355
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <WPFTEncodingDialog.hxx>
22 namespace writerperfect
25 namespace
28 struct EncodingImplementation
31 static OUString const(s_encodings[]);
33 static int numEncodings();
34 static void insertEncodings(ListBox *box);
35 static void selectEncoding(ListBox *box, const OUString &encoding);
36 static OUString getEncoding(ListBox *box);
39 OUString const(EncodingImplementation::s_encodings[])=
41 OUString("MacArabic"), OUString("Arabic (Apple Macintosh)"),
42 OUString("CP864"), OUString("Arabic (DOS/OS2-864)"),
43 OUString("CP1006"), OUString("Arabic (IBM-1006)"),
44 OUString("CP1256"), OUString("Arabic (Windows-1256)"),
45 OUString("CP775"), OUString("Baltic (DOS/OS2-775)"),
46 OUString("CP1257"), OUString("Baltic (Windows-1257)"),
47 OUString("MacCeltic"), OUString("Celtic (Apple Macintosh)"),
48 OUString("MacCyrillic"), OUString("Cyrillic (Apple Macintosh)"),
49 OUString("CP855"), OUString("Cyrillic (DOS/OS2-855)"),
50 OUString("CP866"), OUString("Cyrillic (DOS/OS2-866/Russian)"),
51 OUString("CP1251"), OUString("Cyrillic (Windows-1251)"),
52 OUString("MacCEurope"), OUString("Eastern Europe (Apple Macintosh)"),
53 OUString("MacCroatian"), OUString("Eastern Europe (Apple Macintosh/Croatian)"),
54 OUString("MacRomanian"), OUString("Eastern Europe (Apple Macintosh/Romanian)"),
55 OUString("CP852"), OUString("Eastern Europe (DOS/OS2-852)"),
56 OUString("CP1250"), OUString("Eastern Europe (Windows-1250/WinLatin 2)"),
57 OUString("MacGreek"), OUString("Greek (Apple Macintosh)"),
58 OUString("CP737"), OUString("Greek (DOS/OS2-737)"),
59 OUString("CP869"), OUString("Greek (DOS/OS2-869/Greek-2)"),
60 OUString("CP875"), OUString("Greek (DOS/OS2-875)"),
61 OUString("CP1253"), OUString("Greek (Windows-1253)"),
62 OUString("MacHebrew"), OUString("Hebrew (Apple Macintosh)"),
63 OUString("CP424"), OUString("Hebrew (DOS/OS2-424)"),
64 OUString("CP856"), OUString("Hebrew (DOS/OS2-856)"),
65 OUString("CP862"), OUString("Hebrew (DOS/OS2-862)"),
66 OUString("CP1255"), OUString("Hebrew (Windows-1255)"),
67 OUString("CP500"), OUString("International (DOS/OS2-500)"),
68 OUString("MacThai"), OUString("Thai (Apple Macintosh)"),
69 OUString("CP874"), OUString("Thai (DOS/OS2-874)"),
70 OUString("MacTurkish"), OUString("Turkish (Apple Macintosh)"),
71 OUString("CP857"), OUString("Turkish (DOS/OS2-857)"),
72 OUString("CP1026"), OUString("Turkish (DOS/OS2-1026)"),
73 OUString("CP1254"), OUString("Turkish (Windows-1254)"),
74 OUString("CP1258"), OUString("Vietnamese (Windows-1258)"),
75 OUString("MacRoman"), OUString("Western Europe (Apple Macintosh)"),
76 OUString("MacIceland"), OUString("Western Europe (Apple Macintosh/Icelandic)"),
77 OUString("CP037"), OUString("Western Europe (DOS/OS2-037/US-Canada)"),
78 OUString("CP437"), OUString("Western Europe (DOS/OS2-437/US)"),
79 OUString("CP850"), OUString("Western Europe (DOS/OS2-850)"),
80 OUString("CP860"), OUString("Western Europe (DOS/OS2-860/Portuguese)"),
81 OUString("CP861"), OUString("Western Europe (DOS/OS2-861/Icelandic)"),
82 OUString("CP863"), OUString("Western Europe (DOS/OS2-863/French)"),
83 OUString("CP865"), OUString("Western Europe (DOS/OS2-865/Nordic)"),
84 OUString("CP1252"), OUString("Western Europe (Windows-1252/WinLatin 1)")
87 int EncodingImplementation::numEncodings()
89 return int(sizeof(s_encodings)/(2*sizeof(const OUString *)));
92 void EncodingImplementation::insertEncodings(ListBox *box)
94 sal_IntPtr num=sal_IntPtr(numEncodings());
95 for (sal_IntPtr i=0; i<num; ++i)
97 sal_IntPtr nAt=box->InsertEntry(s_encodings[2*i+1]);
98 box->SetEntryData(nAt, reinterpret_cast<void *>(i));
102 void EncodingImplementation::selectEncoding(ListBox *box, const OUString &encoding)
104 sal_IntPtr num=sal_IntPtr(numEncodings());
105 for (sal_IntPtr i=0; i<num; ++i)
107 if (encoding!=s_encodings[2*i]) continue;
108 box->SelectEntryPos(i);
109 return;
113 OUString EncodingImplementation::getEncoding(ListBox *box)
115 sal_IntPtr pos = reinterpret_cast<sal_IntPtr>(box->GetSelectEntryData());
116 if (pos<0||pos>=numEncodings())
117 return OUString();
118 return s_encodings[2*pos];
123 WPFTEncodingDialog::WPFTEncodingDialog(
124 const OUString &title, const OUString &encoding)
125 : ModalDialog(nullptr, "WPFTEncodingDialog", "writerperfect/ui/wpftencodingdialog.ui"),
126 m_pLbCharset(), m_pBtnOk(), m_pBtnCancel(), m_userHasCancelled(false)
128 get(m_pLbCharset, "comboboxtext");
129 get(m_pBtnOk, "ok");
130 get(m_pBtnCancel, "cancel");
132 m_pBtnCancel->SetClickHdl(LINK(this, WPFTEncodingDialog, CancelHdl));
134 EncodingImplementation::insertEncodings(m_pLbCharset);
135 m_pLbCharset->SetStyle(m_pLbCharset->GetStyle() | WB_SORT);
136 // m_pLbCharset->set_height_request(6 * m_pLbCharset->GetTextHeight());
137 m_pLbCharset->SetDoubleClickHdl(LINK(this, WPFTEncodingDialog, DoubleClickHdl));
138 EncodingImplementation::selectEncoding(m_pLbCharset, encoding);
139 m_pLbCharset->Show();
141 SetText(title);
144 WPFTEncodingDialog::~WPFTEncodingDialog()
146 disposeOnce();
149 OUString WPFTEncodingDialog::GetEncoding() const
151 return EncodingImplementation::getEncoding(m_pLbCharset);
154 IMPL_LINK_NOARG(WPFTEncodingDialog, CancelHdl)
156 m_userHasCancelled=true;
157 Close();
158 return 0;
161 IMPL_LINK(WPFTEncodingDialog, DoubleClickHdl, ListBox *, pLb)
163 if (pLb == m_pLbCharset)
165 m_pBtnOk->Click();
167 return 0;
170 void WPFTEncodingDialog::dispose()
172 m_pLbCharset.disposeAndClear();
173 m_pBtnOk.disposeAndClear();
174 m_pBtnCancel.disposeAndClear();
175 ModalDialog::dispose();
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */