summaryrefslogtreecommitdiff
path: root/writerperfect/source/common/WPFTEncodingDialog.cxx
blob: 30c02c48388b3758d0de505881d377fa960dd5da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <sal/config.h>

#include <cstddef>
#include <utility>

#include <WPFTEncodingDialog.hxx>

namespace writerperfect
{

namespace
{

std::pair<OUStringLiteral, OUStringLiteral> const s_encodings[] =
{
    {OUStringLiteral("MacArabic"), OUStringLiteral("Arabic (Apple Macintosh)")},
    {OUStringLiteral("CP864"), OUStringLiteral("Arabic (DOS/OS2-864)")},
    {OUStringLiteral("CP1006"), OUStringLiteral("Arabic (IBM-1006)")},
    {OUStringLiteral("CP1256"), OUStringLiteral("Arabic (Windows-1256)")},
    {OUStringLiteral("CP775"), OUStringLiteral("Baltic (DOS/OS2-775)")},
    {OUStringLiteral("CP1257"), OUStringLiteral("Baltic (Windows-1257)")},
    {OUStringLiteral("MacCeltic"), OUStringLiteral("Celtic (Apple Macintosh)")},
    {
        OUStringLiteral("MacCyrillic"),
        OUStringLiteral("Cyrillic (Apple Macintosh)")
    },
    {OUStringLiteral("CP855"), OUStringLiteral("Cyrillic (DOS/OS2-855)")},
    {
        OUStringLiteral("CP866"),
        OUStringLiteral("Cyrillic (DOS/OS2-866/Russian)")
    },
    {OUStringLiteral("CP1251"), OUStringLiteral("Cyrillic (Windows-1251)")},
    {
        OUStringLiteral("MacCEurope"),
        OUStringLiteral("Eastern Europe (Apple Macintosh)")
    },
    {
        OUStringLiteral("MacCroatian"),
        OUStringLiteral("Eastern Europe (Apple Macintosh/Croatian)")
    },
    {
        OUStringLiteral("MacRomanian"),
        OUStringLiteral("Eastern Europe (Apple Macintosh/Romanian)")
    },
    {OUStringLiteral("CP852"), OUStringLiteral("Eastern Europe (DOS/OS2-852)")},
    {
        OUStringLiteral("CP1250"),
        OUStringLiteral("Eastern Europe (Windows-1250/WinLatin 2)")
    },
    {OUStringLiteral("MacGreek"), OUStringLiteral("Greek (Apple Macintosh)")},
    {OUStringLiteral("CP737"), OUStringLiteral("Greek (DOS/OS2-737)")},
    {OUStringLiteral("CP869"), OUStringLiteral("Greek (DOS/OS2-869/Greek-2)")},
    {OUStringLiteral("CP875"), OUStringLiteral("Greek (DOS/OS2-875)")},
    {OUStringLiteral("CP1253"), OUStringLiteral("Greek (Windows-1253)")},
    {OUStringLiteral("MacHebrew"), OUStringLiteral("Hebrew (Apple Macintosh)")},
    {OUStringLiteral("CP424"), OUStringLiteral("Hebrew (DOS/OS2-424)")},
    {OUStringLiteral("CP856"), OUStringLiteral("Hebrew (DOS/OS2-856)")},
    {OUStringLiteral("CP862"), OUStringLiteral("Hebrew (DOS/OS2-862)")},
    {OUStringLiteral("CP1255"), OUStringLiteral("Hebrew (Windows-1255)")},
    {OUStringLiteral("CP500"), OUStringLiteral("International (DOS/OS2-500)")},
    {OUStringLiteral("CP932"), OUStringLiteral("Japanese (Windows-932)")},
    {OUStringLiteral("MacThai"), OUStringLiteral("Thai (Apple Macintosh)")},
    {OUStringLiteral("CP874"), OUStringLiteral("Thai (DOS/OS2-874)")},
    {
        OUStringLiteral("CP950"),
        OUStringLiteral("Traditional Chinese (Windows-950)")
    },
    {
        OUStringLiteral("MacTurkish"),
        OUStringLiteral("Turkish (Apple Macintosh)")
    },
    {OUStringLiteral("CP857"), OUStringLiteral("Turkish (DOS/OS2-857)")},
    {OUStringLiteral("CP1026"), OUStringLiteral("Turkish (DOS/OS2-1026)")},
    {OUStringLiteral("CP1254"), OUStringLiteral("Turkish (Windows-1254)")},
    {OUStringLiteral("CP1258"), OUStringLiteral("Vietnamese (Windows-1258)")},
    {
        OUStringLiteral("MacRoman"),
        OUStringLiteral("Western Europe (Apple Macintosh)")
    },
    {
        OUStringLiteral("MacIceland"),
        OUStringLiteral("Western Europe (Apple Macintosh/Icelandic)")
    },
    {
        OUStringLiteral("CP037"),
        OUStringLiteral("Western Europe (DOS/OS2-037/US-Canada)")
    },
    {
        OUStringLiteral("CP437"),
        OUStringLiteral("Western Europe (DOS/OS2-437/US)")
    },
    {OUStringLiteral("CP850"), OUStringLiteral("Western Europe (DOS/OS2-850)")},
    {
        OUStringLiteral("CP860"),
        OUStringLiteral("Western Europe (DOS/OS2-860/Portuguese)")
    },
    {
        OUStringLiteral("CP861"),
        OUStringLiteral("Western Europe (DOS/OS2-861/Icelandic)")
    },
    {
        OUStringLiteral("CP863"),
        OUStringLiteral("Western Europe (DOS/OS2-863/French)")
    },
    {
        OUStringLiteral("CP865"),
        OUStringLiteral("Western Europe (DOS/OS2-865/Nordic)")
    },
    {
        OUStringLiteral("CP1252"),
        OUStringLiteral("Western Europe (Windows-1252/WinLatin 1)")
    }
};

std::size_t const numEncodings = SAL_N_ELEMENTS(s_encodings);

void insertEncodings(ListBox *box)
{
    for (std::size_t i=0; i<numEncodings; ++i)
    {
        sal_IntPtr nAt=box->InsertEntry(s_encodings[i].second);
        box->SetEntryData(
            nAt, reinterpret_cast<void *>(static_cast<sal_uIntPtr>(i)));
    }
}

void selectEncoding(ListBox *box, const OUString &encoding)
{
    for (std::size_t i=0; i<numEncodings; ++i)
    {
        if (encoding!=s_encodings[i].first) continue;
        box->SelectEntryPos(i);
        return;
    }
}

OUString getEncoding(ListBox *box)
{
    sal_uIntPtr pos = reinterpret_cast<sal_uIntPtr>(box->GetSelectEntryData());
    if (pos>=numEncodings)
        return OUString();
    return s_encodings[pos].first;
}

}

WPFTEncodingDialog::WPFTEncodingDialog(
    const OUString &title, const OUString &encoding)
    :   ModalDialog(nullptr, "WPFTEncodingDialog", "writerperfect/ui/wpftencodingdialog.ui"),
        m_pLbCharset(), m_pBtnOk(), m_pBtnCancel(), m_userHasCancelled(false)
{
    get(m_pLbCharset, "comboboxtext");
    get(m_pBtnOk, "ok");
    get(m_pBtnCancel, "cancel");

    m_pBtnCancel->SetClickHdl(LINK(this, WPFTEncodingDialog, CancelHdl));

    insertEncodings(m_pLbCharset);
    m_pLbCharset->SetStyle(m_pLbCharset->GetStyle() | WB_SORT);
    // m_pLbCharset->set_height_request(6 * m_pLbCharset->GetTextHeight());
    m_pLbCharset->SetDoubleClickHdl(LINK(this, WPFTEncodingDialog, DoubleClickHdl));
    selectEncoding(m_pLbCharset, encoding);
    m_pLbCharset->Show();

    SetText(title);
}

WPFTEncodingDialog::~WPFTEncodingDialog()
{
    disposeOnce();
}

OUString WPFTEncodingDialog::GetEncoding() const
{
    return getEncoding(m_pLbCharset);
}

IMPL_LINK_NOARG_TYPED(WPFTEncodingDialog, CancelHdl, Button *, void)
{
    m_userHasCancelled=true;
    Close();
}

IMPL_LINK_TYPED(WPFTEncodingDialog, DoubleClickHdl, ListBox &, rLb, void)
{
    if (&rLb == m_pLbCharset)
    {
        m_pBtnOk->Click();
    }
}

void WPFTEncodingDialog::dispose()
{
    m_pLbCharset.disposeAndClear();
    m_pBtnOk.disposeAndClear();
    m_pBtnCancel.disposeAndClear();
    ModalDialog::dispose();
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */