xref: /trunk/main/dbaccess/source/ui/control/VertSplitView.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 #ifndef DBAUI_VERTSPLITVIEW_HXX
31 #include "VertSplitView.hxx"
32 #endif
33 
34 #ifndef _TOOLS_DEBUG_HXX
35 #include <tools/debug.hxx>
36 #endif
37 
38 #define SPLITTER_WIDTH  80
39 
40 using namespace ::dbaui;
41 
42 //==================================================================
43 // class OSplitterView
44 //==================================================================
45 DBG_NAME(OSplitterView)
46 OSplitterView::OSplitterView(Window* _pParent,sal_Bool _bVertical) : Window(_pParent,WB_DIALOGCONTROL) // ,WB_BORDER
47     ,m_pSplitter( NULL )
48     ,m_pLeft(NULL)
49     ,m_pRight(NULL)
50     ,m_bVertical(_bVertical)
51 {
52     DBG_CTOR(OSplitterView,NULL);
53     ImplInitSettings( sal_True, sal_True, sal_True );
54 }
55 // -----------------------------------------------------------------------------
56 OSplitterView::~OSplitterView()
57 {
58     DBG_DTOR(OSplitterView,NULL);
59     m_pRight = m_pLeft = NULL;
60 }
61 //------------------------------------------------------------------------------
62 IMPL_LINK( OSplitterView, SplitHdl, Splitter*, /*pSplit*/ )
63 {
64     OSL_ENSURE(m_pSplitter, "Splitter is NULL!");
65     if ( m_bVertical )
66     {
67         long nPosY = m_pSplitter->GetPosPixel().Y();
68         m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nPosY ) );
69     }
70     else
71         m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
72 
73     Resize();
74     return 0L;
75 }
76 // -----------------------------------------------------------------------------
77 void OSplitterView::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
78 {
79     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
80 
81     if ( bFont )
82     {
83         Font aFont = rStyleSettings.GetAppFont();
84         if ( IsControlFont() )
85             aFont.Merge( GetControlFont() );
86         SetPointFont( aFont );
87 //      Set/*Zoomed*/PointFont( aFont );
88     }
89 
90     if ( bFont || bForeground )
91     {
92         Color aTextColor = rStyleSettings.GetButtonTextColor();
93         if ( IsControlForeground() )
94             aTextColor = GetControlForeground();
95         SetTextColor( aTextColor );
96     }
97 
98     if ( bBackground )
99     {
100         if( IsControlBackground() )
101             SetBackground( GetControlBackground() );
102         else
103             SetBackground( rStyleSettings.GetFaceColor() );
104     }
105 }
106 // -----------------------------------------------------------------------
107 void OSplitterView::DataChanged( const DataChangedEvent& rDCEvt )
108 {
109     Window::DataChanged( rDCEvt );
110 
111     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
112          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
113     {
114         ImplInitSettings( sal_True, sal_True, sal_True );
115         Invalidate();
116     }
117 }
118 // -----------------------------------------------------------------------------
119 void OSplitterView::GetFocus()
120 {
121     Window::GetFocus();
122 
123     // forward the focus to the current cell of the editor control
124     if ( m_pLeft )
125         m_pLeft->GrabFocus();
126     else if ( m_pRight )
127         m_pRight->GrabFocus();
128 }
129 
130 // -------------------------------------------------------------------------
131 void OSplitterView::Resize()
132 {
133     Window::Resize();
134     OSL_ENSURE( m_pRight, "No init called!");
135 
136     Point   aSplitPos;
137     Size    aSplitSize;
138     Point   aPlaygroundPos( 0,0 );
139     Size    aPlaygroundSize( GetOutputSizePixel() );
140 
141     if ( m_pLeft && m_pLeft->IsVisible() && m_pSplitter )
142     {
143         aSplitPos   = m_pSplitter->GetPosPixel();
144         aSplitSize  = m_pSplitter->GetOutputSizePixel();
145         if ( m_bVertical )
146         {
147             // calculate the splitter pos and size
148             aSplitPos.Y() = aPlaygroundPos.Y();
149             aSplitSize.Height() = aPlaygroundSize.Height();
150 
151             if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
152                 aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
153 
154             if( aSplitPos.X() <= aPlaygroundPos.X() )
155                 aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.3);
156 
157             // the tree pos and size
158             Point   aTreeViewPos( aPlaygroundPos );
159             Size    aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
160 
161             // set the size of treelistbox
162             m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
163 
164             //set the size of the splitter
165             m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
166             m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
167         }
168         else
169         {
170             aSplitPos.X() = aPlaygroundPos.X();
171             aSplitSize.Width() = aPlaygroundSize.Width();
172 
173             if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
174                 aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
175 
176             if( aSplitPos.Y() <= aPlaygroundPos.Y() )
177                 aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.3);
178 
179             // the tree pos and size
180             Point   aTreeViewPos( aPlaygroundPos );
181             Size    aTreeViewSize( aPlaygroundSize.Width() ,aSplitPos.Y());
182 
183             // set the size of treelistbox
184             m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
185 
186             //set the size of the splitter
187             m_pSplitter->SetPosSizePixel( aSplitPos, Size( aPlaygroundSize.Width(), aSplitSize.Height() ) );
188             m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
189         }
190     }
191 
192     if ( m_pRight )
193     {
194         if ( m_bVertical )
195             m_pRight->SetPosSizePixel( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
196                                    aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height());
197         else
198             m_pRight->SetPosSizePixel( aSplitPos.X(), aPlaygroundPos.Y() + aSplitPos.Y() + aSplitSize.Height(),
199                                    aPlaygroundSize.Width() , aPlaygroundSize.Height() - aSplitSize.Height() - aSplitPos.Y());
200     }
201 
202 }
203 // -----------------------------------------------------------------------------
204 void OSplitterView::set(Window* _pRight,Window* _pLeft)
205 {
206     m_pLeft = _pLeft;
207     m_pRight = _pRight;
208 }
209 // -----------------------------------------------------------------------------
210 void OSplitterView::setSplitter(Splitter* _pSplitter)
211 {
212     m_pSplitter = _pSplitter;
213     if ( m_pSplitter )
214     {
215         m_pSplitter->SetSplitPosPixel( LogicToPixel( Size( SPLITTER_WIDTH, 0 ), MAP_APPFONT ).Width() );
216         m_pSplitter->SetSplitHdl( LINK(this, OSplitterView, SplitHdl) );
217         m_pSplitter->Show();
218         LINK( this, OSplitterView, SplitHdl ).Call(m_pSplitter);
219     }
220 }
221