Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / control / VertSplitView.cxx
blob469536b9af6fe08d950c584edef682d7d3f1fa13
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "VertSplitView.hxx"
22 #include <tools/debug.hxx>
23 #include <vcl/split.hxx>
24 #include <vcl/settings.hxx>
26 #define SPLITTER_WIDTH 80
28 using namespace ::dbaui;
30 // class OSplitterView
31 OSplitterView::OSplitterView(vcl::Window* _pParent,bool _bVertical) : Window(_pParent,WB_DIALOGCONTROL) // ,WB_BORDER
32 ,m_pSplitter( NULL )
33 ,m_pLeft(NULL)
34 ,m_pRight(NULL)
35 ,m_bVertical(_bVertical)
37 ImplInitSettings( true, true, true );
40 OSplitterView::~OSplitterView()
42 disposeOnce();
45 void OSplitterView::dispose()
47 m_pSplitter.clear();
48 m_pLeft.clear();
49 m_pRight.clear();
50 vcl::Window::dispose();
53 IMPL_LINK( OSplitterView, SplitHdl, Splitter*, /*pSplit*/ )
55 OSL_ENSURE(m_pSplitter, "Splitter is NULL!");
56 if ( m_bVertical )
58 long nPosY = m_pSplitter->GetPosPixel().Y();
59 m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nPosY ) );
61 else
62 m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
64 Resize();
65 return 0L;
68 void OSplitterView::ImplInitSettings( bool bFont, bool bForeground, bool bBackground )
70 // FIXME RenderContext
71 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
73 if ( bFont )
75 vcl::Font aFont = rStyleSettings.GetAppFont();
76 if ( IsControlFont() )
77 aFont.Merge( GetControlFont() );
78 SetPointFont(*this, aFont);
79 // Set/*Zoomed*/PointFont( aFont );
82 if ( bFont || bForeground )
84 Color aTextColor = rStyleSettings.GetButtonTextColor();
85 if ( IsControlForeground() )
86 aTextColor = GetControlForeground();
87 SetTextColor( aTextColor );
90 if ( bBackground )
92 if( IsControlBackground() )
93 SetBackground( GetControlBackground() );
94 else
95 SetBackground( rStyleSettings.GetFaceColor() );
99 void OSplitterView::DataChanged( const DataChangedEvent& rDCEvt )
101 Window::DataChanged( rDCEvt );
103 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
104 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
106 ImplInitSettings( true, true, true );
107 Invalidate();
111 void OSplitterView::GetFocus()
113 Window::GetFocus();
115 // forward the focus to the current cell of the editor control
116 if ( m_pLeft )
117 m_pLeft->GrabFocus();
118 else if ( m_pRight )
119 m_pRight->GrabFocus();
122 void OSplitterView::Resize()
124 Window::Resize();
125 OSL_ENSURE( m_pRight, "No init called!");
127 Point aSplitPos;
128 Size aSplitSize;
129 Point aPlaygroundPos( 0,0 );
130 Size aPlaygroundSize( GetOutputSizePixel() );
132 if ( m_pLeft && m_pLeft->IsVisible() && m_pSplitter )
134 aSplitPos = m_pSplitter->GetPosPixel();
135 aSplitSize = m_pSplitter->GetOutputSizePixel();
136 if ( m_bVertical )
138 // calculate the splitter pos and size
139 aSplitPos.Y() = aPlaygroundPos.Y();
140 aSplitSize.Height() = aPlaygroundSize.Height();
142 if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
143 aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
145 if( aSplitPos.X() <= aPlaygroundPos.X() )
146 aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.3);
148 // the tree pos and size
149 Point aTreeViewPos( aPlaygroundPos );
150 Size aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
152 // set the size of treelistbox
153 m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
155 //set the size of the splitter
156 m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
157 m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
159 else
161 aSplitPos.X() = aPlaygroundPos.X();
162 aSplitSize.Width() = aPlaygroundSize.Width();
164 if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
165 aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
167 if( aSplitPos.Y() <= aPlaygroundPos.Y() )
168 aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.3);
170 // the tree pos and size
171 Point aTreeViewPos( aPlaygroundPos );
172 Size aTreeViewSize( aPlaygroundSize.Width() ,aSplitPos.Y());
174 // set the size of treelistbox
175 m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
177 //set the size of the splitter
178 m_pSplitter->SetPosSizePixel( aSplitPos, Size( aPlaygroundSize.Width(), aSplitSize.Height() ) );
179 m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
183 if ( m_pRight )
185 if ( m_bVertical )
186 m_pRight->setPosSizePixel( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
187 aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height());
188 else
189 m_pRight->setPosSizePixel( aSplitPos.X(), aPlaygroundPos.Y() + aSplitPos.Y() + aSplitSize.Height(),
190 aPlaygroundSize.Width() , aPlaygroundSize.Height() - aSplitSize.Height() - aSplitPos.Y());
195 void OSplitterView::set(vcl::Window* _pRight,Window* _pLeft)
197 m_pLeft = _pLeft;
198 m_pRight = _pRight;
201 void OSplitterView::setSplitter(Splitter* _pSplitter)
203 m_pSplitter = _pSplitter;
204 if ( m_pSplitter )
206 m_pSplitter->SetSplitPosPixel( LogicToPixel( Size( SPLITTER_WIDTH, 0 ), MAP_APPFONT ).Width() );
207 m_pSplitter->SetSplitHdl( LINK(this, OSplitterView, SplitHdl) );
208 m_pSplitter->Show();
209 LINK( this, OSplitterView, SplitHdl ).Call(m_pSplitter);
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */