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