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_dbaccess.hxx"
26 #ifndef DBAUI_VERTSPLITVIEW_HXX
27 #include "VertSplitView.hxx"
28 #endif
29 
30 #ifndef _TOOLS_DEBUG_HXX
31 #include <tools/debug.hxx>
32 #endif
33 
34 #define SPLITTER_WIDTH	80
35 
36 using namespace ::dbaui;
37 
38 //==================================================================
39 // class OSplitterView
40 //==================================================================
41 DBG_NAME(OSplitterView)
42 OSplitterView::OSplitterView(Window* _pParent,sal_Bool _bVertical) : Window(_pParent,WB_DIALOGCONTROL) // ,WB_BORDER
43 	,m_pSplitter( NULL )
44 	,m_pLeft(NULL)
45 	,m_pRight(NULL)
46 	,m_bVertical(_bVertical)
47 {
48 	DBG_CTOR(OSplitterView,NULL);
49 	ImplInitSettings( sal_True, sal_True, sal_True );
50 }
51 // -----------------------------------------------------------------------------
52 OSplitterView::~OSplitterView()
53 {
54 	DBG_DTOR(OSplitterView,NULL);
55 	m_pRight = m_pLeft = NULL;
56 }
57 //------------------------------------------------------------------------------
58 IMPL_LINK( OSplitterView, SplitHdl, Splitter*, /*pSplit*/ )
59 {
60 	OSL_ENSURE(m_pSplitter, "Splitter is NULL!");
61 	if ( m_bVertical )
62 	{
63 		long nPosY = m_pSplitter->GetPosPixel().Y();
64 		m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nPosY ) );
65 	}
66 	else
67 		m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
68 
69 	Resize();
70 	return 0L;
71 }
72 // -----------------------------------------------------------------------------
73 void OSplitterView::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
74 {
75 	const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
76 
77 	if ( bFont )
78 	{
79 		Font aFont = rStyleSettings.GetAppFont();
80 		if ( IsControlFont() )
81 			aFont.Merge( GetControlFont() );
82 		SetPointFont( aFont );
83 //		Set/*Zoomed*/PointFont( aFont );
84 	}
85 
86 	if ( bFont || bForeground )
87 	{
88 		Color aTextColor = rStyleSettings.GetButtonTextColor();
89 		if ( IsControlForeground() )
90 			aTextColor = GetControlForeground();
91 		SetTextColor( aTextColor );
92 	}
93 
94 	if ( bBackground )
95 	{
96 		if( IsControlBackground() )
97 			SetBackground( GetControlBackground() );
98 		else
99 			SetBackground( rStyleSettings.GetFaceColor() );
100 	}
101 }
102 // -----------------------------------------------------------------------
103 void OSplitterView::DataChanged( const DataChangedEvent& rDCEvt )
104 {
105 	Window::DataChanged( rDCEvt );
106 
107 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
108 		 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
109 	{
110 		ImplInitSettings( sal_True, sal_True, sal_True );
111 		Invalidate();
112 	}
113 }
114 // -----------------------------------------------------------------------------
115 void OSplitterView::GetFocus()
116 {
117 	Window::GetFocus();
118 
119 	// forward the focus to the current cell of the editor control
120 	if ( m_pLeft )
121 		m_pLeft->GrabFocus();
122 	else if ( m_pRight )
123 		m_pRight->GrabFocus();
124 }
125 
126 // -------------------------------------------------------------------------
127 void OSplitterView::Resize()
128 {
129 	Window::Resize();
130 	OSL_ENSURE( m_pRight, "No init called!");
131 
132 	Point	aSplitPos;
133 	Size	aSplitSize;
134 	Point	aPlaygroundPos( 0,0 );
135 	Size	aPlaygroundSize( GetOutputSizePixel() );
136 
137 	if ( m_pLeft && m_pLeft->IsVisible() && m_pSplitter )
138 	{
139 		aSplitPos	= m_pSplitter->GetPosPixel();
140 		aSplitSize	= m_pSplitter->GetOutputSizePixel();
141 		if ( m_bVertical )
142 		{
143 			// calculate the splitter pos and size
144 			aSplitPos.Y() = aPlaygroundPos.Y();
145 			aSplitSize.Height() = aPlaygroundSize.Height();
146 
147 			if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
148 				aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
149 
150 			if( aSplitPos.X() <= aPlaygroundPos.X() )
151 				aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.3);
152 
153 			// the tree pos and size
154 			Point	aTreeViewPos( aPlaygroundPos );
155 			Size	aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
156 
157 			// set the size of treelistbox
158 			m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
159 
160 			//set the size of the splitter
161 			m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
162 			m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
163 		}
164 		else
165 		{
166 			aSplitPos.X() = aPlaygroundPos.X();
167 			aSplitSize.Width() = aPlaygroundSize.Width();
168 
169 			if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
170 				aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
171 
172 			if( aSplitPos.Y() <= aPlaygroundPos.Y() )
173 				aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.3);
174 
175 			// the tree pos and size
176 			Point	aTreeViewPos( aPlaygroundPos );
177 			Size	aTreeViewSize( aPlaygroundSize.Width() ,aSplitPos.Y());
178 
179 			// set the size of treelistbox
180 			m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
181 
182 			//set the size of the splitter
183 			m_pSplitter->SetPosSizePixel( aSplitPos, Size( aPlaygroundSize.Width(), aSplitSize.Height() ) );
184 			m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
185 		}
186 	}
187 
188 	if ( m_pRight )
189 	{
190 		if ( m_bVertical )
191 			m_pRight->SetPosSizePixel( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
192 								   aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height());
193 		else
194 			m_pRight->SetPosSizePixel( aSplitPos.X(), aPlaygroundPos.Y() + aSplitPos.Y() + aSplitSize.Height(),
195 								   aPlaygroundSize.Width() , aPlaygroundSize.Height() - aSplitSize.Height() - aSplitPos.Y());
196 	}
197 
198 }
199 // -----------------------------------------------------------------------------
200 void OSplitterView::set(Window* _pRight,Window* _pLeft)
201 {
202 	m_pLeft = _pLeft;
203 	m_pRight = _pRight;
204 }
205 // -----------------------------------------------------------------------------
206 void OSplitterView::setSplitter(Splitter* _pSplitter)
207 {
208 	m_pSplitter = _pSplitter;
209 	if ( m_pSplitter )
210 	{
211 		m_pSplitter->SetSplitPosPixel( LogicToPixel( Size( SPLITTER_WIDTH, 0 ), MAP_APPFONT ).Width() );
212 		m_pSplitter->SetSplitHdl( LINK(this, OSplitterView, SplitHdl) );
213 		m_pSplitter->Show();
214 		LINK( this, OSplitterView, SplitHdl ).Call(m_pSplitter);
215 	}
216 }
217