xref: /aoo4110/main/vcl/unx/generic/app/soicon.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <unx/salunx.h>
28 #include <unx/saldisp.hxx>
29 #include <unx/salbmp.h>
30 #include <unx/soicon.hxx>
31 
32 #include <vcl/salbtype.hxx>
33 #include <vcl/bitmap.hxx>
34 #include <vcl/bitmapex.hxx>
35 #include <vcl/graph.hxx>
36 
37 #include <svdata.hxx>
38 #include <svids.hrc>
39 #include <salbmp.hxx>
40 #include <impbmp.hxx>
41 
42 
SelectAppIconPixmap(SalDisplay * pDisplay,int nScreen,sal_uInt16 nIcon,sal_uInt16 iconSize,Pixmap & icon_pixmap,Pixmap & icon_mask)43 sal_Bool SelectAppIconPixmap( SalDisplay *pDisplay, int nScreen,sal_uInt16 nIcon, sal_uInt16 iconSize,
44 						  Pixmap& icon_pixmap, Pixmap& icon_mask)
45 {
46     if( ! ImplGetResMgr() )
47         return sal_False;
48 
49     sal_uInt16 nIconSizeOffset;
50 
51     if( iconSize >= 48 )
52         nIconSizeOffset = SV_ICON_SIZE48_START;
53     else if( iconSize >= 32 )
54         nIconSizeOffset = SV_ICON_SIZE32_START;
55     else if( iconSize >= 16 )
56         nIconSizeOffset = SV_ICON_SIZE16_START;
57     else
58         return sal_False;
59 
60     BitmapEx aIcon( ResId(nIconSizeOffset + nIcon, *ImplGetResMgr()));
61     if( sal_True == aIcon.IsEmpty() )
62         return sal_False;
63 
64     SalTwoRect aRect;
65     aRect.mnSrcX = 0; aRect.mnSrcY = 0;
66     aRect.mnSrcWidth = iconSize; aRect.mnSrcHeight = iconSize;
67     aRect.mnDestX = 0; aRect.mnDestY = 0;
68     aRect.mnDestWidth = iconSize; aRect.mnDestHeight = iconSize;
69 
70     X11SalBitmap *pBitmap = static_cast < X11SalBitmap * >
71         (aIcon.ImplGetBitmapImpBitmap()->ImplGetSalBitmap());
72 
73     icon_pixmap = XCreatePixmap( pDisplay->GetDisplay(),
74                                  pDisplay->GetRootWindow( nScreen ),
75                                  iconSize, iconSize,
76                                  DefaultDepth( pDisplay->GetDisplay(), nScreen )
77                                  );
78 
79     pBitmap->ImplDraw( icon_pixmap,
80                        nScreen,
81                        DefaultDepth( pDisplay->GetDisplay(), nScreen ),
82                        aRect,
83                        DefaultGC(pDisplay->GetDisplay(), nScreen ) );
84 
85     icon_mask = None;
86 
87     if( TRANSPARENT_BITMAP == aIcon.GetTransparentType() )
88     {
89         icon_mask = XCreatePixmap( pDisplay->GetDisplay(),
90                                    pDisplay->GetRootWindow( pDisplay->GetDefaultScreenNumber() ),
91                                    iconSize, iconSize, 1);
92 
93         XGCValues aValues;
94         aValues.foreground = 0xffffffff;
95         aValues.background = 0;
96         aValues.function = GXcopy;
97         GC aMonoGC = XCreateGC( pDisplay->GetDisplay(), icon_mask,
98 			GCFunction|GCForeground|GCBackground, &aValues );
99 
100         Bitmap aMask = aIcon.GetMask();
101         aMask.Invert();
102 
103         X11SalBitmap *pMask = static_cast < X11SalBitmap * >
104             (aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
105 
106         pMask->ImplDraw(icon_mask, nScreen, 1, aRect, aMonoGC);
107         XFreeGC( pDisplay->GetDisplay(), aMonoGC );
108     }
109 
110     return sal_True;
111 }
112 
113