LibreOffice Module svx (master)  1
papersizelistbox.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 <svx/strings.hrc>
21 #include <svx/dialmgr.hxx>
22 #include <svx/papersizelistbox.hxx>
23 #include <vcl/builderfactory.hxx>
24 #include "page.hrc"
25 
27  : ListBox( pParent, WB_BORDER | WB_DROPDOWN)
28 {
30 }
31 
33 
35 {
36  const std::pair<const char*, int>* pPaperAry = eApp == PaperSizeApp::Std ?
37  RID_SVXSTRARY_PAPERSIZE_STD : RID_SVXSTRARY_PAPERSIZE_DRAW;
38  sal_uInt32 nCnt = eApp == PaperSizeApp::Std ?
39  SAL_N_ELEMENTS(RID_SVXSTRARY_PAPERSIZE_STD) : SAL_N_ELEMENTS(RID_SVXSTRARY_PAPERSIZE_DRAW);
40 
41  for ( sal_uInt32 i = 0; i < nCnt; ++i )
42  {
43  OUString aStr = SvxResId(pPaperAry[i].first);
44  Paper eSize = static_cast<Paper>(pPaperAry[i].second);
45  sal_Int32 nPos = InsertEntry( aStr );
46  SetEntryData( nPos, reinterpret_cast<void*>(static_cast<sal_uLong>(eSize)) );
47  }
48 }
49 
50 void PaperSizeListBox::SetSelection( Paper ePreselectPaper )
51 {
52  sal_Int32 nEntryCount = GetEntryCount();
53  sal_Int32 nSelPos = LISTBOX_ENTRY_NOTFOUND;
54  sal_Int32 nUserPos = LISTBOX_ENTRY_NOTFOUND;
55 
56  for (sal_Int32 i = 0; i < nEntryCount; ++i )
57  {
58  Paper eTmp = static_cast<Paper>(reinterpret_cast<sal_uLong>(GetEntryData(i)));
59 
60  if ( eTmp == ePreselectPaper )
61  {
62  nSelPos = i;
63  break;
64  }
65 
66  if ( eTmp == PAPER_USER )
67  nUserPos = i;
68  }
69 
70  // preselect current paper format - #115915#: ePaper might not be in aPaperSizeBox so use PAPER_USER instead
71  SelectEntryPos( ( nSelPos != LISTBOX_ENTRY_NOTFOUND ) ? nSelPos : nUserPos );
72 }
73 
75 {
76  const sal_Int32 nPos = GetSelectedEntryPos();
77  Paper ePaper = static_cast<Paper>(reinterpret_cast<sal_uLong>(GetEntryData( nPos )));
78 
79  return ePaper;
80 }
81 
83 {
84  return Size(150, ListBox::GetOptimalSize().Height());
85 }
86 
87 SvxPaperSizeListBox::SvxPaperSizeListBox(std::unique_ptr<weld::ComboBox> pControl)
88  : m_xControl(std::move(pControl))
89 {
90  m_xControl->set_size_request(150, -1);
91 }
92 
94 {
95  const std::pair<const char*, int>* pPaperAry = eApp == PaperSizeApp::Std ?
96  RID_SVXSTRARY_PAPERSIZE_STD : RID_SVXSTRARY_PAPERSIZE_DRAW;
97  sal_uInt32 nCnt = eApp == PaperSizeApp::Std ?
98  SAL_N_ELEMENTS(RID_SVXSTRARY_PAPERSIZE_STD) : SAL_N_ELEMENTS(RID_SVXSTRARY_PAPERSIZE_DRAW);
99 
100  for ( sal_uInt32 i = 0; i < nCnt; ++i )
101  {
102  OUString aStr = SvxResId(pPaperAry[i].first);
103  Paper eSize = static_cast<Paper>(pPaperAry[i].second);
104  m_xControl->append(OUString::number(static_cast<sal_Int32>(eSize)), aStr);
105  }
106 }
107 
109 {
110  int nEntryCount = m_xControl->get_count();
111  int nSelPos = -1;
112  int nUserPos = -1;
113 
114  for (int i = 0; i < nEntryCount; ++i)
115  {
116  Paper eTmp = static_cast<Paper>(m_xControl->get_id(i).toInt32());
117  if (eTmp == ePreselectPaper)
118  {
119  nSelPos = i;
120  break;
121  }
122 
123  if (eTmp == PAPER_USER)
124  nUserPos = i;
125  }
126 
127  // preselect current paper format - #115915#: ePaper might not be in aPaperSizeBox so use PAPER_USER instead
128  m_xControl->set_active((nSelPos != -1) ? nSelPos : nUserPos);
129 }
130 
132 {
133  return static_cast<Paper>(m_xControl->get_active_id().toInt32());
134 }
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
137 
virtual Size GetOptimalSize() const override
sal_Int32 GetSelectedEntryPos(sal_Int32 nSelIndex=0) const
Reference< XControl > m_xControl
Paper GetSelection() const
sal_uIntPtr sal_uLong
Size GetOptimalSize() const override
void SetDropDownLineCount(sal_uInt16 nLines)
VCL_BUILDER_FACTORY(PaperSizeListBox)
void FillPaperSizeEntries(PaperSizeApp eApp)
#define LISTBOX_ENTRY_NOTFOUND
Paper
sal_Int32 GetEntryCount() const
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
void * GetEntryData(sal_Int32 nPos) const
#define SAL_N_ELEMENTS(arr)
void SelectEntryPos(sal_Int32 nPos, bool bSelect=true)
int i
sal_Int32 InsertEntry(const OUString &rStr, sal_Int32 nPos=LISTBOX_APPEND)
WinBits const WB_DROPDOWN
void SetSelection(Paper eSize)
Paper GetSelection() const
std::unique_ptr< weld::ComboBox > m_xControl
WinBits const WB_BORDER
void SetSelection(Paper eSize)
void FillPaperSizeEntries(PaperSizeApp eApp)
void SAL_CALL first(const css::awt::SpinEvent &rEvent) override
PaperSizeApp
void SetEntryData(sal_Int32 nPos, void *pNewData)
PaperSizeListBox(vcl::Window *pParent)
SvxPaperSizeListBox(std::unique_ptr< weld::ComboBox > pControl)
PAPER_USER
aStr
sal_uInt16 nPos