xref: /aoo42x/main/sw/source/ui/misc/pggrid.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
28cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <sfx2/app.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifndef _CMDID_H
36cdf0e10cSrcweir #include <cmdid.h>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #include <hintids.hxx>
39cdf0e10cSrcweir #include <swtypes.hxx>
40cdf0e10cSrcweir #ifndef _GLOBALS_HRC
41cdf0e10cSrcweir #include <globals.hrc>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <svx/xtable.hxx>
44cdf0e10cSrcweir #include <uitool.hxx>
45cdf0e10cSrcweir #include <editeng/sizeitem.hxx>
46cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
47cdf0e10cSrcweir #include <editeng/ulspitem.hxx>
48cdf0e10cSrcweir #include <editeng/boxitem.hxx>
49cdf0e10cSrcweir #include <editeng/frmdiritem.hxx>
50cdf0e10cSrcweir #include <pggrid.hxx>
51cdf0e10cSrcweir #include <tgrditem.hxx>
52cdf0e10cSrcweir #include <pggrid.hrc>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include "wrtsh.hxx"
55cdf0e10cSrcweir #include "doc.hxx"
56cdf0e10cSrcweir #include "uiitems.hxx"
57cdf0e10cSrcweir #include "swmodule.hxx"
58cdf0e10cSrcweir #include "view.hxx"
59cdf0e10cSrcweir /*-- 06.02.2002 15:25:39---------------------------------------------------
60cdf0e10cSrcweir 
61cdf0e10cSrcweir   -----------------------------------------------------------------------*/
62cdf0e10cSrcweir SwTextGridPage::SwTextGridPage(Window *pParent, const SfxItemSet &rSet) :
63cdf0e10cSrcweir     SfxTabPage(pParent, SW_RES(TP_TEXTGRID_PAGE), rSet),
64cdf0e10cSrcweir     aGridTypeFL             (this, SW_RES(FL_GRID_TYPE       )),
65cdf0e10cSrcweir     aNoGridRB               (this, SW_RES(RB_NOGRID          )),
66cdf0e10cSrcweir     aLinesGridRB            (this, SW_RES(RB_LINESGRID       )),
67cdf0e10cSrcweir     aCharsGridRB            (this, SW_RES(RB_CHARSGRID       )),
68cdf0e10cSrcweir 	aSnapToCharsCB          (this, SW_RES(CB_SNAPTOCHARS      )),
69cdf0e10cSrcweir     aExampleWN              (this, SW_RES(WN_EXAMPLE         )),
70cdf0e10cSrcweir     aLayoutFL               (this, SW_RES(FL_LAYOUT          )),
71cdf0e10cSrcweir     aLinesPerPageFT         (this, SW_RES(FT_LINESPERPAGE    )),
72cdf0e10cSrcweir     aLinesPerPageNF         (this, SW_RES(NF_LINESPERPAGE    )),
73cdf0e10cSrcweir     aTextSizeFT             (this, SW_RES(FT_TEXTSIZE        )),
74cdf0e10cSrcweir     aTextSizeMF             (this, SW_RES(MF_TEXTSIZE        )),
75cdf0e10cSrcweir     aCharsPerLineFT         (this, SW_RES(FT_CHARSPERLINE    )),
76cdf0e10cSrcweir     aCharsPerLineNF         (this, SW_RES(NF_CHARSPERLINE    )),
77cdf0e10cSrcweir 	aCharWidthFT            (this, SW_RES(FT_CHARWIDTH        )),
78cdf0e10cSrcweir 	aCharWidthMF            (this, SW_RES(MF_CHARWIDTH        )),
79cdf0e10cSrcweir     aRubySizeFT             (this, SW_RES(FT_RUBYSIZE        )),
80cdf0e10cSrcweir     aRubySizeMF             (this, SW_RES(MF_RUBYSIZE        )),
81cdf0e10cSrcweir     aRubyBelowCB            (this, SW_RES(CB_RUBYBELOW       )),
82cdf0e10cSrcweir     aDisplayFL              (this, SW_RES(FL_DISPLAY         )),
83cdf0e10cSrcweir     aDisplayCB              (this, SW_RES(CB_DISPLAY         )),
84cdf0e10cSrcweir     aPrintCB                (this, SW_RES(CB_PRINT           )),
85cdf0e10cSrcweir     aColorFT                (this, SW_RES(FT_COLOR           )),
86cdf0e10cSrcweir     aColorLB                (this, SW_RES(LB_COLOR           )),
87cdf0e10cSrcweir     m_nRubyUserValue(0),
88cdf0e10cSrcweir     m_bRubyUserValue(sal_False),
89cdf0e10cSrcweir     m_aPageSize(MM50, MM50),
90cdf0e10cSrcweir     m_bVertical(sal_False),
91cdf0e10cSrcweir 	m_bSquaredMode(sal_False)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     FreeResource();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     aControls[0] =&aLayoutFL;
96cdf0e10cSrcweir     aControls[1] =&aLinesPerPageFT;
97cdf0e10cSrcweir     aControls[2] =&aLinesPerPageNF;
98cdf0e10cSrcweir     aControls[3] =&aTextSizeFT;
99cdf0e10cSrcweir     aControls[4] =&aTextSizeMF;
100cdf0e10cSrcweir     aControls[5] =&aCharsPerLineFT;
101cdf0e10cSrcweir     aControls[6] =&aCharsPerLineNF;
102cdf0e10cSrcweir     aControls[7] =&aCharWidthFT;
103cdf0e10cSrcweir     aControls[8] =&aCharWidthMF;
104cdf0e10cSrcweir     aControls[9] =&aRubySizeFT;
105cdf0e10cSrcweir     aControls[10] =&aRubySizeMF;
106cdf0e10cSrcweir     aControls[11] =&aRubyBelowCB;
107cdf0e10cSrcweir     aControls[12] =&aDisplayFL;
108cdf0e10cSrcweir     aControls[13] =&aDisplayCB;
109cdf0e10cSrcweir     aControls[14] =&aPrintCB;
110cdf0e10cSrcweir     aControls[15] =&aColorFT;
111cdf0e10cSrcweir     aControls[16] =&aColorLB;
112cdf0e10cSrcweir     aControls[17] =0;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     Link aLink = LINK(this, SwTextGridPage, CharorLineChangedHdl);
115cdf0e10cSrcweir     aCharsPerLineNF.SetUpHdl(aLink);
116cdf0e10cSrcweir     aCharsPerLineNF.SetDownHdl(aLink);
117cdf0e10cSrcweir     aCharsPerLineNF.SetLoseFocusHdl(aLink);
118cdf0e10cSrcweir     aLinesPerPageNF.SetUpHdl(aLink);
119cdf0e10cSrcweir     aLinesPerPageNF.SetDownHdl(aLink);
120cdf0e10cSrcweir     aLinesPerPageNF.SetLoseFocusHdl(aLink);
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     Link aSizeLink = LINK(this, SwTextGridPage, TextSizeChangedHdl);
123cdf0e10cSrcweir     aTextSizeMF.SetUpHdl(aSizeLink);
124cdf0e10cSrcweir     aTextSizeMF.SetDownHdl(aSizeLink);
125cdf0e10cSrcweir     aTextSizeMF.SetLoseFocusHdl(aSizeLink);
126cdf0e10cSrcweir     aRubySizeMF.SetUpHdl(aSizeLink);
127cdf0e10cSrcweir     aRubySizeMF.SetDownHdl(aSizeLink);
128cdf0e10cSrcweir     aRubySizeMF.SetLoseFocusHdl(aSizeLink);
129cdf0e10cSrcweir     aCharWidthMF.SetUpHdl(aSizeLink);
130cdf0e10cSrcweir     aCharWidthMF.SetDownHdl(aSizeLink);
131cdf0e10cSrcweir     aCharWidthMF.SetLoseFocusHdl(aSizeLink);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     Link aGridTypeHdl = LINK(this, SwTextGridPage, GridTypeHdl);
134cdf0e10cSrcweir     aNoGridRB   .SetClickHdl(aGridTypeHdl);
135cdf0e10cSrcweir     aLinesGridRB.SetClickHdl(aGridTypeHdl);
136cdf0e10cSrcweir     aCharsGridRB.SetClickHdl(aGridTypeHdl);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     Link aModifyLk = LINK(this, SwTextGridPage, GridModifyHdl);
139cdf0e10cSrcweir     aColorLB.SetSelectHdl(aModifyLk);
140cdf0e10cSrcweir     aPrintCB.SetClickHdl(aModifyLk);
141cdf0e10cSrcweir     aRubyBelowCB.SetClickHdl(aModifyLk);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     aDisplayCB.SetClickHdl(LINK(this, SwTextGridPage, DisplayGridHdl));
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     XColorTable* pColorTbl = XColorTable::GetStdColorTable();
147cdf0e10cSrcweir     aColorLB.InsertAutomaticEntry();
148cdf0e10cSrcweir 	for( sal_uInt16 i = 0; i < pColorTbl->Count(); ++i )
149cdf0e10cSrcweir 	{
150cdf0e10cSrcweir 		XColorEntry* pEntry = pColorTbl->GetColor( i );
151cdf0e10cSrcweir 		Color aColor = pEntry->GetColor();
152cdf0e10cSrcweir 		String sName = pEntry->GetName();
153cdf0e10cSrcweir 		aColorLB.InsertEntry( aColor, sName );
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir 	aColorLB.SetUpdateMode( sal_True );
156cdf0e10cSrcweir 	//Get the default paper mode
157cdf0e10cSrcweir 	SwView *pView   = ::GetActiveView();
158cdf0e10cSrcweir 	if( pView )
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir 		SwWrtShell* pSh = pView->GetWrtShellPtr();
161cdf0e10cSrcweir 		if( pSh )
162cdf0e10cSrcweir 		{
163cdf0e10cSrcweir 			m_bSquaredMode = pSh->GetDoc()->IsSquaredPageMode();
164cdf0e10cSrcweir 		}
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 	if( m_bSquaredMode )
167cdf0e10cSrcweir 	{
168cdf0e10cSrcweir 		aRubySizeFT.Show();
169cdf0e10cSrcweir 		aRubySizeMF.Show();
170cdf0e10cSrcweir 		aRubyBelowCB.Show();
171cdf0e10cSrcweir 		aSnapToCharsCB.Hide();
172cdf0e10cSrcweir 		aCharWidthFT.Hide();
173cdf0e10cSrcweir 		aCharWidthMF.Hide();
174cdf0e10cSrcweir 	}
175cdf0e10cSrcweir 	else
176cdf0e10cSrcweir 	{
177cdf0e10cSrcweir 		aRubySizeFT.Hide();
178cdf0e10cSrcweir 		aRubySizeMF.Hide();
179cdf0e10cSrcweir 		aRubyBelowCB.Hide();
180cdf0e10cSrcweir 		aSnapToCharsCB.Show();
181cdf0e10cSrcweir 		aCharWidthFT.Show();
182cdf0e10cSrcweir 		aCharWidthMF.Show();
183cdf0e10cSrcweir 	}
184cdf0e10cSrcweir }
185cdf0e10cSrcweir /*-- 06.02.2002 15:25:40---------------------------------------------------
186cdf0e10cSrcweir 
187cdf0e10cSrcweir   -----------------------------------------------------------------------*/
188cdf0e10cSrcweir SwTextGridPage::~SwTextGridPage()
189cdf0e10cSrcweir {
190cdf0e10cSrcweir }
191cdf0e10cSrcweir /*-- 06.02.2002 15:25:40---------------------------------------------------
192cdf0e10cSrcweir 
193cdf0e10cSrcweir   -----------------------------------------------------------------------*/
194cdf0e10cSrcweir SfxTabPage *SwTextGridPage::Create(Window *pParent, const SfxItemSet &rSet)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     return new SwTextGridPage(pParent, rSet);
197cdf0e10cSrcweir }
198cdf0e10cSrcweir /*-- 06.02.2002 15:25:40---------------------------------------------------
199cdf0e10cSrcweir 
200cdf0e10cSrcweir   -----------------------------------------------------------------------*/
201cdf0e10cSrcweir sal_Bool    SwTextGridPage::FillItemSet(SfxItemSet &rSet)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     sal_Bool bRet = sal_False;
204cdf0e10cSrcweir     if(aNoGridRB.GetSavedValue() != aNoGridRB.IsChecked()||
205cdf0e10cSrcweir         aLinesGridRB.GetSavedValue() != aLinesGridRB.IsChecked()||
206cdf0e10cSrcweir         aLinesPerPageNF.GetSavedValue().ToInt32()
207cdf0e10cSrcweir            != aLinesPerPageNF.GetValue()||
208cdf0e10cSrcweir         aTextSizeMF.GetSavedValue().ToInt32() != aTextSizeMF.GetValue()||
209cdf0e10cSrcweir         aCharsPerLineNF.GetSavedValue().ToInt32()
210cdf0e10cSrcweir            != aCharsPerLineNF.GetValue()||
211cdf0e10cSrcweir         aSnapToCharsCB.GetSavedValue() != aSnapToCharsCB.IsChecked() ||
212cdf0e10cSrcweir         aRubySizeMF.GetSavedValue().ToInt32() != aRubySizeMF.GetValue()||
213cdf0e10cSrcweir         aCharWidthMF.GetSavedValue().ToInt32() != aCharWidthMF.GetValue()||
214cdf0e10cSrcweir         aRubyBelowCB.GetSavedValue() != aRubyBelowCB.IsChecked()||
215cdf0e10cSrcweir         aDisplayCB.GetSavedValue() != aDisplayCB.IsChecked()||
216cdf0e10cSrcweir         aPrintCB.GetSavedValue() != aPrintCB.IsChecked()||
217cdf0e10cSrcweir         aColorLB.GetSavedValue() != aColorLB.GetSelectEntryPos())
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         PutGridItem(rSet);
220cdf0e10cSrcweir         bRet = sal_True;
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     return bRet;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir /*-- 06.02.2002 15:25:40---------------------------------------------------
226cdf0e10cSrcweir 
227cdf0e10cSrcweir   -----------------------------------------------------------------------*/
228cdf0e10cSrcweir void    SwTextGridPage::Reset(const SfxItemSet &rSet)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir     if(SFX_ITEM_AVAILABLE <= rSet.GetItemState(RES_TEXTGRID, sal_True))
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         const SwTextGridItem& rGridItem = (const SwTextGridItem&)rSet.Get(RES_TEXTGRID);
233cdf0e10cSrcweir         RadioButton* pButton = 0;
234cdf0e10cSrcweir         switch(rGridItem.GetGridType())
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir             case GRID_NONE :        pButton = &aNoGridRB;    break;
237cdf0e10cSrcweir             case GRID_LINES_ONLY  : pButton = &aLinesGridRB; break;
238cdf0e10cSrcweir             default:                pButton = &aCharsGridRB;
239cdf0e10cSrcweir         }
240cdf0e10cSrcweir         pButton->Check();
241cdf0e10cSrcweir         aDisplayCB.Check(rGridItem.IsDisplayGrid());
242cdf0e10cSrcweir         GridTypeHdl(pButton);
243cdf0e10cSrcweir         aSnapToCharsCB.Check(rGridItem.IsSnapToChars());
244cdf0e10cSrcweir         aLinesPerPageNF.SetValue(rGridItem.GetLines());
245cdf0e10cSrcweir         m_nRubyUserValue = rGridItem.GetBaseHeight();
246cdf0e10cSrcweir         m_bRubyUserValue = sal_True;
247cdf0e10cSrcweir         aTextSizeMF.SetValue(aTextSizeMF.Normalize(m_nRubyUserValue), FUNIT_TWIP);
248cdf0e10cSrcweir         aRubySizeMF.SetValue(aRubySizeMF.Normalize(rGridItem.GetRubyHeight()), FUNIT_TWIP);
249cdf0e10cSrcweir         aCharWidthMF.SetValue(aCharWidthMF.Normalize(rGridItem.GetBaseWidth()), FUNIT_TWIP);
250cdf0e10cSrcweir         aRubyBelowCB.Check(rGridItem.IsRubyTextBelow());
251cdf0e10cSrcweir         aPrintCB.Check(rGridItem.IsPrintGrid());
252cdf0e10cSrcweir         aColorLB.SelectEntry(rGridItem.GetColor());
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir     UpdatePageSize(rSet);
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     aNoGridRB.SaveValue();
257cdf0e10cSrcweir     aLinesGridRB.SaveValue();
258cdf0e10cSrcweir     aSnapToCharsCB.SaveValue();
259cdf0e10cSrcweir     aLinesPerPageNF.SaveValue();
260cdf0e10cSrcweir     aTextSizeMF.SaveValue();
261cdf0e10cSrcweir     aCharsPerLineNF.SaveValue();
262cdf0e10cSrcweir     aRubySizeMF.SaveValue();
263cdf0e10cSrcweir     aCharWidthMF.SaveValue();
264cdf0e10cSrcweir     aRubyBelowCB.SaveValue();
265cdf0e10cSrcweir     aDisplayCB.SaveValue();
266cdf0e10cSrcweir     aPrintCB.SaveValue();
267cdf0e10cSrcweir     aColorLB.SaveValue();
268cdf0e10cSrcweir }
269cdf0e10cSrcweir /*-- 06.02.2002 15:25:41---------------------------------------------------
270cdf0e10cSrcweir 
271cdf0e10cSrcweir   -----------------------------------------------------------------------*/
272cdf0e10cSrcweir void    SwTextGridPage::ActivatePage( const SfxItemSet& rSet )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     aExampleWN.Hide();
275cdf0e10cSrcweir     aExampleWN.UpdateExample( rSet );
276cdf0e10cSrcweir     UpdatePageSize(rSet);
277cdf0e10cSrcweir     aExampleWN.Show();
278cdf0e10cSrcweir     aExampleWN.Invalidate();
279cdf0e10cSrcweir }
280cdf0e10cSrcweir /*-- 06.02.2002 15:25:41---------------------------------------------------
281cdf0e10cSrcweir 
282cdf0e10cSrcweir   -----------------------------------------------------------------------*/
283cdf0e10cSrcweir int SwTextGridPage::DeactivatePage( SfxItemSet* )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir     return LEAVE_PAGE;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir /* -----------------------------08.02.2002 11:57------------------------------
288cdf0e10cSrcweir 
289cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
290cdf0e10cSrcweir void SwTextGridPage::PutGridItem(SfxItemSet& rSet)
291cdf0e10cSrcweir {
292cdf0e10cSrcweir         SwTextGridItem aGridItem;
293cdf0e10cSrcweir         aGridItem.SetGridType(aNoGridRB.IsChecked() ? GRID_NONE :
294cdf0e10cSrcweir             aLinesGridRB.IsChecked() ? GRID_LINES_ONLY : GRID_LINES_CHARS );
295cdf0e10cSrcweir         aGridItem.SetSnapToChars(aSnapToCharsCB.IsChecked());
296cdf0e10cSrcweir         aGridItem.SetLines( static_cast< sal_uInt16 >(aLinesPerPageNF.GetValue()) );
297cdf0e10cSrcweir         aGridItem.SetBaseHeight( static_cast< sal_uInt16 >(
298cdf0e10cSrcweir             m_bRubyUserValue ? m_nRubyUserValue :
299cdf0e10cSrcweir                 aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP))) );
300cdf0e10cSrcweir         aGridItem.SetRubyHeight( static_cast< sal_uInt16 >(aRubySizeMF.Denormalize(aRubySizeMF.GetValue(FUNIT_TWIP))) );
301cdf0e10cSrcweir         aGridItem.SetBaseWidth( static_cast< sal_uInt16 >(aCharWidthMF.Denormalize(aCharWidthMF.GetValue(FUNIT_TWIP))) );
302cdf0e10cSrcweir         aGridItem.SetRubyTextBelow(aRubyBelowCB.IsChecked());
303cdf0e10cSrcweir         aGridItem.SetSquaredMode(m_bSquaredMode);
304cdf0e10cSrcweir         aGridItem.SetDisplayGrid(aDisplayCB.IsChecked());
305cdf0e10cSrcweir         aGridItem.SetPrintGrid(aPrintCB.IsChecked());
306cdf0e10cSrcweir         aGridItem.SetColor(aColorLB.GetSelectEntryColor());
307cdf0e10cSrcweir         rSet.Put(aGridItem);
308cdf0e10cSrcweir }
309cdf0e10cSrcweir /* -----------------------------08.02.2002 10:54------------------------------
310cdf0e10cSrcweir 
311cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
312cdf0e10cSrcweir void SwTextGridPage::UpdatePageSize(const SfxItemSet& rSet)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     if( SFX_ITEM_UNKNOWN !=  rSet.GetItemState( RES_FRAMEDIR, sal_True ))
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         const SvxFrameDirectionItem& rDirItem =
317cdf0e10cSrcweir                     (const SvxFrameDirectionItem&)rSet.Get(RES_FRAMEDIR);
318cdf0e10cSrcweir         m_bVertical = rDirItem.GetValue() == FRMDIR_VERT_TOP_RIGHT||
319cdf0e10cSrcweir                     rDirItem.GetValue() == FRMDIR_VERT_TOP_LEFT;
320cdf0e10cSrcweir     }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_SIZE ))
323cdf0e10cSrcweir     {
324cdf0e10cSrcweir         const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get(
325cdf0e10cSrcweir                                             SID_ATTR_PAGE_SIZE);
326cdf0e10cSrcweir         const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)rSet.Get(
327cdf0e10cSrcweir                                                             RES_LR_SPACE );
328cdf0e10cSrcweir         const SvxULSpaceItem& rULSpace = (const SvxULSpaceItem&)rSet.Get(
329cdf0e10cSrcweir                                                             RES_UL_SPACE );
330cdf0e10cSrcweir         const SvxBoxItem& rBox = (const SvxBoxItem&) rSet.Get(RES_BOX);
331cdf0e10cSrcweir         sal_Int32 nDistanceLR = rLRSpace.GetLeft() + rLRSpace.GetRight();
332cdf0e10cSrcweir         sal_Int32 nDistanceUL = rULSpace.GetUpper() + rULSpace.GetLower();
333cdf0e10cSrcweir 
334cdf0e10cSrcweir         sal_Int32 nValue1 = rSize.GetSize().Height() - nDistanceUL -
335cdf0e10cSrcweir                 rBox.GetDistance(BOX_LINE_TOP) -
336cdf0e10cSrcweir                                     rBox.GetDistance(BOX_LINE_BOTTOM);
337cdf0e10cSrcweir         sal_Int32 nValue2 = rSize.GetSize().Width() - nDistanceLR -
338cdf0e10cSrcweir                 rBox.GetDistance(BOX_LINE_LEFT) -
339cdf0e10cSrcweir                                     rBox.GetDistance(BOX_LINE_RIGHT);
340cdf0e10cSrcweir         if(m_bVertical)
341cdf0e10cSrcweir         {
342cdf0e10cSrcweir             m_aPageSize.Width() = nValue1;
343cdf0e10cSrcweir             m_aPageSize.Height() = nValue2;
344cdf0e10cSrcweir         }
345cdf0e10cSrcweir         else
346cdf0e10cSrcweir         {
347cdf0e10cSrcweir             m_aPageSize.Width() = nValue2;
348cdf0e10cSrcweir             m_aPageSize.Height() = nValue1;
349cdf0e10cSrcweir         }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         sal_Int32 nTextSize = static_cast< sal_Int32 >(m_bRubyUserValue ?
352cdf0e10cSrcweir                     m_nRubyUserValue :
353cdf0e10cSrcweir                         aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)));
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         if ( m_bSquaredMode )
356cdf0e10cSrcweir         {
357cdf0e10cSrcweir             aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextSize);
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir         else
360cdf0e10cSrcweir         {
361cdf0e10cSrcweir             sal_Int32 nTextWidth = static_cast< sal_Int32 >(aCharWidthMF.Denormalize(aCharWidthMF.GetValue(FUNIT_TWIP)));
362cdf0e10cSrcweir             aLinesPerPageNF.SetValue(m_aPageSize.Height() / nTextSize);
363cdf0e10cSrcweir             if (nTextWidth)
364cdf0e10cSrcweir                 aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextWidth);
365cdf0e10cSrcweir             else
366cdf0e10cSrcweir                 aCharsPerLineNF.SetValue( 45 );
367cdf0e10cSrcweir         }
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir }
370cdf0e10cSrcweir /* -----------------------------06.02.2002 15:24------------------------------
371cdf0e10cSrcweir 
372cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
373cdf0e10cSrcweir sal_uInt16* SwTextGridPage::GetRanges()
374cdf0e10cSrcweir {
375cdf0e10cSrcweir     static sal_uInt16 __FAR_DATA aPageRg[] = {
376cdf0e10cSrcweir         RES_TEXTGRID, RES_TEXTGRID,
377cdf0e10cSrcweir         0};
378cdf0e10cSrcweir     return aPageRg;
379cdf0e10cSrcweir }
380cdf0e10cSrcweir /* -----------------------------08.02.2002 10:56------------------------------
381cdf0e10cSrcweir 
382cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
383cdf0e10cSrcweir IMPL_LINK(SwTextGridPage, CharorLineChangedHdl, SpinField*, pField)
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     //if in squared mode
386cdf0e10cSrcweir     if ( m_bSquaredMode )
387cdf0e10cSrcweir     {
388cdf0e10cSrcweir         if(&aCharsPerLineNF == pField)
389cdf0e10cSrcweir         {
390cdf0e10cSrcweir             long nWidth = (long)(m_aPageSize.Width() / aCharsPerLineNF.GetValue());
391cdf0e10cSrcweir             aTextSizeMF.SetValue(aTextSizeMF.Normalize(nWidth), FUNIT_TWIP);
392cdf0e10cSrcweir             //prevent rounding errors in the MetricField by saving the used value
393cdf0e10cSrcweir             m_nRubyUserValue = nWidth;
394cdf0e10cSrcweir             m_bRubyUserValue = sal_True;
395cdf0e10cSrcweir 
396cdf0e10cSrcweir         }
397cdf0e10cSrcweir 		//set maximum line per page
398cdf0e10cSrcweir         {
399cdf0e10cSrcweir             sal_Int32 nMaxLines = static_cast< sal_Int32 >(m_aPageSize.Height() /
400cdf0e10cSrcweir                 (   aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)) +
401cdf0e10cSrcweir                     aRubySizeMF.Denormalize(aRubySizeMF.GetValue(FUNIT_TWIP))));
402cdf0e10cSrcweir             aLinesPerPageNF.SetMax(nMaxLines);
403cdf0e10cSrcweir         }
404cdf0e10cSrcweir 	}
405cdf0e10cSrcweir     else//in normal mode
406cdf0e10cSrcweir     {
407cdf0e10cSrcweir         if(&aLinesPerPageNF == pField)
408cdf0e10cSrcweir         {
409cdf0e10cSrcweir             long nHeight = static_cast< sal_Int32 >(m_aPageSize.Height() / aLinesPerPageNF.GetValue());
410cdf0e10cSrcweir             aTextSizeMF.SetValue(aTextSizeMF.Normalize(nHeight), FUNIT_TWIP);
411cdf0e10cSrcweir             aRubySizeMF.SetValue(0, FUNIT_TWIP);
412cdf0e10cSrcweir 
413cdf0e10cSrcweir             m_nRubyUserValue = nHeight;
414cdf0e10cSrcweir             m_bRubyUserValue = sal_True;
415cdf0e10cSrcweir         }
416cdf0e10cSrcweir         else if (&aCharsPerLineNF == pField)
417cdf0e10cSrcweir         {
418cdf0e10cSrcweir             long nWidth = static_cast< sal_Int32 >(m_aPageSize.Width() / aCharsPerLineNF.GetValue());
419cdf0e10cSrcweir             aCharWidthMF.SetValue(aCharWidthMF.Normalize(nWidth), FUNIT_TWIP);
420cdf0e10cSrcweir         }
421cdf0e10cSrcweir     }
422cdf0e10cSrcweir     GridModifyHdl(0);
423cdf0e10cSrcweir     return 0;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir /* -----------------------------04.09.2006 15:46------------------------------
426cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
427cdf0e10cSrcweir IMPL_LINK(SwTextGridPage, TextSizeChangedHdl, SpinField*, pField)
428cdf0e10cSrcweir {
429cdf0e10cSrcweir     //if in squared mode
430cdf0e10cSrcweir     if( m_bSquaredMode )
431cdf0e10cSrcweir     {
432cdf0e10cSrcweir         if (&aTextSizeMF == pField)
433cdf0e10cSrcweir         {
434cdf0e10cSrcweir             sal_Int32 nTextSize = static_cast< sal_Int32 >(aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)));
435cdf0e10cSrcweir             aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextSize);
436cdf0e10cSrcweir             m_bRubyUserValue = sal_False;
437cdf0e10cSrcweir         }
438cdf0e10cSrcweir 		//set maximum line per page
439cdf0e10cSrcweir         {
440cdf0e10cSrcweir             sal_Int32 nMaxLines = static_cast< sal_Int32 >(m_aPageSize.Height() /
441cdf0e10cSrcweir                 (   aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)) +
442cdf0e10cSrcweir                     aRubySizeMF.Denormalize(aRubySizeMF.GetValue(FUNIT_TWIP))));
443cdf0e10cSrcweir             aLinesPerPageNF.SetMax(nMaxLines);
444cdf0e10cSrcweir         }
445cdf0e10cSrcweir     }
446cdf0e10cSrcweir     else
447cdf0e10cSrcweir     {
448cdf0e10cSrcweir         if (&aTextSizeMF == pField)
449cdf0e10cSrcweir         {
450cdf0e10cSrcweir             sal_Int32 nTextSize = static_cast< sal_Int32 >(aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)));
451cdf0e10cSrcweir             aLinesPerPageNF.SetValue(m_aPageSize.Height() / nTextSize);
452cdf0e10cSrcweir             m_bRubyUserValue = sal_False;
453cdf0e10cSrcweir         }
454cdf0e10cSrcweir         else if (&aCharWidthMF == pField)
455cdf0e10cSrcweir         {
456cdf0e10cSrcweir             sal_Int32 nTextWidth = static_cast< sal_Int32 >(aCharWidthMF.Denormalize(aCharWidthMF.GetValue(FUNIT_TWIP)));
457cdf0e10cSrcweir             if (nTextWidth)
458cdf0e10cSrcweir                 aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextWidth);
459cdf0e10cSrcweir             else
460cdf0e10cSrcweir                 aCharsPerLineNF.SetValue( 45 );
461cdf0e10cSrcweir         }
462cdf0e10cSrcweir         //rubySize is disabled
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir     GridModifyHdl(0);
465cdf0e10cSrcweir     return 0;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir /* -----------------------------22.04.2002 14:53------------------------------
468cdf0e10cSrcweir 
469cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
470cdf0e10cSrcweir IMPL_LINK(SwTextGridPage, GridTypeHdl, RadioButton*, pButton)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir     sal_Bool bEnable = &aNoGridRB != pButton;
473cdf0e10cSrcweir     sal_Int32 nIndex = 0;
474cdf0e10cSrcweir     while(aControls[nIndex])
475cdf0e10cSrcweir         aControls[nIndex++]->Enable(bEnable);
476cdf0e10cSrcweir     //one special case
477cdf0e10cSrcweir     if(bEnable)
478cdf0e10cSrcweir         DisplayGridHdl(&aDisplayCB);
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	bEnable = &aCharsGridRB == pButton;
481cdf0e10cSrcweir 	aSnapToCharsCB.Enable(bEnable);
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	bEnable = &aLinesGridRB == pButton;
484cdf0e10cSrcweir 	if(bEnable && !m_bSquaredMode )
485cdf0e10cSrcweir 	{
486cdf0e10cSrcweir 		aCharsPerLineFT.Enable(sal_False);
487cdf0e10cSrcweir 		aCharsPerLineNF.Enable(sal_False);
488cdf0e10cSrcweir 		aCharWidthFT.Enable(sal_False);
489cdf0e10cSrcweir 		aCharWidthMF.Enable(sal_False);
490cdf0e10cSrcweir 	}
491cdf0e10cSrcweir 
492cdf0e10cSrcweir     GridModifyHdl(0);
493cdf0e10cSrcweir     return 0;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir /* -----------------------------22.04.2002 15:46------------------------------
496cdf0e10cSrcweir 
497cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
498cdf0e10cSrcweir IMPL_LINK(SwTextGridPage, DisplayGridHdl, CheckBox*, EMPTYARG)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     aPrintCB.Enable(aDisplayCB.IsChecked());
501cdf0e10cSrcweir     return 0;
502cdf0e10cSrcweir }
503cdf0e10cSrcweir /* -----------------------------08.02.2002 11:54------------------------------
504cdf0e10cSrcweir 
505cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
506cdf0e10cSrcweir IMPL_LINK(SwTextGridPage, GridModifyHdl, void*, EMPTYARG)
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     const SfxItemSet& rOldSet = GetItemSet();
509cdf0e10cSrcweir     SfxItemSet aSet(rOldSet);
510cdf0e10cSrcweir     const SfxItemSet* pExSet = GetTabDialog()->GetExampleSet();
511cdf0e10cSrcweir     if(pExSet)
512cdf0e10cSrcweir         aSet.Put(*pExSet);
513cdf0e10cSrcweir     PutGridItem(aSet);
514cdf0e10cSrcweir     aExampleWN.UpdateExample(aSet);
515cdf0e10cSrcweir     return 0;
516cdf0e10cSrcweir }
517cdf0e10cSrcweir 
518