xref: /trunk/main/sw/source/ui/web/wview.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <sfx2/msg.hxx>
33 #include <svl/srchitem.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/templdlg.hxx>
36 #include <svx/srchdlg.hxx>
37 #include <basic/sbxobj.hxx>
38 #include <uivwimp.hxx>
39 #include <svx/fmshell.hxx>
40 #include <svx/extrusionbar.hxx>
41 #include <svx/fontworkbar.hxx>
42 
43 #include <sfx2/objface.hxx>
44 #include <swmodule.hxx>
45 #include <unotxvw.hxx>
46 #include <swtypes.hxx>
47 #include <cmdid.h>
48 #include <globals.hrc>
49 #include <wrtsh.hxx>
50 #include <edtwin.hxx>
51 #include <wgrfsh.hxx>
52 #include <wfrmsh.hxx>
53 #include <wolesh.hxx>
54 #include <wtabsh.hxx>
55 #include <wlistsh.hxx>
56 #include <wformsh.hxx>
57 #include <wtextsh.hxx>
58 #include <barcfg.hxx>
59 #include <doc.hxx>
60 
61 // EIGENTLICH nicht moeglich !!
62 #include <beziersh.hxx>
63 #include <drawsh.hxx>
64 #include <drwtxtsh.hxx>
65 #include <annotsh.hxx>
66 
67 #include <wview.hxx>
68 #include <wdocsh.hxx>
69 #include <web.hrc>
70 #include <shells.hrc>
71 
72 #define SwWebView
73 #define Frames
74 #define Graphics
75 #define OLEObjects
76 #define Controls
77 #define Text
78 #define Frame
79 #define Graphic
80 #define Object
81 #define Draw
82 #define DrawText
83 #define TextInTable
84 #define ListInText
85 #define ListInTable
86 #define Page
87 #include <swslots.hxx>
88 
89 
90 SFX_IMPL_NAMED_VIEWFACTORY(SwWebView, "Default")
91 {
92     SFX_VIEW_REGISTRATION(SwWebDocShell);
93 }
94 
95 SFX_IMPL_INTERFACE( SwWebView, SwView, SW_RES(RID_WEBTOOLS_TOOLBOX) )
96 {
97     SFX_CHILDWINDOW_REGISTRATION(SfxTemplateDialogWrapper::GetChildWindowId());
98     SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
99     SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS|
100                                 SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
101                                 SW_RES(RID_WEBTOOLS_TOOLBOX) );
102 }
103 
104 TYPEINIT1(SwWebView,SwView)
105 
106 /*-----------------22.01.97 14.27-------------------
107 
108 --------------------------------------------------*/
109 
110 
111 SwWebView::SwWebView(SfxViewFrame* _pFrame, SfxViewShell* _pShell) :
112     SwView(_pFrame, _pShell)
113 {
114 }
115 
116 /*-----------------22.01.97 14.27-------------------
117 
118 --------------------------------------------------*/
119 
120 
121 SwWebView::~SwWebView()
122 {
123 }
124 
125 /*-----------------23.01.97 09.01-------------------
126 
127 --------------------------------------------------*/
128 
129 
130 void SwWebView::SelectShell()
131 {
132     // Entscheidung, ob UpdateTable gerufen werden muss
133     sal_Bool bUpdateTable = sal_False;
134     const SwFrmFmt* pCurTableFmt = GetWrtShell().GetTableFmt();
135     if(pCurTableFmt && pCurTableFmt != GetLastTblFrmFmt())
136     {
137         bUpdateTable = sal_True; // kann erst spaeter ausgefuehrt werden
138     }
139     SetLastTblFrmFmt(pCurTableFmt);
140     //SEL_TBL und SEL_TBL_CELLS koennen verodert sein!
141     int nNewSelectionType = (GetWrtShell().GetSelectionType()
142                                 & ~nsSelectionType::SEL_TBL_CELLS);
143 
144     int _nSelectionType = GetSelectionType();
145     if ( nNewSelectionType == _nSelectionType )
146     {
147         GetViewFrame()->GetBindings().InvalidateAll( sal_False );
148         if ( _nSelectionType & nsSelectionType::SEL_OLE ||
149              _nSelectionType & nsSelectionType::SEL_GRF )
150             //Fuer Grafiken und OLE kann sich natuerlich das Verb aendern!
151             ImpSetVerb( nNewSelectionType );
152     }
153     else
154     {
155 
156     //  DELETEZ(pxSelectionObj); //Selektionsobjekt loeschen
157         SfxDispatcher &rDispatcher = *GetViewFrame()->GetDispatcher();
158         SwToolbarConfigItem *pBarCfg = SW_MOD()->GetWebToolbarConfig();
159 
160         if( GetCurShell() )
161         {
162             rDispatcher.Flush();        // alle gecachten Shells wirklich loeschen
163 
164             //Zur alten Selektion merken welche Toolbar sichtbar war
165             sal_Int32 nId = rDispatcher.GetObjectBarId( SFX_OBJECTBAR_OBJECT );
166             if ( nId )
167                 pBarCfg->SetTopToolbar( _nSelectionType, nId );
168 
169             SfxShell *pSfxShell;
170             sal_uInt16 i;
171             for ( i = 0; sal_True; ++i )
172             {
173                 pSfxShell = rDispatcher.GetShell( i );
174                 if ( !( pSfxShell->ISA( SwBaseShell ) ||
175                     pSfxShell->ISA( SwDrawTextShell ) || pSfxShell->ISA( SwAnnotationShell ) ) )
176                     break;
177             }
178             pSfxShell = rDispatcher.GetShell( --i );
179             ASSERT( pSfxShell, "My Shell ist lost in space" );
180             rDispatcher.Pop( *pSfxShell, SFX_SHELL_POP_UNTIL | SFX_SHELL_POP_DELETE);
181         }
182 
183         sal_Bool bInitFormShell = sal_False;
184         if( !GetFormShell() )
185         {
186             bInitFormShell = sal_True;
187             SetFormShell( new FmFormShell( this ) );
188             rDispatcher.Push( *GetFormShell() );
189         }
190 
191         sal_Bool bSetExtInpCntxt = sal_False;
192         _nSelectionType = nNewSelectionType;
193         SetSelectionType( _nSelectionType );
194         ShellModes eShellMode;
195 
196         if ( _nSelectionType & nsSelectionType::SEL_OLE )
197         {
198             eShellMode = SHELL_MODE_OBJECT;
199             SetShell( new SwWebOleShell( *this ));
200             rDispatcher.Push( *GetCurShell() );
201         }
202         else if ( _nSelectionType & nsSelectionType::SEL_FRM
203             || _nSelectionType & nsSelectionType::SEL_GRF)
204         {
205             eShellMode = SHELL_MODE_FRAME;
206             SetShell( new SwWebFrameShell( *this ));
207             rDispatcher.Push( *GetCurShell() );
208             if(_nSelectionType & nsSelectionType::SEL_GRF )
209             {
210                 eShellMode = SHELL_MODE_GRAPHIC;
211                 SetShell( new SwWebGrfShell( *this ));
212                 rDispatcher.Push( *GetCurShell() );
213             }
214         }
215         else if ( _nSelectionType & nsSelectionType::SEL_FRM )
216         {
217             eShellMode = SHELL_MODE_FRAME;
218             SetShell( new SwWebFrameShell( *this ));
219             rDispatcher.Push( *GetCurShell() );
220         }
221         else if ( _nSelectionType & nsSelectionType::SEL_DRW )
222         {
223             eShellMode = SHELL_MODE_DRAW;
224             SetShell( new svx::ExtrusionBar( this ) );
225             rDispatcher.Push( *GetCurShell() );
226 
227             eShellMode = SHELL_MODE_DRAW;
228             SetShell( new svx::FontworkBar( this ) );
229             rDispatcher.Push( *GetCurShell() );
230 
231             SetShell( new SwDrawShell( *this ));
232             rDispatcher.Push( *GetCurShell() );
233             if ( _nSelectionType & nsSelectionType::SEL_BEZ )
234             {
235                 eShellMode = SHELL_MODE_BEZIER;
236                 SetShell( new SwBezierShell( *this ));
237                 rDispatcher.Push( *GetCurShell() );
238             }
239 
240         }
241         else if ( _nSelectionType & nsSelectionType::SEL_DRW_FORM )
242         {
243             eShellMode = SHELL_MODE_DRAW_FORM;
244             SetShell( new SwWebDrawFormShell( *this ));
245 
246             rDispatcher.Push( *GetCurShell() );
247         }
248         else if ( _nSelectionType & nsSelectionType::SEL_DRW_TXT )
249         {
250             eShellMode = SHELL_MODE_DRAWTEXT;
251             rDispatcher.Push( *(new SwBaseShell( *this )) );
252             SetShell( new SwDrawTextShell( *this ));
253             rDispatcher.Push( *GetCurShell() );
254         }
255         else if ( _nSelectionType & nsSelectionType::SEL_POSTIT )
256         {
257             eShellMode = SHELL_MODE_POSTIT;
258             SetShell( new SwAnnotationShell( *this ) );
259             rDispatcher.Push( *GetCurShell() );
260         }
261         else
262         {
263             bSetExtInpCntxt = sal_True;
264             eShellMode = SHELL_MODE_TEXT;
265             if ( _nSelectionType & nsSelectionType::SEL_NUM )
266             {
267                 eShellMode = SHELL_MODE_LIST_TEXT;
268                 SetShell( new SwWebListShell( *this ));
269                 rDispatcher.Push( *GetCurShell() );
270             }
271             SetShell( new SwWebTextShell(*this));
272             rDispatcher.Push( *GetCurShell() );
273             if ( _nSelectionType & nsSelectionType::SEL_TBL )
274             {
275                 eShellMode = eShellMode == SHELL_MODE_LIST_TEXT ? SHELL_MODE_TABLE_LIST_TEXT
276                                                         : SHELL_MODE_TABLE_TEXT;
277                 SetShell( new SwWebTableShell( *this ));
278                 rDispatcher.Push( *GetCurShell() );
279             }
280         }
281         ImpSetVerb( _nSelectionType );
282         GetViewImpl()->SetShellMode(eShellMode);
283 
284         if( !GetDocShell()->IsReadOnly() )
285         {
286             if( bSetExtInpCntxt && GetWrtShell().HasReadonlySel() )
287                 bSetExtInpCntxt = sal_False;
288 
289             InputContext aCntxt( GetEditWin().GetInputContext() );
290             aCntxt.SetOptions( bSetExtInpCntxt
291                                 ? (aCntxt.GetOptions() |
292                                         ( INPUTCONTEXT_TEXT |
293                                             INPUTCONTEXT_EXTTEXTINPUT ))
294                                 : (aCntxt.GetOptions() & ~
295                                         ( INPUTCONTEXT_TEXT |
296                                             INPUTCONTEXT_EXTTEXTINPUT )) );
297             GetEditWin().SetInputContext( aCntxt );
298         }
299 
300         //Zur neuen Selektion die Toolbar aktivieren, die auch beim letzten Mal
301         //aktiviert war
302         //Vorher muss ein Flush() sein, betrifft aber lt. MBA nicht das UI und ist
303         //kein Performance-Problem
304         // TODO/LATER: maybe now the Flush() command is superfluous?!
305         rDispatcher.Flush();
306 
307         Point aPnt = GetEditWin().GetPointerPosPixel();
308         aPnt = GetEditWin().PixelToLogic(aPnt);
309         GetEditWin().UpdatePointer(aPnt);
310 
311         if ( bInitFormShell && GetWrtShell().GetDrawView() )
312             GetFormShell()->SetView( PTR_CAST( FmFormView,
313                                                 GetWrtShell().GetDrawView()));
314 
315 
316     }
317     GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
318 
319     //Guenstiger Zeitpunkt fuer die Kommunikation mit OLE-Objekten?
320     if ( GetDocShell()->GetDoc()->IsOLEPrtNotifyPending() )
321         GetDocShell()->GetDoc()->PrtOLENotify( sal_False );
322 
323     //jetzt das Tabellen-Update
324     if(bUpdateTable)
325         GetWrtShell().UpdateTable();
326 }
327 
328 
329 
330 
331