Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /************************************************************************* *
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2008 by Sun Microsystems, Inc.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <SidebarTxtControl.hxx>
30 : :
31 : : #include <SidebarTxtControlAcc.hxx>
32 : :
33 : : #include <SidebarWin.hxx>
34 : : #include <PostItMgr.hxx>
35 : :
36 : : #include <cmdid.h>
37 : : #include <docvw.hrc>
38 : :
39 : : #include <unotools/securityoptions.hxx>
40 : :
41 : : #include <sfx2/viewfrm.hxx>
42 : : #include <sfx2/bindings.hxx>
43 : : #include <sfx2/dispatch.hxx>
44 : : #include <sfx2/mnumgr.hxx>
45 : :
46 : : #include <vcl/svapp.hxx>
47 : : #include <vcl/help.hxx>
48 : : #include <vcl/msgbox.hxx>
49 : : #include <vcl/gradient.hxx>
50 : : #include <vcl/scrbar.hxx>
51 : :
52 : : #include <editeng/outliner.hxx>
53 : : #include <editeng/editeng.hxx>
54 : : #include <editeng/editview.hxx>
55 : : #include <editeng/flditem.hxx>
56 : :
57 : : #include <uitool.hxx>
58 : : #include <view.hxx>
59 : : #include <wrtsh.hxx>
60 : : #include <shellres.hxx>
61 : : #include <SwRewriter.hxx>
62 : :
63 : : namespace css = ::com::sun::star;
64 : :
65 : : namespace sw { namespace sidebarwindows {
66 : :
67 : 18 : SidebarTxtControl::SidebarTxtControl( SwSidebarWin& rSidebarWin,
68 : : WinBits nBits,
69 : : SwView& rDocView,
70 : : SwPostItMgr& rPostItMgr )
71 : : : Control( &rSidebarWin, nBits )
72 : : , mrSidebarWin( rSidebarWin )
73 : : , mrDocView( rDocView )
74 : : , mrPostItMgr( rPostItMgr )
75 : 18 : , mbMouseOver( false )
76 : : {
77 [ + - ][ + - ]: 18 : AddEventListener( LINK( &mrSidebarWin, SwSidebarWin, WindowEventListener ) );
78 : 18 : }
79 : :
80 : 15 : SidebarTxtControl::~SidebarTxtControl()
81 : : {
82 [ + - ][ + - ]: 15 : RemoveEventListener( LINK( &mrSidebarWin, SwSidebarWin, WindowEventListener ) );
83 [ - + ]: 30 : }
84 : :
85 : 0 : OutlinerView* SidebarTxtControl::GetTextView() const
86 : : {
87 : 0 : return mrSidebarWin.GetOutlinerView();
88 : : }
89 : :
90 : 0 : void SidebarTxtControl::GetFocus()
91 : : {
92 : 0 : Window::GetFocus();
93 [ # # ]: 0 : if ( !mrSidebarWin.IsMouseOver() )
94 : : {
95 : 0 : Invalidate();
96 : : }
97 : 0 : }
98 : :
99 : 0 : void SidebarTxtControl::LoseFocus()
100 : : {
101 : : // write the visible text back into the SwField
102 : 0 : mrSidebarWin.UpdateData();
103 : :
104 : 0 : Window::LoseFocus();
105 [ # # ]: 0 : if ( !mrSidebarWin.IsMouseOver() )
106 : : {
107 : 0 : Invalidate();
108 : : }
109 : 0 : }
110 : :
111 : 0 : void SidebarTxtControl::RequestHelp(const HelpEvent &rEvt)
112 : : {
113 : 0 : sal_uInt16 nResId = 0;
114 [ # # # ]: 0 : switch( mrSidebarWin.GetLayoutStatus() )
115 : : {
116 : 0 : case SwPostItHelper::INSERTED: nResId = STR_REDLINE_INSERT; break;
117 : 0 : case SwPostItHelper::DELETED: nResId = STR_REDLINE_DELETE; break;
118 : 0 : default: nResId = 0;
119 : : }
120 : :
121 [ # # ]: 0 : SwContentAtPos aCntntAtPos( SwContentAtPos::SW_REDLINE );
122 [ # # ][ # # ]: 0 : if ( nResId &&
[ # # ]
123 [ # # ][ # # ]: 0 : mrDocView.GetWrtShell().GetContentAtPos( mrSidebarWin.GetAnchorPos(), aCntntAtPos ) )
[ # # ]
124 : : {
125 [ # # ]: 0 : String sTxt;
126 [ # # ][ # # ]: 0 : sTxt = SW_RESSTR( nResId );
127 [ # # ]: 0 : sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM(": " ));
128 [ # # ][ # # ]: 0 : sTxt += aCntntAtPos.aFnd.pRedl->GetAuthorString();
129 [ # # ]: 0 : sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ));
130 [ # # ][ # # ]: 0 : sTxt += GetAppLangDateTimeString( aCntntAtPos.aFnd.pRedl->GetTimeStamp() );
[ # # ][ # # ]
131 [ # # ][ # # ]: 0 : Help::ShowQuickHelp( this,PixelToLogic(Rectangle(rEvt.GetMousePosPixel(),Size(50,10))),sTxt);
[ # # ][ # # ]
[ # # ]
132 [ # # ]: 0 : }
133 : 0 : }
134 : :
135 : 0 : void SidebarTxtControl::Paint( const Rectangle& rRect)
136 : : {
137 [ # # ]: 0 : if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
138 : : {
139 [ # # # # ]: 0 : if ( mrSidebarWin.IsMouseOverSidebarWin() ||
[ # # ]
140 : 0 : HasFocus() )
141 : : {
142 [ # # ]: 0 : DrawGradient( Rectangle( Point(0,0), PixelToLogic(GetSizePixel()) ),
143 : : Gradient( GradientStyle_LINEAR,
144 : 0 : mrSidebarWin.ColorDark(),
145 [ # # ][ # # ]: 0 : mrSidebarWin.ColorDark() ) );
[ # # ]
146 : : }
147 : : else
148 : : {
149 [ # # ]: 0 : DrawGradient( Rectangle( Point(0,0), PixelToLogic(GetSizePixel()) ),
150 : : Gradient( GradientStyle_LINEAR,
151 : 0 : mrSidebarWin.ColorLight(),
152 [ # # ][ # # ]: 0 : mrSidebarWin.ColorDark()));
[ # # ]
153 : : }
154 : : }
155 : :
156 [ # # ]: 0 : if ( GetTextView() )
157 : : {
158 : 0 : GetTextView()->Paint( rRect );
159 : : }
160 : :
161 [ # # ]: 0 : if ( mrSidebarWin.GetLayoutStatus()==SwPostItHelper::DELETED )
162 : : {
163 [ # # ]: 0 : SetLineColor(mrSidebarWin.GetChangeColor());
164 [ # # ]: 0 : DrawLine( PixelToLogic( GetPosPixel() ),
165 : 0 : PixelToLogic( GetPosPixel() +
166 [ # # ]: 0 : Point( GetSizePixel().Width(),
167 [ # # ][ # # ]: 0 : GetSizePixel().Height() ) ) );
[ # # ][ # # ]
168 : 0 : DrawLine( PixelToLogic( GetPosPixel() +
169 [ # # ][ # # ]: 0 : Point( GetSizePixel().Width(),0) ),
170 : 0 : PixelToLogic( GetPosPixel() +
171 [ # # ]: 0 : Point( 0, GetSizePixel().Height() ) ) );
[ # # # # ]
[ # # ]
172 : : }
173 : 0 : }
174 : :
175 : 0 : void SidebarTxtControl::KeyInput( const KeyEvent& rKeyEvt )
176 : : {
177 : 0 : const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
178 : 0 : sal_uInt16 nKey = rKeyCode.GetCode();
179 [ # # ][ # # ]: 0 : if ( ( rKeyCode.IsMod1() && rKeyCode.IsMod2() ) &&
[ # # ][ # # ]
[ # # ]
180 : : ( (nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN) ) )
181 : : {
182 : 0 : mrSidebarWin.SwitchToPostIt(nKey);
183 : : }
184 [ # # # # ]: 0 : else if ( nKey == KEY_ESCAPE ||
[ # # ][ # # ]
[ # # ]
185 : 0 : ( rKeyCode.IsMod1() &&
186 : : ( nKey == KEY_PAGEUP ||
187 : : nKey == KEY_PAGEDOWN ) ) )
188 : : {
189 : 0 : mrSidebarWin.SwitchToFieldPos();
190 : : }
191 [ # # ]: 0 : else if ( nKey == KEY_INSERT )
192 : : {
193 [ # # ][ # # ]: 0 : if ( !rKeyCode.IsMod1() && !rKeyCode.IsMod2() )
[ # # ]
194 : : {
195 : 0 : mrSidebarWin.ToggleInsMode();
196 : : }
197 : : }
198 : : else
199 : : {
200 : : //let's make sure we see our note
201 : 0 : mrPostItMgr.MakeVisible(&mrSidebarWin);
202 : :
203 : 0 : long aOldHeight = mrSidebarWin.GetPostItTextHeight();
204 : 0 : bool bDone = false;
205 : :
206 : : /// HACK: need to switch off processing of Undo/Redo in Outliner
207 [ # # ][ # # ]: 0 : if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) )
[ # # ][ # # ]
208 : : {
209 : 0 : bool bIsProtected = mrSidebarWin.IsProtected();
210 [ # # # # ]: 0 : if ( !bIsProtected ||
[ # # ][ # # ]
211 : : ( bIsProtected &&
212 : 0 : !mrSidebarWin.GetOutlinerView()->GetOutliner()->GetEditEngine().DoesKeyChangeText(rKeyEvt)) )
213 : : {
214 [ # # ][ # # ]: 0 : bDone = GetTextView() && GetTextView()->PostKeyEvent( rKeyEvt );
215 : : }
216 : : else
217 : : {
218 [ # # ][ # # ]: 0 : InfoBox( this, SW_RES( MSG_READONLY_CONTENT )).Execute();
[ # # ]
219 : : }
220 : : }
221 [ # # ]: 0 : if (bDone)
222 : 0 : mrSidebarWin.ResizeIfNeccessary( aOldHeight, mrSidebarWin.GetPostItTextHeight() );
223 : : else
224 : : {
225 : : // write back data first when showing navigator
226 [ # # ]: 0 : if ( nKey==KEY_F5 )
227 : 0 : mrSidebarWin.UpdateData();
228 [ # # ]: 0 : if (!mrDocView.KeyInput(rKeyEvt))
229 : 0 : Window::KeyInput(rKeyEvt);
230 : : }
231 : : }
232 : :
233 : 0 : mrDocView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
234 : 0 : }
235 : :
236 : 0 : void SidebarTxtControl::MouseMove( const MouseEvent& rMEvt )
237 : : {
238 [ # # ]: 0 : if ( GetTextView() )
239 : : {
240 : 0 : OutlinerView* pOutlinerView( GetTextView() );
241 : 0 : pOutlinerView->MouseMove( rMEvt );
242 : : // mba: why does OutlinerView not handle the modifier setting?!
243 : : // this forces the postit to handle *all* pointer types
244 [ # # ]: 0 : SetPointer( pOutlinerView->GetPointer( rMEvt.GetPosPixel() ) );
245 : :
246 : 0 : const EditView& aEV = pOutlinerView->GetEditView();
247 : 0 : const SvxFieldItem* pItem = aEV.GetFieldUnderMousePointer();
248 [ # # ]: 0 : if ( pItem )
249 : : {
250 : 0 : const SvxFieldData* pFld = pItem->GetField();
251 [ # # ][ # # ]: 0 : const SvxURLField* pURL = PTR_CAST( SvxURLField, pFld );
252 [ # # ]: 0 : if ( pURL )
253 : : {
254 [ # # ]: 0 : String sURL( pURL->GetURL() );
255 [ # # ]: 0 : SvtSecurityOptions aSecOpts;
256 [ # # ][ # # ]: 0 : if ( aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK) )
257 : : {
258 [ # # ]: 0 : sURL.InsertAscii( ": ", 0 );
259 [ # # ][ # # ]: 0 : sURL.Insert( ViewShell::GetShellRes()->aHyperlinkClick, 0 );
260 : : }
261 [ # # ][ # # ]: 0 : Help::ShowQuickHelp( this,PixelToLogic(Rectangle(GetPosPixel(),Size(50,10))),sURL);
[ # # ][ # # ]
[ # # ][ # # ]
262 : : }
263 : : }
264 : : }
265 : 0 : }
266 : :
267 : 0 : void SidebarTxtControl::MouseButtonDown( const MouseEvent& rMEvt )
268 : : {
269 [ # # ]: 0 : if ( GetTextView() )
270 : : {
271 [ # # ]: 0 : SvtSecurityOptions aSecOpts;
272 [ # # ]: 0 : bool bExecuteMod = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK);
273 : :
274 [ # # ][ # # ]: 0 : if ( !bExecuteMod || (bExecuteMod && rMEvt.GetModifier() == KEY_MOD1))
[ # # ][ # # ]
275 : : {
276 : 0 : const EditView& aEV = GetTextView()->GetEditView();
277 [ # # ]: 0 : const SvxFieldItem* pItem = aEV.GetFieldUnderMousePointer();
278 [ # # ]: 0 : if ( pItem )
279 : : {
280 : 0 : const SvxFieldData* pFld = pItem->GetField();
281 [ # # ][ # # ]: 0 : const SvxURLField* pURL = PTR_CAST( SvxURLField, pFld );
[ # # ][ # # ]
282 [ # # ]: 0 : if ( pURL )
283 : : {
284 [ # # ]: 0 : GetTextView()->MouseButtonDown( rMEvt );
285 : 0 : SwWrtShell &rSh = mrDocView.GetWrtShell();
286 [ # # ]: 0 : String sURL( pURL->GetURL() );
287 [ # # ]: 0 : String sTarget( pURL->GetTargetFrame() );
288 [ # # ][ # # ]: 0 : ::LoadURL(rSh, sURL, URLLOAD_NOFILTER, sTarget);
[ # # ]
289 [ # # ][ # # ]: 0 : return;
290 : : }
291 : : }
292 [ # # ][ # # ]: 0 : }
293 : : }
294 : :
295 : 0 : GrabFocus();
296 [ # # ]: 0 : if ( GetTextView() )
297 : : {
298 : 0 : GetTextView()->MouseButtonDown( rMEvt );
299 : : }
300 : 0 : mrDocView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
301 : : }
302 : :
303 : 0 : void SidebarTxtControl::MouseButtonUp( const MouseEvent& rMEvt )
304 : : {
305 [ # # ]: 0 : if ( GetTextView() )
306 : 0 : GetTextView()->MouseButtonUp( rMEvt );
307 : 0 : }
308 : :
309 : 0 : IMPL_LINK( SidebarTxtControl, OnlineSpellCallback, SpellCallbackInfo*, pInfo )
310 : : {
311 [ # # ]: 0 : if ( pInfo->nCommand == SPELLCMD_STARTSPELLDLG )
312 : : {
313 : 0 : mrDocView.GetViewFrame()->GetDispatcher()->Execute( FN_SPELL_GRAMMAR_DIALOG, SFX_CALLMODE_ASYNCHRON);
314 : : }
315 : 0 : return 0;
316 : : }
317 : :
318 : 0 : IMPL_LINK( SidebarTxtControl, Select, Menu*, pSelMenu )
319 : : {
320 : 0 : mrSidebarWin.ExecuteCommand( pSelMenu->GetCurItemId() );
321 : 0 : return 0;
322 : : }
323 : :
324 : 0 : void SidebarTxtControl::Command( const CommandEvent& rCEvt )
325 : : {
326 [ # # ]: 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
327 : : {
328 [ # # # # : 0 : if ( !mrSidebarWin.IsProtected() &&
# # ][ # # ]
329 : 0 : GetTextView() &&
330 : 0 : GetTextView()->IsWrongSpelledWordAtPos( rCEvt.GetMousePosPixel(),sal_True ))
331 : : {
332 [ # # ]: 0 : Link aLink = LINK(this, SidebarTxtControl, OnlineSpellCallback);
333 [ # # ]: 0 : GetTextView()->ExecuteSpellPopup(rCEvt.GetMousePosPixel(),&aLink);
334 : : }
335 : : else
336 : : {
337 [ # # ]: 0 : SfxPopupMenuManager* pMgr = mrDocView.GetViewFrame()->GetDispatcher()->Popup(0, this,&rCEvt.GetMousePosPixel());
338 [ # # ][ # # ]: 0 : ((PopupMenu*)pMgr->GetSVMenu())->SetSelectHdl( LINK(this, SidebarTxtControl, Select) );
339 : :
340 : : {
341 [ # # ][ # # ]: 0 : XubString aText = ((PopupMenu*)pMgr->GetSVMenu())->GetItemText( FN_DELETE_NOTE_AUTHOR );
342 [ # # ]: 0 : SwRewriter aRewriter;
343 [ # # ][ # # ]: 0 : aRewriter.AddRule(UndoArg1, mrSidebarWin.GetAuthor());
[ # # ]
344 [ # # ][ # # ]: 0 : aText = aRewriter.Apply(aText);
[ # # ]
345 [ # # ][ # # ]: 0 : ((PopupMenu*)pMgr->GetSVMenu())->SetItemText(FN_DELETE_NOTE_AUTHOR,aText);
[ # # ][ # # ]
346 : : }
347 : :
348 : 0 : Point aPos;
349 [ # # ]: 0 : if (rCEvt.IsMouseEvent())
350 : 0 : aPos = rCEvt.GetMousePosPixel();
351 : : else
352 : : {
353 [ # # ]: 0 : const Size aSize = GetSizePixel();
354 : 0 : aPos = Point( aSize.getWidth()/2, aSize.getHeight()/2 );
355 : : }
356 : :
357 : : //!! call different Execute function to get rid of the new thesaurus sub menu
358 : : //!! pointer created in the call to Popup.
359 : : //!! Otherwise we would have a memory leak (see also #i107205#)
360 [ # # ]: 0 : pMgr->Execute( aPos, this );
361 [ # # ][ # # ]: 0 : delete pMgr;
362 : : }
363 : : }
364 : : else
365 [ # # ]: 0 : if (rCEvt.GetCommand() == COMMAND_WHEEL)
366 : : {
367 [ # # ]: 0 : if (mrSidebarWin.IsScrollbarVisible())
368 : : {
369 : 0 : const CommandWheelData* pData = rCEvt.GetWheelData();
370 [ # # ][ # # ]: 0 : if (pData->IsShift() || pData->IsMod1() || pData->IsMod2())
[ # # ][ # # ]
371 : : {
372 : 0 : mrDocView.HandleWheelCommands(rCEvt);
373 : : }
374 : : else
375 : : {
376 : 0 : HandleScrollCommand( rCEvt, 0 , mrSidebarWin.Scrollbar());
377 : : }
378 : : }
379 : : else
380 : : {
381 : 0 : mrDocView.HandleWheelCommands(rCEvt);
382 : : }
383 : : }
384 : : else
385 : : {
386 [ # # ]: 0 : if ( GetTextView() )
387 : 0 : GetTextView()->Command( rCEvt );
388 : : else
389 : 0 : Window::Command(rCEvt);
390 : : }
391 : 0 : }
392 : :
393 : 0 : rtl::OUString SidebarTxtControl::GetSurroundingText() const
394 : : {
395 [ # # ]: 0 : if (GetTextView())
396 [ # # ]: 0 : return GetTextView()->GetSurroundingText();
397 : 0 : return rtl::OUString();
398 : : }
399 : :
400 : 0 : Selection SidebarTxtControl::GetSurroundingTextSelection() const
401 : : {
402 [ # # ]: 0 : if( GetTextView() )
403 : 0 : return GetTextView()->GetSurroundingTextSelection();
404 : : else
405 : 0 : return Selection( 0, 0 );
406 : : }
407 : :
408 : 0 : css::uno::Reference< css::accessibility::XAccessible > SidebarTxtControl::CreateAccessible()
409 : : {
410 : :
411 [ # # ]: 0 : SidebarTxtControlAccessible* pAcc( new SidebarTxtControlAccessible( *this ) );
412 [ # # ][ # # ]: 0 : css::uno::Reference< css::awt::XWindowPeer > xWinPeer( pAcc );
413 [ # # ]: 0 : SetWindowPeer( xWinPeer, pAcc );
414 : :
415 [ # # ]: 0 : css::uno::Reference< css::accessibility::XAccessible > xAcc( xWinPeer, css::uno::UNO_QUERY );
416 : 0 : return xAcc;
417 : : }
418 : :
419 : : } } // end of namespace sw::sidebarwindows
420 : :
421 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|