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 #include "precompiled_sc.hxx"
25 
26 #include <CellBorderUpdater.hxx>
27 #include <vcl/bmpacc.hxx>
28 #include <vcl/svapp.hxx>
29 
30 namespace sc { namespace sidebar {
31 
CellBorderUpdater(sal_uInt16 nTbxBtnId,ToolBox & rTbx)32 CellBorderUpdater::CellBorderUpdater(
33 	sal_uInt16 nTbxBtnId,
34 	ToolBox& rTbx)
35 :	mnBtnId(nTbxBtnId),
36 	mrTbx(rTbx)
37 {
38 }
39 
~CellBorderUpdater()40 CellBorderUpdater::~CellBorderUpdater()
41 {
42 }
43 
UpdateCellBorder(bool bTop,bool bBot,bool bLeft,bool bRight,Image aImg,bool bVer,bool bHor)44 void CellBorderUpdater::UpdateCellBorder(bool bTop, bool bBot, bool bLeft, bool bRight, Image aImg, bool bVer, bool bHor)
45 {
46 	BitmapEx			aBmpEx( aImg.GetBitmapEx() );
47 	Bitmap				aBmp( aBmpEx.GetBitmap() );
48 	BitmapWriteAccess*	pBmpAcc = aBmp.AcquireWriteAccess();
49 	const Size maBmpSize = aBmp.GetSizePixel();
50 
51 	if( pBmpAcc )
52 	{
53 		Bitmap				aMsk;
54 		BitmapWriteAccess*	pMskAcc;
55 
56 		if( aBmpEx.IsAlpha() )
57 			pMskAcc = ( aMsk = aBmpEx.GetAlpha().GetBitmap() ).AcquireWriteAccess();
58 		else if( aBmpEx.IsTransparent() )
59 			pMskAcc = ( aMsk = aBmpEx.GetMask() ).AcquireWriteAccess();
60 		else
61 			pMskAcc = NULL;
62 
63 		pBmpAcc->SetLineColor( ::Application::GetSettings().GetStyleSettings().GetFieldTextColor() ) ;
64 		pBmpAcc->SetFillColor( COL_BLACK);
65 
66 		if(maBmpSize.Width() == 43 && maBmpSize.Height() == 43)
67 		{
68 			Point aTL(2, 1), aTR(42,1), aBL(2, 41), aBR(42, 41), aHL(2,21), aHR(42, 21), aVT(22,1), aVB(22, 41);
69 			if( pMskAcc )
70 			{
71 				pMskAcc->SetLineColor( COL_BLACK );
72 				pMskAcc->SetFillColor( COL_BLACK );
73 			}
74 			if(bLeft)
75 			{
76 				pBmpAcc->DrawLine( aTL,aBL );
77 				if( pMskAcc )
78 					pMskAcc->DrawLine( aTL,aBL );
79 			}
80 			if(bRight)
81 			{
82 				pBmpAcc->DrawLine( aTR,aBR );
83 				if( pMskAcc )
84 					pMskAcc->DrawLine( aTR,aBR );
85 			}
86 			if(bTop)
87 			{
88 				pBmpAcc->DrawLine( aTL,aTR );
89 				if( pMskAcc )
90 					pMskAcc->DrawLine( aTL,aTR );
91 			}
92 			if(bBot)
93 			{
94 				pBmpAcc->DrawLine( aBL,aBR );
95 				if( pMskAcc )
96 					pMskAcc->DrawLine( aBL,aBR );
97 			}
98 			if(bVer)
99 			{
100 				pBmpAcc->DrawLine( aVT,aVB );
101 				if( pMskAcc )
102 					pMskAcc->DrawLine( aVT,aVB );
103 			}
104 			if(bHor)
105 			{
106 				pBmpAcc->DrawLine( aHL,aHR );
107 				if( pMskAcc )
108 					pMskAcc->DrawLine( aHL,aHR );
109 			}
110 		}
111 
112 		aBmp.ReleaseAccess( pBmpAcc );
113 		if( pMskAcc )
114 				aMsk.ReleaseAccess( pMskAcc );
115 
116 		if( aBmpEx.IsAlpha() )
117 			aBmpEx = BitmapEx( aBmp, AlphaMask( aMsk ) );
118 		else if( aBmpEx.IsTransparent() )
119 			aBmpEx = BitmapEx( aBmp, aMsk );
120 		else
121 			aBmpEx = aBmp;
122 
123 		mrTbx.SetItemImage( mnBtnId, Image( aBmpEx ) );
124 	}
125 }
126 
127 } } // end of namespace svx::sidebar
128 
129 /* vim: set noet sw=4 ts=4: */
130