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