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_COLUMNCONTROL_HXX
31 #include "ColumnControl.hxx"
32 #endif
33 #ifndef DBAUI_COLUMNPEER_HXX
34 #include "ColumnPeer.hxx"
35 #endif
36 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
37 #include "dbustrings.hrc"
38 #endif
39 #ifndef _DBASHARED_APITOOLS_HXX_
40 #include "apitools.hxx"
41 #endif
42 #ifndef _COM_SUN_STAR_AWT_POSSIZE_HPP_
43 #include <com/sun/star/awt/PosSize.hpp>
44 #endif
45 #ifndef _DBU_REGHELPER_HXX_
46 #include "dbu_reghelper.hxx"
47 #endif
48 
49 extern "C" void SAL_CALL createRegistryInfo_OColumnControl()
50 {
51 	static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OColumnControl> aAutoRegistration;
52 }
53 //.........................................................................
54 namespace dbaui
55 {
56 //.........................................................................
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::awt;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::sdbc;
62 
63 OColumnControl::OColumnControl(const Reference<XMultiServiceFactory>& _rxFactory)
64     :UnoControl( _rxFactory )
65 {
66 }
67 // -----------------------------------------------------------------------------
68 IMPLEMENT_SERVICE_INFO2_STATIC(OColumnControl,SERVICE_CONTROLDEFAULT,"com.sun.star.awt.UnoControl","com.sun.star.sdb.ColumnDescriptorControl")
69 // -----------------------------------------------------------------------------
70 ::rtl::OUString	OColumnControl::GetComponentServiceName()
71 {
72 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.ColumnDescriptorControl"));
73 }
74 // -----------------------------------------------------------------------------
75 void SAL_CALL OColumnControl::createPeer(const Reference< XToolkit >& /*rToolkit*/, const Reference< XWindowPeer >& rParentPeer) throw( RuntimeException )
76 {
77 	::osl::ClearableMutexGuard aGuard( GetMutex() );
78 	if ( !getPeer().is() )
79 	{
80 		mbCreatingPeer = sal_True;
81 
82 		Window* pParentWin = NULL;
83 		if (rParentPeer.is())
84 		{
85 			VCLXWindow* pParent = VCLXWindow::GetImplementation(rParentPeer);
86 			if (pParent)
87 				pParentWin = pParent->GetWindow();
88 		}
89 
90 		OColumnPeer* pPeer = new OColumnPeer( pParentWin, maContext.getLegacyServiceFactory() );
91 		OSL_ENSURE(pPeer != NULL, "FmXGridControl::createPeer : imp_CreatePeer didn't return a peer !");
92 		setPeer( pPeer );
93 
94 		UnoControlComponentInfos aComponentInfos(maComponentInfos);
95 		Reference< XGraphics > xGraphics( mxGraphics );
96 		Reference< XView >  xV(getPeer(), UNO_QUERY);
97 		Reference< XWindow >	xW(getPeer(), UNO_QUERY);
98 
99 		aGuard.clear();
100 
101 		updateFromModel();
102 
103 		xV->setZoom( aComponentInfos.nZoomX, aComponentInfos.nZoomY );
104 		setPosSize( aComponentInfos.nX, aComponentInfos.nY, aComponentInfos.nWidth, aComponentInfos.nHeight, ::com::sun::star::awt::PosSize::POSSIZE );
105 
106 		Reference<XPropertySet> xProp(getModel(), UNO_QUERY);
107 		if ( xProp.is() )
108 		{
109 			Reference<XConnection> xCon(xProp->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY);
110 			pPeer->setConnection(xCon);
111 			Reference<XPropertySet> xColumn(xProp->getPropertyValue(PROPERTY_COLUMN),UNO_QUERY);
112 			pPeer->setColumn(xColumn);
113 			sal_Int32 nWidth = 50;
114 			xProp->getPropertyValue(PROPERTY_EDIT_WIDTH) >>= nWidth;
115 			pPeer->setEditWidth(nWidth);
116 		}
117 
118 		if (aComponentInfos.bVisible)
119 			xW->setVisible(sal_True);
120 
121 		if (!aComponentInfos.bEnable)
122 			xW->setEnable(sal_False);
123 
124 		if (maWindowListeners.getLength())
125 			xW->addWindowListener( &maWindowListeners );
126 
127 		if (maFocusListeners.getLength())
128 			xW->addFocusListener( &maFocusListeners );
129 
130 		if (maKeyListeners.getLength())
131 			xW->addKeyListener( &maKeyListeners );
132 
133 		if (maMouseListeners.getLength())
134 			xW->addMouseListener( &maMouseListeners );
135 
136 		if (maMouseMotionListeners.getLength())
137 			xW->addMouseMotionListener( &maMouseMotionListeners );
138 
139 		if (maPaintListeners.getLength())
140 			xW->addPaintListener( &maPaintListeners );
141 
142 		Reference< ::com::sun::star::awt::XView >  xPeerView(getPeer(), UNO_QUERY);
143 		xPeerView->setZoom( maComponentInfos.nZoomX, maComponentInfos.nZoomY );
144 		xPeerView->setGraphics( xGraphics );
145 
146 		mbCreatingPeer = sal_False;
147 	}
148 }
149 //.........................................................................
150 }	// namespace dbaui
151 //.........................................................................
152