Files
libreoffice/sw/source/ui/misc/insrule.cxx

227 lines
7.1 KiB
C++
Raw Normal View History

2000-09-18 16:15:01 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:15:01 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:15:01 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:15:01 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:15:01 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
#ifdef SW_DLLIMPLEMENTATION
#undef SW_DLLIMPLEMENTATION
#endif
2000-09-18 16:15:01 +00:00
#include "hintids.hxx"
#include <svx/gallery.hxx>
#ifndef _MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#include <editeng/brshitem.hxx>
#include <svl/urihelper.hxx>
#include <vcl/graph.hxx>
2000-09-18 16:15:01 +00:00
#include "swtypes.hxx"
#include "docsh.hxx"
#include "insrule.hxx"
#include "swvset.hxx"
#include "insrule.hrc"
#include "misc.hrc"
#include "helpid.h"
/*------------------------------------------------------------------------
Beschreibung:
------------------------------------------------------------------------*/
2002-04-05 13:18:34 +00:00
SwInsertGrfRulerDlg::SwInsertGrfRulerDlg( Window* pParent ) :
2000-09-18 16:15:01 +00:00
SfxModalDialog(pParent, SW_RES(DLG_INSERT_RULER)),
aSelectionFL(this, SW_RES(FL_SEL )),
aOkPB (this, SW_RES(PB_OK )),
aCancelPB (this, SW_RES(PB_CANCEL )),
aHelpPB (this, SW_RES(PB_HELP )),
sSimple (SW_RES(ST_SIMPLE)),
nSelPos(USHRT_MAX),
pExampleVS (new SwRulerValueSet(this, SW_RES(VS_EXAMPLE )))
2000-09-18 16:15:01 +00:00
{
FreeResource();
pExampleVS->SetLineCount(6);
pExampleVS->SetColCount(1);
pExampleVS->SetSelectHdl(LINK(this, SwInsertGrfRulerDlg, SelectHdl));
pExampleVS->SetDoubleClickHdl(LINK(this, SwInsertGrfRulerDlg, DoubleClickHdl));
pExampleVS->GrabFocus();
// Grafiknamen ermitteln
2002-04-05 13:18:34 +00:00
GalleryExplorer::BeginLocking(GALLERY_THEME_RULERS);
2000-09-18 16:15:01 +00:00
GalleryExplorer::FillObjList( GALLERY_THEME_RULERS, aGrfNames );
pExampleVS->SetHelpId(HID_VS_RULER);
Color aColor(COL_WHITE);
pExampleVS->InsertItem( 1, 1);
pExampleVS->SetItemText( 1, sSimple);
for(USHORT i = 1; i <= aGrfNames.Count(); i++)
{
pExampleVS->InsertItem( i + 1, i);
pExampleVS->SetItemText( i + 1, *((String*)aGrfNames.GetObject(i-1)));
}
pExampleVS->Show();
}
/*-----------------14.02.97 13.18-------------------
--------------------------------------------------*/
SwInsertGrfRulerDlg::~SwInsertGrfRulerDlg()
{
2002-04-05 13:18:34 +00:00
GalleryExplorer::EndLocking(GALLERY_THEME_RULERS);
2000-09-18 16:15:01 +00:00
delete pExampleVS;
}
/*-----------------14.02.97 13.17-------------------
--------------------------------------------------*/
String SwInsertGrfRulerDlg::GetGraphicName()
{
String sRet;
USHORT nSel = nSelPos - 2; //align selection position with ValueSet index
if(nSel < aGrfNames.Count())
sRet = URIHelper::SmartRel2Abs(
INetURLObject(), *(String*) aGrfNames.GetObject(nSel),
URIHelper::GetMaybeFileHdl());
2000-09-18 16:15:01 +00:00
return sRet;
}
/*-----------------14.02.97 13.20-------------------
--------------------------------------------------*/
IMPL_LINK(SwInsertGrfRulerDlg, SelectHdl, ValueSet*, pVS)
{
nSelPos = pVS->GetSelectItemId();
aOkPB.Enable();
return 0;
}
/*-----------------14.02.97 14.17-------------------
--------------------------------------------------*/
2002-04-05 13:18:34 +00:00
SwRulerValueSet::SwRulerValueSet( Window* pParent, const ResId& rResId ) :
SvxBmpNumValueSet(pParent, rResId)
2000-09-18 16:15:01 +00:00
{
2002-04-05 13:18:34 +00:00
SetStyle( GetStyle() & ~WB_ITEMBORDER );
2000-09-18 16:15:01 +00:00
}
/*-----------------14.02.97 14.17-------------------
--------------------------------------------------*/
SwRulerValueSet::~SwRulerValueSet()
{
}
/*-----------------14.02.97 13.42-------------------
--------------------------------------------------*/
void __EXPORT SwRulerValueSet::UserDraw( const UserDrawEvent& rUDEvt )
{
Rectangle aRect = rUDEvt.GetRect();
OutputDevice* pDev = rUDEvt.GetDevice();
USHORT nItemId = rUDEvt.GetItemId();
Point aBLPos = aRect.TopLeft();
// Itemzaehlung beginnt bei 1, und die 1. ist die einfache Linie
if(nItemId > 1)
{
2002-04-05 13:18:34 +00:00
Graphic aGraphic;
if(GalleryExplorer::GetGraphicObj( GALLERY_THEME_RULERS, nItemId - 2,
&aGraphic))
2000-09-18 16:15:01 +00:00
{
2002-04-05 13:18:34 +00:00
Size aGrfSize = aGraphic.GetPrefSize();
if(aGrfSize.Width() && aGrfSize.Height())
2000-09-18 16:15:01 +00:00
{
2002-04-05 13:18:34 +00:00
int nRelGrf = aGrfSize.Height() * 100 / aGrfSize.Width();
Size aWinSize = aRect.GetSize();
Size aPaintSize = aWinSize;
int nRelWin = aWinSize.Height() * 100 / aWinSize.Width();
if(nRelGrf > nRelWin)
2000-09-18 16:15:01 +00:00
{
2002-04-05 13:18:34 +00:00
aPaintSize.Width() = aWinSize.Height() * 100 / nRelGrf;
aBLPos.X() += (aWinSize.Width() - aPaintSize.Width()) /2;
2000-09-18 16:15:01 +00:00
}
2002-04-05 13:18:34 +00:00
else
{
aPaintSize.Height() = aWinSize.Width() * nRelGrf/100;
aBLPos.Y() += (aWinSize.Height() - aPaintSize.Height()) /2;
}
aBLPos.X() -= aPaintSize.Width() /2;
aBLPos.Y() -= aPaintSize.Height() /2;
aPaintSize.Width() *= 2;
aPaintSize.Height() *= 2;
if(aPaintSize.Height() < 2)
aPaintSize.Height() = 2;
Region aRegion = pDev->GetClipRegion();
pDev->SetClipRegion(aRect);
aGraphic.Draw(pDev, aBLPos, aPaintSize);
pDev->SetClipRegion(aRegion);
2000-09-18 16:15:01 +00:00
}
2002-04-05 13:18:34 +00:00
}
else
{
SetGrfNotFound(TRUE);
2000-09-18 16:15:01 +00:00
}
}
else
{
// Text fuer einfache Linie painten
Font aOldFont = pDev->GetFont();
Font aFont = pDev->GetFont();
Size aSize = aFont.GetSize();
int nRectHeight = aRect.GetHeight();
aSize.Height() = nRectHeight * 2 / 3;
aFont.SetSize(aSize);
pDev->SetFont(aFont);
String aText(GetItemText(nItemId));
aSize.Width() = pDev->GetTextWidth(aText);
aSize.Height() = pDev->GetTextHeight();
Point aPos(aBLPos);
aPos.Y() += (nRectHeight - aSize.Height()) / 2;
aPos.X() += (aRect.GetWidth() - aSize.Width()) / 2;
pDev->DrawText(aPos, aText);
pDev->SetFont(aOldFont);
}
}
/*-----------------15.02.97 10.03-------------------
--------------------------------------------------*/
IMPL_LINK(SwInsertGrfRulerDlg, DoubleClickHdl, ValueSet*, EMPTYARG)
2000-09-18 16:15:01 +00:00
{
EndDialog(RET_OK);
return 0;
}