xref: /trunk/main/svx/workben/edittest.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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_svx.hxx"
30 
31 #include <editeng/editeng.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <editeng/editview.hxx>
34 #include <editeng/editobj.hxx>
35 #include <editeng/editstat.hxx>
36 #include <eerdll.hxx>
37 #include <editeng/flditem.hxx>
38 #include <tools/urlobj.hxx>
39 #include <svx/svxacorr.hxx>
40 #include <tools/fsys.hxx>
41 #include <svx/xpoly.hxx>
42 #include <svtools/filedlg.hxx>
43 
44 #include <vcl/window.hxx>
45 #include <vcl/svapp.hxx>
46 #include <vcl/font.hxx>
47 #include <vcl/sound.hxx>
48 #include <vcl/print.hxx>
49 #include <vcl/toolbox.hxx>
50 #include <vcl/help.hxx>
51 #include <vcl/scrbar.hxx>
52 #include <vcl/wrkwin.hxx>
53 #include <vcl/msgbox.hxx>
54 
55 #include <dialdll.hxx>
56 
57 
58 #define SERVICE_SIMPLEREGISTRY             "com.sun.star.registry.SimpleRegistry"
59 #include <comphelper/processfactory.hxx>
60 #include <comphelper/regpathhelper.hxx>
61 #include <cppuhelper/servicefactory.hxx>
62 #include <cppuhelper/bootstrap.hxx>
63 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
64 #include <com/sun/star/lang/XInitialization.hpp>
65 #include <com/sun/star/registry/XSimpleRegistry.hpp>
66 #include <sfx2/sfxuno.hxx>
67 
68 // SVX
69 #include <editeng/lrspitem.hxx>
70 #include <editeng/shdditem.hxx>
71 #include <editeng/cntritem.hxx>
72 #include <editeng/crsditem.hxx>
73 #include <editeng/udlnitem.hxx>
74 #include <editeng/lspcitem.hxx>
75 #include <editeng/escpitem.hxx>
76 #include <editeng/kernitem.hxx>
77 #include <editeng/akrnitem.hxx>
78 #include <editeng/wrlmitem.hxx>
79 #include <editeng/colritem.hxx>
80 #include <editeng/ulspitem.hxx>
81 #include <editeng/postitem.hxx>
82 #include <editeng/adjitem.hxx>
83 #include <editeng/wghtitem.hxx>
84 #include <editeng/fhgtitem.hxx>
85 #include <editeng/fontitem.hxx>
86 #include <fwdtitem.hxx>
87 
88 // SVTOOLS
89 #include <svl/undo.hxx>
90 #include <svl/itemset.hxx>
91 #include <svl/itempool.hxx>
92 #include <svl/poolitem.hxx>
93 #include <svtools/printdlg.hxx>
94 
95 #include <osl/file.hxx>
96 #include <osl/process.h>
97 #include <rtl/bootstrap.hxx>
98 
99 #define TB_LEFT          1
100 #define TB_RIGHT         2
101 #define TB_CENTER        3
102 #define TB_UNDO          4
103 #define TB_REDO          5
104 #define TB_FONT1         6
105 #define TB_FONT2         7
106 #define TB_ITALIC        8
107 #define TB_BOLD          9
108 #define TB_UNDERLINE    10
109 #define TB_BLACK        11
110 #define TB_GREEN        12
111 #define TB_OPEN         13
112 #define TB_SAVE         14
113 #define TB_SBL          15
114 #define TB_SBSA         16
115 #define TB_LR           17
116 #define TB_DRAW         18
117 #define TB_DEFTAB       19
118 #define TB_OPEN2        20
119 #define TB_SAVE2        21
120 #define TB_STDSEL       33
121 #define TB_MOVE         34
122 #define TB_PARATTR1     35
123 #define TB_ROTATE       38
124 #define TB_RED          43
125 #define TB_FLAT         46
126 #define TB_BINOBJ1      47
127 #define TB_BINOBJ3      49
128 #define TB_BINOBJ4      50
129 #define TB_BINOBJ1b     51
130 #define TB_BINOBJ2b     52
131 #define TB_ATTRIBS      54
132 #define TB_IDLE         55
133 #define TB_BLOCK        56
134 #define TB_CLONEBIN     57
135 #define TB_INSERT       58
136 #define TB_PKERN        59
137 #define TB_KERN         60
138 #define TB_SUPER        61
139 #define TB_SUB          62
140 #define TB_PRINT        63
141 #define TB_FONT         64
142 #define TB_COLORS       65
143 #define TB_WLM          66
144 #define TB_OUTL         67
145 #define TB_INSFLD       68
146 #define TB_UPDFLD       69
147 #define TB_ONLINESPELL  70
148 #define TB_REDLINES     71
149 #define TB_AUTOCORRECT  72
150 #define TB_POLY         73
151 #define TB_HYPH         74
152 
153 // VARS...
154 short nRotation = 0;
155 USHORT nZoom = 100;
156 sal_Bool bURLClicked = sal_False;
157 
158 using namespace ::com::sun::star::connection;
159 using namespace ::vos;
160 using namespace ::rtl;
161 using namespace ::com::sun::star::uno;
162 using namespace ::com::sun::star::registry;
163 using namespace ::com::sun::star::lang;
164 
165 
166 
167 Reference< XMultiServiceFactory > createApplicationServiceManager()
168 {
169     Reference< XMultiServiceFactory > xMS;
170     try
171     {
172         Reference< XComponentContext >    xComponentContext = ::cppu::defaultBootstrap_InitialComponentContext();
173         if ( xComponentContext.is() )
174             xMS = xMS.query( xComponentContext->getServiceManager() );
175     }
176     catch( ::com::sun::star::uno::Exception& )
177     {
178     }
179 
180     return xMS;
181 }
182 
183 // --- class EditApp -------------------------------------------------
184 
185 SV_DECL_PTRARR_DEL( StringList, String*, 0, 4 );
186 SV_IMPL_PTRARR( StringList, String* );
187 StringList aSimpleHistory;
188 
189 class EditApp : public Application
190 {
191 public:
192     virtual void Main();
193 };
194 
195 class MyEditEngine : public EditEngine
196 {
197 public:
198     MyEditEngine( SfxItemPool* pPool ) : EditEngine( pPool ) { ; }
199     virtual String  CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos, Color*& rTxtColor, Color*& rFldColor );
200     virtual void    FieldClicked( const SvxFieldItem& rField, USHORT nPara, USHORT nPos );
201     virtual void    FieldSelected( const SvxFieldItem& rField, USHORT nPara, USHORT nPos );
202 };
203 
204 XubString __EXPORT MyEditEngine::CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos, Color*& rpTxtColor, Color*& rpFldColor )
205 {
206     const SvxFieldData* pField = rField.GetField();
207     if ( !pField )
208         return String( RTL_CONSTASCII_USTRINGPARAM( "<Empty>" ) );
209 
210     if ( pField->ISA( SvxDateField ) )
211         return ((const SvxDateField*)pField)->GetFormatted( LANGUAGE_SYSTEM, LANGUAGE_SYSTEM );
212     else if ( pField->ISA( SvxURLField ) )
213     {
214         const SvxURLField* pURL = (const SvxURLField*)pField;
215         if ( !bURLClicked )
216         {
217             delete rpTxtColor;
218             rpTxtColor = new Color( COL_BLUE );
219         }
220         else
221         {
222             delete rpTxtColor;
223             rpTxtColor = new Color( COL_RED );
224             delete rpFldColor;
225             rpFldColor = new Color( COL_YELLOW );
226         }
227         if ( pURL->GetFormat() == SVXURLFORMAT_URL )
228             return pURL->GetURL();
229         return pURL->GetRepresentation();
230     }
231     return String( RTL_CONSTASCII_USTRINGPARAM( "???" ) );
232 }
233 
234 void __EXPORT MyEditEngine::FieldClicked( const SvxFieldItem& rField, USHORT nPara, USHORT nPos )
235 {
236     EditEngine::FieldClicked( rField, nPara, nPos );    // Falls URL
237     const SvxFieldData* pField = rField.GetField();
238     if ( !pField )
239         return;
240 
241     if ( pField->ISA( SvxURLField ) )
242     {
243         bURLClicked = TRUE;
244         UpdateFields();
245     }
246     else
247         Sound::Beep();
248 }
249 
250 void __EXPORT MyEditEngine::FieldSelected( const SvxFieldItem& rField, USHORT nPara, USHORT nPos )
251 {
252     const SvxFieldData* pField = rField.GetField();
253     if ( !pField )
254         return;
255 
256     InfoBox( 0, String( RTL_CONSTASCII_USTRINGPARAM( "Feld selektiert!" ) ) ).Execute();
257 }
258 
259 
260 class MyView : public WorkWindow
261 {
262 private:
263     EditEngine*     pEditEngine;
264     EditView*       pEditView;
265 
266 public:
267                     MyView( Window* pParent, EditEngine* pEditEngine );
268                     ~MyView();
269 
270     virtual void    Paint( const Rectangle& );
271     virtual void    Resize();
272     virtual void    KeyInput( const KeyEvent& rKeyEvt );
273     virtual void    MouseMove( const MouseEvent& rMEvt );
274     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
275     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
276     virtual void    Command( const CommandEvent& rCEvt );
277     BOOL            Drop( const DropEvent& rEvt );
278     BOOL            QueryDrop( DropEvent& rEvt );
279 };
280 
281 MyView::MyView( Window* pParent, EditEngine* pEE ) : WorkWindow( pParent, WinBits( WB_STDWORK ) )
282 {
283     pEditEngine = pEE;
284     pEditView = new EditView( pEditEngine, this );
285     pEditEngine->InsertView( pEditView );
286     SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Another View..." ) ) );
287 //  EnableDrop();
288     SetBackgroundBrush( Brush( Color( COL_LIGHTBLUE ) ) );
289     Show();
290 }
291 
292 MyView::~MyView()
293 {
294     pEditEngine->RemoveView( pEditView );
295     delete pEditView;
296 }
297 
298 void __EXPORT MyView::Paint( const Rectangle& rRec )
299 {
300     pEditView->Paint( rRec );
301 }
302 
303 void __EXPORT MyView::Resize()
304 {
305     Size aPaperSz( GetOutputSize() );
306 //  aPaperSz.Width() /= 2;
307 //  aPaperSz.Height() /= 2;
308     pEditView->SetOutputArea( Rectangle( Point( 0,0 ), aPaperSz ) );
309     pEditView->SetVisArea( Rectangle( Point( 0,0 ), aPaperSz ) );
310     Invalidate();
311     pEditView->ShowCursor();
312 }
313 
314 // --- MyView::KeyInput() --------------------------------------
315 void __EXPORT MyView::KeyInput( const KeyEvent& rKEvt )
316 {
317     pEditView->PostKeyEvent( rKEvt );
318 }
319 
320 void __EXPORT MyView::MouseMove( const MouseEvent& rMEvt )
321 {
322     Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
323     if ( pEditView->GetOutputArea().IsInside( aPos ) )
324         SetPointer( pEditView->GetPointer() );
325     else
326         SetPointer( Pointer() );
327 
328 
329     pEditView->MouseMove( rMEvt );
330 }
331 
332 void __EXPORT MyView::MouseButtonDown( const MouseEvent& rMEvt )
333 {
334     pEditView->MouseButtonDown( rMEvt );
335 }
336 
337 void __EXPORT MyView::MouseButtonUp( const MouseEvent& rMEvt )
338 {
339     pEditView->MouseButtonUp( rMEvt );
340 }
341 
342 void __EXPORT MyView::Command( const CommandEvent& rCEvt )
343 {
344     if ( rCEvt.GetCommand() == COMMAND_STARTDRAG )
345         pEditView->Command(rCEvt);
346 }
347 
348 BOOL __EXPORT MyView::Drop( const DropEvent& rEvt )
349 {
350     return pEditView->Drop( rEvt );
351 }
352 
353 BOOL __EXPORT MyView::QueryDrop( DropEvent& rEvt )
354 {
355     return pEditView->QueryDrop( rEvt );
356 }
357 
358 // --- class EditMainWindow --------------------------------------------
359 DECLARE_LIST( ViewList, MyView* );
360 
361 class EditViewWindow : public Window
362 {
363 private:
364     MyEditEngine*           pEditEngine;
365     EditView*               pEditView;
366     Pointer                 aStdPtr;
367     Pointer                 aURLPtr;
368     WorkWindow*             pTmpWindow;
369     ViewList                aViewList;
370 
371     XubString               aTestStr;
372 
373 
374 public:
375                     EditViewWindow( Window* pParent );
376                     ~EditViewWindow();
377 
378     virtual void    Paint( const Rectangle& );
379     virtual void    Resize();
380     virtual void    KeyInput( const KeyEvent& rKeyEvt );
381     virtual void    MouseMove( const MouseEvent& rMEvt );
382     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
383     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
384     virtual void    Command( const CommandEvent& rCEvt );
385     void            MarkOutputArea();
386     BOOL            Drop( const DropEvent& rEvt );
387     BOOL            QueryDrop( DropEvent& rEvt );
388 
389     EditView*       GetEditView()       { return pEditView; }
390 };
391 
392 class EditMainWindow : public WorkWindow
393 {
394 private:
395     ToolBox                 aToolBox;
396     ScrollBar               aHScrollBar;
397     ScrollBar               aVScrollBar;
398     EditViewWindow          aViewWin;
399     Printer*                pPrinter;
400 
401     WorkWindow*             pTmpWindow;
402 
403     EditTextObject*         pRTFObj;
404     EditTextObject*         pBinObj;
405 
406     FileDialog*             pFileDialogBox;
407     FileDialog*             pFileDialogBox2;
408 
409 
410 protected:
411     void            SetScrollBars();
412     void            SetScrollBarRanges();
413     void            CreatePolygon();
414 
415     virtual void    GetFocus();
416 
417 public:
418                     EditMainWindow();
419                     ~EditMainWindow();
420 
421     virtual void    Resize();
422 
423     DECL_LINK( TBSelect, ToolBox * );
424     void            UpdateToolBox();
425 
426     DECL_LINK( HScrollHdl, ScrollBar * );
427     DECL_LINK( VScrollHdl, ScrollBar * );
428     DECL_LINK( ShowStatus, EditStatus * );
429     void            SetTitle();
430 };
431 
432 
433 EditMainWindow::~EditMainWindow()
434 {
435     delete pRTFObj;
436     delete pBinObj;
437     delete pFileDialogBox;
438     delete pFileDialogBox2;
439     delete pTmpWindow;
440     delete pPrinter;
441 }
442 
443 EditMainWindow::EditMainWindow() :
444                 WorkWindow( NULL, WB_APP | WB_STDWORK | WB_SVLOOK | WB_CLIPCHILDREN ) ,
445                 aViewWin( this ),
446                 aToolBox( this, WinBits( WB_BORDER | WB_SVLOOK | WB_SCROLL | WB_LINESPACING ) ),
447                 aHScrollBar( this, WinBits( WB_HSCROLL | WB_DRAG ) ),
448                 aVScrollBar( this, WinBits( WB_VSCROLL | WB_DRAG ) )
449 {
450     pRTFObj = 0;
451     pBinObj = 0;
452 
453     pFileDialogBox = new FileDialog( this, WinBits( WB_OPEN | WB_SVLOOK ) );
454     pFileDialogBox->SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Open" ) ) );
455     pFileDialogBox->AddFilter( String( RTL_CONSTASCII_USTRINGPARAM( "Text" )), String( RTL_CONSTASCII_USTRINGPARAM( "*.txt" ) ) );
456     pFileDialogBox->AddFilter( String( RTL_CONSTASCII_USTRINGPARAM( "Rich Text Format" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.rtf" ) ) );
457     pFileDialogBox->AddFilter( String( RTL_CONSTASCII_USTRINGPARAM( "HTML" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.htm;*.html" ) ) );
458     pFileDialogBox->SetCurFilter( String( RTL_CONSTASCII_USTRINGPARAM( "Rich Text Format" ) ) );
459 
460     pFileDialogBox2 = new FileDialog( this, WinBits( WB_SAVEAS| WB_SVLOOK ) );
461     pFileDialogBox2->SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Save" ) ) );
462     pFileDialogBox2->AddFilter( String( RTL_CONSTASCII_USTRINGPARAM( "Text" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.txt" ) ) );
463     pFileDialogBox2->AddFilter( String( RTL_CONSTASCII_USTRINGPARAM( "Rich Text Format" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.rtf" ) ) );
464     pFileDialogBox2->AddFilter( String( RTL_CONSTASCII_USTRINGPARAM( "HTML" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.htm" ) ) );
465     pFileDialogBox2->SetCurFilter( String( RTL_CONSTASCII_USTRINGPARAM( "Rich Text Format" ) ) );
466 
467     pPrinter = new Printer;
468     pPrinter->SetMapMode( MAP_100TH_MM );
469     aViewWin.SetMapMode( pPrinter->GetMapMode() );
470     aViewWin.GetEditView()->GetEditEngine()->SetRefDevice( pPrinter );
471 
472 
473 
474     pTmpWindow = new WorkWindow( this, WB_STDWORK );
475 
476     aToolBox.SetButtonType( BUTTON_TEXT );
477     aToolBox.SetLineCount( 4 );
478 
479     {
480     aToolBox.InsertItem( TB_OPEN, String( RTL_CONSTASCII_USTRINGPARAM( "Open" ) ) );
481     aToolBox.InsertItem( TB_SAVE, String( RTL_CONSTASCII_USTRINGPARAM( "Save" ) ) );
482     aToolBox.InsertItem( TB_PRINT, String( RTL_CONSTASCII_USTRINGPARAM( "Print" ) ) );
483     aToolBox.InsertSeparator();
484     aToolBox.InsertItem( TB_LEFT, String( RTL_CONSTASCII_USTRINGPARAM( "L" ) ) );
485     aToolBox.InsertItem( TB_CENTER, String( RTL_CONSTASCII_USTRINGPARAM( "C" ) ) );
486     aToolBox.InsertItem( TB_RIGHT, String( RTL_CONSTASCII_USTRINGPARAM( "R" ) ) );
487     aToolBox.InsertItem( TB_BLOCK, String( RTL_CONSTASCII_USTRINGPARAM( "B" ) ) );
488     aToolBox.InsertSeparator();
489     aToolBox.InsertItem( TB_UNDO, String( RTL_CONSTASCII_USTRINGPARAM( "Undo" ) ) );
490     aToolBox.InsertItem( TB_REDO, String( RTL_CONSTASCII_USTRINGPARAM( "Redo" ) ) );
491     aToolBox.InsertSeparator();
492     aToolBox.InsertItem( TB_FONT1, String( RTL_CONSTASCII_USTRINGPARAM( "Font1" ) ) );
493     aToolBox.InsertItem( TB_FONT2, String( RTL_CONSTASCII_USTRINGPARAM( "Font2" ) ) );
494     aToolBox.InsertItem( TB_DEFTAB, String( RTL_CONSTASCII_USTRINGPARAM( "DefTab" ) ) );
495     aToolBox.InsertBreak();
496     aToolBox.InsertItem( TB_OPEN2, String( RTL_CONSTASCII_USTRINGPARAM( "Read" ) ) );
497     aToolBox.InsertItem( TB_SAVE2, String( RTL_CONSTASCII_USTRINGPARAM( "Write" ) ) );
498     aToolBox.InsertSeparator();
499     aToolBox.InsertItem( TB_FONT, String( RTL_CONSTASCII_USTRINGPARAM( "XXX" ) ) );
500     aToolBox.InsertItem( TB_ITALIC, String( RTL_CONSTASCII_USTRINGPARAM( "K" ) ) );
501     aToolBox.InsertItem( TB_BOLD, String( RTL_CONSTASCII_USTRINGPARAM( "F" ) ) );
502     aToolBox.InsertItem( TB_UNDERLINE, String( RTL_CONSTASCII_USTRINGPARAM( "U" ) ) );
503     aToolBox.InsertItem( TB_SUPER, String( RTL_CONSTASCII_USTRINGPARAM( "SP" ) ) );
504     aToolBox.InsertItem( TB_SUB, String( RTL_CONSTASCII_USTRINGPARAM( "SB" ) ) );
505     aToolBox.InsertItem( TB_PKERN, String( RTL_CONSTASCII_USTRINGPARAM( "PK" ) ) );
506     aToolBox.InsertItem( TB_KERN, String( RTL_CONSTASCII_USTRINGPARAM( "TK" ) ) );
507     aToolBox.InsertItem( TB_WLM, String( RTL_CONSTASCII_USTRINGPARAM( "W!" ) ) );
508     aToolBox.InsertSeparator();
509     aToolBox.InsertItem( TB_BLACK, String( RTL_CONSTASCII_USTRINGPARAM( "Black" ) ) );
510     aToolBox.InsertItem( TB_GREEN, String( RTL_CONSTASCII_USTRINGPARAM( "Green" ) ) );
511     aToolBox.InsertItem( TB_RED, String( RTL_CONSTASCII_USTRINGPARAM( "Red" ) ) );
512     aToolBox.InsertSeparator();
513     aToolBox.InsertItem( TB_SBL, String( RTL_CONSTASCII_USTRINGPARAM( "SBL" ) ) );
514     aToolBox.InsertItem( TB_SBSA, String( RTL_CONSTASCII_USTRINGPARAM( "SBSA" ) ) );
515     aToolBox.InsertItem( TB_LR, String( RTL_CONSTASCII_USTRINGPARAM( "LR" ) ) );
516     aToolBox.InsertSeparator();
517     aToolBox.InsertItem( TB_DRAW, String( RTL_CONSTASCII_USTRINGPARAM( "Draw!" ) ) );
518     aToolBox.InsertItem( TB_ROTATE, String( RTL_CONSTASCII_USTRINGPARAM( "Rotate!" ) ) );
519     aToolBox.InsertItem( TB_MOVE, String( RTL_CONSTASCII_USTRINGPARAM( "Move->2" ) ) );
520     aToolBox.InsertItem( TB_PARATTR1, String( RTL_CONSTASCII_USTRINGPARAM( "ParaAttr0" ) ) );
521     aToolBox.InsertItem( TB_ATTRIBS, String( RTL_CONSTASCII_USTRINGPARAM( "GetAttribs" ) ) );
522     aToolBox.InsertSeparator();
523     aToolBox.InsertItem( TB_INSFLD, String( RTL_CONSTASCII_USTRINGPARAM( "InsFld" ) ) );
524     aToolBox.InsertItem( TB_UPDFLD, String( RTL_CONSTASCII_USTRINGPARAM( "UpdFld" ) ) );
525     }
526     aToolBox.InsertBreak();
527     {
528     aToolBox.InsertItem( TB_ONLINESPELL, String( RTL_CONSTASCII_USTRINGPARAM( "Spell" ) ) );
529     aToolBox.InsertItem( TB_REDLINES, String( RTL_CONSTASCII_USTRINGPARAM( "RedLine" ) ) );
530     aToolBox.InsertItem( TB_AUTOCORRECT, String( RTL_CONSTASCII_USTRINGPARAM( "Auto*" ) ) );
531     aToolBox.InsertItem( TB_HYPH, String( RTL_CONSTASCII_USTRINGPARAM( "Hyph" ) ) );
532     aToolBox.InsertItem( TB_STDSEL, String( RTL_CONSTASCII_USTRINGPARAM( "StdSel" ) ) );
533     aToolBox.InsertItem( TB_FLAT, String( RTL_CONSTASCII_USTRINGPARAM( "FlatMode" ) ) );
534     aToolBox.InsertItem( TB_OUTL, String( RTL_CONSTASCII_USTRINGPARAM( "Ocomphelper" ) ) );
535     aToolBox.InsertItem( TB_POLY, String( RTL_CONSTASCII_USTRINGPARAM( "Poly" ) ) );
536     aToolBox.InsertItem( TB_COLORS, String( RTL_CONSTASCII_USTRINGPARAM( "Colors" ) ));
537     aToolBox.InsertItem( TB_IDLE, String( RTL_CONSTASCII_USTRINGPARAM( "Idle!" ) ) );
538     aToolBox.InsertItem( TB_INSERT, String( RTL_CONSTASCII_USTRINGPARAM( "Insert" ) ) );
539     aToolBox.InsertSeparator();
540     aToolBox.InsertItem( TB_BINOBJ1, String( RTL_CONSTASCII_USTRINGPARAM( ">BINObj" ) ) );
541     aToolBox.InsertItem( TB_BINOBJ1b, String( RTL_CONSTASCII_USTRINGPARAM( ">>BINObj" ) ) );
542     aToolBox.InsertItem( TB_BINOBJ2b, String( RTL_CONSTASCII_USTRINGPARAM( "<<BINObj" ) ) );
543     aToolBox.InsertItem( TB_CLONEBIN, String( RTL_CONSTASCII_USTRINGPARAM( "Clone" ) ) );
544     aToolBox.InsertSeparator();
545     aToolBox.InsertItem( TB_BINOBJ3, String( RTL_CONSTASCII_USTRINGPARAM( "StoreBin" ) ) );
546     aToolBox.InsertItem( TB_BINOBJ4, String( RTL_CONSTASCII_USTRINGPARAM( "CreatBin" ) ) );
547     }
548 
549     aToolBox.SetPosPixel( Point( 0, 0 ) );
550     aToolBox.SetSelectHdl( LINK( this, EditMainWindow, TBSelect ) );
551 
552     SetBackgroundBrush( Brush( Color( COL_LIGHTGRAY ) ) );
553 
554     SetPen( PEN_NULL );
555     Show();
556 
557     aVScrollBar.SetScrollHdl ( LINK( this, EditMainWindow, VScrollHdl ) );
558     aVScrollBar.SetLineSize( 300 );
559     aVScrollBar.SetPageSize( 2000 );
560     aHScrollBar.SetScrollHdl ( LINK( this, EditMainWindow, HScrollHdl ) );
561     aHScrollBar.SetLineSize( 300 );
562     aHScrollBar.SetPageSize( 2000 );
563     aHScrollBar.Enable();
564     aVScrollBar.Enable();
565 
566     aViewWin.GetEditView()->GetEditEngine()->SetStatusEventHdl( LINK( this, EditMainWindow, ShowStatus ) );
567 
568     SetTitle();
569 
570     UpdateToolBox();
571     aToolBox.Show();
572     aViewWin.Show();
573 }
574 
575 void EditMainWindow::SetTitle()
576 {
577     String aHeading( String( RTL_CONSTASCII_USTRINGPARAM( "SvEdit!  -  Zoom " ) ) );
578     aHeading += String::CreateFromInt32(nZoom);
579     aHeading += '%';
580     EditEngine* pEditEngine = aViewWin.GetEditView()->GetEditEngine();
581     if ( pEditEngine->GetControlWord() & EE_CNTRL_STRETCHING )
582     {
583         USHORT nX, nY;
584         pEditEngine->GetGlobalCharStretching( nX, nY );
585         aHeading += String( RTL_CONSTASCII_USTRINGPARAM( ", Stretch=(" ) );
586         aHeading += String::CreateFromInt32(nX);
587         aHeading += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
588         aHeading += String::CreateFromInt32(nY);
589         aHeading += ')';
590     }
591     SetText( aHeading );
592 }
593 
594 void EditMainWindow::UpdateToolBox()
595 {
596     EditView* pEditView = aViewWin.GetEditView();
597     EditEngine* pEditEngine = pEditView->GetEditEngine();
598     SfxItemSet aCurSet( pEditView->GetAttribs() );
599 
600     ULONG nControl = pEditEngine->GetControlWord();
601     aToolBox.EnableItem( TB_UNDO, (BOOL)pEditEngine->GetUndoManager().GetUndoActionCount() );
602     aToolBox.EnableItem( TB_REDO, (BOOL)pEditEngine->GetUndoManager().GetRedoActionCount() );
603     aToolBox.EnableItem( TB_BINOBJ2b, (BOOL)(long)pBinObj );
604     aToolBox.EnableItem( TB_MOVE, pEditEngine->GetParagraphCount() > 3 );
605     aToolBox.CheckItem( TB_ONLINESPELL, nControl & EE_CNTRL_ONLINESPELLING ? TRUE : FALSE );
606     aToolBox.CheckItem( TB_AUTOCORRECT, nControl & EE_CNTRL_AUTOCORRECT ? TRUE : FALSE );
607 //  aToolBox.CheckItem( TB_HYPH, nControl & EE_CNTRL_HYPHENATE ? TRUE : FALSE );
608     aToolBox.CheckItem( TB_REDLINES, nControl & EE_CNTRL_NOREDLINES ? FALSE : TRUE );
609     aToolBox.CheckItem( TB_STDSEL, pEditView->GetSelectionMode() == EE_SELMODE_STD );
610     aToolBox.CheckItem( TB_FLAT, pEditEngine->IsFlatMode() );
611     aToolBox.CheckItem( TB_OUTL, ( nControl & EE_CNTRL_OUTLINER ) ? TRUE : FALSE );
612     aToolBox.CheckItem( TB_POLY, pEditEngine->GetPolygon() ? TRUE : FALSE );
613     aToolBox.CheckItem( TB_COLORS, ( nControl & EE_CNTRL_NOCOLORS ) ? FALSE : TRUE );
614     aToolBox.CheckItem( TB_IDLE, pEditEngine->IsIdleFormatterEnabled() );
615     aToolBox.CheckItem( TB_INSERT, pEditView->IsInsertMode() );
616 
617     for ( USHORT nWhich = EE_ITEMS_START; nWhich <= EE_ITEMS_END; nWhich++)
618     {
619 //      if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_OFF )
620 //          ;
621 //      else if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_DONTCARE )
622 //          ;
623 //      else if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_ON )
624         {
625             const SfxPoolItem& rItem = aCurSet.Get( nWhich );
626             switch ( nWhich )
627             {
628                 case EE_PARA_HYPHENATE:
629                     aToolBox.CheckItem( TB_HYPH, ((SfxBoolItem&)rItem).GetValue() != 0 );
630                 break;
631                 case EE_PARA_LRSPACE:
632                     aToolBox.CheckItem( TB_LR, ((SvxLRSpaceItem&)rItem).GetTxtLeft() != 0 );
633                 break;
634                 case EE_PARA_ULSPACE:
635                     aToolBox.CheckItem( TB_SBSA, ((SvxULSpaceItem&)rItem).GetUpper() != 0 );
636                 break;
637                 case EE_PARA_SBL:
638                     aToolBox.CheckItem( TB_SBL, ((SvxLineSpacingItem&)rItem).GetPropLineSpace() != 100 );
639                 break;
640                 case EE_PARA_JUST:
641                 {
642                     SvxAdjust e = ((SvxAdjustItem&)rItem).GetAdjust();
643                     aToolBox.CheckItem( TB_LEFT, e == SVX_ADJUST_LEFT );
644                     aToolBox.CheckItem( TB_RIGHT, e == SVX_ADJUST_RIGHT);
645                     aToolBox.CheckItem( TB_CENTER, e == SVX_ADJUST_CENTER);
646                     aToolBox.CheckItem( TB_BLOCK, e == SVX_ADJUST_BLOCK );
647                 }
648                 break;
649                 case EE_PARA_TABS:
650                 break;
651                 case EE_CHAR_COLOR:
652                 {
653                     Color aColor( ((SvxColorItem&)rItem).GetValue() );
654                     aToolBox.CheckItem( TB_BLACK, aColor == COL_BLACK );
655                     aToolBox.CheckItem( TB_GREEN, aColor == COL_GREEN );
656                     aToolBox.CheckItem( TB_RED, aColor == COL_RED );
657                 }
658                 break;
659                 case EE_CHAR_FONTINFO:
660                 {
661                     FontFamily e = ((SvxFontItem&)rItem).GetFamily();
662                     aToolBox.CheckItem( TB_FONT1, e == FAMILY_ROMAN );
663                     aToolBox.CheckItem( TB_FONT2, e == FAMILY_SWISS );
664                 }
665                 break;
666                 case EE_CHAR_FONTHEIGHT:
667                 break;
668                 case EE_CHAR_WEIGHT:
669                 {
670                     FontWeight e = ((SvxWeightItem&)rItem).GetWeight();
671                     aToolBox.CheckItem( TB_BOLD, e == WEIGHT_BOLD );
672                 }
673                 break;
674                 case EE_CHAR_UNDERLINE:
675                 {
676                     aToolBox.CheckItem( TB_UNDERLINE, ((SvxUnderlineItem&)rItem).GetLineStyle() );
677                 }
678                 break;
679                 case EE_CHAR_WLM:
680                 {
681                     aToolBox.CheckItem( TB_WLM, ((SvxWordLineModeItem&)rItem).GetValue() );
682                 }
683                 break;
684                 case EE_CHAR_PAIRKERNING:
685                 {
686                     aToolBox.CheckItem( TB_PKERN, ((SvxAutoKernItem&)rItem).GetValue() );
687                 }
688                 break;
689                 case EE_CHAR_KERNING:
690                 {
691                     aToolBox.CheckItem( TB_KERN, (BOOL)((SvxKerningItem&)rItem).GetValue() );
692                 }
693                 break;
694                 case EE_CHAR_ESCAPEMENT:
695                 {
696                     aToolBox.CheckItem( TB_SUPER, ((SvxEscapementItem&)rItem).GetEsc() > 0 );
697                     aToolBox.CheckItem( TB_SUB, ((SvxEscapementItem&)rItem).GetEsc() < 0 );
698                 }
699                 break;
700                 case EE_CHAR_STRIKEOUT:
701                 break;
702                 case EE_CHAR_ITALIC:
703                 {
704                     FontItalic e = ((SvxPostureItem&)rItem).GetPosture();
705                     aToolBox.CheckItem( TB_ITALIC, e == ITALIC_NORMAL );
706                 }
707                 break;
708                 case EE_CHAR_OUTLINE:
709                 break;
710                 case EE_CHAR_SHADOW:
711                 break;
712             }
713         }
714     }
715 }
716 
717 IMPL_LINK( EditMainWindow, TBSelect, ToolBox *, p )
718 {
719     EditView* pEditView = aViewWin.GetEditView();
720     EditEngine* pEditEngine = pEditView->GetEditEngine();
721     USHORT nId = aToolBox.GetCurItemId();
722     BOOL bChecked = aToolBox.IsItemChecked( nId );
723     SfxPoolItem* pNewItem = 0;
724     switch ( nId )
725     {
726         case TB_LEFT:   pNewItem = new SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST );
727                         break;
728         case TB_RIGHT:  pNewItem = new SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST );
729                         break;
730         case TB_CENTER: pNewItem = new SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST );
731                         break;
732         case TB_BLOCK:  pNewItem = new SvxAdjustItem( SVX_ADJUST_BLOCK, EE_PARA_JUST );
733                         break;
734         case TB_HYPH:   pNewItem = new SfxBoolItem( EE_PARA_HYPHENATE, !bChecked );
735                         break;
736         case TB_UNDO:   pEditView->Undo();
737                         pEditView->ShowCursor();
738                         break;
739         case TB_REDO:   pEditView->Redo();
740                         pEditView->ShowCursor();
741                         break;
742         case TB_ONLINESPELL: {
743                             ULONG nControl = pEditView->GetEditEngine()->GetControlWord();
744                             if ( bChecked )
745                                 nControl = nControl & ~EE_CNTRL_ONLINESPELLING;
746                             else
747                                 nControl = nControl | EE_CNTRL_ONLINESPELLING;
748                             pEditView->GetEditEngine()->SetControlWord( nControl );
749                             }
750                             break;
751         case TB_REDLINES: {
752                             ULONG nControl = pEditView->GetEditEngine()->GetControlWord();
753                             if ( !bChecked )
754                                 nControl = nControl & ~EE_CNTRL_NOREDLINES;
755                             else
756                                 nControl = nControl | EE_CNTRL_NOREDLINES;
757                             pEditView->GetEditEngine()->SetControlWord( nControl );
758                             }
759                             break;
760         case TB_AUTOCORRECT: {
761                             ULONG nControl = pEditView->GetEditEngine()->GetControlWord();
762                             if ( bChecked )
763                                 nControl = nControl & ~EE_CNTRL_AUTOCORRECT;
764                             else
765                                 nControl = nControl | EE_CNTRL_AUTOCORRECT;
766                             pEditView->GetEditEngine()->SetControlWord( nControl );
767                             }
768                             break;
769         case TB_STDSEL: if ( bChecked )
770                             pEditView->SetSelectionMode( EE_SELMODE_TXTONLY );
771                         else
772                             pEditView->SetSelectionMode( EE_SELMODE_STD );
773                         break;
774         case TB_FLAT:   pEditEngine->SetFlatMode( !pEditEngine->IsFlatMode() );
775                         break;
776         case TB_COLORS: {
777                             ULONG nControl = pEditView->GetEditEngine()->GetControlWord();
778                             if ( bChecked )
779                                 nControl = nControl | EE_CNTRL_NOCOLORS;
780                             else
781                                 nControl = nControl & ~EE_CNTRL_NOCOLORS;
782                             pEditView->GetEditEngine()->SetControlWord( nControl );
783                         }
784 //                      aViewWin.Invalidate();
785                         pEditView->GetEditEngine()->Draw( pEditView->GetWindow(), pEditView->GetOutputArea(), pEditView->GetVisArea().TopLeft() );
786                         break;
787         case TB_OUTL:   {
788                             ULONG nControl = pEditView->GetEditEngine()->GetControlWord();
789                             if ( !bChecked )
790                                 nControl = nControl | EE_CNTRL_OUTLINER;
791                             else
792                                 nControl = nControl & ~EE_CNTRL_OUTLINER;
793                             pEditView->GetEditEngine()->SetControlWord( nControl );
794                         }
795                         break;
796         case TB_POLY:   {
797                             if ( !bChecked )
798                                 CreatePolygon();
799                             else
800                                 pEditView->GetEditEngine()->ClearPolygon();
801                         }
802                         break;
803         case TB_IDLE:   pEditEngine->EnableIdleFormatter( !pEditEngine->IsIdleFormatterEnabled() );
804                         break;
805         case TB_INSFLD: {
806                         static BYTE nFld = 0;
807                         if ( nFld > 2 )
808                             nFld = 0;
809                         if ( nFld == 0 )
810                         {
811                             SvxFieldItem aFld( SvxURLField( String( RTL_CONSTASCII_USTRINGPARAM( "www.mopo.de" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "Bla" ) ), SVXURLFORMAT_REPR ), EE_FEATURE_FIELD  );
812                             pEditView->InsertField( aFld );
813                         }
814                         else if ( nFld == 1 )
815                             pEditView->InsertField( SvxFieldItem( SvxURLField( String( RTL_CONSTASCII_USTRINGPARAM( "www.mopo.de" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "Morgenpost" ) ), SVXURLFORMAT_URL ), EE_FEATURE_FIELD  ) );
816                         else if ( nFld == 2 )
817                             pEditView->InsertField( SvxFieldItem( SvxDateField( Date( 1,1,1995 ), SVXDATETYPE_FIX, SVXDATEFORMAT_D ), EE_FEATURE_FIELD ) );
818 
819                         nFld++;
820         }
821                         break;
822         case TB_UPDFLD: pEditEngine->UpdateFields();
823                         break;
824         case TB_INSERT: pEditView->SetInsertMode( !pEditView->IsInsertMode() );
825                         break;
826         case TB_FONT1:  pNewItem = new SvxFontItem( FAMILY_ROMAN, String( RTL_CONSTASCII_USTRINGPARAM( "Times New Roman" ) ), String(), PITCH_DONTKNOW, RTL_TEXTENCODING_MS_1252, EE_CHAR_FONTINFO );
827                         break;
828         case TB_FONT2:  pNewItem = new SvxFontItem( FAMILY_SWISS, String( RTL_CONSTASCII_USTRINGPARAM( "Helv" ) ), String(), PITCH_DONTKNOW, RTL_TEXTENCODING_MS_1252, EE_CHAR_FONTINFO );
829                         break;
830 /*
831         case TB_FONT:
832         {
833             FontDialog* pDlg = new FontDialog( this, WB_SVLOOK );
834             pDlg->SetPrinter( pPrinter );
835             Font aFont = pEditEngine->CreateFontFromItemSet( pEditView->GetAttribs() );
836             MapMode aPntMode( MAP_POINT );
837             MapMode aCurrent( aViewWin.GetMapMode() );
838             Size aSz(  aViewWin.LogicToLogic( aFont.GetSize(), &aCurrent, &aPntMode ) );
839             aSz.Width() *= 10;
840             aSz.Height() *= 10;
841             aFont.SetSize(  aSz );
842             pDlg->SetSelectFont( aFont );
843             if ( pDlg->Execute() )
844             {
845                 Font aNewFont( pDlg->GetSelectFont() );
846                 aSz = aViewWin.LogicToLogic( aNewFont.GetSize(), &aPntMode, &aCurrent );
847                 aSz.Width() /= 10;
848                 aSz.Height() /= 10;
849                 aNewFont.SetSize( aSz );
850 
851                 SfxItemSet aSet( pEditEngine->GetEmptyItemSet() );
852 
853                 pEditEngine->SetFontInfoInItemSet( aSet, aNewFont );
854                 pEditView->SetAttribs( aSet );
855             }
856             delete pDlg;
857         }
858         break;
859 */
860         case TB_BOLD:   if ( bChecked )
861                             pNewItem = new SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT);
862                         else
863                             pNewItem = new SvxWeightItem( WEIGHT_BOLD, EE_CHAR_WEIGHT);
864                         break;
865         case TB_ITALIC: if ( bChecked )
866                             pNewItem = new SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC );
867                         else
868                             pNewItem = new SvxPostureItem( ITALIC_NORMAL, EE_CHAR_ITALIC );
869                         break;
870         case TB_UNDERLINE:  if ( bChecked )
871                                 pNewItem = new SvxUnderlineItem( UNDERLINE_NONE, EE_CHAR_UNDERLINE );
872                             else
873                                 pNewItem = new SvxUnderlineItem( UNDERLINE_SINGLE, EE_CHAR_UNDERLINE );
874                         break;
875         case TB_WLM:    pNewItem = new SvxWordLineModeItem( !bChecked, EE_CHAR_WLM );
876                         break;
877         case TB_PKERN:  pNewItem = new SvxAutoKernItem( !bChecked, EE_CHAR_PAIRKERNING );
878                         break;
879         case TB_KERN:   if ( bChecked )
880                                 pNewItem = new SvxKerningItem( 0, EE_CHAR_KERNING );
881                             else
882                                 pNewItem = new SvxKerningItem( 100, EE_CHAR_KERNING);
883                         break;
884         case TB_SUPER:  if ( bChecked )
885                                 pNewItem = new SvxEscapementItem( SVX_ESCAPEMENT_OFF, EE_CHAR_ESCAPEMENT);
886                             else
887 //                              pNewItem = new SvxEscapementItem( SVX_ESCAPEMENT_SUPERSCRIPT, EE_CHAR_ESCAPEMENT);
888                                 pNewItem = new SvxEscapementItem( 50, 100, EE_CHAR_ESCAPEMENT );
889                         break;
890         case TB_SUB:    if ( bChecked )
891                                 pNewItem = new SvxEscapementItem( SVX_ESCAPEMENT_OFF, EE_CHAR_ESCAPEMENT);
892                             else
893 //                              pNewItem = new SvxEscapementItem( SVX_ESCAPEMENT_SUBSCRIPT, EE_CHAR_ESCAPEMENT);
894                                 pNewItem = new SvxEscapementItem( -50, 100, EE_CHAR_ESCAPEMENT );
895                         break;
896         case TB_GREEN:  pNewItem = new SvxColorItem( Color(COL_GREEN), EE_CHAR_COLOR);
897                         break;
898         case TB_RED:    pNewItem = new SvxColorItem( Color(COL_RED), EE_CHAR_COLOR);
899                         break;
900         case TB_BLACK:  pNewItem = new SvxColorItem( Color(COL_BLACK), EE_CHAR_COLOR);
901                         break;
902         case TB_SBL:    pNewItem = new SvxLineSpacingItem( 0, EE_PARA_SBL );
903                         if ( bChecked )
904                         {
905                             ((SvxLineSpacingItem*)pNewItem)->SetInterLineSpace( 0 );
906                         }
907                         else
908                         {
909                             ((SvxLineSpacingItem*)pNewItem)->SetPropLineSpace( 150 );
910                         }
911                         break;
912         case TB_SBSA:   pNewItem = new SvxULSpaceItem( EE_PARA_ULSPACE );
913                         if ( !bChecked )
914                         {
915                             ((SvxULSpaceItem*)pNewItem)->SetUpper( 400 );
916                             ((SvxULSpaceItem*)pNewItem)->SetLower( 400 );
917                         }
918                         break;
919         case TB_LR:     pNewItem = new SvxLRSpaceItem( EE_PARA_LRSPACE );
920                         if ( !bChecked )
921                         {
922                             ((SvxLRSpaceItem*)pNewItem)->SetTxtLeft( 1000 );
923                             ((SvxLRSpaceItem*)pNewItem)->SetTxtFirstLineOfst( -500 );
924                             ((SvxLRSpaceItem*)pNewItem)->SetRight( 500 );
925                         }
926                         break;
927         case TB_DEFTAB: if ( bChecked )
928                             pEditEngine->SetDefTab( 2000 );
929                         else
930                             pEditEngine->SetDefTab( 600 );
931                         pEditView->ShowCursor();
932                         aToolBox.CheckItem( nId, !bChecked );
933                         break;
934         case TB_DRAW:   {
935                             pTmpWindow->SetMapMode( aViewWin.GetMapMode() );
936                             pTmpWindow->SetBackgroundBrush( Brush( Color( COL_GRAY ) ) );
937                             pTmpWindow->SetFillInBrush( Brush( Color( COL_LIGHTGRAY ) ) );
938                             pTmpWindow->Show();
939                             pTmpWindow->Invalidate();
940                             pTmpWindow->Update();
941                             pTmpWindow->DrawText( Point( 20, 20 ), String( RTL_CONSTASCII_USTRINGPARAM( "It's a Test..." ) ) );
942                             Rectangle aRect( Point( 500, 500 ), Size( 10000, 4000 ) );
943                             pTmpWindow->DrawRect( aRect );
944                             pEditEngine->Draw( pTmpWindow, aRect, Point( 0, 0 ) );
945                             nRotation = 0;
946                         }
947                         break;
948         case TB_ROTATE:   {
949                             nRotation += 100;
950                             if ( nRotation == 3600 )
951                                 nRotation = 0;
952                             pTmpWindow->SetMapMode( aViewWin.GetMapMode() );
953                             pTmpWindow->SetBackgroundBrush( Brush( Color( COL_LIGHTGRAY ) ) );
954                             pTmpWindow->SetFillInBrush( Brush( Color( COL_LIGHTGRAY ) ) );
955                             pTmpWindow->Show();
956                             pTmpWindow->Invalidate();
957                             pTmpWindow->Update();
958                             pTmpWindow->DrawText( Point( 20, 20 ), String( RTL_CONSTASCII_USTRINGPARAM( "It's a Test..." ) ) );
959                             Rectangle aRect( Point( 500, 500 ), Size( 10000, 4000 ) );
960                             pEditEngine->Draw( pTmpWindow, Point( 2000, 4000 ), nRotation );
961                         }
962                         break;
963 
964         case TB_MOVE:
965         {
966             ESelection aESel = pEditView->GetSelection();
967             USHORT nStartPara = Min( aESel.nStartPara, aESel.nEndPara );
968             USHORT nEndPara = Max( aESel.nStartPara, aESel.nEndPara );
969             pEditView->MoveParagraphs( Range(nStartPara,nEndPara), 2 );
970         }
971         break;
972         case TB_PARATTR1:
973         {
974             pEditEngine->SetUpdateMode( FALSE );
975             USHORT nPara = 0;
976             SfxItemSet aSet( pEditEngine->GetEmptyItemSet() );
977             aSet.Put( SvxFontItem( FAMILY_DECORATIVE, String( RTL_CONSTASCII_USTRINGPARAM( "StarBats" ) ), String(),PITCH_DONTKNOW, RTL_TEXTENCODING_MS_1252, EE_CHAR_FONTINFO ) );
978             aSet.Put( SvxColorItem( Color(COL_MAGENTA), EE_CHAR_COLOR ) );
979             aSet.Put( SvxFontHeightItem(600, 100, EE_CHAR_FONTHEIGHT) );
980             aSet.Put( SvxPostureItem( ITALIC_NORMAL, EE_CHAR_ITALIC ) );
981             aSet.Put( SvxLRSpaceItem( 0, 0, 1000, 0, EE_PARA_LRSPACE ) );
982             pEditView->SetParaAttribs( aSet, nPara );
983             pEditEngine->SetUpdateMode( TRUE );
984             pEditView->ShowCursor();
985         }
986         break;
987         case TB_BINOBJ1:
988         {
989             delete pBinObj;
990             pBinObj = pEditEngine->CreateTextObject();
991         }
992         break;
993         case TB_BINOBJ1b:
994         {
995             delete pBinObj;
996             pBinObj = pEditView->CreateTextObject();
997         }
998         break;
999         case TB_CLONEBIN:
1000         {
1001             if ( pBinObj )
1002             {
1003                 EditTextObject* p = pBinObj->Clone();
1004                 delete pBinObj;
1005                 pBinObj = p;
1006             }
1007         }
1008         break;
1009         case TB_BINOBJ2b:
1010         {
1011             if ( pBinObj )
1012             {
1013                 pEditView->InsertText( *pBinObj );
1014             }
1015         }
1016         break;
1017         case TB_BINOBJ3:
1018         {
1019             if ( !pFileDialogBox2->Execute() )
1020                 return FALSE;
1021             DirEntry aDirEntry( pFileDialogBox2->GetPath() );
1022             SvFileStream aStrm( aDirEntry.GetFull(), STREAM_WRITE | STREAM_TRUNC );
1023             EditTextObject* pTmpObj = pEditEngine->CreateTextObject();
1024             pTmpObj->Store( aStrm );
1025             DBG_ASSERT( !aStrm.GetError(), "Store: Error!" );
1026             delete pTmpObj;
1027         }
1028         break;
1029         case TB_BINOBJ4:
1030         {
1031             if ( !pFileDialogBox->Execute() )
1032                 return FALSE;
1033             DirEntry aDirEntry( pFileDialogBox->GetPath() );
1034             SvFileStream aStrm( aDirEntry.GetFull(), STREAM_READ );
1035             delete pBinObj;
1036             pBinObj = EditTextObject::Create( aStrm );
1037 //          EditTextObject* pTmpObj = pEditEngine->CreateTextObject( aStrm );
1038 //          pEditEngine->SetText( *pTmpObj );
1039 //          pEditView->ShowCursor();
1040 //          delete pTmpObj;
1041         }
1042         break;
1043         case TB_OPEN:
1044         case TB_OPEN2:
1045         {
1046             if ( !pFileDialogBox->Execute() )
1047                 return FALSE;
1048             DirEntry aDirEntry( pFileDialogBox->GetPath() );
1049             aDirEntry.ToAbs();
1050             String aFileName( aDirEntry.GetFull() );
1051             SvFileStream aStrm( aFileName, STREAM_READ );
1052             if ( aStrm.GetError() )
1053                 InfoBox( 0, String( RTL_CONSTASCII_USTRINGPARAM( "StreamError!" ) ) ).Execute();
1054             Application::EnterWait();
1055             if ( nId == TB_OPEN )
1056             {
1057                 if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "rtf" ) )
1058                     pEditEngine->Read( aStrm, EE_FORMAT_RTF );
1059                 if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "htm" ) )
1060                     pEditEngine->Read( aStrm, EE_FORMAT_HTML );
1061                 if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "html" ) )
1062                     pEditEngine->Read( aStrm, EE_FORMAT_HTML );
1063                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "bin" ) )
1064                     pEditEngine->Read( aStrm, EE_FORMAT_BIN );
1065                 else
1066                     pEditEngine->Read( aStrm, EE_FORMAT_TEXT );
1067 
1068                 pEditView->ShowCursor();
1069             }
1070             else
1071             {
1072                 if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "rtf" ) )
1073                     pEditView->Read( aStrm, EE_FORMAT_RTF );
1074                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "bin" ) )
1075                     pEditView->Read( aStrm, EE_FORMAT_BIN );
1076                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "html" ) )
1077                     pEditView->Read( aStrm, EE_FORMAT_HTML );
1078                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "htm" ) )
1079                     pEditView->Read( aStrm, EE_FORMAT_HTML );
1080                 else
1081                     pEditView->Read( aStrm, EE_FORMAT_TEXT );
1082             }
1083 
1084             Application::LeaveWait();
1085 
1086         }
1087         break;
1088         case TB_PRINT:
1089         {
1090             pPrinter->SetPageQueueSize( 1 );
1091             PrintDialog aPrnDlg( this );
1092             aPrnDlg.SetPrinter( pPrinter );
1093             if ( aPrnDlg.Execute() )
1094             {
1095                 pPrinter->StartJob( String( RTL_CONSTASCII_USTRINGPARAM( "SvEdit - PrinterTest" ) ) );
1096                 pPrinter->StartPage();
1097                 Size aSz( pEditEngine->CalcTextWidth(), pEditEngine->GetTextHeight() );
1098                 Pen aPen( PEN_SOLID );
1099                 aPen.SetColor( Color( COL_BLACK ) );
1100                 pPrinter->SetPen( aPen );
1101                 Rectangle aR( Point( 2000, 4000 ), aSz );
1102                 pPrinter->DrawRect( aR );
1103                 // So folgt auf IIISi, 75DPI kein Ausdruck!
1104 //              pPrinter->SetClipRegion( Region( aR ) );
1105                 pEditEngine->Draw( pPrinter, Point( 2000, 4000 ), nRotation );
1106 //              pPrinter->SetClipRegion();
1107                 pPrinter->EndPage();
1108                 pPrinter->EndJob();
1109             }
1110         }
1111         break;
1112         case TB_SAVE:
1113         case TB_SAVE2:
1114         {
1115             if ( !pFileDialogBox2->Execute() )
1116                 return FALSE;
1117             DirEntry aDirEntry( pFileDialogBox2->GetPath() );
1118 //          DirEntry aDirEntry( String( RTL_CONSTASCII_USTRINGPARAM( "d:\\xxx.rtf" ) ) );
1119             SvFileStream aStrm( aDirEntry.GetFull(), STREAM_WRITE | STREAM_TRUNC );
1120             Application::EnterWait();
1121             if ( nId == TB_SAVE )
1122             {
1123                 if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "rtf") )
1124                     pEditEngine->Write( aStrm, EE_FORMAT_RTF );
1125                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "bin" ) )
1126                     pEditEngine->Write( aStrm, EE_FORMAT_BIN );
1127                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "html" ) )
1128                     pEditEngine->Write( aStrm, EE_FORMAT_HTML );
1129                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "htm" ) )
1130                     pEditEngine->Write( aStrm, EE_FORMAT_HTML );
1131                 else
1132                     pEditEngine->Write( aStrm, EE_FORMAT_TEXT );
1133             }
1134             else
1135             {
1136                 if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "rtf" ) )
1137                     pEditView->Write( aStrm, EE_FORMAT_RTF );
1138                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "bin" ) )
1139                     pEditView->Write( aStrm, EE_FORMAT_BIN );
1140                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "html" ) )
1141                     pEditView->Write( aStrm, EE_FORMAT_HTML );
1142                 else if ( aDirEntry.GetExtension().EqualsIgnoreCaseAscii( "htm" ) )
1143                     pEditView->Write( aStrm, EE_FORMAT_HTML );
1144                 else
1145                     pEditView->Write( aStrm, EE_FORMAT_TEXT );
1146             }
1147             Application::LeaveWait();
1148         }
1149         break;
1150         case TB_ATTRIBS:
1151         {
1152             SfxItemSet aCurSet = pEditView->GetAttribs();
1153             XubString aDebStr( String( RTL_CONSTASCII_USTRINGPARAM( "Attribute in Selektion:" ) ) );
1154             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "\nVorlage:" ) );
1155             XubString aStyle;
1156 //          pEditView->GetStyleSheet( aStyle, eFam );
1157             aDebStr += aStyle;
1158             for ( USHORT nWhich = EE_ITEMS_START; nWhich <= EE_ITEMS_END; nWhich++)
1159             {
1160                 aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "\n" ) );
1161                 aDebStr += String::CreateFromInt32( nWhich );
1162                 aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "\t" ) );
1163                 if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_OFF )
1164                     aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "---" ) );
1165                 else if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_DONTCARE )
1166                     aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "XXX" ) );
1167                 else if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_ON )
1168                 {
1169                     const SfxPoolItem& rItem = aCurSet.Get( nWhich );
1170                     switch ( nWhich )
1171                     {
1172                         case EE_PARA_LRSPACE:
1173                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "FI=" ) );
1174                             aDebStr += String::CreateFromInt32( ((SvxLRSpaceItem&)rItem).GetTxtFirstLineOfst() );
1175                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( ", LI=" ) );
1176                             aDebStr += String::CreateFromInt32( ((SvxLRSpaceItem&)rItem).GetTxtLeft() );
1177                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( ", RI=" ) );
1178                             aDebStr += String::CreateFromInt32( ((SvxLRSpaceItem&)rItem).GetRight() );
1179                         break;
1180                         case EE_PARA_ULSPACE:
1181                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "SB=" ) );
1182                             aDebStr += String::CreateFromInt32( ((SvxULSpaceItem&)rItem).GetUpper() );
1183                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( ", SA=" ) );
1184                             aDebStr += String::CreateFromInt32( ((SvxULSpaceItem&)rItem).GetLower() );
1185                         break;
1186                         case EE_PARA_SBL:
1187                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "SBL=" ) );
1188                             aDebStr += String::CreateFromInt32( ((SvxLineSpacingItem&)rItem).GetInterLineSpace() );
1189                         break;
1190                         case EE_PARA_JUST:
1191                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "SvxAdust=" ) );
1192                             aDebStr += String::CreateFromInt32( (USHORT)((SvxAdjustItem&)rItem).GetAdjust() );
1193                         break;
1194                         case EE_PARA_TABS:
1195                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "Tabs = ?" ) );
1196                         break;
1197                         case EE_CHAR_COLOR:
1198                         {
1199                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "Color= " ) );
1200                             Color aColor( ((SvxColorItem&)rItem).GetValue() );
1201                             aDebStr += String::CreateFromInt32( aColor.GetRed() );
1202                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
1203                             aDebStr += String::CreateFromInt32( aColor.GetGreen() );
1204                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
1205                             aDebStr += String::CreateFromInt32( aColor.GetBlue() );
1206                         }
1207                         break;
1208                         case EE_CHAR_FONTINFO:
1209                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "Font=" ) );
1210                             aDebStr += ((SvxFontItem&)rItem).GetFamilyName();
1211                         break;
1212                         case EE_CHAR_FONTHEIGHT:
1213                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "Groesse=" ) );
1214                             aDebStr += String::CreateFromInt32( ((SvxFontHeightItem&)rItem).GetHeight() );
1215                         break;
1216                         case EE_CHAR_WEIGHT:
1217                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "FontWeight=" ) );
1218                             aDebStr += String::CreateFromInt32( ((SvxWeightItem&)rItem).GetWeight() );
1219                         break;
1220                         case EE_CHAR_UNDERLINE:
1221                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline=" ) );
1222                             aDebStr += String::CreateFromInt32( ((SvxUnderlineItem&)rItem).GetLineStyle() );
1223                         break;
1224                         case EE_CHAR_WLM:
1225                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "WordLineMode=" ) );
1226                             aDebStr += String::CreateFromInt32( ((SvxWordLineModeItem&)rItem).GetValue() );
1227                         break;
1228                         case EE_CHAR_STRIKEOUT:
1229                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout=" ) );
1230                             aDebStr += String::CreateFromInt32( ((SvxCrossedOutItem&)rItem).GetStrikeout() );
1231                         break;
1232                         case EE_CHAR_ITALIC:
1233                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "FontPosture=" ) );
1234                             aDebStr += String::CreateFromInt32( ((SvxPostureItem&)rItem).GetPosture() );
1235                         break;
1236                         case EE_CHAR_OUTLINE:
1237                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "FontOutline=" ) );
1238                             aDebStr += String::CreateFromInt32( ((SvxContourItem&)rItem).GetValue() );
1239                         break;
1240                         case EE_CHAR_SHADOW:
1241                             aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "FontShadowed=" ) );
1242                             aDebStr += String::CreateFromInt32( ((SvxShadowedItem&)rItem).GetValue() );
1243                         break;
1244                     }
1245                 }
1246                 else
1247                     aDebStr += String( RTL_CONSTASCII_USTRINGPARAM( "?" ) );
1248             }
1249             InfoBox( 0, aDebStr ).Execute();
1250         }
1251         break;
1252     }
1253 
1254     if ( pNewItem )
1255     {
1256         SfxItemSet aSet = pEditView->GetEmptyItemSet();
1257         aSet.Put( *pNewItem );
1258         pEditView->SetAttribs( aSet );
1259         delete pNewItem;
1260     }
1261     UpdateToolBox();
1262     return 0;
1263 }
1264 
1265 void EditMainWindow::CreatePolygon()
1266 {
1267     EditView* pEditView = aViewWin.GetEditView();
1268     Size aSz = pEditView->GetWindow()->GetOutputSize();
1269     Point aOffset( aSz.Width()/8, aSz.Height()/8 );
1270     aSz.Width() *= 3;
1271     aSz.Width() /= 4;
1272     aSz.Height() *= 3;
1273     aSz.Height() /= 4;
1274     Polygon aPoly( 5 );
1275     aPoly.SetPoint( Point( aSz.Width()/2, 0 ), 0 );
1276     aPoly.SetPoint( Point( aSz.Width(), aSz.Height()/3 ), 1 );
1277     aPoly.SetPoint( Point( aSz.Width()/2, aSz.Height() ), 2 );
1278     aPoly.SetPoint( Point( 0, aSz.Height()/2 ), 3 );
1279     aPoly.SetPoint( Point( aSz.Width()/2, 0 ), 4 );
1280     PolyPolygon aPPoly( aPoly );
1281     pEditView->GetEditEngine()->SetPolygon( aPPoly );
1282     pEditView->SetOutputArea( Rectangle( aOffset, aSz ) );
1283     ULONG nWord = pEditView->GetControlWord();
1284     nWord &= ~(EV_CNTRL_AUTOSCROLL);
1285     pEditView->SetControlWord( nWord );
1286     aViewWin.Invalidate();
1287 }
1288 
1289 void __EXPORT EditMainWindow::GetFocus()
1290 {
1291     aViewWin.GrabFocus();
1292 }
1293 
1294 IMPL_LINK_INLINE_START( EditMainWindow, HScrollHdl, ScrollBar *, pScrl )
1295 {
1296     EditView* pEditView = aViewWin.GetEditView();
1297     pEditView->Scroll( -pScrl->GetDelta(), 0, RGCHK_PAPERSZ1 );
1298     return 0;
1299 }
1300 IMPL_LINK_INLINE_END( EditMainWindow, HScrollHdl, ScrollBar *, pScrl )
1301 
1302 IMPL_LINK_INLINE_START( EditMainWindow, VScrollHdl, ScrollBar *, pScrl )
1303 {
1304     EditView* pEditView = aViewWin.GetEditView();
1305     pEditView->Scroll( 0, -pScrl->GetDelta(), RGCHK_PAPERSZ1 );
1306     return 0;
1307 }
1308 IMPL_LINK_INLINE_END( EditMainWindow, VScrollHdl, ScrollBar *, pScrl )
1309 
1310 void EditMainWindow::SetScrollBarRanges()
1311 {
1312     EditView* pEditView = aViewWin.GetEditView();
1313     long y = pEditView->GetEditEngine()->GetTextHeight();
1314     long x = pEditView->GetEditEngine()->GetPaperSize().Width();
1315 
1316     aHScrollBar.SetRange( Range( 0, x ) );
1317     aVScrollBar.SetRange( Range( 0, y ) );
1318 }
1319 
1320 void EditMainWindow::SetScrollBars()
1321 {
1322     EditView* pEditView = aViewWin.GetEditView();
1323     Size aSz = GetOutputSizePixel();
1324     Size aRealSz( aSz );
1325     long nScrollbarWidthPixel = aVScrollBar.GetSizePixel().Width();
1326     long nTBHeight = aToolBox.GetSizePixel().Height();
1327     aSz.Height() -= nTBHeight;
1328     Size aOrgSz( aSz );
1329 
1330     // VScroll...
1331     aSz.Height() += 2;
1332     Point aPoint( ( aSz.Width()- nScrollbarWidthPixel+1 ), -1+nTBHeight);
1333     aSz.Width() = nScrollbarWidthPixel;
1334     aVScrollBar.SetPosSizePixel( aPoint, aSz );
1335 
1336     // HScroll...
1337     aSz = aOrgSz;
1338     Point aPoint2( 0, aRealSz.Height()-aHScrollBar.GetSizePixel().Height()+1 ); // TB-Height schon drin!
1339     aSz.Width() -= aVScrollBar.GetSizePixel().Width();
1340     aSz.Width() += 2;
1341 
1342     aSz.Height() = nScrollbarWidthPixel;
1343     aHScrollBar.SetPosSizePixel( aPoint2, aSz );
1344 
1345     aHScrollBar.SetVisibleSize( pEditView->GetOutputArea().GetWidth() );
1346     aVScrollBar.SetVisibleSize( pEditView->GetOutputArea().GetHeight() );
1347 
1348     SetScrollBarRanges();
1349 
1350     aVScrollBar.Show();
1351     aHScrollBar.Show();
1352 }
1353 
1354 void __EXPORT EditMainWindow::Resize()
1355 {
1356     long nBorder = aVScrollBar.GetSizePixel().Width();
1357     long nExtra = 10;
1358     Size aTBSz = aToolBox.CalcWindowSizePixel();
1359     Size aOutSzPixel( GetOutputSizePixel() );
1360     aToolBox.SetSizePixel( Size( aOutSzPixel.Width(), aTBSz.Height()) );
1361 
1362     aViewWin.SetSizePixel( Size( aOutSzPixel.Width()-nBorder-2*nExtra, aOutSzPixel.Height()-aTBSz.Height()-2*nExtra-nBorder) );
1363 
1364     aViewWin.SetPosPixel( Point( nExtra, aTBSz.Height()+nExtra ) );
1365 
1366     SetScrollBars();
1367 
1368     EditView* pEditView = aViewWin.GetEditView();
1369     if ( pEditView && pEditView->GetEditEngine()->GetPolygon() )
1370         CreatePolygon();
1371 }
1372 
1373 IMPL_LINK( EditMainWindow, ShowStatus, EditStatus *, pStat )
1374 {
1375     EditView* pEditView = aViewWin.GetEditView();
1376     EditEngine* pEditEngine = pEditView->GetEditEngine();
1377     if ( ( pStat->GetStatusWord() & EE_STAT_TEXTWIDTHCHANGED ) || ( pStat->GetStatusWord() & EE_STAT_TEXTHEIGHTCHANGED ) )
1378     {
1379         aViewWin.MarkOutputArea();
1380         if ( pEditEngine->GetTextHeight() < (ULONG)pEditView->GetOutputArea().GetHeight() )
1381         {
1382             // Wird durch RGCHK_PAPERSZ1 'geklippt'
1383             if ( !( pEditEngine->GetControlWord() & EE_CNTRL_AUTOPAGESIZE) )
1384                 pEditView->Scroll( -(long)pEditEngine->CalcTextWidth(), -(long)pEditEngine->GetTextHeight(), RGCHK_PAPERSZ1 );
1385         }
1386         SetScrollBarRanges();
1387     }
1388     if ( pStat->GetStatusWord() & EE_STAT_HSCROLL )
1389         aHScrollBar.SetThumbPos( pEditView->GetVisArea().Left() );
1390     if ( pStat->GetStatusWord() & EE_STAT_VSCROLL )
1391         aVScrollBar.SetThumbPos( pEditView->GetVisArea().Top() );
1392 
1393     return 0;
1394 }
1395 
1396 
1397 EditViewWindow::~EditViewWindow()
1398 {
1399     // erst die angemeldeten Views zerstoeren
1400     // (melden sich selbst ab)
1401     MyView* pView = aViewList.First();
1402     while ( pView )
1403     {
1404         delete pView;
1405         pView = aViewList.Next();
1406     }
1407 
1408     pEditEngine->RemoveView( pEditView );
1409     delete pEditView;
1410     // Beim Zerstoeren der Styles am Ende, EditEngine noch nicht kaputt,
1411     // wird der Handler gerufen, ich zerstore hier aber schon die View!
1412     pEditEngine->SetStatusEventHdl( Link() );
1413 //  SvxAutoCorrect* pAutoCorrekt = pEditEngine->GetAutoCorrect();
1414 //  pEditEngine->SetAutoCorrect( 0 );
1415 //  delete pAutoCorrekt;
1416     delete pEditEngine;
1417 }
1418 
1419 EditViewWindow::EditViewWindow( Window* pParent ) :
1420                 Window( pParent ), aURLPtr( POINTER_HAND )
1421 {
1422     SetBackgroundBrush( Brush( Color( COL_WHITE ) ) );
1423     SetMapMode( MAP_100TH_MM );
1424 //  EnableDrop();
1425 
1426     SfxItemPool* pPool = EditEngine::CreatePool();
1427     Font aFont = GetSettings().GetStyleSettings().GetAppFont();
1428     MapMode aPntMode( MAP_POINT );
1429     MapMode aCurrent( GetMapMode() );
1430     Size aSz( LogicToLogic( Size( 12, 0 ), &aPntMode, &aCurrent ) );
1431     aFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Times New Roman" ) ) );
1432     pPool->SetPoolDefaultItem( SvxFontItem( aFont.GetFamily(), aFont.GetName(), String(),aFont.GetPitch(), aFont.GetCharSet(), EE_CHAR_FONTINFO ) );
1433     pPool->SetPoolDefaultItem( SvxFontHeightItem( aSz.Width(), 100, EE_CHAR_FONTHEIGHT ) );
1434     pEditEngine = new MyEditEngine( pPool );
1435 
1436     Size aPaperSz( 10000,8000 );
1437     pEditEngine->SetPaperSize( aPaperSz );
1438 
1439     pEditView = new EditView( pEditEngine, this );
1440     pEditView->SetBackgroundColor( Color( COL_WHITE ) );
1441     pEditView->SetOutputArea( Rectangle( Point( 100, 100 ), aPaperSz ) );
1442     pEditEngine->SetDefaultLanguage( LANGUAGE_ENGLISH );
1443     pEditEngine->InsertView( pEditView );
1444 
1445     SetPosSizePixel( Point( 10, 10 ), Size( 600, 400 ) );
1446     SetPen( PEN_NULL );
1447     Show();
1448 
1449     // Feldbefehle grau hinterlegen
1450     ULONG n = pEditEngine->GetControlWord();
1451     n = n | (EE_CNTRL_MARKFIELDS|EE_CNTRL_AUTOCOMPLETE);
1452     pEditEngine->SetControlWord( n );
1453 
1454     // Test: Autozentrierung
1455 //  ULONG n = pEditEngine->GetControlWord();
1456 //  n = n | EE_CNTRL_AUTOPAGESIZE;
1457 //  pEditEngine->SetControlWord( n );
1458 
1459     // OneLineSpeling
1460 #ifdef WNT
1461 //  pEditEngine->CreateSpeller( DirEntry( String( RTL_CONSTASCII_USTRINGPARAM( "n:\\offenv\\wnti" ) ) ),
1462 //                              DirEntry( String( RTL_CONSTASCII_USTRINGPARAM( "n:\\offenv\\wnti" ) ) ) );
1463 //  pEditEngine->GetSpeller()->SetActualLanguage( LANGUAGE_GERMAN );
1464 //  pEditEngine->GetSpeller()->SetDefaultLanguage( LANGUAGE_GERMAN );
1465 //  pEditEngine->GetSpeller()->SetMinTrail( 2 );
1466 
1467     // AutoCorrect wird nie zerstoert
1468 //  pEditEngine->SetAutoCorrect( new SvxAutoCorrect( String( RTL_CONSTASCII_USTRINGPARAM( "d:\\prj\\office\\autotext\\autocorr.dat" ) ) ) );
1469 #endif
1470 }
1471 
1472 void __EXPORT EditViewWindow::Paint( const Rectangle& rRec )
1473 {
1474     if ( pEditView->GetEditEngine()->GetPolygon() )
1475     {
1476         // Die Punkte des Polygons beziehen sich auf die View...
1477         MapMode aMapMode( GetMapMode() );
1478         aMapMode.SetOrigin( pEditView->GetOutputArea().TopLeft() );
1479         SetMapMode( aMapMode );
1480         DrawPolyPolygon( *pEditView->GetEditEngine()->GetPolygon() );
1481         aMapMode.SetOrigin( Point() );
1482         SetMapMode( aMapMode );
1483     }
1484     pEditView->Paint( rRec );
1485     MarkOutputArea();
1486 }
1487 
1488 void EditViewWindow::MarkOutputArea()
1489 {
1490     static Rectangle aCurFrame;
1491     Rectangle aOutArea( pEditView->GetOutputArea() );
1492     aOutArea = LogicToPixel( aOutArea );
1493     aOutArea.Left()--;
1494     aOutArea.Right()++;
1495     aOutArea.Top()--;
1496     aOutArea.Bottom()++;
1497     aOutArea = PixelToLogic( aOutArea );
1498     SetPen( Pen( Color( COL_RED ) ) );
1499     SetFillInBrush( Brush( BRUSH_NULL ) );
1500     DrawRect( aOutArea );
1501     if ( !aCurFrame.IsEmpty() )
1502     {
1503         if ( aCurFrame.Left() < aOutArea.Left() )
1504             Invalidate( Rectangle( aCurFrame.TopLeft(), Size( aOutArea.Left()-aCurFrame.Left(), aCurFrame.GetHeight() ) ) );
1505         if ( aCurFrame.Right() > aOutArea.Right() )
1506         {
1507             long nW = aCurFrame.Right() - aOutArea.Right();
1508             Point aPos( aCurFrame.TopRight() );
1509             aPos.X() -= nW;
1510             Invalidate( Rectangle( aPos, Size( nW, aCurFrame.GetHeight() ) ) );
1511         }
1512         if ( aCurFrame.Top() < aOutArea.Top() )
1513             Invalidate( Rectangle( aCurFrame.TopLeft(), Size( aCurFrame.GetWidth(), aOutArea.Top() - aCurFrame.Top() ) ) );
1514         if ( aCurFrame.Bottom() > aOutArea.Bottom() )
1515         {
1516             long nH = aCurFrame.Bottom() - aOutArea.Bottom();
1517             Point aPos( aCurFrame.BottomLeft() );
1518             aPos.Y() -= nH;
1519             Invalidate( Rectangle( aPos, Size( aCurFrame.GetWidth(), nH ) ) );
1520         }
1521     }
1522     aCurFrame = aOutArea;
1523 }
1524 
1525 void __EXPORT EditViewWindow::Resize()
1526 {
1527     Size aPaperSz( GetOutputSize() );
1528     pEditView->SetOutputArea( Rectangle( Point(0,0), aPaperSz ) );
1529     pEditEngine->SetPaperSize( Size( aPaperSz.Width()*1, aPaperSz.Height()*1 ) );
1530     pEditView->ShowCursor();
1531     Invalidate();
1532 }
1533 
1534 void __EXPORT EditViewWindow::KeyInput( const KeyEvent& rKEvt )
1535 {
1536     sal_Unicode nCharCode = rKEvt.GetCharCode();
1537 
1538     USHORT nCode = rKEvt.GetKeyCode().GetCode();
1539     // Auswertung fuer besondere Einstellungen....
1540     if ( ( nCode == KEY_A) && rKEvt.GetKeyCode().IsMod1() )
1541         pEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
1542     else if ( ( nCode == KEY_R ) && rKEvt.GetKeyCode().IsMod2() )
1543         Invalidate();
1544     else if ( ( nCode == KEY_L ) && rKEvt.GetKeyCode().IsMod2() )
1545     {
1546         ULONG n = pEditEngine->GetControlWord();
1547         n = n | EE_CNTRL_ONECHARPERLINE;
1548         pEditEngine->SetControlWord( n );
1549         pEditEngine->QuickFormatDoc();
1550     }
1551     else if ( ( nCode == KEY_Z ) && rKEvt.GetKeyCode().IsMod2() )
1552     {
1553         pEditView->RemoveAttribs();
1554     }
1555     else if ( ( nCode == KEY_V ) && rKEvt.GetKeyCode().IsMod2() )
1556     {
1557         pEditEngine->SetVertical( TRUE );
1558         Invalidate();
1559     }
1560     else if ( ( ( nCode == KEY_ADD ) || ( nCode == KEY_SUBTRACT ) )&& rKEvt.GetKeyCode().IsMod2() )
1561     {
1562         short nDiff = ( nCode == KEY_ADD ) ? (+5) : (-5);
1563         if ( nZoom > 1000 )
1564             nDiff *= 20;
1565         if ( nZoom <= 25 )
1566             nDiff /= 5;
1567         if ( ( nZoom + nDiff ) > 0 )
1568             nZoom += nDiff;
1569         MapMode aMapMode( MAP_100TH_MM, Point(0,0), Fraction(nZoom,100), Fraction(nZoom,100) );
1570         SetMapMode( aMapMode );
1571         ((EditMainWindow*)GetParent())->SetTitle();
1572 
1573         if ( rKEvt.GetKeyCode().IsMod1() )
1574         {
1575             InfoBox( 0, String( RTL_CONSTASCII_USTRINGPARAM( "ChangingRefMapMode..." ) ) ).Execute();
1576             pEditEngine->SetRefMapMode( aMapMode );
1577         }
1578         Invalidate();
1579     }
1580     else if ( rKEvt.GetKeyCode().IsMod2() &&
1581             ( ( nCode == KEY_UP) || ( nCode == KEY_DOWN ) ||
1582               ( nCode == KEY_LEFT ) || ( nCode == KEY_RIGHT ) ) )
1583     {
1584         if( rKEvt.GetKeyCode().IsMod1() )
1585         {
1586             ULONG nCtrl = pEditEngine->GetControlWord();
1587             if ( ! ( nCtrl & EE_CNTRL_STRETCHING ) )
1588             {
1589                 nCtrl |= EE_CNTRL_STRETCHING;
1590                 pEditEngine->SetControlWord( nCtrl );
1591             }
1592             USHORT nX, nY;
1593             pEditEngine->GetGlobalCharStretching( nX, nY );
1594             if ( ( nCode == KEY_DOWN ) && ( nY > 5 ) )
1595                 nY += 5;
1596             else if ( nCode == KEY_UP )
1597                 nY -= 5;
1598             else if ( nCode == KEY_RIGHT )
1599                 nX += 5;
1600             else if ( ( nCode == KEY_LEFT ) && ( nX > 5 ) )
1601                 nX -= 5;
1602             pEditEngine->SetGlobalCharStretching( nX, nY );
1603             ((EditMainWindow*)GetParent())->SetTitle();
1604         }
1605         else    // ZeichenAttr
1606         {
1607             SfxItemSet aAttrs( pEditView->GetAttribs() );
1608             SfxItemSet aNewAttrs( pEditEngine->GetEmptyItemSet() );
1609             const SvxFontWidthItem& rItem = (const SvxFontWidthItem&)aAttrs.Get( EE_CHAR_FONTWIDTH );
1610             USHORT nProp = rItem.GetProp();
1611             if ( nCode == KEY_RIGHT )
1612                 nProp += 5;
1613             else if ( ( nCode == KEY_LEFT ) && ( nProp > 5 ) )
1614                 nProp -= 5;
1615             aNewAttrs.Put( SvxFontWidthItem( 0, nProp, EE_CHAR_FONTWIDTH ) );
1616             pEditView->SetAttribs( aNewAttrs );
1617         }
1618     }
1619     else if ( ( nCode == KEY_O ) && rKEvt.GetKeyCode().IsMod2() )
1620     {
1621         MapMode aMapMode( GetMapMode() );
1622         aMapMode.SetOrigin( Point( 41, 41 ) );
1623         SetMapMode( aMapMode );
1624         Invalidate();
1625     }
1626     else if ( ( nCode == KEY_B ) && rKEvt.GetKeyCode().IsMod2() )
1627     {
1628         SfxItemSet aSet = pEditView->GetEmptyItemSet();
1629         aSet.Put( SvxFontHeightItem(800, 100, EE_CHAR_FONTHEIGHT) );
1630         pEditView->SetAttribs( aSet );
1631     }
1632     else if ( ( nCode == KEY_P ) && rKEvt.GetKeyCode().IsMod2() )
1633     {
1634 //              ESelection aSel = pEditView->GetSelection();
1635 //              for ( ULONG n = aSel.nStartPara; n <= aSel.nEndPara; n++ )
1636 //              {
1637 //                  InfoBox( 0, pEditEngine->GetText( n ) ).Execute();
1638 //              }
1639         InfoBox( 0, pEditView->GetSelected() ).Execute();
1640 
1641     }
1642     else if ( rKEvt.GetKeyCode().IsMod2() &&
1643                 ( nCode >= KEY_1 ) && ( nCode <= KEY_9 ) )
1644     {
1645         ULONG nEECtrl = pEditEngine->GetControlWord();
1646         nEECtrl = nEECtrl | EE_CNTRL_AUTOPAGESIZE;
1647         pEditEngine->SetControlWord( nEECtrl );
1648 
1649         ULONG nEVCtrl = pEditView->GetControlWord();
1650         nEVCtrl |= EV_CNTRL_AUTOSIZE;
1651         pEditView->SetControlWord( nEVCtrl );
1652 
1653         pEditView->SetAnchorMode( (EVAnchorMode)(nCode-KEY_1) );
1654         pEditView->SetOutputArea( Rectangle( Point(0,0), GetOutputSize() ) );
1655         pEditEngine->SetMaxAutoPaperSize( GetOutputSize() );
1656         pEditEngine->SetPaperSize( Size( 0, 0 ) );
1657     }
1658     else if ( rKEvt.GetKeyCode().IsMod2() && ( nCode == KEY_0 ) )
1659     {
1660         ULONG nEVCtrl = pEditView->GetControlWord();
1661         nEVCtrl = nEVCtrl | EV_CNTRL_AUTOSIZE;
1662         pEditView->SetControlWord( nEVCtrl );
1663 
1664         Size aOutSz( GetOutputSize() );
1665         Size aPaperSz( aOutSz.Width() / 2, 0 );
1666         pEditView->SetOutputArea( Rectangle( Point(), aPaperSz ) );
1667         pEditEngine->SetPaperSize( aPaperSz );
1668         // Max-Height wird bei View verwendet,
1669         // MinSize/MaxSize nur, wenn AUTOPAGESIZE ( KEY_1 - KEY_9 )
1670         pEditEngine->SetMaxAutoPaperSize( Size( aOutSz.Width() / 2, aOutSz.Height() / 2 ) );
1671         pEditEngine->SetMinAutoPaperSize( Size( aOutSz.Width() / 8, aOutSz.Height() / 8 ) );
1672     }
1673     else if ( ( nCode == KEY_J ) && rKEvt.GetKeyCode().IsMod2() )
1674     {
1675         Size aTextSz( pEditEngine->CalcTextWidth(), pEditEngine->GetTextHeight() );
1676         Rectangle aRect( pEditView->GetOutputArea().TopLeft(), aTextSz );
1677         Brush aTmpBrush( Color( COL_LIGHTBLUE ), BRUSH_25 );
1678         Brush aOldBrush( GetFillInBrush() );
1679         SetFillInBrush( aTmpBrush );
1680         DrawRect( aRect );
1681         SetFillInBrush( aOldBrush );
1682         pEditView->Paint( aRect );
1683     }
1684     else if ( ( nCode == KEY_H ) && rKEvt.GetKeyCode().IsMod2() )
1685     {
1686         Push();
1687         Size aSz( pEditEngine->CalcTextWidth(), pEditEngine->GetTextHeight() );
1688         Pen aPen( PEN_SOLID );
1689         Brush aBrush( Color( COL_GRAY ), BRUSH_SOLID );
1690         aPen.SetColor( Color( COL_BLACK ) );
1691         SetPen( aPen );
1692         SetFillInBrush( aBrush );
1693         Rectangle aR( pEditView->GetOutputArea().TopLeft(), aSz );
1694         DrawRect( aR );
1695         Pop();
1696         pEditEngine->Draw( this, pEditView->GetOutputArea() );
1697         pEditView->ShowCursor( TRUE, TRUE );
1698     }
1699 
1700     // Eingabe an EditEngine...
1701     else
1702     {
1703         BOOL bDone = pEditView->PostKeyEvent( rKEvt );
1704         if ( !bDone )
1705             Window::KeyInput( rKEvt );
1706     }
1707 
1708     ((EditMainWindow*)GetParent())->UpdateToolBox();
1709 }
1710 
1711 void __EXPORT EditViewWindow::MouseMove( const MouseEvent& rMEvt )
1712 {
1713     Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
1714     if ( pEditView->GetOutputArea().IsInside( aPos ) )
1715     {
1716         const SvxFieldItem* pField = pEditView->GetFieldUnderMousePointer();
1717         if ( pField )
1718             SetPointer( aURLPtr );
1719         else
1720             SetPointer( pEditView->GetPointer() );
1721 
1722 //      aPos -= pEditView->GetOutputArea().TopLeft();
1723 //      aPos += pEditView->GetVisArea().TopLeft();
1724 //      if ( pEditView->GetEditEngine()->IsTextPos( aPos, PixelToLogic( Size( 5, 0 ) ).Width() ) )
1725 //          SetPointer( pEditView->GetPointer() );
1726 //      else
1727 //          SetPointer( Pointer( POINTER_REFHAND ) );
1728 
1729     }
1730     else
1731         SetPointer( aStdPtr );
1732 
1733 //  static long x = 0;
1734 //  x++;
1735 //  DBG_ASSERT( x < 1000, String( RTL_CONSTASCII_USTRINGPARAM( "?" ) ) );
1736     pEditView->MouseMove( rMEvt );
1737 }
1738 
1739 void __EXPORT EditViewWindow::MouseButtonDown( const MouseEvent& rMEvt )
1740 {
1741     GrabFocus();
1742     pEditView->MouseButtonDown( rMEvt );
1743 }
1744 
1745 void __EXPORT EditViewWindow::MouseButtonUp( const MouseEvent& rMEvt )
1746 {
1747     pEditView->MouseButtonUp( rMEvt );
1748     ((EditMainWindow*)GetParent())->UpdateToolBox();
1749 }
1750 
1751 void __EXPORT EditViewWindow::Command( const CommandEvent& rCEvt )
1752 {
1753     if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
1754     {
1755         if( pEditView->IsWrongSpelledWordAtPos( rCEvt.GetMousePosPixel() ) )
1756             pEditView->ExecuteSpellPopup( rCEvt.GetMousePosPixel() );
1757     }
1758     else
1759         pEditView->Command(rCEvt);
1760 
1761 }
1762 
1763 BOOL __EXPORT EditViewWindow::Drop( const DropEvent& rEvt )
1764 {
1765     return pEditView->Drop( rEvt );
1766 }
1767 
1768 BOOL __EXPORT EditViewWindow::QueryDrop( DropEvent& rEvt )
1769 {
1770     return pEditView->QueryDrop( rEvt );
1771 }
1772 
1773 // --- aEditApp ------------------------------------------------------
1774 
1775 void __EXPORT EditApp::Main()
1776 {
1777 #ifdef WNT
1778     SvFactory::Init();
1779 #endif
1780 
1781     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >  xSMgr = createApplicationServiceManager();
1782     ::comphelper::setProcessServiceFactory( xSMgr );
1783 
1784     EditDLL aEditDll;
1785     SvxGlobalItemData aItemData;
1786     SvxFieldItem::GetClassManager().SV_CLASS_REGISTER( SvxDateField );
1787     SvxFieldItem::GetClassManager().SV_CLASS_REGISTER( SvxURLField );
1788 
1789     Help::EnableQuickHelp();
1790 
1791     EditMainWindow aWindow;
1792     Execute();
1793 }
1794 
1795 EditApp aEditApp;
1796