summaryrefslogtreecommitdiff
path: root/bf_svx/source/xoutdev/svx_xtabhtch.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bf_svx/source/xoutdev/svx_xtabhtch.cxx')
-rw-r--r--bf_svx/source/xoutdev/svx_xtabhtch.cxx364
1 files changed, 364 insertions, 0 deletions
diff --git a/bf_svx/source/xoutdev/svx_xtabhtch.cxx b/bf_svx/source/xoutdev/svx_xtabhtch.cxx
new file mode 100644
index 000000000..4030e449a
--- /dev/null
+++ b/bf_svx/source/xoutdev/svx_xtabhtch.cxx
@@ -0,0 +1,364 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef SVX_LIGHT
+#include "XPropertyTable.hxx"
+#include <unotools/ucbstreamhelper.hxx>
+#include <vcl/svapp.hxx>
+
+#include "xmlxtimp.hxx"
+#endif
+
+#include <tools/urlobj.hxx>
+#include <vcl/virdev.hxx>
+#include <bf_svtools/itemset.hxx>
+#include <bf_sfx2/docfile.hxx>
+#include "dialogs.hrc"
+#include "dialmgr.hxx"
+#include "xtable.hxx"
+#include "xiocomp.hxx"
+#include "xpool.hxx"
+#include "xoutx.hxx"
+#include "dlgutil.hxx"
+
+#include <xflhtit.hxx>
+#include <xflclit.hxx>
+#include <xfillit0.hxx>
+
+namespace binfilter {
+
+using namespace ::com::sun::star;
+using namespace ::rtl;
+
+sal_Unicode const pszExtHatch[] = {'s','o','h'};
+
+char const aChckHatch[] = { 0x04, 0x00, 'S','O','H','L'}; // < 5.2
+char const aChckHatch0[] = { 0x04, 0x00, 'S','O','H','0'}; // = 5.2
+char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0
+
+// -----------------
+// class XHatchList
+// -----------------
+
+/*************************************************************************
+|*
+|* XHatchList::XHatchList()
+|*
+*************************************************************************/
+
+/*N*/ XHatchList::XHatchList( const String& rPath,
+/*N*/ XOutdevItemPool* pInPool,
+/*N*/ USHORT nInitSize, USHORT nReSize ) :
+/*N*/ XPropertyList ( rPath, pInPool, nInitSize, nReSize),
+/*N*/ pVD ( NULL ),
+/*N*/ pXOut ( NULL ),
+/*N*/ pXFSet ( NULL )
+/*N*/ {
+/*N*/ pBmpList = new List( nInitSize, nReSize );
+/*N*/ }
+
+/************************************************************************/
+
+/*N*/ XHatchList::~XHatchList()
+/*N*/ {
+/*N*/ if( pVD ) delete pVD;
+/*N*/ if( pXOut ) delete pXOut;
+/*N*/ if( pXFSet ) delete pXFSet;
+/*N*/ }
+
+/*N*/ XHatchEntry* XHatchList::Get(long nIndex) const
+/*N*/ {
+/*N*/ return (XHatchEntry*) XPropertyList::Get(nIndex, 0);
+/*N*/ }
+
+/************************************************************************/
+
+/*N*/ BOOL XHatchList::Load()
+/*N*/ {
+/*N*/ #ifndef SVX_LIGHT
+/*N*/ if( bListDirty )
+/*N*/ {
+/*N*/ bListDirty = FALSE;
+/*N*/
+/*N*/ INetURLObject aURL( aPath );
+/*N*/
+/*N*/ if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
+/*N*/ {
+/*N*/ DBG_ASSERT( !aPath.Len(), "invalid URL" );
+/*N*/ return FALSE;
+/*N*/ }
+/*N*/
+/*N*/ aURL.Append( aName );
+/*N*/
+/*N*/ if( !aURL.getExtension().getLength() )
+/*N*/ aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
+/*N*/
+/*N*/ // check if file exists, SfxMedium shows an errorbox else
+/*N*/ {
+/*N*/ ::com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionHandler > xHandler;
+/*N*/ SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ, xHandler );
+/*N*/
+/*N*/ sal_Bool bOk = pIStm && ( pIStm->GetError() == 0);
+/*N*/
+/*N*/ if( pIStm )
+/*N*/ delete pIStm;
+/*N*/
+/*N*/ if( !bOk )
+/*N*/ return sal_False;
+/*N*/ }
+/*N*/
+/*N*/ {
+/*N*/ SfxMedium aMedium( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ | STREAM_NOCREATE, TRUE );
+/*N*/ SvStream* pStream = aMedium.GetInStream();
+/*N*/ if( !pStream )
+/*N*/ return( FALSE );
+/*N*/
+/*N*/ char aCheck[6];
+/*N*/ pStream->Read( aCheck, 6 );
+/*N*/
+/*N*/ // Handelt es sich um die gew"unschte Tabelle?
+/*N*/ if( memcmp( aCheck, aChckHatch, sizeof( aChckHatch ) ) == 0 ||
+/*N*/ memcmp( aCheck, aChckHatch0, sizeof( aChckHatch0 ) ) == 0 )
+/*N*/ {
+/*N*/ ImpRead( *pStream );
+/*N*/ return( pStream->GetError() == SVSTREAM_OK );
+/*N*/ }
+/*N*/ else if( memcmp( aCheck, aChckXML, sizeof( aChckXML ) ) != 0 )
+/*N*/ {
+/*N*/ return FALSE;
+/*N*/ }
+/*N*/
+/*N*/ }
+/*N*/
+/*N*/ uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
+/*N*/ return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
+/*N*/ }
+/*N*/ #endif
+/*N*/ return( FALSE );
+/*N*/ }
+
+/************************************************************************/
+
+/*N*/ BOOL XHatchList::Create()
+/*N*/ {
+/*N*/ XubString aStr( SVX_RES( RID_SVXSTR_HATCH ).toString() );
+/*N*/ xub_StrLen nLen;
+/*N*/
+/*N*/ aStr.AppendAscii(" 1");
+/*N*/ nLen = aStr.Len() - 1;
+/*N*/ Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLACK),XHATCH_SINGLE,100, 0),aStr));
+/*N*/ aStr.SetChar(nLen, sal_Unicode('2'));
+/*N*/ Insert(new XHatchEntry(XHatch(RGB_Color(COL_RED ),XHATCH_DOUBLE, 80,450),aStr));
+/*N*/ aStr.SetChar(nLen, sal_Unicode('3'));
+/*N*/ Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLUE ),XHATCH_TRIPLE,120, 0),aStr));
+/*N*/
+/*N*/ return( TRUE );
+/*N*/ }
+
+/************************************************************************/
+
+/*N*/ BOOL XHatchList::CreateBitmapsForUI()
+/*N*/ {
+/*N*/ for( long i = 0; i < Count(); i++)
+/*N*/ {
+/*N*/ Bitmap* pBmp = CreateBitmapForUI( i, FALSE );
+/*N*/ DBG_ASSERT( pBmp, "XHatchList: Bitmap(UI) konnte nicht erzeugt werden!" );
+/*N*/
+/*N*/ if( pBmp )
+/*N*/ pBmpList->Insert( pBmp, i );
+/*N*/ }
+/*N*/ // Loeschen, da JOE den Pool vorm Dtor entfernt!
+/*N*/ if( pVD ) { delete pVD; pVD = NULL; }
+/*N*/ if( pXOut ) { delete pXOut; pXOut = NULL; }
+/*N*/ if( pXFSet ){ delete pXFSet; pXFSet = NULL; }
+/*N*/
+/*N*/ return( TRUE );
+/*N*/ }
+
+/************************************************************************/
+
+/*N*/ Bitmap* XHatchList::CreateBitmapForUI( long nIndex, BOOL bDelete )
+/*N*/ {
+/*N*/ Point aZero;
+/*N*/
+/*N*/ if( !pVD ) // und pXOut und pXFSet
+/*N*/ {
+/*N*/ pVD = new VirtualDevice;
+/*N*/ DBG_ASSERT( pVD, "XHatchList: Konnte kein VirtualDevice erzeugen!" );
+/*N*/ //pVD->SetMapMode( MAP_100TH_MM );
+/*N*/ //pVD->SetOutputSize( pVD->PixelToLogic( Size( BITMAP_WIDTH, BITMAP_HEIGHT ) ) );
+/*N*/ pVD->SetOutputSizePixel( Size( BITMAP_WIDTH, BITMAP_HEIGHT ) );
+/*N*/
+/*N*/ pXOut = new XOutputDevice( pVD );
+/*N*/ DBG_ASSERT( pVD, "XHatchList: Konnte kein XOutDevice erzeugen!" );
+/*N*/
+/*N*/ pXFSet = new XFillAttrSetItem( pXPool );
+/*N*/ DBG_ASSERT( pVD, "XHatchList: Konnte kein XFillAttrSetItem erzeugen!" );
+/*N*/ }
+/*N*/
+/*N*/ pVD->SetDrawMode( OUTPUT_DRAWMODE_COLOR );
+/*N*/
+/*N*/ // Damit die Schraffuren mit Rahmen angezeigt werden:
+/*N*/ // MapMode-Aenderungen (100th mm <--> Pixel)
+/*N*/ Size aPixelSize = pVD->GetOutputSizePixel();
+/*N*/ pVD->SetMapMode( MAP_PIXEL );
+/*N*/
+/*N*/ pXFSet->GetItemSet().Put( XFillStyleItem( XFILL_SOLID ) );
+/*N*/ pXFSet->GetItemSet().Put( XFillColorItem( String(), RGB_Color( COL_WHITE ) ) );
+/*N*/
+/*N*/ pXOut->SetFillAttr( pXFSet->GetItemSet() );
+/*N*/
+/*N*/ // #73550#
+/*N*/ pXOut->OverrideLineColor( Color( COL_BLACK ) );
+/*N*/
+/*N*/ pXOut->DrawRect( Rectangle( aZero, aPixelSize ) );
+/*N*/
+/*N*/ pVD->SetMapMode( MAP_100TH_MM );
+/*N*/ Size aVDSize = pVD->GetOutputSize();
+/*N*/ // 1 Pixel (Rahmen) abziehen
+/*N*/ aVDSize.Width() -= (long) ( aVDSize.Width() / aPixelSize.Width() + 1 );
+/*N*/ aVDSize.Height() -= (long) ( aVDSize.Height() / aPixelSize.Height() + 1 );
+/*N*/
+/*N*/ pXFSet->GetItemSet().Put( XFillStyleItem( XFILL_HATCH ) );
+/*N*/ pXFSet->GetItemSet().Put( XFillHatchItem( String(), Get( nIndex )->GetHatch() ) );
+
+/*N*/ pXOut->SetFillAttr( pXFSet->GetItemSet() );
+/*N*/
+/*N*/ pXOut->DrawRect( Rectangle( aZero, aVDSize ) );
+/*N*/
+/*N*/ Bitmap* pBitmap = new Bitmap( pVD->GetBitmap( aZero, pVD->GetOutputSize() ) );
+/*N*/
+/*N*/ // Loeschen, da JOE den Pool vorm Dtor entfernt!
+/*N*/ if( bDelete )
+/*N*/ {
+/*N*/ if( pVD ) { delete pVD; pVD = NULL; }
+/*N*/ if( pXOut ) { delete pXOut; pXOut = NULL; }
+/*N*/ if( pXFSet ){ delete pXFSet; pXFSet = NULL; }
+/*N*/ }
+/*N*/
+/*N*/ return( pBitmap );
+/*N*/ }
+
+/************************************************************************/
+
+/*N*/ XubString& XHatchList::ConvertName( XubString& rStrName )
+/*N*/ {
+/*N*/ BOOL bFound = FALSE;
+/*N*/
+/*N*/ for( USHORT i=0; i<(RID_SVXSTR_HATCH_DEF_END-RID_SVXSTR_HATCH_DEF_START+1) && !bFound; i++ )
+/*N*/ {
+/*N*/ XubString aStrDefName = SVX_RESSTR( RID_SVXSTR_HATCH_DEF_START + i );
+/*N*/ if( rStrName.Search( aStrDefName ) == 0 )
+/*N*/ {
+/*N*/ rStrName.Replace( 0, aStrDefName.Len(), SVX_RESSTR( RID_SVXSTR_HATCH_START + i ) );
+/*N*/ bFound = TRUE;
+/*N*/ }
+/*N*/ }
+/*N*/
+/*N*/ return rStrName;
+/*N*/ }
+
+/************************************************************************/
+
+/*N*/ SvStream& XHatchList::ImpRead( SvStream& rIn )
+/*N*/ {
+/*N*/ // Lesen
+/*N*/ rIn.SetStreamCharSet( RTL_TEXTENCODING_IBM_850 );
+/*N*/
+/*N*/ delete pBmpList;
+/*N*/ pBmpList = new List( 16, 16 );
+/*N*/
+/*N*/ XHatchEntry* pEntry = NULL;
+/*N*/ long nCount;
+/*N*/ XubString aLclName;
+/*N*/
+/*N*/ long nStyle;
+/*N*/ USHORT nRed;
+/*N*/ USHORT nGreen;
+/*N*/ USHORT nBlue;
+/*N*/ long nDistance;
+/*N*/ long nAngle;
+/*N*/ Color aColor;
+/*N*/
+/*N*/ rIn >> nCount;
+/*N*/
+/*N*/ if( nCount >= 0 ) // Alte Tabellen (bis 3.00)
+/*N*/ {
+/*N*/ for( long nIndex = 0; nIndex < nCount; nIndex++ )
+/*N*/ {
+/*N*/ // UNICODE:rIn >> aLclName;
+/*N*/ aLclName = rIn.ReadUniOrByteString(rIn.GetStreamCharSet());
+/*N*/
+/*N*/ aLclName = ConvertName( aLclName );
+/*N*/ rIn >> nStyle;
+/*N*/ rIn >> nRed;
+/*N*/ rIn >> nGreen;
+/*N*/ rIn >> nBlue;
+/*N*/ rIn >> nDistance;
+/*N*/ rIn >> nAngle;
+/*N*/
+/*N*/ aColor = Color( (BYTE) ( nRed >> 8 ),
+/*N*/ (BYTE) ( nGreen >> 8 ),
+/*N*/ (BYTE) ( nBlue >> 8 ) );
+/*N*/ XHatch aHatch(aColor, (XHatchStyle)nStyle, nDistance, nAngle);
+/*N*/ pEntry = new XHatchEntry (aHatch, aLclName);
+/*N*/ Insert (pEntry, nIndex);
+/*N*/ }
+/*N*/ }
+/*N*/ else // ab 3.00a
+/*N*/ {
+/*N*/ rIn >> nCount;
+/*N*/
+/*N*/ for( long nIndex = 0; nIndex < nCount; nIndex++ )
+/*N*/ {
+/*N*/ // Versionsverwaltung
+/*N*/ XIOCompat aIOC( rIn, STREAM_READ );
+/*N*/
+/*N*/ // UNICODE: rIn >> aLclName;
+/*N*/ aLclName = rIn.ReadUniOrByteString(rIn.GetStreamCharSet());
+/*N*/
+/*N*/ aLclName = ConvertName( aLclName );
+/*N*/ rIn >> nStyle;
+/*N*/ rIn >> nRed;
+/*N*/ rIn >> nGreen;
+/*N*/ rIn >> nBlue;
+/*N*/ rIn >> nDistance;
+/*N*/ rIn >> nAngle;
+/*N*/
+/*N*/ if (aIOC.GetVersion() > 0)
+/*N*/ {
+/*N*/ // lesen neuer Daten ...
+/*N*/ }
+/*N*/
+/*N*/ aColor = Color( (BYTE) ( nRed >> 8 ),
+/*N*/ (BYTE) ( nGreen >> 8 ),
+/*N*/ (BYTE) ( nBlue >> 8 ) );
+/*N*/ XHatch aHatch(aColor, (XHatchStyle)nStyle, nDistance, nAngle);
+/*N*/ pEntry = new XHatchEntry (aHatch, aLclName);
+/*N*/ Insert (pEntry, nIndex);
+/*N*/ }
+/*N*/ }
+/*N*/ return( rIn );
+/*N*/ }
+
+
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */