merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / dlg / dlgsnap.cxx
blobb4dd3ca834b75ba10aef9badd4cf9b8e39d4d65f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgsnap.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #ifdef SD_DLLIMPLEMENTATION
35 #undef SD_DLLIMPLEMENTATION
36 #endif
39 #include <svx/svxids.hrc>
40 #include <svx/dlgutil.hxx>
41 #include <svtools/itempool.hxx>
42 #include <svtools/aeitem.hxx>
44 #include "dlgsnap.hrc"
45 #include "sdattr.hxx"
46 #include "View.hxx"
47 #include "sdresid.hxx"
48 #include "drawdoc.hxx"
49 #include "dlgsnap.hxx"
52 /*************************************************************************
54 |* Dialog zum Einstellen des Rasters (wohl kaum ESO!)
56 \************************************************************************/
58 SdSnapLineDlg::SdSnapLineDlg(
59 ::Window* pWindow,
60 const SfxItemSet& rInAttrs,
61 ::sd::View* pView)
62 : ModalDialog (pWindow, SdResId(DLG_SNAPLINE)),
63 aFlPos (this, SdResId(FL_POSITION)),
64 aFtX (this, SdResId(FT_X)),
65 aMtrFldX (this, SdResId(MTR_FLD_X)),
66 aFtY (this, SdResId(FT_Y)),
67 aMtrFldY (this, SdResId(MTR_FLD_Y)),
68 aFlDir (this, SdResId(FL_DIRECTION)),
69 aRbPoint (this, SdResId(RB_POINT)),
70 aRbVert (this, SdResId(RB_VERTICAL)),
71 aRbHorz (this, SdResId(RB_HORIZONTAL)),
72 aBtnOK (this, SdResId(BTN_OK)),
73 aBtnCancel (this, SdResId(BTN_CANCEL)),
74 aBtnHelp (this, SdResId(BTN_HELP)),
75 aBtnDelete (this, SdResId(BTN_DELETE)),
76 eUIUnit(pView->GetDoc()->GetUIUnit()),
77 aUIScale(pView->GetDoc()->GetUIScale())
79 aRbPoint.SetModeRadioImage( Image( SdResId( BMP_POINT_H ) ), BMP_COLOR_HIGHCONTRAST );
80 aRbVert.SetModeRadioImage( Image( SdResId( BMP_VERTICAL_H ) ), BMP_COLOR_HIGHCONTRAST );
81 aRbHorz.SetModeRadioImage( Image( SdResId( BMP_HORIZONTAL_H ) ), BMP_COLOR_HIGHCONTRAST );
83 FreeResource();
85 aRbHorz.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
86 aRbVert.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
87 aRbPoint.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
89 aBtnDelete.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
91 SetFieldUnit( aMtrFldX, eUIUnit, TRUE );
92 SetFieldUnit( aMtrFldY, eUIUnit, TRUE );
94 // WorkArea holen
95 Rectangle aWorkArea = pView->GetWorkArea();
97 // PoolUnit ermitteln
98 SfxItemPool* pPool = rInAttrs.GetPool();
99 DBG_ASSERT( pPool, "Wo ist der Pool?" );
100 SfxMapUnit ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
102 // Hier werden die Max- und MinWerte in Ahaengigkeit von der
103 // WorkArea, PoolUnit und der FieldUnit:
104 SetMetricValue( aMtrFldX, aWorkArea.Left(), ePoolUnit );
105 long nValue = static_cast<long>(aMtrFldX.GetValue());
106 nValue = Fraction( nValue ) / aUIScale;
107 aMtrFldX.SetMin( nValue );
108 aMtrFldX.SetFirst( nValue );
110 SetMetricValue( aMtrFldX, aWorkArea.Right()+1, ePoolUnit );
111 nValue = static_cast<long>(aMtrFldX.GetValue());
112 nValue = Fraction( nValue ) / aUIScale;
113 aMtrFldX.SetMax( nValue );
114 aMtrFldX.SetLast( nValue );
116 SetMetricValue( aMtrFldY, aWorkArea.Top(), ePoolUnit );
117 nValue = static_cast<long>(aMtrFldY.GetValue());
118 nValue = Fraction( nValue ) / aUIScale;
119 aMtrFldY.SetMin( nValue );
120 aMtrFldY.SetFirst( nValue );
122 SetMetricValue( aMtrFldY, aWorkArea.Bottom()+1, ePoolUnit );
123 nValue = static_cast<long>(aMtrFldY.GetValue());
124 nValue = Fraction( nValue ) / aUIScale;
125 aMtrFldY.SetMax( nValue );
126 aMtrFldY.SetLast( nValue );
128 // Setzen der Werte
129 nXValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_X)).GetValue();
130 nYValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_Y)).GetValue();
131 nXValue = Fraction(nXValue) / aUIScale;
132 nYValue = Fraction(nYValue) / aUIScale;
133 SetMetricValue( aMtrFldX, nXValue, SFX_MAPUNIT_100TH_MM);
134 SetMetricValue( aMtrFldY, nYValue, SFX_MAPUNIT_100TH_MM);
136 aRbPoint.Check();
139 /*************************************************************************
141 |* Fuellt uebergebenes Item-Set mit Dialogbox-Attributen
143 \************************************************************************/
145 IMPL_LINK( SdSnapLineDlg, ClickHdl, Button *, pBtn )
147 if ( pBtn == &aRbPoint ) SetInputFields(TRUE, TRUE);
148 else if ( pBtn == &aRbHorz ) SetInputFields(FALSE, TRUE);
149 else if ( pBtn == &aRbVert ) SetInputFields(TRUE, FALSE);
150 else if ( pBtn == &aBtnDelete ) EndDialog(RET_SNAP_DELETE);
152 return 0;
155 /*************************************************************************
157 |* Fuellt uebergebenes Item-Set mit Dialogbox-Attributen
159 \************************************************************************/
161 void SdSnapLineDlg::GetAttr(SfxItemSet& rOutAttrs)
163 SnapKind eKind;
165 if ( aRbHorz.IsChecked() ) eKind = SK_HORIZONTAL;
166 else if ( aRbVert.IsChecked() ) eKind = SK_VERTICAL;
167 else eKind = SK_POINT;
169 nXValue = Fraction( GetCoreValue( aMtrFldX, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
170 nYValue = Fraction( GetCoreValue( aMtrFldY, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
172 rOutAttrs.Put(SfxAllEnumItem(ATTR_SNAPLINE_KIND, (USHORT)eKind));
173 rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_X, nXValue));
174 rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, nYValue));
177 /*************************************************************************
179 |* Gruppe mit Radiobutton verstecken
181 \************************************************************************/
183 void SdSnapLineDlg::HideRadioGroup()
185 aFlDir.Hide();
186 aRbHorz.Hide();
187 aRbVert.Hide();
188 aRbPoint.Hide();
191 /*************************************************************************
193 |* X- bzw. Y-Inputfeld disablen
195 \************************************************************************/
197 void SdSnapLineDlg::SetInputFields(BOOL bEnableX, BOOL bEnableY)
199 if ( bEnableX )
201 if ( !aMtrFldX.IsEnabled() )
202 aMtrFldX.SetValue(nXValue);
203 aMtrFldX.Enable();
204 aFtX.Enable();
206 else if ( aMtrFldX.IsEnabled() )
208 nXValue = static_cast<long>(aMtrFldX.GetValue());
209 aMtrFldX.SetText(String());
210 aMtrFldX.Disable();
211 aFtX.Disable();
213 if ( bEnableY )
215 if ( !aMtrFldY.IsEnabled() )
216 aMtrFldY.SetValue(nYValue);
217 aMtrFldY.Enable();
218 aFtY.Enable();
220 else if ( aMtrFldY.IsEnabled() )
222 nYValue = static_cast<long>(aMtrFldY.GetValue());
223 aMtrFldY.SetText(String());
224 aMtrFldY.Disable();
225 aFtY.Disable();