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 "TableDesignView.hxx"
21 : #include <tools/debug.hxx>
22 : #include "TableController.hxx"
23 : #include "dbaccess_helpid.hrc"
24 : #include "FieldDescriptions.hxx"
25 : #include "TEditControl.hxx"
26 : #include "TableFieldDescWin.hxx"
27 : #include "TableRow.hxx"
28 : #include <unotools/configmgr.hxx>
29 : #include <comphelper/types.hxx>
30 : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
31 : #include <unotools/syslocale.hxx>
32 : #include <vcl/settings.hxx>
33 : #include "UITools.hxx"
34 : #include <boost/scoped_ptr.hpp>
35 :
36 : using namespace ::dbaui;
37 : using namespace ::utl;
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::datatransfer::clipboard;
40 : using namespace ::com::sun::star::lang;
41 : using namespace ::com::sun::star::beans;
42 :
43 : // class OTableBorderWindow
44 0 : OTableBorderWindow::OTableBorderWindow(vcl::Window* pParent) : Window(pParent,WB_BORDER)
45 0 : ,m_aHorzSplitter( this )
46 : {
47 :
48 0 : ImplInitSettings( true, true, true );
49 : // Children erzeugen
50 0 : m_pEditorCtrl = new OTableEditorCtrl( this);
51 0 : m_pFieldDescWin = new OTableFieldDescWin( this );
52 :
53 0 : m_pFieldDescWin->SetHelpId(HID_TAB_DESIGN_DESCWIN);
54 :
55 : // set depending windows and controls
56 0 : m_pEditorCtrl->SetDescrWin(m_pFieldDescWin);
57 :
58 : // Splitter einrichten
59 0 : m_aHorzSplitter.SetSplitHdl( LINK(this, OTableBorderWindow, SplitHdl) );
60 0 : m_aHorzSplitter.Show();
61 0 : }
62 :
63 0 : OTableBorderWindow::~OTableBorderWindow()
64 : {
65 : // Children zerstoeren
66 : // ::dbaui::notifySystemWindow(this,m_pFieldDescWin,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
67 0 : m_pEditorCtrl->Hide();
68 0 : m_pFieldDescWin->Hide();
69 :
70 : {
71 0 : boost::scoped_ptr<vcl::Window> aTemp(m_pEditorCtrl);
72 0 : m_pEditorCtrl = NULL;
73 : }
74 : {
75 0 : boost::scoped_ptr<vcl::Window> aTemp(m_pFieldDescWin);
76 0 : m_pFieldDescWin = NULL;
77 : }
78 :
79 0 : }
80 :
81 0 : void OTableBorderWindow::Resize()
82 : {
83 0 : const long nSplitterHeight(3);
84 :
85 : // Abmessungen parent window
86 0 : Size aOutputSize( GetOutputSize() );
87 0 : long nOutputWidth = aOutputSize.Width();
88 0 : long nOutputHeight = aOutputSize.Height();
89 0 : long nSplitPos = m_aHorzSplitter.GetSplitPosPixel();
90 :
91 : // Verschiebebereich Splitter mittleres Drittel des Outputs
92 0 : long nDragPosY = nOutputHeight/3;
93 0 : long nDragSizeHeight = nOutputHeight/3;
94 0 : m_aHorzSplitter.SetDragRectPixel( Rectangle(Point(0,nDragPosY), Size(nOutputWidth,nDragSizeHeight) ), this );
95 0 : if( (nSplitPos < nDragPosY) || (nSplitPos > (nDragPosY+nDragSizeHeight)) )
96 0 : nSplitPos = nDragPosY+nDragSizeHeight-5;
97 :
98 : // Splitter setzen
99 0 : m_aHorzSplitter.SetPosSizePixel( Point( 0, nSplitPos ), Size(nOutputWidth, nSplitterHeight));
100 0 : m_aHorzSplitter.SetSplitPosPixel( nSplitPos );
101 :
102 : // Fenster setzen
103 0 : m_pEditorCtrl->SetPosSizePixel( Point(0, 0), Size(nOutputWidth , nSplitPos) );
104 :
105 : m_pFieldDescWin->SetPosSizePixel( Point(0, nSplitPos+nSplitterHeight),
106 0 : Size(nOutputWidth, nOutputHeight-nSplitPos-nSplitterHeight) );
107 0 : }
108 :
109 0 : IMPL_LINK( OTableBorderWindow, SplitHdl, Splitter*, pSplit )
110 : {
111 0 : if(pSplit == &m_aHorzSplitter)
112 : {
113 0 : m_aHorzSplitter.SetPosPixel( Point( m_aHorzSplitter.GetPosPixel().X(),m_aHorzSplitter.GetSplitPosPixel() ) );
114 0 : Resize();
115 : }
116 0 : return 0;
117 : }
118 :
119 0 : void OTableBorderWindow::ImplInitSettings( bool bFont, bool bForeground, bool bBackground )
120 : {
121 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
122 :
123 0 : if ( bFont )
124 : {
125 0 : vcl::Font aFont = rStyleSettings.GetAppFont();
126 0 : if ( IsControlFont() )
127 0 : aFont.Merge( GetControlFont() );
128 0 : SetPointFont( aFont );
129 : }
130 :
131 0 : if ( bFont || bForeground )
132 : {
133 0 : Color aTextColor = rStyleSettings.GetButtonTextColor();
134 0 : if ( IsControlForeground() )
135 0 : aTextColor = GetControlForeground();
136 0 : SetTextColor( aTextColor );
137 : }
138 :
139 0 : if ( bBackground )
140 : {
141 0 : if( IsControlBackground() )
142 0 : SetBackground( GetControlBackground() );
143 : else
144 0 : SetBackground( rStyleSettings.GetFaceColor() );
145 : }
146 0 : }
147 :
148 0 : void OTableBorderWindow::DataChanged( const DataChangedEvent& rDCEvt )
149 : {
150 0 : Window::DataChanged( rDCEvt );
151 :
152 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
153 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
154 : {
155 0 : ImplInitSettings( true, true, true );
156 0 : Invalidate();
157 : }
158 0 : }
159 :
160 0 : void OTableBorderWindow::GetFocus()
161 : {
162 0 : Window::GetFocus();
163 :
164 : // forward the focus to the current cell of the editor control
165 0 : if (m_pEditorCtrl)
166 0 : m_pEditorCtrl->GrabFocus();
167 0 : }
168 :
169 : // class OTableDesignView
170 0 : OTableDesignView::OTableDesignView( vcl::Window* pParent,
171 : const Reference< XComponentContext >& _rxOrb,
172 : OTableController& _rController
173 : ) :
174 : ODataView( pParent, _rController,_rxOrb )
175 : ,m_rController( _rController )
176 0 : ,m_eChildFocus(NONE)
177 : {
178 :
179 : try
180 : {
181 0 : m_aLocale = SvtSysLocale().GetLanguageTag().getLocale();
182 : }
183 0 : catch(Exception&)
184 : {
185 : }
186 :
187 0 : m_pWin = new OTableBorderWindow(this);
188 0 : m_pWin->Show();
189 0 : }
190 :
191 0 : OTableDesignView::~OTableDesignView()
192 : {
193 0 : m_pWin->Hide();
194 :
195 : {
196 0 : boost::scoped_ptr<vcl::Window> aTemp(m_pWin);
197 0 : m_pWin = NULL;
198 : }
199 0 : }
200 :
201 0 : void OTableDesignView::initialize()
202 : {
203 0 : GetEditorCtrl()->Init();
204 0 : GetDescWin()->Init();
205 : // first call after the editctrl has been set
206 :
207 0 : GetEditorCtrl()->Show();
208 0 : GetDescWin()->Show();
209 :
210 0 : GetEditorCtrl()->DisplayData(0);
211 0 : }
212 :
213 0 : void OTableDesignView::resizeDocumentView(Rectangle& _rPlayground)
214 : {
215 0 : m_pWin->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
216 :
217 : // just for completeness: there is no space left, we occupied it all ...
218 0 : _rPlayground.SetPos( _rPlayground.BottomRight() );
219 0 : _rPlayground.SetSize( Size( 0, 0 ) );
220 0 : }
221 :
222 0 : bool OTableDesignView::PreNotify( NotifyEvent& rNEvt )
223 : {
224 0 : bool bHandled = false;
225 0 : switch(rNEvt.GetType())
226 : {
227 : case EVENT_GETFOCUS:
228 0 : if( GetDescWin() && GetDescWin()->HasChildPathFocus() )
229 0 : m_eChildFocus = DESCRIPTION;
230 0 : else if ( GetEditorCtrl() && GetEditorCtrl()->HasChildPathFocus() )
231 0 : m_eChildFocus = EDITOR;
232 : else
233 0 : m_eChildFocus = NONE;
234 0 : break;
235 : }
236 :
237 0 : return bHandled || ODataView::PreNotify(rNEvt);
238 : }
239 :
240 0 : IClipboardTest* OTableDesignView::getActiveChild() const
241 : {
242 0 : IClipboardTest* pTest = NULL;
243 0 : switch(m_eChildFocus)
244 : {
245 : case DESCRIPTION:
246 0 : pTest = GetDescWin();
247 0 : break;
248 : case EDITOR:
249 0 : pTest = GetEditorCtrl();
250 0 : break;
251 : case NONE:
252 0 : break;
253 : }
254 0 : return pTest;
255 : }
256 :
257 0 : bool OTableDesignView::isCopyAllowed()
258 : {
259 0 : IClipboardTest* pTest = getActiveChild();
260 0 : return pTest && pTest->isCopyAllowed();
261 : }
262 :
263 0 : bool OTableDesignView::isCutAllowed()
264 : {
265 0 : IClipboardTest* pTest = getActiveChild();
266 0 : return pTest && pTest->isCutAllowed();
267 : }
268 :
269 0 : bool OTableDesignView::isPasteAllowed()
270 : {
271 0 : IClipboardTest* pTest = getActiveChild();
272 0 : return pTest && pTest->isPasteAllowed();
273 : }
274 :
275 0 : void OTableDesignView::copy()
276 : {
277 0 : IClipboardTest* pTest = getActiveChild();
278 0 : if ( pTest )
279 0 : pTest->copy();
280 0 : }
281 :
282 0 : void OTableDesignView::cut()
283 : {
284 0 : IClipboardTest* pTest = getActiveChild();
285 0 : if ( pTest )
286 0 : pTest->cut();
287 0 : }
288 :
289 0 : void OTableDesignView::paste()
290 : {
291 0 : IClipboardTest* pTest = getActiveChild();
292 0 : if ( pTest )
293 0 : pTest->paste();
294 0 : }
295 :
296 : // set the view readonly or not
297 0 : void OTableDesignView::setReadOnly(bool _bReadOnly)
298 : {
299 0 : GetDescWin()->SetReadOnly(_bReadOnly);
300 0 : GetEditorCtrl()->SetReadOnly(_bReadOnly);
301 0 : }
302 :
303 0 : void OTableDesignView::reSync()
304 : {
305 0 : GetEditorCtrl()->DeactivateCell();
306 0 : ::boost::shared_ptr<OTableRow> pRow = (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
307 0 : OFieldDescription* pFieldDescr = pRow ? pRow->GetActFieldDescr() : NULL;
308 0 : if ( pFieldDescr )
309 0 : GetDescWin()->DisplayData(pFieldDescr);
310 0 : }
311 :
312 0 : void OTableDesignView::GetFocus()
313 : {
314 0 : if ( GetEditorCtrl() )
315 0 : GetEditorCtrl()->GrabFocus();
316 72 : }
317 :
318 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|