LibreOffice Module sfx2 (master) 1
objface.cxx
Go to the documentation of this file.
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 <assert.h>
21#include <stdlib.h>
22
23#include <sal/log.hxx>
24
25#include <sfx2/module.hxx>
26#include <sfx2/objface.hxx>
27#include <sfx2/msg.hxx>
28#include <sfx2/app.hxx>
29#include <sfx2/msgpool.hxx>
30
31extern "C" {
32
33static int
34SfxCompareSlots_qsort( const void* pSmaller, const void* pBigger )
35{
36 return static_cast<int>(static_cast<SfxSlot const *>(pSmaller)->GetSlotId()) -
37 static_cast<int>(static_cast<SfxSlot const *>(pBigger)->GetSlotId());
38}
39
40static int
41SfxCompareSlots_bsearch( const void* pSmaller, const void* pBigger )
42{
43 return static_cast<int>(*static_cast<sal_uInt16 const *>(pSmaller)) -
44 static_cast<int>(static_cast<SfxSlot const *>(pBigger)->GetSlotId());
45}
46
47}
48
49namespace {
50
51struct SfxObjectUI_Impl
52{
53 sal_uInt16 nPos;
54 SfxVisibilityFlags nFlags;
55 sal_uInt32 nObjId;
56 bool bContext;
57 SfxShellFeature nFeature;
58
59 SfxObjectUI_Impl(sal_uInt16 n, SfxVisibilityFlags f, sal_uInt32 nId, SfxShellFeature nFeat) :
60 nPos(n),
61 nFlags(f),
62 nObjId(nId),
63 bContext(false),
64 nFeature(nFeat)
65 {
66 }
67};
68
69}
70
72{
73 std::vector<SfxObjectUI_Impl>
74 aObjectBars; // registered ObjectBars
75 std::vector<SfxObjectUI_Impl>
76 aChildWindows; // registered ChildWindows
77 OUString aPopupName; // registered PopupMenu
78 StatusBarId eStatBarResId; // registered StatusBar
79
82 {
83 }
84};
85
86static SfxObjectUI_Impl CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature);
87
88// constructor, registers a new unit
89SfxInterface::SfxInterface( const char *pClassName,
90 bool bUsableSuperClass,
92 const SfxInterface* pParent,
93 SfxSlot &rSlotMap, sal_uInt16 nSlotCount ):
94 pName(pClassName),
95 pGenoType(pParent),
96 nClassId(nId),
97 bSuperClass(bUsableSuperClass),
98 pImplData(new SfxInterface_Impl)
99{
100 SetSlotMap( rSlotMap, nSlotCount );
101}
102
104{
105 if ( pMod )
106 pMod->GetSlotPool()->RegisterInterface(*this);
107 else
109}
110
111void SfxInterface::SetSlotMap( SfxSlot& rSlotMap, sal_uInt16 nSlotCount )
112{
113 pSlots = &rSlotMap;
114 nCount = nSlotCount;
115 SfxSlot* pIter = pSlots;
116 if ( 1 == nCount && !pIter->pNextSlot )
117 pIter->pNextSlot = pIter;
118
119 if ( !pIter->pNextSlot )
120 {
121 // sort the SfxSlots by id
122 qsort( pSlots, nCount, sizeof(SfxSlot), SfxCompareSlots_qsort );
123
124 // link masters and slaves
125 sal_uInt16 nIter = 1;
126 for ( pIter = pSlots; nIter <= nCount; ++pIter, ++nIter )
127 {
128
129 assert( nIter == nCount ||
130 pIter->GetSlotId() != (pIter+1)->GetSlotId() );
131
132 if ( nullptr == pIter->GetNextSlot() )
133 {
134 // Slots referring in circle to the next with the same
135 // Status method.
136 SfxSlot *pLastSlot = pIter;
137 for ( sal_uInt16 n = nIter; n < Count(); ++n )
138 {
139 SfxSlot *pCurSlot = pSlots+n;
140 if ( pCurSlot->GetStateFnc() == pIter->GetStateFnc() )
141 {
142 pLastSlot->pNextSlot = pCurSlot;
143 pLastSlot = pCurSlot;
144 }
145 }
146 pLastSlot->pNextSlot = pIter;
147 }
148 }
149 }
150#ifdef DBG_UTIL
151 else
152 {
153 sal_uInt16 nIter = 1;
154 for ( SfxSlot *pNext = pIter+1; nIter < nCount; ++pNext, ++nIter )
155 {
156
157 if ( pNext->GetSlotId() <= pIter->GetSlotId() )
158 SAL_WARN( "sfx.control", "Wrong order" );
159
160 const SfxSlot *pCurSlot = pIter;
161 do
162 {
163 pCurSlot = pCurSlot->pNextSlot;
164 if ( pCurSlot->GetStateFnc() != pIter->GetStateFnc() )
165 {
166 SAL_WARN("sfx.control", "Linked Slots with different State Methods : "
167 << pCurSlot->GetSlotId()
168 << " , " << pIter->GetSlotId() );
169 }
170 }
171 while ( pCurSlot != pIter );
172
173 pIter = pNext;
174 }
175 }
176#endif
177}
178
179
181{
182}
183
184
185// searches for the specified func
186
187const SfxSlot* SfxInterface::GetSlot( sal_uInt16 nFuncId ) const
188{
189
190 assert( pSlots );
191 assert( nCount );
192
193 // find the id using binary search
194 void* p = bsearch( &nFuncId, pSlots, nCount, sizeof(SfxSlot),
196 if ( !p && pGenoType )
197 return pGenoType->GetSlot( nFuncId );
198
199 return static_cast<const SfxSlot*>(p);
200}
201
202const SfxSlot* SfxInterface::GetSlot( const OUString& rCommand ) const
203{
204 static const char UNO_COMMAND[] = ".uno:";
205
206 OUString aCommand( rCommand );
207 if ( aCommand.startsWith( UNO_COMMAND ) )
208 aCommand = aCommand.copy( sizeof( UNO_COMMAND )-1 );
209
210 for ( sal_uInt16 n=0; n<nCount; n++ )
211 {
212 if ( aCommand.equalsIgnoreAsciiCase( (pSlots+n)->GetUnoName() ) )
213 return pSlots+n;
214 }
215
216 return pGenoType ? pGenoType->GetSlot( aCommand ) : nullptr;
217}
218
219
220const SfxSlot* SfxInterface::GetRealSlot( const SfxSlot *pSlot ) const
221{
222
223 assert( pSlots );
224 assert( nCount );
225
226 if ( !ContainsSlot_Impl(pSlot) )
227 {
228 if(pGenoType)
229 return pGenoType->GetRealSlot(pSlot);
230 SAL_WARN( "sfx.control", "unknown Slot" );
231 return nullptr;
232 }
233
234 return nullptr;
235}
236
237
238void SfxInterface::RegisterPopupMenu( const OUString& rResourceName )
239{
240 pImplData->aPopupName = rResourceName;
241}
242
244{
246}
247
249{
250 pImplData->aObjectBars.emplace_back( CreateObjectBarUI_Impl(nPos, nFlags, eId, nFeature) );
251}
252
253SfxObjectUI_Impl CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature)
254{
255 if (nFlags == SfxVisibilityFlags::Invisible)
257
258 return SfxObjectUI_Impl(nPos, nFlags, static_cast<sal_uInt32>(eId), nFeature);
259}
260
262{
263 bool bGenoType = (pGenoType != nullptr && pGenoType->UseAsSuperClass());
264 if ( bGenoType )
265 {
266 // Are there toolbars in the super class?
267 sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount();
268 if ( nNo < nBaseCount )
269 // The Super class comes first
270 return pGenoType->GetObjectBarId(nNo);
271 else
272 nNo = nNo - nBaseCount;
273 }
274
275 assert( nNo<pImplData->aObjectBars.size() );
276
277 return static_cast<ToolbarId>(pImplData->aObjectBars[nNo].nObjId);
278}
279
280sal_uInt16 SfxInterface::GetObjectBarPos( sal_uInt16 nNo ) const
281{
282 bool bGenoType = (pGenoType != nullptr && pGenoType->UseAsSuperClass());
283 if ( bGenoType )
284 {
285 // Are there toolbars in the super class?
286 sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount();
287 if ( nNo < nBaseCount )
288 // The Super class comes first
289 return pGenoType->GetObjectBarPos( nNo );
290 else
291 nNo = nNo - nBaseCount;
292 }
293
294 assert( nNo<pImplData->aObjectBars.size() );
295
296 return pImplData->aObjectBars[nNo].nPos;
297}
298
300{
301 bool bGenoType = (pGenoType != nullptr && pGenoType->UseAsSuperClass());
302 if ( bGenoType )
303 {
304 // Are there toolbars in the super class?
305 sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount();
306 if ( nNo < nBaseCount )
307 // The Super class comes first
308 return pGenoType->GetObjectBarFlags( nNo );
309 else
310 nNo = nNo - nBaseCount;
311 }
312
313 assert( nNo<pImplData->aObjectBars.size() );
314
315 return pImplData->aObjectBars[nNo].nFlags;
316}
317
319{
321 return pImplData->aObjectBars.size() + pGenoType->GetObjectBarCount();
322 else
323 return pImplData->aObjectBars.size();
324}
325
326void SfxInterface::RegisterChildWindow(sal_uInt16 nId, bool bContext)
327{
329}
330
331void SfxInterface::RegisterChildWindow(sal_uInt16 nId, bool bContext, SfxShellFeature nFeature)
332{
333 SfxObjectUI_Impl aUI(0, SfxVisibilityFlags::Invisible, nId, nFeature);
334 aUI.bContext = bContext;
335 pImplData->aChildWindows.emplace_back(aUI);
336}
337
339{
340 pImplData->eStatBarResId = eId;
341}
342
343sal_uInt32 SfxInterface::GetChildWindowId (sal_uInt16 nNo) const
344{
345 if ( pGenoType )
346 {
347 // Are there ChildWindows in the superclass?
348 sal_uInt16 nBaseCount = pGenoType->GetChildWindowCount();
349 if ( nNo < nBaseCount )
350 // The Super class comes first
351 return pGenoType->GetChildWindowId( nNo );
352 else
353 nNo = nNo - nBaseCount;
354 }
355
356 assert( nNo<pImplData->aChildWindows.size() );
357
358 sal_uInt32 nRet = pImplData->aChildWindows[nNo].nObjId;
359 if ( pImplData->aChildWindows[nNo].bContext )
360 nRet += sal_uInt16( nClassId ) << 16;
361 return nRet;
362}
363
365{
366 if ( pGenoType )
367 {
368 // Are there ChildWindows in the superclass?
369 sal_uInt16 nBaseCount = pGenoType->GetChildWindowCount();
370 if ( nNo < nBaseCount )
371 // The Super class comes first
372 return pGenoType->GetChildWindowFeature( nNo );
373 else
374 nNo = nNo - nBaseCount;
375 }
376
377 assert( nNo<pImplData->aChildWindows.size() );
378
379 return pImplData->aChildWindows[nNo].nFeature;
380}
381
382
384{
385 if (pGenoType)
386 return pImplData->aChildWindows.size() + pGenoType->GetChildWindowCount();
387 else
388 return pImplData->aChildWindows.size();
389}
390
391const OUString& SfxInterface::GetPopupMenuName() const
392{
393 return pImplData->aPopupName;
394}
395
397{
398 if (pImplData->eStatBarResId == StatusBarId::None && pGenoType)
399 return pGenoType->GetStatusBarId();
400 else
401 return pImplData->eStatBarResId;
402}
403
405{
406 bool bGenoType = (pGenoType != nullptr && pGenoType->UseAsSuperClass());
407 if ( bGenoType )
408 {
409 // Are there toolbars in the super class?
410 sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount();
411 if ( nNo < nBaseCount )
412 // The Super class comes first
413 return pGenoType->GetObjectBarFeature( nNo );
414 else
415 nNo = nNo - nBaseCount;
416 }
417
418 assert( nNo<pImplData->aObjectBars.size() );
419
420 return pImplData->aObjectBars[nNo].nFeature;
421}
422
423bool SfxInterface::IsObjectBarVisible(sal_uInt16 nNo) const
424{
425 bool bGenoType = (pGenoType != nullptr && pGenoType->UseAsSuperClass());
426 if ( bGenoType )
427 {
428 // Are there toolbars in the super class?
429 sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount();
430 if ( nNo < nBaseCount )
431 // The Super class comes first
432 return pGenoType->IsObjectBarVisible( nNo );
433 else
434 nNo = nNo - nBaseCount;
435 }
436
437 assert( nNo<pImplData->aObjectBars.size() );
438
439 return true;
440}
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
SAL_DLLPRIVATE SfxSlotPool & GetAppSlotPool_Impl() const
Definition: appmisc.cxx:104
StatusBarId GetStatusBarId() const
Definition: objface.cxx:396
void RegisterStatusBar(StatusBarId eId)
Definition: objface.cxx:338
SfxInterfaceId nClassId
Definition: objface.hxx:63
const SfxInterface * pGenoType
Definition: objface.hxx:60
SfxSlot * pSlots
Definition: objface.hxx:61
bool IsObjectBarVisible(sal_uInt16 nNo) const
Definition: objface.cxx:423
std::unique_ptr< SfxInterface_Impl > pImplData
Definition: objface.hxx:65
sal_uInt16 nCount
Definition: objface.hxx:62
void SetSlotMap(SfxSlot &rMessages, sal_uInt16 nMsgCount)
Definition: objface.cxx:111
const SfxSlot * GetSlot(sal_uInt16 nSlotId) const
Definition: objface.cxx:187
void Register(const SfxModule *)
Definition: objface.cxx:103
sal_uInt16 GetChildWindowCount() const
Definition: objface.cxx:383
SfxShellFeature GetChildWindowFeature(sal_uInt16 nNo) const
Definition: objface.cxx:364
SAL_DLLPRIVATE bool ContainsSlot_Impl(const SfxSlot *pSlot) const
Definition: objface.hxx:107
void RegisterPopupMenu(const OUString &)
Definition: objface.cxx:238
void RegisterChildWindow(sal_uInt16, bool bContext=false)
Definition: objface.cxx:326
ToolbarId GetObjectBarId(sal_uInt16 nNo) const
Definition: objface.cxx:261
sal_uInt16 GetObjectBarCount() const
Definition: objface.cxx:318
bool UseAsSuperClass() const
Definition: objface.hxx:83
void RegisterObjectBar(sal_uInt16, SfxVisibilityFlags nFlags, ToolbarId eId)
Definition: objface.cxx:243
const OUString & GetPopupMenuName() const
Definition: objface.cxx:391
SfxVisibilityFlags GetObjectBarFlags(sal_uInt16 nNo) const
Definition: objface.cxx:299
const SfxSlot * GetRealSlot(const SfxSlot *) const
Definition: objface.cxx:220
sal_uInt16 GetObjectBarPos(sal_uInt16 nNo) const
Definition: objface.cxx:280
SfxShellFeature GetObjectBarFeature(sal_uInt16 nNo) const
Definition: objface.cxx:404
sal_uInt32 GetChildWindowId(sal_uInt16 nNo) const
Definition: objface.cxx:343
sal_uInt16 Count() const
Definition: objface.hxx:114
SfxInterface(const char *pClass, bool bSuperClass, SfxInterfaceId nClassId, const SfxInterface *pGeno, SfxSlot &rMessages, sal_uInt16 nMsgCount)
Definition: objface.cxx:89
SfxSlotPool * GetSlotPool() const
Definition: module.cxx:102
void RegisterInterface(SfxInterface &rFace)
Definition: msgpool.cxx:114
Definition: msg.hxx:184
sal_uInt16 GetSlotId() const
Definition: msg.hxx:253
const SfxSlot * pNextSlot
Definition: msg.hxx:198
const SfxSlot * GetNextSlot() const
Definition: msg.hxx:247
SfxStateFunc GetStateFnc() const
Definition: msg.hxx:245
void * p
sal_Int64 n
sal_uInt16 nPos
Definition: linksrc.cxx:118
#define SAL_WARN(area, stream)
None
static int SfxCompareSlots_qsort(const void *pSmaller, const void *pBigger)
Definition: objface.cxx:34
static SfxObjectUI_Impl CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature)
Definition: objface.cxx:253
static int SfxCompareSlots_bsearch(const void *pSmaller, const void *pBigger)
Definition: objface.cxx:41
StatusBarId
Definition: objface.hxx:45
sal_Int16 nId
SfxShellFeature
Definition: shell.hxx:74
SfxVisibilityFlags
Definition: shell.hxx:573
StatusBarId eStatBarResId
Definition: objface.cxx:78
std::vector< SfxObjectUI_Impl > aObjectBars
Definition: objface.cxx:74
OUString aPopupName
Definition: objface.cxx:77
std::vector< SfxObjectUI_Impl > aChildWindows
Definition: objface.cxx:76
ToolbarId
Definition: toolbarids.hxx:18
OUString aCommand