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 <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>
27 :
28 : #include <docstyle.hxx>
29 :
30 : #include "fldbas.hxx"
31 : #include "lineinfo.hxx"
32 : #include "linenum.hxx"
33 : #include "uitool.hxx"
34 : #include <fmtline.hxx>
35 :
36 : #include <IDocumentStylePoolAccess.hxx>
37 :
38 0 : static rtl::Reference<SwDocStyleSheet> lcl_getDocStyleSheet(const OUString& rName, SwWrtShell *pSh)
39 : {
40 0 : sal_uInt16 nFamily = SFX_STYLE_FAMILY_PARA;
41 0 : SfxStyleSheetBasePool* mpBase = pSh->GetView().GetDocShell()->GetStyleSheetPool();
42 0 : SfxStyleSheetBase* pStyle = mpBase->Find(rName, (SfxStyleFamily)nFamily);
43 : SAL_WARN_IF( !pStyle, "linenumbering.ui", "Style not found" );
44 0 : if(!pStyle)
45 0 : return NULL;
46 0 : return new SwDocStyleSheet(*(SwDocStyleSheet*)pStyle);
47 : }
48 :
49 0 : static void lcl_setLineNumbering(const OUString& rName, SwWrtShell* pSh, bool bLineNumber)
50 : {
51 0 : rtl::Reference<SwDocStyleSheet> xStyleSheet = lcl_getDocStyleSheet(rName, pSh);
52 0 : if(!xStyleSheet.is())
53 0 : return;
54 0 : SfxItemSet& rSet = xStyleSheet->GetItemSet();
55 0 : SwFmtLineNumber aFmt;
56 0 : aFmt.SetCountLines(bLineNumber);
57 0 : rSet.Put(aFmt);
58 0 : xStyleSheet->MergeIndentAttrsOfListStyle( rSet );
59 0 : xStyleSheet->SetItemSet(rSet, false);
60 : }
61 :
62 0 : SwLineNumberingDlg::SwLineNumberingDlg(SwView *pVw)
63 0 : : SfxModalDialog( &pVw->GetViewFrame()->GetWindow(), "LineNumberingDialog",
64 : "modules/swriter/ui/linenumbering.ui" )
65 0 : , pSh(pVw->GetWrtShellPtr())
66 : {
67 0 : get(m_pBodyContent, "content");
68 0 : get(m_pDivIntervalFT, "every");
69 0 : get(m_pDivIntervalNF, "linesspin");
70 0 : get(m_pDivRowsFT, "lines");
71 0 : get(m_pNumIntervalNF, "intervalspin");
72 0 : get(m_pCharStyleLB, "styledropdown");
73 0 : get(m_pFormatLB, "formatdropdown");
74 0 : get(m_pPosLB, "positiondropdown");
75 0 : get(m_pOffsetMF, "spacingspin");
76 0 : get(m_pDivisorED, "textentry");
77 0 : get(m_pCountEmptyLinesCB, "blanklines");
78 0 : get(m_pCountFrameLinesCB, "linesintextframes");
79 0 : get(m_pRestartEachPageCB, "restarteverynewpage");
80 0 : get(m_pNumberingOnCB, "shownumbering");
81 0 : get(m_pNumberingOnFooterHeader, "showfooterheadernumbering");
82 :
83 0 : OUString sIntervalName = m_pDivIntervalFT->GetAccessibleName();
84 0 : sIntervalName += "(";
85 0 : sIntervalName += m_pDivRowsFT->GetAccessibleName();
86 0 : sIntervalName += ")";
87 0 : m_pDivIntervalNF->SetAccessibleName(sIntervalName);
88 :
89 0 : vcl::Window *pNumIntervalFT = get<vcl::Window>("interval");
90 0 : vcl::Window *pNumRowsFT = get<vcl::Window>("intervallines");
91 0 : sIntervalName = pNumIntervalFT->GetAccessibleName();
92 0 : sIntervalName += "(";
93 0 : sIntervalName += pNumRowsFT->GetAccessibleName();
94 0 : sIntervalName += ")";
95 0 : m_pNumIntervalNF->SetAccessibleName(sIntervalName);
96 :
97 : // char styles
98 0 : ::FillCharStyleListBox(*m_pCharStyleLB, pSh->GetView().GetDocShell());
99 :
100 0 : const SwLineNumberInfo &rInf = pSh->GetLineNumberInfo();
101 0 : IDocumentStylePoolAccess* pIDSPA = pSh->getIDocumentStylePoolAccess();
102 :
103 0 : OUString sStyleName(rInf.GetCharFmt( *pIDSPA )->GetName());
104 0 : const sal_Int32 nPos = m_pCharStyleLB->GetEntryPos(sStyleName);
105 :
106 0 : if (nPos != LISTBOX_ENTRY_NOTFOUND)
107 0 : m_pCharStyleLB->SelectEntryPos(nPos);
108 : else
109 : {
110 0 : if (!sStyleName.isEmpty())
111 : {
112 0 : m_pCharStyleLB->InsertEntry(sStyleName);
113 0 : m_pCharStyleLB->SelectEntry(sStyleName);
114 : }
115 : }
116 :
117 : // format
118 0 : sal_uInt16 nSelFmt = rInf.GetNumType().GetNumberingType();
119 :
120 0 : m_pFormatLB->SelectNumberingType(nSelFmt);
121 :
122 : // position
123 0 : m_pPosLB->SelectEntryPos((sal_Int32)rInf.GetPos());
124 :
125 : // offset
126 0 : sal_uInt16 nOffset = rInf.GetPosFromLeft();
127 0 : if (nOffset == USHRT_MAX)
128 0 : nOffset = 0;
129 :
130 0 : m_pOffsetMF->SetValue(m_pOffsetMF->Normalize(nOffset), FUNIT_TWIP);
131 :
132 : // numbering offset
133 0 : m_pNumIntervalNF->SetValue(rInf.GetCountBy());
134 :
135 : // divider
136 0 : m_pDivisorED->SetText(rInf.GetDivider());
137 :
138 : // divider offset
139 0 : m_pDivIntervalNF->SetValue(rInf.GetDividerCountBy());
140 :
141 : // count
142 0 : m_pCountEmptyLinesCB->Check(rInf.IsCountBlankLines());
143 0 : m_pCountFrameLinesCB->Check(rInf.IsCountInFlys());
144 0 : m_pRestartEachPageCB->Check(rInf.IsRestartEachPage());
145 :
146 0 : m_pNumberingOnCB->Check(rInf.IsPaintLineNumbers());
147 :
148 : // Header/Footer Line Numbering
149 0 : rtl::Reference< SwDocStyleSheet > xStyleSheet = lcl_getDocStyleSheet("Footer", pSh);
150 0 : if(xStyleSheet.is())
151 : {
152 0 : SfxItemSet& rSet = xStyleSheet->GetItemSet();
153 0 : SwFmtLineNumber &aFmt = (SwFmtLineNumber&)(rSet.Get(RES_LINENUMBER));
154 0 : if(aFmt.IsCount())
155 0 : m_pNumberingOnFooterHeader->SetState(TRISTATE_TRUE);
156 : else
157 0 : m_pNumberingOnFooterHeader->SetState(TRISTATE_FALSE);
158 : }
159 :
160 : // Line Numbering
161 0 : m_pNumberingOnCB->SetClickHdl(LINK(this, SwLineNumberingDlg, LineOnOffHdl));
162 0 : m_pDivisorED->SetModifyHdl(LINK(this, SwLineNumberingDlg, ModifyHdl));
163 0 : ModifyHdl();
164 0 : LineOnOffHdl();
165 :
166 0 : get<PushButton>("ok")->SetClickHdl(LINK(this, SwLineNumberingDlg, OKHdl));
167 0 : }
168 :
169 0 : SwLineNumberingDlg::~SwLineNumberingDlg()
170 : {
171 0 : }
172 :
173 0 : IMPL_LINK_NOARG(SwLineNumberingDlg, OKHdl)
174 : {
175 0 : SwLineNumberInfo aInf(pSh->GetLineNumberInfo());
176 :
177 : // char styles
178 0 : OUString sCharFmtName(m_pCharStyleLB->GetSelectEntry());
179 0 : SwCharFmt *pCharFmt = pSh->FindCharFmtByName(sCharFmtName);
180 :
181 0 : if (!pCharFmt)
182 : {
183 0 : SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
184 : SfxStyleSheetBase* pBase;
185 0 : pBase = pPool->Find(sCharFmtName, SFX_STYLE_FAMILY_CHAR);
186 0 : if(!pBase)
187 0 : pBase = &pPool->Make(sCharFmtName, SFX_STYLE_FAMILY_CHAR);
188 0 : pCharFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
189 : }
190 :
191 0 : if (pCharFmt)
192 0 : aInf.SetCharFmt(pCharFmt);
193 :
194 : // format
195 0 : SvxNumberType aType;
196 0 : aType.SetNumberingType(m_pFormatLB->GetSelectedNumberingType());
197 0 : aInf.SetNumType(aType);
198 :
199 : // position
200 0 : aInf.SetPos((LineNumberPosition)m_pPosLB->GetSelectEntryPos());
201 :
202 : // offset
203 0 : aInf.SetPosFromLeft((sal_uInt16)m_pOffsetMF->Denormalize(m_pOffsetMF->GetValue(FUNIT_TWIP)));
204 :
205 : // numbering offset
206 0 : aInf.SetCountBy((sal_uInt16)m_pNumIntervalNF->GetValue());
207 :
208 : // divider
209 0 : aInf.SetDivider(m_pDivisorED->GetText());
210 :
211 : // divider offset
212 0 : aInf.SetDividerCountBy((sal_uInt16)m_pDivIntervalNF->GetValue());
213 :
214 : // count
215 0 : aInf.SetCountBlankLines(m_pCountEmptyLinesCB->IsChecked());
216 0 : aInf.SetCountInFlys(m_pCountFrameLinesCB->IsChecked());
217 0 : aInf.SetRestartEachPage(m_pRestartEachPageCB->IsChecked());
218 :
219 0 : aInf.SetPaintLineNumbers(m_pNumberingOnCB->IsChecked());
220 :
221 0 : pSh->SetLineNumberInfo(aInf);
222 :
223 : // Set LineNumber explicitly for Header and Footer
224 0 : lcl_setLineNumbering("Footer",pSh,m_pNumberingOnFooterHeader->IsChecked());
225 0 : lcl_setLineNumbering("Header",pSh,m_pNumberingOnFooterHeader->IsChecked());
226 0 : if( m_pNumberingOnFooterHeader->IsChecked())
227 0 : m_pNumberingOnFooterHeader->SetState(TRISTATE_TRUE);
228 : else
229 0 : m_pNumberingOnFooterHeader->SetState(TRISTATE_FALSE);
230 :
231 0 : EndDialog( RET_OK );
232 :
233 0 : return 0;
234 : }
235 :
236 : // modify
237 0 : IMPL_LINK_NOARG(SwLineNumberingDlg, ModifyHdl)
238 : {
239 0 : bool bEnable = m_pNumberingOnCB->IsChecked() && !m_pDivisorED->GetText().isEmpty();
240 :
241 0 : m_pDivIntervalFT->Enable(bEnable);
242 0 : m_pDivIntervalNF->Enable(bEnable);
243 0 : m_pDivRowsFT->Enable(bEnable);
244 :
245 0 : return 0;
246 : }
247 :
248 : // On/Off
249 0 : IMPL_LINK_NOARG(SwLineNumberingDlg, LineOnOffHdl)
250 : {
251 0 : bool bEnable = m_pNumberingOnCB->IsChecked();
252 0 : m_pBodyContent->Enable(bEnable);
253 0 : ModifyHdl();
254 0 : return 0;
255 0 : }
256 :
257 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|