1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbui.hxx"
26 #ifndef DBAUI_TABLEDESIGNVIEW_HXX
27 #include "TableDesignView.hxx"
28 #endif
29 #ifndef _TOOLS_DEBUG_HXX
30 #include <tools/debug.hxx>
31 #endif
32 #ifndef DBUI_TABLECONTROLLER_HXX
33 #include "TableController.hxx"
34 #endif
35 #ifndef _DBA_DBACCESS_HELPID_HRC_
36 #include "dbaccess_helpid.hrc"
37 #endif
38 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
39 #include "FieldDescriptions.hxx"
40 #endif
41 #ifndef DBAUI_TABLEEDITORCONTROL_HXX
42 #include "TEditControl.hxx"
43 #endif
44 #ifndef DBAUI_TABLEFIELDDESCRIPTION_HXX
45 #include "TableFieldDescWin.hxx"
46 #endif
47 #ifndef DBAUI_TABLEROW_HXX
48 #include "TableRow.hxx"
49 #endif
50 #ifndef _UTL_CONFIGMGR_HXX_
51 #include <unotools/configmgr.hxx>
52 #endif
53 #ifndef _COMPHELPER_TYPES_HXX_
54 #include <comphelper/types.hxx>
55 #endif
56 #ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARD_HPP_
57 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
58 #endif
59 #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
60 #include <unotools/syslocale.hxx>
61 #endif
62 #ifndef DBAUI_TOOLS_HXX
63 #include "UITools.hxx"
64 #endif
65 
66 
67 using namespace ::dbaui;
68 using namespace ::utl;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::datatransfer::clipboard;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::beans;
73 
74 //==================================================================
75 // class OTableBorderWindow
DBG_NAME(OTableBorderWindow)76 DBG_NAME(OTableBorderWindow)
77 //==================================================================
78 OTableBorderWindow::OTableBorderWindow(Window* pParent) : Window(pParent,WB_BORDER)
79 	,m_aHorzSplitter( this )
80 {
81     DBG_CTOR(OTableBorderWindow,NULL);
82 
83 	ImplInitSettings( sal_True, sal_True, sal_True );
84 	//////////////////////////////////////////////////////////////////////
85 	// Childs erzeugen
86 	m_pEditorCtrl	= new OTableEditorCtrl( this);
87 	m_pFieldDescWin = new OTableFieldDescWin( this );
88 
89 	m_pFieldDescWin->SetHelpId(HID_TAB_DESIGN_DESCWIN);
90 
91 	// set depending windows and controls
92 	m_pEditorCtrl->SetDescrWin(m_pFieldDescWin);
93 
94 	//////////////////////////////////////////////////////////////////////
95 	// Splitter einrichten
96 	m_aHorzSplitter.SetSplitHdl( LINK(this, OTableBorderWindow, SplitHdl) );
97 	m_aHorzSplitter.Show();
98 }
99 // -----------------------------------------------------------------------------
~OTableBorderWindow()100 OTableBorderWindow::~OTableBorderWindow()
101 {
102 	//////////////////////////////////////////////////////////////////////
103 	// Childs zerstoeren
104 	//	::dbaui::notifySystemWindow(this,m_pFieldDescWin,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
105 	m_pEditorCtrl->Hide();
106 	m_pFieldDescWin->Hide();
107 
108 	{
109 		::std::auto_ptr<Window> aTemp(m_pEditorCtrl);
110 		m_pEditorCtrl = NULL;
111 	}
112 	{
113 		::std::auto_ptr<Window> aTemp(m_pFieldDescWin);
114 		m_pFieldDescWin = NULL;
115 	}
116 
117     DBG_DTOR(OTableBorderWindow,NULL);
118 }
119 // -----------------------------------------------------------------------------
Resize()120 void OTableBorderWindow::Resize()
121 {
122 	const long nSplitterHeight(3);
123 
124 	//////////////////////////////////////////////////////////////////////
125 	// Abmessungen parent window
126 	Size aOutputSize( GetOutputSize() );
127 	long nOutputWidth	= aOutputSize.Width();
128 	long nOutputHeight	= aOutputSize.Height();
129 	long nSplitPos		= m_aHorzSplitter.GetSplitPosPixel();
130 
131 	//////////////////////////////////////////////////////////////////////
132 	// Verschiebebereich Splitter mittleres Drittel des Outputs
133 	long nDragPosY = nOutputHeight/3;
134 	long nDragSizeHeight = nOutputHeight/3;
135 	m_aHorzSplitter.SetDragRectPixel( Rectangle(Point(0,nDragPosY), Size(nOutputWidth,nDragSizeHeight) ), this );
136 	if( (nSplitPos < nDragPosY) || (nSplitPos > (nDragPosY+nDragSizeHeight)) )
137 		nSplitPos = nDragPosY+nDragSizeHeight-5;
138 
139 	//////////////////////////////////////////////////////////////////////
140 	// Splitter setzen
141 	m_aHorzSplitter.SetPosSizePixel( Point( 0, nSplitPos ), Size(nOutputWidth, nSplitterHeight));
142 	m_aHorzSplitter.SetSplitPosPixel( nSplitPos );
143 
144 	//////////////////////////////////////////////////////////////////////
145 	// Fenster setzen
146 	m_pEditorCtrl->SetPosSizePixel( Point(0, 0), Size(nOutputWidth , nSplitPos) );
147 
148 	m_pFieldDescWin->SetPosSizePixel(	Point(0, nSplitPos+nSplitterHeight),
149 						Size(nOutputWidth, nOutputHeight-nSplitPos-nSplitterHeight) );
150 }
151 //------------------------------------------------------------------------------
IMPL_LINK(OTableBorderWindow,SplitHdl,Splitter *,pSplit)152 IMPL_LINK( OTableBorderWindow, SplitHdl, Splitter*, pSplit )
153 {
154 	if(pSplit == &m_aHorzSplitter)
155 	{
156 		m_aHorzSplitter.SetPosPixel( Point( m_aHorzSplitter.GetPosPixel().X(),m_aHorzSplitter.GetSplitPosPixel() ) );
157 		Resize();
158 	}
159 	return 0;
160 }
161 // -----------------------------------------------------------------------------
ImplInitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground)162 void OTableBorderWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
163 {
164 	const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
165 
166 	if ( bFont )
167 	{
168 		Font aFont = rStyleSettings.GetAppFont();
169 		if ( IsControlFont() )
170 			aFont.Merge( GetControlFont() );
171 		SetPointFont( aFont );
172 //		Set/*Zoomed*/PointFont( aFont );
173 	}
174 
175 	if ( bFont || bForeground )
176 	{
177 		Color aTextColor = rStyleSettings.GetButtonTextColor();
178 		if ( IsControlForeground() )
179 			aTextColor = GetControlForeground();
180 		SetTextColor( aTextColor );
181 	}
182 
183 	if ( bBackground )
184 	{
185 		if( IsControlBackground() )
186 			SetBackground( GetControlBackground() );
187 		else
188 			SetBackground( rStyleSettings.GetFaceColor() );
189 	}
190 }
191 // -----------------------------------------------------------------------
DataChanged(const DataChangedEvent & rDCEvt)192 void OTableBorderWindow::DataChanged( const DataChangedEvent& rDCEvt )
193 {
194 	Window::DataChanged( rDCEvt );
195 
196 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
197 		 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
198 	{
199 		ImplInitSettings( sal_True, sal_True, sal_True );
200 		Invalidate();
201 	}
202 }
203 // -----------------------------------------------------------------------------
GetFocus()204 void OTableBorderWindow::GetFocus()
205 {
206 	Window::GetFocus();
207 
208 	// forward the focus to the current cell of the editor control
209 	if (m_pEditorCtrl)
210 		m_pEditorCtrl->GrabFocus();
211 }
212 
213 //==================================================================
214 // class OTableDesignView
215 //==================================================================
216 DBG_NAME(OTableDesignView);
217 //------------------------------------------------------------------------------
OTableDesignView(Window * pParent,const Reference<XMultiServiceFactory> & _rxOrb,OTableController & _rController)218 OTableDesignView::OTableDesignView( Window* pParent,
219 									const Reference< XMultiServiceFactory >& _rxOrb,
220 									OTableController& _rController
221 								   ) :
222 	ODataView( pParent, _rController,_rxOrb )
223 	,m_rController( _rController )
224 	,m_eChildFocus(NONE)
225 {
226 	DBG_CTOR(OTableDesignView,NULL);
227 
228 	try
229 	{
230 		m_aLocale = SvtSysLocale().GetLocaleData().getLocale();
231 	}
232 	catch(Exception&)
233 	{
234 	}
235 
236 	m_pWin = new OTableBorderWindow(this);
237 	m_pWin->Show();
238 }
239 
240 //------------------------------------------------------------------------------
~OTableDesignView()241 OTableDesignView::~OTableDesignView()
242 {
243 	DBG_DTOR(OTableDesignView,NULL);
244 	m_pWin->Hide();
245 
246 	{
247 		::std::auto_ptr<Window> aTemp(m_pWin);
248 		m_pWin = NULL;
249 	}
250 }
251 
252 // -----------------------------------------------------------------------------
initialize()253 void OTableDesignView::initialize()
254 {
255 	GetEditorCtrl()->Init();
256 	GetDescWin()->Init();
257 	// first call after the editctrl has been set
258 
259 	GetEditorCtrl()->Show();
260 	GetDescWin()->Show();
261 
262 	GetEditorCtrl()->DisplayData(0);
263 }
264 //------------------------------------------------------------------------------
265 
266 //------------------------------------------------------------------------------
resizeDocumentView(Rectangle & _rPlayground)267 void OTableDesignView::resizeDocumentView(Rectangle& _rPlayground)
268 {
269 	m_pWin->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
270 
271 	// just for completeness: there is no space left, we occupied it all ...
272 	_rPlayground.SetPos( _rPlayground.BottomRight() );
273 	_rPlayground.SetSize( Size( 0, 0 ) );
274 }
275 
276 //------------------------------------------------------------------------------
277 IMPL_LINK( OTableDesignView, SwitchHdl, Accelerator*, /*pAcc*/ )
278 {
279 	if( getController().isReadOnly() )
280 		return 0;
281 
282 	if( GetDescWin()->HasChildPathFocus() )
283 	{
284 		GetDescWin()->LoseFocus();
285 		GetEditorCtrl()->GrabFocus();
286 	}
287 	else
288 	{
289 		 ::boost::shared_ptr<OTableRow>  pRow = (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
290 		OFieldDescription* pFieldDescr = pRow ? pRow->GetActFieldDescr() : NULL;
291 		if ( pFieldDescr )
292 			GetDescWin()->GrabFocus();
293 		else
294 			GetEditorCtrl()->GrabFocus();
295 	}
296 
297 	return 0;
298 }
299 //------------------------------------------------------------------------------
PreNotify(NotifyEvent & rNEvt)300 long OTableDesignView::PreNotify( NotifyEvent& rNEvt )
301 {
302 	sal_Bool bHandled = sal_False;
303 	switch(rNEvt.GetType())
304 	{
305 		case EVENT_GETFOCUS:
306 			if( GetDescWin() && GetDescWin()->HasChildPathFocus() )
307 				m_eChildFocus = DESCRIPTION;
308 			else if ( GetEditorCtrl() && GetEditorCtrl()->HasChildPathFocus() )
309 				m_eChildFocus = EDITOR;
310 			else
311 				m_eChildFocus = NONE;
312 			break;
313 	}
314 
315 	return bHandled ? 1L : ODataView::PreNotify(rNEvt);
316 }
317 // -----------------------------------------------------------------------------
getActiveChild() const318 IClipboardTest* OTableDesignView::getActiveChild() const
319 {
320 	IClipboardTest* pTest = NULL;
321 	switch(m_eChildFocus)
322 	{
323 		case DESCRIPTION:
324 			pTest = GetDescWin();
325 			break;
326 		case EDITOR:
327 			pTest = GetEditorCtrl();
328 			break;
329         case NONE:
330             break;
331 	}
332 	return pTest;
333 }
334 // -----------------------------------------------------------------------------
isCopyAllowed()335 sal_Bool OTableDesignView::isCopyAllowed()
336 {
337 	IClipboardTest* pTest = getActiveChild();
338 	return pTest && pTest->isCopyAllowed();
339 }
340 // -----------------------------------------------------------------------------
isCutAllowed()341 sal_Bool OTableDesignView::isCutAllowed()
342 {
343 	IClipboardTest* pTest = getActiveChild();
344 	return pTest && pTest->isCutAllowed();
345 }
346 // -----------------------------------------------------------------------------
isPasteAllowed()347 sal_Bool OTableDesignView::isPasteAllowed()
348 {
349 	IClipboardTest* pTest = getActiveChild();
350 	return pTest && pTest->isPasteAllowed();
351 }
352 // -----------------------------------------------------------------------------
copy()353 void OTableDesignView::copy()
354 {
355 	IClipboardTest* pTest = getActiveChild();
356 	if ( pTest )
357 		pTest->copy();
358 }
359 // -----------------------------------------------------------------------------
cut()360 void OTableDesignView::cut()
361 {
362 	IClipboardTest* pTest = getActiveChild();
363 	if ( pTest )
364 		pTest->cut();
365 }
366 // -----------------------------------------------------------------------------
paste()367 void OTableDesignView::paste()
368 {
369 	IClipboardTest* pTest = getActiveChild();
370 	if ( pTest )
371 		pTest->paste();
372 }
373 // -----------------------------------------------------------------------------
374 // set the view readonly or not
setReadOnly(sal_Bool _bReadOnly)375 void OTableDesignView::setReadOnly(sal_Bool _bReadOnly)
376 {
377 	GetDescWin()->SetReadOnly(_bReadOnly);
378 	GetEditorCtrl()->SetReadOnly(_bReadOnly);
379 }
380 // -----------------------------------------------------------------------------
reSync()381 void OTableDesignView::reSync()
382 {
383 	GetEditorCtrl()->DeactivateCell();
384 	 ::boost::shared_ptr<OTableRow>  pRow = (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
385 	OFieldDescription* pFieldDescr = pRow ? pRow->GetActFieldDescr() : NULL;
386 	if ( pFieldDescr )
387 		GetDescWin()->DisplayData(pFieldDescr);
388 }
389 // -----------------------------------------------------------------------------
GetFocus()390 void OTableDesignView::GetFocus()
391 {
392 	if ( GetEditorCtrl() )
393 		GetEditorCtrl()->GrabFocus();
394 }
395 // -----------------------------------------------------------------------------
396 
397