15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
55900e8ecSAndrew Rist * distributed with this work for additional information
65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
105900e8ecSAndrew Rist *
115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist *
135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist * software distributed under the License is distributed on an
155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
175900e8ecSAndrew Rist * specific language governing permissions and limitations
185900e8ecSAndrew Rist * under the License.
195900e8ecSAndrew Rist *
205900e8ecSAndrew Rist *************************************************************/
215900e8ecSAndrew Rist
225900e8ecSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <memory>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "unoiface.hxx"
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <tools/rc.h>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <vcl/decoview.hxx>
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include <svtools/svmedit.hxx>
38cdf0e10cSrcweir #include <svtools/xtextedt.hxx>
39cdf0e10cSrcweir #include <svl/brdcst.hxx>
40cdf0e10cSrcweir #include <svl/undo.hxx>
41cdf0e10cSrcweir #include <svtools/textwindowpeer.hxx>
42cdf0e10cSrcweir #include <svl/lstner.hxx>
43cdf0e10cSrcweir #include <svl/smplhint.hxx>
44cdf0e10cSrcweir
45cdf0e10cSrcweir
46cdf0e10cSrcweir // IDs erstmal aus VCL geklaut, muss mal richtig delivert werden...
47cdf0e10cSrcweir #define SV_MENU_EDIT_UNDO 1
48cdf0e10cSrcweir #define SV_MENU_EDIT_CUT 2
49cdf0e10cSrcweir #define SV_MENU_EDIT_COPY 3
50cdf0e10cSrcweir #define SV_MENU_EDIT_PASTE 4
51cdf0e10cSrcweir #define SV_MENU_EDIT_DELETE 5
52cdf0e10cSrcweir #define SV_MENU_EDIT_SELECTALL 6
53cdf0e10cSrcweir #define SV_MENU_EDIT_INSERTSYMBOL 7
54cdf0e10cSrcweir #include <vcl/scrbar.hxx>
55cdf0e10cSrcweir
56cdf0e10cSrcweir namespace css = ::com::sun::star;
57cdf0e10cSrcweir
58cdf0e10cSrcweir class TextWindow : public Window
59cdf0e10cSrcweir {
60cdf0e10cSrcweir private:
61cdf0e10cSrcweir ExtTextEngine* mpExtTextEngine;
62cdf0e10cSrcweir ExtTextView* mpExtTextView;
63cdf0e10cSrcweir
64cdf0e10cSrcweir sal_Bool mbInMBDown;
65cdf0e10cSrcweir sal_Bool mbFocusSelectionHide;
66cdf0e10cSrcweir sal_Bool mbIgnoreTab;
67cdf0e10cSrcweir sal_Bool mbActivePopup;
68cdf0e10cSrcweir sal_Bool mbSelectOnTab;
69cdf0e10cSrcweir
70cdf0e10cSrcweir public:
71cdf0e10cSrcweir TextWindow( Window* pParent );
72cdf0e10cSrcweir ~TextWindow();
73cdf0e10cSrcweir
GetTextEngine() const74cdf0e10cSrcweir ExtTextEngine* GetTextEngine() const { return mpExtTextEngine; }
GetTextView() const75cdf0e10cSrcweir ExtTextView* GetTextView() const { return mpExtTextView; }
76cdf0e10cSrcweir
77cdf0e10cSrcweir virtual void MouseMove( const MouseEvent& rMEvt );
78cdf0e10cSrcweir virtual void MouseButtonDown( const MouseEvent& rMEvt );
79cdf0e10cSrcweir virtual void MouseButtonUp( const MouseEvent& rMEvt );
80cdf0e10cSrcweir virtual void KeyInput( const KeyEvent& rKEvent );
81cdf0e10cSrcweir
82cdf0e10cSrcweir virtual void Command( const CommandEvent& rCEvt );
83cdf0e10cSrcweir
84cdf0e10cSrcweir virtual void Paint( const Rectangle& rRect );
85cdf0e10cSrcweir virtual void Resize();
86cdf0e10cSrcweir
87cdf0e10cSrcweir virtual void GetFocus();
88cdf0e10cSrcweir virtual void LoseFocus();
89cdf0e10cSrcweir
IsAutoFocusHide() const90cdf0e10cSrcweir sal_Bool IsAutoFocusHide() const { return mbFocusSelectionHide; }
SetAutoFocusHide(sal_Bool bAutoHide)91cdf0e10cSrcweir void SetAutoFocusHide( sal_Bool bAutoHide ) { mbFocusSelectionHide = bAutoHide; }
92cdf0e10cSrcweir
IsIgnoreTab() const93cdf0e10cSrcweir sal_Bool IsIgnoreTab() const { return mbIgnoreTab; }
SetIgnoreTab(sal_Bool bIgnore)94cdf0e10cSrcweir void SetIgnoreTab( sal_Bool bIgnore ) { mbIgnoreTab = bIgnore; }
95cdf0e10cSrcweir
DisableSelectionOnFocus()96cdf0e10cSrcweir void DisableSelectionOnFocus() {mbSelectOnTab = sal_False;}
97cdf0e10cSrcweir
98cdf0e10cSrcweir virtual
99cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
100cdf0e10cSrcweir GetComponentInterface(sal_Bool bCreate = sal_True);
101cdf0e10cSrcweir };
102cdf0e10cSrcweir
103cdf0e10cSrcweir
104cdf0e10cSrcweir class ImpSvMEdit : public SfxListener
105cdf0e10cSrcweir {
106cdf0e10cSrcweir private:
107cdf0e10cSrcweir MultiLineEdit* pSvMultiLineEdit;
108cdf0e10cSrcweir
109cdf0e10cSrcweir TextWindow* mpTextWindow;
110cdf0e10cSrcweir ScrollBar* mpHScrollBar;
111cdf0e10cSrcweir ScrollBar* mpVScrollBar;
112cdf0e10cSrcweir ScrollBarBox* mpScrollBox;
113cdf0e10cSrcweir
114cdf0e10cSrcweir Point maTextWindowOffset;
115cdf0e10cSrcweir xub_StrLen mnTextWidth;
116cdf0e10cSrcweir mutable Selection maSelection;
117cdf0e10cSrcweir
118cdf0e10cSrcweir protected:
119cdf0e10cSrcweir virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
120cdf0e10cSrcweir void ImpUpdateSrollBarVis( WinBits nWinStyle );
121cdf0e10cSrcweir void ImpInitScrollBars();
122cdf0e10cSrcweir void ImpSetScrollBarRanges();
123cdf0e10cSrcweir void ImpSetHScrollBarThumbPos();
124cdf0e10cSrcweir DECL_LINK( ScrollHdl, ScrollBar* );
125cdf0e10cSrcweir
126cdf0e10cSrcweir public:
127cdf0e10cSrcweir ImpSvMEdit( MultiLineEdit* pSvMultiLineEdit, WinBits nWinStyle );
128cdf0e10cSrcweir ~ImpSvMEdit();
129cdf0e10cSrcweir
130cdf0e10cSrcweir void SetModified( sal_Bool bMod );
131cdf0e10cSrcweir sal_Bool IsModified() const;
132cdf0e10cSrcweir
133cdf0e10cSrcweir void SetReadOnly( sal_Bool bRdOnly );
134cdf0e10cSrcweir sal_Bool IsReadOnly() const;
135cdf0e10cSrcweir
136cdf0e10cSrcweir void SetMaxTextLen( xub_StrLen nLen );
137cdf0e10cSrcweir xub_StrLen GetMaxTextLen() const;
138cdf0e10cSrcweir
139cdf0e10cSrcweir void SetInsertMode( sal_Bool bInsert );
140cdf0e10cSrcweir sal_Bool IsInsertMode() const;
141cdf0e10cSrcweir
142cdf0e10cSrcweir void InsertText( const String& rStr );
143cdf0e10cSrcweir String GetSelected() const;
144cdf0e10cSrcweir String GetSelected( LineEnd aSeparator ) const;
145cdf0e10cSrcweir
146cdf0e10cSrcweir void SetSelection( const Selection& rSelection );
147cdf0e10cSrcweir const Selection& GetSelection() const;
148cdf0e10cSrcweir
149cdf0e10cSrcweir void Cut();
150cdf0e10cSrcweir void Copy();
151cdf0e10cSrcweir void Paste();
152cdf0e10cSrcweir
153cdf0e10cSrcweir void SetText( const String& rStr );
154cdf0e10cSrcweir String GetText() const;
155cdf0e10cSrcweir String GetText( LineEnd aSeparator ) const;
156cdf0e10cSrcweir String GetTextLines() const;
157cdf0e10cSrcweir String GetTextLines( LineEnd aSeparator ) const;
158cdf0e10cSrcweir
159cdf0e10cSrcweir void Resize();
160cdf0e10cSrcweir void GetFocus();
161cdf0e10cSrcweir
162cdf0e10cSrcweir sal_Bool HandleCommand( const CommandEvent& rCEvt );
163cdf0e10cSrcweir
164cdf0e10cSrcweir void Enable( sal_Bool bEnable );
165cdf0e10cSrcweir
166cdf0e10cSrcweir Size CalcMinimumSize() const;
167cdf0e10cSrcweir Size CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
168cdf0e10cSrcweir void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
169cdf0e10cSrcweir
170cdf0e10cSrcweir void SetAlign( WinBits nWinStyle );
171cdf0e10cSrcweir
172cdf0e10cSrcweir void InitFromStyle( WinBits nWinStyle );
173cdf0e10cSrcweir
GetTextWindow()174cdf0e10cSrcweir TextWindow* GetTextWindow() { return mpTextWindow; }
GetHScrollBar()175cdf0e10cSrcweir ScrollBar* GetHScrollBar() { return mpHScrollBar; }
GetVScrollBar()176cdf0e10cSrcweir ScrollBar* GetVScrollBar() { return mpVScrollBar; }
177cdf0e10cSrcweir
178cdf0e10cSrcweir void SetTextWindowOffset( const Point& rOffset );
179cdf0e10cSrcweir };
180cdf0e10cSrcweir
ImpSvMEdit(MultiLineEdit * pEdt,WinBits nWinStyle)181cdf0e10cSrcweir ImpSvMEdit::ImpSvMEdit( MultiLineEdit* pEdt, WinBits nWinStyle )
182cdf0e10cSrcweir :mpHScrollBar(NULL)
183cdf0e10cSrcweir ,mpVScrollBar(NULL)
184cdf0e10cSrcweir ,mpScrollBox(NULL)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir pSvMultiLineEdit = pEdt;
187cdf0e10cSrcweir mnTextWidth = 0;
188cdf0e10cSrcweir mpTextWindow = new TextWindow( pEdt );
189cdf0e10cSrcweir mpTextWindow->Show();
190cdf0e10cSrcweir InitFromStyle( nWinStyle );
191cdf0e10cSrcweir StartListening( *mpTextWindow->GetTextEngine() );
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
ImpUpdateSrollBarVis(WinBits nWinStyle)194cdf0e10cSrcweir void ImpSvMEdit::ImpUpdateSrollBarVis( WinBits nWinStyle )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir const sal_Bool bHaveVScroll = (NULL != mpVScrollBar);
197cdf0e10cSrcweir const sal_Bool bHaveHScroll = (NULL != mpHScrollBar);
198cdf0e10cSrcweir const sal_Bool bHaveScrollBox = (NULL != mpScrollBox);
199cdf0e10cSrcweir
200cdf0e10cSrcweir sal_Bool bNeedVScroll = ( nWinStyle & WB_VSCROLL ) == WB_VSCROLL;
201cdf0e10cSrcweir const sal_Bool bNeedHScroll = ( nWinStyle & WB_HSCROLL ) == WB_HSCROLL;
202cdf0e10cSrcweir
203cdf0e10cSrcweir const sal_Bool bAutoVScroll = ( nWinStyle & WB_AUTOVSCROLL ) == WB_AUTOVSCROLL;
204cdf0e10cSrcweir if ( !bNeedVScroll && bAutoVScroll )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir TextEngine& rEngine( *mpTextWindow->GetTextEngine() );
207cdf0e10cSrcweir sal_uLong nOverallTextHeight(0);
208cdf0e10cSrcweir for ( sal_uLong i=0; i<rEngine.GetParagraphCount(); ++i )
209cdf0e10cSrcweir nOverallTextHeight += rEngine.GetTextHeight( i );
210cdf0e10cSrcweir if ( nOverallTextHeight > (sal_uLong)mpTextWindow->GetOutputSizePixel().Height() )
211cdf0e10cSrcweir bNeedVScroll = true;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir const sal_Bool bNeedScrollBox = bNeedVScroll && bNeedHScroll;
215cdf0e10cSrcweir
216cdf0e10cSrcweir sal_Bool bScrollbarsChanged = false;
217cdf0e10cSrcweir if ( bHaveVScroll != bNeedVScroll )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir delete mpVScrollBar;
220cdf0e10cSrcweir mpVScrollBar = bNeedVScroll ? new ScrollBar( pSvMultiLineEdit, WB_VSCROLL|WB_DRAG ) : NULL;
221cdf0e10cSrcweir
222cdf0e10cSrcweir if ( bNeedVScroll )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir mpVScrollBar->Show();
225cdf0e10cSrcweir mpVScrollBar->SetScrollHdl( LINK( this, ImpSvMEdit, ScrollHdl ) );
226cdf0e10cSrcweir }
227cdf0e10cSrcweir
228cdf0e10cSrcweir bScrollbarsChanged = sal_True;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
231cdf0e10cSrcweir if ( bHaveHScroll != bNeedHScroll )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir delete mpHScrollBar;
234cdf0e10cSrcweir mpHScrollBar = bNeedHScroll ? new ScrollBar( pSvMultiLineEdit, WB_HSCROLL|WB_DRAG ) : NULL;
235cdf0e10cSrcweir
236cdf0e10cSrcweir if ( bNeedHScroll )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir mpHScrollBar->Show();
239cdf0e10cSrcweir mpHScrollBar->SetScrollHdl( LINK( this, ImpSvMEdit, ScrollHdl ) );
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
242cdf0e10cSrcweir bScrollbarsChanged = sal_True;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir if ( bHaveScrollBox != bNeedScrollBox )
246cdf0e10cSrcweir {
247cdf0e10cSrcweir delete mpScrollBox;
248cdf0e10cSrcweir mpScrollBox = bNeedScrollBox ? new ScrollBarBox( pSvMultiLineEdit, WB_SIZEABLE ) : NULL;
249cdf0e10cSrcweir
250cdf0e10cSrcweir if ( bNeedScrollBox )
251cdf0e10cSrcweir mpScrollBox->Show();
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
254cdf0e10cSrcweir if ( bScrollbarsChanged )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir ImpInitScrollBars();
257cdf0e10cSrcweir Resize();
258cdf0e10cSrcweir }
259cdf0e10cSrcweir }
260cdf0e10cSrcweir
InitFromStyle(WinBits nWinStyle)261cdf0e10cSrcweir void ImpSvMEdit::InitFromStyle( WinBits nWinStyle )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir ImpUpdateSrollBarVis( nWinStyle );
264cdf0e10cSrcweir SetAlign( nWinStyle );
265cdf0e10cSrcweir
266cdf0e10cSrcweir if ( nWinStyle & WB_NOHIDESELECTION )
267cdf0e10cSrcweir mpTextWindow->SetAutoFocusHide( sal_False );
268cdf0e10cSrcweir else
269cdf0e10cSrcweir mpTextWindow->SetAutoFocusHide( sal_True );
270cdf0e10cSrcweir
271cdf0e10cSrcweir if ( nWinStyle & WB_READONLY )
272cdf0e10cSrcweir mpTextWindow->GetTextView()->SetReadOnly( sal_True );
273cdf0e10cSrcweir else
274cdf0e10cSrcweir mpTextWindow->GetTextView()->SetReadOnly( sal_False );
275cdf0e10cSrcweir
276cdf0e10cSrcweir if ( nWinStyle & WB_IGNORETAB )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir mpTextWindow->SetIgnoreTab( sal_True );
279cdf0e10cSrcweir }
280cdf0e10cSrcweir else
281cdf0e10cSrcweir {
282cdf0e10cSrcweir mpTextWindow->SetIgnoreTab( sal_False );
283cdf0e10cSrcweir // #103667# MultiLineEdit has the flag, but focusable window also needs this flag
284cdf0e10cSrcweir WinBits nStyle = mpTextWindow->GetStyle();
285cdf0e10cSrcweir nStyle |= WINDOW_DLGCTRL_MOD1TAB;
286cdf0e10cSrcweir mpTextWindow->SetStyle( nStyle );
287cdf0e10cSrcweir }
288cdf0e10cSrcweir }
289cdf0e10cSrcweir
~ImpSvMEdit()290cdf0e10cSrcweir ImpSvMEdit::~ImpSvMEdit()
291cdf0e10cSrcweir {
292cdf0e10cSrcweir EndListening( *mpTextWindow->GetTextEngine() );
293cdf0e10cSrcweir delete mpTextWindow;
294cdf0e10cSrcweir delete mpHScrollBar;
295cdf0e10cSrcweir delete mpVScrollBar;
296cdf0e10cSrcweir delete mpScrollBox;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir
ImpSetScrollBarRanges()299cdf0e10cSrcweir void ImpSvMEdit::ImpSetScrollBarRanges()
300cdf0e10cSrcweir {
301cdf0e10cSrcweir if ( mpVScrollBar )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir sal_uLong nTextHeight = mpTextWindow->GetTextEngine()->GetTextHeight();
304cdf0e10cSrcweir mpVScrollBar->SetRange( Range( 0, (long)nTextHeight-1 ) );
305cdf0e10cSrcweir }
306cdf0e10cSrcweir if ( mpHScrollBar )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir // sal_uLong nTextWidth = mpTextWindow->GetTextEngine()->CalcTextWidth();
309cdf0e10cSrcweir // Es gibt kein Notify bei Breiten-Aenderung...
310cdf0e10cSrcweir // sal_uLong nW = Max( (sal_uLong)mpTextWindow->GetOutputSizePixel().Width()*5, (sal_uLong)nTextWidth );
311cdf0e10cSrcweir // mpHScrollBar->SetRange( Range( 0, (long)nW ) );
312cdf0e10cSrcweir mpHScrollBar->SetRange( Range( 0, (long)mnTextWidth-1 ) );
313cdf0e10cSrcweir }
314cdf0e10cSrcweir }
315cdf0e10cSrcweir
ImpInitScrollBars()316cdf0e10cSrcweir void ImpSvMEdit::ImpInitScrollBars()
317cdf0e10cSrcweir {
318cdf0e10cSrcweir static const sal_Unicode sampleText[] = { 'x', '\0' };
319cdf0e10cSrcweir if ( mpHScrollBar || mpVScrollBar )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir ImpSetScrollBarRanges();
322cdf0e10cSrcweir Size aCharBox;
323cdf0e10cSrcweir aCharBox.Width() = mpTextWindow->GetTextWidth( sampleText );
324cdf0e10cSrcweir aCharBox.Height() = mpTextWindow->GetTextHeight();
325cdf0e10cSrcweir Size aOutSz = mpTextWindow->GetOutputSizePixel();
326cdf0e10cSrcweir if ( mpHScrollBar )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir mpHScrollBar->SetVisibleSize( aOutSz.Width() );
329cdf0e10cSrcweir mpHScrollBar->SetPageSize( aOutSz.Width() * 8 / 10 );
330cdf0e10cSrcweir mpHScrollBar->SetLineSize( aCharBox.Width()*10 );
331cdf0e10cSrcweir ImpSetHScrollBarThumbPos();
332cdf0e10cSrcweir }
333cdf0e10cSrcweir if ( mpVScrollBar )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir mpVScrollBar->SetVisibleSize( aOutSz.Height() );
336cdf0e10cSrcweir mpVScrollBar->SetPageSize( aOutSz.Height() * 8 / 10 );
337cdf0e10cSrcweir mpVScrollBar->SetLineSize( aCharBox.Height() );
338cdf0e10cSrcweir mpVScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().Y() );
339cdf0e10cSrcweir }
340cdf0e10cSrcweir }
341cdf0e10cSrcweir }
342cdf0e10cSrcweir
ImpSetHScrollBarThumbPos()343cdf0e10cSrcweir void ImpSvMEdit::ImpSetHScrollBarThumbPos()
344cdf0e10cSrcweir {
345cdf0e10cSrcweir long nX = mpTextWindow->GetTextView()->GetStartDocPos().X();
346cdf0e10cSrcweir if ( !mpTextWindow->GetTextEngine()->IsRightToLeft() )
347cdf0e10cSrcweir mpHScrollBar->SetThumbPos( nX );
348cdf0e10cSrcweir else
349cdf0e10cSrcweir mpHScrollBar->SetThumbPos( mnTextWidth - mpHScrollBar->GetVisibleSize() - nX );
350cdf0e10cSrcweir
351cdf0e10cSrcweir }
352cdf0e10cSrcweir
IMPL_LINK(ImpSvMEdit,ScrollHdl,ScrollBar *,pCurScrollBar)353cdf0e10cSrcweir IMPL_LINK( ImpSvMEdit, ScrollHdl, ScrollBar*, pCurScrollBar )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir long nDiffX = 0, nDiffY = 0;
356cdf0e10cSrcweir
357cdf0e10cSrcweir if ( pCurScrollBar == mpVScrollBar )
358cdf0e10cSrcweir nDiffY = mpTextWindow->GetTextView()->GetStartDocPos().Y() - pCurScrollBar->GetThumbPos();
359cdf0e10cSrcweir else if ( pCurScrollBar == mpHScrollBar )
360cdf0e10cSrcweir nDiffX = mpTextWindow->GetTextView()->GetStartDocPos().X() - pCurScrollBar->GetThumbPos();
361cdf0e10cSrcweir
362cdf0e10cSrcweir mpTextWindow->GetTextView()->Scroll( nDiffX, nDiffY );
363cdf0e10cSrcweir // mpTextWindow->GetTextView()->ShowCursor( sal_False, sal_True );
364cdf0e10cSrcweir
365cdf0e10cSrcweir return 0;
366cdf0e10cSrcweir }
367cdf0e10cSrcweir
368cdf0e10cSrcweir
369cdf0e10cSrcweir // void ImpSvMEdit::ImpModified()
370cdf0e10cSrcweir // {
371cdf0e10cSrcweir // // Wann wird das gerufen ?????????????????????
372cdf0e10cSrcweir // pSvMultiLineEdit->Modify();
373cdf0e10cSrcweir // }
374cdf0e10cSrcweir
SetAlign(WinBits nWinStyle)375cdf0e10cSrcweir void ImpSvMEdit::SetAlign( WinBits nWinStyle )
376cdf0e10cSrcweir {
377cdf0e10cSrcweir sal_Bool bRTL = Application::GetSettings().GetLayoutRTL();
378cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetRightToLeft( bRTL );
379cdf0e10cSrcweir
380cdf0e10cSrcweir if ( nWinStyle & WB_CENTER )
381cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetTextAlign( TXTALIGN_CENTER );
382cdf0e10cSrcweir else if ( nWinStyle & WB_RIGHT )
383cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetTextAlign( !bRTL ? TXTALIGN_RIGHT : TXTALIGN_LEFT );
384cdf0e10cSrcweir else if ( nWinStyle & WB_LEFT )
385cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetTextAlign( !bRTL ? TXTALIGN_LEFT : TXTALIGN_RIGHT );
386cdf0e10cSrcweir }
387cdf0e10cSrcweir
SetTextWindowOffset(const Point & rOffset)388cdf0e10cSrcweir void ImpSvMEdit::SetTextWindowOffset( const Point& rOffset )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir maTextWindowOffset = rOffset;
391cdf0e10cSrcweir Resize();
392cdf0e10cSrcweir }
393cdf0e10cSrcweir
SetModified(sal_Bool bMod)394cdf0e10cSrcweir void ImpSvMEdit::SetModified( sal_Bool bMod )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetModified( bMod );
397cdf0e10cSrcweir }
398cdf0e10cSrcweir
IsModified() const399cdf0e10cSrcweir sal_Bool ImpSvMEdit::IsModified() const
400cdf0e10cSrcweir {
401cdf0e10cSrcweir return mpTextWindow->GetTextEngine()->IsModified();
402cdf0e10cSrcweir }
403cdf0e10cSrcweir
SetInsertMode(sal_Bool bInsert)404cdf0e10cSrcweir void ImpSvMEdit::SetInsertMode( sal_Bool bInsert )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir mpTextWindow->GetTextView()->SetInsertMode( bInsert );
407cdf0e10cSrcweir }
408cdf0e10cSrcweir
SetReadOnly(sal_Bool bRdOnly)409cdf0e10cSrcweir void ImpSvMEdit::SetReadOnly( sal_Bool bRdOnly )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir mpTextWindow->GetTextView()->SetReadOnly( bRdOnly );
412cdf0e10cSrcweir // Farbe anpassen ???????????????????????????
413cdf0e10cSrcweir }
414cdf0e10cSrcweir
IsReadOnly() const415cdf0e10cSrcweir sal_Bool ImpSvMEdit::IsReadOnly() const
416cdf0e10cSrcweir {
417cdf0e10cSrcweir return mpTextWindow->GetTextView()->IsReadOnly();
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
SetMaxTextLen(xub_StrLen nLen)420cdf0e10cSrcweir void ImpSvMEdit::SetMaxTextLen( xub_StrLen nLen )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetMaxTextLen( nLen );
423cdf0e10cSrcweir }
424cdf0e10cSrcweir
GetMaxTextLen() const425cdf0e10cSrcweir xub_StrLen ImpSvMEdit::GetMaxTextLen() const
426cdf0e10cSrcweir {
427cdf0e10cSrcweir return sal::static_int_cast< xub_StrLen >(
428cdf0e10cSrcweir mpTextWindow->GetTextEngine()->GetMaxTextLen());
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
InsertText(const String & rStr)431cdf0e10cSrcweir void ImpSvMEdit::InsertText( const String& rStr )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir mpTextWindow->GetTextView()->InsertText( rStr );
434cdf0e10cSrcweir }
435cdf0e10cSrcweir
GetSelected() const436cdf0e10cSrcweir String ImpSvMEdit::GetSelected() const
437cdf0e10cSrcweir {
438cdf0e10cSrcweir return mpTextWindow->GetTextView()->GetSelected();
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
GetSelected(LineEnd aSeparator) const441cdf0e10cSrcweir String ImpSvMEdit::GetSelected( LineEnd aSeparator ) const
442cdf0e10cSrcweir {
443cdf0e10cSrcweir return mpTextWindow->GetTextView()->GetSelected( aSeparator );
444cdf0e10cSrcweir }
445cdf0e10cSrcweir
Resize()446cdf0e10cSrcweir void ImpSvMEdit::Resize()
447cdf0e10cSrcweir {
448cdf0e10cSrcweir size_t nIteration = 1;
449cdf0e10cSrcweir do
450cdf0e10cSrcweir {
451cdf0e10cSrcweir WinBits nWinStyle( pSvMultiLineEdit->GetStyle() );
452cdf0e10cSrcweir if ( ( nWinStyle & WB_AUTOVSCROLL ) == WB_AUTOVSCROLL )
453cdf0e10cSrcweir ImpUpdateSrollBarVis( nWinStyle );
454cdf0e10cSrcweir
455cdf0e10cSrcweir Size aSz = pSvMultiLineEdit->GetOutputSizePixel();
456cdf0e10cSrcweir Size aEditSize = aSz;
457cdf0e10cSrcweir long nSBWidth = pSvMultiLineEdit->GetSettings().GetStyleSettings().GetScrollBarSize();
458cdf0e10cSrcweir nSBWidth = pSvMultiLineEdit->CalcZoom( nSBWidth );
459cdf0e10cSrcweir
460cdf0e10cSrcweir if ( mpHScrollBar )
461cdf0e10cSrcweir aSz.Height() -= nSBWidth+1;
462cdf0e10cSrcweir if ( mpVScrollBar )
463cdf0e10cSrcweir aSz.Width() -= nSBWidth+1;
464cdf0e10cSrcweir
465cdf0e10cSrcweir if ( !mpHScrollBar )
466cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetMaxTextWidth( aSz.Width() );
467cdf0e10cSrcweir else
468cdf0e10cSrcweir mpHScrollBar->SetPosSizePixel( 0, aEditSize.Height()-nSBWidth, aSz.Width(), nSBWidth );
469cdf0e10cSrcweir
470cdf0e10cSrcweir Point aTextWindowPos( maTextWindowOffset );
471cdf0e10cSrcweir if ( mpVScrollBar )
472cdf0e10cSrcweir {
473cdf0e10cSrcweir if( Application::GetSettings().GetLayoutRTL() )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir mpVScrollBar->SetPosSizePixel( 0, 0, nSBWidth, aSz.Height() );
476cdf0e10cSrcweir aTextWindowPos.X() += nSBWidth;
477cdf0e10cSrcweir }
478cdf0e10cSrcweir else
479cdf0e10cSrcweir mpVScrollBar->SetPosSizePixel( aEditSize.Width()-nSBWidth, 0, nSBWidth, aSz.Height() );
480cdf0e10cSrcweir }
481cdf0e10cSrcweir
482cdf0e10cSrcweir if ( mpScrollBox )
483cdf0e10cSrcweir mpScrollBox->SetPosSizePixel( aSz.Width(), aSz.Height(), nSBWidth, nSBWidth );
484cdf0e10cSrcweir
485cdf0e10cSrcweir Size aTextWindowSize( aSz );
486cdf0e10cSrcweir aTextWindowSize.Width() -= maTextWindowOffset.X();
487cdf0e10cSrcweir aTextWindowSize.Height() -= maTextWindowOffset.Y();
488cdf0e10cSrcweir if ( aTextWindowSize.Width() < 0 )
489cdf0e10cSrcweir aTextWindowSize.Width() = 0;
490cdf0e10cSrcweir if ( aTextWindowSize.Height() < 0 )
491cdf0e10cSrcweir aTextWindowSize.Height() = 0;
492cdf0e10cSrcweir
493cdf0e10cSrcweir Size aOldTextWindowSize( mpTextWindow->GetSizePixel() );
494cdf0e10cSrcweir mpTextWindow->SetPosSizePixel( aTextWindowPos, aTextWindowSize );
495cdf0e10cSrcweir if ( aOldTextWindowSize == aTextWindowSize )
496cdf0e10cSrcweir break;
497cdf0e10cSrcweir
498cdf0e10cSrcweir // Changing the text window size might effectively have changed the need for
499cdf0e10cSrcweir // scrollbars, so do another iteration.
500cdf0e10cSrcweir ++nIteration;
501cdf0e10cSrcweir OSL_ENSURE( nIteration < 3, "ImpSvMEdit::Resize: isn't this expected to terminate with the second iteration?" );
502cdf0e10cSrcweir
503cdf0e10cSrcweir } while ( nIteration <= 3 ); // artificial break after four iterations
504cdf0e10cSrcweir
505cdf0e10cSrcweir ImpInitScrollBars();
506cdf0e10cSrcweir }
507cdf0e10cSrcweir
GetFocus()508cdf0e10cSrcweir void ImpSvMEdit::GetFocus()
509cdf0e10cSrcweir {
510cdf0e10cSrcweir mpTextWindow->GrabFocus();
511cdf0e10cSrcweir }
512cdf0e10cSrcweir
Cut()513cdf0e10cSrcweir void ImpSvMEdit::Cut()
514cdf0e10cSrcweir {
515cdf0e10cSrcweir if ( !mpTextWindow->GetTextView()->IsReadOnly() )
516cdf0e10cSrcweir mpTextWindow->GetTextView()->Cut();
517cdf0e10cSrcweir }
518cdf0e10cSrcweir
Copy()519cdf0e10cSrcweir void ImpSvMEdit::Copy()
520cdf0e10cSrcweir {
521cdf0e10cSrcweir mpTextWindow->GetTextView()->Copy();
522cdf0e10cSrcweir }
523cdf0e10cSrcweir
Paste()524cdf0e10cSrcweir void ImpSvMEdit::Paste()
525cdf0e10cSrcweir {
526cdf0e10cSrcweir if ( !mpTextWindow->GetTextView()->IsReadOnly() )
527cdf0e10cSrcweir mpTextWindow->GetTextView()->Paste();
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
SetText(const String & rStr)530cdf0e10cSrcweir void ImpSvMEdit::SetText( const String& rStr )
531cdf0e10cSrcweir {
532cdf0e10cSrcweir sal_Bool bWasModified = mpTextWindow->GetTextEngine()->IsModified();
533cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetText( rStr );
534cdf0e10cSrcweir if ( !bWasModified )
535cdf0e10cSrcweir mpTextWindow->GetTextEngine()->SetModified( sal_False );
536cdf0e10cSrcweir
537cdf0e10cSrcweir mpTextWindow->GetTextView()->SetSelection( TextSelection() );
538cdf0e10cSrcweir
539cdf0e10cSrcweir WinBits nWinStyle( pSvMultiLineEdit->GetStyle() );
540cdf0e10cSrcweir if ( ( nWinStyle & WB_AUTOVSCROLL ) == WB_AUTOVSCROLL )
541cdf0e10cSrcweir ImpUpdateSrollBarVis( nWinStyle );
542cdf0e10cSrcweir }
543cdf0e10cSrcweir
GetText() const544cdf0e10cSrcweir String ImpSvMEdit::GetText() const
545cdf0e10cSrcweir {
546cdf0e10cSrcweir return mpTextWindow->GetTextEngine()->GetText();
547cdf0e10cSrcweir }
548cdf0e10cSrcweir
GetText(LineEnd aSeparator) const549cdf0e10cSrcweir String ImpSvMEdit::GetText( LineEnd aSeparator ) const
550cdf0e10cSrcweir {
551cdf0e10cSrcweir return mpTextWindow->GetTextEngine()->GetText( aSeparator );
552cdf0e10cSrcweir }
553cdf0e10cSrcweir
GetTextLines() const554cdf0e10cSrcweir String ImpSvMEdit::GetTextLines() const
555cdf0e10cSrcweir {
556cdf0e10cSrcweir return mpTextWindow->GetTextEngine()->GetTextLines();
557cdf0e10cSrcweir }
558cdf0e10cSrcweir
GetTextLines(LineEnd aSeparator) const559cdf0e10cSrcweir String ImpSvMEdit::GetTextLines( LineEnd aSeparator ) const
560cdf0e10cSrcweir {
561cdf0e10cSrcweir return mpTextWindow->GetTextEngine()->GetTextLines( aSeparator );
562cdf0e10cSrcweir }
563cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)564cdf0e10cSrcweir void ImpSvMEdit::Notify( SfxBroadcaster&, const SfxHint& rHint )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir if ( rHint.ISA( TextHint ) )
567cdf0e10cSrcweir {
568cdf0e10cSrcweir const TextHint& rTextHint = (const TextHint&)rHint;
569cdf0e10cSrcweir if( rTextHint.GetId() == TEXT_HINT_VIEWSCROLLED )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir if ( mpHScrollBar )
572cdf0e10cSrcweir ImpSetHScrollBarThumbPos();
573cdf0e10cSrcweir if ( mpVScrollBar )
574cdf0e10cSrcweir mpVScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().Y() );
575cdf0e10cSrcweir }
576cdf0e10cSrcweir else if( rTextHint.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED )
577cdf0e10cSrcweir {
578cdf0e10cSrcweir if ( mpTextWindow->GetTextView()->GetStartDocPos().Y() )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir long nOutHeight = mpTextWindow->GetOutputSizePixel().Height();
581cdf0e10cSrcweir long nTextHeight = mpTextWindow->GetTextEngine()->GetTextHeight();
582cdf0e10cSrcweir if ( nTextHeight < nOutHeight )
583cdf0e10cSrcweir mpTextWindow->GetTextView()->Scroll( 0, mpTextWindow->GetTextView()->GetStartDocPos().Y() );
584cdf0e10cSrcweir }
585cdf0e10cSrcweir
586cdf0e10cSrcweir ImpSetScrollBarRanges();
587cdf0e10cSrcweir }
588cdf0e10cSrcweir else if( rTextHint.GetId() == TEXT_HINT_TEXTFORMATTED )
589cdf0e10cSrcweir {
590cdf0e10cSrcweir if ( mpHScrollBar )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir sal_uLong nWidth = mpTextWindow->GetTextEngine()->CalcTextWidth();
593cdf0e10cSrcweir if ( nWidth != mnTextWidth )
594cdf0e10cSrcweir {
595cdf0e10cSrcweir mnTextWidth = sal::static_int_cast< xub_StrLen >(nWidth);
596cdf0e10cSrcweir mpHScrollBar->SetRange( Range( 0, (long)mnTextWidth-1 ) );
597cdf0e10cSrcweir ImpSetHScrollBarThumbPos();
598cdf0e10cSrcweir }
599cdf0e10cSrcweir }
600cdf0e10cSrcweir }
601cdf0e10cSrcweir else if( rTextHint.GetId() == TEXT_HINT_MODIFIED )
602cdf0e10cSrcweir {
603cdf0e10cSrcweir pSvMultiLineEdit->Modify();
604cdf0e10cSrcweir }
605cdf0e10cSrcweir }
606cdf0e10cSrcweir }
607cdf0e10cSrcweir
SetSelection(const Selection & rSelection)608cdf0e10cSrcweir void ImpSvMEdit::SetSelection( const Selection& rSelection )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir String aText = mpTextWindow->GetTextEngine()->GetText();
611cdf0e10cSrcweir
612cdf0e10cSrcweir Selection aNewSelection( rSelection );
613cdf0e10cSrcweir if ( aNewSelection.Min() < 0 )
614cdf0e10cSrcweir aNewSelection.Min() = 0;
615cdf0e10cSrcweir else if ( aNewSelection.Min() > aText.Len() )
616cdf0e10cSrcweir aNewSelection.Min() = aText.Len();
617cdf0e10cSrcweir if ( aNewSelection.Max() < 0 )
618cdf0e10cSrcweir aNewSelection.Max() = 0;
619cdf0e10cSrcweir else if ( aNewSelection.Max() > aText.Len() )
620cdf0e10cSrcweir aNewSelection.Max() = aText.Len();
621cdf0e10cSrcweir
622cdf0e10cSrcweir long nEnd = Max( aNewSelection.Min(), aNewSelection.Max() );
623cdf0e10cSrcweir TextSelection aTextSel;
624cdf0e10cSrcweir sal_uLong nPara = 0;
625cdf0e10cSrcweir sal_uInt16 nChar = 0;
626cdf0e10cSrcweir sal_uInt16 x = 0;
627cdf0e10cSrcweir while ( x <= nEnd )
628cdf0e10cSrcweir {
629cdf0e10cSrcweir if ( x == aNewSelection.Min() )
630cdf0e10cSrcweir aTextSel.GetStart() = TextPaM( nPara, nChar );
631cdf0e10cSrcweir if ( x == aNewSelection.Max() )
632cdf0e10cSrcweir aTextSel.GetEnd() = TextPaM( nPara, nChar );
633cdf0e10cSrcweir
634cdf0e10cSrcweir if ( ( x < aText.Len() ) && ( aText.GetChar( x ) == '\n' ) )
635cdf0e10cSrcweir {
636cdf0e10cSrcweir nPara++;
637cdf0e10cSrcweir nChar = 0;
638cdf0e10cSrcweir }
639cdf0e10cSrcweir else
640cdf0e10cSrcweir nChar++;
641cdf0e10cSrcweir x++;
642cdf0e10cSrcweir }
643cdf0e10cSrcweir mpTextWindow->GetTextView()->SetSelection( aTextSel );
644cdf0e10cSrcweir }
645cdf0e10cSrcweir
GetSelection() const646cdf0e10cSrcweir const Selection& ImpSvMEdit::GetSelection() const
647cdf0e10cSrcweir {
648cdf0e10cSrcweir maSelection = Selection();
649cdf0e10cSrcweir TextSelection aTextSel( mpTextWindow->GetTextView()->GetSelection() );
650cdf0e10cSrcweir aTextSel.Justify();
651cdf0e10cSrcweir // Selektion flachklopfen => jeder Umbruch ein Zeichen...
652cdf0e10cSrcweir
653cdf0e10cSrcweir ExtTextEngine* pExtTextEngine = mpTextWindow->GetTextEngine();
654cdf0e10cSrcweir // Absaetze davor:
655cdf0e10cSrcweir sal_uLong n;
656cdf0e10cSrcweir for ( n = 0; n < aTextSel.GetStart().GetPara(); n++ )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir maSelection.Min() += pExtTextEngine->GetTextLen( n );
659cdf0e10cSrcweir maSelection.Min()++;
660cdf0e10cSrcweir }
661cdf0e10cSrcweir
662cdf0e10cSrcweir // Erster Absatz mit Selektion:
663cdf0e10cSrcweir maSelection.Max() = maSelection.Min();
664cdf0e10cSrcweir maSelection.Min() += aTextSel.GetStart().GetIndex();
665cdf0e10cSrcweir
666cdf0e10cSrcweir for ( n = aTextSel.GetStart().GetPara(); n < aTextSel.GetEnd().GetPara(); n++ )
667cdf0e10cSrcweir {
668cdf0e10cSrcweir maSelection.Max() += pExtTextEngine->GetTextLen( n );
669cdf0e10cSrcweir maSelection.Max()++;
670cdf0e10cSrcweir }
671cdf0e10cSrcweir
672cdf0e10cSrcweir maSelection.Max() += aTextSel.GetEnd().GetIndex();
673cdf0e10cSrcweir
674cdf0e10cSrcweir return maSelection;
675cdf0e10cSrcweir }
676cdf0e10cSrcweir
CalcMinimumSize() const677cdf0e10cSrcweir Size ImpSvMEdit::CalcMinimumSize() const
678cdf0e10cSrcweir {
679cdf0e10cSrcweir Size aSz( mpTextWindow->GetTextEngine()->CalcTextWidth(),
680cdf0e10cSrcweir mpTextWindow->GetTextEngine()->GetTextHeight() );
681cdf0e10cSrcweir
682cdf0e10cSrcweir if ( mpHScrollBar )
683cdf0e10cSrcweir aSz.Height() += mpHScrollBar->GetSizePixel().Height();
684cdf0e10cSrcweir if ( mpVScrollBar )
685cdf0e10cSrcweir aSz.Width() += mpVScrollBar->GetSizePixel().Width();
686cdf0e10cSrcweir
687cdf0e10cSrcweir return aSz;
688cdf0e10cSrcweir }
689cdf0e10cSrcweir
CalcSize(sal_uInt16 nColumns,sal_uInt16 nLines) const690cdf0e10cSrcweir Size ImpSvMEdit::CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const
691cdf0e10cSrcweir {
692cdf0e10cSrcweir static const sal_Unicode sampleText[] = { 'X', '\0' };
693cdf0e10cSrcweir
694cdf0e10cSrcweir Size aSz;
695cdf0e10cSrcweir Size aCharSz;
696cdf0e10cSrcweir aCharSz.Width() = mpTextWindow->GetTextWidth( sampleText );
697cdf0e10cSrcweir aCharSz.Height() = mpTextWindow->GetTextHeight();
698cdf0e10cSrcweir
699cdf0e10cSrcweir if ( nLines )
700cdf0e10cSrcweir aSz.Height() = nLines*aCharSz.Height();
701cdf0e10cSrcweir else
702cdf0e10cSrcweir aSz.Height() = mpTextWindow->GetTextEngine()->GetTextHeight();
703cdf0e10cSrcweir
704cdf0e10cSrcweir if ( nColumns )
705cdf0e10cSrcweir aSz.Width() = nColumns*aCharSz.Width();
706cdf0e10cSrcweir else
707cdf0e10cSrcweir aSz.Width() = mpTextWindow->GetTextEngine()->CalcTextWidth();
708cdf0e10cSrcweir
709cdf0e10cSrcweir if ( mpHScrollBar )
710cdf0e10cSrcweir aSz.Height() += mpHScrollBar->GetSizePixel().Height();
711cdf0e10cSrcweir if ( mpVScrollBar )
712cdf0e10cSrcweir aSz.Width() += mpVScrollBar->GetSizePixel().Width();
713cdf0e10cSrcweir
714cdf0e10cSrcweir return aSz;
715cdf0e10cSrcweir }
716cdf0e10cSrcweir
GetMaxVisColumnsAndLines(sal_uInt16 & rnCols,sal_uInt16 & rnLines) const717cdf0e10cSrcweir void ImpSvMEdit::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
718cdf0e10cSrcweir {
719cdf0e10cSrcweir static const sal_Unicode sampleText[] = { 'x', '\0' };
720cdf0e10cSrcweir Size aOutSz = mpTextWindow->GetOutputSizePixel();
721cdf0e10cSrcweir Size aCharSz( mpTextWindow->GetTextWidth( sampleText ), mpTextWindow->GetTextHeight() );
722cdf0e10cSrcweir rnCols = (sal_uInt16) (aOutSz.Width()/aCharSz.Width());
723cdf0e10cSrcweir rnLines = (sal_uInt16) (aOutSz.Height()/aCharSz.Height());
724cdf0e10cSrcweir }
725cdf0e10cSrcweir
Enable(sal_Bool bEnable)726cdf0e10cSrcweir void ImpSvMEdit::Enable( sal_Bool bEnable )
727cdf0e10cSrcweir {
728cdf0e10cSrcweir mpTextWindow->Enable( bEnable );
729cdf0e10cSrcweir if ( mpHScrollBar )
730cdf0e10cSrcweir mpHScrollBar->Enable( bEnable );
731cdf0e10cSrcweir if ( mpVScrollBar )
732cdf0e10cSrcweir mpVScrollBar->Enable( bEnable );
733cdf0e10cSrcweir }
734cdf0e10cSrcweir
HandleCommand(const CommandEvent & rCEvt)735cdf0e10cSrcweir sal_Bool ImpSvMEdit::HandleCommand( const CommandEvent& rCEvt )
736cdf0e10cSrcweir {
737cdf0e10cSrcweir sal_Bool bDone = sal_False;
738cdf0e10cSrcweir if ( ( rCEvt.GetCommand() == COMMAND_WHEEL ) ||
739cdf0e10cSrcweir ( rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL ) ||
740cdf0e10cSrcweir ( rCEvt.GetCommand() == COMMAND_AUTOSCROLL ) )
741cdf0e10cSrcweir {
742cdf0e10cSrcweir mpTextWindow->HandleScrollCommand( rCEvt, mpHScrollBar, mpVScrollBar );
743cdf0e10cSrcweir bDone = sal_True;
744cdf0e10cSrcweir }
745cdf0e10cSrcweir return bDone;
746cdf0e10cSrcweir }
747cdf0e10cSrcweir
748cdf0e10cSrcweir
TextWindow(Window * pParent)749cdf0e10cSrcweir TextWindow::TextWindow( Window* pParent ) : Window( pParent )
750cdf0e10cSrcweir {
751cdf0e10cSrcweir mbInMBDown = sal_False;
752cdf0e10cSrcweir mbSelectOnTab = sal_True;
753cdf0e10cSrcweir mbFocusSelectionHide = sal_False;
754cdf0e10cSrcweir mbIgnoreTab = sal_False;
755cdf0e10cSrcweir mbActivePopup = sal_False;
756cdf0e10cSrcweir mbSelectOnTab = sal_True;
757cdf0e10cSrcweir
758cdf0e10cSrcweir SetPointer( Pointer( POINTER_TEXT ) );
759cdf0e10cSrcweir
760cdf0e10cSrcweir mpExtTextEngine = new ExtTextEngine;
761cdf0e10cSrcweir mpExtTextEngine->SetMaxTextLen( STRING_MAXLEN );
762cdf0e10cSrcweir if( pParent->GetStyle() & WB_BORDER )
763cdf0e10cSrcweir mpExtTextEngine->SetLeftMargin( 2 );
764cdf0e10cSrcweir mpExtTextEngine->SetLocale( GetSettings().GetLocale() );
765cdf0e10cSrcweir mpExtTextView = new ExtTextView( mpExtTextEngine, this );
766cdf0e10cSrcweir mpExtTextEngine->InsertView( mpExtTextView );
767cdf0e10cSrcweir mpExtTextEngine->EnableUndo( sal_True );
768cdf0e10cSrcweir mpExtTextView->ShowCursor();
769cdf0e10cSrcweir
770cdf0e10cSrcweir Color aBackgroundColor = GetSettings().GetStyleSettings().GetWorkspaceColor();
771cdf0e10cSrcweir SetBackground( aBackgroundColor );
772cdf0e10cSrcweir pParent->SetBackground( aBackgroundColor );
773cdf0e10cSrcweir }
774cdf0e10cSrcweir
~TextWindow()775cdf0e10cSrcweir TextWindow::~TextWindow()
776cdf0e10cSrcweir {
777cdf0e10cSrcweir delete mpExtTextView;
778cdf0e10cSrcweir delete mpExtTextEngine;
779cdf0e10cSrcweir }
780cdf0e10cSrcweir
MouseMove(const MouseEvent & rMEvt)781cdf0e10cSrcweir void TextWindow::MouseMove( const MouseEvent& rMEvt )
782cdf0e10cSrcweir {
783cdf0e10cSrcweir mpExtTextView->MouseMove( rMEvt );
784cdf0e10cSrcweir Window::MouseMove( rMEvt );
785cdf0e10cSrcweir }
786cdf0e10cSrcweir
MouseButtonDown(const MouseEvent & rMEvt)787cdf0e10cSrcweir void TextWindow::MouseButtonDown( const MouseEvent& rMEvt )
788cdf0e10cSrcweir {
789cdf0e10cSrcweir mbInMBDown = sal_True; // Dann im GetFocus nicht alles selektieren wird
790cdf0e10cSrcweir mpExtTextView->MouseButtonDown( rMEvt );
791cdf0e10cSrcweir Window::MouseButtonDown( rMEvt );
792cdf0e10cSrcweir GrabFocus();
793cdf0e10cSrcweir mbInMBDown = sal_False;
794cdf0e10cSrcweir }
795cdf0e10cSrcweir
MouseButtonUp(const MouseEvent & rMEvt)796cdf0e10cSrcweir void TextWindow::MouseButtonUp( const MouseEvent& rMEvt )
797cdf0e10cSrcweir {
798cdf0e10cSrcweir mpExtTextView->MouseButtonUp( rMEvt );
799cdf0e10cSrcweir Window::MouseButtonUp( rMEvt );
800cdf0e10cSrcweir }
801cdf0e10cSrcweir
KeyInput(const KeyEvent & rKEvent)802cdf0e10cSrcweir void TextWindow::KeyInput( const KeyEvent& rKEvent )
803cdf0e10cSrcweir {
804cdf0e10cSrcweir sal_Bool bDone = sal_False;
805cdf0e10cSrcweir sal_uInt16 nCode = rKEvent.GetKeyCode().GetCode();
806cdf0e10cSrcweir if ( nCode == com::sun::star::awt::Key::SELECT_ALL ||
807cdf0e10cSrcweir ( (nCode == KEY_A) && rKEvent.GetKeyCode().IsMod1() && !rKEvent.GetKeyCode().IsMod2() )
808cdf0e10cSrcweir )
809cdf0e10cSrcweir {
810cdf0e10cSrcweir mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFF, 0xFFFF ) ) );
811cdf0e10cSrcweir bDone = sal_True;
812cdf0e10cSrcweir }
813cdf0e10cSrcweir else if ( (nCode == KEY_S) && rKEvent.GetKeyCode().IsShift() && rKEvent.GetKeyCode().IsMod1() )
814cdf0e10cSrcweir {
815cdf0e10cSrcweir if ( Edit::GetGetSpecialCharsFunction() )
816cdf0e10cSrcweir {
817cdf0e10cSrcweir // Damit die Selektion erhalten bleibt
818cdf0e10cSrcweir mbActivePopup = sal_True;
819cdf0e10cSrcweir XubString aChars = Edit::GetGetSpecialCharsFunction()( this, GetFont() );
820cdf0e10cSrcweir if ( aChars.Len() )
821cdf0e10cSrcweir {
822cdf0e10cSrcweir mpExtTextView->InsertText( aChars );
823cdf0e10cSrcweir mpExtTextView->GetTextEngine()->SetModified( sal_True );
824cdf0e10cSrcweir }
825cdf0e10cSrcweir mbActivePopup = sal_False;
826cdf0e10cSrcweir bDone = sal_True;
827cdf0e10cSrcweir }
828cdf0e10cSrcweir }
829cdf0e10cSrcweir else if ( nCode == KEY_TAB )
830cdf0e10cSrcweir {
831cdf0e10cSrcweir if ( !mbIgnoreTab || rKEvent.GetKeyCode().IsMod1() )
832cdf0e10cSrcweir bDone = mpExtTextView->KeyInput( rKEvent );
833cdf0e10cSrcweir }
834cdf0e10cSrcweir else
835cdf0e10cSrcweir {
836cdf0e10cSrcweir bDone = mpExtTextView->KeyInput( rKEvent );
837cdf0e10cSrcweir }
838cdf0e10cSrcweir
839cdf0e10cSrcweir if ( !bDone )
840cdf0e10cSrcweir Window::KeyInput( rKEvent );
841cdf0e10cSrcweir }
842cdf0e10cSrcweir
Paint(const Rectangle & rRect)843cdf0e10cSrcweir void TextWindow::Paint( const Rectangle& rRect )
844cdf0e10cSrcweir {
845cdf0e10cSrcweir mpExtTextView->Paint( rRect );
846cdf0e10cSrcweir }
847cdf0e10cSrcweir
Resize()848cdf0e10cSrcweir void TextWindow::Resize()
849cdf0e10cSrcweir {
850cdf0e10cSrcweir }
851cdf0e10cSrcweir
Command(const CommandEvent & rCEvt)852cdf0e10cSrcweir void TextWindow::Command( const CommandEvent& rCEvt )
853cdf0e10cSrcweir {
854cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir PopupMenu* pPopup = Edit::CreatePopupMenu();
857cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
858cdf0e10cSrcweir if ( rStyleSettings.GetOptions() & STYLE_OPTION_HIDEDISABLED )
859cdf0e10cSrcweir pPopup->SetMenuFlags( MENU_FLAG_HIDEDISABLEDENTRIES );
860cdf0e10cSrcweir if ( !mpExtTextView->HasSelection() )
861cdf0e10cSrcweir {
862cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_CUT, sal_False );
863cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_COPY, sal_False );
864cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_DELETE, sal_False );
865cdf0e10cSrcweir }
866cdf0e10cSrcweir if ( mpExtTextView->IsReadOnly() )
867cdf0e10cSrcweir {
868cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_CUT, sal_False );
869cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_PASTE, sal_False );
870cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_DELETE, sal_False );
871cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_INSERTSYMBOL, sal_False );
872cdf0e10cSrcweir }
873cdf0e10cSrcweir if ( !mpExtTextView->GetTextEngine()->HasUndoManager() || !mpExtTextView->GetTextEngine()->GetUndoManager().GetUndoActionCount() )
874cdf0e10cSrcweir {
875cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_UNDO, sal_False );
876cdf0e10cSrcweir }
877cdf0e10cSrcweir // if ( ( maSelection.Min() == 0 ) && ( maSelection.Max() == maText.Len() ) )
878cdf0e10cSrcweir // {
879cdf0e10cSrcweir // pPopup->EnableItem( SV_MENU_EDIT_SELECTALL, sal_False );
880cdf0e10cSrcweir // }
881cdf0e10cSrcweir if ( !Edit::GetGetSpecialCharsFunction() )
882cdf0e10cSrcweir {
883cdf0e10cSrcweir sal_uInt16 nPos = pPopup->GetItemPos( SV_MENU_EDIT_INSERTSYMBOL );
884cdf0e10cSrcweir pPopup->RemoveItem( nPos );
885cdf0e10cSrcweir pPopup->RemoveItem( nPos-1 );
886cdf0e10cSrcweir }
887cdf0e10cSrcweir
888cdf0e10cSrcweir mbActivePopup = sal_True;
889cdf0e10cSrcweir Point aPos = rCEvt.GetMousePosPixel();
890cdf0e10cSrcweir if ( !rCEvt.IsMouseEvent() )
891cdf0e10cSrcweir {
892cdf0e10cSrcweir // !!! Irgendwann einmal Menu zentriert in der Selektion anzeigen !!!
893cdf0e10cSrcweir Size aSize = GetOutputSizePixel();
894cdf0e10cSrcweir aPos = Point( aSize.Width()/2, aSize.Height()/2 );
895cdf0e10cSrcweir }
896cdf0e10cSrcweir // pPopup->RemoveDisabledEntries();
897cdf0e10cSrcweir sal_uInt16 n = pPopup->Execute( this, aPos );
898cdf0e10cSrcweir Edit::DeletePopupMenu( pPopup );
899cdf0e10cSrcweir switch ( n )
900cdf0e10cSrcweir {
901cdf0e10cSrcweir case SV_MENU_EDIT_UNDO: mpExtTextView->Undo();
902cdf0e10cSrcweir mpExtTextEngine->SetModified( sal_True );
903cdf0e10cSrcweir mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
904cdf0e10cSrcweir break;
905cdf0e10cSrcweir case SV_MENU_EDIT_CUT: mpExtTextView->Cut();
906cdf0e10cSrcweir mpExtTextEngine->SetModified( sal_True );
907cdf0e10cSrcweir mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
908cdf0e10cSrcweir break;
909cdf0e10cSrcweir case SV_MENU_EDIT_COPY: mpExtTextView->Copy();
910cdf0e10cSrcweir break;
911cdf0e10cSrcweir case SV_MENU_EDIT_PASTE: mpExtTextView->Paste();
912cdf0e10cSrcweir mpExtTextEngine->SetModified( sal_True );
913cdf0e10cSrcweir mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
914cdf0e10cSrcweir break;
915cdf0e10cSrcweir case SV_MENU_EDIT_DELETE: mpExtTextView->DeleteSelected();
916cdf0e10cSrcweir mpExtTextEngine->SetModified( sal_True );
917cdf0e10cSrcweir mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
918cdf0e10cSrcweir break;
919cdf0e10cSrcweir case SV_MENU_EDIT_SELECTALL: mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
920cdf0e10cSrcweir break;
921cdf0e10cSrcweir case SV_MENU_EDIT_INSERTSYMBOL:
922cdf0e10cSrcweir {
923cdf0e10cSrcweir XubString aChars = Edit::GetGetSpecialCharsFunction()( this, GetFont() );
924cdf0e10cSrcweir if ( aChars.Len() )
925cdf0e10cSrcweir {
926cdf0e10cSrcweir mpExtTextView->InsertText( aChars );
927cdf0e10cSrcweir mpExtTextEngine->SetModified( sal_True );
928cdf0e10cSrcweir mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
929cdf0e10cSrcweir }
930cdf0e10cSrcweir }
931cdf0e10cSrcweir break;
932cdf0e10cSrcweir }
933cdf0e10cSrcweir mbActivePopup = sal_False;
934cdf0e10cSrcweir }
935cdf0e10cSrcweir else
936cdf0e10cSrcweir {
937cdf0e10cSrcweir mpExtTextView->Command( rCEvt );
938cdf0e10cSrcweir }
939cdf0e10cSrcweir Window::Command( rCEvt );
940cdf0e10cSrcweir }
941cdf0e10cSrcweir
GetFocus()942cdf0e10cSrcweir void TextWindow::GetFocus()
943cdf0e10cSrcweir {
944*e8a7c477SOliver-Rainer Wittmann Window::GetFocus();
945*e8a7c477SOliver-Rainer Wittmann
946*e8a7c477SOliver-Rainer Wittmann if ( !mbActivePopup )
947*e8a7c477SOliver-Rainer Wittmann {
948*e8a7c477SOliver-Rainer Wittmann sal_Bool bGotoCursor = !mpExtTextView->IsReadOnly();
949*e8a7c477SOliver-Rainer Wittmann if ( mbFocusSelectionHide
950*e8a7c477SOliver-Rainer Wittmann && IsReallyVisible()
951*e8a7c477SOliver-Rainer Wittmann && !mpExtTextView->IsReadOnly()
952*e8a7c477SOliver-Rainer Wittmann && ( mbSelectOnTab
953*e8a7c477SOliver-Rainer Wittmann && ( !mbInMBDown
954*e8a7c477SOliver-Rainer Wittmann || ( GetSettings().GetStyleSettings().GetSelectionOptions() & SELECTION_OPTION_FOCUS ) ) ) )
955*e8a7c477SOliver-Rainer Wittmann {
956*e8a7c477SOliver-Rainer Wittmann // Alles selektieren, aber nicht scrollen
957*e8a7c477SOliver-Rainer Wittmann sal_Bool bAutoScroll = mpExtTextView->IsAutoScroll();
958*e8a7c477SOliver-Rainer Wittmann mpExtTextView->SetAutoScroll( sal_False );
959*e8a7c477SOliver-Rainer Wittmann mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFF, 0xFFFF ) ) );
960*e8a7c477SOliver-Rainer Wittmann mpExtTextView->SetAutoScroll( bAutoScroll );
961*e8a7c477SOliver-Rainer Wittmann bGotoCursor = sal_False;
962*e8a7c477SOliver-Rainer Wittmann }
963*e8a7c477SOliver-Rainer Wittmann mpExtTextView->SetPaintSelection( sal_True );
964*e8a7c477SOliver-Rainer Wittmann mpExtTextView->ShowCursor( bGotoCursor );
965*e8a7c477SOliver-Rainer Wittmann }
966cdf0e10cSrcweir }
967cdf0e10cSrcweir
968*e8a7c477SOliver-Rainer Wittmann
LoseFocus()969cdf0e10cSrcweir void TextWindow::LoseFocus()
970cdf0e10cSrcweir {
971*e8a7c477SOliver-Rainer Wittmann Window::LoseFocus();
972cdf0e10cSrcweir
973*e8a7c477SOliver-Rainer Wittmann if ( mbFocusSelectionHide && !mbActivePopup )
974*e8a7c477SOliver-Rainer Wittmann mpExtTextView->SetPaintSelection( sal_False );
975cdf0e10cSrcweir }
976cdf0e10cSrcweir
977*e8a7c477SOliver-Rainer Wittmann
978cdf0e10cSrcweir // virtual
979cdf0e10cSrcweir ::css::uno::Reference< ::css::awt::XWindowPeer >
GetComponentInterface(sal_Bool bCreate)980cdf0e10cSrcweir TextWindow::GetComponentInterface(sal_Bool bCreate)
981cdf0e10cSrcweir {
982cdf0e10cSrcweir ::css::uno::Reference< ::css::awt::XWindowPeer > xPeer(
983cdf0e10cSrcweir Window::GetComponentInterface(false));
984cdf0e10cSrcweir if (!xPeer.is() && bCreate)
985cdf0e10cSrcweir {
986cdf0e10cSrcweir xPeer = new ::svt::TextWindowPeer(*GetTextView(), true);
987cdf0e10cSrcweir SetComponentInterface(xPeer);
988cdf0e10cSrcweir }
989cdf0e10cSrcweir return xPeer;
990cdf0e10cSrcweir }
991cdf0e10cSrcweir
MultiLineEdit(Window * pParent,WinBits nWinStyle)992cdf0e10cSrcweir MultiLineEdit::MultiLineEdit( Window* pParent, WinBits nWinStyle )
993cdf0e10cSrcweir : Edit( pParent, nWinStyle )
994cdf0e10cSrcweir {
995cdf0e10cSrcweir SetType( WINDOW_MULTILINEEDIT );
996cdf0e10cSrcweir pImpSvMEdit = new ImpSvMEdit( this, nWinStyle );
997cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True );
998cdf0e10cSrcweir pUpdateDataTimer = 0;
999cdf0e10cSrcweir
1000cdf0e10cSrcweir SetCompoundControl( sal_True );
1001cdf0e10cSrcweir SetStyle( ImplInitStyle( nWinStyle ) );
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir
MultiLineEdit(Window * pParent,const ResId & rResId)1004cdf0e10cSrcweir MultiLineEdit::MultiLineEdit( Window* pParent, const ResId& rResId )
1005cdf0e10cSrcweir : Edit( pParent, rResId.SetRT( RSC_MULTILINEEDIT ) )
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir SetType( WINDOW_MULTILINEEDIT );
1008cdf0e10cSrcweir WinBits nWinStyle = rResId.GetWinBits();
1009cdf0e10cSrcweir pImpSvMEdit = new ImpSvMEdit( this, nWinStyle );
1010cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True );
1011cdf0e10cSrcweir pUpdateDataTimer = 0;
1012cdf0e10cSrcweir
1013cdf0e10cSrcweir sal_uInt16 nMaxLen = Edit::GetMaxTextLen();
1014cdf0e10cSrcweir if ( nMaxLen )
1015cdf0e10cSrcweir SetMaxTextLen( nMaxLen );
1016cdf0e10cSrcweir
1017cdf0e10cSrcweir SetText( Edit::GetText() );
1018cdf0e10cSrcweir
1019cdf0e10cSrcweir if ( IsVisible() )
1020cdf0e10cSrcweir pImpSvMEdit->Resize();
1021cdf0e10cSrcweir
1022cdf0e10cSrcweir SetCompoundControl( sal_True );
1023cdf0e10cSrcweir SetStyle( ImplInitStyle( nWinStyle ) );
1024cdf0e10cSrcweir
1025cdf0e10cSrcweir // Base Edit ctor could call Show already, but that would cause problems
1026cdf0e10cSrcweir // with accessibility, as Show might (indirectly) trigger a call to virtual
1027cdf0e10cSrcweir // GetComponentInterface, which is the Edit's base version instead of the
1028cdf0e10cSrcweir // MultiLineEdit's version while in the base Edit ctor:
1029cdf0e10cSrcweir if ((GetStyle() & WB_HIDE) == 0)
1030cdf0e10cSrcweir Show();
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir
~MultiLineEdit()1033cdf0e10cSrcweir MultiLineEdit::~MultiLineEdit()
1034cdf0e10cSrcweir {
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir ::std::auto_ptr< ImpSvMEdit > pDelete( pImpSvMEdit );
1037cdf0e10cSrcweir pImpSvMEdit = NULL;
1038cdf0e10cSrcweir }
1039cdf0e10cSrcweir delete pUpdateDataTimer;
1040cdf0e10cSrcweir }
1041cdf0e10cSrcweir
ImplInitStyle(WinBits nStyle)1042cdf0e10cSrcweir WinBits MultiLineEdit::ImplInitStyle( WinBits nStyle )
1043cdf0e10cSrcweir {
1044cdf0e10cSrcweir if ( !(nStyle & WB_NOTABSTOP) )
1045cdf0e10cSrcweir nStyle |= WB_TABSTOP;
1046cdf0e10cSrcweir
1047cdf0e10cSrcweir if ( !(nStyle & WB_NOGROUP) )
1048cdf0e10cSrcweir nStyle |= WB_GROUP;
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir if ( !(nStyle & WB_IGNORETAB ))
1051cdf0e10cSrcweir nStyle |= WINDOW_DLGCTRL_MOD1TAB;
1052cdf0e10cSrcweir
1053cdf0e10cSrcweir return nStyle;
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir
1056cdf0e10cSrcweir
ImplInitSettings(sal_Bool,sal_Bool,sal_Bool bBackground)1057cdf0e10cSrcweir void MultiLineEdit::ImplInitSettings( sal_Bool /*bFont*/, sal_Bool /*bForeground*/, sal_Bool bBackground )
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir // Der Font muss immer mit manipuliert werden, weil die TextEngine
1062cdf0e10cSrcweir // sich nicht um TextColor/Background kuemmert
1063cdf0e10cSrcweir
1064cdf0e10cSrcweir Color aTextColor = rStyleSettings.GetFieldTextColor();
1065cdf0e10cSrcweir if ( IsControlForeground() )
1066cdf0e10cSrcweir aTextColor = GetControlForeground();
1067cdf0e10cSrcweir if ( !IsEnabled() )
1068cdf0e10cSrcweir aTextColor = rStyleSettings.GetDisableColor();
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir Font aFont = rStyleSettings.GetFieldFont();
1071cdf0e10cSrcweir if ( IsControlFont() )
1072cdf0e10cSrcweir aFont.Merge( GetControlFont() );
1073cdf0e10cSrcweir aFont.SetTransparent( IsPaintTransparent() );
1074cdf0e10cSrcweir SetZoomedPointFont( aFont );
1075cdf0e10cSrcweir Font TheFont = GetFont();
1076cdf0e10cSrcweir TheFont.SetColor( aTextColor );
1077cdf0e10cSrcweir if( IsPaintTransparent() )
1078cdf0e10cSrcweir TheFont.SetFillColor( Color( COL_TRANSPARENT ) );
1079cdf0e10cSrcweir else
1080cdf0e10cSrcweir TheFont.SetFillColor( IsControlBackground() ? GetControlBackground() : rStyleSettings.GetFieldColor() );
1081cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetFont( TheFont );
1082cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->GetTextEngine()->SetFont( TheFont );
1083cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetTextColor( aTextColor );
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir if ( bBackground )
1086cdf0e10cSrcweir {
1087cdf0e10cSrcweir if( IsPaintTransparent() )
1088cdf0e10cSrcweir {
1089cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetPaintTransparent( sal_True );
1090cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetBackground();
1091cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetControlBackground();
1092cdf0e10cSrcweir SetBackground();
1093cdf0e10cSrcweir SetControlBackground();
1094cdf0e10cSrcweir }
1095cdf0e10cSrcweir else
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir if( IsControlBackground() )
1098cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetBackground( GetControlBackground() );
1099cdf0e10cSrcweir else
1100cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetBackground( rStyleSettings.GetFieldColor() );
1101cdf0e10cSrcweir // Auch am MultiLineEdit einstellen, weil die TextComponent
1102cdf0e10cSrcweir // ggf. die Scrollbars hidet.
1103cdf0e10cSrcweir SetBackground( pImpSvMEdit->GetTextWindow()->GetBackground() );
1104cdf0e10cSrcweir }
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir }
1107cdf0e10cSrcweir
Modify()1108cdf0e10cSrcweir void MultiLineEdit::Modify()
1109cdf0e10cSrcweir {
1110cdf0e10cSrcweir aModifyHdlLink.Call( this );
1111cdf0e10cSrcweir
1112cdf0e10cSrcweir CallEventListeners( VCLEVENT_EDIT_MODIFY );
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir if ( pUpdateDataTimer )
1115cdf0e10cSrcweir pUpdateDataTimer->Start();
1116cdf0e10cSrcweir }
1117cdf0e10cSrcweir
IMPL_LINK(MultiLineEdit,ImpUpdateDataHdl,Timer *,EMPTYARG)1118cdf0e10cSrcweir IMPL_LINK( MultiLineEdit, ImpUpdateDataHdl, Timer*, EMPTYARG )
1119cdf0e10cSrcweir {
1120cdf0e10cSrcweir UpdateData();
1121cdf0e10cSrcweir return 0;
1122cdf0e10cSrcweir }
1123cdf0e10cSrcweir
UpdateData()1124cdf0e10cSrcweir void MultiLineEdit::UpdateData()
1125cdf0e10cSrcweir {
1126cdf0e10cSrcweir aUpdateDataHdlLink.Call( this );
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir
SetModifyFlag()1129cdf0e10cSrcweir void MultiLineEdit::SetModifyFlag()
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir pImpSvMEdit->SetModified( sal_True );
1132cdf0e10cSrcweir }
1133cdf0e10cSrcweir
ClearModifyFlag()1134cdf0e10cSrcweir void MultiLineEdit::ClearModifyFlag()
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir pImpSvMEdit->SetModified( sal_False );
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir
IsModified() const1139cdf0e10cSrcweir sal_Bool MultiLineEdit::IsModified() const
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir return pImpSvMEdit->IsModified();
1142cdf0e10cSrcweir }
1143cdf0e10cSrcweir
EnableUpdateData(sal_uLong nTimeout)1144cdf0e10cSrcweir void MultiLineEdit::EnableUpdateData( sal_uLong nTimeout )
1145cdf0e10cSrcweir {
1146cdf0e10cSrcweir if ( !nTimeout )
1147cdf0e10cSrcweir DisableUpdateData();
1148cdf0e10cSrcweir else
1149cdf0e10cSrcweir {
1150cdf0e10cSrcweir if ( !pUpdateDataTimer )
1151cdf0e10cSrcweir {
1152cdf0e10cSrcweir pUpdateDataTimer = new Timer;
1153cdf0e10cSrcweir pUpdateDataTimer->SetTimeoutHdl( LINK( this, MultiLineEdit, ImpUpdateDataHdl ) );
1154cdf0e10cSrcweir }
1155cdf0e10cSrcweir pUpdateDataTimer->SetTimeout( nTimeout );
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir
SetReadOnly(sal_Bool bReadOnly)1159cdf0e10cSrcweir void MultiLineEdit::SetReadOnly( sal_Bool bReadOnly )
1160cdf0e10cSrcweir {
1161cdf0e10cSrcweir pImpSvMEdit->SetReadOnly( bReadOnly );
1162cdf0e10cSrcweir Edit::SetReadOnly( bReadOnly );
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir // #94921# ReadOnly can be overwritten in InitFromStyle() when WB not set.
1165cdf0e10cSrcweir WinBits nStyle = GetStyle();
1166cdf0e10cSrcweir if ( bReadOnly )
1167cdf0e10cSrcweir nStyle |= WB_READONLY;
1168cdf0e10cSrcweir else
1169cdf0e10cSrcweir nStyle &= ~WB_READONLY;
1170cdf0e10cSrcweir SetStyle( nStyle );
1171cdf0e10cSrcweir }
1172cdf0e10cSrcweir
IsReadOnly() const1173cdf0e10cSrcweir sal_Bool MultiLineEdit::IsReadOnly() const
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir return pImpSvMEdit->IsReadOnly();
1176cdf0e10cSrcweir }
1177cdf0e10cSrcweir
SetMaxTextLen(xub_StrLen nMaxLen)1178cdf0e10cSrcweir void MultiLineEdit::SetMaxTextLen( xub_StrLen nMaxLen )
1179cdf0e10cSrcweir {
1180cdf0e10cSrcweir pImpSvMEdit->SetMaxTextLen( nMaxLen );
1181cdf0e10cSrcweir }
1182cdf0e10cSrcweir
GetMaxTextLen() const1183cdf0e10cSrcweir xub_StrLen MultiLineEdit::GetMaxTextLen() const
1184cdf0e10cSrcweir {
1185cdf0e10cSrcweir return pImpSvMEdit->GetMaxTextLen();
1186cdf0e10cSrcweir }
1187cdf0e10cSrcweir
ReplaceSelected(const String & rStr)1188cdf0e10cSrcweir void MultiLineEdit::ReplaceSelected( const String& rStr )
1189cdf0e10cSrcweir {
1190cdf0e10cSrcweir pImpSvMEdit->InsertText( rStr );
1191cdf0e10cSrcweir }
1192cdf0e10cSrcweir
DeleteSelected()1193cdf0e10cSrcweir void MultiLineEdit::DeleteSelected()
1194cdf0e10cSrcweir {
1195cdf0e10cSrcweir pImpSvMEdit->InsertText( String() );
1196cdf0e10cSrcweir }
1197cdf0e10cSrcweir
GetSelected() const1198cdf0e10cSrcweir String MultiLineEdit::GetSelected() const
1199cdf0e10cSrcweir {
1200cdf0e10cSrcweir return pImpSvMEdit->GetSelected();
1201cdf0e10cSrcweir }
1202cdf0e10cSrcweir
GetSelected(LineEnd aSeparator) const1203cdf0e10cSrcweir String MultiLineEdit::GetSelected( LineEnd aSeparator ) const
1204cdf0e10cSrcweir {
1205cdf0e10cSrcweir return pImpSvMEdit->GetSelected( aSeparator );
1206cdf0e10cSrcweir }
1207cdf0e10cSrcweir
Cut()1208cdf0e10cSrcweir void MultiLineEdit::Cut()
1209cdf0e10cSrcweir {
1210cdf0e10cSrcweir pImpSvMEdit->Cut();
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir
Copy()1213cdf0e10cSrcweir void MultiLineEdit::Copy()
1214cdf0e10cSrcweir {
1215cdf0e10cSrcweir pImpSvMEdit->Copy();
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir
Paste()1218cdf0e10cSrcweir void MultiLineEdit::Paste()
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir pImpSvMEdit->Paste();
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir
SetText(const String & rStr)1223cdf0e10cSrcweir void MultiLineEdit::SetText( const String& rStr )
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir pImpSvMEdit->SetText( rStr );
1226cdf0e10cSrcweir }
1227cdf0e10cSrcweir
GetText() const1228cdf0e10cSrcweir String MultiLineEdit::GetText() const
1229cdf0e10cSrcweir {
1230cdf0e10cSrcweir return pImpSvMEdit->GetText();
1231cdf0e10cSrcweir }
1232cdf0e10cSrcweir
GetText(LineEnd aSeparator) const1233cdf0e10cSrcweir String MultiLineEdit::GetText( LineEnd aSeparator ) const
1234cdf0e10cSrcweir {
1235cdf0e10cSrcweir return pImpSvMEdit->GetText( aSeparator );
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir
GetTextLines() const1238cdf0e10cSrcweir String MultiLineEdit::GetTextLines() const
1239cdf0e10cSrcweir {
1240cdf0e10cSrcweir return pImpSvMEdit->GetTextLines();
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir
GetTextLines(LineEnd aSeparator) const1243cdf0e10cSrcweir String MultiLineEdit::GetTextLines( LineEnd aSeparator ) const
1244cdf0e10cSrcweir {
1245cdf0e10cSrcweir return pImpSvMEdit->GetTextLines( aSeparator );
1246cdf0e10cSrcweir }
1247cdf0e10cSrcweir
Resize()1248cdf0e10cSrcweir void MultiLineEdit::Resize()
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir pImpSvMEdit->Resize();
1251cdf0e10cSrcweir }
1252cdf0e10cSrcweir
GetFocus()1253cdf0e10cSrcweir void MultiLineEdit::GetFocus()
1254cdf0e10cSrcweir {
1255*e8a7c477SOliver-Rainer Wittmann if ( pImpSvMEdit == NULL ) // might be called from within the dtor, when pImpSvMEdit == NULL is a valid state
1256cdf0e10cSrcweir return;
1257*e8a7c477SOliver-Rainer Wittmann
1258*e8a7c477SOliver-Rainer Wittmann Edit::GetFocus();
1259*e8a7c477SOliver-Rainer Wittmann
1260cdf0e10cSrcweir pImpSvMEdit->GetFocus();
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir
1263*e8a7c477SOliver-Rainer Wittmann
SetSelection(const Selection & rSelection)1264cdf0e10cSrcweir void MultiLineEdit::SetSelection( const Selection& rSelection )
1265cdf0e10cSrcweir {
1266cdf0e10cSrcweir pImpSvMEdit->SetSelection( rSelection );
1267cdf0e10cSrcweir }
1268cdf0e10cSrcweir
GetSelection() const1269cdf0e10cSrcweir const Selection& MultiLineEdit::GetSelection() const
1270cdf0e10cSrcweir {
1271cdf0e10cSrcweir return pImpSvMEdit->GetSelection();
1272cdf0e10cSrcweir }
1273cdf0e10cSrcweir
CalcMinimumSize() const1274cdf0e10cSrcweir Size MultiLineEdit::CalcMinimumSize() const
1275cdf0e10cSrcweir {
1276cdf0e10cSrcweir Size aSz = pImpSvMEdit->CalcMinimumSize();
1277cdf0e10cSrcweir
1278cdf0e10cSrcweir sal_Int32 nLeft, nTop, nRight, nBottom;
1279cdf0e10cSrcweir ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
1280cdf0e10cSrcweir aSz.Width() += nLeft+nRight;
1281cdf0e10cSrcweir aSz.Height() += nTop+nBottom;
1282cdf0e10cSrcweir
1283cdf0e10cSrcweir return aSz;
1284cdf0e10cSrcweir }
1285cdf0e10cSrcweir
CalcAdjustedSize(const Size & rPrefSize) const1286cdf0e10cSrcweir Size MultiLineEdit::CalcAdjustedSize( const Size& rPrefSize ) const
1287cdf0e10cSrcweir {
1288cdf0e10cSrcweir Size aSz = rPrefSize;
1289cdf0e10cSrcweir sal_Int32 nLeft, nTop, nRight, nBottom;
1290cdf0e10cSrcweir ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
1291cdf0e10cSrcweir
1292cdf0e10cSrcweir // In der Hoehe auf ganze Zeilen justieren
1293cdf0e10cSrcweir
1294cdf0e10cSrcweir long nHeight = aSz.Height() - nTop - nBottom;
1295cdf0e10cSrcweir long nLineHeight = pImpSvMEdit->CalcSize( 1, 1 ).Height();
1296cdf0e10cSrcweir long nLines = nHeight / nLineHeight;
1297cdf0e10cSrcweir if ( nLines < 1 )
1298cdf0e10cSrcweir nLines = 1;
1299cdf0e10cSrcweir
1300cdf0e10cSrcweir aSz.Height() = nLines * nLineHeight;
1301cdf0e10cSrcweir aSz.Height() += nTop+nBottom;
1302cdf0e10cSrcweir
1303cdf0e10cSrcweir return aSz;
1304cdf0e10cSrcweir }
1305cdf0e10cSrcweir
CalcSize(sal_uInt16 nColumns,sal_uInt16 nLines) const1306cdf0e10cSrcweir Size MultiLineEdit::CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const
1307cdf0e10cSrcweir {
1308cdf0e10cSrcweir Size aSz = pImpSvMEdit->CalcSize( nColumns, nLines );
1309cdf0e10cSrcweir
1310cdf0e10cSrcweir sal_Int32 nLeft, nTop, nRight, nBottom;
1311cdf0e10cSrcweir ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
1312cdf0e10cSrcweir aSz.Width() += nLeft+nRight;
1313cdf0e10cSrcweir aSz.Height() += nTop+nBottom;
1314cdf0e10cSrcweir return aSz;
1315cdf0e10cSrcweir }
1316cdf0e10cSrcweir
GetMaxVisColumnsAndLines(sal_uInt16 & rnCols,sal_uInt16 & rnLines) const1317cdf0e10cSrcweir void MultiLineEdit::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
1318cdf0e10cSrcweir {
1319cdf0e10cSrcweir pImpSvMEdit->GetMaxVisColumnsAndLines( rnCols, rnLines );
1320cdf0e10cSrcweir }
1321cdf0e10cSrcweir
StateChanged(StateChangedType nType)1322cdf0e10cSrcweir void MultiLineEdit::StateChanged( StateChangedType nType )
1323cdf0e10cSrcweir {
1324cdf0e10cSrcweir if( nType == STATE_CHANGE_ENABLE )
1325cdf0e10cSrcweir {
1326cdf0e10cSrcweir pImpSvMEdit->Enable( IsEnabled() );
1327cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False );
1328cdf0e10cSrcweir }
1329cdf0e10cSrcweir else if( nType == STATE_CHANGE_READONLY )
1330cdf0e10cSrcweir {
1331cdf0e10cSrcweir pImpSvMEdit->SetReadOnly( IsReadOnly() );
1332cdf0e10cSrcweir }
1333cdf0e10cSrcweir else if ( nType == STATE_CHANGE_ZOOM )
1334cdf0e10cSrcweir {
1335cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetZoom( GetZoom() );
1336cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False );
1337cdf0e10cSrcweir Resize();
1338cdf0e10cSrcweir }
1339cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFONT )
1340cdf0e10cSrcweir {
1341cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False );
1342cdf0e10cSrcweir Resize();
1343cdf0e10cSrcweir Invalidate();
1344cdf0e10cSrcweir }
1345cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1346cdf0e10cSrcweir {
1347cdf0e10cSrcweir ImplInitSettings( sal_False, sal_True, sal_False );
1348cdf0e10cSrcweir Invalidate();
1349cdf0e10cSrcweir }
1350cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1351cdf0e10cSrcweir {
1352cdf0e10cSrcweir ImplInitSettings( sal_False, sal_False, sal_True );
1353cdf0e10cSrcweir Invalidate();
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir else if ( nType == STATE_CHANGE_STYLE )
1356cdf0e10cSrcweir {
1357cdf0e10cSrcweir pImpSvMEdit->InitFromStyle( GetStyle() );
1358cdf0e10cSrcweir SetStyle( ImplInitStyle( GetStyle() ) );
1359cdf0e10cSrcweir }
1360cdf0e10cSrcweir else if ( nType == STATE_CHANGE_INITSHOW )
1361cdf0e10cSrcweir {
1362cdf0e10cSrcweir if( IsPaintTransparent() )
1363cdf0e10cSrcweir {
1364cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetPaintTransparent( sal_True );
1365cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetBackground();
1366cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetControlBackground();
1367cdf0e10cSrcweir SetBackground();
1368cdf0e10cSrcweir SetControlBackground();
1369cdf0e10cSrcweir }
1370cdf0e10cSrcweir }
1371cdf0e10cSrcweir
1372cdf0e10cSrcweir Control::StateChanged( nType );
1373cdf0e10cSrcweir }
1374cdf0e10cSrcweir
DataChanged(const DataChangedEvent & rDCEvt)1375cdf0e10cSrcweir void MultiLineEdit::DataChanged( const DataChangedEvent& rDCEvt )
1376cdf0e10cSrcweir {
1377cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1378cdf0e10cSrcweir (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1379cdf0e10cSrcweir {
1380cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True );
1381cdf0e10cSrcweir Resize();
1382cdf0e10cSrcweir Invalidate();
1383cdf0e10cSrcweir }
1384cdf0e10cSrcweir else
1385cdf0e10cSrcweir Control::DataChanged( rDCEvt );
1386cdf0e10cSrcweir }
1387cdf0e10cSrcweir
Draw(OutputDevice * pDev,const Point & rPos,const Size & rSize,sal_uLong nFlags)1388cdf0e10cSrcweir void MultiLineEdit::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
1389cdf0e10cSrcweir {
1390cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True );
1391cdf0e10cSrcweir
1392cdf0e10cSrcweir Point aPos = pDev->LogicToPixel( rPos );
1393cdf0e10cSrcweir Size aSize = pDev->LogicToPixel( rSize );
1394cdf0e10cSrcweir Font aFont = pImpSvMEdit->GetTextWindow()->GetDrawPixelFont( pDev );
1395cdf0e10cSrcweir aFont.SetTransparent( sal_True );
1396cdf0e10cSrcweir OutDevType eOutDevType = pDev->GetOutDevType();
1397cdf0e10cSrcweir
1398cdf0e10cSrcweir pDev->Push();
1399cdf0e10cSrcweir pDev->SetMapMode();
1400cdf0e10cSrcweir pDev->SetFont( aFont );
1401cdf0e10cSrcweir pDev->SetTextFillColor();
1402cdf0e10cSrcweir
1403cdf0e10cSrcweir // Border/Background
1404cdf0e10cSrcweir pDev->SetLineColor();
1405cdf0e10cSrcweir pDev->SetFillColor();
1406cdf0e10cSrcweir sal_Bool bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER);
1407cdf0e10cSrcweir sal_Bool bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground();
1408cdf0e10cSrcweir if ( bBorder || bBackground )
1409cdf0e10cSrcweir {
1410cdf0e10cSrcweir Rectangle aRect( aPos, aSize );
1411cdf0e10cSrcweir if ( bBorder )
1412cdf0e10cSrcweir {
1413cdf0e10cSrcweir DecorationView aDecoView( pDev );
1414cdf0e10cSrcweir aRect = aDecoView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN );
1415cdf0e10cSrcweir }
1416cdf0e10cSrcweir if ( bBackground )
1417cdf0e10cSrcweir {
1418cdf0e10cSrcweir pDev->SetFillColor( GetControlBackground() );
1419cdf0e10cSrcweir pDev->DrawRect( aRect );
1420cdf0e10cSrcweir }
1421cdf0e10cSrcweir }
1422cdf0e10cSrcweir
1423cdf0e10cSrcweir // Inhalt
1424cdf0e10cSrcweir if ( ( nFlags & WINDOW_DRAW_MONO ) || ( eOutDevType == OUTDEV_PRINTER ) )
1425cdf0e10cSrcweir pDev->SetTextColor( Color( COL_BLACK ) );
1426cdf0e10cSrcweir else
1427cdf0e10cSrcweir {
1428cdf0e10cSrcweir if ( !(nFlags & WINDOW_DRAW_NODISABLE ) && !IsEnabled() )
1429cdf0e10cSrcweir {
1430cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1431cdf0e10cSrcweir pDev->SetTextColor( rStyleSettings.GetDisableColor() );
1432cdf0e10cSrcweir }
1433cdf0e10cSrcweir else
1434cdf0e10cSrcweir {
1435cdf0e10cSrcweir pDev->SetTextColor( GetTextColor() );
1436cdf0e10cSrcweir }
1437cdf0e10cSrcweir }
1438cdf0e10cSrcweir
1439cdf0e10cSrcweir XubString aText = GetText();
1440cdf0e10cSrcweir Size aTextSz( pDev->GetTextWidth( aText ), pDev->GetTextHeight() );
1441cdf0e10cSrcweir sal_uLong nLines = (sal_uLong) (aSize.Height() / aTextSz.Height());
1442cdf0e10cSrcweir if ( !nLines )
1443cdf0e10cSrcweir nLines = 1;
1444cdf0e10cSrcweir aTextSz.Height() = nLines*aTextSz.Height();
1445cdf0e10cSrcweir long nOnePixel = GetDrawPixel( pDev, 1 );
1446cdf0e10cSrcweir long nOffX = 3*nOnePixel;
1447cdf0e10cSrcweir long nOffY = 2*nOnePixel;
1448cdf0e10cSrcweir
1449cdf0e10cSrcweir // Clipping?
1450cdf0e10cSrcweir if ( ( nOffY < 0 ) || ( (nOffY+aTextSz.Height()) > aSize.Height() ) || ( (nOffX+aTextSz.Width()) > aSize.Width() ) )
1451cdf0e10cSrcweir {
1452cdf0e10cSrcweir Rectangle aClip( aPos, aSize );
1453cdf0e10cSrcweir if ( aTextSz.Height() > aSize.Height() )
1454cdf0e10cSrcweir aClip.Bottom() += aTextSz.Height() - aSize.Height() + 1; // Damit HP-Drucker nicht 'weg-optimieren'
1455cdf0e10cSrcweir pDev->IntersectClipRegion( aClip );
1456cdf0e10cSrcweir }
1457cdf0e10cSrcweir
1458cdf0e10cSrcweir TextEngine aTE;
1459cdf0e10cSrcweir aTE.SetText( GetText() );
1460cdf0e10cSrcweir aTE.SetMaxTextWidth( aSize.Width() );
1461cdf0e10cSrcweir aTE.SetFont( aFont );
1462cdf0e10cSrcweir aTE.SetTextAlign( pImpSvMEdit->GetTextWindow()->GetTextEngine()->GetTextAlign() );
1463cdf0e10cSrcweir aTE.Draw( pDev, Point( aPos.X() + nOffX, aPos.Y() + nOffY ) );
1464cdf0e10cSrcweir
1465cdf0e10cSrcweir pDev->Pop();
1466cdf0e10cSrcweir }
1467cdf0e10cSrcweir
Notify(NotifyEvent & rNEvt)1468cdf0e10cSrcweir long MultiLineEdit::Notify( NotifyEvent& rNEvt )
1469cdf0e10cSrcweir {
1470cdf0e10cSrcweir long nDone = 0;
1471cdf0e10cSrcweir if( rNEvt.GetType() == EVENT_COMMAND )
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir nDone = pImpSvMEdit->HandleCommand( *rNEvt.GetCommandEvent() );
1474cdf0e10cSrcweir }
1475cdf0e10cSrcweir return nDone ? nDone : Edit::Notify( rNEvt );
1476cdf0e10cSrcweir }
1477cdf0e10cSrcweir
PreNotify(NotifyEvent & rNEvt)1478cdf0e10cSrcweir long MultiLineEdit::PreNotify( NotifyEvent& rNEvt )
1479cdf0e10cSrcweir {
1480cdf0e10cSrcweir long nDone = 0;
1481cdf0e10cSrcweir
1482cdf0e10cSrcweir #if (OSL_DEBUG_LEVEL > 1) && defined(DBG_UTIL)
1483cdf0e10cSrcweir if( rNEvt.GetType() == EVENT_KEYINPUT )
1484cdf0e10cSrcweir {
1485cdf0e10cSrcweir const KeyEvent& rKEvent = *rNEvt.GetKeyEvent();
1486cdf0e10cSrcweir if ( ( rKEvent.GetKeyCode().GetCode() == KEY_W ) && rKEvent.GetKeyCode().IsMod1() && rKEvent.GetKeyCode().IsMod2() )
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir SetRightToLeft( !IsRightToLeft() );
1489cdf0e10cSrcweir }
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir #endif
1492cdf0e10cSrcweir
1493cdf0e10cSrcweir if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && ( !GetTextView()->IsCursorEnabled() ) )
1494cdf0e10cSrcweir {
1495cdf0e10cSrcweir const KeyEvent& rKEvent = *rNEvt.GetKeyEvent();
1496cdf0e10cSrcweir if ( !rKEvent.GetKeyCode().IsShift() && ( rKEvent.GetKeyCode().GetGroup() == KEYGROUP_CURSOR ) )
1497cdf0e10cSrcweir {
1498cdf0e10cSrcweir nDone = 1;
1499cdf0e10cSrcweir TextSelection aSel = pImpSvMEdit->GetTextWindow()->GetTextView()->GetSelection();
1500cdf0e10cSrcweir if ( aSel.HasRange() )
1501cdf0e10cSrcweir {
1502cdf0e10cSrcweir aSel.GetStart() = aSel.GetEnd();
1503cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->GetTextView()->SetSelection( aSel );
1504cdf0e10cSrcweir }
1505cdf0e10cSrcweir else
1506cdf0e10cSrcweir {
1507cdf0e10cSrcweir switch ( rKEvent.GetKeyCode().GetCode() )
1508cdf0e10cSrcweir {
1509cdf0e10cSrcweir case KEY_UP:
1510cdf0e10cSrcweir {
1511cdf0e10cSrcweir if ( pImpSvMEdit->GetVScrollBar() )
1512cdf0e10cSrcweir pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_LINEUP );
1513cdf0e10cSrcweir }
1514cdf0e10cSrcweir break;
1515cdf0e10cSrcweir case KEY_DOWN:
1516cdf0e10cSrcweir {
1517cdf0e10cSrcweir if ( pImpSvMEdit->GetVScrollBar() )
1518cdf0e10cSrcweir pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_LINEDOWN );
1519cdf0e10cSrcweir }
1520cdf0e10cSrcweir break;
1521cdf0e10cSrcweir case KEY_PAGEUP :
1522cdf0e10cSrcweir {
1523cdf0e10cSrcweir if ( pImpSvMEdit->GetVScrollBar() )
1524cdf0e10cSrcweir pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_PAGEUP );
1525cdf0e10cSrcweir }
1526cdf0e10cSrcweir break;
1527cdf0e10cSrcweir case KEY_PAGEDOWN:
1528cdf0e10cSrcweir {
1529cdf0e10cSrcweir if ( pImpSvMEdit->GetVScrollBar() )
1530cdf0e10cSrcweir pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_PAGEDOWN );
1531cdf0e10cSrcweir }
1532cdf0e10cSrcweir break;
1533cdf0e10cSrcweir case KEY_LEFT:
1534cdf0e10cSrcweir {
1535cdf0e10cSrcweir if ( pImpSvMEdit->GetHScrollBar() )
1536cdf0e10cSrcweir pImpSvMEdit->GetHScrollBar()->DoScrollAction( SCROLL_LINEUP );
1537cdf0e10cSrcweir }
1538cdf0e10cSrcweir break;
1539cdf0e10cSrcweir case KEY_RIGHT:
1540cdf0e10cSrcweir {
1541cdf0e10cSrcweir if ( pImpSvMEdit->GetHScrollBar() )
1542cdf0e10cSrcweir pImpSvMEdit->GetHScrollBar()->DoScrollAction( SCROLL_LINEDOWN );
1543cdf0e10cSrcweir }
1544cdf0e10cSrcweir break;
1545cdf0e10cSrcweir case KEY_HOME:
1546cdf0e10cSrcweir {
1547cdf0e10cSrcweir if ( rKEvent.GetKeyCode().IsMod1() )
1548cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->GetTextView()->
1549cdf0e10cSrcweir SetSelection( TextSelection( TextPaM( 0, 0 ) ) );
1550cdf0e10cSrcweir }
1551cdf0e10cSrcweir break;
1552cdf0e10cSrcweir case KEY_END:
1553cdf0e10cSrcweir {
1554cdf0e10cSrcweir if ( rKEvent.GetKeyCode().IsMod1() )
1555cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->GetTextView()->
1556cdf0e10cSrcweir SetSelection( TextSelection( TextPaM( 0xFFFF, 0xFFFF ) ) );
1557cdf0e10cSrcweir }
1558cdf0e10cSrcweir break;
1559cdf0e10cSrcweir default:
1560cdf0e10cSrcweir {
1561cdf0e10cSrcweir nDone = 0;
1562cdf0e10cSrcweir }
1563cdf0e10cSrcweir }
1564cdf0e10cSrcweir }
1565cdf0e10cSrcweir }
1566cdf0e10cSrcweir }
1567cdf0e10cSrcweir
1568cdf0e10cSrcweir return nDone ? nDone : Edit::PreNotify( rNEvt );
1569cdf0e10cSrcweir }
1570cdf0e10cSrcweir
1571cdf0e10cSrcweir //
1572cdf0e10cSrcweir // Internas fuer abgeleitete Klassen, z.B. TextComponent
1573cdf0e10cSrcweir
GetTextEngine() const1574cdf0e10cSrcweir ExtTextEngine* MultiLineEdit::GetTextEngine() const
1575cdf0e10cSrcweir {
1576cdf0e10cSrcweir return pImpSvMEdit->GetTextWindow()->GetTextEngine();
1577cdf0e10cSrcweir }
1578cdf0e10cSrcweir
GetTextView() const1579cdf0e10cSrcweir ExtTextView* MultiLineEdit::GetTextView() const
1580cdf0e10cSrcweir {
1581cdf0e10cSrcweir return pImpSvMEdit->GetTextWindow()->GetTextView();
1582cdf0e10cSrcweir }
1583cdf0e10cSrcweir
GetHScrollBar() const1584cdf0e10cSrcweir ScrollBar* MultiLineEdit::GetHScrollBar() const
1585cdf0e10cSrcweir {
1586cdf0e10cSrcweir return pImpSvMEdit->GetHScrollBar();
1587cdf0e10cSrcweir }
1588cdf0e10cSrcweir
1589cdf0e10cSrcweir
GetVScrollBar() const1590cdf0e10cSrcweir ScrollBar* MultiLineEdit::GetVScrollBar() const
1591cdf0e10cSrcweir {
1592cdf0e10cSrcweir return pImpSvMEdit->GetVScrollBar();
1593cdf0e10cSrcweir }
1594cdf0e10cSrcweir
EnableFocusSelectionHide(sal_Bool bHide)1595cdf0e10cSrcweir void MultiLineEdit::EnableFocusSelectionHide( sal_Bool bHide )
1596cdf0e10cSrcweir {
1597cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->SetAutoFocusHide( bHide );
1598cdf0e10cSrcweir }
1599cdf0e10cSrcweir
IsFocusSelectionHideEnabled() const1600cdf0e10cSrcweir sal_Bool MultiLineEdit::IsFocusSelectionHideEnabled() const
1601cdf0e10cSrcweir {
1602cdf0e10cSrcweir return pImpSvMEdit->GetTextWindow()->IsAutoFocusHide();
1603cdf0e10cSrcweir }
1604cdf0e10cSrcweir
1605cdf0e10cSrcweir
SetLeftMargin(sal_uInt16 n)1606cdf0e10cSrcweir void MultiLineEdit::SetLeftMargin( sal_uInt16 n )
1607cdf0e10cSrcweir {
1608cdf0e10cSrcweir if ( GetTextEngine() )
1609cdf0e10cSrcweir GetTextEngine()->SetLeftMargin( n );
1610cdf0e10cSrcweir }
1611cdf0e10cSrcweir
GetLeftMargin() const1612cdf0e10cSrcweir sal_uInt16 MultiLineEdit::GetLeftMargin() const
1613cdf0e10cSrcweir {
1614cdf0e10cSrcweir if ( GetTextEngine() )
1615cdf0e10cSrcweir return GetTextEngine()->GetLeftMargin();
1616cdf0e10cSrcweir else
1617cdf0e10cSrcweir return 0;
1618cdf0e10cSrcweir }
1619cdf0e10cSrcweir
SetRightToLeft(sal_Bool bRightToLeft)1620cdf0e10cSrcweir void MultiLineEdit::SetRightToLeft( sal_Bool bRightToLeft )
1621cdf0e10cSrcweir {
1622cdf0e10cSrcweir if ( GetTextEngine() )
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir GetTextEngine()->SetRightToLeft( bRightToLeft );
1625cdf0e10cSrcweir GetTextView()->ShowCursor();
1626cdf0e10cSrcweir }
1627cdf0e10cSrcweir }
1628cdf0e10cSrcweir
IsRightToLeft() const1629cdf0e10cSrcweir sal_Bool MultiLineEdit::IsRightToLeft() const
1630cdf0e10cSrcweir {
1631cdf0e10cSrcweir sal_Bool bRightToLeft = sal_False;
1632cdf0e10cSrcweir
1633cdf0e10cSrcweir if ( GetTextEngine() )
1634cdf0e10cSrcweir bRightToLeft = GetTextEngine()->IsRightToLeft();
1635cdf0e10cSrcweir
1636cdf0e10cSrcweir return bRightToLeft;
1637cdf0e10cSrcweir }
1638cdf0e10cSrcweir
1639cdf0e10cSrcweir // virtual
1640cdf0e10cSrcweir ::css::uno::Reference< ::css::awt::XWindowPeer >
GetComponentInterface(sal_Bool bCreate)1641cdf0e10cSrcweir MultiLineEdit::GetComponentInterface(sal_Bool bCreate)
1642cdf0e10cSrcweir {
1643cdf0e10cSrcweir ::css::uno::Reference< ::css::awt::XWindowPeer > xPeer(
1644cdf0e10cSrcweir Edit::GetComponentInterface(false));
1645cdf0e10cSrcweir if (!xPeer.is() && bCreate)
1646cdf0e10cSrcweir {
1647cdf0e10cSrcweir ::std::auto_ptr< VCLXMultiLineEdit > xEdit(new VCLXMultiLineEdit());
1648cdf0e10cSrcweir xEdit->SetWindow(this);
1649cdf0e10cSrcweir xPeer = xEdit.release();
1650cdf0e10cSrcweir SetComponentInterface(xPeer);
1651cdf0e10cSrcweir }
1652cdf0e10cSrcweir return xPeer;
1653cdf0e10cSrcweir }
1654cdf0e10cSrcweir /*-- 11.08.2004 11:29:23---------------------------------------------------
1655cdf0e10cSrcweir
1656cdf0e10cSrcweir -----------------------------------------------------------------------*/
DisableSelectionOnFocus()1657cdf0e10cSrcweir void MultiLineEdit::DisableSelectionOnFocus()
1658cdf0e10cSrcweir {
1659cdf0e10cSrcweir pImpSvMEdit->GetTextWindow()->DisableSelectionOnFocus();
1660cdf0e10cSrcweir }
1661