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