LCOV - code coverage report
Current view: top level - writerperfect/source/common - WPFTEncodingDialog.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 5 54 9.3 %
Date: 2015-06-13 12:38:46 Functions: 4 16 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <WPFTEncodingDialog.hxx>
      21             : 
      22             : namespace writerperfect
      23             : {
      24             : 
      25             : namespace
      26             : {
      27             : 
      28             : struct EncodingImplementation
      29             : {
      30             : 
      31             :     static OUString const(s_encodings[]);
      32             : 
      33             :     static inline int numEncodings();
      34             :     static void insertEncodings(ListBox *box);
      35             :     static void selectEncoding(ListBox *box, const OUString &encoding);
      36             :     static OUString getEncoding(ListBox *box);
      37             : };
      38             : 
      39          20 : OUString const(EncodingImplementation::s_encodings[])=
      40             : {
      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)")
      85          10 : };
      86             : 
      87           0 : inline int EncodingImplementation::numEncodings()
      88             : {
      89           0 :     return int(sizeof(s_encodings)/(2*sizeof(const OUString *)));
      90             : }
      91             : 
      92           0 : void EncodingImplementation::insertEncodings(ListBox *box)
      93             : {
      94           0 :     sal_IntPtr num=sal_IntPtr(numEncodings());
      95           0 :     for (sal_IntPtr i=0; i<num; ++i)
      96             :     {
      97           0 :         sal_IntPtr nAt=box->InsertEntry(s_encodings[2*i+1]);
      98           0 :         box->SetEntryData(nAt, reinterpret_cast<void *>(i));
      99             :     }
     100           0 : }
     101             : 
     102           0 : void EncodingImplementation::selectEncoding(ListBox *box, const OUString &encoding)
     103             : {
     104           0 :     sal_IntPtr num=sal_IntPtr(numEncodings());
     105           0 :     for (sal_IntPtr i=0; i<num; ++i)
     106             :     {
     107           0 :         if (encoding!=s_encodings[2*i]) continue;
     108           0 :         box->SelectEntryPos(i);
     109           0 :         return;
     110             :     }
     111             : }
     112             : 
     113           0 : OUString EncodingImplementation::getEncoding(ListBox *box)
     114             : {
     115           0 :     sal_IntPtr pos = reinterpret_cast<sal_IntPtr>(box->GetSelectEntryData());
     116           0 :     if (pos<0||pos>=numEncodings())
     117           0 :         return OUString();
     118           0 :     return s_encodings[2*pos];
     119             : }
     120             : 
     121             : }
     122             : 
     123           3 : WPFTEncodingDialog::WPFTEncodingDialog(
     124             :     const OUString &title, const OUString &encoding)
     125             :     :   ModalDialog(nullptr, "WPFTEncodingDialog", "writerperfect/ui/wpftencodingdialog.ui"),
     126           6 :         m_pLbCharset(), m_pBtnOk(), m_pBtnCancel(), m_userHasCancelled(false)
     127             : {
     128           0 :     get(m_pLbCharset, "comboboxtext");
     129           0 :     get(m_pBtnOk, "ok");
     130           0 :     get(m_pBtnCancel, "cancel");
     131             : 
     132           0 :     m_pBtnCancel->SetClickHdl(LINK(this, WPFTEncodingDialog, CancelHdl));
     133             : 
     134           0 :     EncodingImplementation::insertEncodings(m_pLbCharset);
     135           0 :     m_pLbCharset->SetStyle(m_pLbCharset->GetStyle() | WB_SORT);
     136             :     // m_pLbCharset->set_height_request(6 * m_pLbCharset->GetTextHeight());
     137           0 :     m_pLbCharset->SetDoubleClickHdl(LINK(this, WPFTEncodingDialog, DoubleClickHdl));
     138           0 :     EncodingImplementation::selectEncoding(m_pLbCharset, encoding);
     139           0 :     m_pLbCharset->Show();
     140             : 
     141           0 :     SetText(title);
     142           0 : }
     143             : 
     144           0 : WPFTEncodingDialog::~WPFTEncodingDialog()
     145             : {
     146           0 :     disposeOnce();
     147           0 : }
     148             : 
     149           0 : OUString WPFTEncodingDialog::GetEncoding() const
     150             : {
     151           0 :     return EncodingImplementation::getEncoding(m_pLbCharset);
     152             : }
     153             : 
     154           0 : IMPL_LINK_NOARG(WPFTEncodingDialog, CancelHdl)
     155             : {
     156           0 :     m_userHasCancelled=true;
     157           0 :     Close();
     158           0 :     return 0;
     159             : }
     160             : 
     161           0 : IMPL_LINK(WPFTEncodingDialog, DoubleClickHdl, ListBox *, pLb)
     162             : {
     163           0 :     if (pLb == m_pLbCharset)
     164             :     {
     165           0 :         m_pBtnOk->Click();
     166             :     }
     167           0 :     return 0;
     168             : }
     169             : 
     170           0 : void WPFTEncodingDialog::dispose()
     171             : {
     172           0 :     m_pLbCharset.disposeAndClear();
     173           0 :     m_pBtnOk.disposeAndClear();
     174           0 :     m_pBtnCancel.disposeAndClear();
     175           0 :     ModalDialog::dispose();
     176           0 : }
     177             : 
     178          30 : }
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11