1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
26 #include <charfmt.hxx>
28 #include <docstyle.hxx>
31 #include "lineinfo.hxx"
32 #include "linenum.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
);
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
);
86 m_pCharStyleLB
->InsertEntry(sStyleName
);
87 m_pCharStyleLB
->SelectEntry(sStyleName
);
92 sal_uInt16 nSelFmt
= rInf
.GetNumType().GetNumberingType();
94 m_pFormatLB
->SelectNumberingType(nSelFmt
);
97 m_pPosLB
->SelectEntryPos((sal_uInt16
)rInf
.GetPos());
100 sal_uInt16 nOffset
= rInf
.GetPosFromLeft();
101 if (nOffset
== USHRT_MAX
)
104 m_pOffsetMF
->SetValue(m_pOffsetMF
->Normalize(nOffset
), FUNIT_TWIP
);
107 m_pNumIntervalNF
->SetValue(rInf
.GetCountBy());
110 m_pDivisorED
->SetText(rInf
.GetDivider());
113 m_pDivIntervalNF
->SetValue(rInf
.GetDividerCountBy());
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
));
127 get
<PushButton
>("ok")->SetClickHdl(LINK(this, SwLineNumberingDlg
, OKHdl
));
130 SwLineNumberingDlg::~SwLineNumberingDlg()
134 IMPL_LINK_NOARG(SwLineNumberingDlg
, OKHdl
)
136 SwLineNumberInfo
aInf(pSh
->GetLineNumberInfo());
139 String
sCharFmtName(m_pCharStyleLB
->GetSelectEntry());
140 SwCharFmt
*pCharFmt
= pSh
->FindCharFmtByName(sCharFmtName
);
144 SfxStyleSheetBasePool
* pPool
= pSh
->GetView().GetDocShell()->GetStyleSheetPool();
145 SfxStyleSheetBase
* pBase
;
146 pBase
= pPool
->Find(sCharFmtName
, SFX_STYLE_FAMILY_CHAR
);
148 pBase
= &pPool
->Make(sCharFmtName
, SFX_STYLE_FAMILY_CHAR
);
149 pCharFmt
= ((SwDocStyleSheet
*)pBase
)->GetCharFmt();
153 aInf
.SetCharFmt(pCharFmt
);
157 aType
.SetNumberingType(m_pFormatLB
->GetSelectedNumberingType());
158 aInf
.SetNumType(aType
);
161 aInf
.SetPos((LineNumberPosition
)m_pPosLB
->GetSelectEntryPos());
164 aInf
.SetPosFromLeft((sal_uInt16
)m_pOffsetMF
->Denormalize(m_pOffsetMF
->GetValue(FUNIT_TWIP
)));
167 aInf
.SetCountBy((sal_uInt16
)m_pNumIntervalNF
->GetValue());
170 aInf
.SetDivider(m_pDivisorED
->GetText());
173 aInf
.SetDividerCountBy((sal_uInt16
)m_pDivIntervalNF
->GetValue());
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
);
189 /*--------------------------------------------------------------------
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
);
203 /*--------------------------------------------------------------------
205 --------------------------------------------------------------------*/
206 IMPL_LINK_NOARG(SwLineNumberingDlg
, LineOnOffHdl
)
208 bool bEnable
= m_pNumberingOnCB
->IsChecked();
209 m_pBodyContent
->Enable(bEnable
);
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */