bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / misc / linenum.cxx
blob5aa6859f807a3a28a3638539502d53e02cab77ec
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 <sfx2/viewfrm.hxx>
21 #include <svl/style.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <view.hxx>
24 #include <wrtsh.hxx>
25 #include <docsh.hxx>
26 #include <charfmt.hxx>
28 #include <docstyle.hxx>
30 #include "fldbas.hxx"
31 #include "lineinfo.hxx"
32 #include "linenum.hxx"
33 #include "uitool.hxx"
35 #include <IDocumentStylePoolAccess.hxx>
37 SwLineNumberingDlg::SwLineNumberingDlg(SwView *pVw)
38 : SfxModalDialog( &pVw->GetViewFrame()->GetWindow(), "LineNumberingDialog",
39 "modules/swriter/ui/linenumbering.ui" )
40 , pSh(pVw->GetWrtShellPtr())
42 get(m_pBodyContent, "content");
43 get(m_pDivIntervalFT, "every");
44 get(m_pDivIntervalNF, "linesspin");
45 get(m_pDivRowsFT, "lines");
46 get(m_pNumIntervalNF, "intervalspin");
47 get(m_pCharStyleLB, "styledropdown");
48 get(m_pFormatLB, "formatdropdown");
49 get(m_pPosLB, "positiondropdown");
50 get(m_pOffsetMF, "spacingspin");
51 get(m_pDivisorED, "textentry");
52 get(m_pCountEmptyLinesCB, "blanklines");
53 get(m_pCountFrameLinesCB, "linesintextframes");
54 get(m_pRestartEachPageCB, "restarteverynewpage");
55 get(m_pNumberingOnCB, "shownumbering");
57 String sIntervalName = m_pDivIntervalFT->GetAccessibleName();
58 sIntervalName += OUString("(");
59 sIntervalName += m_pDivRowsFT->GetAccessibleName();
60 sIntervalName += OUString(")");
61 m_pDivIntervalNF->SetAccessibleName(sIntervalName);
63 Window *pNumIntervalFT = get<Window>("interval");
64 Window *pNumRowsFT = get<Window>("intervallines");
65 sIntervalName = pNumIntervalFT->GetAccessibleName();
66 sIntervalName += OUString("(");
67 sIntervalName += pNumRowsFT->GetAccessibleName();
68 sIntervalName += OUString(")");
69 m_pNumIntervalNF->SetAccessibleName(sIntervalName);
71 // char styles
72 ::FillCharStyleListBox(*m_pCharStyleLB, pSh->GetView().GetDocShell());
74 const SwLineNumberInfo &rInf = pSh->GetLineNumberInfo();
75 IDocumentStylePoolAccess* pIDSPA = pSh->getIDocumentStylePoolAccess();
77 String sStyleName(rInf.GetCharFmt( *pIDSPA )->GetName());
78 const sal_uInt16 nPos = m_pCharStyleLB->GetEntryPos(sStyleName);
80 if (nPos != LISTBOX_ENTRY_NOTFOUND)
81 m_pCharStyleLB->SelectEntryPos(nPos);
82 else
84 if (sStyleName.Len())
86 m_pCharStyleLB->InsertEntry(sStyleName);
87 m_pCharStyleLB->SelectEntry(sStyleName);
91 // format
92 sal_uInt16 nSelFmt = rInf.GetNumType().GetNumberingType();
94 m_pFormatLB->SelectNumberingType(nSelFmt);
96 // position
97 m_pPosLB->SelectEntryPos((sal_uInt16)rInf.GetPos());
99 // offset
100 sal_uInt16 nOffset = rInf.GetPosFromLeft();
101 if (nOffset == USHRT_MAX)
102 nOffset = 0;
104 m_pOffsetMF->SetValue(m_pOffsetMF->Normalize(nOffset), FUNIT_TWIP);
106 // numbering offset
107 m_pNumIntervalNF->SetValue(rInf.GetCountBy());
109 // divider
110 m_pDivisorED->SetText(rInf.GetDivider());
112 // divider offset
113 m_pDivIntervalNF->SetValue(rInf.GetDividerCountBy());
115 // count
116 m_pCountEmptyLinesCB->Check(rInf.IsCountBlankLines());
117 m_pCountFrameLinesCB->Check(rInf.IsCountInFlys());
118 m_pRestartEachPageCB->Check(rInf.IsRestartEachPage());
120 m_pNumberingOnCB->Check(rInf.IsPaintLineNumbers());
122 m_pNumberingOnCB->SetClickHdl(LINK(this, SwLineNumberingDlg, LineOnOffHdl));
123 m_pDivisorED->SetModifyHdl(LINK(this, SwLineNumberingDlg, ModifyHdl));
124 ModifyHdl();
125 LineOnOffHdl();
127 get<PushButton>("ok")->SetClickHdl(LINK(this, SwLineNumberingDlg, OKHdl));
130 SwLineNumberingDlg::~SwLineNumberingDlg()
134 IMPL_LINK_NOARG(SwLineNumberingDlg, OKHdl)
136 SwLineNumberInfo aInf(pSh->GetLineNumberInfo());
138 // char styles
139 String sCharFmtName(m_pCharStyleLB->GetSelectEntry());
140 SwCharFmt *pCharFmt = pSh->FindCharFmtByName(sCharFmtName);
142 if (!pCharFmt)
144 SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
145 SfxStyleSheetBase* pBase;
146 pBase = pPool->Find(sCharFmtName, SFX_STYLE_FAMILY_CHAR);
147 if(!pBase)
148 pBase = &pPool->Make(sCharFmtName, SFX_STYLE_FAMILY_CHAR);
149 pCharFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
152 if (pCharFmt)
153 aInf.SetCharFmt(pCharFmt);
155 // format
156 SvxNumberType aType;
157 aType.SetNumberingType(m_pFormatLB->GetSelectedNumberingType());
158 aInf.SetNumType(aType);
160 // position
161 aInf.SetPos((LineNumberPosition)m_pPosLB->GetSelectEntryPos());
163 // offset
164 aInf.SetPosFromLeft((sal_uInt16)m_pOffsetMF->Denormalize(m_pOffsetMF->GetValue(FUNIT_TWIP)));
166 // numbering offset
167 aInf.SetCountBy((sal_uInt16)m_pNumIntervalNF->GetValue());
169 // divider
170 aInf.SetDivider(m_pDivisorED->GetText());
172 // divider offset
173 aInf.SetDividerCountBy((sal_uInt16)m_pDivIntervalNF->GetValue());
175 // count
176 aInf.SetCountBlankLines(m_pCountEmptyLinesCB->IsChecked());
177 aInf.SetCountInFlys(m_pCountFrameLinesCB->IsChecked());
178 aInf.SetRestartEachPage(m_pRestartEachPageCB->IsChecked());
180 aInf.SetPaintLineNumbers(m_pNumberingOnCB->IsChecked());
182 pSh->SetLineNumberInfo(aInf);
184 EndDialog( RET_OK );
186 return 0;
189 /*--------------------------------------------------------------------
190 Description: modify
191 --------------------------------------------------------------------*/
192 IMPL_LINK_NOARG(SwLineNumberingDlg, ModifyHdl)
194 bool bEnable = m_pNumberingOnCB->IsChecked() && !m_pDivisorED->GetText().isEmpty();
196 m_pDivIntervalFT->Enable(bEnable);
197 m_pDivIntervalNF->Enable(bEnable);
198 m_pDivRowsFT->Enable(bEnable);
200 return 0;
203 /*--------------------------------------------------------------------
204 Description: On/Off
205 --------------------------------------------------------------------*/
206 IMPL_LINK_NOARG(SwLineNumberingDlg, LineOnOffHdl)
208 bool bEnable = m_pNumberingOnCB->IsChecked();
209 m_pBodyContent->Enable(bEnable);
210 ModifyHdl();
211 return 0;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */