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 #ifndef INCLUDED_SFX2_STBITEM_HXX
20 #define INCLUDED_SFX2_STBITEM_HXX
21 
22 #include <sal/config.h>
23 #include <sfx2/dllapi.h>
24 #include <svl/poolitem.hxx>
25 #include <svtools/statusbarcontroller.hxx>
26 #include <vcl/status.hxx>
27 
28 
29 class SfxModule;
30 class SfxStatusBarControl;
31 
32 svt::StatusbarController* SfxStatusBarControllerFactory(
33     const css::uno::Reference< css::frame::XFrame >& rFrame,
34     StatusBar* pStatusBar,
35     unsigned short nID,
36     const OUString& aCommandURL );
37 typedef SfxStatusBarControl* (*SfxStatusBarControlCtor)( sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb );
38 
39 struct SfxStbCtrlFactory
40 {
41     SfxStatusBarControlCtor const pCtor;
42     const std::type_info&   nTypeId;
43     sal_uInt16 const        nSlotId;
44 
SfxStbCtrlFactorySfxStbCtrlFactory45     SfxStbCtrlFactory( SfxStatusBarControlCtor pTheCtor,
46             const std::type_info& nTheTypeId, sal_uInt16 nTheSlotId ):
47         pCtor(pTheCtor),
48         nTypeId(nTheTypeId),
49         nSlotId(nTheSlotId)
50     {}
51 };
52 
53 
54 class CommandEvent;
55 class MouseEvent;
56 class UserDrawEvent;
57 
58 class SFX2_DLLPUBLIC SfxStatusBarControl: public svt::StatusbarController
59 {
60     sal_uInt16 const   nSlotId;
61     sal_uInt16 const   nId;
62     VclPtr<StatusBar>  pBar;
63 
64 protected:
65     // new controller API
66     // XInterface
67     virtual void               SAL_CALL acquire() throw() override;
68     virtual void               SAL_CALL release() throw() override;
69 
70     // XEventListener
71     using svt::StatusbarController::disposing;
72 
73     // XComponent
74     using svt::StatusbarController::dispose;
75 
76     // XStatusListener
77     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
78 
79     // XStatusbarController
80     virtual sal_Bool SAL_CALL mouseButtonDown( const css::awt::MouseEvent& aMouseEvent ) override;
81     virtual sal_Bool SAL_CALL mouseMove( const css::awt::MouseEvent& aMouseEvent ) override;
82     virtual sal_Bool SAL_CALL mouseButtonUp( const css::awt::MouseEvent& aMouseEvent ) override;
83     virtual void SAL_CALL command( const css::awt::Point& aPos,
84                                     ::sal_Int32 nCommand,
85                                     sal_Bool bMouseEvent,
86                                     const css::uno::Any& aData ) override;
87     virtual void SAL_CALL paint( const css::uno::Reference< css::awt::XGraphics >& xGraphics,
88                                  const css::awt::Rectangle& rOutputRectangle,
89                                  ::sal_Int32 nStyle ) override;
90     virtual void SAL_CALL click( const css::awt::Point& aPos ) override;
91     virtual void SAL_CALL doubleClick( const css::awt::Point& aPos ) override;
92 
93     // Old sfx2 interface
94     virtual void    StateChanged( sal_uInt16 nSID, SfxItemState eState,
95                                   const SfxPoolItem* pState );
96     virtual void    Click();
97     virtual void    Command( const CommandEvent& rCEvt );
98     virtual bool    MouseButtonDown( const MouseEvent & );
99     virtual bool    MouseMove( const MouseEvent & );
100     virtual bool    MouseButtonUp( const MouseEvent & );
101     virtual void    Paint( const UserDrawEvent &rUDEvt );
102 
103     static sal_uInt16   convertAwtToVCLMouseButtons( sal_Int16 nAwtMouseButtons );
104 
105 public:
106                     SfxStatusBarControl( sal_uInt16 nSlotID, sal_uInt16 nId, StatusBar& rBar );
107     virtual         ~SfxStatusBarControl() override;
108 
GetSlotId() const109     sal_uInt16      GetSlotId() const { return nSlotId; }
GetId() const110     sal_uInt16      GetId() const { return nId; }
GetStatusBar() const111     StatusBar&      GetStatusBar() const { return *pBar; }
112 
113     static SfxStatusBarControl* CreateControl( sal_uInt16 nSlotID, sal_uInt16 nId, StatusBar *pBar, SfxModule const * );
114     static void RegisterStatusBarControl(SfxModule*, const SfxStbCtrlFactory&);
115 
116 };
117 
118 
119 #define SFX_DECL_STATUSBAR_CONTROL() \
120         static SfxStatusBarControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb ); \
121         static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=nullptr)
122 
123 #define SFX_IMPL_STATUSBAR_CONTROL(Class, nItemClass) \
124         SfxStatusBarControl* Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb ) \
125                { return new Class( nSlotId, nId, rStb ); } \
126         void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
127                { SfxStatusBarControl::RegisterStatusBarControl( pMod, SfxStbCtrlFactory( \
128                     Class::CreateImpl, typeid(nItemClass), nSlotId ) ); }
129 
130 
131 #endif
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
134