xref: /trunk/main/sw/source/ui/misc/insrule.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 
33 #include "hintids.hxx"
34 #include <svx/gallery.hxx>
35 #ifndef _MSGBOX_HXX //autogen
36 #include <vcl/msgbox.hxx>
37 #endif
38 #include <editeng/brshitem.hxx>
39 #include <svl/urihelper.hxx>
40 #include <vcl/graph.hxx>
41 
42 #include "swtypes.hxx"
43 #include "docsh.hxx"
44 #include "insrule.hxx"
45 #include "swvset.hxx"
46 #include "insrule.hrc"
47 #include "misc.hrc"
48 #include "helpid.h"
49 
50 /*------------------------------------------------------------------------
51  Beschreibung:
52 ------------------------------------------------------------------------*/
53 
54 
SwInsertGrfRulerDlg(Window * pParent)55 SwInsertGrfRulerDlg::SwInsertGrfRulerDlg( Window* pParent ) :
56 	SfxModalDialog(pParent, SW_RES(DLG_INSERT_RULER)),
57     aSelectionFL(this, SW_RES(FL_SEL     )),
58     aOkPB       (this, SW_RES(PB_OK     )),
59     aCancelPB   (this, SW_RES(PB_CANCEL )),
60     aHelpPB     (this, SW_RES(PB_HELP   )),
61 
62     sSimple (SW_RES(ST_SIMPLE)),
63     nSelPos(USHRT_MAX),
64     pExampleVS  (new SwRulerValueSet(this, SW_RES(VS_EXAMPLE )))
65 {
66 	FreeResource();
67 	pExampleVS->SetLineCount(6);
68 	pExampleVS->SetColCount(1);
69 	pExampleVS->SetSelectHdl(LINK(this, SwInsertGrfRulerDlg, SelectHdl));
70 	pExampleVS->SetDoubleClickHdl(LINK(this, SwInsertGrfRulerDlg, DoubleClickHdl));
71 	pExampleVS->GrabFocus();
72 
73 	// Grafiknamen ermitteln
74     GalleryExplorer::BeginLocking(GALLERY_THEME_RULERS);
75     GalleryExplorer::FillObjList( GALLERY_THEME_RULERS, aGrfNames );
76 	pExampleVS->SetHelpId(HID_VS_RULER);
77 	Color aColor(COL_WHITE);
78 	pExampleVS->InsertItem( 1, 1);
79 	pExampleVS->SetItemText( 1, sSimple);
80 
81 	for(sal_uInt16 i = 1; i <= aGrfNames.Count(); i++)
82 	{
83 		pExampleVS->InsertItem( i + 1, i);
84 		pExampleVS->SetItemText( i + 1, *((String*)aGrfNames.GetObject(i-1)));
85 	}
86 	pExampleVS->Show();
87 
88 }
89 /*-----------------14.02.97 13.18-------------------
90 
91 --------------------------------------------------*/
92 
~SwInsertGrfRulerDlg()93 SwInsertGrfRulerDlg::~SwInsertGrfRulerDlg()
94 {
95     GalleryExplorer::EndLocking(GALLERY_THEME_RULERS);
96     delete pExampleVS;
97 }
98 
99 /*-----------------14.02.97 13.17-------------------
100 
101 --------------------------------------------------*/
102 
GetGraphicName()103 String SwInsertGrfRulerDlg::GetGraphicName()
104 {
105 	String sRet;
106     sal_uInt16 nSel = nSelPos - 2; //align selection position with ValueSet index
107     if(nSel < aGrfNames.Count())
108         sRet = URIHelper::SmartRel2Abs(
109             INetURLObject(), *(String*) aGrfNames.GetObject(nSel),
110             URIHelper::GetMaybeFileHdl());
111 	return sRet;
112 }
113 
114 /*-----------------14.02.97 13.20-------------------
115 
116 --------------------------------------------------*/
117 
IMPL_LINK(SwInsertGrfRulerDlg,SelectHdl,ValueSet *,pVS)118 IMPL_LINK(SwInsertGrfRulerDlg, SelectHdl, ValueSet*, pVS)
119 {
120     nSelPos = pVS->GetSelectItemId();
121 	aOkPB.Enable();
122 	return 0;
123 }
124 
125 /*-----------------14.02.97 14.17-------------------
126 
127 --------------------------------------------------*/
SwRulerValueSet(Window * pParent,const ResId & rResId)128 SwRulerValueSet::SwRulerValueSet(   Window* pParent, const ResId& rResId ) :
129     SvxBmpNumValueSet(pParent, rResId)
130 {
131     SetStyle(  GetStyle() & ~WB_ITEMBORDER     );
132 }
133 /*-----------------14.02.97 14.17-------------------
134 
135 --------------------------------------------------*/
~SwRulerValueSet()136 SwRulerValueSet::~SwRulerValueSet()
137 {
138 }
139 /*-----------------14.02.97 13.42-------------------
140 
141 --------------------------------------------------*/
UserDraw(const UserDrawEvent & rUDEvt)142 void __EXPORT SwRulerValueSet::UserDraw( const UserDrawEvent& rUDEvt )
143 {
144 	Rectangle aRect = rUDEvt.GetRect();
145 	OutputDevice*  pDev = rUDEvt.GetDevice();
146 	sal_uInt16	nItemId = rUDEvt.GetItemId();
147 	Point aBLPos = aRect.TopLeft();
148 
149 	// Itemzaehlung beginnt bei 1, und die 1. ist die einfache Linie
150 	if(nItemId > 1)
151 	{
152         Graphic aGraphic;
153         if(GalleryExplorer::GetGraphicObj( GALLERY_THEME_RULERS, nItemId - 2,
154                                                             &aGraphic))
155         {
156             Size aGrfSize = aGraphic.GetPrefSize();
157             if(aGrfSize.Width() && aGrfSize.Height())
158             {
159                 int nRelGrf = aGrfSize.Height() * 100 / aGrfSize.Width();
160                 Size aWinSize = aRect.GetSize();
161                 Size aPaintSize = aWinSize;
162                 int nRelWin = aWinSize.Height() * 100 / aWinSize.Width();
163                 if(nRelGrf > nRelWin)
164                 {
165                     aPaintSize.Width() = aWinSize.Height() * 100 / nRelGrf;
166                     aBLPos.X() += (aWinSize.Width() - aPaintSize.Width()) /2;
167                 }
168                 else
169                 {
170                     aPaintSize.Height() = aWinSize.Width() * nRelGrf/100;
171                     aBLPos.Y() += (aWinSize.Height() - aPaintSize.Height()) /2;
172                 }
173                 aBLPos.X() -= aPaintSize.Width() /2;
174                 aBLPos.Y() -= aPaintSize.Height() /2;
175 
176                 aPaintSize.Width() *= 2;
177                 aPaintSize.Height() *= 2;
178                 if(aPaintSize.Height() < 2)
179                     aPaintSize.Height() = 2;
180                 Region aRegion = pDev->GetClipRegion();
181                 pDev->SetClipRegion(aRect);
182                 aGraphic.Draw(pDev, aBLPos, aPaintSize);
183                 pDev->SetClipRegion(aRegion);
184             }
185         }
186         else
187         {
188             SetGrfNotFound(sal_True);
189         }
190     }
191 	else
192 	{
193 		// Text fuer einfache Linie painten
194 		Font aOldFont = pDev->GetFont();
195 		Font aFont = pDev->GetFont();
196 		Size aSize = aFont.GetSize();
197 		int nRectHeight = aRect.GetHeight();
198 		aSize.Height() = nRectHeight * 2 / 3;
199 		aFont.SetSize(aSize);
200 		pDev->SetFont(aFont);
201 		String aText(GetItemText(nItemId));
202 		aSize.Width() = pDev->GetTextWidth(aText);
203 		aSize.Height() = pDev->GetTextHeight();
204 		Point aPos(aBLPos);
205 		aPos.Y() += (nRectHeight - aSize.Height()) / 2;
206 		aPos.X() += (aRect.GetWidth() - aSize.Width()) / 2;
207 		pDev->DrawText(aPos, aText);
208 
209 		pDev->SetFont(aOldFont);
210 	}
211 }
212 
213 /*-----------------15.02.97 10.03-------------------
214 
215 --------------------------------------------------*/
216 
IMPL_LINK(SwInsertGrfRulerDlg,DoubleClickHdl,ValueSet *,EMPTYARG)217 IMPL_LINK(SwInsertGrfRulerDlg, DoubleClickHdl, ValueSet*, EMPTYARG)
218 {
219 	EndDialog(RET_OK);
220 	return 0;
221 }
222 
223