xref: /aoo41x/main/vcl/source/app/svapp.cxx (revision b0a7a3cf)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include "svsys.h"
28 
29 #include "comphelper/processfactory.hxx"
30 
31 #include "osl/module.h"
32 #include "osl/file.hxx"
33 #include "osl/thread.h"
34 
35 #include "rtl/tencinfo.h"
36 #include "rtl/instance.hxx"
37 
38 #include "vos/process.hxx"
39 #include "vos/mutex.hxx"
40 
41 #include "tools/tools.h"
42 #include "tools/debug.hxx"
43 #include "tools/time.hxx"
44 
45 #include "i18npool/mslangid.hxx"
46 
47 #include "unotools/syslocaleoptions.hxx"
48 
49 #include "vcl/settings.hxx"
50 #include "vcl/keycod.hxx"
51 #include "vcl/event.hxx"
52 #include "vcl/vclevent.hxx"
53 #include "vcl/virdev.hxx"
54 #include "vcl/wrkwin.hxx"
55 #include "vcl/svapp.hxx"
56 #include "vcl/cvtgrf.hxx"
57 #include "vcl/unowrap.hxx"
58 #include "vcl/timer.hxx"
59 #include "vcl/unohelp.hxx"
60 #include "vcl/lazydelete.hxx"
61 
62 #include "salinst.hxx"
63 #include "salframe.hxx"
64 #include "salsys.hxx"
65 #include "svdata.hxx"
66 #include "salimestatus.hxx"
67 #include "xconnection.hxx"
68 #include "window.h"
69 #include "accmgr.hxx"
70 #include "idlemgr.hxx"
71 #include "svids.hrc"
72 
73 #include "com/sun/star/uno/Reference.h"
74 #include "com/sun/star/awt/XToolkit.hpp"
75 #include "com/sun/star/uno/XNamingService.hpp"
76 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
77 
78 #include <utility>
79 
80 #ifdef WNT
81 #include <tchar.h>
82 #endif
83 
84 using namespace ::com::sun::star::uno;
85 
86 // keycodes handled internally by VCL
87 class ImplReservedKey
88 {
89 public:
90     ImplReservedKey( KeyCode aKeyCode, sal_uInt16 nResId ) :
91       mKeyCode(aKeyCode), mnResId( nResId)
92      {}
93 
94     KeyCode mKeyCode;
95     sal_uInt16  mnResId;
96 };
97 
98 typedef std::pair<ImplReservedKey*, size_t> ReservedKeys;
99 namespace
100 {
101     struct ImplReservedKeysImpl
102     {
103         ReservedKeys* operator()()
104         {
105             static ImplReservedKey ImplReservedKeys[] =
106             {
107 			    ImplReservedKey(KeyCode(KEY_F1,0),                  SV_SHORTCUT_HELP),
108 			    ImplReservedKey(KeyCode(KEY_F1,KEY_SHIFT),          SV_SHORTCUT_ACTIVEHELP),
109     			ImplReservedKey(KeyCode(KEY_F1,KEY_MOD1),           SV_SHORTCUT_CONTEXTHELP),
110     			ImplReservedKey(KeyCode(KEY_F2,KEY_SHIFT),          SV_SHORTCUT_CONTEXTHELP),
111     			ImplReservedKey(KeyCode(KEY_F4,KEY_MOD1),           SV_SHORTCUT_DOCKUNDOCK),
112     			ImplReservedKey(KeyCode(KEY_F4,KEY_MOD2),           SV_SHORTCUT_DOCKUNDOCK),
113     			ImplReservedKey(KeyCode(KEY_F4,KEY_MOD1|KEY_MOD2),  SV_SHORTCUT_DOCKUNDOCK),
114     			ImplReservedKey(KeyCode(KEY_F6,0),                  SV_SHORTCUT_NEXTSUBWINDOW),
115     			ImplReservedKey(KeyCode(KEY_F6,KEY_MOD1),           SV_SHORTCUT_TODOCUMENT),
116     			ImplReservedKey(KeyCode(KEY_F6,KEY_SHIFT),          SV_SHORTCUT_PREVSUBWINDOW),
117     			ImplReservedKey(KeyCode(KEY_F6,KEY_MOD1|KEY_SHIFT), SV_SHORTCUT_SPLITTER),
118     			ImplReservedKey(KeyCode(KEY_F10,0),                 SV_SHORTCUT_MENUBAR)
119 #ifdef UNX
120                 ,
121                 ImplReservedKey(KeyCode(KEY_1,KEY_SHIFT|KEY_MOD1), 0),
122                 ImplReservedKey(KeyCode(KEY_2,KEY_SHIFT|KEY_MOD1), 0),
123                 ImplReservedKey(KeyCode(KEY_3,KEY_SHIFT|KEY_MOD1), 0),
124                 ImplReservedKey(KeyCode(KEY_4,KEY_SHIFT|KEY_MOD1), 0),
125                 ImplReservedKey(KeyCode(KEY_5,KEY_SHIFT|KEY_MOD1), 0),
126                 ImplReservedKey(KeyCode(KEY_6,KEY_SHIFT|KEY_MOD1), 0),
127                 ImplReservedKey(KeyCode(KEY_7,KEY_SHIFT|KEY_MOD1), 0),
128                 ImplReservedKey(KeyCode(KEY_8,KEY_SHIFT|KEY_MOD1), 0),
129                 ImplReservedKey(KeyCode(KEY_9,KEY_SHIFT|KEY_MOD1), 0),
130                 ImplReservedKey(KeyCode(KEY_0,KEY_SHIFT|KEY_MOD1), 0),
131                 ImplReservedKey(KeyCode(KEY_ADD,KEY_SHIFT|KEY_MOD1), 0)
132 #endif
133             };
134             static ReservedKeys aKeys
135             (
136                 &ImplReservedKeys[0],
137                 sizeof(ImplReservedKeys) / sizeof(ImplReservedKey)
138             );
139             return &aKeys;
140         }
141     };
142 
143     struct ImplReservedKeys
144         : public rtl::StaticAggregate<ReservedKeys, ImplReservedKeysImpl> {};
145 }
146 
147 
148 // #include <usr/refl.hxx>
149 class Reflection;
150 
151 
152 
153 extern "C" {
154     typedef UnoWrapperBase* (SAL_CALL *FN_TkCreateUnoWrapper)();
155 }
156 
157 // =======================================================================
158 
159 // --------------
160 // - ImplHotKey -
161 // --------------
162 
163 struct ImplHotKey
164 {
165     ImplHotKey*             mpNext;
166     void*                   mpUserData;
167     KeyCode                 maKeyCode;
168     Link                    maLink;
169 };
170 
171 // =======================================================================
172 
173 // -----------------
174 // - ImplEventHook -
175 // -----------------
176 
177 struct ImplEventHook
178 {
179     ImplEventHook*          mpNext;
180     void*                   mpUserData;
181     VCLEventHookProc        mpProc;
182 };
183 
184 // =======================================================================
185 
186 // ---------------------
187 // - ImplPostEventData -
188 // ---------------------
189 
190 struct ImplPostEventData
191 {
192     sal_uLong			mnEvent;
193     const Window*	mpWin;
194 	sal_uLong			mnEventId;
195     KeyEvent    	maKeyEvent;
196 	MouseEvent		maMouseEvent;
197 
198 
199    	ImplPostEventData( sal_uLong nEvent, const Window* pWin, const KeyEvent& rKeyEvent ) :
200     	mnEvent( nEvent ), mpWin( pWin ), mnEventId( 0 ), maKeyEvent( rKeyEvent ) {}
201    	ImplPostEventData( sal_uLong nEvent, const Window* pWin, const MouseEvent& rMouseEvent ) :
202     	mnEvent( nEvent ), mpWin( pWin ), mnEventId( 0 ), maMouseEvent( rMouseEvent ) {}
203 
204 	~ImplPostEventData() {}
205 };
206 
207 typedef ::std::pair< Window*, ImplPostEventData* > ImplPostEventPair;
208 
209 static ::std::list< ImplPostEventPair > aPostedEventList;
210 
211 // =======================================================================
212 
213 Application* GetpApp()
214 {
215     ImplSVData* pSVData = ImplGetSVData();
216     if ( !pSVData )
217         return NULL;
218     return pSVData->mpApp;
219 }
220 
221 // -----------------------------------------------------------------------
222 
223 Application::Application()
224 {
225     if( ! ImplGetSVData() )
226         ImplInitSVData();
227     ImplGetSVData()->mpApp = this;
228     InitSalData();
229 }
230 
231 // -----------------------------------------------------------------------
232 
233 Application::~Application()
234 {
235     ImplDeInitSVData();
236     DeInitSalData();
237     ImplGetSVData()->mpApp = NULL;
238     ImplDestroySVData();
239     GlobalDeInitTools();
240 }
241 
242 // -----------------------------------------------------------------------
243 
244 void Application::InitAppRes( const ResId& )
245 {
246 }
247 
248 // -----------------------------------------------------------------------
249 
250 sal_Bool Application::QueryExit()
251 {
252     WorkWindow* pAppWin = ImplGetSVData()->maWinData.mpAppWin;
253 
254     // Aufruf des Close-Handlers des Applikationsfensters
255     if ( pAppWin )
256         return pAppWin->Close();
257     else
258         return sal_True;
259 }
260 
261 // -----------------------------------------------------------------------
262 
263 void Application::UserEvent( sal_uLong, void* )
264 {
265 }
266 
267 // -----------------------------------------------------------------------
268 
269 void Application::ShowStatusText( const XubString& )
270 {
271 }
272 
273 // -----------------------------------------------------------------------
274 
275 void Application::ShowHelpStatusText( const XubString& )
276 {
277 }
278 
279 // -----------------------------------------------------------------------
280 
281 void Application::ActivateExtHelp()
282 {
283 }
284 
285 // -----------------------------------------------------------------------
286 
287 void Application::DeactivateExtHelp()
288 {
289 }
290 
291 // -----------------------------------------------------------------------
292 
293 void Application::HideStatusText()
294 {
295 }
296 
297 // -----------------------------------------------------------------------
298 
299 void Application::HideHelpStatusText()
300 {
301 }
302 
303 // -----------------------------------------------------------------------
304 
305 void Application::FocusChanged()
306 {
307 }
308 
309 // -----------------------------------------------------------------------
310 
311 void Application::DataChanged( const DataChangedEvent& )
312 {
313 }
314 
315 // -----------------------------------------------------------------------
316 void Application::Init()
317 {
318 }
319 
320 // -----------------------------------------------------------------------
321 
322 void Application::DeInit()
323 {
324 }
325 
326 // -----------------------------------------------------------------------
327 
328 sal_uInt16 Application::GetCommandLineParamCount()
329 {
330     vos::OStartupInfo aStartInfo;
331     return (sal_uInt16)aStartInfo.getCommandArgCount();
332 }
333 
334 // -----------------------------------------------------------------------
335 
336 XubString Application::GetCommandLineParam( sal_uInt16 nParam )
337 {
338     vos::OStartupInfo   aStartInfo;
339     rtl::OUString       aParam;
340     aStartInfo.getCommandArg( nParam, aParam );
341     return XubString( aParam );
342 }
343 
344 // -----------------------------------------------------------------------
345 
346 const XubString& Application::GetAppFileName()
347 {
348     ImplSVData* pSVData = ImplGetSVData();
349     DBG_ASSERT( pSVData->maAppData.mpAppFileName, "AppFileName vor SVMain ?!" );
350     if ( pSVData->maAppData.mpAppFileName )
351         return *pSVData->maAppData.mpAppFileName;
352 
353     /*
354      *  #91147# provide a fallback for people without initialized
355      *  vcl here (like setup in responsefile mode)
356      */
357     static String aAppFileName;
358     if( !aAppFileName.Len() )
359     {
360         vos::OStartupInfo   aStartInfo;
361         ::rtl::OUString		aExeFileName;
362 
363         aStartInfo.getExecutableFile( aExeFileName );
364 
365         // convert path to native file format
366         rtl::OUString aNativeFileName;
367         osl::FileBase::getSystemPathFromFileURL( aExeFileName, aNativeFileName );
368         aAppFileName = aNativeFileName;
369     }
370 
371     return aAppFileName;
372 }
373 
374 // -----------------------------------------------------------------------
375 
376 sal_uInt16 Application::Exception( sal_uInt16 nError )
377 {
378     switch ( nError & EXC_MAJORTYPE )
379     {
380         // Bei System machen wir nichts und lassen dem System den
381         // vortritt
382         case EXC_SYSTEM:
383             return 0;
384 
385         case EXC_DISPLAY:
386         case EXC_REMOTE:
387             return 0;
388 
389 #ifdef DBG_UTIL
390         case EXC_RSCNOTLOADED:
391             Abort( XubString( RTL_CONSTASCII_USTRINGPARAM( "Resource not loaded" ) ) );
392             break;
393         case EXC_SYSOBJNOTCREATED:
394             Abort( XubString( RTL_CONSTASCII_USTRINGPARAM( "System Object not created" ) ) );
395             break;
396         default:
397             Abort( XubString( RTL_CONSTASCII_USTRINGPARAM( "Unknown Error" ) ) );
398             break;
399 #else
400         default:
401             Abort( ImplGetSVEmptyStr() );
402             break;
403 #endif
404     }
405 
406     return 0;
407 }
408 
409 // -----------------------------------------------------------------------
410 
411 void Application::Abort( const XubString& rErrorText )
412 {
413     SalAbort( rErrorText );
414 }
415 
416 // -----------------------------------------------------------------------
417 
418 sal_uLong   Application::GetReservedKeyCodeCount()
419 {
420     return ImplReservedKeys::get()->second;
421 }
422 
423 const KeyCode*  Application::GetReservedKeyCode( sal_uLong i )
424 {
425     if( i >= GetReservedKeyCodeCount() )
426         return NULL;
427     else
428         return &ImplReservedKeys::get()->first[i].mKeyCode;
429 }
430 
431 String Application::GetReservedKeyCodeDescription( sal_uLong i )
432 {
433     ResMgr* pResMgr = ImplGetResMgr();
434     if( ! pResMgr )
435         return String();
436     ImplReservedKey *pImplReservedKeys = ImplReservedKeys::get()->first;
437     if( i >= GetReservedKeyCodeCount() || ! pImplReservedKeys[i].mnResId )
438         return String();
439     else
440         return String( ResId( pImplReservedKeys[i].mnResId, *pResMgr ) );
441 }
442 
443 // -----------------------------------------------------------------------
444 
445 void Application::Execute()
446 {
447     DBG_STARTAPPEXECUTE();
448 
449     ImplSVData* pSVData = ImplGetSVData();
450     pSVData->maAppData.mbInAppExecute = sal_True;
451 
452     while ( !pSVData->maAppData.mbAppQuit )
453         Application::Yield();
454 
455     pSVData->maAppData.mbInAppExecute = sal_False;
456 
457     DBG_ENDAPPEXECUTE();
458 }
459 
460 // -----------------------------------------------------------------------
461 
462 inline void ImplYield( bool i_bWait, bool i_bAllEvents )
463 {
464     ImplSVData* pSVData = ImplGetSVData();
465 
466     // run timers that have timed out
467     if ( !pSVData->mbNoCallTimer )
468         while ( pSVData->mbNotAllTimerCalled )
469             Timer::ImplTimerCallbackProc();
470 
471     pSVData->maAppData.mnDispatchLevel++;
472     // do not wait for events if application was already quit; in that
473     // case only dispatch events already available
474     // do not wait for events either if the app decided that it is too busy for timers
475     // (feature added for the slideshow)
476     pSVData->mpDefInst->Yield( i_bWait && !pSVData->maAppData.mbAppQuit && !pSVData->maAppData.mbNoYield, i_bAllEvents );
477     pSVData->maAppData.mnDispatchLevel--;
478 
479     // flush lazy deleted objects
480     if( pSVData->maAppData.mnDispatchLevel == 0 )
481         vcl::LazyDelete::flush();
482 
483     // the system timer events will not necesseraly come in in non waiting mode
484     // e.g. on aqua; need to trigger timer checks manually
485     if( pSVData->maAppData.mbNoYield && !pSVData->mbNoCallTimer )
486     {
487         do
488         {
489             Timer::ImplTimerCallbackProc();
490         }
491         while( pSVData->mbNotAllTimerCalled );
492     }
493 
494     // call post yield listeners
495     if( pSVData->maAppData.mpPostYieldListeners )
496         pSVData->maAppData.mpPostYieldListeners->callListeners( NULL );
497 }
498 
499 // -----------------------------------------------------------------------
500 
501 void Application::Reschedule( bool i_bAllEvents )
502 {
503     ImplYield( false, i_bAllEvents );
504 }
505 
506 // -----------------------------------------------------------------------
507 
508 void Application::Yield( bool i_bAllEvents )
509 {
510     ImplYield( true, i_bAllEvents );
511 }
512 
513 // -----------------------------------------------------------------------
514 
515 IMPL_STATIC_LINK_NOINSTANCE( ImplSVAppData, ImplQuitMsg, void*, EMPTYARG )
516 {
517     ImplGetSVData()->maAppData.mbAppQuit = sal_True;
518     return 0;
519 }
520 
521 // -----------------------------------------------------------------------
522 
523 void Application::Quit()
524 {
525     Application::PostUserEvent( STATIC_LINK( NULL, ImplSVAppData, ImplQuitMsg ) );
526 }
527 
528 // -----------------------------------------------------------------------
529 
530 vos::IMutex& Application::GetSolarMutex()
531 {
532     ImplSVData* pSVData = ImplGetSVData();
533     return *(pSVData->mpDefInst->GetYieldMutex());
534 }
535 
536 // -----------------------------------------------------------------------
537 
538 vos::OThread::TThreadIdentifier Application::GetMainThreadIdentifier()
539 {
540     return ImplGetSVData()->mnMainThreadId;
541 }
542 
543 // -----------------------------------------------------------------------
544 
545 sal_uLong Application::ReleaseSolarMutex()
546 {
547     ImplSVData* pSVData = ImplGetSVData();
548     return pSVData->mpDefInst->ReleaseYieldMutex();
549 }
550 
551 // -----------------------------------------------------------------------
552 
553 void Application::AcquireSolarMutex( sal_uLong nCount )
554 {
555     ImplSVData* pSVData = ImplGetSVData();
556     pSVData->mpDefInst->AcquireYieldMutex( nCount );
557 }
558 
559 // -----------------------------------------------------------------------
560 
561 sal_Bool Application::IsInMain()
562 {
563     return ImplGetSVData()->maAppData.mbInAppMain;
564 }
565 
566 // -----------------------------------------------------------------------
567 
568 sal_Bool Application::IsInExecute()
569 {
570     return ImplGetSVData()->maAppData.mbInAppExecute;
571 }
572 
573 // -----------------------------------------------------------------------
574 
575 sal_Bool Application::IsShutDown()
576 {
577     return ImplGetSVData()->maAppData.mbAppQuit;
578 }
579 
580 // -----------------------------------------------------------------------
581 
582 sal_Bool Application::IsInModalMode()
583 {
584     return (ImplGetSVData()->maAppData.mnModalMode != 0);
585 }
586 
587 // -----------------------------------------------------------------------
588 
589 sal_uInt16 Application::GetModalModeCount()
590 {
591     return ImplGetSVData()->maAppData.mnModalMode;
592 }
593 
594 // -----------------------------------------------------------------------
595 
596 sal_uInt16 Application::GetDispatchLevel()
597 {
598     return ImplGetSVData()->maAppData.mnDispatchLevel;
599 }
600 
601 // -----------------------------------------------------------------------
602 
603 sal_Bool Application::AnyInput( sal_uInt16 nType )
604 {
605     return (sal_Bool)ImplGetSVData()->mpDefInst->AnyInput( nType );
606 }
607 
608 // -----------------------------------------------------------------------
609 
610 sal_uLong Application::GetLastInputInterval()
611 {
612     return (Time::GetSystemTicks()-ImplGetSVData()->maAppData.mnLastInputTime);
613 }
614 
615 // -----------------------------------------------------------------------
616 
617 extern int nImplSysDialog;
618 
619 sal_Bool Application::IsUICaptured()
620 {
621     ImplSVData* pSVData = ImplGetSVData();
622     // Wenn Mouse gecaptured, oder im TrackingModus oder im Auswahlmodus
623     // eines FloatingWindows (wie Menus, Aufklapp-ToolBoxen) soll kein
624     // weiteres Fenster aufgezogen werden
625     // D&D aktive !!!
626     if ( pSVData->maWinData.mpCaptureWin || pSVData->maWinData.mpTrackWin ||
627          pSVData->maWinData.mpFirstFloat || nImplSysDialog )
628         return sal_True;
629     else
630         return sal_False;
631 }
632 
633 // -----------------------------------------------------------------------
634 
635 sal_Bool Application::IsUserActive( sal_uInt16 nTest )
636 {
637     if ( nTest & (USERACTIVE_MOUSEDRAG | USERACTIVE_INPUT) )
638     {
639         if ( IsUICaptured() )
640             return sal_True;
641     }
642 
643     if ( nTest & USERACTIVE_INPUT )
644     {
645         if ( GetLastInputInterval() < 500 )
646             return sal_True;
647 
648         if ( AnyInput( INPUT_KEYBOARD ) )
649             return sal_True;
650     }
651 
652     if ( nTest & USERACTIVE_MODALDIALOG )
653     {
654         if ( ImplGetSVData()->maAppData.mnModalDialog )
655             return sal_True;
656     }
657 
658     return sal_False;
659 }
660 
661 // -----------------------------------------------------------------------
662 
663 void Application::SystemSettingsChanging( AllSettings& /*rSettings*/,
664                                           Window* /*pFrame*/ )
665 {
666 }
667 
668 // -----------------------------------------------------------------------
669 
670 void Application::MergeSystemSettings( AllSettings& rSettings )
671 {
672     Window* pWindow = ImplGetSVData()->maWinData.mpFirstFrame;
673     if( ! pWindow )
674         pWindow = ImplGetDefaultWindow();
675     if( pWindow )
676     {
677         ImplSVData* pSVData = ImplGetSVData();
678         if ( !pSVData->maAppData.mbSettingsInit )
679         {
680             // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
681             pWindow->ImplUpdateGlobalSettings( *pSVData->maAppData.mpSettings );
682             pSVData->maAppData.mbSettingsInit = sal_True;
683         }
684         // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
685         pWindow->ImplUpdateGlobalSettings( rSettings, sal_False );
686     }
687 }
688 
689 // -----------------------------------------------------------------------
690 
691 bool Application::ValidateSystemFont()
692 {
693     Window* pWindow = ImplGetSVData()->maWinData.mpFirstFrame;
694     if( ! pWindow )
695         pWindow = ImplGetDefaultWindow();
696 
697     if( pWindow )
698     {
699         AllSettings aSettings;
700         pWindow->ImplGetFrame()->UpdateSettings( aSettings );
701         return pWindow->ImplCheckUIFont( aSettings.GetStyleSettings().GetAppFont() );
702     }
703     return false;
704 }
705 
706 // -----------------------------------------------------------------------
707 
708 void Application::SetSettings( const AllSettings& rSettings )
709 {
710     ImplSVData* pSVData = ImplGetSVData();
711     if ( !pSVData->maAppData.mpSettings )
712     {
713 		GetSettings();
714         *pSVData->maAppData.mpSettings = rSettings;
715         ResMgr::SetDefaultLocale( rSettings.GetUILocale() );
716     }
717     else
718     {
719         AllSettings aOldSettings = *pSVData->maAppData.mpSettings;
720         if( aOldSettings.GetUILanguage() != rSettings.GetUILanguage() && pSVData->mpResMgr )
721         {
722             delete pSVData->mpResMgr;
723             pSVData->mpResMgr = NULL;
724         }
725         ResMgr::SetDefaultLocale( rSettings.GetUILocale() );
726         *pSVData->maAppData.mpSettings = rSettings;
727         sal_uLong nChangeFlags = aOldSettings.GetChangeFlags( *pSVData->maAppData.mpSettings );
728         if ( nChangeFlags )
729         {
730             DataChangedEvent aDCEvt( DATACHANGED_SETTINGS, &aOldSettings, nChangeFlags );
731             GetpApp()->DataChanged( aDCEvt );
732 
733             // notify data change handler
734             ImplCallEventListeners( VCLEVENT_APPLICATION_DATACHANGED, NULL, &aDCEvt);
735 
736             // Update all windows
737             Window* pFirstFrame = pSVData->maWinData.mpFirstFrame;
738             // Daten, die neu berechnet werden muessen, zuruecksetzen
739             long nOldDPIX = 0;
740             long nOldDPIY = 0;
741             if ( pFirstFrame )
742             {
743                 nOldDPIX = pFirstFrame->mnDPIX;
744                 nOldDPIY = pFirstFrame->mnDPIY;
745                 pSVData->maGDIData.mnAppFontX = 0;
746             }
747             Window* pFrame = pFirstFrame;
748             while ( pFrame )
749             {
750                 // AppFont-Cache-Daten zuruecksetzen
751                 pFrame->mpWindowImpl->mpFrameData->meMapUnit = MAP_PIXEL;
752 
753                 // UpdateSettings am ClientWindow aufrufen, damit
754                 // die Daten nicht doppelt geupdatet werden
755                 Window* pClientWin = pFrame;
756                 while ( pClientWin->ImplGetClientWindow() )
757                     pClientWin = pClientWin->ImplGetClientWindow();
758                 pClientWin->UpdateSettings( rSettings, sal_True );
759 
760                 Window* pTempWin = pFrame->mpWindowImpl->mpFrameData->mpFirstOverlap;
761                 while ( pTempWin )
762                 {
763                     // UpdateSettings am ClientWindow aufrufen, damit
764                     // die Daten nicht doppelt geupdatet werden
765                     pClientWin = pTempWin;
766                     while ( pClientWin->ImplGetClientWindow() )
767                         pClientWin = pClientWin->ImplGetClientWindow();
768                     pClientWin->UpdateSettings( rSettings, sal_True );
769                     pTempWin = pTempWin->mpWindowImpl->mpNextOverlap;
770                 }
771 
772                 pFrame = pFrame->mpWindowImpl->mpFrameData->mpNextFrame;
773             }
774 
775             // Wenn sich die DPI-Aufloesung fuer Screen-Ausgaben
776             // geaendert hat, setzen wir auch bei allen
777             // Screen-Kompatiblen VirDev's die neue Aufloesung
778             pFirstFrame = pSVData->maWinData.mpFirstFrame;
779             if ( pFirstFrame )
780             {
781                 if ( (pFirstFrame->mnDPIX != nOldDPIX) ||
782                      (pFirstFrame->mnDPIY != nOldDPIY) )
783                 {
784                     VirtualDevice* pVirDev = pSVData->maGDIData.mpFirstVirDev;
785                     while ( pVirDev )
786                     {
787                         if ( pVirDev->mbScreenComp &&
788                              (pVirDev->mnDPIX == nOldDPIX) &&
789                              (pVirDev->mnDPIY == nOldDPIY) )
790                         {
791                             pVirDev->mnDPIX = pFirstFrame->mnDPIX;
792                             pVirDev->mnDPIY = pFirstFrame->mnDPIY;
793                             if ( pVirDev->IsMapMode() )
794                             {
795                                 MapMode aMapMode = pVirDev->GetMapMode();
796                                 pVirDev->SetMapMode();
797                                 pVirDev->SetMapMode( aMapMode );
798                             }
799                         }
800 
801                         pVirDev = pVirDev->mpNext;
802                     }
803                 }
804             }
805         }
806     }
807 }
808 
809 // -----------------------------------------------------------------------
810 
811 const AllSettings& Application::GetSettings()
812 {
813     ImplSVData* pSVData = ImplGetSVData();
814     if ( !pSVData->maAppData.mpSettings )
815 	{
816 		pSVData->maAppData.mpCfgListener = new LocaleConfigurationListener;
817         pSVData->maAppData.mpSettings = new AllSettings();
818 		pSVData->maAppData.mpSettings->GetSysLocale().GetOptions().AddListener( pSVData->maAppData.mpCfgListener );
819 	}
820 
821     return *(pSVData->maAppData.mpSettings);
822 }
823 
824 // -----------------------------------------------------------------------
825 
826 void Application::NotifyAllWindows( DataChangedEvent& rDCEvt )
827 {
828     ImplSVData* pSVData = ImplGetSVData();
829     Window*     pFrame = pSVData->maWinData.mpFirstFrame;
830     while ( pFrame )
831     {
832         pFrame->NotifyAllChilds( rDCEvt );
833 
834         Window* pSysWin = pFrame->mpWindowImpl->mpFrameData->mpFirstOverlap;
835         while ( pSysWin )
836         {
837             pSysWin->NotifyAllChilds( rDCEvt );
838             pSysWin = pSysWin->mpWindowImpl->mpNextOverlap;
839         }
840 
841         pFrame = pFrame->mpWindowImpl->mpFrameData->mpNextFrame;
842     }
843 }
844 
845 // -----------------------------------------------------------------------
846 
847 void Application::ImplCallEventListeners( sal_uLong nEvent, Window *pWin, void* pData )
848 {
849     ImplSVData* pSVData = ImplGetSVData();
850     VclWindowEvent aEvent( pWin, nEvent, pData );
851 
852     if ( pSVData->maAppData.mpEventListeners )
853         if ( !pSVData->maAppData.mpEventListeners->empty() )
854             pSVData->maAppData.mpEventListeners->Call( &aEvent );
855 }
856 
857 // -----------------------------------------------------------------------
858 
859 void Application::ImplCallEventListeners( VclSimpleEvent* pEvent )
860 {
861     ImplSVData* pSVData = ImplGetSVData();
862 
863     if ( pSVData->maAppData.mpEventListeners )
864         if ( !pSVData->maAppData.mpEventListeners->empty() )
865             pSVData->maAppData.mpEventListeners->Call( pEvent );
866 }
867 
868 // -----------------------------------------------------------------------
869 
870 void Application::AddEventListener( const Link& rEventListener )
871 {
872     ImplSVData* pSVData = ImplGetSVData();
873     if( !pSVData->maAppData.mpEventListeners )
874         pSVData->maAppData.mpEventListeners = new VclEventListeners;
875     pSVData->maAppData.mpEventListeners->push_back( rEventListener );
876 }
877 
878 // -----------------------------------------------------------------------
879 
880 void Application::RemoveEventListener( const Link& rEventListener )
881 {
882     ImplSVData* pSVData = ImplGetSVData();
883     if( pSVData->maAppData.mpEventListeners )
884         pSVData->maAppData.mpEventListeners->remove( rEventListener );
885 }
886 
887 // -----------------------------------------------------------------------
888 void Application::AddKeyListener( const Link& rKeyListener )
889 {
890     ImplSVData* pSVData = ImplGetSVData();
891     if( !pSVData->maAppData.mpKeyListeners )
892         pSVData->maAppData.mpKeyListeners = new VclEventListeners;
893     pSVData->maAppData.mpKeyListeners->push_back( rKeyListener );
894 }
895 
896 // -----------------------------------------------------------------------
897 
898 void Application::RemoveKeyListener( const Link& rKeyListener )
899 {
900     ImplSVData* pSVData = ImplGetSVData();
901     if( pSVData->maAppData.mpKeyListeners )
902         pSVData->maAppData.mpKeyListeners->remove( rKeyListener );
903 }
904 
905 // -----------------------------------------------------------------------
906 
907 sal_Bool Application::HandleKey( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent )
908 {
909     // let listeners process the key event
910     VclWindowEvent aEvent( pWin, nEvent, (void *) pKeyEvent );
911 
912     ImplSVData* pSVData = ImplGetSVData();
913     sal_Bool bProcessed = sal_False;
914 
915     if ( pSVData->maAppData.mpKeyListeners )
916         if ( !pSVData->maAppData.mpKeyListeners->empty() )
917             bProcessed = pSVData->maAppData.mpKeyListeners->Process( &aEvent );
918 
919     return bProcessed;
920 }
921 
922 // -----------------------------------------------------------------------------
923 
924 sal_uLong Application::PostKeyEvent( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent )
925 {
926 	const ::vos::OGuard	aGuard( GetSolarMutex() );
927 	sal_uLong 				nEventId = 0;
928 
929     if( pWin && pKeyEvent )
930     {
931 		ImplPostEventData* pPostEventData = new ImplPostEventData( nEvent, pWin, *pKeyEvent );
932 
933         PostUserEvent( nEventId,
934 					   STATIC_LINK( NULL, Application, PostEventHandler ),
935                        pPostEventData );
936 
937 		if( nEventId )
938 		{
939 			pPostEventData->mnEventId = nEventId;
940 			aPostedEventList.push_back( ImplPostEventPair( pWin, pPostEventData ) );
941 		}
942 		else
943 			delete pPostEventData;
944     }
945 
946 	return nEventId;
947 }
948 
949 // -----------------------------------------------------------------------------
950 
951 sal_uLong Application::PostMouseEvent( sal_uLong nEvent, Window *pWin, MouseEvent* pMouseEvent )
952 {
953 	const ::vos::OGuard	aGuard( GetSolarMutex() );
954 	sal_uLong 				nEventId = 0;
955 
956     if( pWin && pMouseEvent )
957     {
958 		Point aTransformedPos( pMouseEvent->GetPosPixel() );
959 
960 		aTransformedPos.X() += pWin->mnOutOffX;
961 		aTransformedPos.Y() += pWin->mnOutOffY;
962 
963 		const MouseEvent aTransformedEvent( aTransformedPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(),
964 											pMouseEvent->GetButtons(), pMouseEvent->GetModifier() );
965 
966 		ImplPostEventData* pPostEventData = new ImplPostEventData( nEvent, pWin, aTransformedEvent );
967 
968         PostUserEvent( nEventId,
969 					   STATIC_LINK( NULL, Application, PostEventHandler ),
970                        pPostEventData );
971 
972 		if( nEventId )
973 		{
974 			pPostEventData->mnEventId = nEventId;
975 			aPostedEventList.push_back( ImplPostEventPair( pWin, pPostEventData ) );
976 		}
977 		else
978 			delete pPostEventData;
979     }
980 
981 	return nEventId;
982 }
983 
984 // -----------------------------------------------------------------------------
985 
986 IMPL_STATIC_LINK_NOINSTANCE( Application, PostEventHandler, void*, pCallData )
987 {
988 	const ::vos::OGuard	aGuard( GetSolarMutex() );
989     ImplPostEventData*	pData = static_cast< ImplPostEventData * >( pCallData );
990 	const void*			pEventData;
991     sal_uLong               nEvent;
992 	const sal_uLong			nEventId = pData->mnEventId;
993 
994     switch( pData->mnEvent )
995     {
996         case VCLEVENT_WINDOW_MOUSEMOVE:
997 			nEvent = SALEVENT_EXTERNALMOUSEMOVE;
998 			pEventData = &pData->maMouseEvent;
999 		break;
1000 
1001 		case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
1002 			nEvent = SALEVENT_EXTERNALMOUSEBUTTONDOWN;
1003 			pEventData = &pData->maMouseEvent;
1004 		break;
1005 
1006 		case VCLEVENT_WINDOW_MOUSEBUTTONUP:
1007 			nEvent = SALEVENT_EXTERNALMOUSEBUTTONUP;
1008 			pEventData = &pData->maMouseEvent;
1009 		break;
1010 
1011         case VCLEVENT_WINDOW_KEYINPUT:
1012 			nEvent = SALEVENT_EXTERNALKEYINPUT;
1013 			pEventData = &pData->maKeyEvent;
1014 		break;
1015 
1016 		case VCLEVENT_WINDOW_KEYUP:
1017 			nEvent = SALEVENT_EXTERNALKEYUP;
1018 			pEventData = &pData->maKeyEvent;
1019 		break;
1020 
1021         default:
1022 			nEvent = 0;
1023 			pEventData = NULL;
1024 		break;
1025     };
1026 
1027     if( pData->mpWin && pData->mpWin->mpWindowImpl->mpFrameWindow && pEventData )
1028 		ImplWindowFrameProc( pData->mpWin->mpWindowImpl->mpFrameWindow, NULL, (sal_uInt16) nEvent, pEventData );
1029 
1030 	// remove this event from list of posted events, watch for destruction of internal data
1031 	::std::list< ImplPostEventPair >::iterator aIter( aPostedEventList.begin() );
1032 
1033 	while( aIter != aPostedEventList.end() )
1034 	{
1035 		if( nEventId == (*aIter).second->mnEventId )
1036 		{
1037 			delete (*aIter).second;
1038 			aIter = aPostedEventList.erase( aIter );
1039 		}
1040 		else
1041 			++aIter;
1042 	}
1043 
1044     return 0;
1045 }
1046 
1047 // -----------------------------------------------------------------------
1048 
1049 void Application::RemoveMouseAndKeyEvents( Window* pWin )
1050 {
1051 	const ::vos::OGuard	aGuard( GetSolarMutex() );
1052 
1053 	// remove all events for specific window, watch for destruction of internal data
1054 	::std::list< ImplPostEventPair >::iterator aIter( aPostedEventList.begin() );
1055 
1056 	while( aIter != aPostedEventList.end() )
1057 	{
1058 		if( pWin == (*aIter).first )
1059 		{
1060 			if( (*aIter).second->mnEventId )
1061 				RemoveUserEvent( (*aIter).second->mnEventId );
1062 
1063 			delete (*aIter).second;
1064 			aIter = aPostedEventList.erase( aIter );
1065 		}
1066 		else
1067 			++aIter;
1068 	}
1069 }
1070 
1071 // -----------------------------------------------------------------------
1072 
1073 sal_Bool Application::IsProcessedMouseOrKeyEvent( sal_uLong nEventId )
1074 {
1075     const ::vos::OGuard aGuard( GetSolarMutex() );
1076 
1077     // find event
1078     ::std::list< ImplPostEventPair >::iterator aIter( aPostedEventList.begin() );
1079 
1080     while( aIter != aPostedEventList.end() )
1081     {
1082         if( (*aIter).second->mnEventId == nEventId )
1083             return sal_False;
1084 
1085         else
1086             ++aIter;
1087     }
1088     return sal_True;
1089 }
1090 
1091 // -----------------------------------------------------------------------
1092 
1093 sal_uLong Application::PostUserEvent( sal_uLong nEvent, void* pEventData )
1094 {
1095     sal_uLong nEventId;
1096     PostUserEvent( nEventId, nEvent, pEventData );
1097     return nEventId;
1098 }
1099 
1100 // -----------------------------------------------------------------------
1101 
1102 sal_uLong Application::PostUserEvent( const Link& rLink, void* pCaller )
1103 {
1104     sal_uLong nEventId;
1105     PostUserEvent( nEventId, rLink, pCaller );
1106     return nEventId;
1107 }
1108 
1109 // -----------------------------------------------------------------------
1110 
1111 sal_Bool Application::PostUserEvent( sal_uLong& rEventId, sal_uLong nEvent, void* pEventData )
1112 {
1113     ImplSVEvent* pSVEvent = new ImplSVEvent;
1114     pSVEvent->mnEvent   = nEvent;
1115     pSVEvent->mpData    = pEventData;
1116     pSVEvent->mpLink    = NULL;
1117     pSVEvent->mpWindow  = NULL;
1118     pSVEvent->mbCall    = sal_True;
1119     rEventId = (sal_uLong)pSVEvent;
1120     Window* pDefWindow = ImplGetDefaultWindow();
1121     if ( pDefWindow && pDefWindow->ImplGetFrame()->PostEvent( pSVEvent ) )
1122         return sal_True;
1123     else
1124     {
1125         rEventId = 0;
1126         delete pSVEvent;
1127         return sal_False;
1128     }
1129 }
1130 
1131 // -----------------------------------------------------------------------
1132 
1133 sal_Bool Application::PostUserEvent( sal_uLong& rEventId, const Link& rLink, void* pCaller )
1134 {
1135     ImplSVEvent* pSVEvent = new ImplSVEvent;
1136     pSVEvent->mnEvent   = 0;
1137     pSVEvent->mpData    = pCaller;
1138     pSVEvent->mpLink    = new Link( rLink );
1139     pSVEvent->mpWindow  = NULL;
1140     pSVEvent->mbCall    = sal_True;
1141     rEventId = (sal_uLong)pSVEvent;
1142     Window* pDefWindow = ImplGetDefaultWindow();
1143     if ( pDefWindow && pDefWindow->ImplGetFrame()->PostEvent( pSVEvent ) )
1144         return sal_True;
1145     else
1146     {
1147         rEventId = 0;
1148         delete pSVEvent;
1149         return sal_False;
1150     }
1151 }
1152 
1153 // -----------------------------------------------------------------------
1154 
1155 void Application::RemoveUserEvent( sal_uLong nUserEvent )
1156 {
1157     if(nUserEvent)
1158 	{
1159 		ImplSVEvent* pSVEvent = (ImplSVEvent*)nUserEvent;
1160 
1161 		DBG_ASSERT( !pSVEvent->mpWindow,
1162 					"Application::RemoveUserEvent(): Event is send to a window" );
1163 		DBG_ASSERT( pSVEvent->mbCall,
1164 					"Application::RemoveUserEvent(): Event is already removed" );
1165 
1166 		if ( pSVEvent->mpWindow )
1167 		{
1168             if( ! pSVEvent->maDelData.IsDelete() )
1169                 pSVEvent->mpWindow->ImplRemoveDel( &(pSVEvent->maDelData) );
1170 			pSVEvent->mpWindow = NULL;
1171 		}
1172 
1173 		pSVEvent->mbCall = sal_False;
1174 	}
1175 }
1176 
1177 // -----------------------------------------------------------------------
1178 
1179 sal_Bool Application::InsertIdleHdl( const Link& rLink, sal_uInt16 nPrio )
1180 {
1181     ImplSVData* pSVData = ImplGetSVData();
1182 
1183     // Falls er noch nicht existiert, dann anlegen
1184     if ( !pSVData->maAppData.mpIdleMgr )
1185         pSVData->maAppData.mpIdleMgr = new ImplIdleMgr;
1186 
1187     return pSVData->maAppData.mpIdleMgr->InsertIdleHdl( rLink, nPrio );
1188 }
1189 
1190 // -----------------------------------------------------------------------
1191 
1192 void Application::RemoveIdleHdl( const Link& rLink )
1193 {
1194     ImplSVData* pSVData = ImplGetSVData();
1195 
1196     if ( pSVData->maAppData.mpIdleMgr )
1197         pSVData->maAppData.mpIdleMgr->RemoveIdleHdl( rLink );
1198 }
1199 
1200 // -----------------------------------------------------------------------
1201 
1202 void Application::EnableNoYieldMode( bool i_bNoYield )
1203 {
1204     ImplSVData* pSVData = ImplGetSVData();
1205     pSVData->maAppData.mbNoYield = i_bNoYield;
1206 }
1207 
1208 // -----------------------------------------------------------------------
1209 
1210 void Application::AddPostYieldListener( const Link& i_rListener )
1211 {
1212     ImplSVData* pSVData = ImplGetSVData();
1213     if( ! pSVData->maAppData.mpPostYieldListeners )
1214         pSVData->maAppData.mpPostYieldListeners = new VclEventListeners2();
1215     pSVData->maAppData.mpPostYieldListeners->addListener( i_rListener );
1216 }
1217 
1218 // -----------------------------------------------------------------------
1219 
1220 void Application::RemovePostYieldListener( const Link& i_rListener )
1221 {
1222     ImplSVData* pSVData = ImplGetSVData();
1223     if( pSVData->maAppData.mpPostYieldListeners )
1224         pSVData->maAppData.mpPostYieldListeners->removeListener( i_rListener );
1225 }
1226 
1227 // -----------------------------------------------------------------------
1228 
1229 WorkWindow* Application::GetAppWindow()
1230 {
1231     return ImplGetSVData()->maWinData.mpAppWin;
1232 }
1233 
1234 // -----------------------------------------------------------------------
1235 
1236 Window* Application::GetFocusWindow()
1237 {
1238     return ImplGetSVData()->maWinData.mpFocusWin;
1239 }
1240 
1241 // -----------------------------------------------------------------------
1242 
1243 OutputDevice* Application::GetDefaultDevice()
1244 {
1245     return ImplGetDefaultWindow();
1246 }
1247 
1248 // -----------------------------------------------------------------------
1249 
1250 Window* Application::GetFirstTopLevelWindow()
1251 {
1252     ImplSVData* pSVData = ImplGetSVData();
1253     return pSVData->maWinData.mpFirstFrame;
1254 }
1255 
1256 // -----------------------------------------------------------------------
1257 
1258 Window* Application::GetNextTopLevelWindow( Window* pWindow )
1259 {
1260     return pWindow->mpWindowImpl->mpFrameData->mpNextFrame;
1261 }
1262 
1263 // -----------------------------------------------------------------------
1264 
1265 long    Application::GetTopWindowCount()
1266 {
1267     long nRet = 0;
1268     ImplSVData* pSVData = ImplGetSVData();
1269     Window *pWin = pSVData ? pSVData->maWinData.mpFirstFrame : NULL;
1270     while( pWin )
1271     {
1272         if( pWin->ImplGetWindow()->IsTopWindow() )
1273             nRet++;
1274         pWin = pWin->mpWindowImpl->mpFrameData->mpNextFrame;
1275     }
1276     return nRet;
1277 }
1278 
1279 // -----------------------------------------------------------------------
1280 
1281 Window* Application::GetTopWindow( long nIndex )
1282 {
1283     long nIdx = 0;
1284     ImplSVData* pSVData = ImplGetSVData();
1285     Window *pWin = pSVData ? pSVData->maWinData.mpFirstFrame : NULL;
1286     while( pWin )
1287     {
1288         if( pWin->ImplGetWindow()->IsTopWindow() )
1289         {
1290             if( nIdx == nIndex )
1291                 return pWin->ImplGetWindow();
1292             else
1293                 nIdx++;
1294         }
1295         pWin = pWin->mpWindowImpl->mpFrameData->mpNextFrame;
1296     }
1297     return NULL;
1298 }
1299 
1300 // -----------------------------------------------------------------------
1301 
1302 Window* Application::GetActiveTopWindow()
1303 {
1304     Window *pWin = ImplGetSVData()->maWinData.mpFocusWin;
1305     while( pWin )
1306     {
1307         if( pWin->IsTopWindow() )
1308             return pWin;
1309         pWin = pWin->mpWindowImpl->mpParent;
1310     }
1311     return NULL;
1312 }
1313 
1314 // -----------------------------------------------------------------------
1315 
1316 void Application::SetAppName( const XubString& rUniqueName )
1317 {
1318     ImplSVData* pSVData = ImplGetSVData();
1319 
1320     // Falls er noch nicht existiert, dann anlegen
1321     if ( !pSVData->maAppData.mpAppName )
1322         pSVData->maAppData.mpAppName = new XubString( rUniqueName );
1323     else
1324         *(pSVData->maAppData.mpAppName) = rUniqueName;
1325 }
1326 
1327 // -----------------------------------------------------------------------
1328 
1329 XubString Application::GetAppName()
1330 {
1331     ImplSVData* pSVData = ImplGetSVData();
1332     if ( pSVData->maAppData.mpAppName )
1333         return *(pSVData->maAppData.mpAppName);
1334     else
1335         return ImplGetSVEmptyStr();
1336 }
1337 
1338 // -----------------------------------------------------------------------
1339 
1340 void Application::SetDisplayName( const UniString& rName )
1341 {
1342     ImplSVData* pSVData = ImplGetSVData();
1343 
1344     // Falls er noch nicht existiert, dann anlegen
1345     if ( !pSVData->maAppData.mpDisplayName )
1346         pSVData->maAppData.mpDisplayName = new UniString( rName );
1347     else
1348         *(pSVData->maAppData.mpDisplayName) = rName;
1349 }
1350 
1351 // -----------------------------------------------------------------------
1352 
1353 UniString Application::GetDisplayName()
1354 {
1355     ImplSVData* pSVData = ImplGetSVData();
1356     if ( pSVData->maAppData.mpDisplayName )
1357         return *(pSVData->maAppData.mpDisplayName);
1358     else if ( pSVData->maWinData.mpAppWin )
1359         return pSVData->maWinData.mpAppWin->GetText();
1360     else
1361         return ImplGetSVEmptyStr();
1362 }
1363 
1364 // -----------------------------------------------------------------------
1365 
1366 unsigned int Application::GetScreenCount()
1367 {
1368     SalSystem* pSys = ImplGetSalSystem();
1369     return pSys ? pSys->GetDisplayScreenCount() : 0;
1370 }
1371 
1372 rtl::OUString Application::GetScreenName( unsigned int nScreen )
1373 {
1374     SalSystem* pSys = ImplGetSalSystem();
1375     return pSys ? pSys->GetScreenName( nScreen ) : rtl::OUString();
1376 }
1377 
1378 bool Application::IsMultiDisplay()
1379 {
1380     SalSystem* pSys = ImplGetSalSystem();
1381     return pSys ? pSys->IsMultiDisplay() : false;
1382 }
1383 
1384 unsigned int Application::GetDefaultDisplayNumber()
1385 {
1386     SalSystem* pSys = ImplGetSalSystem();
1387     return pSys ? pSys->GetDefaultDisplayNumber() : 0;
1388 }
1389 
1390 Rectangle Application::GetScreenPosSizePixel( unsigned int nScreen )
1391 {
1392     SalSystem* pSys = ImplGetSalSystem();
1393     return pSys ? pSys->GetDisplayScreenPosSizePixel( nScreen ) : Rectangle();
1394 }
1395 
1396 Rectangle Application::GetWorkAreaPosSizePixel( unsigned int nScreen )
1397 {
1398     SalSystem* pSys = ImplGetSalSystem();
1399     return pSys ? pSys->GetDisplayWorkAreaPosSizePixel( nScreen ) : Rectangle();
1400 }
1401 
1402 namespace {
1403 unsigned long calcDistSquare( const Point& i_rPoint, const Rectangle& i_rRect )
1404 {
1405     const Point aRectCenter( (i_rRect.Left() + i_rRect.Right())/2,
1406                        (i_rRect.Top() + i_rRect.Bottom())/ 2 );
1407     const long nDX = aRectCenter.X() - i_rPoint.X();
1408     const long nDY = aRectCenter.Y() - i_rPoint.Y();
1409     return nDX*nDX + nDY*nDY;
1410 }
1411 }
1412 
1413 unsigned int Application::GetBestScreen( const Rectangle& i_rRect )
1414 {
1415     if( IsMultiDisplay() )
1416         return GetDefaultDisplayNumber();
1417 
1418     const unsigned int nScreens = GetScreenCount();
1419     unsigned int nBestMatchScreen = 0;
1420     unsigned long nOverlap = 0;
1421     for( unsigned int i = 0; i < nScreens; i++ )
1422     {
1423         const Rectangle aCurScreenRect( GetScreenPosSizePixel( i ) );
1424         // if a screen contains the rectangle completely it is obviously the best screen
1425         if( aCurScreenRect.IsInside( i_rRect ) )
1426             return i;
1427         // next the screen which contains most of the area of the rect is the best
1428         Rectangle aIntersection( aCurScreenRect.GetIntersection( i_rRect ) );
1429         if( ! aIntersection.IsEmpty() )
1430         {
1431             const unsigned long nCurOverlap( aIntersection.GetWidth() * aIntersection.GetHeight() );
1432             if( nCurOverlap > nOverlap )
1433             {
1434                 nOverlap = nCurOverlap;
1435                 nBestMatchScreen = i;
1436             }
1437         }
1438     }
1439     if( nOverlap > 0 )
1440         return nBestMatchScreen;
1441 
1442     // finally the screen which center is nearest to the rect is the best
1443     const Point aCenter( (i_rRect.Left() + i_rRect.Right())/2,
1444                          (i_rRect.Top() + i_rRect.Bottom())/2 );
1445     unsigned long nDist = ULONG_MAX;
1446     for( unsigned int i = 0; i < nScreens; i++ )
1447     {
1448         const Rectangle aCurScreenRect( GetScreenPosSizePixel( i ) );
1449         const unsigned long nCurDist( calcDistSquare( aCenter, aCurScreenRect ) );
1450         if( nCurDist < nDist )
1451         {
1452             nBestMatchScreen = i;
1453             nDist = nCurDist;
1454         }
1455     }
1456     return nBestMatchScreen;
1457 }
1458 
1459 // -----------------------------------------------------------------------
1460 
1461 sal_Bool Application::InsertAccel( Accelerator* pAccel )
1462 {
1463     ImplSVData* pSVData = ImplGetSVData();
1464 
1465     if ( !pSVData->maAppData.mpAccelMgr )
1466         pSVData->maAppData.mpAccelMgr = new ImplAccelManager();
1467     return pSVData->maAppData.mpAccelMgr->InsertAccel( pAccel );
1468 }
1469 
1470 // -----------------------------------------------------------------------
1471 
1472 void Application::RemoveAccel( Accelerator* pAccel )
1473 {
1474     ImplSVData* pSVData = ImplGetSVData();
1475 
1476     if ( pSVData->maAppData.mpAccelMgr )
1477         pSVData->maAppData.mpAccelMgr->RemoveAccel( pAccel );
1478 }
1479 
1480 // -----------------------------------------------------------------------
1481 
1482 void Application::FlushAccel()
1483 {
1484     ImplSVData* pSVData = ImplGetSVData();
1485 
1486     if ( pSVData->maAppData.mpAccelMgr )
1487         pSVData->maAppData.mpAccelMgr->FlushAccel();
1488 }
1489 
1490 // -----------------------------------------------------------------------
1491 
1492 sal_Bool Application::CallAccel( const KeyCode& rKeyCode, sal_uInt16 nRepeat )
1493 {
1494     ImplSVData* pSVData = ImplGetSVData();
1495 
1496     if ( pSVData->maAppData.mpAccelMgr )
1497     {
1498         if ( pSVData->maAppData.mpAccelMgr->IsAccelKey( rKeyCode, nRepeat ) )
1499             return sal_True;
1500     }
1501 
1502     return sal_False;
1503 }
1504 
1505 // -----------------------------------------------------------------------
1506 
1507 void Application::SetHelp( Help* pHelp )
1508 {
1509     ImplGetSVData()->maAppData.mpHelp = pHelp;
1510 }
1511 
1512 // -----------------------------------------------------------------------
1513 
1514 Help* Application::GetHelp()
1515 {
1516     return ImplGetSVData()->maAppData.mpHelp;
1517 }
1518 
1519 // -----------------------------------------------------------------------
1520 
1521 void Application::EnableAutoHelpId( sal_Bool bEnabled )
1522 {
1523     ImplGetSVData()->maHelpData.mbAutoHelpId = bEnabled;
1524 }
1525 
1526 // -----------------------------------------------------------------------
1527 
1528 sal_Bool Application::IsAutoHelpIdEnabled()
1529 {
1530     return ImplGetSVData()->maHelpData.mbAutoHelpId;
1531 }
1532 
1533 // -----------------------------------------------------------------------
1534 
1535 void Application::EnableAutoMnemonic( sal_Bool bEnabled )
1536 {
1537     AllSettings aSettings = GetSettings();
1538     StyleSettings aStyle = aSettings.GetStyleSettings();
1539     aStyle.SetAutoMnemonic( bEnabled );
1540     aSettings.SetStyleSettings( aStyle );
1541     SetSettings( aSettings );
1542 }
1543 
1544 // -----------------------------------------------------------------------
1545 
1546 sal_Bool Application::IsAutoMnemonicEnabled()
1547 {
1548     return GetSettings().GetStyleSettings().GetAutoMnemonic();
1549 }
1550 
1551 // -----------------------------------------------------------------------
1552 
1553 void Application::SetDialogScaleX( short nScale )
1554 {
1555     ImplSVData* pSVData = ImplGetSVData();
1556     pSVData->maAppData.mnDialogScaleX = nScale;
1557     pSVData->maGDIData.mnAppFontX = pSVData->maGDIData.mnRealAppFontX;
1558     if ( nScale )
1559         pSVData->maGDIData.mnAppFontX += (pSVData->maGDIData.mnAppFontX*nScale)/100;
1560 }
1561 
1562 // -----------------------------------------------------------------------
1563 
1564 short Application::GetDialogScaleX()
1565 {
1566     return ImplGetSVData()->maAppData.mnDialogScaleX;
1567 }
1568 
1569 // -----------------------------------------------------------------------
1570 
1571 void Application::SetDefDialogParent( Window* pWindow )
1572 {
1573     ImplGetSVData()->maWinData.mpDefDialogParent = pWindow;
1574 }
1575 
1576 // -----------------------------------------------------------------------
1577 
1578 Window* Application::GetDefDialogParent()
1579 {
1580     ImplSVData* pSVData = ImplGetSVData();
1581     // #103442# find some useful dialog parent if there
1582     // was no default set
1583     // NOTE: currently even the default is not used
1584     if( sal_False && pSVData->maWinData.mpDefDialogParent != NULL )
1585         return pSVData->maWinData.mpDefDialogParent;
1586     else
1587     {
1588         // always use the topmost parent of the candidate
1589         // window to avoid using dialogs or floaters
1590         // as DefDialogParent
1591 
1592         // current focus frame
1593         Window *pWin = NULL;
1594         if( (pWin = pSVData->maWinData.mpFocusWin) != NULL )
1595         {
1596             while( pWin->mpWindowImpl && pWin->mpWindowImpl->mpParent )
1597                 pWin = pWin->mpWindowImpl->mpParent;
1598 
1599             if( (pWin->mpWindowImpl->mnStyle & WB_INTROWIN) == 0 )
1600             {
1601                 // check for corrupted window hierarchy, #122232#, may be we now crash somewhere else
1602                 if( !pWin->mpWindowImpl )
1603                 {
1604                     DBG_ERROR( "Window hierarchy corrupted!" );
1605                     pSVData->maWinData.mpFocusWin = NULL;   // avoid further access
1606                     return NULL;
1607                 }
1608 
1609                 // MAV: before the implementation has used only decorated windows,
1610                 //      but it is not true in case of ActiveX or plugin scenario,
1611                 //      so this check is commented out
1612                 // if( pWin->mpWindowImpl->mpFrameWindow->GetStyle() & (WB_MOVEABLE | WB_SIZEABLE) )
1613                     return pWin->mpWindowImpl->mpFrameWindow->ImplGetWindow();
1614                 // else
1615                 //    return NULL;
1616             }
1617         }
1618         // last active application frame
1619         if( NULL != (pWin = pSVData->maWinData.mpActiveApplicationFrame) )
1620         {
1621             return pWin->mpWindowImpl->mpFrameWindow->ImplGetWindow();
1622         }
1623         else
1624         {
1625             // first visible top window (may be totally wrong....)
1626             pWin = pSVData->maWinData.mpFirstFrame;
1627             while( pWin )
1628             {
1629                 if( pWin->ImplGetWindow()->IsTopWindow() &&
1630                     pWin->mpWindowImpl->mbReallyVisible &&
1631                     (pWin->mpWindowImpl->mnStyle & WB_INTROWIN) == 0
1632                 )
1633                 {
1634                     while( pWin->mpWindowImpl->mpParent )
1635                         pWin = pWin->mpWindowImpl->mpParent;
1636                     return pWin->mpWindowImpl->mpFrameWindow->ImplGetWindow();
1637                 }
1638                 pWin = pWin->mpWindowImpl->mpFrameData->mpNextFrame;
1639             }
1640             // use the desktop
1641             return NULL;
1642         }
1643     }
1644 }
1645 
1646 // -----------------------------------------------------------------------
1647 
1648 void Application::EnableDialogCancel( sal_Bool bDialogCancel )
1649 {
1650     ImplGetSVData()->maAppData.mbDialogCancel = bDialogCancel;
1651 }
1652 
1653 // -----------------------------------------------------------------------
1654 
1655 sal_Bool Application::IsDialogCancelEnabled()
1656 {
1657     return ImplGetSVData()->maAppData.mbDialogCancel;
1658 }
1659 
1660 // -----------------------------------------------------------------------
1661 
1662 void Application::SetSystemWindowMode( sal_uInt16 nMode )
1663 {
1664     ImplGetSVData()->maAppData.mnSysWinMode = nMode;
1665 }
1666 
1667 // -----------------------------------------------------------------------
1668 
1669 sal_uInt16 Application::GetSystemWindowMode()
1670 {
1671     return ImplGetSVData()->maAppData.mnSysWinMode;
1672 }
1673 
1674 // -----------------------------------------------------------------------
1675 
1676 const String& Application::GetFontPath()
1677 {
1678     ImplSVData* pSVData = ImplGetSVData();
1679     if( !pSVData->maAppData.mpFontPath )
1680     {
1681         if( const char* pFontPath = ::getenv( "SAL_FONTPATH_PRIVATE" ) )
1682             pSVData->maAppData.mpFontPath = new String( String::CreateFromAscii( pFontPath ) );
1683     }
1684 
1685     if( pSVData->maAppData.mpFontPath )
1686         return *(pSVData->maAppData.mpFontPath);
1687     return ImplGetSVEmptyStr();
1688 }
1689 
1690 // -----------------------------------------------------------------------
1691 
1692 void Application::SetFontPath( const String& rPath )
1693 {
1694     ImplSVData* pSVData = ImplGetSVData();
1695 
1696     // if it doesn't exist create a new one
1697     if( !pSVData->maAppData.mpFontPath )
1698         pSVData->maAppData.mpFontPath = new String( rPath );
1699     else
1700         *(pSVData->maAppData.mpFontPath) = rPath;
1701 }
1702 
1703 // -----------------------------------------------------------------------
1704 
1705 UniqueItemId Application::CreateUniqueId()
1706 {
1707     ImplSVData* pSVData = ImplGetSVData();
1708 
1709     if ( !pSVData->maAppData.mpUniqueIdCont )
1710         pSVData->maAppData.mpUniqueIdCont = new UniqueIdContainer( UNIQUEID_SV_BEGIN );
1711     return pSVData->maAppData.mpUniqueIdCont->CreateId();
1712 }
1713 
1714 // -----------------------------------------------------------------------
1715 
1716 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > Application::GetVCLToolkit()
1717 {
1718     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > xT;
1719     UnoWrapperBase* pWrapper = Application::GetUnoWrapper( sal_True );
1720     if ( pWrapper )
1721         xT = pWrapper->GetVCLToolkit();
1722     return xT;
1723 }
1724 
1725 // -----------------------------------------------------------------------
1726 
1727 extern "C" { static void SAL_CALL thisModule() {} }
1728 
1729 UnoWrapperBase* Application::GetUnoWrapper( sal_Bool bCreateIfNotExist )
1730 {
1731     ImplSVData* pSVData = ImplGetSVData();
1732     static sal_Bool bAlreadyTriedToCreate = sal_False;
1733     if ( !pSVData->mpUnoWrapper && bCreateIfNotExist && !bAlreadyTriedToCreate )
1734     {
1735         ::rtl::OUString aLibName = ::vcl::unohelper::CreateLibraryName( "ootk", sal_True );
1736         oslModule hTkLib = osl_loadModuleRelative(
1737             &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT );
1738         if ( hTkLib )
1739         {
1740             ::rtl::OUString aFunctionName( RTL_CONSTASCII_USTRINGPARAM( "CreateUnoWrapper" ) );
1741             FN_TkCreateUnoWrapper fnCreateWrapper = (FN_TkCreateUnoWrapper)osl_getFunctionSymbol( hTkLib, aFunctionName.pData );
1742             if ( fnCreateWrapper )
1743             {
1744                 pSVData->mpUnoWrapper = fnCreateWrapper();
1745             }
1746         }
1747         DBG_ASSERT( pSVData->mpUnoWrapper, "UnoWrapper could not be created!" );
1748         bAlreadyTriedToCreate = sal_True;
1749     }
1750     return pSVData->mpUnoWrapper;
1751 }
1752 
1753 // -----------------------------------------------------------------------
1754 
1755 void Application::SetUnoWrapper( UnoWrapperBase* pWrapper )
1756 {
1757     ImplSVData* pSVData = ImplGetSVData();
1758     DBG_ASSERT( !pSVData->mpUnoWrapper, "SetUnoWrapper: Wrapper allready exists" );
1759     pSVData->mpUnoWrapper = pWrapper;
1760 }
1761 
1762 // -----------------------------------------------------------------------
1763 
1764 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayConnection > Application::GetDisplayConnection()
1765 {
1766     ImplSVData* pSVData = ImplGetSVData();
1767 
1768     if( !pSVData->mxDisplayConnection.is() )
1769     {
1770         pSVData->mxDisplayConnection.set( new ::vcl::DisplayConnection );
1771         pSVData->mxDisplayConnection->start();
1772     }
1773 
1774     return pSVData->mxDisplayConnection.get();
1775 }
1776 
1777 // -----------------------------------------------------------------------
1778 
1779 void Application::SetFilterHdl( const Link& rLink )
1780 {
1781     ImplGetSVData()->maGDIData.mpGrfConverter->SetFilterHdl( rLink );
1782 }
1783 
1784 // -----------------------------------------------------------------------
1785 
1786 const Link& Application::GetFilterHdl()
1787 {
1788     return ImplGetSVData()->maGDIData.mpGrfConverter->GetFilterHdl();
1789 }
1790 
1791 // -----------------------------------------------------------------------
1792 
1793 sal_Bool ImplCallHotKey( const KeyCode& rKeyCode )
1794 {
1795     ImplSVData*     pSVData = ImplGetSVData();
1796     ImplHotKey*     pHotKeyData = pSVData->maAppData.mpFirstHotKey;
1797     while ( pHotKeyData )
1798     {
1799         if ( pHotKeyData->maKeyCode.IsDefinedKeyCodeEqual( rKeyCode ) )
1800         {
1801             pHotKeyData->maLink.Call( pHotKeyData->mpUserData );
1802             return sal_True;
1803         }
1804 
1805         pHotKeyData = pHotKeyData->mpNext;
1806     }
1807 
1808     return sal_False;
1809 }
1810 
1811 // -----------------------------------------------------------------------
1812 
1813 void ImplFreeHotKeyData()
1814 {
1815     ImplSVData*     pSVData = ImplGetSVData();
1816     ImplHotKey*     pTempHotKeyData;
1817     ImplHotKey*     pHotKeyData = pSVData->maAppData.mpFirstHotKey;
1818     while ( pHotKeyData )
1819     {
1820         pTempHotKeyData = pHotKeyData->mpNext;
1821         delete pHotKeyData;
1822         pHotKeyData = pTempHotKeyData;
1823     }
1824 
1825     pSVData->maAppData.mpFirstHotKey = NULL;
1826 }
1827 
1828 // -----------------------------------------------------------------------
1829 
1830 sal_uIntPtr Application::AddHotKey( const KeyCode& rKeyCode, const Link& rLink, void* pData )
1831 {
1832     ImplSVData*     pSVData = ImplGetSVData();
1833     ImplHotKey*     pHotKeyData = new ImplHotKey;
1834     pHotKeyData->mpUserData = pData;
1835     pHotKeyData->maKeyCode  = rKeyCode;
1836     pHotKeyData->maLink     = rLink;
1837     pHotKeyData->mpNext     = pSVData->maAppData.mpFirstHotKey;
1838     pSVData->maAppData.mpFirstHotKey = pHotKeyData;
1839     return (sal_uIntPtr)pHotKeyData;
1840 }
1841 
1842 // -----------------------------------------------------------------------
1843 
1844 void Application::RemoveHotKey( sal_uIntPtr nId )
1845 {
1846     ImplSVData*     pSVData = ImplGetSVData();
1847     ImplHotKey*     pFindHotKeyData = (ImplHotKey*)nId;
1848     ImplHotKey*     pPrevHotKeyData = NULL;
1849     ImplHotKey*     pHotKeyData = pSVData->maAppData.mpFirstHotKey;
1850     while ( pHotKeyData )
1851     {
1852         if ( pHotKeyData == pFindHotKeyData )
1853         {
1854             if ( pPrevHotKeyData )
1855                 pPrevHotKeyData->mpNext = pFindHotKeyData->mpNext;
1856             else
1857                 pSVData->maAppData.mpFirstHotKey = pFindHotKeyData->mpNext;
1858             delete pFindHotKeyData;
1859             break;
1860         }
1861 
1862         pPrevHotKeyData = pHotKeyData;
1863         pHotKeyData = pHotKeyData->mpNext;
1864     }
1865 
1866     DBG_ASSERT( pHotKeyData, "Application::RemoveHotKey() - HotKey is not added" );
1867 }
1868 
1869 // -----------------------------------------------------------------------
1870 
1871 void ImplFreeEventHookData()
1872 {
1873     ImplSVData*     pSVData = ImplGetSVData();
1874     ImplEventHook*  pTempEventHookData;
1875     ImplEventHook*  pEventHookData = pSVData->maAppData.mpFirstEventHook;
1876     while ( pEventHookData )
1877     {
1878         pTempEventHookData = pEventHookData->mpNext;
1879         delete pEventHookData;
1880         pEventHookData = pTempEventHookData;
1881     }
1882 
1883     pSVData->maAppData.mpFirstEventHook = NULL;
1884 }
1885 
1886 // -----------------------------------------------------------------------
1887 
1888 sal_uIntPtr Application::AddEventHook( VCLEventHookProc pProc, void* pData )
1889 {
1890     ImplSVData*     pSVData = ImplGetSVData();
1891     ImplEventHook*  pEventHookData = new ImplEventHook;
1892     pEventHookData->mpUserData = pData;
1893     pEventHookData->mpProc     = pProc;
1894     pEventHookData->mpNext     = pSVData->maAppData.mpFirstEventHook;
1895     pSVData->maAppData.mpFirstEventHook = pEventHookData;
1896     return (sal_uIntPtr)pEventHookData;
1897 }
1898 
1899 // -----------------------------------------------------------------------
1900 
1901 void Application::RemoveEventHook( sal_uIntPtr nId )
1902 {
1903     ImplSVData*     pSVData = ImplGetSVData();
1904     ImplEventHook*  pFindEventHookData = (ImplEventHook*)nId;
1905     ImplEventHook*  pPrevEventHookData = NULL;
1906     ImplEventHook*  pEventHookData = pSVData->maAppData.mpFirstEventHook;
1907     while ( pEventHookData )
1908     {
1909         if ( pEventHookData == pFindEventHookData )
1910         {
1911             if ( pPrevEventHookData )
1912                 pPrevEventHookData->mpNext = pFindEventHookData->mpNext;
1913             else
1914                 pSVData->maAppData.mpFirstEventHook = pFindEventHookData->mpNext;
1915             delete pFindEventHookData;
1916             break;
1917         }
1918 
1919         pPrevEventHookData = pEventHookData;
1920         pEventHookData = pEventHookData->mpNext;
1921     }
1922 
1923     DBG_ASSERT( pEventHookData, "Application::RemoveEventHook() - EventHook is not added" );
1924 }
1925 
1926 // -----------------------------------------------------------------------
1927 
1928 long Application::CallEventHooks( NotifyEvent& rEvt )
1929 {
1930     ImplSVData*     pSVData = ImplGetSVData();
1931     long            nRet = 0;
1932     ImplEventHook*  pTempEventHookData;
1933     ImplEventHook*  pEventHookData = pSVData->maAppData.mpFirstEventHook;
1934     while ( pEventHookData )
1935     {
1936         pTempEventHookData = pEventHookData->mpNext;
1937         nRet = pEventHookData->mpProc( rEvt, pEventHookData->mpUserData );
1938         if ( nRet )
1939             break;
1940         pEventHookData = pTempEventHookData;
1941     }
1942 
1943     return nRet;
1944 }
1945 
1946 // -----------------------------------------------------------------------
1947 
1948 long Application::CallPreNotify( NotifyEvent& rEvt )
1949 {
1950     return ImplCallPreNotify( rEvt );
1951 }
1952 
1953 // -----------------------------------------------------------------------
1954 
1955 long Application::CallEvent( NotifyEvent& rEvt )
1956 {
1957     return ImplCallEvent( rEvt );
1958 }
1959 
1960 // -----------------------------------------------------------------------
1961 
1962 const LocaleDataWrapper& Application::GetAppLocaleDataWrapper()
1963 {
1964     return GetSettings().GetLocaleDataWrapper();
1965 }
1966 
1967 // -----------------------------------------------------------------------
1968 
1969 void Application::EnableHeadlessMode( sal_Bool bEnable )
1970 {
1971     EnableDialogCancel( bEnable );
1972 }
1973 
1974 // -----------------------------------------------------------------------
1975 
1976 sal_Bool Application::IsHeadlessModeEnabled()
1977 {
1978     return IsDialogCancelEnabled();
1979 }
1980 
1981 
1982 void Application::EnableConversionMode( bool bEnableConv )
1983 {
1984     ImplGetSVData()->maAppData.mbConversionMode = bEnableConv;
1985 }
1986 
1987 // -----------------------------------------------------------------------
1988 
1989 bool Application::IsConversionModeEnabled()
1990 {
1991     return ImplGetSVData()->maAppData.mbConversionMode;
1992 }
1993 
1994 // -----------------------------------------------------------------------
1995 
1996 void Application::ShowNativeErrorBox(const String& sTitle  ,
1997                                      const String& sMessage)
1998 {
1999     int btn = ImplGetSalSystem()->ShowNativeMessageBox (
2000             sTitle,
2001             sMessage,
2002             SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK,
2003             SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK);
2004     if (btn != SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK) {
2005         OSL_TRACE("ShowNativeMessageBox returned %d\n", btn);
2006     }
2007 }
2008 
2009 // -----------------------------------------------------------------------
2010 
2011 bool Application::CanToggleImeStatusWindow()
2012 {
2013     ImplSVData* pSVData = ImplGetSVData();
2014     if( ! pSVData->mpImeStatus )
2015         pSVData->mpImeStatus  = pSVData->mpDefInst->CreateI18NImeStatus();
2016     return pSVData->mpImeStatus->canToggle();
2017 }
2018 
2019 void Application::ShowImeStatusWindow(bool bShow)
2020 {
2021     ImplGetSVData()->maAppData.meShowImeStatusWindow = bShow
2022         ? ImplSVAppData::ImeStatusWindowMode_SHOW
2023         : ImplSVAppData::ImeStatusWindowMode_HIDE;
2024 
2025     ImplSVData* pSVData = ImplGetSVData();
2026     if( ! pSVData->mpImeStatus )
2027         pSVData->mpImeStatus  = pSVData->mpDefInst->CreateI18NImeStatus();
2028     pSVData->mpImeStatus->toggle();
2029 }
2030 
2031 bool Application::GetShowImeStatusWindowDefault()
2032 {
2033     rtl_TextEncodingInfo aInfo;
2034     aInfo.StructSize = sizeof aInfo;
2035     return rtl_getTextEncodingInfo(osl_getThreadTextEncoding(), &aInfo)
2036         && aInfo.MaximumCharSize > 1;
2037 }
2038 
2039 const ::rtl::OUString& Application::GetDesktopEnvironment()
2040 {
2041     return SalGetDesktopEnvironment();
2042 }
2043 
2044 void Application::AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType)
2045 {
2046     ImplSVData* pSVData = ImplGetSVData();
2047     pSVData->mpDefInst->AddToRecentDocumentList(rFileUrl, rMimeType);
2048 }
2049 
2050 sal_Bool Application::IsAccessibilityEnabled()
2051 {
2052 //IAccessible2 Implementation 2009-----
2053 #ifdef WNT
2054 	return IsWNTInitAccessBridge();
2055 #else
2056     return sal_False;
2057 #endif
2058 //-----IAccessible2 Implementation 2009
2059 }
2060 
2061 sal_Bool InitAccessBridge( sal_Bool bShowCancel, sal_Bool &rCancelled )
2062 {
2063     sal_Bool bRet = sal_True;
2064     rCancelled = sal_False;
2065 
2066 // Disable Java bridge on UNIX
2067 #if defined UNX
2068     (void) bShowCancel; // unsued
2069 #else
2070 
2071 	// Checking TestBridgeRegistered() && HasAtHook() was introduced with IBM's IA2 CWS.
2072 	if( HasAtHook() )
2073 	{
2074 	    bRet = ImplInitAccessBridge( bShowCancel, rCancelled );
2075 
2076 	    if( !bRet && bShowCancel && !rCancelled )
2077 	    {
2078 	        // disable accessibility if the user chooses to continue
2079 	        AllSettings aSettings = Application::GetSettings();
2080 	        MiscSettings aMisc = aSettings.GetMiscSettings();
2081 	        aMisc.SetEnableATToolSupport( sal_False );
2082 	        aSettings.SetMiscSettings( aMisc );
2083 	        Application::SetSettings( aSettings );
2084 	    }
2085 	}
2086 	else
2087 	{
2088 		bRet = sal_False;
2089 	}
2090 #endif
2091 
2092     return bRet;
2093 }
2094 
2095 //IAccessible2 Implementation 2009-----
2096 #ifdef WNT
2097 sal_Bool HasAtHook()
2098 {
2099 	sal_Int32 bIsRuning=0;
2100 	// BOOL WINAPI SystemParametersInfo(
2101 	//	  __in     UINT uiAction,
2102 	//	  __in     UINT uiParam,
2103 	//	  __inout  PVOID pvParam,
2104 	//	  __in     UINT fWinIni
2105 	//	);
2106 	// pvParam must be BOOL (defined in MFC as int)
2107 	// End
2108 	if(SystemParametersInfo(SPI_GETSCREENREADER,0,&bIsRuning,0))
2109 	{
2110 		if( bIsRuning )
2111 			return sal_True;
2112 	}
2113 	return sal_False;
2114 }
2115 #endif
2116 //-----IAccessible2 Implementation 2009
2117 // MT: AppProperty, AppEvent was in oldsv.cxx, but is still needed...
2118 // ------------------------------------------------------------------------
2119 
2120 TYPEINIT0(ApplicationProperty)
2121 
2122 // ------------------------------------------------------------------------
2123 
2124 static PropertyHandler* pHandler=NULL;
2125 
2126 void Application::Property( ApplicationProperty& rProp )
2127 {
2128     if ( pHandler )
2129         pHandler->Property( rProp );
2130 }
2131 
2132 void Application::SetPropertyHandler( PropertyHandler* p )
2133 {
2134     if ( pHandler )
2135         delete pHandler;
2136     pHandler = p;
2137 }
2138 //IAccessible2 Implementation 2009-----
2139 bool Application::EnableAccessInterface(bool bEnable)
2140 {
2141 #ifdef WNT
2142 	return WNTEnableAccessInterface(bEnable);
2143 #else
2144     bEnable = TRUE; // avoid compiler warning
2145     return TRUE;
2146 #endif
2147 }
2148 bool Application::IsEnableAccessInterface()
2149 {
2150 	return ImplGetSVData()->maAppData.m_bEnableAccessInterface;
2151 }
2152 //-----IAccessibility2 Implementation 2009
2153 
2154 
2155 
2156 void Application::AppEvent( const ApplicationEvent& /*rAppEvent*/ )
2157 {
2158 }
2159