LibreOffice Module svx (master)  1
spacinglistbox.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 #include <svx/strings.hrc>
20 #include <svx/dialmgr.hxx>
21 #include <svx/spacinglistbox.hxx>
22 #include <vcl/builderfactory.hxx>
23 #include <spacing.hrc>
24 
26  : ListBox( pParent, WB_BORDER | WB_DROPDOWN)
27 {
28 }
29 
31 {
32  auto nSelected = GetSelectedEntryPos();
33  if (nSelected == LISTBOX_ENTRY_NOTFOUND)
34  nSelected = 0;
35  Clear();
36 
37  const std::pair<const char*, int>* pResources;
38  switch (eType)
39  {
41  pResources = RID_SVXSTRARY_SPACING_INCH;
42  break;
44  pResources = RID_SVXSTRARY_MARGINS_INCH;
45  break;
47  pResources = RID_SVXSTRARY_SPACING_CM;
48  break;
49  default:
51  pResources = RID_SVXSTRARY_MARGINS_CM;
52  break;
53  }
54 
55  while (pResources->first)
56  {
57  OUString aStr = SvxResId(pResources->first);
58  sal_uInt16 nData = pResources->second;
59  sal_Int32 nPos = InsertEntry( aStr );
60  SetEntryData( nPos, reinterpret_cast<void*>(static_cast<sal_uLong>(nData)) );
61  ++pResources;
62  }
63 
65  SelectEntryPos(nSelected);
66 }
67 
69 
71 {
72  return Size(150, ListBox::GetOptimalSize().Height());
73 }
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Size GetOptimalSize() const override
sal_Int32 GetSelectedEntryPos(sal_Int32 nSelIndex=0) const
void Init(SpacingType eType)
void SetDropDownLineCount(sal_uInt16 nLines)
void Clear()
#define LISTBOX_ENTRY_NOTFOUND
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
SpacingListBox(vcl::Window *pParent)
SpacingType
void SelectEntryPos(sal_Int32 nPos, bool bSelect=true)
sal_Int32 InsertEntry(const OUString &rStr, sal_Int32 nPos=LISTBOX_APPEND)
WinBits const WB_DROPDOWN
DocumentType const eType
Size GetOptimalSize() const override
WinBits const WB_BORDER
Custom Widget ListBox to hold entries for Spacing & Margin settings of Header/Footer.
VCL_BUILDER_FACTORY(SpacingListBox)
void SetEntryData(sal_Int32 nPos, void *pNewData)
aStr
sal_uInt16 nPos