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 #ifndef LAYOUT_VCL_WRAPPER_HXX
25 #define LAYOUT_VCL_WRAPPER_HXX
26
27 #include <layout/layout.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/awt/XDialog2.hpp>
30 #include <com/sun/star/awt/XFocusListener.hpp>
31 #include <com/sun/star/awt/XWindow.hpp>
32 #include <com/sun/star/awt/XVclWindowPeer.hpp>
33 #include <cppuhelper/implbase1.hxx>
34
35 #include <cstring>
36
37 namespace layout
38 {
39
40 namespace css = com::sun::star;
41
42 class WindowImpl
43 {
44 public:
45 Window *mpWindow;
46 Context *mpCtx;
47 css::uno::Reference< css::awt::XWindow > mxWindow;
48 css::uno::Reference< css::awt::XVclWindowPeer > mxVclPeer;
49 ::Window *mvclWindow;
50 bool bFirstTimeVisible;
51
52 WindowImpl (Context *context, PeerHandle const &peer, Window *window);
53 virtual ~WindowImpl ();
54
55 void wrapperGone();
56 css::uno::Any getProperty (char const *name);
57 void setProperty (char const *name, css::uno::Any any);
58 void redraw (bool resize=false);
59
60 // XFocusListener
61 virtual void SAL_CALL disposing (css::lang::EventObject const&) throw (css::uno::RuntimeException);
62 };
63
64 class ControlImpl : public WindowImpl
65 , public ::cppu::WeakImplHelper1 <css::awt::XFocusListener>
66 {
67 public:
68 Link mGetFocusHdl;
69 Link mLoseFocusHdl;
70
71 ControlImpl( Context *context, PeerHandle const& peer, Window *window );
72 ~ControlImpl ();
73
74 virtual void SetGetFocusHdl (Link const& link);
75 Link& GetGetFocusHdl ();
76 virtual void SetLoseFocusHdl (Link const& link);
77 Link& GetLoseFocusHdl ();
78 virtual void UpdateListening (Link const& link);
79
80 // XFocusListener
81 virtual void SAL_CALL disposing (css::lang::EventObject const&) throw (css::uno::RuntimeException);
82 void SAL_CALL focusGained (css::awt::FocusEvent const& e) throw (css::uno::RuntimeException);
83 void SAL_CALL focusLost (css::awt::FocusEvent const& e) throw (css::uno::RuntimeException);
84 };
85
getImpl() const86 inline WindowImpl *Window::getImpl() const{ return (static_cast< WindowImpl * >( mpImpl )); }
87
88 // Helpers for defining boiler-plate constructors ...
89 // Could in-line in top-level but not with safe static_casts.
90 #define IMPL_GET_IMPL(t) \
91 inline t##Impl* t::getImpl() const \
92 { \
93 return (static_cast<t##Impl *>(mpImpl)); \
94 }
95 #define IMPL_CONSTRUCTORS_BODY(t,par,unoName,body) \
96 t::t( Context *context, const char *pId, sal_uInt32 nId ) \
97 : par( new t##Impl( context, context->GetPeerHandle( pId, nId ), this ) ) \
98 { \
99 Window *parent = dynamic_cast<Window*> (context);\
100 body;\
101 if (parent)\
102 SetParent (parent);\
103 } \
104 t::t( Window *parent, WinBits bits) \
105 : par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, bits, unoName ), this ) ) \
106 { \
107 body;\
108 if ( parent )\
109 SetParent (parent);\
110 } \
111 t::t( Window *parent, ResId const& res) \
112 : par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, 0, unoName ), this ) ) \
113 { \
114 body;\
115 setRes (res);\
116 if (parent)\
117 SetParent (parent);\
118 }
119 #define IMPL_CONSTRUCTORS(t,par,unoName) IMPL_CONSTRUCTORS_BODY(t, par, unoName, )
120 #define IMPL_CONSTRUCTORS_2(t,win_par,other_par,unoName) \
121 t::t( Context *context, const char *pId, sal_uInt32 nId ) \
122 : win_par( new t##Impl( context, context->GetPeerHandle( pId, nId ), this ) ) \
123 , other_par( new other_par##Impl( Window::GetPeer() ) ) \
124 { \
125 } \
126 t::t( Window *parent, WinBits bits) \
127 : win_par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, bits, unoName ), this ) ) \
128 , other_par( new other_par##Impl( Window::GetPeer() ) ) \
129 { \
130 }
131
132 #define IMPL_IMPL(t, parent) \
133 class t##Impl : public parent##Impl \
134 { \
135 public: \
136 t##Impl( Context *context, PeerHandle const& peer, Window *window ) \
137 : parent##Impl( context, peer, window ) \
138 { \
139 } \
140 };
141
142
143 } // namespace layout
144
145 #endif /* LAYOUT_VCL_WRAPPER_HXX */
146