xref: /trunk/main/sd/source/ui/dlg/paragr.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #ifdef SD_DLLIMPLEMENTATION
28 #undef SD_DLLIMPLEMENTATION
29 #endif
30 
31 #include <vcl/field.hxx>
32 
33 #include <svl/cjkoptions.hxx>
34 #include <svl/eitem.hxx>
35 #include <svl/intitem.hxx>
36 
37 #include <editeng/editdata.hxx>
38 #include <svx/dialogs.hrc>
39 #include <editeng/eeitem.hxx>
40 #include <svx/flagsdef.hxx>
41 
42 #include "eetext.hxx"
43 #include "paragr.hxx"
44 #include "sdresid.hxx"
45 #include "glob.hrc"
46 #include "sdattr.hrc"
47 
48 class SdParagraphNumTabPage : public SfxTabPage
49 {
50 public:
51     SdParagraphNumTabPage(Window* pParent, const SfxItemSet& rSet );
52     ~SdParagraphNumTabPage();
53 
54 	static SfxTabPage*	Create(	Window* pParent, const SfxItemSet& rSet );
55 	static sal_uInt16*		GetRanges();
56 
57 	virtual sal_Bool		FillItemSet( SfxItemSet& rSet );
58 	virtual void		Reset( const SfxItemSet& rSet );
59 
60 private:
61 	TriStateBox		maNewStartCB;
62     TriStateBox     maNewStartNumberCB;
63 	NumericField	maNewStartNF;
64     bool            mbModified;
65 
66 	DECL_LINK( ImplNewStartHdl, CheckBox* );
67 };
68 
SdParagraphNumTabPage(Window * pParent,const SfxItemSet & rAttr)69 SdParagraphNumTabPage::SdParagraphNumTabPage(Window* pParent, const SfxItemSet& rAttr )
70 : SfxTabPage(pParent, SdResId(RID_TABPAGE_PARA_NUMBERING), rAttr)
71 , maNewStartCB( this, SdResId( CB_NEW_START ) )
72 , maNewStartNumberCB( this, SdResId( CB_NUMBER_NEW_START ) )
73 , maNewStartNF( this, SdResId( NF_NEW_START ) )
74 , mbModified(false)
75 {
76     FreeResource();
77 
78     maNewStartCB.SetClickHdl(LINK(this, SdParagraphNumTabPage, ImplNewStartHdl));
79     maNewStartNumberCB.SetClickHdl(LINK(this, SdParagraphNumTabPage, ImplNewStartHdl));
80 }
81 
~SdParagraphNumTabPage()82 SdParagraphNumTabPage::~SdParagraphNumTabPage()
83 {
84 }
85 
Create(Window * pParent,const SfxItemSet & rAttrSet)86 SfxTabPage* SdParagraphNumTabPage::Create(Window *pParent, const SfxItemSet & rAttrSet)
87 {
88     return new SdParagraphNumTabPage( pParent, rAttrSet );
89 }
90 
GetRanges()91 sal_uInt16* SdParagraphNumTabPage::GetRanges()
92 {
93     static sal_uInt16 __FAR_DATA aRange[] =
94     {
95 	    ATTR_PARANUMBERING_START, ATTR_PARANUMBERING_END,
96 	    0
97     };
98 
99     return aRange;
100 }
101 
FillItemSet(SfxItemSet & rSet)102 sal_Bool SdParagraphNumTabPage::FillItemSet( SfxItemSet& rSet )
103 {
104 	if(maNewStartCB.GetState() != maNewStartCB.GetSavedValue() ||
105         maNewStartNumberCB.GetState() != maNewStartNumberCB.GetSavedValue()||
106         maNewStartNF.GetText() != maNewStartNF.GetSavedValue())
107 	{
108 		mbModified = true;
109         sal_Bool bNewStartChecked = STATE_CHECK == maNewStartCB.GetState();
110         sal_Bool bNumberNewStartChecked = STATE_CHECK == maNewStartNumberCB.GetState();
111         rSet.Put(SfxBoolItem(ATTR_NUMBER_NEWSTART, bNewStartChecked));
112 
113         const sal_Int16 nStartAt = (sal_Int16)maNewStartNF.GetValue();
114         rSet.Put(SfxInt16Item(ATTR_NUMBER_NEWSTART_AT, bNumberNewStartChecked && bNewStartChecked ? nStartAt : -1));
115 	}
116 
117     return mbModified;
118 }
119 
Reset(const SfxItemSet & rSet)120 void SdParagraphNumTabPage::Reset( const SfxItemSet& rSet )
121 {
122 	SfxItemState eItemState = rSet.GetItemState( ATTR_NUMBER_NEWSTART );
123 	if(eItemState > SFX_ITEM_AVAILABLE )
124     {
125 		const SfxBoolItem& rStart = (const SfxBoolItem&)rSet.Get(ATTR_NUMBER_NEWSTART);
126 		maNewStartCB.SetState( rStart.GetValue() ? STATE_CHECK : STATE_NOCHECK );
127 		maNewStartCB.EnableTriState(sal_False);
128 	}
129 	else
130     {
131         maNewStartCB.SetState(STATE_DONTKNOW);
132         maNewStartCB.Disable();
133     }
134 	maNewStartCB.SaveValue();
135 
136 	eItemState = rSet.GetItemState( ATTR_NUMBER_NEWSTART_AT);
137 	if( eItemState > SFX_ITEM_AVAILABLE )
138 	{
139 		sal_Int16 nNewStart = ((const SfxInt16Item&)rSet.Get(ATTR_NUMBER_NEWSTART_AT)).GetValue();
140         maNewStartNumberCB.Check(-1 != nNewStart);
141         if(-1 == nNewStart)
142 			nNewStart = 1;
143 
144 		maNewStartNF.SetValue(nNewStart);
145 		maNewStartNumberCB.EnableTriState(sal_False);
146     }
147     else
148     {
149         maNewStartCB.SetState(STATE_DONTKNOW);
150     }
151     ImplNewStartHdl(&maNewStartCB);
152     maNewStartNF.SaveValue();
153     maNewStartNumberCB.SaveValue();
154 	mbModified = sal_False;
155 }
156 
IMPL_LINK(SdParagraphNumTabPage,ImplNewStartHdl,CheckBox *,EMPTYARG)157 IMPL_LINK( SdParagraphNumTabPage, ImplNewStartHdl, CheckBox*, EMPTYARG )
158 {
159     sal_Bool bEnable = maNewStartCB.IsChecked();
160     maNewStartNumberCB.Enable(bEnable);
161     maNewStartNF.Enable(bEnable && maNewStartNumberCB.IsChecked());
162 	return 0;
163 }
164 
SdParagraphDlg(Window * pParent,const SfxItemSet * pAttr)165 SdParagraphDlg::SdParagraphDlg( Window* pParent, const SfxItemSet* pAttr )
166 : SfxTabDialog( pParent, SdResId( TAB_PARAGRAPH ), pAttr )
167 , rOutAttrs( *pAttr )
168 {
169 	FreeResource();
170 
171 	AddTabPage( RID_SVXPAGE_STD_PARAGRAPH );
172 
173     SvtCJKOptions aCJKOptions;
174     if( aCJKOptions.IsAsianTypographyEnabled() )
175 		AddTabPage( RID_SVXPAGE_PARA_ASIAN);
176 	else
177 		RemoveTabPage( RID_SVXPAGE_PARA_ASIAN );
178 
179 	AddTabPage( RID_SVXPAGE_ALIGN_PARAGRAPH );
180 
181     static const sal_Bool bShowParaNumbering = ( getenv( "SD_SHOW_NUMBERING_PAGE" ) != NULL );
182     if( bShowParaNumbering )
183         AddTabPage( RID_TABPAGE_PARA_NUMBERING, SdParagraphNumTabPage::Create, SdParagraphNumTabPage::GetRanges );
184     else
185         RemoveTabPage( RID_TABPAGE_PARA_NUMBERING );
186 
187    	AddTabPage( RID_SVXPAGE_TABULATOR );
188 }
189