Line data Source code
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 :
21 : #include <sal/macros.h>
22 : #include "fmitems.hxx"
23 : #include "fmobj.hxx"
24 : #include "fmpgeimp.hxx"
25 : #include "svx/fmtools.hxx"
26 : #include "fmprop.hrc"
27 : #include "svx/fmresids.hrc"
28 : #include "fmservs.hxx"
29 : #include "fmshimp.hxx"
30 : #include "fmtextcontrolshell.hxx"
31 : #include "fmundo.hxx"
32 : #include "fmurl.hxx"
33 : #include "fmvwimp.hxx"
34 : #include "formtoolbars.hxx"
35 : #include "gridcols.hxx"
36 : #include "svx/svditer.hxx"
37 : #include "svx/dialmgr.hxx"
38 : #include "svx/dialogs.hrc"
39 : #include "svx/fmglob.hxx"
40 : #include "svx/fmmodel.hxx"
41 : #include "svx/fmpage.hxx"
42 : #include "svx/fmshell.hxx"
43 : #include "svx/obj3d.hxx"
44 : #include "svx/sdrpagewindow.hxx"
45 : #include "svx/svdpagv.hxx"
46 : #include "svx/svxdlg.hxx"
47 : #include "svx/svxids.hrc"
48 :
49 : #include <com/sun/star/awt/XWindow2.hpp>
50 : #include <com/sun/star/awt/XCheckBox.hpp>
51 : #include <com/sun/star/awt/XListBox.hpp>
52 : #include <com/sun/star/awt/XTextComponent.hpp>
53 : #include <com/sun/star/beans/Introspection.hpp>
54 : #include <com/sun/star/beans/NamedValue.hpp>
55 : #include <com/sun/star/beans/PropertyAttribute.hpp>
56 : #include <com/sun/star/beans/XPropertyState.hpp>
57 : #include <com/sun/star/container/XContainer.hpp>
58 : #include <com/sun/star/container/XEnumeration.hpp>
59 : #include <com/sun/star/container/XEnumerationAccess.hpp>
60 : #include <com/sun/star/container/XIndexAccess.hpp>
61 : #include <com/sun/star/container/XNamed.hpp>
62 : #include <com/sun/star/form/ListSourceType.hpp>
63 : #include <com/sun/star/form/XBoundComponent.hpp>
64 : #include <com/sun/star/form/XBoundControl.hpp>
65 : #include <com/sun/star/form/XGrid.hpp>
66 : #include <com/sun/star/form/XGridPeer.hpp>
67 : #include <com/sun/star/form/XLoadable.hpp>
68 : #include <com/sun/star/form/XReset.hpp>
69 : #include <com/sun/star/form/binding/XBindableValue.hpp>
70 : #include <com/sun/star/form/binding/XListEntrySink.hpp>
71 : #include <com/sun/star/frame/FrameSearchFlag.hpp>
72 : #include <com/sun/star/script/XEventAttacherManager.hpp>
73 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
74 : #include <com/sun/star/util/XCancellable.hpp>
75 : #include <com/sun/star/util/XModeSelector.hpp>
76 : #include <com/sun/star/util/XModifyBroadcaster.hpp>
77 : #include <com/sun/star/util/XNumberFormatter.hpp>
78 : #include <com/sun/star/view/XSelectionSupplier.hpp>
79 :
80 : #include <comphelper/extract.hxx>
81 : #include <comphelper/evtmethodhelper.hxx>
82 : #include <comphelper/processfactory.hxx>
83 : #include <comphelper/property.hxx>
84 : #include <comphelper/stl_types.hxx>
85 : #include <comphelper/string.hxx>
86 : #include <connectivity/dbtools.hxx>
87 : #include <osl/mutex.hxx>
88 : #include <rtl/logfile.hxx>
89 : #include <sfx2/dispatch.hxx>
90 : #include <sfx2/docfile.hxx>
91 : #include <sfx2/frame.hxx>
92 : #include <sfx2/objsh.hxx>
93 : #include <sfx2/viewfrm.hxx>
94 : #include <sfx2/viewsh.hxx>
95 : #include <toolkit/helper/vclunohelper.hxx>
96 : #include <tools/diagnose_ex.h>
97 : #include <tools/shl.hxx>
98 : #include <vcl/msgbox.hxx>
99 : #include <vcl/waitobj.hxx>
100 :
101 : #include <algorithm>
102 : #include <functional>
103 : #include <vector>
104 :
105 : // wird fuer Invalidate verwendet -> mitpflegen
106 : static sal_uInt16 DatabaseSlotMap[] =
107 : {
108 : SID_FM_RECORD_FIRST,
109 : SID_FM_RECORD_NEXT,
110 : SID_FM_RECORD_PREV,
111 : SID_FM_RECORD_LAST,
112 : SID_FM_RECORD_NEW,
113 : SID_FM_RECORD_DELETE,
114 : SID_FM_RECORD_ABSOLUTE,
115 : SID_FM_RECORD_TOTAL,
116 : SID_FM_RECORD_SAVE,
117 : SID_FM_RECORD_UNDO,
118 : SID_FM_REMOVE_FILTER_SORT,
119 : SID_FM_SORTUP,
120 : SID_FM_SORTDOWN,
121 : SID_FM_ORDERCRIT,
122 : SID_FM_AUTOFILTER,
123 : SID_FM_FORM_FILTERED,
124 : SID_FM_REFRESH,
125 : SID_FM_REFRESH_FORM_CONTROL,
126 : SID_FM_SEARCH,
127 : SID_FM_FILTER_START,
128 : SID_FM_VIEW_AS_GRID,
129 : 0
130 : };
131 :
132 : // wird fuer Invalidate verwendet -> mitpflegen
133 : // aufsteigend sortieren !!!!!!
134 : static sal_Int16 DlgSlotMap[] = // slots des Controllers
135 : {
136 : SID_FM_CTL_PROPERTIES,
137 : SID_FM_PROPERTIES,
138 : SID_FM_TAB_DIALOG,
139 : SID_FM_ADD_FIELD,
140 : SID_FM_SHOW_FMEXPLORER,
141 : SID_FM_FIELDS_CONTROL,
142 : SID_FM_SHOW_PROPERTIES,
143 : SID_FM_PROPERTY_CONTROL,
144 : SID_FM_FMEXPLORER_CONTROL,
145 : SID_FM_SHOW_DATANAVIGATOR,
146 : SID_FM_DATANAVIGATOR_CONTROL,
147 : 0
148 : };
149 :
150 : static sal_Int16 SelObjectSlotMap[] = // vom SelObject abhaengige Slots
151 : {
152 : SID_FM_CONVERTTO_EDIT,
153 : SID_FM_CONVERTTO_BUTTON,
154 : SID_FM_CONVERTTO_FIXEDTEXT,
155 : SID_FM_CONVERTTO_LISTBOX,
156 : SID_FM_CONVERTTO_CHECKBOX,
157 : SID_FM_CONVERTTO_RADIOBUTTON,
158 : SID_FM_CONVERTTO_GROUPBOX,
159 : SID_FM_CONVERTTO_COMBOBOX,
160 : SID_FM_CONVERTTO_IMAGEBUTTON,
161 : SID_FM_CONVERTTO_FILECONTROL,
162 : SID_FM_CONVERTTO_DATE,
163 : SID_FM_CONVERTTO_TIME,
164 : SID_FM_CONVERTTO_NUMERIC,
165 : SID_FM_CONVERTTO_CURRENCY,
166 : SID_FM_CONVERTTO_PATTERN,
167 : SID_FM_CONVERTTO_IMAGECONTROL,
168 : SID_FM_CONVERTTO_FORMATTED,
169 : SID_FM_CONVERTTO_SCROLLBAR,
170 : SID_FM_CONVERTTO_SPINBUTTON,
171 : SID_FM_CONVERTTO_NAVIGATIONBAR,
172 :
173 : SID_FM_FMEXPLORER_CONTROL,
174 : SID_FM_DATANAVIGATOR_CONTROL,
175 :
176 : 0
177 : };
178 :
179 : // die folgenden Arrays muessen kosistent sein, also einander entsprechende Eintraege an der selben relativen Position
180 : // innerhalb ihres jeweiligen Arrays stehen
181 : static sal_Int16 nConvertSlots[] =
182 : {
183 : SID_FM_CONVERTTO_EDIT,
184 : SID_FM_CONVERTTO_BUTTON,
185 : SID_FM_CONVERTTO_FIXEDTEXT,
186 : SID_FM_CONVERTTO_LISTBOX,
187 : SID_FM_CONVERTTO_CHECKBOX,
188 : SID_FM_CONVERTTO_RADIOBUTTON,
189 : SID_FM_CONVERTTO_GROUPBOX,
190 : SID_FM_CONVERTTO_COMBOBOX,
191 : SID_FM_CONVERTTO_IMAGEBUTTON,
192 : SID_FM_CONVERTTO_FILECONTROL,
193 : SID_FM_CONVERTTO_DATE,
194 : SID_FM_CONVERTTO_TIME,
195 : SID_FM_CONVERTTO_NUMERIC,
196 : SID_FM_CONVERTTO_CURRENCY,
197 : SID_FM_CONVERTTO_PATTERN,
198 : SID_FM_CONVERTTO_IMAGECONTROL,
199 : SID_FM_CONVERTTO_FORMATTED,
200 : SID_FM_CONVERTTO_SCROLLBAR,
201 : SID_FM_CONVERTTO_SPINBUTTON,
202 : SID_FM_CONVERTTO_NAVIGATIONBAR
203 : };
204 :
205 : static sal_Int16 nCreateSlots[] =
206 : {
207 : SID_FM_EDIT,
208 : SID_FM_PUSHBUTTON,
209 : SID_FM_FIXEDTEXT,
210 : SID_FM_LISTBOX,
211 : SID_FM_CHECKBOX,
212 : SID_FM_RADIOBUTTON,
213 : SID_FM_GROUPBOX,
214 : SID_FM_COMBOBOX,
215 : SID_FM_IMAGEBUTTON,
216 : SID_FM_FILECONTROL,
217 : SID_FM_DATEFIELD,
218 : SID_FM_TIMEFIELD,
219 : SID_FM_NUMERICFIELD,
220 : SID_FM_CURRENCYFIELD,
221 : SID_FM_PATTERNFIELD,
222 : SID_FM_IMAGECONTROL,
223 : SID_FM_FORMATTEDFIELD,
224 : SID_FM_SCROLLBAR,
225 : SID_FM_SPINBUTTON,
226 : SID_FM_NAVIGATIONBAR
227 : };
228 :
229 : static sal_Int16 nObjectTypes[] =
230 : {
231 : OBJ_FM_EDIT,
232 : OBJ_FM_BUTTON,
233 : OBJ_FM_FIXEDTEXT,
234 : OBJ_FM_LISTBOX,
235 : OBJ_FM_CHECKBOX,
236 : OBJ_FM_RADIOBUTTON,
237 : OBJ_FM_GROUPBOX,
238 : OBJ_FM_COMBOBOX,
239 : OBJ_FM_IMAGEBUTTON,
240 : OBJ_FM_FILECONTROL,
241 : OBJ_FM_DATEFIELD,
242 : OBJ_FM_TIMEFIELD,
243 : OBJ_FM_NUMERICFIELD,
244 : OBJ_FM_CURRENCYFIELD,
245 : OBJ_FM_PATTERNFIELD,
246 : OBJ_FM_IMAGECONTROL,
247 : OBJ_FM_FORMATTEDFIELD,
248 : OBJ_FM_SCROLLBAR,
249 : OBJ_FM_SPINBUTTON,
250 : OBJ_FM_NAVIGATIONBAR
251 : };
252 :
253 : using namespace ::com::sun::star;
254 : using namespace ::com::sun::star::ui;
255 : using namespace ::com::sun::star::uno;
256 : using namespace ::com::sun::star::sdb;
257 : using namespace ::com::sun::star::sdbc;
258 : using namespace ::com::sun::star::sdbcx;
259 : using namespace ::com::sun::star::beans;
260 : using namespace ::com::sun::star::container;
261 : using namespace ::com::sun::star::form;
262 : using namespace ::com::sun::star::form::binding;
263 : using namespace ::com::sun::star::form::runtime;
264 : using namespace ::com::sun::star::awt;
265 : using namespace ::com::sun::star::view;
266 : using namespace ::com::sun::star::lang;
267 : using namespace ::com::sun::star::util;
268 : using namespace ::com::sun::star::frame;
269 : using namespace ::com::sun::star::script;
270 : using namespace ::svxform;
271 : using namespace ::svx;
272 :
273 : //==============================================================================
274 : //= helper
275 : //==============================================================================
276 : namespace
277 : {
278 : //..........................................................................
279 0 : void collectInterfacesFromMarkList( const SdrMarkList& _rMarkList, InterfaceBag& /* [out] */ _rInterfaces )
280 : {
281 0 : _rInterfaces.clear();
282 :
283 0 : sal_uInt32 nMarkCount = _rMarkList.GetMarkCount();
284 0 : for ( sal_uInt32 i = 0; i < nMarkCount; ++i)
285 : {
286 0 : SdrObject* pCurrent = _rMarkList.GetMark( i )->GetMarkedSdrObj();
287 :
288 0 : SdrObjListIter* pGroupIterator = NULL;
289 0 : if ( pCurrent->IsGroupObject() )
290 : {
291 0 : pGroupIterator = new SdrObjListIter( *pCurrent->GetSubList() );
292 0 : pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
293 : }
294 :
295 0 : while ( pCurrent )
296 : {
297 0 : FmFormObj* pAsFormObject = FmFormObj::GetFormObject( pCurrent );
298 : // note this will de-reference virtual objects, if necessary/possible
299 0 : if ( pAsFormObject )
300 : {
301 0 : Reference< XInterface > xControlModel( pAsFormObject->GetUnoControlModel(), UNO_QUERY );
302 : // the UNO_QUERY is important for normalization
303 0 : if ( xControlModel.is() )
304 0 : _rInterfaces.insert( xControlModel );
305 : }
306 :
307 : // next element
308 0 : pCurrent = pGroupIterator && pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
309 : }
310 :
311 0 : if ( pGroupIterator )
312 0 : delete pGroupIterator;
313 : }
314 0 : }
315 :
316 : //..........................................................................
317 0 : sal_Int16 GridView2ModelPos(const Reference< XIndexAccess>& rColumns, sal_Int16 nViewPos)
318 : {
319 : try
320 : {
321 0 : if (rColumns.is())
322 : {
323 : // loop through all columns
324 : sal_Int16 i;
325 0 : Reference< XPropertySet> xCur;
326 0 : for (i=0; i<rColumns->getCount(); ++i)
327 : {
328 0 : rColumns->getByIndex(i) >>= xCur;
329 0 : if (!::comphelper::getBOOL(xCur->getPropertyValue(FM_PROP_HIDDEN)))
330 : {
331 : // for every visible col : if nViewPos is greater zero, decrement it, else we
332 : // have found the model position
333 0 : if (!nViewPos)
334 0 : break;
335 : else
336 0 : --nViewPos;
337 : }
338 : }
339 0 : if (i<rColumns->getCount())
340 0 : return i;
341 : }
342 : }
343 0 : catch(const Exception&)
344 : {
345 : DBG_UNHANDLED_EXCEPTION();
346 : }
347 0 : return (sal_Int16)-1;
348 : }
349 :
350 : //..........................................................................
351 0 : void TransferEventScripts(const Reference< XControlModel>& xModel, const Reference< XControl>& xControl,
352 : const Sequence< ScriptEventDescriptor>& rTransferIfAvailable)
353 : {
354 : // first check if we have a XEventAttacherManager for the model
355 0 : Reference< XChild> xModelChild(xModel, UNO_QUERY);
356 0 : if (!xModelChild.is())
357 : return; // nothing to do
358 :
359 0 : Reference< XEventAttacherManager> xEventManager(xModelChild->getParent(), UNO_QUERY);
360 0 : if (!xEventManager.is())
361 : return; // nothing to do
362 :
363 0 : if (!rTransferIfAvailable.getLength())
364 : return; // nothing to do
365 :
366 : // check for the index of the model within it's parent
367 0 : Reference< XIndexAccess> xParentIndex(xModelChild->getParent(), UNO_QUERY);
368 0 : if (!xParentIndex.is())
369 : return; // nothing to do
370 0 : sal_Int32 nIndex = getElementPos(xParentIndex, xModel);
371 0 : if (nIndex<0 || nIndex>=xParentIndex->getCount())
372 : return; // nothing to do
373 :
374 : // then we need informations about the listeners supported by the control and the model
375 0 : Sequence< Type> aModelListeners;
376 0 : Sequence< Type> aControlListeners;
377 :
378 0 : Reference< XIntrospection> xModelIntrospection = Introspection::create(::comphelper::getProcessComponentContext());
379 0 : Reference< XIntrospection> xControlIntrospection = Introspection::create(::comphelper::getProcessComponentContext());
380 :
381 0 : if (xModel.is())
382 : {
383 0 : Any aModel(makeAny(xModel));
384 0 : aModelListeners = xModelIntrospection->inspect(aModel)->getSupportedListeners();
385 : }
386 :
387 0 : if (xControl.is())
388 : {
389 0 : Any aControl(makeAny(xControl));
390 0 : aControlListeners = xControlIntrospection->inspect(aControl)->getSupportedListeners();
391 : }
392 :
393 0 : sal_Int32 nMaxNewLen = aModelListeners.getLength() + aControlListeners.getLength();
394 0 : if (!nMaxNewLen)
395 : return; // the model and the listener don't support any listeners (or we were unable to retrieve these infos)
396 :
397 0 : Sequence< ScriptEventDescriptor> aTransferable(nMaxNewLen);
398 0 : ScriptEventDescriptor* pTransferable = aTransferable.getArray();
399 :
400 0 : const ScriptEventDescriptor* pCurrent = rTransferIfAvailable.getConstArray();
401 : sal_Int32 i,j,k;
402 0 : for (i=0; i<rTransferIfAvailable.getLength(); ++i, ++pCurrent)
403 : {
404 : // search the model/control idl classes for the event described by pCurrent
405 0 : for ( Sequence< Type>* pCurrentArray = &aModelListeners;
406 : pCurrentArray;
407 : pCurrentArray = (pCurrentArray == &aModelListeners) ? &aControlListeners : NULL
408 : )
409 : {
410 0 : const Type* pCurrentListeners = pCurrentArray->getConstArray();
411 0 : for (j=0; j<pCurrentArray->getLength(); ++j, ++pCurrentListeners)
412 : {
413 0 : rtl::OUString aListener = (*pCurrentListeners).getTypeName();
414 0 : sal_Int32 nTokens = comphelper::string::getTokenCount(aListener, '.');
415 0 : if (nTokens)
416 0 : aListener = comphelper::string::getToken(aListener, nTokens - 1, '.');
417 :
418 0 : if (aListener == pCurrent->ListenerType.getStr())
419 : // the current ScriptEventDescriptor doesn't match the current listeners class
420 0 : continue;
421 :
422 : // now check the methods
423 0 : Sequence< ::rtl::OUString> aMethodsNames = ::comphelper::getEventMethodsForType(*pCurrentListeners);
424 :
425 0 : const ::rtl::OUString* pMethodsNames = aMethodsNames.getConstArray();
426 0 : for (k=0; k<aMethodsNames.getLength(); ++k, ++pMethodsNames)
427 : {
428 0 : if ((*pMethodsNames).compareTo(pCurrent->EventMethod) != COMPARE_EQUAL)
429 : // the current ScriptEventDescriptor doesn't match the current listeners current method
430 0 : continue;
431 :
432 : // we can transfer the script event : the model (control) supports it
433 0 : *pTransferable = *pCurrent;
434 0 : ++pTransferable;
435 0 : break;
436 : }
437 0 : if (k<aMethodsNames.getLength())
438 : break;
439 0 : }
440 : }
441 : }
442 :
443 0 : sal_Int32 nRealNewLen = pTransferable - aTransferable.getArray();
444 0 : aTransferable.realloc(nRealNewLen);
445 :
446 0 : xEventManager->registerScriptEvents(nIndex, aTransferable);
447 : }
448 :
449 : //------------------------------------------------------------------------------
450 0 : ::rtl::OUString getServiceNameByControlType(sal_Int16 nType)
451 : {
452 0 : switch (nType)
453 : {
454 0 : case OBJ_FM_EDIT : return FM_COMPONENT_TEXTFIELD;
455 0 : case OBJ_FM_BUTTON : return FM_COMPONENT_COMMANDBUTTON;
456 0 : case OBJ_FM_FIXEDTEXT : return FM_COMPONENT_FIXEDTEXT;
457 0 : case OBJ_FM_LISTBOX : return FM_COMPONENT_LISTBOX;
458 0 : case OBJ_FM_CHECKBOX : return FM_COMPONENT_CHECKBOX;
459 0 : case OBJ_FM_RADIOBUTTON : return FM_COMPONENT_RADIOBUTTON;
460 0 : case OBJ_FM_GROUPBOX : return FM_COMPONENT_GROUPBOX;
461 0 : case OBJ_FM_COMBOBOX : return FM_COMPONENT_COMBOBOX;
462 0 : case OBJ_FM_GRID : return FM_COMPONENT_GRIDCONTROL;
463 0 : case OBJ_FM_IMAGEBUTTON : return FM_COMPONENT_IMAGEBUTTON;
464 0 : case OBJ_FM_FILECONTROL : return FM_COMPONENT_FILECONTROL;
465 0 : case OBJ_FM_DATEFIELD : return FM_COMPONENT_DATEFIELD;
466 0 : case OBJ_FM_TIMEFIELD : return FM_COMPONENT_TIMEFIELD;
467 0 : case OBJ_FM_NUMERICFIELD : return FM_COMPONENT_NUMERICFIELD;
468 0 : case OBJ_FM_CURRENCYFIELD : return FM_COMPONENT_CURRENCYFIELD;
469 0 : case OBJ_FM_PATTERNFIELD : return FM_COMPONENT_PATTERNFIELD;
470 0 : case OBJ_FM_HIDDEN : return FM_COMPONENT_HIDDENCONTROL;
471 0 : case OBJ_FM_IMAGECONTROL : return FM_COMPONENT_IMAGECONTROL;
472 0 : case OBJ_FM_FORMATTEDFIELD : return FM_COMPONENT_FORMATTEDFIELD;
473 0 : case OBJ_FM_SCROLLBAR : return FM_SUN_COMPONENT_SCROLLBAR;
474 0 : case OBJ_FM_SPINBUTTON : return FM_SUN_COMPONENT_SPINBUTTON;
475 0 : case OBJ_FM_NAVIGATIONBAR : return FM_SUN_COMPONENT_NAVIGATIONBAR;
476 : }
477 0 : return ::rtl::OUString();
478 : }
479 :
480 : }
481 :
482 : //------------------------------------------------------------------------------
483 : // check if the control has one of the interfaces we can use for searching
484 : // *_pCurrentText will be filled with the current text of the control (as used when searching this control)
485 0 : sal_Bool IsSearchableControl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxControl,
486 : ::rtl::OUString* _pCurrentText )
487 : {
488 0 : if ( !_rxControl.is() )
489 0 : return sal_False;
490 :
491 0 : Reference< XTextComponent > xAsText( _rxControl, UNO_QUERY );
492 0 : if ( xAsText.is() )
493 : {
494 0 : if ( _pCurrentText )
495 0 : *_pCurrentText = xAsText->getText();
496 0 : return sal_True;
497 : }
498 :
499 0 : Reference< XListBox > xListBox( _rxControl, UNO_QUERY );
500 0 : if ( xListBox.is() )
501 : {
502 0 : if ( _pCurrentText )
503 0 : *_pCurrentText = xListBox->getSelectedItem();
504 0 : return sal_True;
505 : }
506 :
507 0 : Reference< XCheckBox > xCheckBox( _rxControl, UNO_QUERY );
508 0 : if ( xCheckBox.is() )
509 : {
510 0 : if ( _pCurrentText )
511 : {
512 0 : switch ( (::TriState)xCheckBox->getState() )
513 : {
514 0 : case STATE_NOCHECK: *_pCurrentText = ::rtl::OUString("0" ); break;
515 0 : case STATE_CHECK: *_pCurrentText = ::rtl::OUString("1" ); break;
516 0 : default: *_pCurrentText = ::rtl::OUString(); break;
517 : }
518 : }
519 0 : return sal_True;
520 : }
521 :
522 0 : return sal_False;
523 : }
524 :
525 : //------------------------------------------------------------------------------
526 0 : sal_Bool FmXBoundFormFieldIterator::ShouldStepInto(const Reference< XInterface>& _rContainer) const
527 : {
528 0 : if (_rContainer == m_xStartingPoint)
529 : // would be quite stupid to step over the root ....
530 0 : return sal_True;
531 :
532 0 : return Reference< XControlModel>(_rContainer, UNO_QUERY).is();
533 : }
534 :
535 : //------------------------------------------------------------------------------
536 0 : sal_Bool FmXBoundFormFieldIterator::ShouldHandleElement(const Reference< XInterface>& _rElement)
537 : {
538 0 : if (!_rElement.is())
539 : // NULL element
540 0 : return sal_False;
541 :
542 0 : if (Reference< XForm>(_rElement, UNO_QUERY).is() || Reference< XGrid>(_rElement, UNO_QUERY).is())
543 : // a forms or a grid
544 0 : return sal_False;
545 :
546 0 : Reference< XPropertySet> xSet(_rElement, UNO_QUERY);
547 0 : if (!xSet.is() || !::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xSet))
548 : // no "BoundField" property
549 0 : return sal_False;
550 :
551 0 : Any aVal( xSet->getPropertyValue(FM_PROP_BOUNDFIELD) );
552 0 : if (aVal.getValueTypeClass() != TypeClass_INTERFACE)
553 : // void or invalid property value
554 0 : return sal_False;
555 :
556 0 : return aVal.hasValue();
557 : }
558 :
559 : //------------------------------------------------------------------------------
560 0 : sal_Bool isControlList(const SdrMarkList& rMarkList)
561 : {
562 : // enthaelt die liste nur Controls und mindestens ein control
563 0 : sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
564 0 : sal_Bool bControlList = nMarkCount != 0;
565 :
566 0 : sal_Bool bHadAnyLeafs = sal_False;
567 :
568 0 : for (sal_uInt32 i = 0; i < nMarkCount && bControlList; i++)
569 : {
570 0 : SdrObject *pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
571 0 : E3dObject* pAs3DObject = PTR_CAST(E3dObject, pObj);
572 : // E3dObject's do not contain any 2D-objects (by definition)
573 : // we need this extra check here : an E3dObject->IsGroupObject says "YES", but an SdrObjListIter working
574 : // with an E3dObject doesn't give me any Nodes (E3dObject has a sub list, but no members in that list,
575 : // cause there implementation differs from the one of "normal" SdrObject's. Unfortunally SdrObject::IsGroupObject
576 : // doesn't check the element count of the sub list, which is simply a bug in IsGroupObject we can't fix at the moment).
577 : // So at the end of this function bControlList would have the same value it was initialized with above : sal_True
578 : // And this would be wrong :)
579 : // 03.02.00 - 72529 - FS
580 0 : if (!pAs3DObject)
581 : {
582 0 : if (pObj->IsGroupObject())
583 : {
584 0 : SdrObjListIter aIter(*pObj->GetSubList());
585 0 : while (aIter.IsMore() && bControlList)
586 : {
587 0 : bControlList = FmFormInventor == aIter.Next()->GetObjInventor();
588 0 : bHadAnyLeafs = sal_True;
589 0 : }
590 : }
591 : else
592 : {
593 0 : bHadAnyLeafs = sal_True;
594 0 : bControlList = FmFormInventor == pObj->GetObjInventor();
595 : }
596 : }
597 : }
598 :
599 0 : return bControlList && bHadAnyLeafs;
600 : }
601 :
602 : //------------------------------------------------------------------------
603 0 : Reference< XForm > GetForm(const Reference< XInterface>& _rxElement)
604 : {
605 0 : Reference< XForm > xForm( _rxElement, UNO_QUERY );
606 0 : if ( xForm.is() )
607 0 : return xForm;
608 :
609 0 : Reference< XChild > xChild( _rxElement, UNO_QUERY );
610 0 : if ( xChild.is() )
611 0 : return GetForm( xChild->getParent() );
612 :
613 0 : return Reference< XForm >();
614 : }
615 :
616 : //========================================================================
617 : // class FmXFormShell_Base_Disambiguation
618 : //========================================================================
619 236 : FmXFormShell_Base_Disambiguation::FmXFormShell_Base_Disambiguation( ::osl::Mutex& _rMutex )
620 236 : :FmXFormShell_BD_BASE( _rMutex )
621 : {
622 236 : }
623 :
624 63 : void SAL_CALL FmXFormShell_Base_Disambiguation::disposing()
625 : {
626 63 : WeakComponentImplHelperBase::disposing();
627 : // Note:
628 : // This is a HACK.
629 : // Normally it should be sufficient to call the "disposing" of our direct
630 : // base class, but SUN PRO 5 does not like this and claims there is a conflict
631 : // with the XEventListener::disposing(EventObject) of our various listener
632 : // base classes.
633 63 : }
634 :
635 : //========================================================================
636 : // class FmXFormShell
637 : //========================================================================
638 : DBG_NAME(FmXFormShell);
639 : //------------------------------------------------------------------------
640 236 : FmXFormShell::FmXFormShell( FmFormShell& _rShell, SfxViewFrame* _pViewFrame )
641 : :FmXFormShell_BASE(m_aMutex)
642 : ,FmXFormShell_CFGBASE(::rtl::OUString("Office.Common/Misc"), CONFIG_MODE_DELAYED_UPDATE)
643 : ,m_eNavigate( NavigationBarMode_NONE )
644 : ,m_nInvalidationEvent( 0 )
645 : ,m_nActivationEvent( 0 )
646 : ,m_pShell( &_rShell )
647 236 : ,m_pTextShell( new ::svx::FmTextControlShell( _pViewFrame ) )
648 : ,m_aActiveControllerFeatures( ::comphelper::getProcessServiceFactory(), this )
649 : ,m_aNavControllerFeatures( ::comphelper::getProcessServiceFactory(), this )
650 : ,m_eDocumentType( eUnknownDocumentType )
651 : ,m_nLockSlotInvalidation( 0 )
652 : ,m_bHadPropertyBrowserInDesignMode( sal_False )
653 : ,m_bTrackProperties( sal_True )
654 : ,m_bUseWizards( sal_True )
655 : ,m_bDatabaseBar( sal_False )
656 : ,m_bInActivate( sal_False )
657 : ,m_bSetFocus( sal_False )
658 : ,m_bFilterMode( sal_False )
659 : ,m_bChangingDesignMode( sal_False )
660 : ,m_bPreparedClose( sal_False )
661 472 : ,m_bFirstActivation( sal_True )
662 : {
663 : DBG_CTOR(FmXFormShell,NULL);
664 236 : m_aMarkTimer.SetTimeout(100);
665 236 : m_aMarkTimer.SetTimeoutHdl(LINK(this,FmXFormShell,OnTimeOut));
666 :
667 236 : if ( _pViewFrame )
668 236 : m_xAttachedFrame = _pViewFrame->GetFrame().GetFrameInterface();
669 :
670 : // to prevent deletion of this we acquire our refcounter once
671 236 : ::comphelper::increment(FmXFormShell_BASE::m_refCount);
672 :
673 : // correct the refcounter
674 236 : ::comphelper::decrement(FmXFormShell_BASE::m_refCount);
675 :
676 : // cache the current configuration settings we're interested in
677 236 : implAdjustConfigCache();
678 : // and register for changes on this settings
679 236 : Sequence< ::rtl::OUString > aNames(1);
680 236 : aNames[0] = ::rtl::OUString("FormControlPilotsEnabled");
681 236 : EnableNotification(aNames);
682 236 : }
683 :
684 : //------------------------------------------------------------------------
685 189 : FmXFormShell::~FmXFormShell()
686 : {
687 63 : delete m_pTextShell;
688 : DBG_DTOR(FmXFormShell,NULL);
689 126 : }
690 :
691 : //------------------------------------------------------------------
692 236 : Reference< XModel > FmXFormShell::getContextDocument() const
693 : {
694 236 : Reference< XModel > xModel;
695 :
696 : // determine the type of document we live in
697 : try
698 : {
699 236 : Reference< XController > xController;
700 236 : if ( m_xAttachedFrame.is() )
701 236 : xController = m_xAttachedFrame->getController();
702 236 : if ( xController.is() )
703 236 : xModel = xController->getModel();
704 : }
705 0 : catch( const Exception& )
706 : {
707 : DBG_UNHANDLED_EXCEPTION();
708 : }
709 236 : return xModel;
710 : }
711 :
712 : //------------------------------------------------------------------
713 361 : bool FmXFormShell::isEnhancedForm() const
714 : {
715 361 : return getDocumentType() == eEnhancedForm;
716 : }
717 :
718 : //------------------------------------------------------------------
719 1855 : bool FmXFormShell::impl_checkDisposed() const
720 : {
721 1855 : if ( !m_pShell )
722 : {
723 : OSL_FAIL( "FmXFormShell::impl_checkDisposed: already disposed!" );
724 0 : return true;
725 : }
726 1855 : return false;
727 : }
728 :
729 : //------------------------------------------------------------------
730 361 : ::svxform::DocumentType FmXFormShell::getDocumentType() const
731 : {
732 361 : if ( m_eDocumentType != eUnknownDocumentType )
733 125 : return m_eDocumentType;
734 :
735 : // determine the type of document we live in
736 236 : Reference< XModel > xModel = getContextDocument();
737 236 : if ( xModel.is() )
738 236 : m_eDocumentType = DocumentClassification::classifyDocument( xModel );
739 : else
740 : {
741 : OSL_FAIL( "FmXFormShell::getDocumentType: can't determine the document type!" );
742 0 : m_eDocumentType = eTextDocument;
743 : // fallback, just to have a defined state
744 : }
745 :
746 236 : return m_eDocumentType;
747 : }
748 :
749 : //------------------------------------------------------------------
750 360 : bool FmXFormShell::IsReadonlyDoc() const
751 : {
752 360 : if ( impl_checkDisposed() )
753 0 : return true;
754 :
755 360 : FmFormModel* pModel = m_pShell->GetFormModel();
756 360 : if ( pModel && pModel->GetObjectShell() )
757 360 : return pModel->GetObjectShell()->IsReadOnly() || pModel->GetObjectShell()->IsReadOnlyUI();
758 0 : return true;
759 : }
760 :
761 : //------------------------------------------------------------------
762 0 : Any SAL_CALL FmXFormShell::queryInterface( const Type& type) throw ( RuntimeException )
763 : {
764 0 : return FmXFormShell_BASE::queryInterface(type);
765 : }
766 : //------------------------------------------------------------------------------
767 0 : Sequence< Type > SAL_CALL FmXFormShell::getTypes( ) throw(RuntimeException)
768 : {
769 0 : return FmXFormShell_BASE::getTypes();
770 : }
771 : //------------------------------------------------------------------------------
772 0 : Sequence< sal_Int8 > SAL_CALL FmXFormShell::getImplementationId() throw(RuntimeException)
773 : {
774 : static ::cppu::OImplementationId* pId = 0;
775 0 : if (! pId)
776 : {
777 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
778 0 : if (! pId)
779 : {
780 0 : static ::cppu::OImplementationId aId;
781 0 : pId = &aId;
782 0 : }
783 : }
784 0 : return pId->getImplementationId();
785 : }
786 : // EventListener
787 : //------------------------------------------------------------------------------
788 0 : void SAL_CALL FmXFormShell::disposing(const EventObject& e) throw( RuntimeException )
789 : {
790 0 : impl_checkDisposed();
791 :
792 0 : if (m_xActiveController == e.Source)
793 : {
794 : // wird der Controller freigeben dann alles loslassen
795 0 : stopListening();
796 0 : m_xActiveForm = NULL;
797 0 : m_xActiveController = NULL;
798 0 : m_xNavigationController = NULL;
799 :
800 0 : m_aActiveControllerFeatures.dispose();
801 0 : m_aNavControllerFeatures.dispose();
802 :
803 0 : if ( m_pShell )
804 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
805 : }
806 :
807 0 : if (e.Source == m_xExternalViewController)
808 : {
809 0 : Reference< runtime::XFormController > xFormController( m_xExternalViewController, UNO_QUERY );
810 : OSL_ENSURE( xFormController.is(), "FmXFormShell::disposing: invalid external view controller!" );
811 0 : if (xFormController.is())
812 0 : xFormController->removeActivateListener((XFormControllerListener*)this);
813 :
814 0 : Reference< ::com::sun::star::lang::XComponent> xComp(m_xExternalViewController, UNO_QUERY);
815 0 : if (xComp.is())
816 0 : xComp->removeEventListener((XEventListener*)(XPropertyChangeListener*)this);
817 :
818 0 : m_xExternalViewController = NULL;
819 0 : m_xExternalDisplayedForm = NULL;
820 0 : m_xExtViewTriggerController = NULL;
821 :
822 0 : InvalidateSlot( SID_FM_VIEW_AS_GRID, sal_False );
823 : }
824 0 : }
825 :
826 : //------------------------------------------------------------------------------
827 0 : void SAL_CALL FmXFormShell::propertyChange(const PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException)
828 : {
829 0 : if ( impl_checkDisposed() )
830 0 : return;
831 :
832 0 : if (evt.PropertyName == FM_PROP_ROWCOUNT)
833 : {
834 : // Das gleich folgenden Update erzwingt ein Neu-Painten der entsprechenden Slots. Wenn ich mich aber hier nicht
835 : // in dem HauptThread der Applikation befinde (weil zum Beispiel ein Cursor gerade Datensaetze zaehlt und mir dabei
836 : // immer diese PropertyChanges beschert), kann sich das mit en normalen Paints im HauptThread der Applikation beissen.
837 : // (Solche Paints passieren zum Beispiel, wenn man einfach nur eine andere Applikation ueber das Office legt und wieder
838 : // zurueckschaltet).
839 : // Deshalb die Benutzung des SolarMutex, der sichert das ab.
840 0 : ::osl::SolarMutex& rSolarSafety = Application::GetSolarMutex();
841 0 : if (rSolarSafety.tryToAcquire())
842 : {
843 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_RECORD_TOTAL , sal_True, sal_False);
844 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update(SID_FM_RECORD_TOTAL);
845 0 : rSolarSafety.release();
846 : }
847 : else
848 : {
849 : // with the following the slot is invalidated asynchron
850 0 : LockSlotInvalidation(sal_True);
851 0 : InvalidateSlot(SID_FM_RECORD_TOTAL, sal_False);
852 0 : LockSlotInvalidation(sal_False);
853 : }
854 : }
855 :
856 : // this may be called from a non-main-thread so invalidate the shell asynchronously
857 0 : LockSlotInvalidation(sal_True);
858 0 : InvalidateSlot(0, 0); // special meaning : invalidate m_pShell
859 0 : LockSlotInvalidation(sal_False);
860 : }
861 :
862 : //------------------------------------------------------------------------------
863 0 : void FmXFormShell::invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures )
864 : {
865 0 : if ( impl_checkDisposed() )
866 0 : return;
867 :
868 : OSL_ENSURE( _rFeatures.size() > 0, "FmXFormShell::invalidateFeatures: invalid arguments!" );
869 :
870 0 : if ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() )
871 : {
872 : // unfortunately, SFX requires sal_uInt16
873 0 : ::std::vector< sal_uInt16 > aSlotIds;
874 0 : aSlotIds.reserve( _rFeatures.size() );
875 : ::std::copy( _rFeatures.begin(),
876 : _rFeatures.end(),
877 : ::std::insert_iterator< ::std::vector< sal_uInt16 > >( aSlotIds, aSlotIds.begin() )
878 0 : );
879 :
880 : // furthermore, SFX wants a terminating 0
881 0 : aSlotIds.push_back( 0 );
882 :
883 : // and, last but not least, SFX wants the ids to be sorted
884 0 : ::std::sort( aSlotIds.begin(), aSlotIds.end() - 1 );
885 :
886 0 : sal_uInt16 *pSlotIds = aSlotIds.empty() ? 0 : &(aSlotIds[0]);
887 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( pSlotIds );
888 : }
889 : }
890 :
891 : //------------------------------------------------------------------------------
892 0 : void SAL_CALL FmXFormShell::formActivated(const EventObject& rEvent) throw( RuntimeException )
893 : {
894 0 : if ( impl_checkDisposed() )
895 0 : return;
896 :
897 0 : Reference< runtime::XFormController > xController( rEvent.Source, UNO_QUERY_THROW );
898 0 : m_pTextShell->formActivated( xController );
899 0 : setActiveController( xController );
900 : }
901 :
902 : //------------------------------------------------------------------------------
903 0 : void SAL_CALL FmXFormShell::formDeactivated(const EventObject& rEvent) throw( RuntimeException )
904 : {
905 0 : if ( impl_checkDisposed() )
906 0 : return;
907 :
908 0 : Reference< runtime::XFormController > xController( rEvent.Source, UNO_QUERY_THROW );
909 0 : m_pTextShell->formDeactivated( xController );
910 : }
911 :
912 : //------------------------------------------------------------------------------
913 63 : void FmXFormShell::disposing()
914 : {
915 63 : impl_checkDisposed();
916 :
917 63 : FmXFormShell_BASE::disposing();
918 :
919 63 : if ( m_pShell && !m_pShell->IsDesignMode() )
920 2 : setActiveController( NULL, sal_True );
921 : // do NOT save the content of the old form (the second parameter tells this)
922 : // if we're here, then we expect that PrepareClose has been called, and thus the user
923 : // got a chance to commit or reject any changes. So in case we're here and there
924 : // are still uncommitted changes, the user explicitly wanted this.
925 :
926 63 : m_pTextShell->dispose();
927 :
928 63 : m_xAttachedFrame = NULL;
929 :
930 63 : CloseExternalFormViewer();
931 :
932 126 : while ( m_aLoadingPages.size() )
933 : {
934 0 : Application::RemoveUserEvent( m_aLoadingPages.front().nEventId );
935 0 : m_aLoadingPages.pop();
936 : }
937 :
938 : {
939 63 : ::osl::MutexGuard aGuard(m_aInvalidationSafety);
940 63 : if (m_nInvalidationEvent)
941 : {
942 0 : Application::RemoveUserEvent(m_nInvalidationEvent);
943 0 : m_nInvalidationEvent = 0;
944 : }
945 63 : if ( m_nActivationEvent )
946 : {
947 63 : Application::RemoveUserEvent( m_nActivationEvent );
948 63 : m_nActivationEvent = 0;
949 63 : }
950 : }
951 :
952 : {
953 63 : ::osl::ClearableMutexGuard aGuard(m_aAsyncSafety);
954 63 : aGuard.clear();
955 :
956 : DBG_ASSERT(!m_nInvalidationEvent, "FmXFormShell::~FmXFormShell : still have an invalidation event !");
957 : // should habe been deleted while beeing disposed
958 :
959 63 : m_aMarkTimer.Stop();
960 : }
961 :
962 63 : DisableNotification();
963 :
964 63 : RemoveElement( m_xForms );
965 63 : m_xForms.clear();
966 :
967 63 : impl_switchActiveControllerListening( false );
968 63 : m_xActiveController = NULL;
969 63 : m_xActiveForm = NULL;
970 :
971 63 : m_pShell = NULL;
972 63 : m_xNavigationController = NULL;
973 63 : m_xCurrentForm = NULL;
974 63 : m_xLastGridFound = NULL;
975 63 : m_xAttachedFrame = NULL;
976 63 : m_xExternalViewController = NULL;
977 63 : m_xExtViewTriggerController = NULL;
978 63 : m_xExternalDisplayedForm = NULL;
979 63 : m_xLastGridFound = NULL;
980 :
981 63 : InterfaceBag aEmpty;
982 63 : m_aCurrentSelection.swap( aEmpty );
983 :
984 63 : m_aActiveControllerFeatures.dispose();
985 63 : m_aNavControllerFeatures.dispose();
986 63 : }
987 :
988 : //------------------------------------------------------------------------------
989 0 : void FmXFormShell::UpdateSlot( sal_Int16 _nId )
990 : {
991 0 : if ( impl_checkDisposed() )
992 0 : return;
993 :
994 0 : ::osl::MutexGuard aGuard(m_aInvalidationSafety);
995 :
996 0 : if ( m_nLockSlotInvalidation )
997 : {
998 : OSL_FAIL( "FmXFormShell::UpdateSlot: cannot update if invalidation is currently locked!" );
999 0 : InvalidateSlot( _nId, sal_False );
1000 : }
1001 : else
1002 : {
1003 : OSL_ENSURE( _nId, "FmXFormShell::UpdateSlot: can't update the complete shell!" );
1004 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( _nId, sal_True, sal_True );
1005 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update( _nId );
1006 0 : }
1007 : }
1008 :
1009 : //------------------------------------------------------------------------------
1010 0 : void FmXFormShell::InvalidateSlot( sal_Int16 nId, sal_Bool bWithId )
1011 : {
1012 0 : if ( impl_checkDisposed() )
1013 0 : return;
1014 :
1015 0 : ::osl::MutexGuard aGuard(m_aInvalidationSafety);
1016 0 : if (m_nLockSlotInvalidation)
1017 : {
1018 0 : sal_uInt8 nFlags = ( bWithId ? 0x01 : 0 );
1019 0 : m_arrInvalidSlots.push_back( InvalidSlotInfo(nId, nFlags) );
1020 : }
1021 : else
1022 0 : if (nId)
1023 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(nId, sal_True, bWithId);
1024 : else
1025 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
1026 : }
1027 :
1028 : //------------------------------------------------------------------------------
1029 0 : void FmXFormShell::LockSlotInvalidation(sal_Bool bLock)
1030 : {
1031 0 : if ( impl_checkDisposed() )
1032 0 : return;
1033 :
1034 0 : ::osl::MutexGuard aGuard(m_aInvalidationSafety);
1035 : DBG_ASSERT(bLock || m_nLockSlotInvalidation>0, "FmXFormShell::LockSlotInvalidation : invalid call !");
1036 :
1037 0 : if (bLock)
1038 0 : ++m_nLockSlotInvalidation;
1039 0 : else if (!--m_nLockSlotInvalidation)
1040 : {
1041 : // alles, was sich waehrend der gelockten Phase angesammelt hat, (asynchron) invalidieren
1042 0 : if (!m_nInvalidationEvent)
1043 0 : m_nInvalidationEvent = Application::PostUserEvent(LINK(this, FmXFormShell, OnInvalidateSlots));
1044 0 : }
1045 : }
1046 :
1047 : //------------------------------------------------------------------------------
1048 0 : IMPL_LINK_NOARG(FmXFormShell, OnInvalidateSlots)
1049 : {
1050 0 : if ( impl_checkDisposed() )
1051 0 : return 0L;
1052 :
1053 0 : ::osl::MutexGuard aGuard(m_aInvalidationSafety);
1054 0 : m_nInvalidationEvent = 0;
1055 :
1056 0 : for (std::vector<InvalidSlotInfo>::const_iterator i = m_arrInvalidSlots.begin(); i < m_arrInvalidSlots.end(); ++i)
1057 : {
1058 0 : if (i->id)
1059 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(i->id, sal_True, (i->flags & 0x01));
1060 : else
1061 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
1062 : }
1063 0 : m_arrInvalidSlots.clear();
1064 0 : return 0L;
1065 : }
1066 :
1067 : //------------------------------------------------------------------------------
1068 0 : void FmXFormShell::ForceUpdateSelection(sal_Bool bAllowInvalidation)
1069 : {
1070 0 : if ( impl_checkDisposed() )
1071 0 : return;
1072 :
1073 0 : if (IsSelectionUpdatePending())
1074 : {
1075 0 : m_aMarkTimer.Stop();
1076 :
1077 : // die Invalidierung der Slots, die implizit von SetSelection besorgt wird, eventuell abschalten
1078 0 : if (!bAllowInvalidation)
1079 0 : LockSlotInvalidation(sal_True);
1080 :
1081 0 : SetSelection(m_pShell->GetFormView()->GetMarkedObjectList());
1082 :
1083 0 : if (!bAllowInvalidation)
1084 0 : LockSlotInvalidation(sal_False);
1085 : }
1086 : }
1087 :
1088 : //------------------------------------------------------------------------------
1089 0 : PopupMenu* FmXFormShell::GetConversionMenu()
1090 : {
1091 :
1092 0 : PopupMenu* pNewMenu = new PopupMenu(SVX_RES( RID_FMSHELL_CONVERSIONMENU ));
1093 :
1094 0 : ImageList aImageList( SVX_RES( RID_SVXIMGLIST_FMEXPL) );
1095 0 : for ( size_t i = 0; i < sizeof (nConvertSlots) / sizeof (nConvertSlots[0]); ++i )
1096 : {
1097 : // das entsprechende Image dran
1098 0 : pNewMenu->SetItemImage(nConvertSlots[i], aImageList.GetImage(nCreateSlots[i]));
1099 : }
1100 :
1101 0 : return pNewMenu;
1102 : }
1103 :
1104 : //------------------------------------------------------------------------------
1105 0 : bool FmXFormShell::isControlConversionSlot( sal_uInt16 nSlotId )
1106 : {
1107 0 : for ( size_t i = 0; i < sizeof (nConvertSlots) / sizeof (nConvertSlots[0]); ++i )
1108 0 : if (nConvertSlots[i] == nSlotId)
1109 0 : return true;
1110 0 : return false;
1111 : }
1112 :
1113 : //------------------------------------------------------------------------------
1114 0 : bool FmXFormShell::executeControlConversionSlot( sal_uInt16 _nSlotId )
1115 : {
1116 : OSL_PRECOND( canConvertCurrentSelectionToControl( _nSlotId ), "FmXFormShell::executeControlConversionSlot: illegal call!" );
1117 0 : InterfaceBag::const_iterator aSelectedElement = m_aCurrentSelection.begin();
1118 0 : if ( aSelectedElement == m_aCurrentSelection.end() )
1119 0 : return false;
1120 :
1121 0 : return executeControlConversionSlot( Reference< XFormComponent >( *aSelectedElement, UNO_QUERY ), _nSlotId );
1122 : }
1123 :
1124 : //------------------------------------------------------------------------------
1125 0 : bool FmXFormShell::executeControlConversionSlot( const Reference< XFormComponent >& _rxObject, sal_uInt16 _nSlotId )
1126 : {
1127 0 : if ( impl_checkDisposed() )
1128 0 : return false;
1129 :
1130 : OSL_ENSURE( _rxObject.is(), "FmXFormShell::executeControlConversionSlot: invalid object!" );
1131 0 : if ( !_rxObject.is() )
1132 0 : return false;
1133 :
1134 0 : SdrPage* pPage = m_pShell->GetCurPage();
1135 0 : FmFormPage* pFormPage = pPage ? dynamic_cast< FmFormPage* >( pPage ) : NULL;
1136 : OSL_ENSURE( pFormPage, "FmXFormShell::executeControlConversionSlot: no current (form) page!" );
1137 0 : if ( !pFormPage )
1138 0 : return false;
1139 :
1140 : OSL_ENSURE( isSolelySelected( _rxObject ),
1141 : "FmXFormShell::executeControlConversionSlot: hmm ... shouldn't this parameter be redundant?" );
1142 :
1143 0 : for ( size_t lookupSlot = 0; lookupSlot < sizeof( nConvertSlots ) / sizeof( nConvertSlots[0] ); ++lookupSlot )
1144 : {
1145 0 : if (nConvertSlots[lookupSlot] == _nSlotId)
1146 : {
1147 0 : Reference< XInterface > xNormalizedObject( _rxObject, UNO_QUERY );
1148 :
1149 0 : FmFormObj* pFormObject = NULL;
1150 0 : SdrObjListIter aPageIter( *pFormPage );
1151 0 : while ( aPageIter.IsMore() )
1152 : {
1153 0 : SdrObject* pCurrent = aPageIter.Next();
1154 0 : pFormObject = FmFormObj::GetFormObject( pCurrent );
1155 0 : if ( !pFormObject )
1156 0 : continue;
1157 :
1158 0 : Reference< XInterface > xCurrentNormalized( pFormObject->GetUnoControlModel(), UNO_QUERY );
1159 0 : if ( xCurrentNormalized.get() == xNormalizedObject.get() )
1160 : break;
1161 :
1162 0 : pFormObject = NULL;
1163 0 : }
1164 :
1165 0 : if ( !pFormObject )
1166 0 : return false;
1167 :
1168 0 : ::rtl::OUString sNewName( getServiceNameByControlType( nObjectTypes[ lookupSlot ] ) );
1169 0 : Reference< XControlModel> xNewModel( ::comphelper::getProcessServiceFactory()->createInstance( sNewName ), UNO_QUERY );
1170 0 : if (!xNewModel.is())
1171 0 : return false;
1172 :
1173 0 : Reference< XControlModel> xOldModel( pFormObject->GetUnoControlModel() );
1174 0 : Reference< XServiceInfo> xModelInfo(xOldModel, UNO_QUERY);
1175 :
1176 : // Properties uebertragen
1177 0 : Reference< XPropertySet> xOldSet(xOldModel, UNO_QUERY);
1178 0 : Reference< XPropertySet> xNewSet(xNewModel, UNO_QUERY);
1179 :
1180 :
1181 0 : Locale aNewLanguage = Application::GetSettings().GetUILanguageTag().getLocale();
1182 0 : TransferFormComponentProperties(xOldSet, xNewSet, aNewLanguage);
1183 :
1184 0 : Sequence< ::com::sun::star::script::ScriptEventDescriptor> aOldScripts;
1185 0 : Reference< XChild> xChild(xOldModel, UNO_QUERY);
1186 0 : if (xChild.is())
1187 : {
1188 0 : Reference< XIndexAccess> xParent(xChild->getParent(), UNO_QUERY);
1189 :
1190 : // remember old script events
1191 0 : Reference< ::com::sun::star::script::XEventAttacherManager> xEvManager(xChild->getParent(), UNO_QUERY);
1192 0 : if (xParent.is() && xEvManager.is())
1193 : {
1194 0 : sal_Int32 nIndex = getElementPos(xParent, xOldModel);
1195 0 : if (nIndex>=0 && nIndex<xParent->getCount())
1196 0 : aOldScripts = xEvManager->getScriptEvents(nIndex);
1197 : }
1198 :
1199 : // replace the mdoel within the parent container
1200 0 : Reference< XIndexContainer> xIndexParent(xChild->getParent(), UNO_QUERY);
1201 0 : if (xIndexParent.is())
1202 : {
1203 : // the form container works with FormComponents
1204 0 : Reference< XFormComponent> xComponent(xNewModel, UNO_QUERY);
1205 : DBG_ASSERT(xComponent.is(), "FmXFormShell::executeControlConversionSlot: the new model is no form component !");
1206 0 : Any aNewModel(makeAny(xComponent));
1207 : try
1208 : {
1209 :
1210 0 : sal_Int32 nIndex = getElementPos(xParent, xOldModel);
1211 0 : if (nIndex>=0 && nIndex<xParent->getCount())
1212 0 : xIndexParent->replaceByIndex(nIndex, aNewModel);
1213 : else
1214 : {
1215 : OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
1216 0 : Reference< ::com::sun::star::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY);
1217 0 : if (xNewComponent.is())
1218 0 : xNewComponent->dispose();
1219 0 : return false;
1220 : }
1221 : }
1222 0 : catch(Exception&)
1223 : {
1224 : OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
1225 0 : Reference< ::com::sun::star::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY);
1226 0 : if (xNewComponent.is())
1227 0 : xNewComponent->dispose();
1228 0 : return false;
1229 0 : }
1230 :
1231 0 : }
1232 : }
1233 :
1234 : // special handling for the LabelControl-property : can only be set when the model is placed
1235 : // within the forms hierarchy
1236 0 : if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xOldSet) && ::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xNewSet))
1237 : {
1238 : try
1239 : {
1240 0 : xNewSet->setPropertyValue(FM_PROP_CONTROLLABEL, xOldSet->getPropertyValue(FM_PROP_CONTROLLABEL));
1241 : }
1242 0 : catch(Exception&)
1243 : {
1244 : }
1245 :
1246 : }
1247 :
1248 : // neues Model setzen
1249 0 : pFormObject->SetChanged();
1250 0 : pFormObject->SetUnoControlModel(xNewModel);
1251 :
1252 : // transfer script events
1253 : // (do this _after_ SetUnoControlModel as we need the new (implicitly created) control)
1254 0 : if (aOldScripts.getLength())
1255 : {
1256 : // das Control zum Model suchen
1257 0 : Reference< XControlContainer > xControlContainer( getControlContainerForView() );
1258 :
1259 0 : Sequence< Reference< XControl> > aControls( xControlContainer->getControls() );
1260 0 : const Reference< XControl>* pControls = aControls.getConstArray();
1261 :
1262 0 : sal_uInt32 nLen = aControls.getLength();
1263 0 : Reference< XControl> xControl;
1264 0 : for (sal_uInt32 i=0 ; i<nLen; ++i)
1265 : {
1266 0 : if (pControls[i]->getModel() == xNewModel)
1267 : {
1268 0 : xControl = pControls[i];
1269 0 : break;
1270 : }
1271 : }
1272 0 : TransferEventScripts(xNewModel, xControl, aOldScripts);
1273 : }
1274 :
1275 : // transfer value bindings, if possible
1276 : {
1277 0 : Reference< XBindableValue > xOldBindable( xOldModel, UNO_QUERY );
1278 0 : Reference< XBindableValue > xNewBindable( xNewModel, UNO_QUERY );
1279 0 : if ( xOldBindable.is() )
1280 : {
1281 : try
1282 : {
1283 0 : if ( xNewBindable.is() )
1284 0 : xNewBindable->setValueBinding( xOldBindable->getValueBinding() );
1285 0 : xOldBindable->setValueBinding( NULL );
1286 : }
1287 0 : catch(const Exception&)
1288 : {
1289 : DBG_UNHANDLED_EXCEPTION();
1290 : }
1291 0 : }
1292 : }
1293 : // same for list entry sources
1294 : {
1295 0 : Reference< XListEntrySink > xOldSink( xOldModel, UNO_QUERY );
1296 0 : Reference< XListEntrySink > xNewSink( xNewModel, UNO_QUERY );
1297 0 : if ( xOldSink.is() )
1298 : {
1299 : try
1300 : {
1301 0 : if ( xNewSink.is() )
1302 0 : xNewSink->setListEntrySource( xOldSink->getListEntrySource() );
1303 0 : xOldSink->setListEntrySource( NULL );
1304 : }
1305 0 : catch(const Exception&)
1306 : {
1307 : DBG_UNHANDLED_EXCEPTION();
1308 : }
1309 0 : }
1310 : }
1311 :
1312 : // create an undo action
1313 0 : FmFormModel* pModel = m_pShell->GetFormModel();
1314 : DBG_ASSERT(pModel != NULL, "FmXFormShell::executeControlConversionSlot: my shell has no model !");
1315 0 : if (pModel && pModel->IsUndoEnabled() )
1316 : {
1317 0 : pModel->AddUndo(new FmUndoModelReplaceAction(*pModel, pFormObject, xOldModel));
1318 : }
1319 : else
1320 : {
1321 0 : FmUndoModelReplaceAction::DisposeElement( xOldModel );
1322 : }
1323 :
1324 0 : return true;
1325 : }
1326 : }
1327 0 : return false;
1328 : }
1329 :
1330 : //------------------------------------------------------------------------------
1331 0 : bool FmXFormShell::canConvertCurrentSelectionToControl( sal_Int16 nConversionSlot )
1332 : {
1333 0 : if ( m_aCurrentSelection.empty() )
1334 0 : return false;
1335 :
1336 0 : InterfaceBag::const_iterator aCheck = m_aCurrentSelection.begin();
1337 0 : Reference< XServiceInfo > xElementInfo( *aCheck, UNO_QUERY );
1338 0 : if ( !xElementInfo.is() )
1339 : // no service info -> cannot determine this
1340 0 : return false;
1341 :
1342 0 : if ( ++aCheck != m_aCurrentSelection.end() )
1343 : // more than one element
1344 0 : return false;
1345 :
1346 0 : if ( Reference< XForm >::query( xElementInfo ).is() )
1347 : // it's a form
1348 0 : return false;
1349 :
1350 0 : sal_Int16 nObjectType = getControlTypeByObject( xElementInfo );
1351 :
1352 0 : if ( ( OBJ_FM_HIDDEN == nObjectType )
1353 : || ( OBJ_FM_CONTROL == nObjectType )
1354 : || ( OBJ_FM_GRID == nObjectType )
1355 : )
1356 0 : return false; // those types cannot be converted
1357 :
1358 : DBG_ASSERT(sizeof(nConvertSlots)/sizeof(nConvertSlots[0]) == sizeof(nObjectTypes)/sizeof(nObjectTypes[0]),
1359 : "FmXFormShell::canConvertCurrentSelectionToControl: nConvertSlots & nObjectTypes must have the same size !");
1360 :
1361 0 : for ( size_t i = 0; i < sizeof( nConvertSlots ) / sizeof( nConvertSlots[0] ); ++i )
1362 0 : if (nConvertSlots[i] == nConversionSlot)
1363 0 : return nObjectTypes[i] != nObjectType;
1364 :
1365 0 : return sal_True; // all other slots: assume "yes"
1366 : }
1367 :
1368 : //------------------------------------------------------------------------------
1369 0 : void FmXFormShell::checkControlConversionSlotsForCurrentSelection( Menu& rMenu )
1370 : {
1371 0 : for (sal_Int16 i=0; i<rMenu.GetItemCount(); ++i)
1372 : // der Context ist schon von einem Typ, der dem Eitnrag entspricht -> disable
1373 0 : rMenu.EnableItem( rMenu.GetItemId(i), canConvertCurrentSelectionToControl( rMenu.GetItemId( i ) ) );
1374 0 : }
1375 :
1376 : //------------------------------------------------------------------------------
1377 0 : void FmXFormShell::LoopGrids(sal_Int16 nWhat)
1378 : {
1379 0 : if ( impl_checkDisposed() )
1380 0 : return;
1381 :
1382 0 : Reference< XIndexContainer> xControlModels(m_xActiveForm, UNO_QUERY);
1383 0 : if (xControlModels.is())
1384 : {
1385 0 : for (sal_Int16 i=0; i<xControlModels->getCount(); ++i)
1386 : {
1387 0 : Reference< XPropertySet> xModelSet;
1388 0 : xControlModels->getByIndex(i) >>= xModelSet;
1389 0 : if (!xModelSet.is())
1390 0 : continue;
1391 :
1392 0 : if (!::comphelper::hasProperty(FM_PROP_CLASSID, xModelSet))
1393 0 : continue;
1394 0 : sal_Int16 nClassId = ::comphelper::getINT16(xModelSet->getPropertyValue(FM_PROP_CLASSID));
1395 0 : if (FormComponentType::GRIDCONTROL != nClassId)
1396 0 : continue;
1397 :
1398 0 : if (!::comphelper::hasProperty(FM_PROP_CURSORCOLOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_ALWAYSSHOWCURSOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_DISPLAYSYNCHRON, xModelSet))
1399 0 : continue;
1400 :
1401 0 : switch (nWhat & GA_SYNC_MASK)
1402 : {
1403 : case GA_DISABLE_SYNC:
1404 : {
1405 0 : sal_Bool bB(sal_False);
1406 0 : xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
1407 : }
1408 0 : break;
1409 : case GA_FORCE_SYNC:
1410 : {
1411 0 : Any aOldVal( xModelSet->getPropertyValue(FM_PROP_DISPLAYSYNCHRON) );
1412 0 : sal_Bool bB(sal_True);
1413 0 : xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
1414 0 : xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, aOldVal);
1415 : }
1416 0 : break;
1417 : case GA_ENABLE_SYNC:
1418 : {
1419 0 : sal_Bool bB(sal_True);
1420 0 : xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
1421 : }
1422 0 : break;
1423 : }
1424 :
1425 0 : if (nWhat & GA_DISABLE_ROCTRLR)
1426 : {
1427 0 : sal_Bool bB(sal_False);
1428 0 : xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
1429 0 : Reference< XPropertyState> xModelPropState(xModelSet, UNO_QUERY);
1430 0 : if (xModelPropState.is())
1431 0 : xModelPropState->setPropertyToDefault(FM_PROP_CURSORCOLOR);
1432 : else
1433 0 : xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any()); // this should be the default
1434 : }
1435 0 : else if (nWhat & GA_ENABLE_ROCTRLR)
1436 : {
1437 0 : sal_Bool bB(sal_True);
1438 0 : xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
1439 0 : xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, makeAny(sal_Int32(COL_LIGHTRED)));
1440 : }
1441 0 : }
1442 0 : }
1443 : }
1444 :
1445 : //------------------------------------------------------------------------------
1446 0 : Reference< XControlContainer > FmXFormShell::getControlContainerForView()
1447 : {
1448 0 : if ( impl_checkDisposed() )
1449 0 : return NULL;
1450 :
1451 0 : SdrPageView* pPageView = NULL;
1452 0 : if ( m_pShell && m_pShell->GetFormView() )
1453 0 : pPageView = m_pShell->GetFormView()->GetSdrPageView();
1454 :
1455 0 : Reference< XControlContainer> xControlContainer;
1456 0 : if ( pPageView )
1457 0 : xControlContainer = pPageView->GetPageWindow(0)->GetControlContainer();
1458 :
1459 0 : return xControlContainer;
1460 : }
1461 :
1462 : //------------------------------------------------------------------------------
1463 0 : void FmXFormShell::ExecuteTabOrderDialog( const Reference< XTabControllerModel >& _rxForForm )
1464 : {
1465 0 : if ( impl_checkDisposed() )
1466 0 : return;
1467 :
1468 : OSL_PRECOND( _rxForForm.is(), "FmXFormShell::ExecuteTabOrderDialog: invalid tabbing model!" );
1469 0 : if ( !_rxForForm.is() )
1470 0 : return;
1471 :
1472 : try
1473 : {
1474 0 : Sequence< Any > aDialogArgs( 3 );
1475 0 : aDialogArgs[0] <<= NamedValue(
1476 : ::rtl::OUString( "TabbingModel" ),
1477 : makeAny( _rxForForm )
1478 0 : );
1479 0 : aDialogArgs[1] <<= NamedValue(
1480 : ::rtl::OUString( "ControlContext" ),
1481 : makeAny( getControlContainerForView() )
1482 0 : );
1483 :
1484 0 : Reference< XWindow > xParentWindow;
1485 0 : if ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() )
1486 0 : xParentWindow = VCLUnoHelper::GetInterface ( &m_pShell->GetViewShell()->GetViewFrame()->GetWindow() );
1487 0 : aDialogArgs[2] <<= NamedValue(
1488 : ::rtl::OUString( "ParentWindow" ),
1489 : makeAny( xParentWindow )
1490 0 : );
1491 :
1492 : Reference< dialogs::XExecutableDialog > xDialog(
1493 0 : ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(
1494 : ::rtl::OUString( "com.sun.star.form.ui.TabOrderDialog" ),
1495 : aDialogArgs
1496 0 : ),
1497 : UNO_QUERY
1498 0 : );
1499 : OSL_ENSURE( xDialog.is(), "FmXFormShell::ExecuteTabOrderDialog: could not create the dialog!" );
1500 :
1501 0 : if ( xDialog.is() )
1502 0 : xDialog->execute();
1503 : }
1504 0 : catch( const Exception& )
1505 : {
1506 : OSL_FAIL( "FmXFormShell::ExecuteTabOrderDialog: caught an exception!" );
1507 : }
1508 : }
1509 :
1510 : //------------------------------------------------------------------------------
1511 0 : void FmXFormShell::ExecuteSearch()
1512 : {
1513 0 : if ( impl_checkDisposed() )
1514 : return;
1515 :
1516 : // eine Sammlung aller (logischen) Formulare
1517 0 : FmFormArray aEmpty;
1518 0 : m_aSearchForms.swap( aEmpty );
1519 0 : ::std::vector< String > aContextNames;
1520 0 : impl_collectFormSearchContexts_nothrow( m_pShell->GetCurPage()->GetForms(), ::rtl::OUString(), m_aSearchForms, aContextNames );
1521 : OSL_POSTCOND( m_aSearchForms.size() == aContextNames.size(),
1522 : "FmXFormShell::ExecuteSearch: nonsense!" );
1523 0 : if ( m_aSearchForms.size() != aContextNames.size() )
1524 : return;
1525 :
1526 : // filter out the forms which do not contain valid controls at all
1527 : {
1528 0 : FmFormArray aValidForms;
1529 0 : ::std::vector< String > aValidContexts;
1530 0 : FmFormArray::const_iterator form = m_aSearchForms.begin();
1531 0 : ::std::vector< String >::const_iterator contextName = aContextNames.begin();
1532 0 : for ( ; form != m_aSearchForms.end(); ++form, ++contextName )
1533 : {
1534 0 : FmSearchContext aTestContext;
1535 0 : aTestContext.nContext = static_cast< sal_Int16 >( form - m_aSearchForms.begin() );
1536 0 : sal_uInt32 nValidControls = OnSearchContextRequest( &aTestContext );
1537 0 : if ( nValidControls > 0 )
1538 : {
1539 0 : aValidForms.push_back( *form );
1540 0 : aValidContexts.push_back( *contextName );
1541 : }
1542 0 : }
1543 :
1544 0 : m_aSearchForms.swap( aValidForms );
1545 0 : aContextNames.swap( aValidContexts );
1546 : }
1547 :
1548 0 : if (m_aSearchForms.empty() )
1549 : { // es gibt keine Controls, die alle Bedingungen fuer eine Suche erfuellen
1550 0 : ErrorBox(NULL, WB_OK, SVX_RESSTR(RID_STR_NODATACONTROLS)).Execute();
1551 : return;
1552 : }
1553 :
1554 : // jetzt brauche ich noch einen 'initial context'
1555 0 : sal_Int16 nInitialContext = 0;
1556 0 : Reference< XForm> xActiveForm( getActiveForm());
1557 0 : for ( size_t i=0; i<m_aSearchForms.size(); ++i )
1558 : {
1559 0 : if (m_aSearchForms.at(i) == xActiveForm)
1560 : {
1561 0 : nInitialContext = (sal_Int16)i;
1562 0 : break;
1563 : }
1564 : }
1565 :
1566 : // wenn der Dialog initial den Text des aktiven Controls anbieten soll, muss dieses ein XTextComponent-Interface habe,
1567 : // ausserdem macht das nur Sinn, wenn das aktuelle Feld auch an ein Tabellen- (oder was-auch-immer-)Feld gebunden ist
1568 0 : UniString strActiveField;
1569 0 : UniString strInitialText;
1570 : // ... das bekomme ich von meinem FormController
1571 : DBG_ASSERT(m_xActiveController.is(), "FmXFormShell::ExecuteSearch : no active controller !");
1572 0 : Reference< XControl> xActiveControl( m_xActiveController->getCurrentControl());
1573 0 : if (xActiveControl.is())
1574 : {
1575 : // das Control kann mir sein Model sagen ...
1576 0 : Reference< XControlModel> xActiveModel( xActiveControl->getModel());
1577 : DBG_ASSERT(xActiveModel.is(), "FmXFormShell::ExecuteSearch : active control has no model !");
1578 :
1579 : // das Model frage ich nach der ControlSource-Eigenschaft ...
1580 0 : Reference< XPropertySet> xProperties(xActiveControl->getModel(), UNO_QUERY);
1581 0 : if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
1582 : {
1583 0 : Reference< XPropertySet> xField;
1584 0 : xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
1585 0 : if (xField.is()) // (nur wenn das Ding wirklich gebunden ist)
1586 : {
1587 : // und das Control selber nach einem TextComponent-Interface (damit ich mir dort den Text abholen kann)
1588 0 : Reference< XTextComponent> xText(xActiveControl, UNO_QUERY);
1589 0 : if (xText.is())
1590 : {
1591 0 : strActiveField = getLabelName(xProperties).getStr();
1592 0 : strInitialText = xText->getText().getStr();
1593 0 : }
1594 0 : }
1595 : }
1596 : else
1597 : {
1598 : // das Control selber hat keine ControlSource, aber vielleicht ist es ein GridControl
1599 0 : Reference< XGrid> xGrid(xActiveControl, UNO_QUERY);
1600 0 : if (xGrid.is())
1601 : {
1602 : // fuer strActiveField brauche ich die die ControlSource der Column, dafuer den Columns-Container, dafuer die
1603 : // GridPeer
1604 0 : Reference< XGridPeer> xGridPeer(xActiveControl->getPeer(), UNO_QUERY);
1605 0 : Reference< XIndexAccess> xColumns;
1606 0 : if (xGridPeer.is())
1607 0 : xColumns = Reference< XIndexAccess>(xGridPeer->getColumns(),UNO_QUERY);
1608 :
1609 0 : sal_Int16 nViewCol = xGrid->getCurrentColumnPosition();
1610 0 : sal_Int16 nModelCol = GridView2ModelPos(xColumns, nViewCol);
1611 0 : Reference< XPropertySet> xCurrentCol;
1612 0 : if(xColumns.is())
1613 0 : xColumns->getByIndex(nModelCol) >>= xCurrentCol;
1614 0 : if (xCurrentCol.is())
1615 0 : strActiveField = ::comphelper::getString(xCurrentCol->getPropertyValue(FM_PROP_LABEL)).getStr();
1616 :
1617 : // the text fo the current column
1618 0 : Reference< XIndexAccess> xColControls(xGridPeer, UNO_QUERY);
1619 0 : Reference< XInterface> xCurControl;
1620 0 : xColControls->getByIndex(nViewCol) >>= xCurControl;
1621 0 : ::rtl::OUString sInitialText;
1622 0 : if (IsSearchableControl(xCurControl, &sInitialText))
1623 0 : strInitialText = sInitialText.getStr();
1624 0 : }
1625 0 : }
1626 : }
1627 :
1628 : // um eventuelle GridControls, die ich kenne, kuemmern
1629 0 : LoopGrids(GA_DISABLE_SYNC /*| GA_ENABLE_ROCTRLR*/);
1630 :
1631 : // jetzt bin ich reif fuer den Dialog
1632 : // wenn die potentiellen Deadlocks, die durch die Benutzung des Solar-Mutex in MTs VCLX...-Klasen entstehen, irgendwann mal
1633 : // ausgeraeumt sind, sollte hier ein SM_USETHREAD rein, denn die Suche in einem eigenen Thread ist doch etwas fluessiger
1634 : // sollte allerdings irgendwie von dem unterliegenden Cursor abhaengig gemacht werden, DAO zum Beispiel ist nicht thread-sicher
1635 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1636 0 : AbstractFmSearchDialog* pDialog = NULL;
1637 0 : if ( pFact )
1638 0 : pDialog = pFact->CreateFmSearchDialog( &m_pShell->GetViewShell()->GetViewFrame()->GetWindow(), strInitialText, aContextNames, nInitialContext, LINK( this, FmXFormShell, OnSearchContextRequest ) );
1639 : DBG_ASSERT( pDialog, "FmXFormShell::ExecuteSearch: could not create the search dialog!" );
1640 0 : if ( pDialog )
1641 : {
1642 0 : pDialog->SetActiveField( strActiveField );
1643 0 : pDialog->SetFoundHandler( LINK( this, FmXFormShell, OnFoundData ) );
1644 0 : pDialog->SetCanceledNotFoundHdl( LINK( this, FmXFormShell, OnCanceledNotFound ) );
1645 0 : pDialog->Execute();
1646 0 : delete pDialog;
1647 : }
1648 :
1649 : // GridControls wieder restaurieren
1650 0 : LoopGrids(GA_ENABLE_SYNC | GA_DISABLE_ROCTRLR);
1651 :
1652 0 : m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
1653 : // da ich in OnFoundData (fals ich dort war) Controls markiert habe
1654 : }
1655 :
1656 : //------------------------------------------------------------------------------
1657 0 : sal_Bool FmXFormShell::GetY2KState(sal_uInt16& n)
1658 : {
1659 0 : if ( impl_checkDisposed() )
1660 0 : return sal_False;
1661 :
1662 0 : if (m_pShell->IsDesignMode())
1663 : // im Design-Modus (ohne aktive Controls) soll sich das Haupt-Dokument darum kuemmern
1664 0 : return sal_False;
1665 :
1666 0 : Reference< XForm> xForm( getActiveForm());
1667 0 : if (!xForm.is())
1668 : // kein aktuelles Formular (also insbesondere kein aktuelles Control) -> das Haupt-Dokument soll sich kuemmern
1669 0 : return sal_False;
1670 :
1671 0 : Reference< XRowSet> xDB(xForm, UNO_QUERY);
1672 : DBG_ASSERT(xDB.is(), "FmXFormShell::GetY2KState : current form has no dbform-interface !");
1673 :
1674 0 : Reference< XNumberFormatsSupplier> xSupplier( getNumberFormats(OStaticDataAccessTools().getRowSetConnection(xDB), sal_False));
1675 0 : if (xSupplier.is())
1676 : {
1677 0 : Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
1678 0 : if (xSet.is())
1679 : {
1680 : try
1681 : {
1682 0 : Any aVal( xSet->getPropertyValue(::rtl::OUString("TwoDigitDateStart")) );
1683 0 : aVal >>= n;
1684 0 : return sal_True;
1685 : }
1686 0 : catch(Exception&)
1687 : {
1688 : }
1689 :
1690 0 : }
1691 : }
1692 0 : return sal_False;
1693 : }
1694 :
1695 : //------------------------------------------------------------------------------
1696 0 : void FmXFormShell::SetY2KState(sal_uInt16 n)
1697 : {
1698 0 : if ( impl_checkDisposed() )
1699 : return;
1700 :
1701 0 : Reference< XForm > xActiveForm( getActiveForm());
1702 0 : Reference< XRowSet > xActiveRowSet( xActiveForm, UNO_QUERY );
1703 0 : if ( xActiveRowSet.is() )
1704 : {
1705 0 : Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( getRowSetConnection( xActiveRowSet ), sal_False ) );
1706 0 : if (xSupplier.is())
1707 : {
1708 0 : Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
1709 0 : if (xSet.is())
1710 : {
1711 : try
1712 : {
1713 0 : Any aVal;
1714 0 : aVal <<= n;
1715 0 : xSet->setPropertyValue(::rtl::OUString("TwoDigitDateStart"), aVal);
1716 : }
1717 0 : catch(Exception&)
1718 : {
1719 : OSL_FAIL("FmXFormShell::SetY2KState: Exception occurred!");
1720 : }
1721 :
1722 : }
1723 0 : return;
1724 0 : }
1725 : }
1726 :
1727 : // kein aktives Formular gefunden -> alle aktuell vorhandenen Formulare durchiterieren
1728 0 : Reference< XIndexAccess> xCurrentForms( m_xForms);
1729 0 : if (!xCurrentForms.is())
1730 : { // im alive-Modus sind meine Forms nicht gesetzt, wohl aber die an der Page
1731 0 : if (m_pShell->GetCurPage())
1732 0 : xCurrentForms = Reference< XIndexAccess>( m_pShell->GetCurPage()->GetForms( false ), UNO_QUERY );
1733 : }
1734 0 : if (!xCurrentForms.is())
1735 : return;
1736 :
1737 0 : ::comphelper::IndexAccessIterator aIter(xCurrentForms);
1738 0 : Reference< XInterface> xCurrentElement( aIter.Next());
1739 0 : while (xCurrentElement.is())
1740 : {
1741 : // ist das aktuelle Element eine DatabaseForm ?
1742 0 : Reference< XRowSet> xElementAsRowSet( xCurrentElement, UNO_QUERY );
1743 0 : if ( xElementAsRowSet.is() )
1744 : {
1745 0 : Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( getRowSetConnection( xElementAsRowSet ), sal_False ) );
1746 0 : if (!xSupplier.is())
1747 0 : continue;
1748 :
1749 0 : Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
1750 0 : if (xSet.is())
1751 : {
1752 : try
1753 : {
1754 0 : Any aVal;
1755 0 : aVal <<= n;
1756 0 : xSet->setPropertyValue(::rtl::OUString("TwoDigitDateStart"), aVal);
1757 : }
1758 0 : catch(Exception&)
1759 : {
1760 : OSL_FAIL("FmXFormShell::SetY2KState: Exception occurred!");
1761 : }
1762 :
1763 0 : }
1764 : }
1765 0 : xCurrentElement = aIter.Next();
1766 0 : }
1767 : }
1768 :
1769 : //------------------------------------------------------------------------------
1770 63 : void FmXFormShell::CloseExternalFormViewer()
1771 : {
1772 63 : if ( impl_checkDisposed() )
1773 : return;
1774 :
1775 63 : if (!m_xExternalViewController.is())
1776 : return;
1777 :
1778 0 : Reference< ::com::sun::star::frame::XFrame> xExternalViewFrame( m_xExternalViewController->getFrame());
1779 0 : Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
1780 0 : if (!xCommLink.is())
1781 : return;
1782 :
1783 0 : xExternalViewFrame->setComponent(NULL,NULL);
1784 0 : ::comphelper::disposeComponent(xExternalViewFrame);
1785 0 : m_xExternalViewController = NULL;
1786 0 : m_xExtViewTriggerController = NULL;
1787 0 : m_xExternalDisplayedForm = NULL;
1788 : }
1789 :
1790 : //------------------------------------------------------------------------------
1791 0 : Reference< XResultSet> FmXFormShell::getInternalForm(const Reference< XResultSet>& _xForm) const
1792 : {
1793 0 : if ( impl_checkDisposed() )
1794 0 : return NULL;
1795 :
1796 0 : Reference< runtime::XFormController> xExternalCtrlr(m_xExternalViewController, UNO_QUERY);
1797 0 : if (xExternalCtrlr.is() && (_xForm == xExternalCtrlr->getModel()))
1798 : {
1799 : DBG_ASSERT(m_xExternalDisplayedForm.is(), "FmXFormShell::getInternalForm : invalid external form !");
1800 0 : return m_xExternalDisplayedForm;
1801 : }
1802 0 : return _xForm;
1803 : }
1804 :
1805 : //------------------------------------------------------------------------------
1806 0 : Reference< XForm> FmXFormShell::getInternalForm(const Reference< XForm>& _xForm) const
1807 : {
1808 0 : if ( impl_checkDisposed() )
1809 0 : return NULL;
1810 :
1811 0 : Reference< runtime::XFormController > xExternalCtrlr(m_xExternalViewController, UNO_QUERY);
1812 0 : if (xExternalCtrlr.is() && (_xForm == xExternalCtrlr->getModel()))
1813 : {
1814 : DBG_ASSERT(m_xExternalDisplayedForm.is(), "FmXFormShell::getInternalForm : invalid external form !");
1815 0 : return Reference< XForm>(m_xExternalDisplayedForm, UNO_QUERY);
1816 : }
1817 0 : return _xForm;
1818 : }
1819 :
1820 : //------------------------------------------------------------------------
1821 : namespace
1822 : {
1823 0 : static bool lcl_isNavigationRelevant( sal_Int32 _nWhich )
1824 : {
1825 : return ( _nWhich == SID_FM_RECORD_FIRST )
1826 : || ( _nWhich == SID_FM_RECORD_PREV )
1827 : || ( _nWhich == SID_FM_RECORD_NEXT )
1828 : || ( _nWhich == SID_FM_RECORD_LAST )
1829 0 : || ( _nWhich == SID_FM_RECORD_NEW );
1830 : }
1831 : }
1832 :
1833 : //------------------------------------------------------------------------------
1834 0 : bool FmXFormShell::IsFormSlotEnabled( sal_Int32 _nSlot, FeatureState* _pCompleteState )
1835 : {
1836 : const ::svx::ControllerFeatures& rController =
1837 0 : lcl_isNavigationRelevant( _nSlot )
1838 : ? getNavControllerFeatures()
1839 0 : : getActiveControllerFeatures();
1840 :
1841 0 : if ( !_pCompleteState )
1842 0 : return rController->isEnabled( _nSlot );
1843 :
1844 0 : rController->getState( _nSlot, *_pCompleteState );
1845 0 : return _pCompleteState->Enabled;
1846 : }
1847 :
1848 : //------------------------------------------------------------------------------
1849 0 : void FmXFormShell::ExecuteFormSlot( sal_Int32 _nSlot )
1850 : {
1851 : const ::svx::ControllerFeatures& rController =
1852 0 : lcl_isNavigationRelevant( _nSlot )
1853 : ? getNavControllerFeatures()
1854 0 : : getActiveControllerFeatures();
1855 :
1856 0 : rController->execute( _nSlot );
1857 :
1858 0 : if ( _nSlot == SID_FM_RECORD_UNDO )
1859 : {
1860 : // if we're doing an UNDO, *and* if the affected form is the form which we also display
1861 : // as external view, then we need to reset the controls of the external form, too
1862 0 : if ( getInternalForm( getActiveForm() ) == m_xExternalDisplayedForm )
1863 : {
1864 0 : Reference< XIndexAccess > xContainer( m_xExternalDisplayedForm, UNO_QUERY );
1865 0 : if ( xContainer.is() )
1866 : {
1867 0 : Reference< XReset > xReset;
1868 0 : for ( sal_Int32 i = 0; i < xContainer->getCount(); ++i )
1869 : {
1870 0 : if ( ( xContainer->getByIndex( i ) >>= xReset ) && xReset.is() )
1871 : {
1872 : // no resets on sub forms
1873 0 : Reference< XForm > xAsForm( xReset, UNO_QUERY );
1874 0 : if ( !xAsForm.is() )
1875 0 : xReset->reset();
1876 : }
1877 0 : }
1878 0 : }
1879 : }
1880 : }
1881 0 : }
1882 :
1883 : //------------------------------------------------------------------------------
1884 63 : void FmXFormShell::impl_switchActiveControllerListening( const bool _bListen )
1885 : {
1886 63 : Reference< XComponent> xComp( m_xActiveController, UNO_QUERY );
1887 63 : if ( !xComp.is() )
1888 63 : return;
1889 :
1890 0 : if ( _bListen )
1891 0 : xComp->addEventListener( (XFormControllerListener*)this );
1892 : else
1893 0 : xComp->removeEventListener( (XFormControllerListener*)this );
1894 : }
1895 :
1896 : //------------------------------------------------------------------------------
1897 2 : void FmXFormShell::setActiveController( const Reference< runtime::XFormController >& xController, sal_Bool _bNoSaveOldContent )
1898 : {
1899 2 : if ( impl_checkDisposed() )
1900 0 : return;
1901 :
1902 2 : if (m_bChangingDesignMode)
1903 0 : return;
1904 : DBG_ASSERT(!m_pShell->IsDesignMode(), "nur im alive mode verwenden");
1905 :
1906 : // Ist die Routine ein zweites Mal gerufen worden,
1907 : // dann sollte der Focus nicht mehr umgesetzt werden
1908 2 : if (m_bInActivate)
1909 : {
1910 0 : m_bSetFocus = xController != m_xActiveController;
1911 0 : return;
1912 : }
1913 :
1914 2 : if (xController != m_xActiveController)
1915 : {
1916 0 : ::osl::ClearableMutexGuard aGuard(m_aAsyncSafety);
1917 : // switch all nav dispatchers belonging to the form of the current nav controller to 'non active'
1918 0 : Reference< XResultSet> xNavigationForm;
1919 0 : if (m_xNavigationController.is())
1920 0 : xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
1921 0 : aGuard.clear();
1922 :
1923 0 : m_bInActivate = sal_True;
1924 :
1925 : // check if the 2 controllers serve different forms
1926 0 : Reference< XResultSet> xOldForm;
1927 0 : if (m_xActiveController.is())
1928 0 : xOldForm = Reference< XResultSet>(m_xActiveController->getModel(), UNO_QUERY);
1929 0 : Reference< XResultSet> xNewForm;
1930 0 : if (xController.is())
1931 0 : xNewForm = Reference< XResultSet>(xController->getModel(), UNO_QUERY);
1932 0 : xOldForm = getInternalForm(xOldForm);
1933 0 : xNewForm = getInternalForm(xNewForm);
1934 :
1935 0 : sal_Bool bDifferentForm = ( xOldForm.get() != xNewForm.get() );
1936 0 : sal_Bool bNeedSave = bDifferentForm && !_bNoSaveOldContent;
1937 : // we save the content of the old form if we move to a new form, and saving old content is allowed
1938 :
1939 0 : if ( m_xActiveController.is() && bNeedSave )
1940 : {
1941 : // beim Wechsel des Controllers den Inhalt speichern, ein Commit
1942 : // wurde bereits ausgefuehrt
1943 0 : if ( m_aActiveControllerFeatures->commitCurrentControl() )
1944 : {
1945 0 : m_bSetFocus = sal_True;
1946 0 : if ( m_aActiveControllerFeatures->isModifiedRow() )
1947 : {
1948 0 : sal_Bool bIsNew = m_aActiveControllerFeatures->isInsertionRow();
1949 0 : sal_Bool bResult = m_aActiveControllerFeatures->commitCurrentRecord();
1950 0 : if ( !bResult && m_bSetFocus )
1951 : {
1952 : // if we couldn't save the current record, set the focus back to the
1953 : // current control
1954 0 : Reference< XWindow > xWindow( m_xActiveController->getCurrentControl(), UNO_QUERY );
1955 0 : if ( xWindow.is() )
1956 0 : xWindow->setFocus();
1957 0 : m_bInActivate = sal_False;
1958 0 : return;
1959 : }
1960 0 : else if ( bResult && bIsNew )
1961 : {
1962 0 : Reference< XResultSet > xCursor( m_aActiveControllerFeatures->getCursor().get() );
1963 0 : if ( xCursor.is() )
1964 : {
1965 0 : DO_SAFE( xCursor->last(); );
1966 0 : }
1967 : }
1968 : }
1969 : }
1970 : }
1971 :
1972 0 : stopListening();
1973 :
1974 0 : impl_switchActiveControllerListening( false );
1975 :
1976 0 : m_aActiveControllerFeatures.dispose();
1977 0 : m_xActiveController = xController;
1978 0 : if ( m_xActiveController.is() )
1979 0 : m_aActiveControllerFeatures.assign( m_xActiveController );
1980 :
1981 0 : impl_switchActiveControllerListening( true );
1982 :
1983 0 : if ( m_xActiveController.is() )
1984 0 : m_xActiveForm = getInternalForm( Reference< XForm >( m_xActiveController->getModel(), UNO_QUERY ) );
1985 : else
1986 0 : m_xActiveForm = NULL;
1987 :
1988 0 : startListening();
1989 :
1990 : // activate all dispatchers belonging to form of the new navigation controller
1991 0 : xNavigationForm = NULL;
1992 0 : if (m_xNavigationController.is())
1993 0 : xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
1994 :
1995 0 : m_bInActivate = sal_False;
1996 :
1997 0 : m_pShell->UIFeatureChanged();
1998 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
1999 :
2000 0 : InvalidateSlot(SID_FM_FILTER_NAVIGATOR_CONTROL, sal_True);
2001 : }
2002 : }
2003 :
2004 : //------------------------------------------------------------------------------
2005 0 : void FmXFormShell::getCurrentSelection( InterfaceBag& /* [out] */ _rSelection ) const
2006 : {
2007 0 : _rSelection = m_aCurrentSelection;
2008 0 : }
2009 :
2010 : //------------------------------------------------------------------------------
2011 0 : bool FmXFormShell::setCurrentSelectionFromMark( const SdrMarkList& _rMarkList )
2012 : {
2013 0 : m_aLastKnownMarkedControls.clear();
2014 :
2015 0 : if ( ( _rMarkList.GetMarkCount() > 0 ) && isControlList( _rMarkList ) )
2016 0 : collectInterfacesFromMarkList( _rMarkList, m_aLastKnownMarkedControls );
2017 :
2018 0 : return setCurrentSelection( m_aLastKnownMarkedControls );
2019 : }
2020 :
2021 : //------------------------------------------------------------------------------
2022 0 : bool FmXFormShell::selectLastMarkedControls()
2023 : {
2024 0 : return setCurrentSelection( m_aLastKnownMarkedControls );
2025 : }
2026 :
2027 : //------------------------------------------------------------------------------
2028 0 : bool FmXFormShell::setCurrentSelection( const InterfaceBag& _rSelection )
2029 : {
2030 0 : if ( impl_checkDisposed() )
2031 0 : return false;
2032 :
2033 : DBG_ASSERT( m_pShell->IsDesignMode(), "FmXFormShell::setCurrentSelection: only to be used in design mode!" );
2034 :
2035 0 : if ( _rSelection.empty() && m_aCurrentSelection.empty() )
2036 : // nothing to do
2037 0 : return false;
2038 :
2039 0 : if ( _rSelection.size() == m_aCurrentSelection.size() )
2040 : {
2041 0 : InterfaceBag::const_iterator aNew = _rSelection.begin();
2042 0 : InterfaceBag::const_iterator aOld = m_aCurrentSelection.begin();
2043 0 : for ( ; aNew != _rSelection.end(); ++aNew, ++aOld )
2044 : {
2045 : OSL_ENSURE( Reference< XInterface >( *aNew, UNO_QUERY ).get() == aNew->get(), "FmXFormShell::setCurrentSelection: new interface not normalized!" );
2046 : OSL_ENSURE( Reference< XInterface >( *aOld, UNO_QUERY ).get() == aOld->get(), "FmXFormShell::setCurrentSelection: old interface not normalized!" );
2047 :
2048 0 : if ( aNew->get() != aOld->get() )
2049 0 : break;
2050 : }
2051 :
2052 0 : if ( aNew == _rSelection.end() )
2053 : // both bags equal
2054 0 : return false;
2055 : }
2056 :
2057 : // the following is some strange code to ensure that when you have two grid controls in a document,
2058 : // only one of them can have a selected column.
2059 : // TODO: this should happen elsewhere, but not here - shouldn't it?
2060 0 : if ( !m_aCurrentSelection.empty() )
2061 : {
2062 0 : Reference< XChild > xCur; if ( m_aCurrentSelection.size() == 1 ) xCur = xCur.query( *m_aCurrentSelection.begin() );
2063 0 : Reference< XChild > xNew; if ( _rSelection.size() == 1 ) xNew = xNew.query( *_rSelection.begin() );
2064 :
2065 : // is there nothing to be selected, or the parents differ, and the parent of the current object
2066 : // is a selection supplier, then deselect
2067 0 : if ( xCur.is() && ( !xNew.is() || ( xCur->getParent() != xNew->getParent() ) ) )
2068 : {
2069 0 : Reference< XSelectionSupplier > xSel( xCur->getParent(), UNO_QUERY );
2070 0 : if ( xSel.is() )
2071 0 : xSel->select( Any() );
2072 0 : }
2073 : }
2074 :
2075 0 : m_aCurrentSelection = _rSelection;
2076 :
2077 : // determine the form which all the selected obj�cts belong to, if any
2078 0 : Reference< XForm > xNewCurrentForm;
2079 0 : for ( InterfaceBag::const_iterator loop = m_aCurrentSelection.begin();
2080 0 : loop != m_aCurrentSelection.end();
2081 : ++loop
2082 : )
2083 : {
2084 0 : Reference< XForm > xThisRoundsForm( GetForm( *loop ) );
2085 : OSL_ENSURE( xThisRoundsForm.is(), "FmXFormShell::setCurrentSelection: *everything* should belong to a form!" );
2086 :
2087 0 : if ( !xNewCurrentForm.is() )
2088 : { // the first form we encounterd
2089 0 : xNewCurrentForm = xThisRoundsForm;
2090 : }
2091 0 : else if ( xNewCurrentForm != xThisRoundsForm )
2092 : { // different forms -> no "current form" at all
2093 0 : xNewCurrentForm.clear();
2094 : break;
2095 : }
2096 0 : }
2097 :
2098 0 : if ( !m_aCurrentSelection.empty() )
2099 0 : impl_updateCurrentForm( xNewCurrentForm );
2100 :
2101 : // ensure some slots are updated
2102 0 : for ( size_t i = 0; i < sizeof( SelObjectSlotMap ) / sizeof( SelObjectSlotMap[0] ); ++i )
2103 0 : InvalidateSlot( SelObjectSlotMap[i], sal_False);
2104 :
2105 0 : return true;
2106 : }
2107 :
2108 : //------------------------------------------------------------------------------
2109 0 : bool FmXFormShell::isSolelySelected( const Reference< XInterface >& _rxObject )
2110 : {
2111 0 : return ( m_aCurrentSelection.size() == 1 ) && ( *m_aCurrentSelection.begin() == _rxObject );
2112 : }
2113 :
2114 : //------------------------------------------------------------------------------
2115 0 : void FmXFormShell::forgetCurrentForm()
2116 : {
2117 0 : if ( !m_xCurrentForm.is() )
2118 0 : return;
2119 :
2120 : // reset ...
2121 0 : impl_updateCurrentForm( NULL );
2122 :
2123 : // ... and try finding a new current form
2124 : // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
2125 0 : impl_defaultCurrentForm_nothrow();
2126 : }
2127 :
2128 : //------------------------------------------------------------------------------
2129 0 : void FmXFormShell::impl_updateCurrentForm( const Reference< XForm >& _rxNewCurForm )
2130 : {
2131 0 : if ( impl_checkDisposed() )
2132 0 : return;
2133 :
2134 0 : m_xCurrentForm = _rxNewCurForm;
2135 :
2136 : // propagate to the FormPage(Impl)
2137 0 : FmFormPage* pPage = m_pShell->GetCurPage();
2138 0 : if ( pPage )
2139 0 : pPage->GetImpl().setCurForm( m_xCurrentForm );
2140 :
2141 : // ensure the UI which depends on the current form is up-to-date
2142 0 : for ( size_t i = 0; i < sizeof( DlgSlotMap ) / sizeof( DlgSlotMap[0] ); ++i )
2143 0 : InvalidateSlot( DlgSlotMap[i], sal_False );
2144 : }
2145 :
2146 : //------------------------------------------------------------------------------
2147 0 : void FmXFormShell::startListening()
2148 : {
2149 0 : if ( impl_checkDisposed() )
2150 : return;
2151 :
2152 0 : Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY);
2153 0 : if (xDatabaseForm.is() && getRowSetConnection(xDatabaseForm).is())
2154 : {
2155 0 : Reference< XPropertySet> xActiveFormSet(m_xActiveForm, UNO_QUERY);
2156 0 : if (xActiveFormSet.is())
2157 : {
2158 : // wenn es eine Datenquelle gibt, dann den Listener aufbauen
2159 : // TODO: this is strange - shouldn't this depend on a isLoaded instead of
2160 : // a "has command value"? Finally, the command value only means that it was
2161 : // intended to be loaded, not that it actually *is* loaded
2162 0 : ::rtl::OUString aSource = ::comphelper::getString(xActiveFormSet->getPropertyValue(FM_PROP_COMMAND));
2163 0 : if (!aSource.isEmpty())
2164 : {
2165 0 : m_bDatabaseBar = sal_True;
2166 :
2167 0 : xActiveFormSet->getPropertyValue(FM_PROP_NAVIGATION) >>= m_eNavigate;
2168 :
2169 0 : switch (m_eNavigate)
2170 : {
2171 : case NavigationBarMode_PARENT:
2172 : {
2173 : // suchen des Controllers, ueber den eine Navigation moeglich ist
2174 0 : Reference< XChild> xChild(m_xActiveController, UNO_QUERY);
2175 0 : Reference< runtime::XFormController > xParent;
2176 0 : while (xChild.is())
2177 : {
2178 0 : xChild = Reference< XChild>(xChild->getParent(), UNO_QUERY);
2179 0 : xParent = Reference< runtime::XFormController >(xChild, UNO_QUERY);
2180 0 : Reference< XPropertySet> xParentSet;
2181 0 : if (xParent.is())
2182 0 : xParentSet = Reference< XPropertySet>(xParent->getModel(), UNO_QUERY);
2183 0 : if (xParentSet.is())
2184 : {
2185 0 : xParentSet->getPropertyValue(FM_PROP_NAVIGATION) >>= m_eNavigate;
2186 0 : if (m_eNavigate == NavigationBarMode_CURRENT)
2187 : break;
2188 : }
2189 0 : }
2190 0 : m_xNavigationController = xParent;
2191 : }
2192 0 : break;
2193 :
2194 : case NavigationBarMode_CURRENT:
2195 0 : m_xNavigationController = m_xActiveController;
2196 0 : break;
2197 :
2198 : default:
2199 0 : m_xNavigationController = NULL;
2200 0 : m_bDatabaseBar = sal_False;
2201 : }
2202 :
2203 0 : m_aNavControllerFeatures.dispose();
2204 0 : if ( m_xNavigationController.is() && ( m_xNavigationController != m_xActiveController ) )
2205 0 : m_aNavControllerFeatures.assign( m_xNavigationController );
2206 :
2207 : // an dem Controller, der die Navigation regelt, wg. RecordCount lauschen
2208 0 : Reference< XPropertySet> xNavigationSet;
2209 0 : if (m_xNavigationController.is())
2210 : {
2211 0 : xNavigationSet = Reference< XPropertySet>(m_xNavigationController->getModel(), UNO_QUERY);
2212 0 : if (xNavigationSet.is())
2213 0 : xNavigationSet->addPropertyChangeListener(FM_PROP_ROWCOUNT,this);
2214 : }
2215 0 : return;
2216 0 : }
2217 0 : }
2218 : }
2219 :
2220 0 : m_eNavigate = NavigationBarMode_NONE;
2221 0 : m_bDatabaseBar = sal_False;
2222 0 : m_xNavigationController = NULL;
2223 : }
2224 :
2225 : //------------------------------------------------------------------------------
2226 0 : void FmXFormShell::stopListening()
2227 : {
2228 0 : if ( impl_checkDisposed() )
2229 0 : return;
2230 :
2231 0 : Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY);
2232 0 : if ( xDatabaseForm.is() )
2233 : {
2234 0 : if (m_xNavigationController.is())
2235 : {
2236 0 : Reference< XPropertySet> xSet(m_xNavigationController->getModel(), UNO_QUERY);
2237 0 : if (xSet.is())
2238 0 : xSet->removePropertyChangeListener(FM_PROP_ROWCOUNT, this);
2239 :
2240 : }
2241 : }
2242 :
2243 0 : m_bDatabaseBar = sal_False;
2244 0 : m_eNavigate = NavigationBarMode_NONE;
2245 0 : m_xNavigationController = NULL;
2246 : }
2247 :
2248 : //------------------------------------------------------------------------------
2249 0 : void FmXFormShell::ShowSelectionProperties( sal_Bool bShow )
2250 : {
2251 0 : if ( impl_checkDisposed() )
2252 0 : return;
2253 :
2254 : // if the window is already visible, only update the state
2255 0 : sal_Bool bHasChild = m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_SHOW_PROPERTIES );
2256 0 : if ( bHasChild && bShow )
2257 0 : UpdateSlot( SID_FM_PROPERTY_CONTROL );
2258 :
2259 : // else toggle state
2260 : else
2261 0 : m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
2262 :
2263 0 : InvalidateSlot( SID_FM_PROPERTIES, sal_False );
2264 0 : InvalidateSlot( SID_FM_CTL_PROPERTIES, sal_False );
2265 : }
2266 :
2267 : //------------------------------------------------------------------------------
2268 0 : IMPL_LINK(FmXFormShell, OnFoundData, FmFoundRecordInformation*, pfriWhere)
2269 : {
2270 0 : if ( impl_checkDisposed() )
2271 0 : return 0;
2272 :
2273 : DBG_ASSERT((pfriWhere->nContext >= 0) && (pfriWhere->nContext < (sal_Int16)m_aSearchForms.size()),
2274 : "FmXFormShell::OnFoundData : ungueltiger Kontext !");
2275 0 : Reference< XForm> xForm( m_aSearchForms.at(pfriWhere->nContext));
2276 : DBG_ASSERT(xForm.is(), "FmXFormShell::OnFoundData : ungueltige Form !");
2277 :
2278 0 : Reference< XRowLocate> xCursor(xForm, UNO_QUERY);
2279 0 : if (!xCursor.is())
2280 0 : return 0; // was soll ich da machen ?
2281 :
2282 : // zum Datensatz
2283 : try
2284 : {
2285 0 : xCursor->moveToBookmark(pfriWhere->aPosition);
2286 : }
2287 0 : catch(const SQLException&)
2288 : {
2289 : OSL_FAIL("Can position on bookmark!");
2290 : }
2291 :
2292 0 : LoopGrids(GA_FORCE_SYNC);
2293 :
2294 : // und zum Feld (dazu habe ich vor dem Start des Suchens die XVclComponent-Interfaces eingesammelt)
2295 : SAL_WARN_IF(static_cast<size_t>(pfriWhere->nFieldPos) >=
2296 : m_arrSearchedControls.size(),
2297 : "svx.form", "FmXFormShell::OnFoundData : invalid index!");
2298 0 : SdrObject* pObject = m_arrSearchedControls.at(pfriWhere->nFieldPos);
2299 :
2300 0 : m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
2301 0 : m_pShell->GetFormView()->MarkObj(pObject, m_pShell->GetFormView()->GetSdrPageView());
2302 :
2303 0 : FmFormObj* pFormObject = FmFormObj::GetFormObject( pObject );
2304 0 : Reference< XControlModel > xControlModel( pFormObject ? pFormObject->GetUnoControlModel() : Reference< XControlModel >() );
2305 : DBG_ASSERT( xControlModel.is(), "FmXFormShell::OnFoundData: invalid control!" );
2306 0 : if ( !xControlModel.is() )
2307 0 : return 0;
2308 :
2309 : // disable the permanent cursor for the last grid we found a record
2310 0 : if (m_xLastGridFound.is() && (m_xLastGridFound != xControlModel))
2311 : {
2312 0 : Reference< XPropertySet> xOldSet(m_xLastGridFound, UNO_QUERY);
2313 0 : xOldSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, makeAny( (sal_Bool)sal_False ) );
2314 0 : Reference< XPropertyState> xOldSetState(xOldSet, UNO_QUERY);
2315 0 : if (xOldSetState.is())
2316 0 : xOldSetState->setPropertyToDefault(FM_PROP_CURSORCOLOR);
2317 : else
2318 0 : xOldSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any());
2319 : }
2320 :
2321 : // wenn das Feld sich in einem GridControl befindet, muss ich dort noch in die entsprechende Spalte gehen
2322 0 : sal_Int32 nGridColumn = m_arrRelativeGridColumn[pfriWhere->nFieldPos];
2323 0 : if (nGridColumn != -1)
2324 : { // dummer weise muss ich mir das Control erst wieder besorgen
2325 0 : Reference< XControl> xControl( impl_getControl( xControlModel, *pFormObject ) );
2326 0 : Reference< XGrid> xGrid(xControl, UNO_QUERY);
2327 : DBG_ASSERT(xGrid.is(), "FmXFormShell::OnFoundData : ungueltiges Control !");
2328 : // wenn eine der Asserts anschlaegt, habe ich beim Aufbauen von m_arrSearchedControls wohl was falsch gemacht
2329 :
2330 : // enable a permanent cursor for the grid so we can see the found text
2331 0 : Reference< XPropertySet> xModelSet(xControlModel, UNO_QUERY);
2332 : DBG_ASSERT(xModelSet.is(), "FmXFormShell::OnFoundData : invalid control model (no property set) !");
2333 0 : xModelSet->setPropertyValue( FM_PROP_ALWAYSSHOWCURSOR, makeAny( (sal_Bool)sal_True ) );
2334 0 : xModelSet->setPropertyValue( FM_PROP_CURSORCOLOR, makeAny( sal_Int32( COL_LIGHTRED ) ) );
2335 0 : m_xLastGridFound = xControlModel;
2336 :
2337 0 : if ( xGrid.is() )
2338 0 : xGrid->setCurrentColumnPosition((sal_Int16)nGridColumn);
2339 : }
2340 :
2341 : // als der Cursor neu positioniert wurde, habe ich (in positioned) meine Formularleisten-Slots invalidiert, aber das greift
2342 : // hier dummerweise nicht, da i.A. ja der (modale) Suchdialog oben ist ... also Gewalt ...
2343 0 : sal_uInt16 nPos = 0;
2344 0 : while (DatabaseSlotMap[nPos])
2345 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update(DatabaseSlotMap[nPos++]);
2346 : // leider geht das Update im Gegensatz zum Invalidate nur mit einzelnen Slots)
2347 :
2348 0 : return 0;
2349 : }
2350 :
2351 : //------------------------------------------------------------------------------
2352 0 : IMPL_LINK(FmXFormShell, OnCanceledNotFound, FmFoundRecordInformation*, pfriWhere)
2353 : {
2354 0 : if ( impl_checkDisposed() )
2355 0 : return 0;
2356 :
2357 : DBG_ASSERT((pfriWhere->nContext >= 0) && (pfriWhere->nContext < (sal_Int16)m_aSearchForms.size()),
2358 : "FmXFormShell::OnCanceledNotFound : ungueltiger Kontext !");
2359 0 : Reference< XForm> xForm( m_aSearchForms.at(pfriWhere->nContext));
2360 : DBG_ASSERT(xForm.is(), "FmXFormShell::OnCanceledNotFound : ungueltige Form !");
2361 :
2362 0 : Reference< XRowLocate> xCursor(xForm, UNO_QUERY);
2363 0 : if (!xCursor.is())
2364 0 : return 0; // was soll ich da machen ?
2365 :
2366 : // zum Datensatz
2367 : try
2368 : {
2369 0 : xCursor->moveToBookmark(pfriWhere->aPosition);
2370 : }
2371 0 : catch(const SQLException&)
2372 : {
2373 : OSL_FAIL("Can position on bookmark!");
2374 : }
2375 :
2376 :
2377 0 : m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
2378 0 : return 0L;
2379 : }
2380 :
2381 : //------------------------------------------------------------------------------
2382 0 : IMPL_LINK(FmXFormShell, OnSearchContextRequest, FmSearchContext*, pfmscContextInfo)
2383 : {
2384 0 : if ( impl_checkDisposed() )
2385 0 : return 0;
2386 :
2387 : DBG_ASSERT(pfmscContextInfo->nContext < (sal_Int16)m_aSearchForms.size(), "FmXFormShell::OnSearchContextRequest : invalid parameter !");
2388 0 : Reference< XForm> xForm( m_aSearchForms.at(pfmscContextInfo->nContext));
2389 : DBG_ASSERT(xForm.is(), "FmXFormShell::OnSearchContextRequest : unexpected : invalid context !");
2390 :
2391 0 : Reference< XResultSet> xIter(xForm, UNO_QUERY);
2392 : DBG_ASSERT(xIter.is(), "FmXFormShell::OnSearchContextRequest : unexpected : context has no iterator !");
2393 :
2394 : // --------------------------------------------------------------------------------------------
2395 : // assemble the list of fields to involve (that is, the ControlSources of all fields that have such a property)
2396 0 : UniString strFieldList, sFieldDisplayNames;
2397 0 : m_arrSearchedControls.clear();
2398 0 : m_arrRelativeGridColumn.clear();
2399 :
2400 : // small problem: To mark found fields, I need SdrObjects. To determine which controls
2401 : // to include in the search, I need Controls (that is, XControl interfaces). So I have
2402 : // to iterate over one of them and get the other in some way. Unfortunately, there is
2403 : // no direct connexion between the two worlds (except from a GetUnoControl to a
2404 : // SdrUnoObject, but this requires an OutputDevice I can not do anything with.
2405 : // However I can get to the Model from the Control and also from the SdrObject, and in
2406 : // this way the assignment SdrObject<->Control is possible with a double loop.
2407 : // The alternative to this (ugly but certainly not entirely fixable) solution would be
2408 : // to renounce the caching of the SdrObjects, which would lead to significant extra
2409 : // work in OnFoundData (since there I'd have to get the SdrObject first thing every
2410 : // time). But since OnFoundData is usually called more often than ExecuteSeearch, I'll
2411 : // do that here.
2412 :
2413 0 : Reference< XNameAccess> xValidFormFields;
2414 0 : Reference< XColumnsSupplier> xSupplyCols(xIter, UNO_QUERY);
2415 : DBG_ASSERT(xSupplyCols.is(), "FmXFormShell::OnSearchContextRequest : invalid cursor : no columns supplier !");
2416 0 : if (xSupplyCols.is())
2417 0 : xValidFormFields = xSupplyCols->getColumns();
2418 : DBG_ASSERT(xValidFormFields.is(), "FmXFormShell::OnSearchContextRequest : form has no fields !");
2419 :
2420 : // current Page/Controller
2421 0 : FmFormPage* pCurrentPage = m_pShell->GetCurPage();
2422 : DBG_ASSERT(pCurrentPage!=NULL, "FmXFormShell::OnSearchContextRequest : no page !");
2423 : // Search all SdrControls of this page...
2424 0 : ::rtl::OUString sControlSource, aName;
2425 :
2426 0 : SdrObjListIter aPageIter( *pCurrentPage );
2427 0 : while ( aPageIter.IsMore() )
2428 : {
2429 0 : SdrObject* pCurrent = aPageIter.Next();
2430 0 : FmFormObj* pFormObject = FmFormObj::GetFormObject( pCurrent );
2431 : // note that in case pCurrent is a virtual object, pFormObject points to the referenced object
2432 :
2433 0 : if ( !pFormObject )
2434 0 : continue;
2435 :
2436 : // the current object's model, in different tastes
2437 0 : Reference< XControlModel> xControlModel( pFormObject->GetUnoControlModel() );
2438 0 : Reference< XFormComponent > xCurrentFormComponent( xControlModel, UNO_QUERY );
2439 : DBG_ASSERT( xCurrentFormComponent.is(), "FmXFormShell::OnSearchContextRequest: invalid objects!" );
2440 0 : if ( !xCurrentFormComponent.is() )
2441 0 : continue;
2442 :
2443 : // does the component belong to the form which we're interested in?
2444 0 : if ( xCurrentFormComponent->getParent() != xForm )
2445 0 : continue;
2446 :
2447 : // ... ask for the ControlSource property
2448 0 : SearchableControlIterator iter( xCurrentFormComponent );
2449 0 : Reference< XControl> xControl;
2450 : // the control that has model xControlModel
2451 : // (the following while can be passed through several times, without the Control
2452 : // being modified, so I don't have to search every time from scratch)
2453 :
2454 0 : Reference< XInterface > xSearchable( iter.Next() );
2455 0 : while ( xSearchable.is() )
2456 : {
2457 0 : sControlSource = iter.getCurrentValue();
2458 0 : if ( sControlSource.isEmpty() )
2459 : {
2460 : // the current element has no ControlSource, so it is a GridControl (that
2461 : // is the only thing that still permits the SearchableControlIteratore)
2462 0 : xControl = impl_getControl( xControlModel, *pFormObject );
2463 : DBG_ASSERT(xControl.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
2464 :
2465 0 : Reference< XGridPeer> xGridPeer;
2466 0 : if ( xControl.is() )
2467 0 : xGridPeer.set( xControl->getPeer(), UNO_QUERY );
2468 : do
2469 : {
2470 0 : if (!xGridPeer.is())
2471 : break;
2472 :
2473 0 : Reference< XIndexAccess> xPeerContainer(xGridPeer, UNO_QUERY);
2474 0 : if (!xPeerContainer.is())
2475 : break;
2476 :
2477 0 : Reference< XIndexAccess> xModelColumns(xGridPeer->getColumns(), UNO_QUERY);
2478 : DBG_ASSERT(xModelColumns.is(), "FmXFormShell::OnSearchContextRequest : there is a grid control without columns !");
2479 : // the case 'no columns' should be indicated with an empty container, I think ...
2480 : DBG_ASSERT(xModelColumns->getCount() >= xPeerContainer->getCount(), "FmXFormShell::OnSearchContextRequest : impossible : have more view than model columns !");
2481 :
2482 0 : Reference< XInterface> xCurrentColumn;
2483 0 : for (sal_Int16 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
2484 : {
2485 0 : xPeerContainer->getByIndex(nViewPos) >>= xCurrentColumn;
2486 0 : if (!xCurrentColumn.is())
2487 0 : continue;
2488 :
2489 : // can we use this column control for searching ?
2490 0 : if (!IsSearchableControl(xCurrentColumn))
2491 0 : continue;
2492 :
2493 0 : sal_Int16 nModelPos = GridView2ModelPos(xModelColumns, nViewPos);
2494 0 : Reference< XPropertySet> xCurrentColModel;
2495 0 : xModelColumns->getByIndex(nModelPos) >>= xCurrentColModel;
2496 0 : aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_CONTROLSOURCE));
2497 : // the cursor has a field matching the control source ?
2498 0 : if (xValidFormFields->hasByName(aName))
2499 : {
2500 0 : strFieldList += aName.getStr();
2501 0 : strFieldList += ';';
2502 :
2503 0 : sFieldDisplayNames += ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_LABEL)).getStr();
2504 0 : sFieldDisplayNames += ';';
2505 :
2506 0 : pfmscContextInfo->arrFields.push_back(xCurrentColumn);
2507 :
2508 : // and the SdrOject to the Field
2509 0 : m_arrSearchedControls.push_back(pCurrent);
2510 : // the number of the column
2511 0 : m_arrRelativeGridColumn.push_back(nViewPos);
2512 : }
2513 0 : }
2514 0 : } while (sal_False);
2515 : }
2516 : else
2517 : {
2518 0 : if (!sControlSource.isEmpty() && xValidFormFields->hasByName(sControlSource))
2519 : {
2520 : // now I need the Control to SdrObject
2521 0 : if (!xControl.is())
2522 : {
2523 0 : xControl = impl_getControl( xControlModel, *pFormObject );
2524 : DBG_ASSERT(xControl.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
2525 : }
2526 :
2527 0 : if (IsSearchableControl(xControl))
2528 : {
2529 : // all tests passed -> take along in the list
2530 0 : strFieldList += sControlSource.getStr();
2531 0 : strFieldList += ';';
2532 :
2533 : // the label which should appear for the control :
2534 0 : sFieldDisplayNames += getLabelName(Reference< XPropertySet>(xControlModel, UNO_QUERY)).getStr();
2535 0 : sFieldDisplayNames += ';';
2536 :
2537 : // mark the SdrObject (accelerates the treatment in OnFoundData)
2538 0 : m_arrSearchedControls.push_back(pCurrent);
2539 :
2540 : // the number of the colum (here a dummy, since it is only interesting for GridControls)
2541 0 : m_arrRelativeGridColumn.push_back(-1);
2542 :
2543 : // and for the formatted search...
2544 0 : pfmscContextInfo->arrFields.push_back(Reference< XInterface>(xControl, UNO_QUERY));
2545 : }
2546 : }
2547 : }
2548 :
2549 0 : xSearchable = iter.Next();
2550 : }
2551 0 : }
2552 :
2553 0 : strFieldList = comphelper::string::stripEnd(strFieldList, ';');
2554 0 : sFieldDisplayNames = comphelper::string::stripEnd(sFieldDisplayNames, ';');
2555 :
2556 0 : if (pfmscContextInfo->arrFields.empty())
2557 : {
2558 0 : pfmscContextInfo->arrFields.clear();
2559 0 : pfmscContextInfo->xCursor = NULL;
2560 0 : pfmscContextInfo->strUsedFields.Erase();
2561 0 : return 0L;
2562 : }
2563 :
2564 0 : pfmscContextInfo->xCursor = xIter;
2565 0 : pfmscContextInfo->strUsedFields = strFieldList;
2566 0 : pfmscContextInfo->sFieldDisplayNames = sFieldDisplayNames;
2567 :
2568 : // 66463 - 31.05.99 - FS
2569 : // when the cursor is a non-STANDARD RecordMode, set it back
2570 0 : Reference< XPropertySet> xCursorSet(pfmscContextInfo->xCursor, UNO_QUERY);
2571 0 : Reference< XResultSetUpdate> xUpdateCursor(pfmscContextInfo->xCursor, UNO_QUERY);
2572 0 : if (xUpdateCursor.is() && xCursorSet.is() && xCursorSet.is())
2573 : {
2574 0 : if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISNEW)))
2575 0 : xUpdateCursor->moveToCurrentRow();
2576 0 : else if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISMODIFIED)))
2577 0 : xUpdateCursor->cancelRowUpdates();
2578 : }
2579 :
2580 0 : return pfmscContextInfo->arrFields.size();
2581 : }
2582 :
2583 : // XContainerListener
2584 : //------------------------------------------------------------------------------
2585 0 : void FmXFormShell::elementInserted(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
2586 : {
2587 0 : if ( impl_checkDisposed() )
2588 0 : return;
2589 :
2590 : // new object to listen to
2591 0 : Reference< XInterface> xTemp;
2592 0 : evt.Element >>= xTemp;
2593 0 : AddElement(xTemp);
2594 0 : m_pShell->DetermineForms(sal_True);
2595 : }
2596 :
2597 : //------------------------------------------------------------------------------
2598 0 : void FmXFormShell::elementReplaced(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
2599 : {
2600 0 : if ( impl_checkDisposed() )
2601 0 : return;
2602 :
2603 0 : Reference< XInterface> xTemp;
2604 0 : evt.ReplacedElement >>= xTemp;
2605 0 : RemoveElement(xTemp);
2606 0 : evt.Element >>= xTemp;
2607 0 : AddElement(xTemp);
2608 : }
2609 :
2610 : //------------------------------------------------------------------------------
2611 0 : void FmXFormShell::elementRemoved(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
2612 : {
2613 0 : if ( impl_checkDisposed() )
2614 0 : return;
2615 :
2616 0 : Reference< XInterface> xTemp;
2617 0 : evt.Element >>= xTemp;
2618 0 : RemoveElement(xTemp);
2619 0 : m_pShell->DetermineForms(sal_True);
2620 : }
2621 :
2622 : //------------------------------------------------------------------------------
2623 708 : void FmXFormShell::UpdateForms( sal_Bool _bInvalidate )
2624 : {
2625 708 : if ( impl_checkDisposed() )
2626 708 : return;
2627 :
2628 708 : Reference< XIndexAccess > xForms;
2629 :
2630 708 : FmFormPage* pPage = m_pShell->GetCurPage();
2631 708 : if ( pPage )
2632 : {
2633 708 : if ( m_pShell->m_bDesignMode )
2634 681 : xForms = xForms.query( pPage->GetForms( false ) );
2635 : }
2636 :
2637 708 : if ( m_xForms != xForms )
2638 : {
2639 0 : RemoveElement( m_xForms );
2640 0 : m_xForms = xForms;
2641 0 : AddElement( m_xForms );
2642 : }
2643 :
2644 708 : m_pShell->DetermineForms( _bInvalidate );
2645 : }
2646 :
2647 : //------------------------------------------------------------------------------
2648 0 : void FmXFormShell::AddElement(const Reference< XInterface>& _xElement)
2649 : {
2650 0 : if ( impl_checkDisposed() )
2651 0 : return;
2652 0 : impl_AddElement_nothrow(_xElement);
2653 : }
2654 : // -----------------------------------------------------------------------------
2655 0 : void FmXFormShell::impl_AddElement_nothrow(const Reference< XInterface>& Element)
2656 : {
2657 : // am Container horchen
2658 0 : const Reference< XIndexContainer> xContainer(Element, UNO_QUERY);
2659 0 : if (xContainer.is())
2660 : {
2661 0 : const sal_uInt32 nCount = xContainer->getCount();
2662 0 : Reference< XInterface> xElement;
2663 0 : for (sal_uInt32 i = 0; i < nCount; ++i)
2664 : {
2665 0 : xElement.set(xContainer->getByIndex(i),UNO_QUERY);
2666 0 : impl_AddElement_nothrow(xElement);
2667 : }
2668 :
2669 0 : const Reference< XContainer> xCont(Element, UNO_QUERY);
2670 0 : if (xCont.is())
2671 0 : xCont->addContainerListener(this);
2672 : }
2673 :
2674 0 : const Reference< ::com::sun::star::view::XSelectionSupplier> xSelSupplier(Element, UNO_QUERY);
2675 0 : if (xSelSupplier.is())
2676 0 : xSelSupplier->addSelectionChangeListener(this);
2677 0 : }
2678 :
2679 : //------------------------------------------------------------------------------
2680 63 : void FmXFormShell::RemoveElement(const Reference< XInterface>& Element)
2681 : {
2682 63 : if ( impl_checkDisposed() )
2683 63 : return;
2684 63 : impl_RemoveElement_nothrow(Element);
2685 : }
2686 : //------------------------------------------------------------------------------
2687 63 : void FmXFormShell::impl_RemoveElement_nothrow(const Reference< XInterface>& Element)
2688 : {
2689 63 : const Reference< ::com::sun::star::view::XSelectionSupplier> xSelSupplier(Element, UNO_QUERY);
2690 63 : if (xSelSupplier.is())
2691 0 : xSelSupplier->removeSelectionChangeListener(this);
2692 :
2693 : // remove connection to children
2694 63 : const Reference< XIndexContainer> xContainer(Element, UNO_QUERY);
2695 63 : if (xContainer.is())
2696 : {
2697 0 : const Reference< XContainer> xCont(Element, UNO_QUERY);
2698 0 : if (xCont.is())
2699 0 : xCont->removeContainerListener(this);
2700 :
2701 0 : const sal_uInt32 nCount = xContainer->getCount();
2702 0 : Reference< XInterface> xElement;
2703 0 : for (sal_uInt32 i = 0; i < nCount; i++)
2704 : {
2705 0 : xElement.set(xContainer->getByIndex(i),UNO_QUERY);
2706 0 : impl_RemoveElement_nothrow(xElement);
2707 0 : }
2708 : }
2709 :
2710 63 : InterfaceBag::iterator wasSelectedPos = m_aCurrentSelection.find( Element );
2711 63 : if ( wasSelectedPos != m_aCurrentSelection.end() )
2712 0 : m_aCurrentSelection.erase( wasSelectedPos );
2713 63 : }
2714 :
2715 : //------------------------------------------------------------------------------
2716 0 : void FmXFormShell::selectionChanged(const EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException)
2717 : {
2718 0 : if ( impl_checkDisposed() )
2719 : return;
2720 :
2721 0 : Reference< XSelectionSupplier > xSupplier( rEvent.Source, UNO_QUERY );
2722 0 : Reference< XInterface > xSelObj( xSupplier->getSelection(), UNO_QUERY );
2723 : // a selection was removed, this can only be done by the shell
2724 0 : if ( !xSelObj.is() )
2725 : return;
2726 :
2727 0 : EnableTrackProperties(sal_False);
2728 :
2729 0 : sal_Bool bMarkChanged = m_pShell->GetFormView()->checkUnMarkAll(rEvent.Source);
2730 0 : Reference< XForm > xNewForm( GetForm( rEvent.Source ) );
2731 :
2732 0 : InterfaceBag aNewSelection;
2733 0 : aNewSelection.insert( Reference< XInterface >( xSelObj, UNO_QUERY ) );
2734 :
2735 0 : if ( setCurrentSelection( aNewSelection ) && IsPropBrwOpen() )
2736 0 : ShowSelectionProperties( sal_True );
2737 :
2738 0 : EnableTrackProperties(sal_True);
2739 :
2740 0 : if ( bMarkChanged )
2741 0 : m_pShell->NotifyMarkListChanged( m_pShell->GetFormView() );
2742 : }
2743 :
2744 : //------------------------------------------------------------------------------
2745 0 : IMPL_LINK(FmXFormShell, OnTimeOut, void*, /*EMPTYTAG*/)
2746 : {
2747 0 : if ( impl_checkDisposed() )
2748 0 : return 0;
2749 :
2750 0 : if (m_pShell->IsDesignMode() && m_pShell->GetFormView())
2751 0 : SetSelection(m_pShell->GetFormView()->GetMarkedObjectList());
2752 :
2753 0 : return 0;
2754 : }
2755 :
2756 : //------------------------------------------------------------------------
2757 0 : void FmXFormShell::SetSelectionDelayed()
2758 : {
2759 0 : if ( impl_checkDisposed() )
2760 0 : return;
2761 :
2762 0 : if (m_pShell->IsDesignMode() && IsTrackPropertiesEnabled() && !m_aMarkTimer.IsActive())
2763 0 : m_aMarkTimer.Start();
2764 : }
2765 :
2766 : //------------------------------------------------------------------------
2767 0 : void FmXFormShell::SetSelection(const SdrMarkList& rMarkList)
2768 : {
2769 0 : if ( impl_checkDisposed() )
2770 0 : return;
2771 :
2772 0 : DetermineSelection(rMarkList);
2773 0 : m_pShell->NotifyMarkListChanged(m_pShell->GetFormView());
2774 : }
2775 :
2776 : //------------------------------------------------------------------------
2777 0 : void FmXFormShell::DetermineSelection(const SdrMarkList& rMarkList)
2778 : {
2779 0 : if ( setCurrentSelectionFromMark( rMarkList ) && IsPropBrwOpen() )
2780 0 : ShowSelectionProperties( sal_True );
2781 0 : }
2782 :
2783 : //------------------------------------------------------------------------------
2784 0 : sal_Bool FmXFormShell::IsPropBrwOpen() const
2785 : {
2786 0 : if ( impl_checkDisposed() )
2787 0 : return sal_False;
2788 :
2789 0 : return( ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() ) ?
2790 0 : m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES) : sal_False );
2791 : }
2792 :
2793 : //------------------------------------------------------------------------------
2794 : class FmXFormShell::SuspendPropertyTracking
2795 : {
2796 : private:
2797 : FmXFormShell& m_rShell;
2798 : sal_Bool m_bEnabled;
2799 :
2800 : public:
2801 236 : SuspendPropertyTracking( FmXFormShell& _rShell )
2802 : :m_rShell( _rShell )
2803 236 : ,m_bEnabled( sal_False )
2804 : {
2805 236 : if ( m_rShell.IsTrackPropertiesEnabled() )
2806 : {
2807 236 : m_rShell.EnableTrackProperties( sal_False );
2808 236 : m_bEnabled = sal_True;
2809 : }
2810 236 : }
2811 :
2812 236 : ~SuspendPropertyTracking( )
2813 : {
2814 236 : if ( m_bEnabled ) // note that ( sal_False != m_bEnabled ) implies ( NULL != m_pShell )
2815 236 : m_rShell.EnableTrackProperties( sal_True );
2816 236 : }
2817 : };
2818 :
2819 : //------------------------------------------------------------------------------
2820 236 : void FmXFormShell::SetDesignMode(sal_Bool bDesign)
2821 : {
2822 236 : if ( impl_checkDisposed() )
2823 236 : return;
2824 :
2825 : DBG_ASSERT(m_pShell->GetFormView(), "FmXFormShell::SetDesignMode : invalid call (have no shell or no view) !");
2826 236 : m_bChangingDesignMode = sal_True;
2827 :
2828 : // 67506 - 15.07.99 - FS
2829 : // if we're switching off the design mode we have to force the property browser to be closed
2830 : // so it can commit it's changes _before_ we load the forms
2831 236 : if (!bDesign)
2832 : {
2833 9 : m_bHadPropertyBrowserInDesignMode = m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES);
2834 9 : if (m_bHadPropertyBrowserInDesignMode)
2835 0 : m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
2836 : }
2837 :
2838 236 : FmFormView* pFormView = m_pShell->GetFormView();
2839 236 : if (bDesign)
2840 : {
2841 : // we are currently filtering, so stop filtering
2842 227 : if (m_bFilterMode)
2843 0 : stopFiltering(sal_False);
2844 :
2845 : // unsubscribe from the objects of my MarkList
2846 227 : pFormView->GetImpl()->stopMarkListWatching();
2847 : }
2848 : else
2849 : {
2850 9 : m_aMarkTimer.Stop();
2851 :
2852 9 : SuspendPropertyTracking aSuspend( *this );
2853 9 : pFormView->GetImpl()->saveMarkList( sal_True );
2854 : }
2855 :
2856 236 : if (bDesign && m_xExternalViewController.is())
2857 0 : CloseExternalFormViewer();
2858 :
2859 236 : pFormView->ChangeDesignMode(bDesign);
2860 :
2861 : // notify listensers
2862 236 : FmDesignModeChangedHint aChangedHint( bDesign );
2863 236 : m_pShell->Broadcast(aChangedHint);
2864 :
2865 236 : m_pShell->m_bDesignMode = bDesign;
2866 236 : UpdateForms( sal_False );
2867 :
2868 236 : m_pTextShell->designModeChanged( m_pShell->m_bDesignMode );
2869 :
2870 236 : if (bDesign)
2871 : {
2872 227 : SdrMarkList aList;
2873 : {
2874 : // during changing the mark list, don't track the selected objects in the property browser
2875 227 : SuspendPropertyTracking aSuspend( *this );
2876 : // restore the marks
2877 227 : pFormView->GetImpl()->restoreMarkList( aList );
2878 : }
2879 :
2880 : // synchronize with the restored mark list
2881 227 : if ( aList.GetMarkCount() )
2882 0 : SetSelection( aList );
2883 : }
2884 : else
2885 : {
2886 : // subscribe to the model of the view (so that I'm informed when someone deletes
2887 : // during the alive mode controls that I had saved in the saveMarklist (60343)
2888 9 : pFormView->GetImpl()->startMarkListWatching();
2889 : }
2890 :
2891 236 : m_pShell->UIFeatureChanged();
2892 :
2893 : // 67506 - 15.07.99 - FS
2894 236 : if (bDesign && m_bHadPropertyBrowserInDesignMode)
2895 : {
2896 : // The UIFeatureChanged performes an update (a check of the available features) asynchronously.
2897 : // So we can't call ShowSelectionProperties directly as the according feature isn't enabled yet.
2898 : // That's why we use an asynchron execution on the dispatcher.
2899 : // (And that's why this has to be done AFTER the UIFeatureChanged.)
2900 0 : m_pShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON );
2901 : }
2902 236 : m_bChangingDesignMode = sal_False;
2903 : }
2904 :
2905 : //------------------------------------------------------------------------------
2906 0 : Reference< XControl> FmXFormShell::impl_getControl( const Reference< XControlModel >& i_rxModel, const FmFormObj& i_rKnownFormObj )
2907 : {
2908 0 : if ( impl_checkDisposed() )
2909 0 : return NULL;
2910 :
2911 0 : Reference< XControl > xControl;
2912 : try
2913 : {
2914 0 : Reference< XControlContainer> xControlContainer( getControlContainerForView(), UNO_SET_THROW );
2915 :
2916 0 : Sequence< Reference< XControl > > seqControls( xControlContainer->getControls() );
2917 0 : const Reference< XControl >* pControls = seqControls.getArray();
2918 : // ... that I can then search
2919 0 : for (sal_Int32 i=0; i<seqControls.getLength(); ++i)
2920 : {
2921 0 : xControl.set( pControls[i], UNO_SET_THROW );
2922 0 : Reference< XControlModel > xCurrentModel( xControl->getModel() );
2923 0 : if ( xCurrentModel == i_rxModel )
2924 : break;
2925 0 : xControl.clear();
2926 0 : }
2927 :
2928 0 : if ( !xControl.is() )
2929 : {
2930 : // fallabck (some controls might not have been created, yet, since they were never visible so far)
2931 0 : Reference< XControl > xContainerControl( xControlContainer, UNO_QUERY_THROW );
2932 0 : const Window* pContainerWindow = VCLUnoHelper::GetWindow( xContainerControl->getPeer() );
2933 0 : ENSURE_OR_THROW( pContainerWindow, "unexpected control container implementation" );
2934 :
2935 0 : const SdrView* pSdrView = m_pShell ? m_pShell->GetFormView() : NULL;
2936 0 : ENSURE_OR_THROW( pSdrView, "no current view" );
2937 :
2938 0 : xControl.set( i_rKnownFormObj.GetUnoControl( *pSdrView, *pContainerWindow ), UNO_QUERY_THROW );
2939 0 : }
2940 : }
2941 0 : catch( const Exception& )
2942 : {
2943 : DBG_UNHANDLED_EXCEPTION();
2944 : }
2945 :
2946 : OSL_ENSURE( xControl.is(), "FmXFormShell::impl_getControl: no control found!" );
2947 0 : return xControl;
2948 : }
2949 :
2950 : //------------------------------------------------------------------------------
2951 0 : void FmXFormShell::impl_collectFormSearchContexts_nothrow( const Reference< XInterface>& _rxStartingPoint,
2952 : const ::rtl::OUString& _rCurrentLevelPrefix, FmFormArray& _out_rForms, ::std::vector< String >& _out_rNames )
2953 : {
2954 : try
2955 : {
2956 0 : Reference< XIndexAccess> xContainer( _rxStartingPoint, UNO_QUERY );
2957 0 : if ( !xContainer.is() )
2958 : return;
2959 :
2960 0 : sal_Int32 nCount( xContainer->getCount() );
2961 0 : if ( nCount == 0 )
2962 : return;
2963 :
2964 0 : ::rtl::OUString sCurrentFormName;
2965 0 : ::rtl::OUStringBuffer aNextLevelPrefix;
2966 0 : for ( sal_Int32 i=0; i<nCount; ++i )
2967 : {
2968 : // is the current child a form?
2969 0 : Reference< XForm > xCurrentAsForm( xContainer->getByIndex(i), UNO_QUERY );
2970 0 : if ( !xCurrentAsForm.is() )
2971 0 : continue;
2972 :
2973 0 : Reference< XNamed > xNamed( xCurrentAsForm, UNO_QUERY_THROW );
2974 0 : sCurrentFormName = xNamed->getName();
2975 :
2976 : // the name of the current form
2977 0 : ::rtl::OUStringBuffer sCompleteCurrentName( sCurrentFormName );
2978 0 : if ( !_rCurrentLevelPrefix.isEmpty() )
2979 : {
2980 0 : sCompleteCurrentName.appendAscii( " (" );
2981 0 : sCompleteCurrentName.append ( _rCurrentLevelPrefix );
2982 0 : sCompleteCurrentName.appendAscii( ")" );
2983 : }
2984 :
2985 : // the prefix for the next level
2986 0 : aNextLevelPrefix = _rCurrentLevelPrefix;
2987 0 : if ( !_rCurrentLevelPrefix.isEmpty() )
2988 0 : aNextLevelPrefix.append( (sal_Unicode)'/' );
2989 0 : aNextLevelPrefix.append( sCurrentFormName );
2990 :
2991 : // remember both the form and it's "display name"
2992 0 : _out_rForms.push_back( xCurrentAsForm );
2993 0 : _out_rNames.push_back( sCompleteCurrentName.makeStringAndClear() );
2994 :
2995 : // und absteigen
2996 0 : impl_collectFormSearchContexts_nothrow( xCurrentAsForm, aNextLevelPrefix.makeStringAndClear(), _out_rForms, _out_rNames );
2997 0 : }
2998 : }
2999 0 : catch( const Exception& )
3000 : {
3001 : DBG_UNHANDLED_EXCEPTION();
3002 : }
3003 : }
3004 :
3005 : //------------------------------------------------------------------------------
3006 0 : void FmXFormShell::startFiltering()
3007 : {
3008 0 : if ( impl_checkDisposed() )
3009 0 : return;
3010 :
3011 : // setting all forms in filter mode
3012 0 : FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
3013 :
3014 : // if the active controller is our external one we have to use the trigger controller
3015 0 : Reference< XControlContainer> xContainer;
3016 0 : if (getActiveController() == m_xExternalViewController)
3017 : {
3018 : DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::startFiltering : inconsistent : active external controller, but noone triggered this !");
3019 0 : xContainer = m_xExtViewTriggerController->getContainer();
3020 : }
3021 : else
3022 0 : xContainer = getActiveController()->getContainer();
3023 :
3024 0 : PFormViewPageWindowAdapter pAdapter = pXView->findWindow( xContainer );
3025 0 : if ( pAdapter.is() )
3026 : {
3027 0 : const ::std::vector< Reference< runtime::XFormController> >& rControllerList = pAdapter->GetList();
3028 0 : for ( ::std::vector< Reference< runtime::XFormController> >::const_iterator j = rControllerList.begin();
3029 0 : j != rControllerList.end();
3030 : ++j
3031 : )
3032 : {
3033 0 : Reference< XModeSelector> xModeSelector(*j, UNO_QUERY);
3034 0 : if (xModeSelector.is())
3035 0 : xModeSelector->setMode( ::rtl::OUString( "FilterMode" ) );
3036 0 : }
3037 : }
3038 :
3039 0 : m_bFilterMode = sal_True;
3040 :
3041 0 : m_pShell->UIFeatureChanged();
3042 0 : SfxViewFrame* pViewFrame = m_pShell->GetViewShell()->GetViewFrame();
3043 0 : pViewFrame->GetBindings().InvalidateShell( *m_pShell );
3044 :
3045 0 : if ( pViewFrame->KnowsChildWindow( SID_FM_FILTER_NAVIGATOR )
3046 0 : && !pViewFrame->HasChildWindow( SID_FM_FILTER_NAVIGATOR )
3047 : )
3048 : {
3049 0 : pViewFrame->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
3050 0 : }
3051 : }
3052 :
3053 : //------------------------------------------------------------------------------
3054 0 : void saveFilter(const Reference< runtime::XFormController >& _rxController)
3055 : {
3056 0 : Reference< XPropertySet> xFormAsSet(_rxController->getModel(), UNO_QUERY);
3057 0 : Reference< XPropertySet> xControllerAsSet(_rxController, UNO_QUERY);
3058 0 : Reference< XIndexAccess> xControllerAsIndex(_rxController, UNO_QUERY);
3059 :
3060 : // call the subcontroller
3061 0 : Reference< runtime::XFormController > xController;
3062 0 : for (sal_Int32 i = 0, nCount = xControllerAsIndex->getCount(); i < nCount; ++i)
3063 : {
3064 0 : xControllerAsIndex->getByIndex(i) >>= xController;
3065 0 : saveFilter(xController);
3066 : }
3067 :
3068 : try
3069 : {
3070 :
3071 0 : xFormAsSet->setPropertyValue(FM_PROP_FILTER, xControllerAsSet->getPropertyValue(FM_PROP_FILTER));
3072 0 : xFormAsSet->setPropertyValue(FM_PROP_APPLYFILTER, makeAny( (sal_Bool)sal_True ) );
3073 : }
3074 0 : catch (const Exception& )
3075 : {
3076 : DBG_UNHANDLED_EXCEPTION();
3077 0 : }
3078 :
3079 0 : }
3080 :
3081 : //------------------------------------------------------------------------------
3082 0 : void FmXFormShell::stopFiltering(sal_Bool bSave)
3083 : {
3084 0 : if ( impl_checkDisposed() )
3085 0 : return;
3086 :
3087 0 : m_bFilterMode = sal_False;
3088 :
3089 0 : FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
3090 :
3091 : // if the active controller is our external one we have to use the trigger controller
3092 0 : Reference< XControlContainer> xContainer;
3093 0 : if (getActiveController() == m_xExternalViewController)
3094 : {
3095 : DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::stopFiltering : inconsistent : active external controller, but noone triggered this !");
3096 0 : xContainer = m_xExtViewTriggerController->getContainer();
3097 : }
3098 : else
3099 0 : xContainer = getActiveController()->getContainer();
3100 :
3101 0 : PFormViewPageWindowAdapter pAdapter = pXView->findWindow(xContainer);
3102 0 : if ( pAdapter.is() )
3103 : {
3104 0 : const ::std::vector< Reference< runtime::XFormController > >& rControllerList = pAdapter->GetList();
3105 0 : ::std::vector < ::rtl::OUString > aOriginalFilters;
3106 0 : ::std::vector < sal_Bool > aOriginalApplyFlags;
3107 :
3108 0 : if (bSave)
3109 : {
3110 0 : for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllerList.begin();
3111 0 : j != rControllerList.end(); ++j)
3112 : {
3113 0 : if (bSave)
3114 : { // remember the current filter settings in case we're goin to reload the forms below (which may fail)
3115 : try
3116 : {
3117 0 : Reference< XPropertySet > xFormAsSet((*j)->getModel(), UNO_QUERY);
3118 0 : aOriginalFilters.push_back(::comphelper::getString(xFormAsSet->getPropertyValue(FM_PROP_FILTER)));
3119 0 : aOriginalApplyFlags.push_back(::comphelper::getBOOL(xFormAsSet->getPropertyValue(FM_PROP_APPLYFILTER)));
3120 : }
3121 0 : catch(Exception&)
3122 : {
3123 : OSL_FAIL("FmXFormShell::stopFiltering : could not get the original filter !");
3124 : // put dummies into the arrays so the they have the right size
3125 :
3126 0 : if (aOriginalFilters.size() == aOriginalApplyFlags.size())
3127 : // the first getPropertyValue failed -> use two dummies
3128 0 : aOriginalFilters.push_back( ::rtl::OUString() );
3129 0 : aOriginalApplyFlags.push_back( sal_False );
3130 : }
3131 : }
3132 0 : saveFilter(*j);
3133 : }
3134 : }
3135 0 : for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllerList.begin();
3136 0 : j != rControllerList.end(); ++j)
3137 : {
3138 :
3139 0 : Reference< XModeSelector> xModeSelector(*j, UNO_QUERY);
3140 0 : if (xModeSelector.is())
3141 0 : xModeSelector->setMode( ::rtl::OUString( "DataMode" ) );
3142 0 : }
3143 0 : if (bSave) // execute the filter
3144 : {
3145 0 : const ::std::vector< Reference< runtime::XFormController > > & rControllers = pAdapter->GetList();
3146 0 : for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllers.begin();
3147 0 : j != rControllers.end(); ++j)
3148 : {
3149 0 : Reference< XLoadable> xReload((*j)->getModel(), UNO_QUERY);
3150 0 : if (!xReload.is())
3151 0 : continue;
3152 0 : Reference< XPropertySet > xFormSet(xReload, UNO_QUERY);
3153 :
3154 : try
3155 : {
3156 0 : xReload->reload();
3157 : }
3158 0 : catch(Exception&)
3159 : {
3160 : OSL_FAIL("FmXFormShell::stopFiltering: Exception occurred!");
3161 : }
3162 :
3163 0 : if (!isRowSetAlive(xFormSet))
3164 : { // something went wrong -> restore the original state
3165 0 : ::rtl::OUString sOriginalFilter = aOriginalFilters[ j - rControllers.begin() ];
3166 0 : sal_Bool bOriginalApplyFlag = aOriginalApplyFlags[ j - rControllers.begin() ];
3167 : try
3168 : {
3169 0 : xFormSet->setPropertyValue(FM_PROP_FILTER, makeAny(sOriginalFilter));
3170 0 : xFormSet->setPropertyValue(FM_PROP_APPLYFILTER, makeAny(bOriginalApplyFlag));
3171 0 : xReload->reload();
3172 : }
3173 0 : catch(const Exception&)
3174 : {
3175 : DBG_UNHANDLED_EXCEPTION();
3176 0 : }
3177 : }
3178 0 : }
3179 0 : }
3180 : }
3181 :
3182 0 : m_pShell->UIFeatureChanged();
3183 0 : m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
3184 : }
3185 :
3186 : //------------------------------------------------------------------------------
3187 0 : void FmXFormShell::CreateExternalView()
3188 : {
3189 0 : if ( impl_checkDisposed() )
3190 : return;
3191 :
3192 : DBG_ASSERT(m_xAttachedFrame.is(), "FmXFormShell::CreateExternalView : no frame !");
3193 :
3194 : // the frame the external view is displayed in
3195 0 : sal_Bool bAlreadyExistent = m_xExternalViewController.is();
3196 0 : Reference< ::com::sun::star::frame::XFrame> xExternalViewFrame;
3197 0 : ::rtl::OUString sFrameName("_beamer");
3198 0 : sal_Int32 nSearchFlags = ::com::sun::star::frame::FrameSearchFlag::CHILDREN | ::com::sun::star::frame::FrameSearchFlag::CREATE;
3199 :
3200 0 : Reference< runtime::XFormController > xCurrentNavController( getNavController());
3201 : // the creation of the "partwindow" may cause a deactivate of the document which will result in our nav controller to be set to NULL
3202 :
3203 : // _first_ check if we have any valid fields we can use for the grid view
3204 : // FS - 21.10.99 - 69219
3205 : {
3206 0 : FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
3207 0 : Reference< XPropertySet> xCurrentModelSet;
3208 0 : sal_Bool bHaveUsableControls = sal_False;
3209 0 : while ((xCurrentModelSet = Reference< XPropertySet>(aModelIterator.Next(), UNO_QUERY)).is())
3210 : {
3211 : // the FmXBoundFormFieldIterator only supplies controls with a valid control source
3212 : // so we just have to check the field type
3213 0 : sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID));
3214 0 : switch (nClassId)
3215 : {
3216 : case FormComponentType::IMAGECONTROL:
3217 : case FormComponentType::CONTROL:
3218 0 : continue;
3219 : }
3220 0 : bHaveUsableControls = sal_True;
3221 0 : break;
3222 : }
3223 :
3224 0 : if (!bHaveUsableControls)
3225 : {
3226 0 : ErrorBox(NULL, WB_OK, SVX_RESSTR(RID_STR_NOCONTROLS_FOR_EXTERNALDISPLAY)).Execute();
3227 : return;
3228 0 : }
3229 : }
3230 :
3231 : // load the component for external form views
3232 0 : if (!bAlreadyExistent)
3233 : {
3234 0 : URL aWantToDispatch;
3235 0 : aWantToDispatch.Complete = FMURL_COMPONENT_FORMGRIDVIEW;
3236 :
3237 0 : Reference< ::com::sun::star::frame::XDispatchProvider> xProv(m_xAttachedFrame, UNO_QUERY);
3238 0 : Reference< ::com::sun::star::frame::XDispatch> xDisp;
3239 0 : if (xProv.is())
3240 0 : xDisp = xProv->queryDispatch(aWantToDispatch, sFrameName, nSearchFlags);
3241 0 : if (xDisp.is())
3242 : {
3243 0 : xDisp->dispatch(aWantToDispatch, Sequence< PropertyValue>());
3244 : }
3245 :
3246 : // with this the component should be loaded, now search the frame where it resides in
3247 0 : xExternalViewFrame = m_xAttachedFrame->findFrame(sFrameName, ::com::sun::star::frame::FrameSearchFlag::CHILDREN);
3248 0 : if (xExternalViewFrame.is())
3249 : {
3250 0 : m_xExternalViewController = xExternalViewFrame->getController();
3251 0 : Reference< ::com::sun::star::lang::XComponent> xComp(m_xExternalViewController, UNO_QUERY);
3252 0 : if (xComp.is())
3253 0 : xComp->addEventListener((XEventListener*)(XPropertyChangeListener*)this);
3254 0 : }
3255 : }
3256 : else
3257 : {
3258 0 : xExternalViewFrame = m_xExternalViewController->getFrame();
3259 0 : Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
3260 :
3261 : // if we display the active form we interpret the slot as "remove it"
3262 0 : Reference< XForm> xCurrentModel(xCurrentNavController->getModel(), UNO_QUERY);
3263 0 : if ((xCurrentModel == m_xExternalDisplayedForm) || (getInternalForm(xCurrentModel) == m_xExternalDisplayedForm))
3264 : {
3265 0 : if ( m_xExternalViewController == getActiveController() )
3266 : {
3267 0 : Reference< runtime::XFormController > xAsFormController( m_xExternalViewController, UNO_QUERY );
3268 0 : ControllerFeatures aHelper( ::comphelper::getProcessServiceFactory(), xAsFormController, NULL );
3269 0 : aHelper->commitCurrentControl();
3270 : }
3271 :
3272 0 : Reference< runtime::XFormController > xNewController(m_xExtViewTriggerController);
3273 0 : CloseExternalFormViewer();
3274 0 : setActiveController(xNewController);
3275 0 : return;
3276 : }
3277 :
3278 0 : URL aClearURL;
3279 0 : aClearURL.Complete = FMURL_GRIDVIEW_CLEARVIEW;
3280 :
3281 0 : Reference< ::com::sun::star::frame::XDispatch> xClear( xCommLink->queryDispatch(aClearURL, ::rtl::OUString(), 0));
3282 0 : if (xClear.is())
3283 0 : xClear->dispatch(aClearURL, Sequence< PropertyValue>());
3284 : }
3285 :
3286 : // TODO: We need an interceptor at the xSupplier, which forwards all queryDispatch requests to the FormController
3287 : // instance for which this "external view" was triggered
3288 :
3289 : // get the dispatch interface of the frame so we can communicate (interceptable) with the controller
3290 0 : Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
3291 :
3292 0 : if (m_xExternalViewController.is())
3293 : {
3294 : DBG_ASSERT(xCommLink.is(), "FmXFormShell::CreateExternalView : the component doesn't have the necessary interfaces !");
3295 : // collect the dispatchers we will need
3296 0 : URL aAddColumnURL;
3297 0 : aAddColumnURL.Complete = FMURL_GRIDVIEW_ADDCOLUMN;
3298 0 : Reference< ::com::sun::star::frame::XDispatch> xAddColumnDispatch( xCommLink->queryDispatch(aAddColumnURL, ::rtl::OUString(), 0));
3299 0 : URL aAttachURL;
3300 0 : aAttachURL.Complete = FMURL_GRIDVIEW_ATTACHTOFORM;
3301 0 : Reference< ::com::sun::star::frame::XDispatch> xAttachDispatch( xCommLink->queryDispatch(aAttachURL, ::rtl::OUString(), 0));
3302 :
3303 0 : if (xAddColumnDispatch.is() && xAttachDispatch.is())
3304 : {
3305 : DBG_ASSERT(xCurrentNavController.is(), "FmXFormShell::CreateExternalView : invalid call : have no nav controller !");
3306 : // first : dispatch the descriptions for the columns to add
3307 0 : Sequence< Reference< XControl> > aCurrentControls(xCurrentNavController->getControls());
3308 :
3309 0 : sal_Int16 nAddedColumns = 0;
3310 :
3311 : // for radio buttons we need some special structures
3312 : DECLARE_STL_USTRINGACCESS_MAP(Sequence< ::rtl::OUString>, MapUString2UstringSeq);
3313 : DECLARE_STL_ITERATORS(MapUString2UstringSeq);
3314 : DECLARE_STL_USTRINGACCESS_MAP(::rtl::OUString, FmMapUString2UString);
3315 : DECLARE_STL_USTRINGACCESS_MAP(sal_Int16, FmMapUString2Int16);
3316 : DECLARE_STL_ITERATORS(FmMapUString2Int16);
3317 :
3318 0 : MapUString2UstringSeq aRadioValueLists;
3319 0 : MapUString2UstringSeq aRadioListSources;
3320 0 : FmMapUString2UString aRadioControlSources;
3321 0 : FmMapUString2Int16 aRadioPositions;
3322 :
3323 0 : FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
3324 0 : Reference< XPropertySet> xCurrentModelSet;
3325 0 : Any aCurrentBoundField;
3326 0 : ::rtl::OUString sColumnType,aGroupName,sControlSource;
3327 0 : Sequence< Property> aProps;
3328 0 : Reference< XPropertySet> xCurrentBoundField;
3329 0 : while ((xCurrentModelSet = Reference< XPropertySet>(aModelIterator.Next(), UNO_QUERY)).is())
3330 : {
3331 0 : xCurrentModelSet->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xCurrentBoundField;
3332 : OSL_ENSURE(xCurrentModelSet.is(),"xCurrentModelSet is null!");
3333 : // create a description of the column to be created
3334 : // first : determine it's type
3335 :
3336 0 : sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID));
3337 0 : switch (nClassId)
3338 : {
3339 : case FormComponentType::RADIOBUTTON:
3340 : {
3341 : // get the label of the button (this is the access key for our structures)
3342 0 : aGroupName = getLabelName(xCurrentModelSet);
3343 :
3344 : // add the reference value of the radio button to the list source sequence
3345 0 : Sequence< ::rtl::OUString>& aThisGroupLabels = aRadioListSources[aGroupName];
3346 0 : sal_Int32 nNewSizeL = aThisGroupLabels.getLength() + 1;
3347 0 : aThisGroupLabels.realloc(nNewSizeL);
3348 0 : aThisGroupLabels.getArray()[nNewSizeL - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_REFVALUE));
3349 :
3350 : // add the label to the value list sequence
3351 0 : Sequence< ::rtl::OUString>& aThisGroupControlSources = aRadioValueLists[aGroupName];
3352 0 : sal_Int32 nNewSizeC = aThisGroupControlSources.getLength() + 1;
3353 0 : aThisGroupControlSources.realloc(nNewSizeC);
3354 0 : aThisGroupControlSources.getArray()[nNewSizeC - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_LABEL));
3355 :
3356 : // remember the controls source of the radio group
3357 0 : sControlSource = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_CONTROLSOURCE));
3358 0 : if (aRadioControlSources.find(aGroupName) == aRadioControlSources.end())
3359 0 : aRadioControlSources[aGroupName] = sControlSource;
3360 : #ifdef DBG_UTIL
3361 : else
3362 : DBG_ASSERT(aRadioControlSources[aGroupName] == sControlSource,
3363 : "FmXFormShell::CreateExternalView : inconsistent radio buttons detected !");
3364 : // (radio buttons with the same name should have the same control source)
3365 : #endif
3366 : // remember the position within the columns
3367 0 : if (aRadioPositions.find(aGroupName) == aRadioPositions.end())
3368 0 : aRadioPositions[aGroupName] = (sal_Int16)nAddedColumns;
3369 :
3370 : // any further handling is done below
3371 : }
3372 0 : continue;
3373 :
3374 : case FormComponentType::IMAGECONTROL:
3375 : case FormComponentType::CONTROL:
3376 : // no grid columns for these types (though they have a control source)
3377 0 : continue;
3378 : case FormComponentType::CHECKBOX:
3379 0 : sColumnType = FM_COL_CHECKBOX; break;
3380 : case FormComponentType::LISTBOX:
3381 0 : sColumnType = FM_COL_LISTBOX; break;
3382 : case FormComponentType::COMBOBOX:
3383 0 : sColumnType = FM_COL_COMBOBOX; break;
3384 : case FormComponentType::DATEFIELD:
3385 0 : sColumnType = FM_COL_DATEFIELD; break;
3386 : case FormComponentType::TIMEFIELD:
3387 0 : sColumnType = FM_COL_TIMEFIELD; break;
3388 : case FormComponentType::NUMERICFIELD:
3389 0 : sColumnType = FM_COL_NUMERICFIELD; break;
3390 : case FormComponentType::CURRENCYFIELD:
3391 0 : sColumnType = FM_COL_CURRENCYFIELD; break;
3392 : case FormComponentType::PATTERNFIELD:
3393 0 : sColumnType = FM_COL_PATTERNFIELD; break;
3394 :
3395 : case FormComponentType::TEXTFIELD:
3396 : {
3397 0 : sColumnType = FM_COL_TEXTFIELD;
3398 : // we know at least two different controls which are TextFields : the basic edit field and the formatted
3399 : // field. we distinguish them by their service name
3400 0 : Reference< XServiceInfo> xInfo(xCurrentModelSet, UNO_QUERY);
3401 0 : if (xInfo.is())
3402 : {
3403 0 : sal_Int16 nObjectType = getControlTypeByObject(xInfo);
3404 0 : if (OBJ_FM_FORMATTEDFIELD == nObjectType)
3405 0 : sColumnType = FM_COL_FORMATTEDFIELD;
3406 0 : }
3407 : }
3408 0 : break;
3409 : default:
3410 0 : sColumnType = FM_COL_TEXTFIELD; break;
3411 : }
3412 :
3413 0 : const sal_Int16 nDispatchArgs = 3;
3414 0 : Sequence< PropertyValue> aDispatchArgs(nDispatchArgs);
3415 0 : PropertyValue* pDispatchArgs = aDispatchArgs.getArray();
3416 :
3417 : // properties describing "meta data" about the column
3418 : // the type
3419 0 : pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
3420 0 : pDispatchArgs->Value <<= sColumnType;
3421 0 : ++pDispatchArgs;
3422 :
3423 : // the pos : append the col
3424 0 : pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
3425 0 : pDispatchArgs->Value <<= nAddedColumns;
3426 0 : ++pDispatchArgs;
3427 :
3428 : // the properties to forward to the new column
3429 0 : Sequence< PropertyValue> aColumnProps(1);
3430 0 : PropertyValue* pColumnProps = aColumnProps.getArray();
3431 :
3432 : // the label
3433 0 : pColumnProps->Name = FM_PROP_LABEL;
3434 0 : pColumnProps->Value <<= getLabelName(xCurrentModelSet);
3435 0 : ++pColumnProps;
3436 :
3437 : // for all other props : transfer them
3438 0 : Reference< XPropertySetInfo> xControlModelInfo( xCurrentModelSet->getPropertySetInfo());
3439 : DBG_ASSERT(xControlModelInfo.is(), "FmXFormShell::CreateExternalView : the control model has no property info ! This will crash !");
3440 0 : aProps = xControlModelInfo->getProperties();
3441 0 : const Property* pProps = aProps.getConstArray();
3442 :
3443 : // realloc the control description sequence
3444 0 : sal_Int32 nExistentDescs = pColumnProps - aColumnProps.getArray();
3445 0 : aColumnProps.realloc(nExistentDescs + aProps.getLength());
3446 0 : pColumnProps = aColumnProps.getArray() + nExistentDescs;
3447 :
3448 0 : for (sal_Int32 i=0; i<aProps.getLength(); ++i, ++pProps)
3449 : {
3450 0 : if (pProps->Name.equals(FM_PROP_LABEL))
3451 : // already set
3452 0 : continue;
3453 0 : if (pProps->Name.equals(FM_PROP_DEFAULTCONTROL))
3454 : // allow the column's own "default control"
3455 0 : continue;
3456 0 : if (pProps->Attributes & PropertyAttribute::READONLY)
3457 : // assume that properties which are readonly for the control are ro for the column to be created, too
3458 0 : continue;
3459 :
3460 0 : pColumnProps->Name = pProps->Name;
3461 0 : pColumnProps->Value = xCurrentModelSet->getPropertyValue(pProps->Name);
3462 0 : ++pColumnProps;
3463 : }
3464 0 : aColumnProps.realloc(pColumnProps - aColumnProps.getArray());
3465 :
3466 : // columns props are a dispatch argument
3467 0 : pDispatchArgs->Name = ::rtl::OUString("ColumnProperties"); // TODO : fmurl.*
3468 0 : pDispatchArgs->Value = makeAny(aColumnProps);
3469 0 : ++pDispatchArgs;
3470 : DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()),
3471 : "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
3472 :
3473 : // dispatch the "add column"
3474 0 : xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
3475 0 : ++nAddedColumns;
3476 0 : }
3477 :
3478 : // now for the radio button handling
3479 0 : sal_Int16 nOffset(0);
3480 : // properties describing the "direct" column properties
3481 0 : const sal_Int16 nListBoxDescription = 6;
3482 0 : Sequence< PropertyValue> aListBoxDescription(nListBoxDescription);
3483 0 : for ( ConstFmMapUString2UStringIterator aCtrlSource = aRadioControlSources.begin();
3484 0 : aCtrlSource != aRadioControlSources.end();
3485 : ++aCtrlSource, ++nOffset
3486 : )
3487 : {
3488 :
3489 0 : PropertyValue* pListBoxDescription = aListBoxDescription.getArray();
3490 : // label
3491 0 : pListBoxDescription->Name = FM_PROP_LABEL;
3492 0 : pListBoxDescription->Value <<= (*aCtrlSource).first;
3493 0 : ++pListBoxDescription;
3494 :
3495 : // control source
3496 0 : pListBoxDescription->Name = FM_PROP_CONTROLSOURCE;
3497 0 : pListBoxDescription->Value <<= (*aCtrlSource).second;
3498 0 : ++pListBoxDescription;
3499 :
3500 : // bound column
3501 0 : pListBoxDescription->Name = FM_PROP_BOUNDCOLUMN;
3502 0 : pListBoxDescription->Value <<= (sal_Int16)1;
3503 0 : ++pListBoxDescription;
3504 :
3505 : // content type
3506 0 : pListBoxDescription->Name = FM_PROP_LISTSOURCETYPE;
3507 0 : ListSourceType eType = ListSourceType_VALUELIST;
3508 0 : pListBoxDescription->Value = makeAny(eType);
3509 0 : ++pListBoxDescription;
3510 :
3511 : // list source
3512 0 : MapUString2UstringSeq::const_iterator aCurrentListSource = aRadioListSources.find((*aCtrlSource).first);
3513 : DBG_ASSERT(aCurrentListSource != aRadioListSources.end(),
3514 : "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3515 0 : pListBoxDescription->Name = FM_PROP_LISTSOURCE;
3516 0 : pListBoxDescription->Value = makeAny((*aCurrentListSource).second);
3517 0 : ++pListBoxDescription;
3518 :
3519 : // value list
3520 0 : MapUString2UstringSeq::const_iterator aCurrentValueList = aRadioValueLists.find((*aCtrlSource).first);
3521 : DBG_ASSERT(aCurrentValueList != aRadioValueLists.end(),
3522 : "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3523 0 : pListBoxDescription->Name = FM_PROP_STRINGITEMLIST;
3524 0 : pListBoxDescription->Value = makeAny(((*aCurrentValueList).second));
3525 0 : ++pListBoxDescription;
3526 :
3527 : DBG_ASSERT(nListBoxDescription == (pListBoxDescription - aListBoxDescription.getConstArray()),
3528 : "FmXFormShell::CreateExternalView : forgot to adjust nListBoxDescription ?");
3529 :
3530 : // properties describing the column "meta data"
3531 0 : const sal_Int16 nDispatchArgs = 3;
3532 0 : Sequence< PropertyValue> aDispatchArgs(nDispatchArgs);
3533 0 : PropertyValue* pDispatchArgs = aDispatchArgs.getArray();
3534 :
3535 : // column type : listbox
3536 0 : pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
3537 0 : ::rtl::OUString fColName = FM_COL_LISTBOX;
3538 0 : pDispatchArgs->Value <<= fColName;
3539 : // pDispatchArgs->Value <<= (::rtl::OUString)FM_COL_LISTBOX;
3540 0 : ++pDispatchArgs;
3541 :
3542 : // column position
3543 0 : pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
3544 0 : FmMapUString2Int16::const_iterator aOffset = aRadioPositions.find((*aCtrlSource).first);
3545 : DBG_ASSERT(aOffset != aRadioPositions.end(),
3546 : "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3547 0 : sal_Int16 nPosition = (*aOffset).second;
3548 0 : nPosition = nPosition + nOffset;
3549 : // we alread inserted nOffset additinal columns ....
3550 0 : pDispatchArgs->Value <<= nPosition;
3551 0 : ++pDispatchArgs;
3552 :
3553 : // the
3554 0 : pDispatchArgs->Name = ::rtl::OUString("ColumnProperties"); // TODO : fmurl.*
3555 0 : pDispatchArgs->Value = makeAny(aListBoxDescription);
3556 0 : ++pDispatchArgs;
3557 : DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()),
3558 : "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
3559 :
3560 : // dispatch the "add column"
3561 0 : xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
3562 0 : ++nAddedColumns;
3563 0 : }
3564 :
3565 :
3566 : DBG_ASSERT(nAddedColumns > 0, "FmXFormShell::CreateExternalView : no controls (inconsistent) !");
3567 : // we should have checked if we have any usable controls (see above).
3568 :
3569 : // "load" the "form" of the external view
3570 0 : PropertyValue aArg;
3571 0 : aArg.Name = FMARG_ATTACHTO_MASTERFORM;
3572 0 : Reference< XResultSet> xForm(xCurrentNavController->getModel(), UNO_QUERY);
3573 0 : aArg.Value <<= xForm;
3574 :
3575 0 : m_xExternalDisplayedForm = Reference< XResultSet>(xForm, UNO_QUERY);
3576 : // do this before dispatching the "attach" command, as the atach may result in a call to our queryDispatch (for the FormSlots)
3577 : // whichs needs the m_xExternalDisplayedForm
3578 :
3579 0 : xAttachDispatch->dispatch(aAttachURL, Sequence< PropertyValue>(&aArg, 1));
3580 :
3581 0 : m_xExtViewTriggerController = xCurrentNavController;
3582 :
3583 : // we want to know modifications done in the external view
3584 : // if the external controller is a XFormController we can use all our default handlings for it
3585 0 : Reference< runtime::XFormController > xFormController( m_xExternalViewController, UNO_QUERY );
3586 : OSL_ENSURE( xFormController.is(), "FmXFormShell::CreateExternalView:: invalid external view controller!" );
3587 0 : if (xFormController.is())
3588 0 : xFormController->addActivateListener((XFormControllerListener*)this);
3589 0 : }
3590 : }
3591 : #ifdef DBG_UTIL
3592 : else
3593 : {
3594 : OSL_FAIL("FmXFormShell::CreateExternalView : could not create the external form view !");
3595 : }
3596 : #endif
3597 0 : InvalidateSlot( SID_FM_VIEW_AS_GRID, sal_False );
3598 : }
3599 :
3600 : //------------------------------------------------------------------------
3601 236 : void FmXFormShell::implAdjustConfigCache()
3602 : {
3603 : // get (cache) the wizard usage flag
3604 236 : Sequence< ::rtl::OUString > aNames(1);
3605 236 : aNames[0] = ::rtl::OUString("FormControlPilotsEnabled");
3606 236 : Sequence< Any > aFlags = GetProperties(aNames);
3607 236 : if (1 == aFlags.getLength())
3608 236 : m_bUseWizards = ::cppu::any2bool(aFlags[0]);
3609 236 : }
3610 :
3611 : //------------------------------------------------------------------------
3612 0 : void FmXFormShell::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& _rPropertyNames)
3613 : {
3614 0 : if ( impl_checkDisposed() )
3615 0 : return;
3616 :
3617 0 : const ::rtl::OUString* pSearch = _rPropertyNames.getConstArray();
3618 0 : const ::rtl::OUString* pSearchTil = pSearch + _rPropertyNames.getLength();
3619 0 : for (;pSearch < pSearchTil; ++pSearch)
3620 0 : if (0 == pSearch->compareToAscii("FormControlPilotsEnabled"))
3621 : {
3622 0 : implAdjustConfigCache();
3623 0 : InvalidateSlot( SID_FM_USE_WIZARDS, sal_True );
3624 : }
3625 : }
3626 :
3627 0 : void FmXFormShell::Commit()
3628 : {
3629 0 : }
3630 :
3631 : //------------------------------------------------------------------------
3632 0 : void FmXFormShell::SetWizardUsing(sal_Bool _bUseThem)
3633 : {
3634 0 : m_bUseWizards = _bUseThem;
3635 :
3636 0 : Sequence< ::rtl::OUString > aNames(1);
3637 0 : aNames[0] = ::rtl::OUString("FormControlPilotsEnabled");
3638 0 : Sequence< Any > aValues(1);
3639 0 : aValues[0] = ::cppu::bool2any(m_bUseWizards);
3640 0 : PutProperties(aNames, aValues);
3641 0 : }
3642 :
3643 : //------------------------------------------------------------------------
3644 236 : void FmXFormShell::viewDeactivated( FmFormView& _rCurrentView, sal_Bool _bDeactivateController /* = sal_True */ )
3645 : {
3646 :
3647 236 : if ( _rCurrentView.GetImpl() && !_rCurrentView.IsDesignMode() )
3648 : {
3649 9 : _rCurrentView.GetImpl()->Deactivate( _bDeactivateController );
3650 : }
3651 :
3652 : // if we have an async load operation pending for the 0-th page for this view,
3653 : // we need to cancel this
3654 236 : FmFormPage* pPage = _rCurrentView.GetCurPage();
3655 236 : if ( pPage )
3656 : {
3657 : // move all events from our queue to a new one, omit the events for the deactivated
3658 : // page
3659 236 : ::std::queue< FmLoadAction > aNewEvents;
3660 474 : while ( !m_aLoadingPages.empty() )
3661 : {
3662 2 : FmLoadAction aAction = m_aLoadingPages.front();
3663 2 : m_aLoadingPages.pop();
3664 2 : if ( pPage != aAction.pPage )
3665 : {
3666 0 : aNewEvents.push( aAction );
3667 : }
3668 : else
3669 : {
3670 2 : Application::RemoveUserEvent( aAction.nEventId );
3671 : }
3672 : }
3673 236 : m_aLoadingPages = aNewEvents;
3674 : }
3675 :
3676 : // remove callbacks at the page
3677 236 : if ( pPage )
3678 : {
3679 236 : pPage->GetImpl().SetFormsCreationHdl( Link() );
3680 : }
3681 236 : UpdateForms( sal_True );
3682 236 : }
3683 :
3684 : //------------------------------------------------------------------------
3685 248 : IMPL_LINK( FmXFormShell, OnFirstTimeActivation, void*, /*NOTINTERESTEDIN*/ )
3686 : {
3687 124 : if ( impl_checkDisposed() )
3688 0 : return 0L;
3689 :
3690 124 : m_nActivationEvent = 0;
3691 124 : SfxObjectShell* pDocument = m_pShell->GetObjectShell();
3692 :
3693 124 : if ( pDocument && !pDocument->HasName() )
3694 : {
3695 1 : if ( isEnhancedForm() )
3696 : {
3697 : // show the data navigator
3698 0 : if ( !m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_SHOW_DATANAVIGATOR ) )
3699 0 : m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_SHOW_DATANAVIGATOR );
3700 : }
3701 : }
3702 :
3703 124 : return 0L;
3704 : }
3705 :
3706 : //------------------------------------------------------------------------
3707 0 : IMPL_LINK( FmXFormShell, OnFormsCreated, FmFormPage*, /*_pPage*/ )
3708 : {
3709 0 : UpdateForms( sal_True );
3710 0 : return 0L;
3711 : }
3712 :
3713 : //------------------------------------------------------------------------
3714 236 : void FmXFormShell::viewActivated( FmFormView& _rCurrentView, sal_Bool _bSyncAction /* = sal_False */ )
3715 : {
3716 :
3717 236 : FmFormPage* pPage = _rCurrentView.GetCurPage();
3718 :
3719 : // activate our view if we are activated ourself
3720 : // FS - 30.06.99 - 67308
3721 236 : if ( _rCurrentView.GetImpl() && !_rCurrentView.IsDesignMode() )
3722 : {
3723 : // load forms for the page the current view belongs to
3724 9 : if ( pPage )
3725 : {
3726 9 : if ( !pPage->GetImpl().hasEverBeenActivated() )
3727 9 : loadForms( pPage, FORMS_LOAD | ( _bSyncAction ? FORMS_SYNC : FORMS_ASYNC ) );
3728 9 : pPage->GetImpl().setHasBeenActivated( );
3729 : }
3730 :
3731 : // first-time initializations for the views
3732 9 : if ( !_rCurrentView.GetImpl()->hasEverBeenActivated( ) )
3733 : {
3734 9 : _rCurrentView.GetImpl()->onFirstViewActivation( PTR_CAST( FmFormModel, _rCurrentView.GetModel() ) );
3735 9 : _rCurrentView.GetImpl()->setHasBeenActivated( );
3736 : }
3737 :
3738 : // activate the current view
3739 9 : _rCurrentView.GetImpl()->Activate( _bSyncAction );
3740 : }
3741 :
3742 : // set callbacks at the page
3743 236 : if ( pPage )
3744 : {
3745 236 : pPage->GetImpl().SetFormsCreationHdl( LINK( this, FmXFormShell, OnFormsCreated ) );
3746 : }
3747 :
3748 236 : UpdateForms( sal_True );
3749 :
3750 236 : if ( !hasEverBeenActivated() )
3751 : {
3752 236 : m_nActivationEvent = Application::PostUserEvent( LINK( this, FmXFormShell, OnFirstTimeActivation ) );
3753 236 : setHasBeenActivated();
3754 : }
3755 :
3756 : // find a default "current form", if there is none, yet
3757 : // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
3758 236 : impl_defaultCurrentForm_nothrow();
3759 236 : }
3760 :
3761 : //------------------------------------------------------------------------------
3762 236 : void FmXFormShell::impl_defaultCurrentForm_nothrow()
3763 : {
3764 236 : if ( impl_checkDisposed() )
3765 0 : return;
3766 :
3767 236 : if ( m_xCurrentForm.is() )
3768 : // no action required
3769 0 : return;
3770 :
3771 236 : FmFormView* pFormView = m_pShell->GetFormView();
3772 236 : FmFormPage* pPage = pFormView ? pFormView->GetCurPage() : NULL;
3773 236 : if ( !pPage )
3774 0 : return;
3775 :
3776 : try
3777 : {
3778 236 : Reference< XIndexAccess > xForms( pPage->GetForms( false ), UNO_QUERY );
3779 236 : if ( !xForms.is() || !xForms->hasElements() )
3780 : return;
3781 :
3782 0 : Reference< XForm > xNewCurrentForm( xForms->getByIndex(0), UNO_QUERY_THROW );
3783 0 : impl_updateCurrentForm( xNewCurrentForm );
3784 : }
3785 0 : catch( const Exception& )
3786 : {
3787 : DBG_UNHANDLED_EXCEPTION();
3788 : }
3789 : }
3790 :
3791 : //------------------------------------------------------------------------------
3792 0 : void FmXFormShell::smartControlReset( const Reference< XIndexAccess >& _rxModels )
3793 : {
3794 0 : if (!_rxModels.is())
3795 : {
3796 : OSL_FAIL("FmXFormShell::smartControlReset: invalid container!");
3797 0 : return;
3798 : }
3799 :
3800 0 : static const ::rtl::OUString sClassIdPropertyName = FM_PROP_CLASSID;
3801 0 : static const ::rtl::OUString sBoundFieldPropertyName = FM_PROP_BOUNDFIELD;
3802 0 : sal_Int32 nCount = _rxModels->getCount();
3803 0 : Reference< XPropertySet > xCurrent;
3804 0 : Reference< XPropertySetInfo > xCurrentInfo;
3805 0 : Reference< XPropertySet > xBoundField;
3806 :
3807 0 : for (sal_Int32 i=0; i<nCount; ++i)
3808 : {
3809 0 : _rxModels->getByIndex(i) >>= xCurrent;
3810 0 : if (xCurrent.is())
3811 0 : xCurrentInfo = xCurrent->getPropertySetInfo();
3812 : else
3813 0 : xCurrentInfo.clear();
3814 0 : if (!xCurrentInfo.is())
3815 0 : continue;
3816 :
3817 0 : if (xCurrentInfo->hasPropertyByName(sClassIdPropertyName))
3818 : { // it's a control model
3819 :
3820 : // check if this control is bound to a living database field
3821 0 : if (xCurrentInfo->hasPropertyByName(sBoundFieldPropertyName))
3822 0 : xCurrent->getPropertyValue(sBoundFieldPropertyName) >>= xBoundField;
3823 : else
3824 0 : xBoundField.clear();
3825 :
3826 : // reset only if it's *not* bound
3827 0 : bool bReset = !xBoundField.is();
3828 :
3829 : // and additionally, check if it has an external value binding
3830 0 : Reference< XBindableValue > xBindable( xCurrent, UNO_QUERY );
3831 0 : if ( xBindable.is() && xBindable->getValueBinding().is() )
3832 0 : bReset = false;
3833 :
3834 0 : if ( bReset )
3835 : {
3836 0 : Reference< XReset > xControlReset( xCurrent, UNO_QUERY );
3837 0 : if ( xControlReset.is() )
3838 0 : xControlReset->reset();
3839 0 : }
3840 : }
3841 : else
3842 : {
3843 0 : Reference< XIndexAccess > xContainer(xCurrent, UNO_QUERY);
3844 0 : if (xContainer.is())
3845 0 : smartControlReset(xContainer);
3846 : }
3847 0 : }
3848 : }
3849 :
3850 : //------------------------------------------------------------------------
3851 14 : IMPL_LINK( FmXFormShell, OnLoadForms, FmFormPage*, /*_pPage*/ )
3852 : {
3853 7 : FmLoadAction aAction = m_aLoadingPages.front();
3854 7 : m_aLoadingPages.pop();
3855 :
3856 7 : loadForms( aAction.pPage, aAction.nFlags & ~FORMS_ASYNC );
3857 7 : return 0L;
3858 : }
3859 :
3860 : //------------------------------------------------------------------------------
3861 : namespace
3862 : {
3863 0 : sal_Bool lcl_isLoadable( const Reference< XInterface >& _rxLoadable )
3864 : {
3865 : // determines whether a form should be loaded or not
3866 : // if there is no datasource or connection there is no reason to load a form
3867 0 : Reference< XPropertySet > xSet( _rxLoadable, UNO_QUERY );
3868 0 : if ( !xSet.is() )
3869 0 : return sal_False;
3870 : try
3871 : {
3872 0 : Reference< XConnection > xConn;
3873 0 : if ( OStaticDataAccessTools().isEmbeddedInDatabase( _rxLoadable.get(), xConn ) )
3874 0 : return sal_True;
3875 :
3876 : // is there already a active connection
3877 0 : xSet->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConn;
3878 0 : if ( xConn.is() )
3879 0 : return sal_True;
3880 :
3881 0 : ::rtl::OUString sPropertyValue;
3882 0 : OSL_VERIFY( xSet->getPropertyValue( FM_PROP_DATASOURCE ) >>= sPropertyValue );
3883 0 : if ( !sPropertyValue.isEmpty() )
3884 0 : return sal_True;
3885 :
3886 0 : OSL_VERIFY( xSet->getPropertyValue( FM_PROP_URL ) >>= sPropertyValue );
3887 0 : if ( !sPropertyValue.isEmpty() )
3888 0 : return sal_True;
3889 : }
3890 0 : catch(const Exception&)
3891 : {
3892 : DBG_UNHANDLED_EXCEPTION();
3893 : }
3894 0 : return sal_False;
3895 : }
3896 : }
3897 :
3898 : //------------------------------------------------------------------------
3899 16 : void FmXFormShell::loadForms( FmFormPage* _pPage, const sal_uInt16 _nBehaviour /* FORMS_LOAD | FORMS_SYNC */ )
3900 : {
3901 : DBG_ASSERT( ( _nBehaviour & ( FORMS_ASYNC | FORMS_UNLOAD ) ) != ( FORMS_ASYNC | FORMS_UNLOAD ),
3902 : "FmXFormShell::loadForms: async loading not supported - this will heavily fail!" );
3903 :
3904 16 : if ( _nBehaviour & FORMS_ASYNC )
3905 : {
3906 : m_aLoadingPages.push( FmLoadAction(
3907 : _pPage,
3908 : _nBehaviour,
3909 : Application::PostUserEvent( LINK( this, FmXFormShell, OnLoadForms ), _pPage )
3910 9 : ) );
3911 25 : return;
3912 : }
3913 :
3914 : DBG_ASSERT( _pPage, "FmXFormShell::loadForms: invalid page!" );
3915 7 : if ( _pPage )
3916 : {
3917 : // lock the undo env so the forms can change non-transient properties while loading
3918 : // (without this my doc's modified flag would be set)
3919 7 : FmFormModel* pModel = PTR_CAST( FmFormModel, _pPage->GetModel() );
3920 : DBG_ASSERT( pModel, "FmXFormShell::loadForms: invalid model!" );
3921 7 : if ( pModel )
3922 7 : pModel->GetUndoEnv().Lock();
3923 :
3924 : // load all forms
3925 7 : Reference< XIndexAccess > xForms;
3926 7 : xForms = xForms.query( _pPage->GetForms( false ) );
3927 :
3928 7 : if ( xForms.is() )
3929 : {
3930 6 : Reference< XLoadable > xForm;
3931 6 : sal_Bool bFormWasLoaded = sal_False;
3932 6 : for ( sal_Int32 j = 0, nCount = xForms->getCount(); j < nCount; ++j )
3933 : {
3934 0 : xForms->getByIndex( j ) >>= xForm;
3935 0 : bFormWasLoaded = sal_False;
3936 : // a database form must be loaded for
3937 : try
3938 : {
3939 0 : if ( 0 == ( _nBehaviour & FORMS_UNLOAD ) )
3940 : {
3941 0 : if ( lcl_isLoadable( xForm ) && !xForm->isLoaded() )
3942 0 : xForm->load();
3943 : }
3944 : else
3945 : {
3946 0 : if ( xForm->isLoaded() )
3947 : {
3948 0 : bFormWasLoaded = sal_True;
3949 0 : xForm->unload();
3950 : }
3951 : }
3952 : }
3953 0 : catch( const Exception& )
3954 : {
3955 : DBG_UNHANDLED_EXCEPTION();
3956 : }
3957 :
3958 : // reset the form if it was loaded
3959 0 : if ( bFormWasLoaded )
3960 : {
3961 0 : Reference< XIndexAccess > xContainer( xForm, UNO_QUERY );
3962 : DBG_ASSERT( xContainer.is(), "FmXFormShell::loadForms: the form is no container!" );
3963 0 : if ( xContainer.is() )
3964 0 : smartControlReset( xContainer );
3965 : }
3966 6 : }
3967 : }
3968 :
3969 7 : if ( pModel )
3970 : // unlock the environment
3971 7 : pModel->GetUndoEnv().UnLock();
3972 : }
3973 : }
3974 :
3975 : //------------------------------------------------------------------------
3976 0 : void FmXFormShell::ExecuteTextAttribute( SfxRequest& _rReq )
3977 : {
3978 0 : m_pTextShell->ExecuteTextAttribute( _rReq );
3979 0 : }
3980 :
3981 : //------------------------------------------------------------------------
3982 0 : void FmXFormShell::GetTextAttributeState( SfxItemSet& _rSet )
3983 : {
3984 0 : m_pTextShell->GetTextAttributeState( _rSet );
3985 0 : }
3986 :
3987 : //------------------------------------------------------------------------
3988 682 : bool FmXFormShell::IsActiveControl( bool _bCountRichTextOnly ) const
3989 : {
3990 682 : return m_pTextShell->IsActiveControl( _bCountRichTextOnly );
3991 : }
3992 :
3993 : //------------------------------------------------------------------------
3994 0 : void FmXFormShell::ForgetActiveControl()
3995 : {
3996 0 : m_pTextShell->ForgetActiveControl();
3997 0 : }
3998 :
3999 : //------------------------------------------------------------------------
4000 236 : void FmXFormShell::SetControlActivationHandler( const Link& _rHdl )
4001 : {
4002 236 : m_pTextShell->SetControlActivationHandler( _rHdl );
4003 236 : }
4004 : //------------------------------------------------------------------------
4005 0 : void FmXFormShell::handleShowPropertiesRequest()
4006 : {
4007 0 : if ( onlyControlsAreMarked() )
4008 0 : ShowSelectionProperties( sal_True );
4009 0 : }
4010 :
4011 : //------------------------------------------------------------------------
4012 0 : void FmXFormShell::handleMouseButtonDown( const SdrViewEvent& _rViewEvent )
4013 : {
4014 : // catch simple double clicks
4015 0 : if ( ( _rViewEvent.nMouseClicks == 2 ) && ( _rViewEvent.nMouseCode == MOUSE_LEFT ) )
4016 : {
4017 0 : if ( _rViewEvent.eHit == SDRHIT_MARKEDOBJECT )
4018 : {
4019 0 : if ( onlyControlsAreMarked() )
4020 0 : ShowSelectionProperties( sal_True );
4021 : }
4022 : }
4023 0 : }
4024 :
4025 : //------------------------------------------------------------------------------
4026 0 : bool FmXFormShell::HasControlFocus() const
4027 : {
4028 0 : bool bHasControlFocus = false;
4029 :
4030 : try
4031 : {
4032 0 : Reference< XFormController > xController( getActiveController() );
4033 0 : Reference< XControl > xCurrentControl;
4034 0 : if ( xController.is() )
4035 0 : xCurrentControl.set( xController->getCurrentControl() );
4036 0 : if ( xCurrentControl.is() )
4037 : {
4038 0 : Reference< XWindow2 > xPeerWindow( xCurrentControl->getPeer(), UNO_QUERY_THROW );
4039 0 : bHasControlFocus = xPeerWindow->hasFocus();
4040 0 : }
4041 : }
4042 0 : catch( const Exception& )
4043 : {
4044 : DBG_UNHANDLED_EXCEPTION();
4045 : }
4046 :
4047 0 : return bHasControlFocus;
4048 : }
4049 :
4050 : //==============================================================================
4051 : //==============================================================================
4052 0 : SearchableControlIterator::SearchableControlIterator(Reference< XInterface> xStartingPoint)
4053 0 : :IndexAccessIterator(xStartingPoint)
4054 : {
4055 0 : }
4056 :
4057 : //------------------------------------------------------------------------------
4058 0 : sal_Bool SearchableControlIterator::ShouldHandleElement(const Reference< XInterface>& xElement)
4059 : {
4060 : // wenn das Ding eine ControlSource und einen BoundField-Property hat
4061 0 : Reference< XPropertySet> xProperties(xElement, UNO_QUERY);
4062 0 : if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
4063 : {
4064 : // und das BoundField gueltig ist
4065 0 : Reference< XPropertySet> xField;
4066 0 : xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
4067 0 : if (xField.is())
4068 : {
4069 : // nehmen wir's
4070 0 : m_sCurrentValue = ::comphelper::getString(xProperties->getPropertyValue(FM_PROP_CONTROLSOURCE));
4071 0 : return sal_True;
4072 0 : }
4073 : }
4074 :
4075 : // wenn es ein Grid-Control ist
4076 0 : if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
4077 : {
4078 0 : Any aClassId( xProperties->getPropertyValue(FM_PROP_CLASSID) );
4079 0 : if (::comphelper::getINT16(aClassId) == FormComponentType::GRIDCONTROL)
4080 : {
4081 0 : m_sCurrentValue = ::rtl::OUString();
4082 0 : return sal_True;
4083 0 : }
4084 : }
4085 :
4086 0 : return sal_False;
4087 : }
4088 :
4089 : //------------------------------------------------------------------------------
4090 0 : sal_Bool SearchableControlIterator::ShouldStepInto(const Reference< XInterface>& /*xContainer*/) const
4091 : {
4092 0 : return sal_True;
4093 : }
4094 :
4095 : //==============================================================================
4096 : //==============================================================================
4097 :
4098 18 : SFX_IMPL_MENU_CONTROL(ControlConversionMenuController, SfxBoolItem);
4099 :
4100 : //------------------------------------------------------------------------------
4101 0 : ControlConversionMenuController::ControlConversionMenuController( sal_uInt16 _nId, Menu& _rMenu, SfxBindings& _rBindings )
4102 : :SfxMenuControl( _nId, _rBindings )
4103 : ,m_pMainMenu( &_rMenu )
4104 0 : ,m_pConversionMenu( NULL )
4105 : {
4106 0 : if ( _nId == SID_FM_CHANGECONTROLTYPE )
4107 : {
4108 0 : m_pConversionMenu = FmXFormShell::GetConversionMenu();
4109 0 : _rMenu.SetPopupMenu( _nId, m_pConversionMenu );
4110 :
4111 0 : for (sal_Int16 i=0; i<m_pConversionMenu->GetItemCount(); ++i)
4112 : {
4113 0 : _rBindings.Invalidate(m_pConversionMenu->GetItemId(i));
4114 0 : SfxStatusForwarder* pForwarder = new SfxStatusForwarder(m_pConversionMenu->GetItemId(i), *this);
4115 0 : m_aStatusForwarders.push_back(pForwarder);
4116 : }
4117 : }
4118 0 : }
4119 :
4120 : //------------------------------------------------------------------------------
4121 0 : ControlConversionMenuController::~ControlConversionMenuController()
4122 : {
4123 0 : m_pMainMenu->SetPopupMenu(SID_FM_CHANGECONTROLTYPE, NULL);
4124 0 : delete m_pConversionMenu;
4125 0 : }
4126 :
4127 : //------------------------------------------------------------------------------
4128 0 : void ControlConversionMenuController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
4129 : {
4130 0 : if (nSID == GetId())
4131 0 : SfxMenuControl::StateChanged(nSID, eState, pState);
4132 0 : else if (FmXFormShell::isControlConversionSlot(nSID))
4133 : {
4134 0 : if ((m_pConversionMenu->GetItemPos(nSID) != MENU_ITEM_NOTFOUND) && (eState == SFX_ITEM_DISABLED))
4135 : {
4136 0 : m_pConversionMenu->RemoveItem(m_pConversionMenu->GetItemPos(nSID));
4137 : }
4138 0 : else if ((m_pConversionMenu->GetItemPos(nSID) == MENU_ITEM_NOTFOUND) && (eState != SFX_ITEM_DISABLED))
4139 : {
4140 : // We can't simply re-insert the item because we have a clear order for all the our items.
4141 : // So first we have to determine the position of the item to insert.
4142 0 : PopupMenu* pSource = FmXFormShell::GetConversionMenu();
4143 0 : sal_uInt16 nSourcePos = pSource->GetItemPos(nSID);
4144 : DBG_ASSERT(nSourcePos != MENU_ITEM_NOTFOUND, "ControlConversionMenuController::StateChanged : FmXFormShell supplied an invalid menu !");
4145 0 : sal_uInt16 nPrevInSource = nSourcePos;
4146 0 : sal_uInt16 nPrevInConversion = MENU_ITEM_NOTFOUND;
4147 0 : while (nPrevInSource>0)
4148 : {
4149 0 : sal_Int16 nPrevId = pSource->GetItemId(--nPrevInSource);
4150 :
4151 : // do we have the source's predecessor in our conversion menu, too ?
4152 0 : nPrevInConversion = m_pConversionMenu->GetItemPos(nPrevId);
4153 0 : if (nPrevInConversion != MENU_ITEM_NOTFOUND)
4154 0 : break;
4155 : }
4156 0 : if (MENU_ITEM_NOTFOUND == nPrevInConversion)
4157 : // none of the items which precede the nSID-slot in the source menu are present in our conversion menu
4158 0 : nPrevInConversion = sal::static_int_cast< sal_uInt16 >(-1); // put the item at the first position
4159 0 : m_pConversionMenu->InsertItem(nSID, pSource->GetItemText(nSID), pSource->GetItemBits(nSID), ++nPrevInConversion);
4160 0 : m_pConversionMenu->SetItemImage(nSID, pSource->GetItemImage(nSID));
4161 0 : m_pConversionMenu->SetHelpId(nSID, pSource->GetHelpId(nSID));
4162 :
4163 0 : delete pSource;
4164 : }
4165 0 : m_pMainMenu->EnableItem(SID_FM_CHANGECONTROLTYPE, m_pConversionMenu->GetItemCount() > 0);
4166 : }
4167 : else
4168 : {
4169 : OSL_FAIL("ControlConversionMenuController::StateChanged : unknown id !");
4170 : }
4171 63 : }
4172 :
4173 : //==============================================================================
4174 :
4175 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|