Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / dbaccess / source / ui / control / VertSplitView.cxx
blobbf9dd114b3cff55d6e8e91ffafe76b79cec778a9
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) : Window(_pParent,WB_DIALOGCONTROL) // ,WB_BORDER
32 ,m_pSplitter( nullptr )
33 ,m_pLeft(nullptr)
34 ,m_pRight(nullptr)
35 ,m_bVertical(false)
37 ImplInitSettings();
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_NOARG_TYPED( OSplitterView, SplitHdl, Splitter*, void )
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();
67 void OSplitterView::ImplInitSettings()
69 // FIXME RenderContext
70 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
72 vcl::Font aFont = rStyleSettings.GetAppFont();
73 if ( IsControlFont() )
74 aFont.Merge( GetControlFont() );
75 SetPointFont(*this, aFont);
76 // Set/*Zoomed*/PointFont( aFont );
78 Color aTextColor = rStyleSettings.GetButtonTextColor();
79 if ( IsControlForeground() )
80 aTextColor = GetControlForeground();
81 SetTextColor( aTextColor );
83 if( IsControlBackground() )
84 SetBackground( GetControlBackground() );
85 else
86 SetBackground( rStyleSettings.GetFaceColor() );
89 void OSplitterView::DataChanged( const DataChangedEvent& rDCEvt )
91 Window::DataChanged( rDCEvt );
93 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
94 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
96 ImplInitSettings();
97 Invalidate();
101 void OSplitterView::GetFocus()
103 Window::GetFocus();
105 // forward the focus to the current cell of the editor control
106 if ( m_pLeft )
107 m_pLeft->GrabFocus();
108 else if ( m_pRight )
109 m_pRight->GrabFocus();
112 void OSplitterView::Resize()
114 Window::Resize();
115 OSL_ENSURE( m_pRight, "No init called!");
117 Point aSplitPos;
118 Size aSplitSize;
119 Point aPlaygroundPos( 0,0 );
120 Size aPlaygroundSize( GetOutputSizePixel() );
122 if ( m_pLeft && m_pLeft->IsVisible() && m_pSplitter )
124 aSplitPos = m_pSplitter->GetPosPixel();
125 aSplitSize = m_pSplitter->GetOutputSizePixel();
126 if ( m_bVertical )
128 // calculate the splitter pos and size
129 aSplitPos.Y() = aPlaygroundPos.Y();
130 aSplitSize.Height() = aPlaygroundSize.Height();
132 if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
133 aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
135 if( aSplitPos.X() <= aPlaygroundPos.X() )
136 aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.3);
138 // the tree pos and size
139 Point aTreeViewPos( aPlaygroundPos );
140 Size aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
142 // set the size of treelistbox
143 m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
145 //set the size of the splitter
146 m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
147 m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
149 else
151 aSplitPos.X() = aPlaygroundPos.X();
152 aSplitSize.Width() = aPlaygroundSize.Width();
154 if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
155 aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
157 if( aSplitPos.Y() <= aPlaygroundPos.Y() )
158 aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.3);
160 // the tree pos and size
161 Point aTreeViewPos( aPlaygroundPos );
162 Size aTreeViewSize( aPlaygroundSize.Width() ,aSplitPos.Y());
164 // set the size of treelistbox
165 m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
167 //set the size of the splitter
168 m_pSplitter->SetPosSizePixel( aSplitPos, Size( aPlaygroundSize.Width(), aSplitSize.Height() ) );
169 m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
173 if ( m_pRight )
175 if ( m_bVertical )
176 m_pRight->setPosSizePixel( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
177 aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height());
178 else
179 m_pRight->setPosSizePixel( aSplitPos.X(), aPlaygroundPos.Y() + aSplitPos.Y() + aSplitSize.Height(),
180 aPlaygroundSize.Width() , aPlaygroundSize.Height() - aSplitSize.Height() - aSplitPos.Y());
185 void OSplitterView::set(vcl::Window* _pRight,Window* _pLeft)
187 m_pLeft = _pLeft;
188 m_pRight = _pRight;
191 void OSplitterView::setSplitter(Splitter* _pSplitter)
193 m_pSplitter = _pSplitter;
194 if ( m_pSplitter )
196 m_pSplitter->SetSplitPosPixel( LogicToPixel( Size( SPLITTER_WIDTH, 0 ), MAP_APPFONT ).Width() );
197 m_pSplitter->SetSplitHdl( LINK(this, OSplitterView, SplitHdl) );
198 m_pSplitter->Show();
199 LINK( this, OSplitterView, SplitHdl ).Call(m_pSplitter);
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */