Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "VertSplitView.hxx"
21 :
22 : #include <tools/debug.hxx>
23 : #include <vcl/split.hxx>
24 : #include <vcl/settings.hxx>
25 :
26 : #define SPLITTER_WIDTH 80
27 :
28 : using namespace ::dbaui;
29 :
30 : // class OSplitterView
31 7 : 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 7 : ,m_bVertical(_bVertical)
36 : {
37 7 : ImplInitSettings( true, true, true );
38 7 : }
39 :
40 10 : OSplitterView::~OSplitterView()
41 : {
42 5 : disposeOnce();
43 5 : }
44 :
45 5 : void OSplitterView::dispose()
46 : {
47 5 : m_pSplitter.clear();
48 5 : m_pLeft.clear();
49 5 : m_pRight.clear();
50 5 : vcl::Window::dispose();
51 5 : }
52 :
53 14 : IMPL_LINK( OSplitterView, SplitHdl, Splitter*, /*pSplit*/ )
54 : {
55 : OSL_ENSURE(m_pSplitter, "Splitter is NULL!");
56 7 : if ( m_bVertical )
57 : {
58 0 : long nPosY = m_pSplitter->GetPosPixel().Y();
59 0 : m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nPosY ) );
60 : }
61 : else
62 7 : m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
63 :
64 7 : Resize();
65 7 : return 0L;
66 : }
67 :
68 7 : void OSplitterView::ImplInitSettings( bool bFont, bool bForeground, bool bBackground )
69 : {
70 : // FIXME RenderContext
71 7 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
72 :
73 7 : if ( bFont )
74 : {
75 7 : vcl::Font aFont = rStyleSettings.GetAppFont();
76 7 : if ( IsControlFont() )
77 0 : aFont.Merge( GetControlFont() );
78 7 : SetPointFont(*this, aFont);
79 : // Set/*Zoomed*/PointFont( aFont );
80 : }
81 :
82 7 : if ( bFont || bForeground )
83 : {
84 7 : Color aTextColor = rStyleSettings.GetButtonTextColor();
85 7 : if ( IsControlForeground() )
86 0 : aTextColor = GetControlForeground();
87 7 : SetTextColor( aTextColor );
88 : }
89 :
90 7 : if ( bBackground )
91 : {
92 7 : if( IsControlBackground() )
93 0 : SetBackground( GetControlBackground() );
94 : else
95 7 : SetBackground( rStyleSettings.GetFaceColor() );
96 : }
97 7 : }
98 :
99 0 : void OSplitterView::DataChanged( const DataChangedEvent& rDCEvt )
100 : {
101 0 : Window::DataChanged( rDCEvt );
102 :
103 0 : if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
104 0 : (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
105 : {
106 0 : ImplInitSettings( true, true, true );
107 0 : Invalidate();
108 : }
109 0 : }
110 :
111 0 : void OSplitterView::GetFocus()
112 : {
113 0 : Window::GetFocus();
114 :
115 : // forward the focus to the current cell of the editor control
116 0 : if ( m_pLeft )
117 0 : m_pLeft->GrabFocus();
118 0 : else if ( m_pRight )
119 0 : m_pRight->GrabFocus();
120 0 : }
121 :
122 32 : void OSplitterView::Resize()
123 : {
124 32 : Window::Resize();
125 : OSL_ENSURE( m_pRight, "No init called!");
126 :
127 32 : Point aSplitPos;
128 32 : Size aSplitSize;
129 32 : Point aPlaygroundPos( 0,0 );
130 32 : Size aPlaygroundSize( GetOutputSizePixel() );
131 :
132 32 : if ( m_pLeft && m_pLeft->IsVisible() && m_pSplitter )
133 : {
134 32 : aSplitPos = m_pSplitter->GetPosPixel();
135 32 : aSplitSize = m_pSplitter->GetOutputSizePixel();
136 32 : if ( m_bVertical )
137 : {
138 : // calculate the splitter pos and size
139 0 : aSplitPos.Y() = aPlaygroundPos.Y();
140 0 : aSplitSize.Height() = aPlaygroundSize.Height();
141 :
142 0 : if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
143 0 : aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
144 :
145 0 : if( aSplitPos.X() <= aPlaygroundPos.X() )
146 0 : aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.3);
147 :
148 : // the tree pos and size
149 0 : Point aTreeViewPos( aPlaygroundPos );
150 0 : Size aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
151 :
152 : // set the size of treelistbox
153 0 : m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
154 :
155 : //set the size of the splitter
156 0 : m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
157 0 : m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
158 : }
159 : else
160 : {
161 32 : aSplitPos.X() = aPlaygroundPos.X();
162 32 : aSplitSize.Width() = aPlaygroundSize.Width();
163 :
164 32 : if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
165 14 : aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
166 :
167 32 : if( aSplitPos.Y() <= aPlaygroundPos.Y() )
168 20 : aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.3);
169 :
170 : // the tree pos and size
171 32 : Point aTreeViewPos( aPlaygroundPos );
172 32 : Size aTreeViewSize( aPlaygroundSize.Width() ,aSplitPos.Y());
173 :
174 : // set the size of treelistbox
175 32 : m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
176 :
177 : //set the size of the splitter
178 32 : m_pSplitter->SetPosSizePixel( aSplitPos, Size( aPlaygroundSize.Width(), aSplitSize.Height() ) );
179 32 : m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
180 : }
181 : }
182 :
183 32 : if ( m_pRight )
184 : {
185 32 : if ( m_bVertical )
186 0 : m_pRight->setPosSizePixel( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
187 0 : aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height());
188 : else
189 96 : m_pRight->setPosSizePixel( aSplitPos.X(), aPlaygroundPos.Y() + aSplitPos.Y() + aSplitSize.Height(),
190 96 : aPlaygroundSize.Width() , aPlaygroundSize.Height() - aSplitSize.Height() - aSplitPos.Y());
191 : }
192 :
193 32 : }
194 :
195 12 : void OSplitterView::set(vcl::Window* _pRight,Window* _pLeft)
196 : {
197 12 : m_pLeft = _pLeft;
198 12 : m_pRight = _pRight;
199 12 : }
200 :
201 12 : void OSplitterView::setSplitter(Splitter* _pSplitter)
202 : {
203 12 : m_pSplitter = _pSplitter;
204 12 : if ( m_pSplitter )
205 : {
206 7 : m_pSplitter->SetSplitPosPixel( LogicToPixel( Size( SPLITTER_WIDTH, 0 ), MAP_APPFONT ).Width() );
207 7 : m_pSplitter->SetSplitHdl( LINK(this, OSplitterView, SplitHdl) );
208 7 : m_pSplitter->Show();
209 7 : LINK( this, OSplitterView, SplitHdl ).Call(m_pSplitter);
210 : }
211 12 : }
212 :
213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|