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 <tools/debug.hxx>
28
29 #include <vcl/dockingarea.hxx>
30 #include <vcl/syswin.hxx>
31 #include <vcl/menu.hxx>
32
33 #include <svdata.hxx>
34
35 #include <map>
36
37 // =======================================================================
38
39 class DockingAreaWindow::ImplData
40 {
41 public:
42 ImplData();
43 ~ImplData();
44
45 WindowAlign meAlign;
46 };
47
ImplData()48 DockingAreaWindow::ImplData::ImplData()
49 {
50 meAlign = WINDOWALIGN_TOP;
51 }
52
~ImplData()53 DockingAreaWindow::ImplData::~ImplData()
54 {
55 }
56
57 // =======================================================================
58
ImplInitBackground(DockingAreaWindow * pThis)59 static void ImplInitBackground( DockingAreaWindow* pThis )
60 {
61 if( !pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
62 {
63 Wallpaper aWallpaper;
64 aWallpaper.SetStyle( WALLPAPER_APPLICATIONGRADIENT );
65 pThis->SetBackground( aWallpaper );
66 }
67 else
68 pThis->SetBackground( Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceColor() ) );
69 }
70
DockingAreaWindow(Window * pParent)71 DockingAreaWindow::DockingAreaWindow( Window* pParent ) :
72 Window( WINDOW_DOCKINGAREA )
73 {
74 ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, NULL );
75
76 mpImplData = new ImplData;
77 ImplInitBackground( this );
78 }
79
~DockingAreaWindow()80 DockingAreaWindow::~DockingAreaWindow()
81 {
82 delete mpImplData;
83 }
84
85 // -----------------------------------------------------------------------
86
DataChanged(const DataChangedEvent & rDCEvt)87 void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt )
88 {
89 Window::DataChanged( rDCEvt );
90
91 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
92 {
93 ImplInitBackground( this );
94 }
95 }
96
97 // -----------------------------------------------------------------------
98
ImplInvalidateMenubar(DockingAreaWindow * pThis)99 static void ImplInvalidateMenubar( DockingAreaWindow* pThis )
100 {
101 // due to a possible common gradient covering menubar and top dockingarea
102 // the menubar must be repainted if the top dockingarea changes size or visibility
103 if( ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG &&
104 (pThis->GetAlign() == WINDOWALIGN_TOP)
105 && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL )
106 && pThis->IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL ) )
107 {
108 SystemWindow *pSysWin = pThis->GetSystemWindow();
109 if( pSysWin && pSysWin->GetMenuBar() )
110 {
111 Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
112 if( pMenubarWin )
113 pMenubarWin->Invalidate();
114 }
115 }
116 }
117
StateChanged(StateChangedType nType)118 void DockingAreaWindow::StateChanged( StateChangedType nType )
119 {
120 Window::StateChanged( nType );
121
122 if ( nType == STATE_CHANGE_VISIBLE )
123 ImplInvalidateMenubar( this );
124 }
125
126 // -----------------------------------------------------------------------
127
IsHorizontal() const128 sal_Bool DockingAreaWindow::IsHorizontal() const
129 {
130 return ( mpImplData->meAlign == WINDOWALIGN_TOP || mpImplData->meAlign == WINDOWALIGN_BOTTOM );
131 }
132
SetAlign(WindowAlign eNewAlign)133 void DockingAreaWindow::SetAlign( WindowAlign eNewAlign )
134 {
135 if( eNewAlign != mpImplData->meAlign )
136 {
137 mpImplData->meAlign = eNewAlign;
138 Invalidate();
139 }
140 }
141
GetAlign() const142 WindowAlign DockingAreaWindow::GetAlign() const
143 {
144 return mpImplData->meAlign;
145 }
146
147 // -----------------------------------------------------------------------
148
Paint(const Rectangle &)149 void DockingAreaWindow::Paint( const Rectangle& )
150 {
151 EnableNativeWidget( sal_True ); // only required because the toolkit curently switches this flag off
152 if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
153 {
154 ToolbarValue aControlValue;
155
156 if( GetAlign() == WINDOWALIGN_TOP && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG )
157 {
158 // give NWF a hint that this dockingarea is adjacent to the menubar
159 // useful for special gradient effects that should cover both windows
160 aControlValue.mbIsTopDockingArea = sal_True;
161 }
162 ControlState nState = CTRL_STATE_ENABLED;
163
164 if( !ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB )
165 {
166 // draw a single toolbar background covering the whole docking area
167 Point tmp;
168 Rectangle aCtrlRegion( tmp, GetOutputSizePixel() );
169
170 DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
171 aCtrlRegion, nState, aControlValue, rtl::OUString() );
172
173 // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
174 sal_uInt16 nChildren = GetChildCount();
175 for( sal_uInt16 n = 0; n < nChildren; n++ )
176 {
177 Window* pChild = GetChild( n );
178 if ( pChild->IsVisible() )
179 {
180 Point aPos = pChild->GetPosPixel();
181 Size aSize = pChild->GetSizePixel();
182 Rectangle aRect( aPos, aSize );
183
184 SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
185 DrawLine( aRect.TopLeft(), aRect.TopRight() );
186 DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
187
188 SetLineColor( GetSettings().GetStyleSettings().GetSeparatorColor() );
189 DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
190 DrawLine( aRect.TopRight(), aRect.BottomRight() );
191 }
192 }
193 }
194 else
195 {
196 // create map to find toolbar lines
197 Size aOutSz = GetOutputSizePixel();
198 std::map< int, int > ranges;
199 sal_uInt16 nChildren = GetChildCount();
200 for( sal_uInt16 n = 0; n < nChildren; n++ )
201 {
202 Window* pChild = GetChild( n );
203 Point aPos = pChild->GetPosPixel();
204 Size aSize = pChild->GetSizePixel();
205 if( IsHorizontal() )
206 ranges[ aPos.Y() ] = aSize.Height();
207 else
208 ranges[ aPos.X() ] = aSize.Width();
209 }
210
211
212 // draw multiple toolbar backgrounds, i.e., one for each toolbar line
213 for( std::map<int,int>::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
214 {
215 Rectangle aTBRect;
216 if( IsHorizontal() )
217 {
218 aTBRect.Left() = 0;
219 aTBRect.Right() = aOutSz.Width() - 1;
220 aTBRect.Top() = it->first;
221 aTBRect.Bottom() = it->first + it->second - 1;
222 }
223 else
224 {
225 aTBRect.Left() = it->first;
226 aTBRect.Right() = it->first + it->second - 1;
227 aTBRect.Top() = 0;
228 aTBRect.Bottom() = aOutSz.Height() - 1;
229 }
230 DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
231 aTBRect, nState, aControlValue, rtl::OUString() );
232 }
233 }
234 }
235 }
236
Resize()237 void DockingAreaWindow::Resize()
238 {
239 ImplInvalidateMenubar( this );
240 if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
241 Invalidate();
242 }
243
244 // -----------------------------------------------------------------------
245
246