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_dbaccess.hxx"
26 #ifndef DBAUI_TABLEWINDOWTITLE_HXX
27 #include "TableWindowTitle.hxx"
28 #endif
29 #ifndef DBAUI_TABLEWINDOW_HXX
30 #include "TableWindow.hxx"
31 #endif
32 #ifndef DBAUI_QUERYTABLEVIEW_HXX
33 #include "QueryTableView.hxx"
34 #endif
35 #ifndef _SV_SVAPP_HXX
36 #include <vcl/svapp.hxx>
37 #endif
38 #ifndef _SV_HELP_HXX
39 #include <vcl/help.hxx>
40 #endif
41 #ifndef _SV_MENU_HXX
42 #include <vcl/menu.hxx>
43 #endif
44 #ifndef _TOOLS_DEBUG_HXX
45 #include <tools/debug.hxx>
46 #endif
47 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
48 #include "dbustrings.hrc"
49 #endif
50 #ifndef _CNTIDS_HRC
51 #include <sfx2/cntids.hrc>
52 #endif
53 #ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
54 #include "TableWindowListBox.hxx"
55 #endif
56 #ifndef DBAUI_TABLECONNECTION_HXX
57 #include "TableConnection.hxx"
58 #endif
59 #ifndef _DBU_QRY_HRC_
60 #include "dbu_qry.hrc"
61 #endif
62 #ifndef DBAUI_QUERYDESIGNVIEW_HXX
63 #include "QueryDesignView.hxx"
64 #endif
65 #ifndef DBAUI_JOINCONTROLLER_HXX
66 #include "JoinController.hxx"
67 #endif
68 
69 #include <algorithm>
70 
71 using namespace dbaui;
72 using namespace ::com::sun::star::beans;
73 using namespace ::com::sun::star::uno;
74 //==================================================================
75 // class OTableWindowTitle
76 //==================================================================
DBG_NAME(OTableWindowTitle)77 DBG_NAME(OTableWindowTitle)
78 //------------------------------------------------------------------------------
79 OTableWindowTitle::OTableWindowTitle( OTableWindow* pParent ) :
80 	 FixedText( pParent, WB_3DLOOK|WB_LEFT|WB_NOLABEL|WB_VCENTER )
81 	,m_pTabWin( pParent )
82 {
83 	DBG_CTOR(OTableWindowTitle,NULL);
84 	// Hintergrund- und Textfarbe setzen
85 	StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
86 	SetBackground(Wallpaper(Color(aSystemStyle.GetFaceColor())));
87 	SetTextColor(aSystemStyle.GetButtonTextColor());
88 
89 	Font aFont( GetFont() );
90 	aFont.SetTransparent( sal_True );
91 	SetFont( aFont );
92 }
93 
94 //------------------------------------------------------------------------------
~OTableWindowTitle()95 OTableWindowTitle::~OTableWindowTitle()
96 {
97 	DBG_DTOR(OTableWindowTitle,NULL);
98 	m_pTabWin = NULL;
99 }
100 
101 //------------------------------------------------------------------------------
GetFocus()102 void OTableWindowTitle::GetFocus()
103 {
104 	if(m_pTabWin)
105 		m_pTabWin->GetFocus();
106 }
107 
108 //------------------------------------------------------------------------------
LoseFocus()109 void OTableWindowTitle::LoseFocus()
110 {
111 	m_pTabWin->LoseFocus();
112 }
113 //------------------------------------------------------------------------------
RequestHelp(const HelpEvent & rHEvt)114 void OTableWindowTitle::RequestHelp( const HelpEvent& rHEvt )
115 {
116 	if(m_pTabWin)
117 	{
118 		String aHelpText = m_pTabWin->GetComposedName();
119 		if( aHelpText.Len())
120 		{
121 			// Hilfe anzeigen
122 			Rectangle aItemRect(Point(0,0),GetSizePixel());
123 			aItemRect = LogicToPixel( aItemRect );
124 			Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
125 			aItemRect.Left()   = aPt.X();
126 			aItemRect.Top()    = aPt.Y();
127 			aPt = OutputToScreenPixel( aItemRect.BottomRight() );
128 			aItemRect.Right()  = aPt.X();
129 			aItemRect.Bottom() = aPt.Y();
130 			if( rHEvt.GetMode() == HELPMODE_BALLOON )
131 				Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText);
132 			else
133 				Help::ShowQuickHelp( this, aItemRect, aHelpText );
134 		}
135 	}
136 }
137 
138 //------------------------------------------------------------------------------
Command(const CommandEvent & rEvt)139 void OTableWindowTitle::Command( const CommandEvent& rEvt )
140 {
141 	switch( rEvt.GetCommand() )
142 	{
143 		case COMMAND_CONTEXTMENU:
144 		{
145 			GrabFocus();
146 			if ( m_pTabWin )
147 				m_pTabWin->Command( rEvt );
148 			else
149 				Control::Command(rEvt);
150 		}
151 	}
152 }
153 
154 //------------------------------------------------------------------------------
155 //void OTableWindowTitle::Paint( const Rectangle& rRect )
156 //{
157 //	//////////////////////////////////////////////////////////////////////
158 //	// Ausgabe des Textes in der Titelzeile
159 //	Rectangle aWinRect( Point(0,0), GetSizePixel() );
160 //	DrawText( aWinRect, GetText(), TEXT_DRAW_CENTER|TEXT_DRAW_VCENTER|TEXT_DRAW_ENDELLIPSIS );
161 //}
162 
163 //------------------------------------------------------------------------------
KeyInput(const KeyEvent & rEvt)164 void OTableWindowTitle::KeyInput( const KeyEvent& rEvt )
165 {
166 	if ( m_pTabWin )
167 		m_pTabWin->KeyInput( rEvt );
168 }
169 
170 //------------------------------------------------------------------------------
MouseButtonDown(const MouseEvent & rEvt)171 void OTableWindowTitle::MouseButtonDown( const MouseEvent& rEvt )
172 {
173 	if( rEvt.IsLeft() )
174 	{
175 		if(	rEvt.GetClicks() == 2)
176 		{
177 			Size aSize(GetTextWidth(GetText()) + 20,
178 						m_pTabWin->GetSizePixel().Height() - m_pTabWin->GetListBox()->GetSizePixel().Height());
179 
180 			aSize.Height() += (m_pTabWin->GetListBox()->GetEntryCount() + 2) * m_pTabWin->GetListBox()->GetEntryHeight();
181 			if(m_pTabWin->GetSizePixel() != aSize)
182 			{
183 				m_pTabWin->SetSizePixel(aSize);
184 
185 				OJoinTableView* pView = static_cast<OJoinTableView*>(m_pTabWin->getTableView());
186 				OSL_ENSURE(pView,"No OJoinTableView!");
187 				const ::std::vector<OTableConnection*>* pConns = pView->getTableConnections();
188 				::std::for_each(pConns->begin(),
189 								pConns->end(),
190 								::std::mem_fun(&OTableConnection::RecalcLines));
191 
192 				pView->InvalidateConnections();
193 				pView->getDesignView()->getController().setModified(sal_True);
194 				pView->Invalidate(INVALIDATE_NOCHILDREN);
195 			}
196 		}
197 		else
198 		{
199 			Point aPos = rEvt.GetPosPixel();
200 			aPos = OutputToScreenPixel( aPos );
201 			OJoinTableView* pView = static_cast<OJoinTableView*>(m_pTabWin->getTableView());
202 			OSL_ENSURE(pView,"No OJoinTableView!");
203 			pView->NotifyTitleClicked( static_cast<OTableWindow*>(GetParent()), aPos );
204 		}
205 		GrabFocus();
206 	}
207 	else
208 		Control::MouseButtonDown( rEvt );
209 }
210 
211 
212 //------------------------------------------------------------------------------
DataChanged(const DataChangedEvent & rDCEvt)213 void OTableWindowTitle::DataChanged(const DataChangedEvent& rDCEvt)
214 {
215 	if (rDCEvt.GetType() == DATACHANGED_SETTINGS)
216 	{
217 		// nehmen wir den worst-case an : die Farben haben sich geaendert, also
218 		// mich anpassen
219 		StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
220 		SetBackground(Wallpaper(Color(aSystemStyle.GetFaceColor())));
221 		SetTextColor(aSystemStyle.GetButtonTextColor());
222 	}
223 }
224 // -----------------------------------------------------------------------------
StateChanged(StateChangedType nType)225 void OTableWindowTitle::StateChanged( StateChangedType nType )
226 {
227 	Window::StateChanged( nType );
228 
229 	if ( nType == STATE_CHANGE_ZOOM )
230 	{
231 		const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
232 
233 		Font aFont = rStyleSettings.GetGroupFont();
234 		if ( IsControlFont() )
235 			aFont.Merge( GetControlFont() );
236 		SetZoomedPointFont( aFont );
237 
238 		Resize();
239 	}
240 }
241 
242 
243 
244 
245