Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "hintids.hxx"
30 : : #include <svx/gallery.hxx>
31 : : #include <vcl/msgbox.hxx>
32 : : #include <editeng/brshitem.hxx>
33 : : #include <svl/urihelper.hxx>
34 : : #include <vcl/graph.hxx>
35 : :
36 : : #include "swtypes.hxx"
37 : : #include "docsh.hxx"
38 : : #include "insrule.hxx"
39 : : #include "swvset.hxx"
40 : : #include "insrule.hrc"
41 : : #include "misc.hrc"
42 : : #include "helpid.h"
43 : :
44 : 0 : SwInsertGrfRulerDlg::SwInsertGrfRulerDlg( Window* pParent ) :
45 : : SfxModalDialog(pParent, SW_RES(DLG_INSERT_RULER)),
46 : : aSelectionFL(this, SW_RES(FL_SEL )),
47 : : aOkPB (this, SW_RES(PB_OK )),
48 : : aCancelPB (this, SW_RES(PB_CANCEL )),
49 : : aHelpPB (this, SW_RES(PB_HELP )),
50 : :
51 : : sSimple (SW_RES(ST_SIMPLE)),
52 : : nSelPos(USHRT_MAX),
53 : 0 : pExampleVS (new SwRulerValueSet(this, SW_RES(VS_EXAMPLE )))
54 : : {
55 : 0 : FreeResource();
56 : 0 : pExampleVS->SetLineCount(6);
57 : 0 : pExampleVS->SetColCount(1);
58 : 0 : pExampleVS->SetSelectHdl(LINK(this, SwInsertGrfRulerDlg, SelectHdl));
59 : 0 : pExampleVS->SetDoubleClickHdl(LINK(this, SwInsertGrfRulerDlg, DoubleClickHdl));
60 : 0 : pExampleVS->GrabFocus();
61 : :
62 : : // determine graphic name
63 : 0 : GalleryExplorer::BeginLocking(GALLERY_THEME_RULERS);
64 : 0 : GalleryExplorer::FillObjList( GALLERY_THEME_RULERS, aGrfNames );
65 : 0 : pExampleVS->SetHelpId(HID_VS_RULER);
66 : 0 : Color aColor(COL_WHITE);
67 : 0 : pExampleVS->InsertItem( 1, 1);
68 : 0 : pExampleVS->SetItemText( 1, sSimple);
69 : :
70 : 0 : for(sal_uInt16 i = 1; i <= aGrfNames.size(); i++)
71 : : {
72 : 0 : pExampleVS->InsertItem( i + 1, i);
73 : 0 : pExampleVS->SetItemText( i + 1, aGrfNames[i-1]);
74 : : }
75 : 0 : pExampleVS->Show();
76 : :
77 : 0 : }
78 : :
79 : 0 : SwInsertGrfRulerDlg::~SwInsertGrfRulerDlg()
80 : : {
81 : 0 : GalleryExplorer::EndLocking(GALLERY_THEME_RULERS);
82 : 0 : delete pExampleVS;
83 : 0 : }
84 : :
85 : 0 : String SwInsertGrfRulerDlg::GetGraphicName()
86 : : {
87 : 0 : String sRet;
88 : 0 : sal_uInt16 nSel = nSelPos - 2; //align selection position with ValueSet index
89 : 0 : if(nSel < aGrfNames.size())
90 : : sRet = URIHelper::SmartRel2Abs(
91 : 0 : INetURLObject(), aGrfNames[nSel],
92 : 0 : URIHelper::GetMaybeFileHdl());
93 : 0 : return sRet;
94 : : }
95 : :
96 : 0 : IMPL_LINK(SwInsertGrfRulerDlg, SelectHdl, ValueSet*, pVS)
97 : : {
98 : 0 : nSelPos = pVS->GetSelectItemId();
99 : 0 : aOkPB.Enable();
100 : 0 : return 0;
101 : : }
102 : :
103 : 0 : SwRulerValueSet::SwRulerValueSet( Window* pParent, const ResId& rResId ) :
104 : 0 : SvxBmpNumValueSet(pParent, rResId)
105 : : {
106 : 0 : SetStyle( GetStyle() & ~WB_ITEMBORDER );
107 : 0 : }
108 : :
109 : 0 : SwRulerValueSet::~SwRulerValueSet()
110 : : {
111 : 0 : }
112 : :
113 : 0 : void SwRulerValueSet::UserDraw( const UserDrawEvent& rUDEvt )
114 : : {
115 : 0 : Rectangle aRect = rUDEvt.GetRect();
116 : 0 : OutputDevice* pDev = rUDEvt.GetDevice();
117 : 0 : sal_uInt16 nItemId = rUDEvt.GetItemId();
118 : 0 : Point aBLPos = aRect.TopLeft();
119 : :
120 : : // item count starts with 1 and the 1st is the simple line
121 : 0 : if(nItemId > 1)
122 : : {
123 : 0 : Graphic aGraphic;
124 : 0 : if(GalleryExplorer::GetGraphicObj( GALLERY_THEME_RULERS, nItemId - 2,
125 : 0 : &aGraphic))
126 : : {
127 : 0 : Size aGrfSize = aGraphic.GetPrefSize();
128 : 0 : if(aGrfSize.Width() && aGrfSize.Height())
129 : : {
130 : 0 : int nRelGrf = aGrfSize.Height() * 100 / aGrfSize.Width();
131 : 0 : Size aWinSize = aRect.GetSize();
132 : 0 : Size aPaintSize = aWinSize;
133 : 0 : int nRelWin = aWinSize.Height() * 100 / aWinSize.Width();
134 : 0 : if(nRelGrf > nRelWin)
135 : : {
136 : 0 : aPaintSize.Width() = aWinSize.Height() * 100 / nRelGrf;
137 : 0 : aBLPos.X() += (aWinSize.Width() - aPaintSize.Width()) /2;
138 : : }
139 : : else
140 : : {
141 : 0 : aPaintSize.Height() = aWinSize.Width() * nRelGrf/100;
142 : 0 : aBLPos.Y() += (aWinSize.Height() - aPaintSize.Height()) /2;
143 : : }
144 : 0 : aBLPos.X() -= aPaintSize.Width() /2;
145 : 0 : aBLPos.Y() -= aPaintSize.Height() /2;
146 : :
147 : 0 : aPaintSize.Width() *= 2;
148 : 0 : aPaintSize.Height() *= 2;
149 : 0 : if(aPaintSize.Height() < 2)
150 : 0 : aPaintSize.Height() = 2;
151 : 0 : Region aRegion = pDev->GetClipRegion();
152 : 0 : pDev->SetClipRegion(aRect);
153 : 0 : aGraphic.Draw(pDev, aBLPos, aPaintSize);
154 : 0 : pDev->SetClipRegion(aRegion);
155 : : }
156 : : }
157 : : else
158 : : {
159 : 0 : SetGrfNotFound(sal_True);
160 : 0 : }
161 : : }
162 : : else
163 : : {
164 : : // paint text for simple line
165 : 0 : Font aOldFont = pDev->GetFont();
166 : 0 : Font aFont = pDev->GetFont();
167 : 0 : Size aSize = aFont.GetSize();
168 : 0 : int nRectHeight = aRect.GetHeight();
169 : 0 : aSize.Height() = nRectHeight * 2 / 3;
170 : 0 : aFont.SetSize(aSize);
171 : 0 : pDev->SetFont(aFont);
172 : 0 : String aText(GetItemText(nItemId));
173 : 0 : aSize.Width() = pDev->GetTextWidth(aText);
174 : 0 : aSize.Height() = pDev->GetTextHeight();
175 : 0 : Point aPos(aBLPos);
176 : 0 : aPos.Y() += (nRectHeight - aSize.Height()) / 2;
177 : 0 : aPos.X() += (aRect.GetWidth() - aSize.Width()) / 2;
178 : 0 : pDev->DrawText(aPos, aText);
179 : :
180 : 0 : pDev->SetFont(aOldFont);
181 : : }
182 : 0 : }
183 : :
184 : 0 : IMPL_LINK_NOARG(SwInsertGrfRulerDlg, DoubleClickHdl)
185 : : {
186 : 0 : EndDialog(RET_OK);
187 : 0 : return 0;
188 : : }
189 : :
190 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|