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