xref: /AOO41X/main/sd/source/ui/dlg/paragr.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifdef SD_DLLIMPLEMENTATION
32*cdf0e10cSrcweir #undef SD_DLLIMPLEMENTATION
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <vcl/field.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <svl/cjkoptions.hxx>
38*cdf0e10cSrcweir #include <svl/eitem.hxx>
39*cdf0e10cSrcweir #include <svl/intitem.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <editeng/editdata.hxx>
42*cdf0e10cSrcweir #include <svx/dialogs.hrc>
43*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
44*cdf0e10cSrcweir #include <svx/flagsdef.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include "eetext.hxx"
47*cdf0e10cSrcweir #include "paragr.hxx"
48*cdf0e10cSrcweir #include "sdresid.hxx"
49*cdf0e10cSrcweir #include "glob.hrc"
50*cdf0e10cSrcweir #include "sdattr.hrc"
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir class SdParagraphNumTabPage : public SfxTabPage
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir public:
55*cdf0e10cSrcweir     SdParagraphNumTabPage(Window* pParent, const SfxItemSet& rSet );
56*cdf0e10cSrcweir     ~SdParagraphNumTabPage();
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	static SfxTabPage*	Create(	Window* pParent, const SfxItemSet& rSet );
59*cdf0e10cSrcweir 	static sal_uInt16*		GetRanges();
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	virtual sal_Bool		FillItemSet( SfxItemSet& rSet );
62*cdf0e10cSrcweir 	virtual void		Reset( const SfxItemSet& rSet );
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir private:
65*cdf0e10cSrcweir 	TriStateBox		maNewStartCB;
66*cdf0e10cSrcweir     TriStateBox     maNewStartNumberCB;
67*cdf0e10cSrcweir 	NumericField	maNewStartNF;
68*cdf0e10cSrcweir     bool            mbModified;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 	DECL_LINK( ImplNewStartHdl, CheckBox* );
71*cdf0e10cSrcweir };
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir SdParagraphNumTabPage::SdParagraphNumTabPage(Window* pParent, const SfxItemSet& rAttr )
74*cdf0e10cSrcweir : SfxTabPage(pParent, SdResId(RID_TABPAGE_PARA_NUMBERING), rAttr)
75*cdf0e10cSrcweir , maNewStartCB( this, SdResId( CB_NEW_START ) )
76*cdf0e10cSrcweir , maNewStartNumberCB( this, SdResId( CB_NUMBER_NEW_START ) )
77*cdf0e10cSrcweir , maNewStartNF( this, SdResId( NF_NEW_START ) )
78*cdf0e10cSrcweir , mbModified(false)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     FreeResource();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     maNewStartCB.SetClickHdl(LINK(this, SdParagraphNumTabPage, ImplNewStartHdl));
83*cdf0e10cSrcweir     maNewStartNumberCB.SetClickHdl(LINK(this, SdParagraphNumTabPage, ImplNewStartHdl));
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir SdParagraphNumTabPage::~SdParagraphNumTabPage()
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir SfxTabPage* SdParagraphNumTabPage::Create(Window *pParent, const SfxItemSet & rAttrSet)
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     return new SdParagraphNumTabPage( pParent, rAttrSet );
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir sal_uInt16* SdParagraphNumTabPage::GetRanges()
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     static sal_uInt16 __FAR_DATA aRange[] =
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir 	    ATTR_PARANUMBERING_START, ATTR_PARANUMBERING_END,
100*cdf0e10cSrcweir 	    0
101*cdf0e10cSrcweir     };
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     return aRange;
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir sal_Bool SdParagraphNumTabPage::FillItemSet( SfxItemSet& rSet )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	if(maNewStartCB.GetState() != maNewStartCB.GetSavedValue() ||
109*cdf0e10cSrcweir         maNewStartNumberCB.GetState() != maNewStartNumberCB.GetSavedValue()||
110*cdf0e10cSrcweir         maNewStartNF.GetText() != maNewStartNF.GetSavedValue())
111*cdf0e10cSrcweir 	{
112*cdf0e10cSrcweir 		mbModified = true;
113*cdf0e10cSrcweir         sal_Bool bNewStartChecked = STATE_CHECK == maNewStartCB.GetState();
114*cdf0e10cSrcweir         sal_Bool bNumberNewStartChecked = STATE_CHECK == maNewStartNumberCB.GetState();
115*cdf0e10cSrcweir         rSet.Put(SfxBoolItem(ATTR_NUMBER_NEWSTART, bNewStartChecked));
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         const sal_Int16 nStartAt = (sal_Int16)maNewStartNF.GetValue();
118*cdf0e10cSrcweir         rSet.Put(SfxInt16Item(ATTR_NUMBER_NEWSTART_AT, bNumberNewStartChecked && bNewStartChecked ? nStartAt : -1));
119*cdf0e10cSrcweir 	}
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     return mbModified;
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir void SdParagraphNumTabPage::Reset( const SfxItemSet& rSet )
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir 	SfxItemState eItemState = rSet.GetItemState( ATTR_NUMBER_NEWSTART );
127*cdf0e10cSrcweir 	if(eItemState > SFX_ITEM_AVAILABLE )
128*cdf0e10cSrcweir     {
129*cdf0e10cSrcweir 		const SfxBoolItem& rStart = (const SfxBoolItem&)rSet.Get(ATTR_NUMBER_NEWSTART);
130*cdf0e10cSrcweir 		maNewStartCB.SetState( rStart.GetValue() ? STATE_CHECK : STATE_NOCHECK );
131*cdf0e10cSrcweir 		maNewStartCB.EnableTriState(sal_False);
132*cdf0e10cSrcweir 	}
133*cdf0e10cSrcweir 	else
134*cdf0e10cSrcweir     {
135*cdf0e10cSrcweir         maNewStartCB.SetState(STATE_DONTKNOW);
136*cdf0e10cSrcweir         maNewStartCB.Disable();
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir 	maNewStartCB.SaveValue();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	eItemState = rSet.GetItemState( ATTR_NUMBER_NEWSTART_AT);
141*cdf0e10cSrcweir 	if( eItemState > SFX_ITEM_AVAILABLE )
142*cdf0e10cSrcweir 	{
143*cdf0e10cSrcweir 		sal_Int16 nNewStart = ((const SfxInt16Item&)rSet.Get(ATTR_NUMBER_NEWSTART_AT)).GetValue();
144*cdf0e10cSrcweir         maNewStartNumberCB.Check(-1 != nNewStart);
145*cdf0e10cSrcweir         if(-1 == nNewStart)
146*cdf0e10cSrcweir 			nNewStart = 1;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 		maNewStartNF.SetValue(nNewStart);
149*cdf0e10cSrcweir 		maNewStartNumberCB.EnableTriState(sal_False);
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir     else
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         maNewStartCB.SetState(STATE_DONTKNOW);
154*cdf0e10cSrcweir     }
155*cdf0e10cSrcweir     ImplNewStartHdl(&maNewStartCB);
156*cdf0e10cSrcweir     maNewStartNF.SaveValue();
157*cdf0e10cSrcweir     maNewStartNumberCB.SaveValue();
158*cdf0e10cSrcweir 	mbModified = sal_False;
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir IMPL_LINK( SdParagraphNumTabPage, ImplNewStartHdl, CheckBox*, EMPTYARG )
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     sal_Bool bEnable = maNewStartCB.IsChecked();
164*cdf0e10cSrcweir     maNewStartNumberCB.Enable(bEnable);
165*cdf0e10cSrcweir     maNewStartNF.Enable(bEnable && maNewStartNumberCB.IsChecked());
166*cdf0e10cSrcweir 	return 0;
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir SdParagraphDlg::SdParagraphDlg( Window* pParent, const SfxItemSet* pAttr )
170*cdf0e10cSrcweir : SfxTabDialog( pParent, SdResId( TAB_PARAGRAPH ), pAttr )
171*cdf0e10cSrcweir , rOutAttrs( *pAttr )
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir 	FreeResource();
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_STD_PARAGRAPH );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     SvtCJKOptions aCJKOptions;
178*cdf0e10cSrcweir     if( aCJKOptions.IsAsianTypographyEnabled() )
179*cdf0e10cSrcweir 		AddTabPage( RID_SVXPAGE_PARA_ASIAN);
180*cdf0e10cSrcweir 	else
181*cdf0e10cSrcweir 		RemoveTabPage( RID_SVXPAGE_PARA_ASIAN );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_ALIGN_PARAGRAPH );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     static const sal_Bool bShowParaNumbering = ( getenv( "SD_SHOW_NUMBERING_PAGE" ) != NULL );
186*cdf0e10cSrcweir     if( bShowParaNumbering )
187*cdf0e10cSrcweir         AddTabPage( RID_TABPAGE_PARA_NUMBERING, SdParagraphNumTabPage::Create, SdParagraphNumTabPage::GetRanges );
188*cdf0e10cSrcweir     else
189*cdf0e10cSrcweir         RemoveTabPage( RID_TABPAGE_PARA_NUMBERING );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir    	AddTabPage( RID_SVXPAGE_TABULATOR );
192*cdf0e10cSrcweir }
193