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