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 <TableWindowTitle.hxx>
21 #include <TableWindow.hxx>
22 #include <QueryTableView.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/help.hxx>
25 #include <vcl/menu.hxx>
26 #include <vcl/settings.hxx>
27 #include <vcl/commandevent.hxx>
28 #include <vcl/event.hxx>
29 #include <stringconstants.hxx>
30 #include <TableWindowListBox.hxx>
31 #include <TableConnection.hxx>
32 #include <QueryDesignView.hxx>
33 #include <JoinController.hxx>
34 
35 #include <algorithm>
36 
37 using namespace dbaui;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::uno;
40 // class OTableWindowTitle
OTableWindowTitle(OTableWindow * pParent)41 OTableWindowTitle::OTableWindowTitle( OTableWindow* pParent ) :
42      FixedText( pParent, WB_3DLOOK|WB_LEFT|WB_NOLABEL|WB_VCENTER )
43     ,m_pTabWin( pParent )
44 {
45     // set background- and text colour
46     StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
47     SetBackground(Wallpaper(aSystemStyle.GetFaceColor()));
48     SetTextColor(aSystemStyle.GetButtonTextColor());
49 
50     vcl::Font aFont( GetFont() );
51     aFont.SetTransparent( true );
52     SetFont( aFont );
53 }
54 
~OTableWindowTitle()55 OTableWindowTitle::~OTableWindowTitle()
56 {
57     disposeOnce();
58 }
59 
dispose()60 void OTableWindowTitle::dispose()
61 {
62     m_pTabWin.clear();
63     FixedText::dispose();
64 }
65 
GetFocus()66 void OTableWindowTitle::GetFocus()
67 {
68     if(m_pTabWin)
69         m_pTabWin->GetFocus();
70     else
71         FixedText::GetFocus();
72 }
73 
LoseFocus()74 void OTableWindowTitle::LoseFocus()
75 {
76     if (m_pTabWin)
77         m_pTabWin->LoseFocus();
78     else
79         FixedText::LoseFocus();
80 }
81 
RequestHelp(const HelpEvent & rHEvt)82 void OTableWindowTitle::RequestHelp( const HelpEvent& rHEvt )
83 {
84     if(m_pTabWin)
85     {
86         OUString aHelpText = m_pTabWin->GetComposedName();
87         if( !aHelpText.isEmpty())
88         {
89             // show help
90             tools::Rectangle aItemRect(Point(0,0),GetSizePixel());
91             aItemRect = LogicToPixel( aItemRect );
92             Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
93             aItemRect.SetLeft( aPt.X() );
94             aItemRect.SetTop( aPt.Y() );
95             aPt = OutputToScreenPixel( aItemRect.BottomRight() );
96             aItemRect.SetRight( aPt.X() );
97             aItemRect.SetBottom( aPt.Y() );
98             if( rHEvt.GetMode() == HelpEventMode::BALLOON )
99                 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText);
100             else
101                 Help::ShowQuickHelp( this, aItemRect, aHelpText );
102         }
103     }
104 }
105 
Command(const CommandEvent & rEvt)106 void OTableWindowTitle::Command( const CommandEvent& rEvt )
107 {
108     if ( rEvt.GetCommand() == CommandEventId::ContextMenu )
109     {
110         GrabFocus();
111         if ( m_pTabWin )
112         {
113             // tdf#94709 - protect shutdown code-path.
114             VclPtr<OTableWindow> xTabWin(m_pTabWin);
115             xTabWin->Command( rEvt );
116         }
117         else
118             Control::Command(rEvt);
119     }
120 }
121 
KeyInput(const KeyEvent & rEvt)122 void OTableWindowTitle::KeyInput( const KeyEvent& rEvt )
123 {
124     if ( m_pTabWin )
125         m_pTabWin->KeyInput( rEvt );
126 }
127 
MouseButtonDown(const MouseEvent & rEvt)128 void OTableWindowTitle::MouseButtonDown( const MouseEvent& rEvt )
129 {
130     if( rEvt.IsLeft() )
131     {
132         if( rEvt.GetClicks() == 2)
133         {
134             Size aSize(GetTextWidth(GetText()) + 20,
135                         m_pTabWin->GetSizePixel().Height() - m_pTabWin->GetListBox()->GetSizePixel().Height());
136 
137             aSize.AdjustHeight((m_pTabWin->GetListBox()->GetEntryCount() + 2) * m_pTabWin->GetListBox()->GetEntryHeight() );
138             if(m_pTabWin->GetSizePixel() != aSize)
139             {
140                 m_pTabWin->SetSizePixel(aSize);
141 
142                 OJoinTableView* pView = m_pTabWin->getTableView();
143                 OSL_ENSURE(pView,"No OJoinTableView!");
144                 for (auto& conn : pView->getTableConnections())
145                     conn->RecalcLines();
146 
147                 pView->InvalidateConnections();
148                 pView->getDesignView()->getController().setModified(true);
149                 pView->Invalidate(InvalidateFlags::NoChildren);
150             }
151         }
152         else
153         {
154             Point aPos = rEvt.GetPosPixel();
155             aPos = OutputToScreenPixel( aPos );
156             OJoinTableView* pView = m_pTabWin->getTableView();
157             OSL_ENSURE(pView,"No OJoinTableView!");
158             pView->NotifyTitleClicked( static_cast<OTableWindow*>(GetParent()), aPos );
159         }
160         GrabFocus();
161     }
162     else
163         Control::MouseButtonDown( rEvt );
164 }
165 
DataChanged(const DataChangedEvent & rDCEvt)166 void OTableWindowTitle::DataChanged(const DataChangedEvent& rDCEvt)
167 {
168     if (rDCEvt.GetType() == DataChangedEventType::SETTINGS)
169     {
170         // assume worst-case: colours have changed, therefore I have to adept
171         StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
172         SetBackground(Wallpaper(aSystemStyle.GetFaceColor()));
173         SetTextColor(aSystemStyle.GetButtonTextColor());
174     }
175 }
176 
StateChanged(StateChangedType nType)177 void OTableWindowTitle::StateChanged( StateChangedType nType )
178 {
179     Window::StateChanged( nType );
180 
181     if ( nType == StateChangedType::Zoom )
182     {
183         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
184 
185         vcl::Font aFont = rStyleSettings.GetGroupFont();
186         if ( IsControlFont() )
187             aFont.Merge( GetControlFont() );
188         SetZoomedPointFont(*this, aFont);
189 
190         Resize();
191     }
192 }
193 
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
195