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 "hintids.hxx"
34cdf0e10cSrcweir #include <svx/gallery.hxx>
35cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen
36cdf0e10cSrcweir #include <vcl/msgbox.hxx>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #include <editeng/brshitem.hxx>
39cdf0e10cSrcweir #include <svl/urihelper.hxx>
40cdf0e10cSrcweir #include <vcl/graph.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include "swtypes.hxx"
43cdf0e10cSrcweir #include "docsh.hxx"
44cdf0e10cSrcweir #include "insrule.hxx"
45cdf0e10cSrcweir #include "swvset.hxx"
46cdf0e10cSrcweir #include "insrule.hrc"
47cdf0e10cSrcweir #include "misc.hrc"
48cdf0e10cSrcweir #include "helpid.h"
49cdf0e10cSrcweir
50cdf0e10cSrcweir /*------------------------------------------------------------------------
51cdf0e10cSrcweir Beschreibung:
52cdf0e10cSrcweir ------------------------------------------------------------------------*/
53cdf0e10cSrcweir
54cdf0e10cSrcweir
SwInsertGrfRulerDlg(Window * pParent)55cdf0e10cSrcweir SwInsertGrfRulerDlg::SwInsertGrfRulerDlg( Window* pParent ) :
56cdf0e10cSrcweir SfxModalDialog(pParent, SW_RES(DLG_INSERT_RULER)),
57cdf0e10cSrcweir aSelectionFL(this, SW_RES(FL_SEL )),
58cdf0e10cSrcweir aOkPB (this, SW_RES(PB_OK )),
59cdf0e10cSrcweir aCancelPB (this, SW_RES(PB_CANCEL )),
60cdf0e10cSrcweir aHelpPB (this, SW_RES(PB_HELP )),
61cdf0e10cSrcweir
62cdf0e10cSrcweir sSimple (SW_RES(ST_SIMPLE)),
63cdf0e10cSrcweir nSelPos(USHRT_MAX),
64cdf0e10cSrcweir pExampleVS (new SwRulerValueSet(this, SW_RES(VS_EXAMPLE )))
65cdf0e10cSrcweir {
66cdf0e10cSrcweir FreeResource();
67cdf0e10cSrcweir pExampleVS->SetLineCount(6);
68cdf0e10cSrcweir pExampleVS->SetColCount(1);
69cdf0e10cSrcweir pExampleVS->SetSelectHdl(LINK(this, SwInsertGrfRulerDlg, SelectHdl));
70cdf0e10cSrcweir pExampleVS->SetDoubleClickHdl(LINK(this, SwInsertGrfRulerDlg, DoubleClickHdl));
71cdf0e10cSrcweir pExampleVS->GrabFocus();
72cdf0e10cSrcweir
73cdf0e10cSrcweir // Grafiknamen ermitteln
74cdf0e10cSrcweir GalleryExplorer::BeginLocking(GALLERY_THEME_RULERS);
75cdf0e10cSrcweir GalleryExplorer::FillObjList( GALLERY_THEME_RULERS, aGrfNames );
76cdf0e10cSrcweir pExampleVS->SetHelpId(HID_VS_RULER);
77cdf0e10cSrcweir Color aColor(COL_WHITE);
78cdf0e10cSrcweir pExampleVS->InsertItem( 1, 1);
79cdf0e10cSrcweir pExampleVS->SetItemText( 1, sSimple);
80cdf0e10cSrcweir
81cdf0e10cSrcweir for(sal_uInt16 i = 1; i <= aGrfNames.Count(); i++)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir pExampleVS->InsertItem( i + 1, i);
84cdf0e10cSrcweir pExampleVS->SetItemText( i + 1, *((String*)aGrfNames.GetObject(i-1)));
85cdf0e10cSrcweir }
86cdf0e10cSrcweir pExampleVS->Show();
87cdf0e10cSrcweir
88cdf0e10cSrcweir }
89cdf0e10cSrcweir /*-----------------14.02.97 13.18-------------------
90cdf0e10cSrcweir
91cdf0e10cSrcweir --------------------------------------------------*/
92cdf0e10cSrcweir
~SwInsertGrfRulerDlg()93cdf0e10cSrcweir SwInsertGrfRulerDlg::~SwInsertGrfRulerDlg()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir GalleryExplorer::EndLocking(GALLERY_THEME_RULERS);
96cdf0e10cSrcweir delete pExampleVS;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
99cdf0e10cSrcweir /*-----------------14.02.97 13.17-------------------
100cdf0e10cSrcweir
101cdf0e10cSrcweir --------------------------------------------------*/
102cdf0e10cSrcweir
GetGraphicName()103cdf0e10cSrcweir String SwInsertGrfRulerDlg::GetGraphicName()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir String sRet;
106cdf0e10cSrcweir sal_uInt16 nSel = nSelPos - 2; //align selection position with ValueSet index
107cdf0e10cSrcweir if(nSel < aGrfNames.Count())
108cdf0e10cSrcweir sRet = URIHelper::SmartRel2Abs(
109cdf0e10cSrcweir INetURLObject(), *(String*) aGrfNames.GetObject(nSel),
110cdf0e10cSrcweir URIHelper::GetMaybeFileHdl());
111cdf0e10cSrcweir return sRet;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir /*-----------------14.02.97 13.20-------------------
115cdf0e10cSrcweir
116cdf0e10cSrcweir --------------------------------------------------*/
117cdf0e10cSrcweir
IMPL_LINK(SwInsertGrfRulerDlg,SelectHdl,ValueSet *,pVS)118cdf0e10cSrcweir IMPL_LINK(SwInsertGrfRulerDlg, SelectHdl, ValueSet*, pVS)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir nSelPos = pVS->GetSelectItemId();
121cdf0e10cSrcweir aOkPB.Enable();
122cdf0e10cSrcweir return 0;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
125cdf0e10cSrcweir /*-----------------14.02.97 14.17-------------------
126cdf0e10cSrcweir
127cdf0e10cSrcweir --------------------------------------------------*/
SwRulerValueSet(Window * pParent,const ResId & rResId)128cdf0e10cSrcweir SwRulerValueSet::SwRulerValueSet( Window* pParent, const ResId& rResId ) :
129cdf0e10cSrcweir SvxBmpNumValueSet(pParent, rResId)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir SetStyle( GetStyle() & ~WB_ITEMBORDER );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir /*-----------------14.02.97 14.17-------------------
134cdf0e10cSrcweir
135cdf0e10cSrcweir --------------------------------------------------*/
~SwRulerValueSet()136cdf0e10cSrcweir SwRulerValueSet::~SwRulerValueSet()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir }
139cdf0e10cSrcweir /*-----------------14.02.97 13.42-------------------
140cdf0e10cSrcweir
141cdf0e10cSrcweir --------------------------------------------------*/
UserDraw(const UserDrawEvent & rUDEvt)142cdf0e10cSrcweir void __EXPORT SwRulerValueSet::UserDraw( const UserDrawEvent& rUDEvt )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir Rectangle aRect = rUDEvt.GetRect();
145cdf0e10cSrcweir OutputDevice* pDev = rUDEvt.GetDevice();
146cdf0e10cSrcweir sal_uInt16 nItemId = rUDEvt.GetItemId();
147cdf0e10cSrcweir Point aBLPos = aRect.TopLeft();
148cdf0e10cSrcweir
149cdf0e10cSrcweir // Itemzaehlung beginnt bei 1, und die 1. ist die einfache Linie
150cdf0e10cSrcweir if(nItemId > 1)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir Graphic aGraphic;
153cdf0e10cSrcweir if(GalleryExplorer::GetGraphicObj( GALLERY_THEME_RULERS, nItemId - 2,
154cdf0e10cSrcweir &aGraphic))
155cdf0e10cSrcweir {
156cdf0e10cSrcweir Size aGrfSize = aGraphic.GetPrefSize();
157cdf0e10cSrcweir if(aGrfSize.Width() && aGrfSize.Height())
158cdf0e10cSrcweir {
159cdf0e10cSrcweir int nRelGrf = aGrfSize.Height() * 100 / aGrfSize.Width();
160cdf0e10cSrcweir Size aWinSize = aRect.GetSize();
161cdf0e10cSrcweir Size aPaintSize = aWinSize;
162cdf0e10cSrcweir int nRelWin = aWinSize.Height() * 100 / aWinSize.Width();
163cdf0e10cSrcweir if(nRelGrf > nRelWin)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir aPaintSize.Width() = aWinSize.Height() * 100 / nRelGrf;
166cdf0e10cSrcweir aBLPos.X() += (aWinSize.Width() - aPaintSize.Width()) /2;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir else
169cdf0e10cSrcweir {
170cdf0e10cSrcweir aPaintSize.Height() = aWinSize.Width() * nRelGrf/100;
171cdf0e10cSrcweir aBLPos.Y() += (aWinSize.Height() - aPaintSize.Height()) /2;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir aBLPos.X() -= aPaintSize.Width() /2;
174cdf0e10cSrcweir aBLPos.Y() -= aPaintSize.Height() /2;
175cdf0e10cSrcweir
176cdf0e10cSrcweir aPaintSize.Width() *= 2;
177cdf0e10cSrcweir aPaintSize.Height() *= 2;
178cdf0e10cSrcweir if(aPaintSize.Height() < 2)
179cdf0e10cSrcweir aPaintSize.Height() = 2;
180cdf0e10cSrcweir Region aRegion = pDev->GetClipRegion();
181cdf0e10cSrcweir pDev->SetClipRegion(aRect);
182cdf0e10cSrcweir aGraphic.Draw(pDev, aBLPos, aPaintSize);
183cdf0e10cSrcweir pDev->SetClipRegion(aRegion);
184cdf0e10cSrcweir }
185cdf0e10cSrcweir }
186cdf0e10cSrcweir else
187cdf0e10cSrcweir {
188cdf0e10cSrcweir SetGrfNotFound(sal_True);
189cdf0e10cSrcweir }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir else
192cdf0e10cSrcweir {
193cdf0e10cSrcweir // Text fuer einfache Linie painten
194cdf0e10cSrcweir Font aOldFont = pDev->GetFont();
195cdf0e10cSrcweir Font aFont = pDev->GetFont();
196cdf0e10cSrcweir Size aSize = aFont.GetSize();
197cdf0e10cSrcweir int nRectHeight = aRect.GetHeight();
198cdf0e10cSrcweir aSize.Height() = nRectHeight * 2 / 3;
199cdf0e10cSrcweir aFont.SetSize(aSize);
200cdf0e10cSrcweir pDev->SetFont(aFont);
201cdf0e10cSrcweir String aText(GetItemText(nItemId));
202cdf0e10cSrcweir aSize.Width() = pDev->GetTextWidth(aText);
203cdf0e10cSrcweir aSize.Height() = pDev->GetTextHeight();
204cdf0e10cSrcweir Point aPos(aBLPos);
205cdf0e10cSrcweir aPos.Y() += (nRectHeight - aSize.Height()) / 2;
206cdf0e10cSrcweir aPos.X() += (aRect.GetWidth() - aSize.Width()) / 2;
207cdf0e10cSrcweir pDev->DrawText(aPos, aText);
208cdf0e10cSrcweir
209cdf0e10cSrcweir pDev->SetFont(aOldFont);
210cdf0e10cSrcweir }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
213cdf0e10cSrcweir /*-----------------15.02.97 10.03-------------------
214cdf0e10cSrcweir
215cdf0e10cSrcweir --------------------------------------------------*/
216cdf0e10cSrcweir
IMPL_LINK(SwInsertGrfRulerDlg,DoubleClickHdl,ValueSet *,EMPTYARG)217cdf0e10cSrcweir IMPL_LINK(SwInsertGrfRulerDlg, DoubleClickHdl, ValueSet*, EMPTYARG)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir EndDialog(RET_OK);
220cdf0e10cSrcweir return 0;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
223