sync master with lastest vba changes
[ooovba.git] / sd / inc / Outliner.hxx
bloba23205cddfe9205b13bec4f78bb8e17e1f7ca93c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Outliner.hxx,v $
10 * $Revision: 1.16.14.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_OUTLINER_HXX
32 #define SD_OUTLINER_HXX
34 #include <svx/svdobj.hxx>
35 #include <svx/svdoutl.hxx>
36 #include "pres.hxx"
37 #include "OutlinerIterator.hxx"
38 #include <svx/SpellPortions.hxx>
39 #include <memory>
40 #include <boost/shared_ptr.hpp>
42 class Dialog;
43 class SdPage;
44 class SdrObject;
45 class SdrTextObj;
46 class SdDrawDocument;
47 class SfxStyleSheetPool;
48 class SdrObjListIter;
50 namespace sd {
52 class DrawViewShell;
53 class View;
54 class ViewShell;
55 class Window;
57 /** The main purpose of this class is searching and replacing as well as
58 spelling of impress documents. The main part of both tasks lies in
59 iterating over the pages and view modes of a document and apply the
60 respective function to all objects containing text on those pages.
62 <p>Relevant objects: There are two sets of objects to search/spell
63 check. One is the set of all selected objects. The other consists of
64 all objects on all pages in draw-, notes-, and handout view as well as
65 slide- and background view (draw pages and master pages).</p>
67 <p>Iteration: Search/replace and spelling functions operate on shapes
68 containing text. To cover all relevant objects an order has to be
69 defined on the objects. For the set of all selected objects this order
70 is simply the order in which they can be retrieved from the selection
71 object.<br>
72 When there is no selection the order is nested. The three modes of the
73 draw view are on the outer level: draw mode, notes mode, handout mode.
74 The inner level switches between draw pages and master pages. This
75 leads to the following order:
76 <ol>
77 <li>draw pages of draw mode</li>
78 <li>master pages of draw mode</li>
79 <li>draw pages of notes mode</li>
80 <li>master pages of notes mode</li>
81 <li>draw pages of handout mode</li>
82 <li>master pages of handout mode</li>
83 </ol>
84 Iteration starts at the top of the current page. When reaching the end
85 of the document, i.e. the last master page of the handout mode, it jumps
86 to the first draw page of draw mode. In backward searches this order is
87 reversed. When doing a <em>replace all</em> then the whole document is
88 searched for matches starting at the first page of the draw/slide view
89 (or last page of handout/background view even though search
90 direction).</p>
92 <p>The start position is restored after finishing spell checking or
93 replacing all matches in a document.</p>
95 <p>Some related pieces of information:
96 The search dialog (<type>SvxSearchDialog</type>) can be controlled in
97 more than one way:
98 <ul><li>A set of option flags returned by the slot call
99 SID_SEARCH_OPTIONS handled by the
100 <member>SdDrawDocument::GetState()</member> method.</li>
101 <li>The contents of the search item of type
102 <type>SvxSearchItem</type>.</li>
103 <li>The <member>HasSelection()</member> view shell method that returns
104 whether or not a selection exists. However, it is called from the
105 search dialog with an argument so that only text selections are
106 queried. This is only sufficient for searching the outline view.
107 </p>
109 class Outliner
110 : public SdrOutliner
112 public:
113 friend class ::sd::outliner::OutlinerContainer;
115 /** Create a new sd outliner object.
116 @param pDoc
117 The draw document from which to take the content.
118 @param nMode
119 The valid values <const>OUTLINERMODE_DONTKNOW</const>,
120 <const>OUTLINERMODE_TEXTOBJECT</const>,
121 <const>OUTLINERMODE_TITLEOBJECT</const>,
122 <const>OUTLINERMODE_OUTLINEOBJECT</const>, and
123 <const>OUTLINERMODE_OUTLINEVIEW</const> are defined in
124 svx/outliner.hxx.
126 Outliner( SdDrawDocument* pDoc, USHORT nMode );
127 virtual ~Outliner();
129 /** Despite the name this method is called prior to spell cheking *and*
130 searching and replacing. The position of current view
131 mode/page/object/caret position is remembered and, depending on the
132 search mode, may be restored after finishing searching/spell
133 checking.
135 void PrepareSpelling (void);
137 /** Initialize a spell check but do not start it yet. This method
138 is a better candiate for the name PrepareSpelling.
140 void StartSpelling (void);
142 /** Proxy for method from base class to avoid compiler warning */
143 void StartSpelling(EditView&, unsigned char);
145 /** Initiate a find and/or replace on the next relevant text object.
146 @return
147 Returns </TRUE> when the search/replace is finished (as
148 indicated by user input to the search dialog). A </FALSE> value
149 indicates that another call to this method is required.
151 bool StartSearchAndReplace (const SvxSearchItem* pSearchItem);
153 /** Iterate over the sentences in all text shapes and stop at the
154 next sentence with spelling errors. While doing so the view
155 mode may be changed and text shapes are set into edit mode.
157 ::svx::SpellPortions GetNextSpellSentence (void);
159 /** Release all resources that have been created during the find&replace
160 or spell check.
162 void EndSpelling (void);
164 /** callback for textconversion */
165 sal_Bool ConvertNextDocument (void);
167 /** Starts the text conversion (hangul/hanja or Chinese simplified/traditional)
168 for the current viewshell */
169 void StartConversion( INT16 nSourceLanguage, INT16 nTargetLanguage,
170 const Font *pTargetFont, INT32 nOptions, BOOL bIsInteractive );
172 /** This is called internaly when text conversion is started.
173 The position of current view mode/page/object/caret position
174 is remembered and will be restored after conversion.
176 void BeginConversion (void);
178 /** Release all resources that have been created during the conversion */
179 void EndConversion (void);
181 DECL_LINK( SpellError, void * );
183 enum ChangeHint { CH_VIEW_SHELL_INVALID, CH_VIEW_SHELL_VALID };
185 /** Handle a change outside the outliner which may affect the outliner.
186 At the moment this is restricted to changes of the main view shell
187 but later may include any changes that are detected now by
188 DetectChange().
190 void HandleOutsideChange (ChangeHint eHint);
192 int GetIgnoreCurrentPageChangesLevel() const { return mnIgnoreCurrentPageChangesLevel; };
193 void IncreIgnoreCurrentPageChangesLevel() { mnIgnoreCurrentPageChangesLevel++; };
194 void DecreIgnoreCurrentPageChangesLevel() { mnIgnoreCurrentPageChangesLevel--; };
196 private:
197 class Implementation;
198 ::std::auto_ptr<Implementation> mpImpl;
200 /// Specifies whether to search and replace, to spell check or to do a
201 /// text conversion.
202 enum mode {SEARCH, SPELL, TEXT_CONVERSION} meMode;
204 /// The view which displays the searched objects.
205 ::sd::View* mpView;
206 /// The view shell containing the view.
207 ::boost::shared_ptr<ViewShell> mpViewShell;
208 /// This window contains the view.
209 ::sd::Window* mpWindow;
210 /// The document on whose objects and pages this class operates.
211 SdDrawDocument* mpDrawDocument;
213 /** this is the language that is used for current text conversion.
214 Only valid if meMode is TEXT_CONVERSION.
216 INT16 mnConversionLanguage;
218 /** While the value of this flag is greater than 0 changes of the current page
219 do not lead to selecting the corresponding text in the outliner.
221 int mnIgnoreCurrentPageChangesLevel;
223 /// Specifies whether the search string has been found so far.
224 bool mbStringFound;
226 /** This flag indicates whether there may exist a match of the search
227 string before/after the current position in the document. It can be
228 set to </FALSE> only when starting from the beginning/end of the
229 document. When reaching the end/beginning with it still be set to
230 </FALSE> then there exists no match and the search can be terminated.
232 bool mbMatchMayExist;
234 /// The number of pages in the current view.
235 USHORT mnPageCount;
237 /// Number of objects on the current page / in the current selection.
238 INT32 mnObjectCount;
240 /** A <TRUE/> value indicates that the end of the find&replace or spell
241 check has been reached.
243 bool mbEndOfSearch;
245 /** Set to <TRUE/> when an object has been prepared successfully for
246 searching/spell checking. This flag directs the internal iteration
247 which stops when set to </TRUE>.
249 bool mbFoundObject;
251 /** When set to <TRUE/> this flag indicates that an error has occured
252 that should terminate the iteration over the objects to search/spell
253 check.
255 bool mbError;
257 /** This flag indicates whether to search forward or backwards.
259 bool mbDirectionIsForward;
261 /** This flag indicates that only the selected objects are to be
262 searched.
264 bool mbRestrictSearchToSelection;
266 /** When the search is restricted to the current selection then
267 this list contains pointers to all the objects of the
268 selection. This copy is necessary because during the search
269 process the mark list is modified.
271 ::std::vector<SdrObjectWeakRef> maMarkListCopy;
273 /** This flag inidcates that only the current view is to be used for
274 searching and spelling. Automatically switching to other view does
275 not take place when this flag is set.
277 bool mbProcessCurrentViewOnly;
279 /** Current object that may be a text object. The object pointer to
280 corresponds to <member>mnObjIndex</member>. While iterating over the
281 objects on a page <member>mpObj</member> will point to every object
282 while <member>mpTextObj</member> will be set only to valid text
283 objects.
285 SdrObject* mpObj;
287 /** this stores the first object that is used for text conversion.
288 Conversion automaticly wraps around the document and stops when it
289 finds this object again.
291 SdrObject* mpFirstObj;
293 /// Candidate for being searched/spell checked.
294 SdrTextObj* mpTextObj;
296 /// Current text to be searched/spelled inside the current text object
297 sal_Int32 mnText;
299 /// Paragraph object of <member>mpTextObj</member>.
300 OutlinerParaObject* mpParaObj;
302 /// The view mode that was active when starting to search/spell check.
303 PageKind meStartViewMode;
305 /// The master page mode that was active when starting to search/spell check.
306 EditMode meStartEditMode;
308 /// The current page index on starting to search/spell check.
309 USHORT mnStartPageIndex;
311 /// The object in edit mode when searching /spell checking was started
312 /// (if any).
313 SdrObject* mpStartEditedObject;
315 /// The position of the caret when searching /spell checking was started.
316 ESelection maStartSelection;
318 /** The search item contains various attributes that define the type of
319 search. It is set every time the
320 <member>SearchAndReplaceAll</member> method is called.
322 const SvxSearchItem* mpSearchItem;
324 /// The actual object iterator.
325 ::sd::outliner::Iterator maObjectIterator;
326 /// The current position of the object iterator.
327 ::sd::outliner::IteratorPosition maCurrentPosition;
328 /// The position when the search started. Corresponds largely to the
329 /// m?Start* members.
330 ::sd::outliner::Iterator maSearchStartPosition;
331 /** The last valid position desribes where the last text object has been
332 found. This position is restored when some dialogs are shown. The
333 position is initially set to the where the search begins.
335 ::sd::outliner::IteratorPosition maLastValidPosition;
337 /** This flag remebers a selection change between a call to the
338 selection change listener callback and the next
339 <member>DetectChange()</member> method call.
341 bool mbSelectionHasChanged;
343 /** This flag indicates whether a selection change event is expected due
344 to a programatical change of the selection.
346 bool mbExpectingSelectionChangeEvent;
348 /** This flag is set to true when the whole document has been
349 processed once 'officially', i.e. a message box has been shown
350 that tells the user so.
352 bool mbWholeDocumentProcessed;
354 /** When this flag is true then a PrepareSpelling() is executed when
355 StartSearchAndReplace() is called the next time.
357 bool mbPrepareSpellingPending;
359 /** In this flag we store whether the view shell is valid and may be
360 accessed.
362 bool mbViewShellValid;
364 /** Initialize the object iterator. Call this method after being
365 invoked from the search or spellcheck dialog. It creates a new
366 iterator pointing at the current object when this has not been done
367 before. It reverses the direction of iteration if the given flag
368 differs from the current direction.
369 @param bDirectionIsForward
370 This flag specifies in which direction to iterator over the
371 objects. If it differs from the current direction the iterator
372 is reversed.
374 void Initialize (bool bDirectionIsForward);
376 /** Do search and replace for whole document.
378 bool SearchAndReplaceAll (void);
380 /** Do search and replace for next match.
381 @return
382 The return value specifies whether the search ended (</TRUE>) or
383 another call to this method is required (</FALSE>).
385 bool SearchAndReplaceOnce (void);
387 /** Detect changes of the document or view and react accordingly. Such
388 changes may occur because different calls to
389 <member>SearchAndReplace()</member> there usually is user
390 interaction. This is at least the press of the search or replace
391 button but may include any other action some of which affect the
392 search.
394 void DetectChange (void);
396 /** Detect whether the selection has changed.
397 @return
398 Return <TRUE/> when the selection has been changed since the
399 last call to this method.
401 bool DetectSelectionChange (void);
403 /** Remember the current edited object/caret position/page/view mode
404 when starting to search/spell check so that it can be restored on
405 termination.
407 void RememberStartPosition (void);
409 /** Restore the position stored in the last call of
410 <member>RememberStartPositiony</member>.
412 void RestoreStartPosition (void);
414 /** Provide next object to search or spell check as text object in edit
415 mode on the current page. This skips all objects that do not
416 match or are no text object.
418 void ProvideNextTextObject (void);
420 /** Handle the situation that the iterator has reached the last object.
421 This may result in setting the <member>mbEndOfSearch</member> flag
422 back to </FALSE>. This method may show either the end-of-search
423 dialog or the wrap-arround dialog.
425 void EndOfSearch (void);
427 /** Prepare to commence searching/spell checking on the specified page.
428 This also creates a proper page iterator.
429 @param nPageIndex
430 Index of the page to prepare for searching. The default value
431 of -1 is a flag for using the first/last page of the current
432 edit mode/view mode depending on the search direction.
434 void InitPage (USHORT nPageIndex = (USHORT)-1);
436 /** Show a dialog that tells the user that the search has ended either
437 because there are no more matches after finding at least one or that
438 no match has been found at all.
440 void ShowEndOfSearchDialog (void);
442 /** Show a dialog that asks the user whether to wrap arround to the
443 beginning/end of the document and continue with the search/spell
444 check.
446 bool ShowWrapArroundDialog (void);
448 /** Check whether the object pointed to by the iterator is a valid text
449 object.
450 @param aPosition
451 The object for which to test whether it is a valid text object.
453 bool IsValidTextObject (const ::sd::outliner::IteratorPosition& rPosition);
455 /** Put text of current text object into outliner so that the text can
456 be searched/spell checked.
458 void PutTextIntoOutliner (void);
460 /** Prepare to do spell checking on the current text object. This
461 includes putting it into edit mode. Under certain conditions this
462 method sets <member>mbEndOfSearch</member> to <TRUE/>.
464 void PrepareSpellCheck (void);
466 /** Prepare to search and replace on the current text object. This
467 includes putting it into edit mode.
469 void PrepareSearchAndReplace (void);
471 /** Prepare to do a text conversion on the current text
472 object. This includes putting it into edit mode.
474 void PrepareConversion (void);
476 /** Switch to a new view mode. Try to restore the original edit mode
477 before doing so.
478 @param ePageKind
479 Specifies the new view mode.
481 void SetViewMode (PageKind ePageKind);
483 /** Switch to the page or master page specified by the
484 <member>mnPage</member> index. Master page mode is specified by
485 <member>meEditMode</member>.
486 @param eEditMode
487 The new edit mode.
488 @param nPageIndex
489 The new page index.
491 void SetPage (EditMode eEditMode, USHORT nPageIndex);
493 /** Switch on edit mode for the currently selected text object.
495 void EnterEditMode (BOOL bGrabFocus=TRUE);
497 /** Return the position at which a new search is started with respect to
498 the search direction as specified by the argument.
499 @return
500 The position mentioned above in form of a selection with start
501 equals end.
503 ESelection GetSearchStartPosition (void);
505 /** Detect whether there exists a previous match. Note that only the
506 absence of such a match can be detected reliably. An existing match
507 is assumed when the search started not at the beginning/end of the
508 presentation. This does not have to be true. The user can have set
509 the cursor at the middle of the text without a prior search.
510 @return
511 Returns </True> when there is no previous match and </False>
512 when there may be one.
514 bool HasNoPreviousMatch (void);
516 /** Handle a failed search (with or without replace) for the outline
517 mode. Show message boxes when the search failed completely,
518 i.e. there is no match in the whole presentation, or when no further
519 match exists.
520 @return
521 The returned value indicates whether another (wrapped arround)
522 search shall take place. If that is so, then it is the caller's
523 responsibility to set the cursor position accordingly.
525 bool HandleFailedSearch (void);
527 /** Return a parent window for a dialog. The returned window depends on
528 the search mode.
530 ::Window* GetParentForDialog (void);
532 /** Take a position as returned by an object iterator and switch to the
533 view and page on which the object specified by this position is
534 located.
535 @param rPosition
536 This position points to a <type>SdrObject</type> object and
537 contains the view and page where it is located.
538 @return
539 Return a pointer to the <type>SdrObject</type>.
541 SdrObject* SetObject (const ::sd::outliner::IteratorPosition& rPosition);
543 /** Use this method when the view shell in which to search has changed.
544 It handles i.e. registering at the associated view as selection
545 change listener.
547 void SetViewShell (const ::boost::shared_ptr<ViewShell>& rpViewShell);
549 /** Activate or deactivate the search in the current selection. Call
550 this method whenever the selection has changed. This method creates
551 a copy of the current selection and reassings the object iterator to
552 the current() iterator.
554 void HandleChangedSelection (void);
556 /** Initiate the spell check of the next relevant text object.
557 When the outline view is active then this method is called
558 after a wrap arround to continue at the beginning of the document.
559 @return
560 Returns <TRUE/> to indicate that another call to this method is
561 required. When all text objects have been processed then
562 <FALSE/> is returned.
564 virtual BOOL SpellNextDocument (void);
566 /** Show the given message box and make it modal. It is assumed that
567 the parent of the given dialog is NULL, i.e. the application
568 window. This function makes sure that the otherwise non-modal
569 search dialog, if visible, is locked, too.
571 USHORT ShowModalMessageBox (Dialog& rMessageBox);
574 } // end of namespace sd
576 #endif