merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / control / VertSplitView.cxx
blob1d56aef1d2c50191e2a3ba24d87b1964d86510f7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VertSplitView.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_VERTSPLITVIEW_HXX
34 #include "VertSplitView.hxx"
35 #endif
37 #ifndef _TOOLS_DEBUG_HXX
38 #include <tools/debug.hxx>
39 #endif
41 #define SPLITTER_WIDTH 80
43 using namespace ::dbaui;
45 //==================================================================
46 // class OSplitterView
47 //==================================================================
48 DBG_NAME(OSplitterView)
49 OSplitterView::OSplitterView(Window* _pParent,sal_Bool _bVertical) : Window(_pParent,WB_DIALOGCONTROL) // ,WB_BORDER
50 ,m_pSplitter( NULL )
51 ,m_pLeft(NULL)
52 ,m_pRight(NULL)
53 ,m_bVertical(_bVertical)
55 DBG_CTOR(OSplitterView,NULL);
56 ImplInitSettings( sal_True, sal_True, sal_True );
58 // -----------------------------------------------------------------------------
59 OSplitterView::~OSplitterView()
61 DBG_DTOR(OSplitterView,NULL);
62 m_pRight = m_pLeft = NULL;
64 //------------------------------------------------------------------------------
65 IMPL_LINK( OSplitterView, SplitHdl, Splitter*, /*pSplit*/ )
67 OSL_ENSURE(m_pSplitter, "Splitter is NULL!");
68 if ( m_bVertical )
70 long nPosY = m_pSplitter->GetPosPixel().Y();
71 m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nPosY ) );
73 else
74 m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
76 Resize();
77 return 0L;
79 // -----------------------------------------------------------------------------
80 void OSplitterView::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
82 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
84 if ( bFont )
86 Font aFont = rStyleSettings.GetAppFont();
87 if ( IsControlFont() )
88 aFont.Merge( GetControlFont() );
89 SetPointFont( aFont );
90 // Set/*Zoomed*/PointFont( aFont );
93 if ( bFont || bForeground )
95 Color aTextColor = rStyleSettings.GetButtonTextColor();
96 if ( IsControlForeground() )
97 aTextColor = GetControlForeground();
98 SetTextColor( aTextColor );
101 if ( bBackground )
103 if( IsControlBackground() )
104 SetBackground( GetControlBackground() );
105 else
106 SetBackground( rStyleSettings.GetFaceColor() );
109 // -----------------------------------------------------------------------
110 void OSplitterView::DataChanged( const DataChangedEvent& rDCEvt )
112 Window::DataChanged( rDCEvt );
114 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
115 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
117 ImplInitSettings( sal_True, sal_True, sal_True );
118 Invalidate();
121 // -----------------------------------------------------------------------------
122 void OSplitterView::GetFocus()
124 Window::GetFocus();
126 // forward the focus to the current cell of the editor control
127 if ( m_pLeft )
128 m_pLeft->GrabFocus();
129 else if ( m_pRight )
130 m_pRight->GrabFocus();
133 // -------------------------------------------------------------------------
134 void OSplitterView::Resize()
136 Window::Resize();
137 OSL_ENSURE( m_pRight, "No init called!");
139 Point aSplitPos;
140 Size aSplitSize;
141 Point aPlaygroundPos( 0,0 );
142 Size aPlaygroundSize( GetOutputSizePixel() );
144 if ( m_pLeft && m_pLeft->IsVisible() && m_pSplitter )
146 aSplitPos = m_pSplitter->GetPosPixel();
147 aSplitSize = m_pSplitter->GetOutputSizePixel();
148 if ( m_bVertical )
150 // calculate the splitter pos and size
151 aSplitPos.Y() = aPlaygroundPos.Y();
152 aSplitSize.Height() = aPlaygroundSize.Height();
154 if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
155 aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
157 if( aSplitPos.X() <= aPlaygroundPos.X() )
158 aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.3);
160 // the tree pos and size
161 Point aTreeViewPos( aPlaygroundPos );
162 Size aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
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( aSplitSize.Width(), aPlaygroundSize.Height() ) );
169 m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
171 else
173 aSplitPos.X() = aPlaygroundPos.X();
174 aSplitSize.Width() = aPlaygroundSize.Width();
176 if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
177 aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
179 if( aSplitPos.Y() <= aPlaygroundPos.Y() )
180 aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.3);
182 // the tree pos and size
183 Point aTreeViewPos( aPlaygroundPos );
184 Size aTreeViewSize( aPlaygroundSize.Width() ,aSplitPos.Y());
186 // set the size of treelistbox
187 m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
189 //set the size of the splitter
190 m_pSplitter->SetPosSizePixel( aSplitPos, Size( aPlaygroundSize.Width(), aSplitSize.Height() ) );
191 m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
195 if ( m_pRight )
197 if ( m_bVertical )
198 m_pRight->SetPosSizePixel( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
199 aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height());
200 else
201 m_pRight->SetPosSizePixel( aSplitPos.X(), aPlaygroundPos.Y() + aSplitPos.Y() + aSplitSize.Height(),
202 aPlaygroundSize.Width() , aPlaygroundSize.Height() - aSplitSize.Height() - aSplitPos.Y());
206 // -----------------------------------------------------------------------------
207 void OSplitterView::set(Window* _pRight,Window* _pLeft)
209 m_pLeft = _pLeft;
210 m_pRight = _pRight;
212 // -----------------------------------------------------------------------------
213 void OSplitterView::setSplitter(Splitter* _pSplitter)
215 m_pSplitter = _pSplitter;
216 if ( m_pSplitter )
218 m_pSplitter->SetSplitPosPixel( LogicToPixel( Size( SPLITTER_WIDTH, 0 ), MAP_APPFONT ).Width() );
219 m_pSplitter->SetSplitHdl( LINK(this, OSplitterView, SplitHdl) );
220 m_pSplitter->Show();
221 LINK( this, OSplitterView, SplitHdl ).Call(m_pSplitter);