update dev300-m58
[ooovba.git] / sw / source / ui / misc / insrule.cxx
blob87468ba50ce47692d3194cdba00b3bbc8b5a1d55
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: insrule.cxx,v $
10 * $Revision: 1.15 $
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_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
40 #include "hintids.hxx"
41 #include <svx/gallery.hxx>
42 #ifndef _MSGBOX_HXX //autogen
43 #include <vcl/msgbox.hxx>
44 #endif
45 #include <svx/brshitem.hxx>
46 #include <svtools/urihelper.hxx>
47 #include <vcl/graph.hxx>
49 #include "swtypes.hxx"
50 #include "docsh.hxx"
51 #include "insrule.hxx"
52 #include "swvset.hxx"
53 #include "insrule.hrc"
54 #include "misc.hrc"
55 #include "helpid.h"
57 /*------------------------------------------------------------------------
58 Beschreibung:
59 ------------------------------------------------------------------------*/
62 SwInsertGrfRulerDlg::SwInsertGrfRulerDlg( Window* pParent ) :
63 SfxModalDialog(pParent, SW_RES(DLG_INSERT_RULER)),
64 aSelectionFL(this, SW_RES(FL_SEL )),
65 aOkPB (this, SW_RES(PB_OK )),
66 aCancelPB (this, SW_RES(PB_CANCEL )),
67 aHelpPB (this, SW_RES(PB_HELP )),
69 sSimple (SW_RES(ST_SIMPLE)),
70 nSelPos(USHRT_MAX),
71 pExampleVS (new SwRulerValueSet(this, SW_RES(VS_EXAMPLE )))
73 FreeResource();
74 pExampleVS->SetLineCount(6);
75 pExampleVS->SetColCount(1);
76 pExampleVS->SetSelectHdl(LINK(this, SwInsertGrfRulerDlg, SelectHdl));
77 pExampleVS->SetDoubleClickHdl(LINK(this, SwInsertGrfRulerDlg, DoubleClickHdl));
78 pExampleVS->GrabFocus();
80 // Grafiknamen ermitteln
81 GalleryExplorer::BeginLocking(GALLERY_THEME_RULERS);
82 GalleryExplorer::FillObjList( GALLERY_THEME_RULERS, aGrfNames );
83 pExampleVS->SetHelpId(HID_VS_RULER);
84 Color aColor(COL_WHITE);
85 pExampleVS->InsertItem( 1, 1);
86 pExampleVS->SetItemText( 1, sSimple);
88 for(USHORT i = 1; i <= aGrfNames.Count(); i++)
90 pExampleVS->InsertItem( i + 1, i);
91 pExampleVS->SetItemText( i + 1, *((String*)aGrfNames.GetObject(i-1)));
93 pExampleVS->Show();
96 /*-----------------14.02.97 13.18-------------------
98 --------------------------------------------------*/
100 SwInsertGrfRulerDlg::~SwInsertGrfRulerDlg()
102 GalleryExplorer::EndLocking(GALLERY_THEME_RULERS);
103 delete pExampleVS;
106 /*-----------------14.02.97 13.17-------------------
108 --------------------------------------------------*/
110 String SwInsertGrfRulerDlg::GetGraphicName()
112 String sRet;
113 USHORT nSel = nSelPos - 2; //align selection position with ValueSet index
114 if(nSel < aGrfNames.Count())
115 sRet = URIHelper::SmartRel2Abs(
116 INetURLObject(), *(String*) aGrfNames.GetObject(nSel),
117 URIHelper::GetMaybeFileHdl());
118 return sRet;
121 /*-----------------14.02.97 13.20-------------------
123 --------------------------------------------------*/
125 IMPL_LINK(SwInsertGrfRulerDlg, SelectHdl, ValueSet*, pVS)
127 nSelPos = pVS->GetSelectItemId();
128 aOkPB.Enable();
129 return 0;
132 /*-----------------14.02.97 14.17-------------------
134 --------------------------------------------------*/
135 SwRulerValueSet::SwRulerValueSet( Window* pParent, const ResId& rResId ) :
136 SvxBmpNumValueSet(pParent, rResId)
138 SetStyle( GetStyle() & ~WB_ITEMBORDER );
140 /*-----------------14.02.97 14.17-------------------
142 --------------------------------------------------*/
143 SwRulerValueSet::~SwRulerValueSet()
146 /*-----------------14.02.97 13.42-------------------
148 --------------------------------------------------*/
149 void __EXPORT SwRulerValueSet::UserDraw( const UserDrawEvent& rUDEvt )
151 Rectangle aRect = rUDEvt.GetRect();
152 OutputDevice* pDev = rUDEvt.GetDevice();
153 USHORT nItemId = rUDEvt.GetItemId();
154 Point aBLPos = aRect.TopLeft();
156 // Itemzaehlung beginnt bei 1, und die 1. ist die einfache Linie
157 if(nItemId > 1)
159 Graphic aGraphic;
160 if(GalleryExplorer::GetGraphicObj( GALLERY_THEME_RULERS, nItemId - 2,
161 &aGraphic))
163 Size aGrfSize = aGraphic.GetPrefSize();
164 if(aGrfSize.Width() && aGrfSize.Height())
166 int nRelGrf = aGrfSize.Height() * 100 / aGrfSize.Width();
167 Size aWinSize = aRect.GetSize();
168 Size aPaintSize = aWinSize;
169 int nRelWin = aWinSize.Height() * 100 / aWinSize.Width();
170 if(nRelGrf > nRelWin)
172 aPaintSize.Width() = aWinSize.Height() * 100 / nRelGrf;
173 aBLPos.X() += (aWinSize.Width() - aPaintSize.Width()) /2;
175 else
177 aPaintSize.Height() = aWinSize.Width() * nRelGrf/100;
178 aBLPos.Y() += (aWinSize.Height() - aPaintSize.Height()) /2;
180 aBLPos.X() -= aPaintSize.Width() /2;
181 aBLPos.Y() -= aPaintSize.Height() /2;
183 aPaintSize.Width() *= 2;
184 aPaintSize.Height() *= 2;
185 if(aPaintSize.Height() < 2)
186 aPaintSize.Height() = 2;
187 Region aRegion = pDev->GetClipRegion();
188 pDev->SetClipRegion(aRect);
189 aGraphic.Draw(pDev, aBLPos, aPaintSize);
190 pDev->SetClipRegion(aRegion);
193 else
195 SetGrfNotFound(TRUE);
198 else
200 // Text fuer einfache Linie painten
201 Font aOldFont = pDev->GetFont();
202 Font aFont = pDev->GetFont();
203 Size aSize = aFont.GetSize();
204 int nRectHeight = aRect.GetHeight();
205 aSize.Height() = nRectHeight * 2 / 3;
206 aFont.SetSize(aSize);
207 pDev->SetFont(aFont);
208 String aText(GetItemText(nItemId));
209 aSize.Width() = pDev->GetTextWidth(aText);
210 aSize.Height() = pDev->GetTextHeight();
211 Point aPos(aBLPos);
212 aPos.Y() += (nRectHeight - aSize.Height()) / 2;
213 aPos.X() += (aRect.GetWidth() - aSize.Width()) / 2;
214 pDev->DrawText(aPos, aText);
216 pDev->SetFont(aOldFont);
220 /*-----------------15.02.97 10.03-------------------
222 --------------------------------------------------*/
224 IMPL_LINK(SwInsertGrfRulerDlg, DoubleClickHdl, ValueSet*, EMPTYARG)
226 EndDialog(RET_OK);
227 return 0;