summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2005-03-03 18:58:00 +0000
committerKurt Zenker <kz@openoffice.org>2005-03-03 18:58:00 +0000
commitc7f6ac63231c6eb281f1d5679c384c43954edddd (patch)
tree2273996bcb112828b816a287b3df6864e4180049
parent303c190b7ed51bb3a4fa7e5bee88ea990abfee26 (diff)
INTEGRATION: CWS wmicons (1.15.276); FILE MERGED
2005/02/24 14:14:01 obr 1.15.276.1: #i37167# window manager icons now loaded from resource
-rw-r--r--vcl/unx/source/app/soicon.cxx500
1 files changed, 43 insertions, 457 deletions
diff --git a/vcl/unx/source/app/soicon.cxx b/vcl/unx/source/app/soicon.cxx
index 54a3f467f35c..79cba609315b 100644
--- a/vcl/unx/source/app/soicon.cxx
+++ b/vcl/unx/source/app/soicon.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: soicon.cxx,v $
*
- * $Revision: 1.15 $
+ * $Revision: 1.16 $
*
- * last change: $Author: rt $ $Date: 2004-03-30 13:43:24 $
+ * last change: $Author: kz $ $Date: 2005-03-03 19:58:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -59,11 +59,6 @@
*
************************************************************************/
-#include <dlfcn.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-
#include <salunx.h>
#ifndef _SV_SALDISP_HXX
@@ -87,484 +82,75 @@
#ifndef _SV_GRAPH_HXX
#include <graph.hxx>
#endif
-#ifndef _SV_CVTGRF_HXX
-#include <cvtgrf.hxx>
-#endif
-#ifndef _PSPRINT_STRHELPER_HXX
-#include <psprint/strhelper.hxx>
-#endif
#ifndef _SV_SOICON_HXX
#include <soicon.hxx>
#endif
-#ifndef _SV_SALINST_HXX
-#include <salinst.hxx>
-#endif
#ifndef _SV_SVDATA_HXX
#include <svdata.hxx>
#endif
+#ifndef _SV_SALBMP_H
+#include <salbmp.h>
+#endif
+#include <svids.hrc>
-#include <tools/stream.hxx>
-#include <tools/string.hxx>
-
-using namespace psp;
-
-typedef struct {
- int id; // 'resource' id
- char **xpmdata[4]; // 4 resolutions
- Pixmap mPixmap[4], mMask[4]; // caches
- } SOICON;
-
-static void ConvertXpm( SalDisplay* pDisplay, char *xpm[], Pixmap& aPixmap, Pixmap& aMask, int nSize )
-{
- int nWidth, nHeight, nColors, nCharsPerPixel;
- XColor *pColors;
- char *pColorAlias;
- int nElement = 0,nColor = 0,nX,nY;
- char pColorString[256];
- BOOL bTransparent = FALSE;
-
- sscanf( xpm[ nElement++ ], "%d%d%d%d", &nWidth, &nHeight,
- &nColors, &nCharsPerPixel );
- nColor = 0;
- pColors = new XColor[ nColors ];
- pColorAlias = new char[ nColors * nCharsPerPixel ];
- while( nElement <= nColors )
- {
- char* pLine = xpm[nElement++];
- char* pStart = pLine + nCharsPerPixel;
- while( *pStart && ( pStart[0] != 'c' || ! isspace( pStart[1] ) ) )
- pStart++;
- if( *pStart )
- {
- sscanf( pStart,"c %s", pColorString);
- if( strncasecmp( pColorString, "None", 4 ) )
- {
- XAllocNamedColor( pDisplay->GetDisplay(),
- DefaultColormap( pDisplay->GetDisplay(),
- pDisplay->GetScreenNumber() ),
- pColorString, &pColors[nColor], &pColors[nColor] );
- strncpy( &pColorAlias[nColor*nCharsPerPixel],
- pLine, nCharsPerPixel );
- nColor++;
- }
- }
- }
- nColors = nColor;
-
- aPixmap = XCreatePixmap( pDisplay->GetDisplay(),
- pDisplay->GetRootWindow(),
- nSize, nSize,
- pDisplay->GetRootVisual()->GetDepth() );
- XSetForeground( pDisplay->GetDisplay(),
- DefaultGC( pDisplay->GetDisplay(),
- pDisplay->GetScreenNumber() ),
- BlackPixel( pDisplay->GetDisplay(),
- pDisplay->GetScreenNumber() ) );
- XFillRectangle( pDisplay->GetDisplay(), aPixmap,
- DefaultGC( pDisplay->GetDisplay(),
- pDisplay->GetScreenNumber() ),
- 0,0,nSize,nSize );
-
- aMask = XCreatePixmap( pDisplay->GetDisplay(),
- pDisplay->GetRootWindow(),
- nSize, nSize, 1 );
-
- XGCValues aValues;
- aValues.foreground = 0xffffffff;
- aValues.function = GXclear;
- GC aMonoGC = XCreateGC( pDisplay->GetDisplay(), aMask,
- GCFunction|GCForeground, &aValues );
-
- XFillRectangle( pDisplay->GetDisplay(), aMask, aMonoGC,
- 0,0, nSize, nSize );
- aValues.function = GXset;
- XChangeGC( pDisplay->GetDisplay(), aMonoGC, GCFunction, &aValues );
-
- int nOffX = (nSize-nWidth)/2;
- int nOffY = (nSize-nHeight)/2;
-
- for( nY=0; nY < nHeight; nY++ )
- {
- char *pRun = xpm[ nElement+nY ];
- for( nX=0; nX < nWidth; nX++ )
- {
- // get color number
- nColor = 0;
- while( nColor < nColors &&
- strncmp( pRun, &pColorAlias[nColor*nCharsPerPixel],
- nCharsPerPixel ) )
- nColor++;
- if( nColor < nColors )
- {
- XSetForeground( pDisplay->GetDisplay(),
- DefaultGC( pDisplay->GetDisplay(),
- pDisplay->GetScreenNumber() ),
- pColors[ nColor ].pixel );
- XDrawPoint( pDisplay->GetDisplay(),
- aPixmap,
- DefaultGC( pDisplay->GetDisplay(),
- pDisplay->GetScreenNumber() ),
- nX+nOffX, nY+nOffY );
-
- XDrawPoint( pDisplay->GetDisplay(),
- aMask, aMonoGC, nX+nOffX, nY+nOffY );
- }
- else
- {
- bTransparent = TRUE;
- }
- pRun += nCharsPerPixel;
- }
- }
- delete [] pColors;
- delete [] pColorAlias;
- XFreeGC( pDisplay->GetDisplay(), aMonoGC );
-
- if( ! bTransparent )
- {
- XFreePixmap( pDisplay->GetDisplay(), aMask );
- aMask = 0;
- }
-}
BOOL SelectAppIconPixmap( SalDisplay *pDisplay, USHORT nIcon, USHORT iconSize,
Pixmap& icon_pixmap, Pixmap& icon_mask)
{
- VCL_CUSTOM_ICON_FN *pCustomIcon = 0;
-
- if( nIcon == 0 ) // 0 means default icon which is icon #1 actually
- nIcon = 1;
-
- SOICON *pIcon = NULL;
-
- // call custom function to read icon
- char customIconFn[256];
-
- snprintf( customIconFn, sizeof(customIconFn), "%s%d", VCL_CUSTOM_ICON_BASE, nIcon );
- static void* pAppHdl = dlopen( NULL, RTLD_LAZY );
- if ( ( pCustomIcon = ( VCL_CUSTOM_ICON_FN* ) dlsym( pAppHdl, customIconFn ) )
- != NULL )
- {
- pIcon = new SOICON[2]; // 2nd entry is terminator
- memset( pIcon, 0, 2*sizeof( SOICON ) );
- pIcon->id = nIcon;
- pCustomIcon( pIcon->xpmdata[0], pIcon->xpmdata[1], pIcon->xpmdata[2], pIcon->xpmdata[3] );
- }
- else
- {
- DBG_ERROR( "SelectAppIconPixmap: Icon not found!");
- return FALSE;
- }
-
- // search optimal size
- int i, maxSize = 0, iIcon=-1;
- for(i=0; i<4; i++)
- {
- int nWidth, nHeight, nColors, nCharsPerPixel;
- if( !pIcon->xpmdata[i] )
- continue;
- sscanf( pIcon->xpmdata[i][0], "%d%d%d%d", &nWidth, &nHeight,
- &nColors, &nCharsPerPixel );
- if( iconSize == nWidth )
- {
- iIcon = i;
- break;
- }
- if ( nWidth < iconSize && nWidth > maxSize )
- {
- // use largest icon if sizes don't match
- maxSize = nWidth;
- iIcon = i;
- }
- }
-
- DBG_ASSERT( iIcon != -1, "SelectAppIconPixmap: Invalid icon definition found!");
- if( iIcon == -1 )
- {
- if( pCustomIcon )
- delete [] pIcon;
- return FALSE;
- }
-
- if( !pIcon->mPixmap[iIcon] )
- ConvertXpm( pDisplay, pIcon->xpmdata[iIcon], pIcon->mPixmap[iIcon], pIcon->mMask[iIcon], iconSize );
-
- icon_pixmap = pIcon->mPixmap[iIcon];
- icon_mask = pIcon->mMask[iIcon];
-
- if( pCustomIcon )
- delete [] pIcon;
-
- return TRUE;
-}
-
-static void NextLine( SvStream& rFile, ByteString& rLine, BOOL bXpm2Mode )
-{
- if( bXpm2Mode )
- {
- rFile.ReadLine( rLine );
- }
+ USHORT nIconSizeOffset;
+
+ if( iconSize >= 48 )
+ nIconSizeOffset = SV_ICON_SIZE48_START;
+ else if( iconSize >= 32 )
+ nIconSizeOffset = SV_ICON_SIZE32_START;
+ else if( iconSize >= 16 )
+ nIconSizeOffset = SV_ICON_SIZE16_START;
else
- {
- do
- {
- rFile.ReadLine( rLine );
- rLine = rLine.GetToken( 1, '"' );
- if( rLine.Len() )
- rLine = rLine.GetToken( 0, '"' );
- } while( ! ( rLine.Len() || rFile.IsEof() ) );
- }
-}
-
-BOOL ReadXBMFile( Display* pDisplay, const String& rFile, SalBitmap*& rpBmp )
-{
- SvFileStream aFile( rFile, STREAM_READ );
- int nWidth= -1, nHeight=-1;
-
- rpBmp = NULL;
-
- // read in bitmap file ( cause XReadBitmapFileData not present
- // in Solaris 2.5.1)
- if( ! aFile.IsOpen() )
return FALSE;
- ByteString aLine;
-
- while( ( nWidth < 0 || nHeight < 0 ) && ! aFile.IsEof() )
- {
- aFile.ReadLine( aLine );
- aLine = WhitespaceToSpace( aLine );
-
- if( aLine.GetChar(0) == '#' )
- {
- if( aLine.Search( "_width" ) != STRING_NOTFOUND )
- nWidth = aLine.GetToken( ' ', 2 ).ToInt32();
- else if( aLine.Search( "_height" ) != STRING_NOTFOUND )
- nHeight = aLine.GetToken( ' ', 2 ).ToInt32();
- }
- }
-
- if( nWidth <= 0 || nHeight <= 0 )
+ BitmapEx aIcon( ResId(nIconSizeOffset + nIcon, ImplGetResMgr()));
+ if( TRUE == aIcon.IsEmpty() )
return FALSE;
- BitmapPalette aPal( 2 );
- const Size aSize( nWidth, nHeight );
+ SalTwoRect aRect;
+ aRect.mnSrcX = 0; aRect.mnSrcY = 0;
+ aRect.mnSrcWidth = iconSize; aRect.mnSrcHeight = iconSize;
+ aRect.mnDestX = 0; aRect.mnDestY = 0;
+ aRect.mnDestWidth = iconSize; aRect.mnDestHeight = iconSize;
- aPal[ 0 ] = BitmapColor( 0, 0, 0 );
- aPal[ 1 ] = BitmapColor( 0xff, 0xff, 0xff );
+ X11SalBitmap *pBitmap = static_cast < X11SalBitmap * >
+ (aIcon.ImplGetBitmapImpBitmap()->ImplGetSalBitmap());
- rpBmp = ImplGetSVData()->mpDefInst->CreateSalBitmap();
- rpBmp->Create( aSize, 1, aPal );
+ icon_pixmap = XCreatePixmap( pDisplay->GetDisplay(), pDisplay->GetRootWindow(),
+ iconSize, iconSize, pDisplay->GetRootVisual()->GetDepth());
- BitmapBuffer* pBmpBuf = rpBmp->AcquireBuffer( FALSE );
- BYTE* pBmpScan = pBmpBuf->mpBits + ( nHeight - 1 ) * pBmpBuf->mnScanlineSize;
- long nX = 0, nY = 0;
+ pBitmap->ImplDraw(icon_pixmap, pDisplay->GetRootVisual()->GetDepth(),
+ aRect, DefaultGC(pDisplay->GetDisplay(), pDisplay->GetScreenNumber()), false);
- aFile.Seek( 0L );
+ icon_mask = None;
- do
+ if( TRANSPARENT_BITMAP == aIcon.GetTransparentType() )
{
- int nPos;
-
- aFile.ReadLine( aLine );
- aLine.ToUpperAscii();
-
- while( ( ( nPos = aLine.Search( "0X" ) ) != STRING_NOTFOUND ) && ( nY < nHeight ) )
- {
- BYTE cData = 0;
-
- for( int i = 0; i < 2; i++ )
- {
- cData *= 16;
- char c = aLine.GetChar( nPos + 2 + i);
+ icon_mask = XCreatePixmap( pDisplay->GetDisplay(),
+ pDisplay->GetRootWindow(), iconSize, iconSize, 1);
- if( c >= '0' && c <= '9' )
- cData += (unsigned char)( c - '0' );
- else if( c >= 'A' && c <= 'F' )
- cData += (unsigned char)( c - 'A' + 10 );
- }
+ XGCValues aValues;
+ aValues.foreground = 0xffffffff;
+ aValues.background = 0;
+ aValues.function = GXcopy;
+ GC aMonoGC = XCreateGC( pDisplay->GetDisplay(), icon_mask,
+ GCFunction|GCForeground|GCBackground, &aValues );
- *pBmpScan++ += ( ( cData & 1 ) << 7 ) | ( ( cData & 2 ) << 5 ) |
- ( ( cData & 4 ) << 3 ) | ( ( cData & 8 ) << 1 ) |
- ( ( cData & 16 ) >> 1 ) | ( ( cData & 32 ) >> 3 ) |
- ( ( cData & 64 ) >> 5 ) | ( ( cData& 128 ) >> 7 );
+ Bitmap aMask = aIcon.GetMask();
+ aMask.Invert();
- if( ( nX += 8 ) >= nWidth )
- nX = 0, pBmpScan = pBmpBuf->mpBits + ( nHeight - ++nY - 1 ) * pBmpBuf->mnScanlineSize;
+ X11SalBitmap *pMask = static_cast < X11SalBitmap * >
+ (aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
- aLine.Erase( 0, nPos + 5 );
- }
+ pMask->ImplDraw(icon_mask, 1, aRect, aMonoGC, false);
+ XFreeGC( pDisplay->GetDisplay(), aMonoGC );
}
- while( !aFile.IsEof() && ( nY < nHeight ) );
-
- rpBmp->ReleaseBuffer( pBmpBuf, FALSE );
return TRUE;
}
-//------------------------------------------------------------------------------
-
-BOOL ReadXPMFile( Display* pDisplay, const String& rFile,
- SalBitmap*& rpBmp, SalBitmap*& rpMsk )
-{
- SvFileStream aFile( rFile, STREAM_READ );
- ByteString aColorName, aColorString, aLine;
- int nWidth, nHeight, nColors, nCharsPerPixel;
- int nColor = 0, nX, nY;
- UINT8* pColorTable;
- char* pColorAlias;
- BOOL bXpm2Mode = FALSE;
-
- rpBmp = rpMsk = NULL;
-
- if( ! aFile.IsOpen() )
- return FALSE;
-
- aFile.ReadLine( aLine );
- aLine = WhitespaceToSpace( aLine );
-
- if( aLine.CompareTo( "! XPM", 5 ) == COMPARE_EQUAL )
- bXpm2Mode = TRUE;
- else
- {
- bXpm2Mode = FALSE;
- aFile.Seek( 0L );
- }
-
- NextLine( aFile, aLine, bXpm2Mode );
-
- nWidth = GetCommandLineToken( 0, aLine ).ToInt32();
- nHeight = GetCommandLineToken( 1, aLine ).ToInt32();
- nColors = GetCommandLineToken( 2, aLine ).ToInt32();
- nCharsPerPixel = GetCommandLineToken( 3, aLine ).ToInt32();
-
- if( nWidth == 0 || nHeight == 0 || nColors == 0 || nCharsPerPixel == 0 )
- {
- // not really an xpm despite the name => try to load it via GraphicConverter
- aFile.Seek( 0L );
- Graphic aGraphic;
- GraphicConverter::Import( aFile, aGraphic );
-
- BitmapEx aBitmapEx( aGraphic.GetBitmapEx() );
-
- if( aBitmapEx.GetSizePixel().Width() == 0 || aBitmapEx.GetSizePixel().Height() == 0 )
- return FALSE;
-
- const Bitmap aBmp( aBitmapEx.GetBitmap() );
- const Bitmap aMsk( aBitmapEx.GetMask() );
-
- if( !!aBmp )
- {
- rpBmp = ImplGetSVData()->mpDefInst->CreateSalBitmap();
- rpBmp->Create( *aBmp.ImplGetImpBitmap()->ImplGetSalBitmap() );
- }
-
- if( !!aMsk )
- {
- rpMsk = ImplGetSVData()->mpDefInst->CreateSalBitmap();
- rpMsk->Create( *aMsk.ImplGetImpBitmap()->ImplGetSalBitmap() );
- }
-
- return TRUE;
- }
-
- nColor = 0;
- pColorTable = new UINT8[ (nColors+1) * 3 ];
- pColorAlias = new char[ nColors * nCharsPerPixel ];
- XColor aExactColor;
- aExactColor.flags = DoRed | DoGreen | DoBlue;
- while( nColors )
- {
- NextLine( aFile, aLine, bXpm2Mode );
- // might be a space as color variable
- aColorName = aLine.Copy( 0, nCharsPerPixel );
- aLine.Erase( 0, nCharsPerPixel );
- aLine = WhitespaceToSpace( aLine );
-
- int nPos = aLine.Search( " c " );
- if( nPos == STRING_NOTFOUND && aLine.CompareIgnoreCaseToAscii( "c ", 2 ) == COMPARE_EQUAL )
- nPos = 2;
- else
- nPos += 3;
- aColorString = aLine.Copy( nPos );
-
- if( aColorString.CompareIgnoreCaseToAscii( "none", 4 ) != COMPARE_EQUAL )
- {
- XParseColor( pDisplay,
- DefaultColormap( pDisplay,
- DefaultScreen( pDisplay ) ),
- aColorString.GetBuffer(),
- &aExactColor );
- pColorTable[ nColor * 3 +2 ] = (UINT8)(aExactColor.red / 256 );
- pColorTable[ nColor * 3 +1 ] = (UINT8)(aExactColor.green / 256 );
- pColorTable[ nColor * 3 ] = (UINT8)(aExactColor.blue / 256 );
- strncpy( pColorAlias + nColor*nCharsPerPixel,
- aColorName.GetBuffer(), nCharsPerPixel );
- nColor++;
- }
- nColors--;
- }
- pColorTable[ 3*nColor ] = pColorTable[ 3*nColor+1 ] =
- pColorTable[ 3*nColor+2 ] = 0;
- nColors = nColor;
-
- // read SalBitmap's
- BitmapPalette aPal( 2 );
- const Size aSize( nWidth, nHeight );
-
- aPal[ 0 ] = BitmapColor( 0, 0, 0 );
- aPal[ 1 ] = BitmapColor( 0xff, 0xff, 0xff );
-
- rpBmp = ImplGetSVData()->mpDefInst->CreateSalBitmap();
- rpBmp->Create( aSize, 24, aPal );
- BitmapBuffer* pBmpBuf = rpBmp->AcquireBuffer( FALSE );
-
- rpMsk = ImplGetSVData()->mpDefInst->CreateSalBitmap();
- rpMsk->Create( aSize, 1, aPal );
- BitmapBuffer* pMskBuf = rpMsk->AcquireBuffer( FALSE );
-
- for( nY=0; nY < nHeight; nY++ )
- {
- NextLine( aFile, aLine, bXpm2Mode );
-
- const char* pRun = aLine.GetBuffer();
- BYTE* pBmpScan = pBmpBuf->mpBits + pBmpBuf->mnScanlineSize * ( nHeight - nY - 1 );
- BYTE* pMskScan = pMskBuf->mpBits + pMskBuf->mnScanlineSize * ( nHeight - nY - 1 );
- UINT8 nMaskByte = 0;
-
- for( nX = 0; nX < nWidth; nX++ )
- {
- // get color number
- for( nColor=0; nColor < nColors; nColor++ )
- {
- if( ! strncmp( pRun, pColorAlias + nColor*nCharsPerPixel,
- nCharsPerPixel ) )
- break;
- }
-
- long nIndex = nColor * 3;
-
- *pBmpScan++ = pColorTable[ nIndex++ ];
- *pBmpScan++ = pColorTable[ nIndex++ ];
- *pBmpScan++ = pColorTable[ nIndex ];
-
- if( nColor == nColors )
- nMaskByte |= ( 1 << ( 7 - ( nX & 7 ) ) );
-
- pRun += nCharsPerPixel;
-
- if( ( ( nX & 7 ) == 7 ) || ( nX == nWidth - 1 ) )
- {
- *pMskScan++ = nMaskByte;
- nMaskByte = 0;
- }
- }
- }
-
- rpBmp->ReleaseBuffer( pBmpBuf, FALSE );
- rpMsk->ReleaseBuffer( pMskBuf, FALSE );
- delete[] pColorTable;
- delete[] pColorAlias;
-
- return TRUE;
-}