1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <tools/rc.h> 28cdf0e10cSrcweir #include <vcl/decoview.hxx> 29cdf0e10cSrcweir #include <vcl/event.hxx> 30cdf0e10cSrcweir #include <vcl/cursor.hxx> 31cdf0e10cSrcweir #include <vcl/virdev.hxx> 32cdf0e10cSrcweir #include <vcl/menu.hxx> 33cdf0e10cSrcweir #include <vcl/cmdevt.h> 34cdf0e10cSrcweir #include <vcl/edit.hxx> 35cdf0e10cSrcweir #include <vcl/svapp.hxx> 36cdf0e10cSrcweir #include <vcl/msgbox.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <window.h> 39cdf0e10cSrcweir #include <svdata.hxx> 40cdf0e10cSrcweir #include <svids.hrc> 41cdf0e10cSrcweir #include <subedit.hxx> 42cdf0e10cSrcweir #include <controldata.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <vos/mutex.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp> 48cdf0e10cSrcweir #include <com/sun/star/i18n/CharacterIteratorMode.hpp> 49cdf0e10cSrcweir #include <com/sun/star/i18n/WordType.hpp> 50cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 51cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp> 52cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 53cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 54cdf0e10cSrcweir 55cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DATATRANSFER_DND_DNDCONSTANS_HPP_ 56cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> 57cdf0e10cSrcweir #endif 58cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp> 59cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> 60cdf0e10cSrcweir 61cdf0e10cSrcweir #ifndef _COM_SUN_STAR_I18N_XEXTENDEDINPUTSEQUENCECHECKER_HDL_ 62cdf0e10cSrcweir #include <com/sun/star/i18n/XExtendedInputSequenceChecker.hpp> 63cdf0e10cSrcweir #endif 64cdf0e10cSrcweir #include <com/sun/star/i18n/InputSequenceCheckMode.hpp> 65cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hpp> 66cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 67cdf0e10cSrcweir 68cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 69cdf0e10cSrcweir 70cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 71cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 72cdf0e10cSrcweir 73cdf0e10cSrcweir #include <sot/exchange.hxx> 74cdf0e10cSrcweir #include <sot/formats.hxx> 75cdf0e10cSrcweir #include <rtl/memory.h> 76cdf0e10cSrcweir 77cdf0e10cSrcweir #include <vcl/unohelp.hxx> 78cdf0e10cSrcweir #include <vcl/unohelp2.hxx> 79cdf0e10cSrcweir 80cdf0e10cSrcweir 81cdf0e10cSrcweir 82cdf0e10cSrcweir 83cdf0e10cSrcweir using namespace ::com::sun::star; 84cdf0e10cSrcweir using namespace ::com::sun::star::uno; 85cdf0e10cSrcweir using namespace ::com::sun::star::lang; 86cdf0e10cSrcweir using namespace ::rtl; 87cdf0e10cSrcweir 88cdf0e10cSrcweir // - Redo 89cdf0e10cSrcweir // - Bei Tracking-Cancel DefaultSelection wieder herstellen 90cdf0e10cSrcweir 91cdf0e10cSrcweir // ======================================================================= 92cdf0e10cSrcweir 93cdf0e10cSrcweir static FncGetSpecialChars pImplFncGetSpecialChars = NULL; 94cdf0e10cSrcweir 95cdf0e10cSrcweir // ======================================================================= 96cdf0e10cSrcweir 97cdf0e10cSrcweir #define EDIT_ALIGN_LEFT 1 98cdf0e10cSrcweir #define EDIT_ALIGN_CENTER 2 99cdf0e10cSrcweir #define EDIT_ALIGN_RIGHT 3 100cdf0e10cSrcweir 101cdf0e10cSrcweir #define EDIT_DEL_LEFT 1 102cdf0e10cSrcweir #define EDIT_DEL_RIGHT 2 103cdf0e10cSrcweir 104cdf0e10cSrcweir #define EDIT_DELMODE_SIMPLE 11 105cdf0e10cSrcweir #define EDIT_DELMODE_RESTOFWORD 12 106cdf0e10cSrcweir #define EDIT_DELMODE_RESTOFCONTENT 13 107cdf0e10cSrcweir 108cdf0e10cSrcweir // ======================================================================= 109cdf0e10cSrcweir 110cdf0e10cSrcweir struct DDInfo 111cdf0e10cSrcweir { 112cdf0e10cSrcweir Cursor aCursor; 113cdf0e10cSrcweir Selection aDndStartSel; 114cdf0e10cSrcweir xub_StrLen nDropPos; 115cdf0e10cSrcweir sal_Bool bStarterOfDD; 116cdf0e10cSrcweir sal_Bool bDroppedInMe; 117cdf0e10cSrcweir sal_Bool bVisCursor; 118cdf0e10cSrcweir sal_Bool bIsStringSupported; 119cdf0e10cSrcweir 120cdf0e10cSrcweir DDInfo() 121cdf0e10cSrcweir { 122cdf0e10cSrcweir aCursor.SetStyle( CURSOR_SHADOW ); 123cdf0e10cSrcweir nDropPos = 0; 124cdf0e10cSrcweir bStarterOfDD = sal_False; 125cdf0e10cSrcweir bDroppedInMe = sal_False; 126cdf0e10cSrcweir bVisCursor = sal_False; 127cdf0e10cSrcweir bIsStringSupported = sal_False; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir }; 130cdf0e10cSrcweir 131cdf0e10cSrcweir // ======================================================================= 132cdf0e10cSrcweir 133cdf0e10cSrcweir struct Impl_IMEInfos 134cdf0e10cSrcweir { 135cdf0e10cSrcweir String aOldTextAfterStartPos; 136cdf0e10cSrcweir sal_uInt16* pAttribs; 137cdf0e10cSrcweir xub_StrLen nPos; 138cdf0e10cSrcweir xub_StrLen nLen; 139cdf0e10cSrcweir sal_Bool bCursor; 140cdf0e10cSrcweir sal_Bool bWasCursorOverwrite; 141cdf0e10cSrcweir 142cdf0e10cSrcweir Impl_IMEInfos( xub_StrLen nPos, const String& rOldTextAfterStartPos ); 143cdf0e10cSrcweir ~Impl_IMEInfos(); 144cdf0e10cSrcweir 145cdf0e10cSrcweir void CopyAttribs( const xub_StrLen* pA, xub_StrLen nL ); 146cdf0e10cSrcweir void DestroyAttribs(); 147cdf0e10cSrcweir }; 148cdf0e10cSrcweir 149cdf0e10cSrcweir // ----------------------------------------------------------------------- 150cdf0e10cSrcweir 151cdf0e10cSrcweir Impl_IMEInfos::Impl_IMEInfos( xub_StrLen nP, const String& rOldTextAfterStartPos ) 152cdf0e10cSrcweir : aOldTextAfterStartPos( rOldTextAfterStartPos ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir nPos = nP; 155cdf0e10cSrcweir nLen = 0; 156cdf0e10cSrcweir bCursor = sal_True; 157cdf0e10cSrcweir pAttribs = NULL; 158cdf0e10cSrcweir bWasCursorOverwrite = sal_False; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir // ----------------------------------------------------------------------- 162cdf0e10cSrcweir 163cdf0e10cSrcweir Impl_IMEInfos::~Impl_IMEInfos() 164cdf0e10cSrcweir { 165cdf0e10cSrcweir delete[] pAttribs; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir // ----------------------------------------------------------------------- 169cdf0e10cSrcweir 170cdf0e10cSrcweir void Impl_IMEInfos::CopyAttribs( const xub_StrLen* pA, xub_StrLen nL ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir nLen = nL; 173cdf0e10cSrcweir delete[] pAttribs; 174cdf0e10cSrcweir pAttribs = new sal_uInt16[ nL ]; 175cdf0e10cSrcweir rtl_copyMemory( pAttribs, pA, nL*sizeof(sal_uInt16) ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir // ----------------------------------------------------------------------- 179cdf0e10cSrcweir 180cdf0e10cSrcweir void Impl_IMEInfos::DestroyAttribs() 181cdf0e10cSrcweir { 182cdf0e10cSrcweir delete[] pAttribs; 183cdf0e10cSrcweir pAttribs = NULL; 184cdf0e10cSrcweir nLen = 0; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir // ======================================================================= 188cdf0e10cSrcweir 189cdf0e10cSrcweir Edit::Edit( WindowType nType ) : 190cdf0e10cSrcweir Control( nType ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir ImplInitEditData(); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir // ----------------------------------------------------------------------- 196cdf0e10cSrcweir 197cdf0e10cSrcweir Edit::Edit( Window* pParent, WinBits nStyle ) : 198cdf0e10cSrcweir Control( WINDOW_EDIT ) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir ImplInitEditData(); 201cdf0e10cSrcweir ImplInit( pParent, nStyle ); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir // ----------------------------------------------------------------------- 205cdf0e10cSrcweir 206cdf0e10cSrcweir Edit::Edit( Window* pParent, const ResId& rResId ) : 207cdf0e10cSrcweir Control( WINDOW_EDIT ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir ImplInitEditData(); 210cdf0e10cSrcweir rResId.SetRT( RSC_EDIT ); 211cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 212cdf0e10cSrcweir ImplInit( pParent, nStyle ); 213cdf0e10cSrcweir ImplLoadRes( rResId ); 214cdf0e10cSrcweir 215cdf0e10cSrcweir // Derived MultiLineEdit takes care to call Show only after MultiLineEdit 216cdf0e10cSrcweir // ctor has already started: 217cdf0e10cSrcweir if ( !(nStyle & WB_HIDE) && rResId.GetRT() != RSC_MULTILINEEDIT ) 218cdf0e10cSrcweir Show(); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir // ----------------------------------------------------------------------- 222cdf0e10cSrcweir 223cdf0e10cSrcweir Edit::Edit( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabeledByRelation ) : 224cdf0e10cSrcweir Control( WINDOW_EDIT ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir ImplInitEditData(); 227cdf0e10cSrcweir rResId.SetRT( RSC_EDIT ); 228cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 229cdf0e10cSrcweir ImplInit( pParent, nStyle ); 230cdf0e10cSrcweir ImplLoadRes( rResId ); 231cdf0e10cSrcweir if ( bDisableAccessibleLabeledByRelation ) 232cdf0e10cSrcweir ImplGetWindowImpl()->mbDisableAccessibleLabeledByRelation = sal_True; 233cdf0e10cSrcweir 234cdf0e10cSrcweir // Derived MultiLineEdit takes care to call Show only after MultiLineEdit 235cdf0e10cSrcweir // ctor has already started: 236cdf0e10cSrcweir if ( !(nStyle & WB_HIDE) && rResId.GetRT() != RSC_MULTILINEEDIT ) 237cdf0e10cSrcweir Show(); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir // ----------------------------------------------------------------------- 241cdf0e10cSrcweir 242cdf0e10cSrcweir Edit::~Edit() 243cdf0e10cSrcweir { 244cdf0e10cSrcweir delete mpDDInfo; 245cdf0e10cSrcweir Cursor* pCursor = GetCursor(); 246cdf0e10cSrcweir if ( pCursor ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir SetCursor( NULL ); 249cdf0e10cSrcweir delete pCursor; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir delete mpIMEInfos; 253cdf0e10cSrcweir 254cdf0e10cSrcweir if ( mpUpdateDataTimer ) 255cdf0e10cSrcweir delete mpUpdateDataTimer; 256cdf0e10cSrcweir 257cdf0e10cSrcweir if ( mxDnDListener.is() ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir if ( GetDragGestureRecognizer().is() ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir uno::Reference< datatransfer::dnd::XDragGestureListener> xDGL( mxDnDListener, uno::UNO_QUERY ); 262cdf0e10cSrcweir GetDragGestureRecognizer()->removeDragGestureListener( xDGL ); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir if ( GetDropTarget().is() ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir uno::Reference< datatransfer::dnd::XDropTargetListener> xDTL( mxDnDListener, uno::UNO_QUERY ); 267cdf0e10cSrcweir GetDropTarget()->removeDropTargetListener( xDTL ); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir uno::Reference< lang::XEventListener> xEL( mxDnDListener, uno::UNO_QUERY ); 271cdf0e10cSrcweir xEL->disposing( lang::EventObject() ); // #95154# #96585# Empty Source means it's the Client 272cdf0e10cSrcweir } 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir // ----------------------------------------------------------------------- 276cdf0e10cSrcweir 277cdf0e10cSrcweir void Edit::ImplInitEditData() 278cdf0e10cSrcweir { 279cdf0e10cSrcweir mpSubEdit = NULL; 280cdf0e10cSrcweir mpUpdateDataTimer = NULL; 281cdf0e10cSrcweir mnXOffset = 0; 282cdf0e10cSrcweir mnAlign = EDIT_ALIGN_LEFT; 283cdf0e10cSrcweir mnMaxTextLen = EDIT_NOLIMIT; 284cdf0e10cSrcweir meAutocompleteAction = AUTOCOMPLETE_KEYINPUT; 285cdf0e10cSrcweir mbModified = sal_False; 286cdf0e10cSrcweir mbInternModified = sal_False; 287cdf0e10cSrcweir mbReadOnly = sal_False; 288cdf0e10cSrcweir mbInsertMode = sal_True; 289cdf0e10cSrcweir mbClickedInSelection = sal_False; 290cdf0e10cSrcweir mbActivePopup = sal_False; 291cdf0e10cSrcweir mbIsSubEdit = sal_False; 292cdf0e10cSrcweir mbInMBDown = sal_False; 293cdf0e10cSrcweir mpDDInfo = NULL; 294cdf0e10cSrcweir mpIMEInfos = NULL; 295cdf0e10cSrcweir mcEchoChar = 0; 296cdf0e10cSrcweir 297cdf0e10cSrcweir // --- RTL --- no default mirroring for Edit controls 298cdf0e10cSrcweir // note: controls that use a subedit will revert this (SpinField, ComboBox) 299cdf0e10cSrcweir EnableRTL( sal_False ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir vcl::unohelper::DragAndDropWrapper* pDnDWrapper = new vcl::unohelper::DragAndDropWrapper( this ); 302cdf0e10cSrcweir mxDnDListener = pDnDWrapper; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir // ----------------------------------------------------------------------- 306cdf0e10cSrcweir 307cdf0e10cSrcweir bool Edit::ImplUseNativeBorder( WinBits nStyle ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir bool bRet = 310cdf0e10cSrcweir IsNativeControlSupported(ImplGetNativeControlType(), HAS_BACKGROUND_TEXTURE) 311cdf0e10cSrcweir && ((nStyle&WB_BORDER) && !(nStyle&WB_NOBORDER)); 312cdf0e10cSrcweir if( ! bRet && mbIsSubEdit ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir Window* pWindow = GetParent(); 315cdf0e10cSrcweir nStyle = pWindow->GetStyle(); 316cdf0e10cSrcweir bRet = pWindow->IsNativeControlSupported(ImplGetNativeControlType(), HAS_BACKGROUND_TEXTURE) 317cdf0e10cSrcweir && ((nStyle&WB_BORDER) && !(nStyle&WB_NOBORDER)); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir return bRet; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir void Edit::ImplInit( Window* pParent, WinBits nStyle ) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir nStyle = ImplInitStyle( nStyle ); 325cdf0e10cSrcweir if ( !(nStyle & (WB_CENTER | WB_RIGHT)) ) 326cdf0e10cSrcweir nStyle |= WB_LEFT; 327cdf0e10cSrcweir 328cdf0e10cSrcweir Control::ImplInit( pParent, nStyle, NULL ); 329cdf0e10cSrcweir 330cdf0e10cSrcweir mbReadOnly = (nStyle & WB_READONLY) != 0; 331cdf0e10cSrcweir 332cdf0e10cSrcweir mnAlign = EDIT_ALIGN_LEFT; 333cdf0e10cSrcweir 334cdf0e10cSrcweir // --- RTL --- hack: right align until keyinput and cursor travelling works 335cdf0e10cSrcweir if( IsRTLEnabled() ) 336cdf0e10cSrcweir mnAlign = EDIT_ALIGN_RIGHT; 337cdf0e10cSrcweir 338cdf0e10cSrcweir if ( nStyle & WB_RIGHT ) 339cdf0e10cSrcweir mnAlign = EDIT_ALIGN_RIGHT; 340cdf0e10cSrcweir else if ( nStyle & WB_CENTER ) 341cdf0e10cSrcweir mnAlign = EDIT_ALIGN_CENTER; 342cdf0e10cSrcweir 343cdf0e10cSrcweir SetCursor( new Cursor ); 344cdf0e10cSrcweir 345cdf0e10cSrcweir SetPointer( Pointer( POINTER_TEXT ) ); 346cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True ); 347cdf0e10cSrcweir 348cdf0e10cSrcweir uno::Reference< datatransfer::dnd::XDragGestureListener> xDGL( mxDnDListener, uno::UNO_QUERY ); 349cdf0e10cSrcweir uno::Reference< datatransfer::dnd::XDragGestureRecognizer > xDGR = GetDragGestureRecognizer(); 350cdf0e10cSrcweir if ( xDGR.is() ) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir xDGR->addDragGestureListener( xDGL ); 353cdf0e10cSrcweir uno::Reference< datatransfer::dnd::XDropTargetListener> xDTL( mxDnDListener, uno::UNO_QUERY ); 354cdf0e10cSrcweir GetDropTarget()->addDropTargetListener( xDTL ); 355cdf0e10cSrcweir GetDropTarget()->setActive( sal_True ); 356cdf0e10cSrcweir GetDropTarget()->setDefaultActions( datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE ); 357cdf0e10cSrcweir } 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir // ----------------------------------------------------------------------- 361cdf0e10cSrcweir 362cdf0e10cSrcweir WinBits Edit::ImplInitStyle( WinBits nStyle ) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir if ( !(nStyle & WB_NOTABSTOP) ) 365cdf0e10cSrcweir nStyle |= WB_TABSTOP; 366cdf0e10cSrcweir if ( !(nStyle & WB_NOGROUP) ) 367cdf0e10cSrcweir nStyle |= WB_GROUP; 368cdf0e10cSrcweir 369cdf0e10cSrcweir return nStyle; 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir // ----------------------------------------------------------------------- 373cdf0e10cSrcweir 374cdf0e10cSrcweir sal_Bool Edit::IsCharInput( const KeyEvent& rKeyEvent ) 375cdf0e10cSrcweir { 376cdf0e10cSrcweir // In the future we must use new Unicode functions for this 377cdf0e10cSrcweir xub_Unicode cCharCode = rKeyEvent.GetCharCode(); 378cdf0e10cSrcweir return ((cCharCode >= 32) && (cCharCode != 127) && 379cdf0e10cSrcweir !rKeyEvent.GetKeyCode().IsMod3() && 380cdf0e10cSrcweir !rKeyEvent.GetKeyCode().IsMod2() && 381cdf0e10cSrcweir !rKeyEvent.GetKeyCode().IsMod1() ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir // ----------------------------------------------------------------------- 385cdf0e10cSrcweir 386cdf0e10cSrcweir void Edit::ImplModified() 387cdf0e10cSrcweir { 388cdf0e10cSrcweir mbModified = sal_True; 389cdf0e10cSrcweir Modify(); 390cdf0e10cSrcweir } 391cdf0e10cSrcweir 392cdf0e10cSrcweir // ----------------------------------------------------------------------- 393cdf0e10cSrcweir 394cdf0e10cSrcweir void Edit::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 397cdf0e10cSrcweir 398cdf0e10cSrcweir if ( bFont ) 399cdf0e10cSrcweir { 400cdf0e10cSrcweir Font aFont = rStyleSettings.GetFieldFont(); 401cdf0e10cSrcweir if ( IsControlFont() ) 402cdf0e10cSrcweir aFont.Merge( GetControlFont() ); 403cdf0e10cSrcweir SetZoomedPointFont( aFont ); 404cdf0e10cSrcweir ImplClearLayoutData(); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir 407cdf0e10cSrcweir if ( bFont || bForeground ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir Color aTextColor = rStyleSettings.GetFieldTextColor(); 410cdf0e10cSrcweir if ( IsControlForeground() ) 411cdf0e10cSrcweir aTextColor = GetControlForeground(); 412cdf0e10cSrcweir SetTextColor( aTextColor ); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir if ( bBackground ) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir if ( ImplUseNativeBorder( GetStyle() ) || IsPaintTransparent() ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir // Transparent background 420cdf0e10cSrcweir SetBackground(); 421cdf0e10cSrcweir SetFillColor(); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir else if ( IsControlBackground() ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir SetBackground( GetControlBackground() ); 426cdf0e10cSrcweir SetFillColor( GetControlBackground() ); 427cdf0e10cSrcweir } 428cdf0e10cSrcweir else 429cdf0e10cSrcweir { 430cdf0e10cSrcweir SetBackground( rStyleSettings.GetFieldColor() ); 431cdf0e10cSrcweir SetFillColor( rStyleSettings.GetFieldColor() ); 432cdf0e10cSrcweir } 433cdf0e10cSrcweir } 434cdf0e10cSrcweir } 435cdf0e10cSrcweir 436cdf0e10cSrcweir // ----------------------------------------------------------------------- 437cdf0e10cSrcweir 438cdf0e10cSrcweir long Edit::ImplGetExtraOffset() const 439cdf0e10cSrcweir { 440cdf0e10cSrcweir // MT 09/2002: nExtraOffsetX should become a member, instead of checking every time, 441cdf0e10cSrcweir // but I need an incompatible update for this... 442cdf0e10cSrcweir // #94095# Use extra offset only when edit has a border 443cdf0e10cSrcweir long nExtraOffset = 0; 444cdf0e10cSrcweir if( ( GetStyle() & WB_BORDER ) || ( mbIsSubEdit && ( GetParent()->GetStyle() & WB_BORDER ) ) ) 445cdf0e10cSrcweir nExtraOffset = 2; 446cdf0e10cSrcweir 447cdf0e10cSrcweir return nExtraOffset; 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir 451cdf0e10cSrcweir // ----------------------------------------------------------------------- 452cdf0e10cSrcweir 453cdf0e10cSrcweir XubString Edit::ImplGetText() const 454cdf0e10cSrcweir { 455cdf0e10cSrcweir if ( mcEchoChar || (GetStyle() & WB_PASSWORD) ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir XubString aText; 458cdf0e10cSrcweir xub_Unicode cEchoChar; 459cdf0e10cSrcweir if ( mcEchoChar ) 460cdf0e10cSrcweir cEchoChar = mcEchoChar; 461cdf0e10cSrcweir else 462cdf0e10cSrcweir cEchoChar = '*'; 463cdf0e10cSrcweir aText.Fill( maText.Len(), cEchoChar ); 464cdf0e10cSrcweir return aText; 465cdf0e10cSrcweir } 466cdf0e10cSrcweir else 467cdf0e10cSrcweir return maText; 468cdf0e10cSrcweir } 469cdf0e10cSrcweir 470cdf0e10cSrcweir // ----------------------------------------------------------------------- 471cdf0e10cSrcweir 472cdf0e10cSrcweir void Edit::ImplInvalidateOrRepaint( xub_StrLen nStart, xub_StrLen nEnd ) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir if( IsPaintTransparent() ) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir Invalidate(); 477cdf0e10cSrcweir // FIXME: this is currently only on aqua 478cdf0e10cSrcweir if( ImplGetSVData()->maNWFData.mbNoFocusRects ) 479cdf0e10cSrcweir Update(); 480cdf0e10cSrcweir } 481cdf0e10cSrcweir else 482cdf0e10cSrcweir ImplRepaint( nStart, nEnd ); 483cdf0e10cSrcweir } 484cdf0e10cSrcweir 485cdf0e10cSrcweir // ----------------------------------------------------------------------- 486cdf0e10cSrcweir 487cdf0e10cSrcweir long Edit::ImplGetTextYPosition() const 488cdf0e10cSrcweir { 489cdf0e10cSrcweir if ( GetStyle() & WB_TOP ) 490cdf0e10cSrcweir return ImplGetExtraOffset(); 491cdf0e10cSrcweir else if ( GetStyle() & WB_BOTTOM ) 492cdf0e10cSrcweir return GetOutputSizePixel().Height() - GetTextHeight() - ImplGetExtraOffset(); 493cdf0e10cSrcweir return ( GetOutputSizePixel().Height() - GetTextHeight() ) / 2; 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir // ----------------------------------------------------------------------- 497cdf0e10cSrcweir 498cdf0e10cSrcweir void Edit::ImplRepaint( xub_StrLen nStart, xub_StrLen nEnd, bool bLayout ) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir if ( !IsReallyVisible() ) 501cdf0e10cSrcweir return; 502cdf0e10cSrcweir 503cdf0e10cSrcweir XubString aText = ImplGetText(); 504cdf0e10cSrcweir nStart = 0; 505cdf0e10cSrcweir nEnd = aText.Len(); 506cdf0e10cSrcweir 507cdf0e10cSrcweir sal_Int32 nDXBuffer[256]; 508cdf0e10cSrcweir sal_Int32* pDXBuffer = NULL; 509cdf0e10cSrcweir sal_Int32* pDX = nDXBuffer; 510cdf0e10cSrcweir 511cdf0e10cSrcweir if( aText.Len() ) 512cdf0e10cSrcweir { 513cdf0e10cSrcweir if( 2*aText.Len() > xub_StrLen(sizeof(nDXBuffer)/sizeof(nDXBuffer[0])) ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir pDXBuffer = new sal_Int32[2*(aText.Len()+1)]; 516cdf0e10cSrcweir pDX = pDXBuffer; 517cdf0e10cSrcweir } 518cdf0e10cSrcweir 519cdf0e10cSrcweir GetCaretPositions( aText, pDX, nStart, nEnd ); 520cdf0e10cSrcweir } 521cdf0e10cSrcweir 522cdf0e10cSrcweir long nTH = GetTextHeight(); 523cdf0e10cSrcweir Point aPos( mnXOffset, ImplGetTextYPosition() ); 524cdf0e10cSrcweir 525cdf0e10cSrcweir if( bLayout ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir long nPos = nStart ? pDX[2*nStart] : 0; 528cdf0e10cSrcweir aPos.X() = nPos + mnXOffset + ImplGetExtraOffset(); 529cdf0e10cSrcweir 530cdf0e10cSrcweir MetricVector* pVector = &mpControlData->mpLayoutData->m_aUnicodeBoundRects; 531cdf0e10cSrcweir String* pDisplayText = &mpControlData->mpLayoutData->m_aDisplayText; 532cdf0e10cSrcweir 533cdf0e10cSrcweir DrawText( aPos, aText, nStart, nEnd - nStart, pVector, pDisplayText ); 534cdf0e10cSrcweir 535cdf0e10cSrcweir if( pDXBuffer ) 536cdf0e10cSrcweir delete [] pDXBuffer; 537cdf0e10cSrcweir return; 538cdf0e10cSrcweir } 539cdf0e10cSrcweir 540cdf0e10cSrcweir Cursor* pCursor = GetCursor(); 541cdf0e10cSrcweir sal_Bool bVisCursor = pCursor ? pCursor->IsVisible() : sal_False; 542cdf0e10cSrcweir if ( pCursor ) 543cdf0e10cSrcweir pCursor->Hide(); 544cdf0e10cSrcweir 545cdf0e10cSrcweir ImplClearBackground( 0, GetOutputSizePixel().Width() ); 546cdf0e10cSrcweir 547cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 548cdf0e10cSrcweir if ( IsEnabled() ) 549cdf0e10cSrcweir ImplInitSettings( sal_False, sal_True, sal_False ); 550cdf0e10cSrcweir else 551cdf0e10cSrcweir SetTextColor( rStyleSettings.GetDisableColor() ); 552cdf0e10cSrcweir 553cdf0e10cSrcweir // Set background color of the normal text 554cdf0e10cSrcweir if( (GetStyle() & WB_FORCECTRLBACKGROUND) != 0 && IsControlBackground() ) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir // check if we need to set ControlBackground even in NWF case 557cdf0e10cSrcweir Push( PUSH_FILLCOLOR | PUSH_LINECOLOR ); 558cdf0e10cSrcweir SetLineColor(); 559cdf0e10cSrcweir SetFillColor( GetControlBackground() ); 560cdf0e10cSrcweir DrawRect( Rectangle( aPos, Size( GetOutputSizePixel().Width() - 2*mnXOffset, nTH ) ) ); 561cdf0e10cSrcweir Pop(); 562cdf0e10cSrcweir 563cdf0e10cSrcweir SetTextFillColor( GetControlBackground() ); 564cdf0e10cSrcweir } 565cdf0e10cSrcweir else if( IsPaintTransparent() || ImplUseNativeBorder( GetStyle() ) ) 566cdf0e10cSrcweir SetTextFillColor(); 567cdf0e10cSrcweir else 568cdf0e10cSrcweir SetTextFillColor( IsControlBackground() ? GetControlBackground() : rStyleSettings.GetFieldColor() ); 569cdf0e10cSrcweir 570cdf0e10cSrcweir sal_Bool bDrawSelection = maSelection.Len() && ( HasFocus() || ( GetStyle() & WB_NOHIDESELECTION ) || mbActivePopup ); 571cdf0e10cSrcweir 572cdf0e10cSrcweir long nPos = nStart ? pDX[2*nStart] : 0; 573cdf0e10cSrcweir aPos.X() = nPos + mnXOffset + ImplGetExtraOffset(); 574cdf0e10cSrcweir if ( !bDrawSelection && !mpIMEInfos ) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir DrawText( aPos, aText, nStart, nEnd - nStart ); 577cdf0e10cSrcweir } 578cdf0e10cSrcweir else 579cdf0e10cSrcweir { 580cdf0e10cSrcweir // save graphics state 581cdf0e10cSrcweir Push(); 582cdf0e10cSrcweir // first calculate higlighted and non highlighted clip regions 583cdf0e10cSrcweir Region aHiglightClipRegion; 584cdf0e10cSrcweir Region aNormalClipRegion; 585cdf0e10cSrcweir Selection aTmpSel( maSelection ); 586cdf0e10cSrcweir aTmpSel.Justify(); 587cdf0e10cSrcweir // selection is highlighted 588cdf0e10cSrcweir int i; 589cdf0e10cSrcweir for( i = 0; i < aText.Len(); i++ ) 590cdf0e10cSrcweir { 591cdf0e10cSrcweir Rectangle aRect( aPos, Size( 10, nTH ) ); 592cdf0e10cSrcweir aRect.Left() = pDX[2*i] + mnXOffset + ImplGetExtraOffset(); 593cdf0e10cSrcweir aRect.Right() = pDX[2*i+1] + mnXOffset + ImplGetExtraOffset(); 594cdf0e10cSrcweir aRect.Justify(); 595cdf0e10cSrcweir bool bHighlight = false; 596cdf0e10cSrcweir if( i >= aTmpSel.Min() && i < aTmpSel.Max() ) 597cdf0e10cSrcweir bHighlight = true; 598cdf0e10cSrcweir 599cdf0e10cSrcweir if( mpIMEInfos && mpIMEInfos->pAttribs && 600cdf0e10cSrcweir i >= mpIMEInfos->nPos && i < (mpIMEInfos->nPos+mpIMEInfos->nLen ) && 601cdf0e10cSrcweir ( mpIMEInfos->pAttribs[i-mpIMEInfos->nPos] & EXTTEXTINPUT_ATTR_HIGHLIGHT) ) 602cdf0e10cSrcweir bHighlight = true; 603cdf0e10cSrcweir 604cdf0e10cSrcweir if( bHighlight ) 605cdf0e10cSrcweir aHiglightClipRegion.Union( aRect ); 606cdf0e10cSrcweir else 607cdf0e10cSrcweir aNormalClipRegion.Union( aRect ); 608cdf0e10cSrcweir } 609cdf0e10cSrcweir // draw normal text 610cdf0e10cSrcweir Color aNormalTextColor = GetTextColor(); 611cdf0e10cSrcweir SetClipRegion( aNormalClipRegion ); 612cdf0e10cSrcweir 613cdf0e10cSrcweir if( IsPaintTransparent() ) 614cdf0e10cSrcweir SetTextFillColor(); 615cdf0e10cSrcweir else 616cdf0e10cSrcweir { 617cdf0e10cSrcweir // Set background color when part of the text is selected 618cdf0e10cSrcweir if ( ImplUseNativeBorder( GetStyle() ) ) 619cdf0e10cSrcweir { 620cdf0e10cSrcweir if( (GetStyle() & WB_FORCECTRLBACKGROUND) != 0 && IsControlBackground() ) 621cdf0e10cSrcweir SetTextFillColor( GetControlBackground() ); 622cdf0e10cSrcweir else 623cdf0e10cSrcweir SetTextFillColor(); 624cdf0e10cSrcweir } 625cdf0e10cSrcweir else 626cdf0e10cSrcweir SetTextFillColor( IsControlBackground() ? GetControlBackground() : rStyleSettings.GetFieldColor() ); 627cdf0e10cSrcweir } 628cdf0e10cSrcweir DrawText( aPos, aText, nStart, nEnd - nStart ); 629cdf0e10cSrcweir 630cdf0e10cSrcweir // draw highlighted text 631cdf0e10cSrcweir SetClipRegion( aHiglightClipRegion ); 632cdf0e10cSrcweir SetTextColor( rStyleSettings.GetHighlightTextColor() ); 633cdf0e10cSrcweir SetTextFillColor( rStyleSettings.GetHighlightColor() ); 634cdf0e10cSrcweir DrawText( aPos, aText, nStart, nEnd - nStart ); 635cdf0e10cSrcweir 636cdf0e10cSrcweir // if IME info exists loop over portions and output different font attributes 637cdf0e10cSrcweir if( mpIMEInfos && mpIMEInfos->pAttribs ) 638cdf0e10cSrcweir { 639cdf0e10cSrcweir for( int n = 0; n < 2; n++ ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir Region aRegion; 642cdf0e10cSrcweir if( n == 0 ) 643cdf0e10cSrcweir { 644cdf0e10cSrcweir SetTextColor( aNormalTextColor ); 645cdf0e10cSrcweir if( IsPaintTransparent() ) 646cdf0e10cSrcweir SetTextFillColor(); 647cdf0e10cSrcweir else 648cdf0e10cSrcweir SetTextFillColor( IsControlBackground() ? GetControlBackground() : rStyleSettings.GetFieldColor() ); 649cdf0e10cSrcweir aRegion = aNormalClipRegion; 650cdf0e10cSrcweir } 651cdf0e10cSrcweir else 652cdf0e10cSrcweir { 653cdf0e10cSrcweir SetTextColor( rStyleSettings.GetHighlightTextColor() ); 654cdf0e10cSrcweir SetTextFillColor( rStyleSettings.GetHighlightColor() ); 655cdf0e10cSrcweir aRegion = aHiglightClipRegion; 656cdf0e10cSrcweir } 657cdf0e10cSrcweir 658cdf0e10cSrcweir for( i = 0; i < mpIMEInfos->nLen; ) 659cdf0e10cSrcweir { 660cdf0e10cSrcweir sal_uInt16 nAttr = mpIMEInfos->pAttribs[i]; 661cdf0e10cSrcweir Region aClip; 662cdf0e10cSrcweir int nIndex = i; 663cdf0e10cSrcweir while( nIndex < mpIMEInfos->nLen && mpIMEInfos->pAttribs[nIndex] == nAttr) // #112631# check nIndex before using it 664cdf0e10cSrcweir { 665cdf0e10cSrcweir Rectangle aRect( aPos, Size( 10, nTH ) ); 666cdf0e10cSrcweir aRect.Left() = pDX[2*(nIndex+mpIMEInfos->nPos)] + mnXOffset + ImplGetExtraOffset(); 667cdf0e10cSrcweir aRect.Right() = pDX[2*(nIndex+mpIMEInfos->nPos)+1] + mnXOffset + ImplGetExtraOffset(); 668cdf0e10cSrcweir aRect.Justify(); 669cdf0e10cSrcweir aClip.Union( aRect ); 670cdf0e10cSrcweir nIndex++; 671cdf0e10cSrcweir } 672cdf0e10cSrcweir i = nIndex; 673cdf0e10cSrcweir if( aClip.Intersect( aRegion ) && nAttr ) 674cdf0e10cSrcweir { 675cdf0e10cSrcweir Font aFont = GetFont(); 676cdf0e10cSrcweir if ( nAttr & EXTTEXTINPUT_ATTR_UNDERLINE ) 677cdf0e10cSrcweir aFont.SetUnderline( UNDERLINE_SINGLE ); 678cdf0e10cSrcweir else if ( nAttr & EXTTEXTINPUT_ATTR_BOLDUNDERLINE ) 679cdf0e10cSrcweir aFont.SetUnderline( UNDERLINE_BOLD ); 680cdf0e10cSrcweir else if ( nAttr & EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE ) 681cdf0e10cSrcweir aFont.SetUnderline( UNDERLINE_DOTTED ); 682cdf0e10cSrcweir else if ( nAttr & EXTTEXTINPUT_ATTR_DASHDOTUNDERLINE ) 683cdf0e10cSrcweir aFont.SetUnderline( UNDERLINE_DOTTED ); 684cdf0e10cSrcweir else if ( nAttr & EXTTEXTINPUT_ATTR_GRAYWAVELINE ) 685cdf0e10cSrcweir { 686cdf0e10cSrcweir aFont.SetUnderline( UNDERLINE_WAVE ); 687cdf0e10cSrcweir SetTextLineColor( Color( COL_LIGHTGRAY ) ); 688cdf0e10cSrcweir } 689cdf0e10cSrcweir SetFont( aFont ); 690cdf0e10cSrcweir 691cdf0e10cSrcweir if ( nAttr & EXTTEXTINPUT_ATTR_REDTEXT ) 692cdf0e10cSrcweir SetTextColor( Color( COL_RED ) ); 693cdf0e10cSrcweir else if ( nAttr & EXTTEXTINPUT_ATTR_HALFTONETEXT ) 694cdf0e10cSrcweir SetTextColor( Color( COL_LIGHTGRAY ) ); 695cdf0e10cSrcweir 696cdf0e10cSrcweir SetClipRegion( aClip ); 697cdf0e10cSrcweir DrawText( aPos, aText, nStart, nEnd - nStart ); 698cdf0e10cSrcweir } 699cdf0e10cSrcweir } 700cdf0e10cSrcweir } 701cdf0e10cSrcweir } 702cdf0e10cSrcweir 703cdf0e10cSrcweir // restore graphics state 704cdf0e10cSrcweir Pop(); 705cdf0e10cSrcweir } 706cdf0e10cSrcweir 707cdf0e10cSrcweir if ( bVisCursor && ( !mpIMEInfos || mpIMEInfos->bCursor ) ) 708cdf0e10cSrcweir pCursor->Show(); 709cdf0e10cSrcweir 710cdf0e10cSrcweir if( pDXBuffer ) 711cdf0e10cSrcweir delete [] pDXBuffer; 712cdf0e10cSrcweir } 713cdf0e10cSrcweir 714cdf0e10cSrcweir // ----------------------------------------------------------------------- 715cdf0e10cSrcweir 716cdf0e10cSrcweir void Edit::ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode ) 717cdf0e10cSrcweir { 718cdf0e10cSrcweir XubString aText = ImplGetText(); 719cdf0e10cSrcweir 720cdf0e10cSrcweir // loeschen moeglich? 721cdf0e10cSrcweir if ( !rSelection.Len() && 722cdf0e10cSrcweir (((rSelection.Min() == 0) && (nDirection == EDIT_DEL_LEFT)) || 723cdf0e10cSrcweir ((rSelection.Max() == aText.Len()) && (nDirection == EDIT_DEL_RIGHT))) ) 724cdf0e10cSrcweir return; 725cdf0e10cSrcweir 726cdf0e10cSrcweir ImplClearLayoutData(); 727cdf0e10cSrcweir 728cdf0e10cSrcweir Selection aSelection( rSelection ); 729cdf0e10cSrcweir aSelection.Justify(); 730cdf0e10cSrcweir 731cdf0e10cSrcweir if ( !aSelection.Len() ) 732cdf0e10cSrcweir { 733cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = ImplGetBreakIterator(); 734cdf0e10cSrcweir if ( nDirection == EDIT_DEL_LEFT ) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir if ( nMode == EDIT_DELMODE_RESTOFWORD ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->getWordBoundary( maText, aSelection.Min(), GetSettings().GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES, sal_True ); 739cdf0e10cSrcweir if ( aBoundary.startPos == aSelection.Min() ) 740cdf0e10cSrcweir aBoundary = xBI->previousWord( maText, aSelection.Min(), GetSettings().GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES ); 741cdf0e10cSrcweir aSelection.Min() = aBoundary.startPos; 742cdf0e10cSrcweir } 743cdf0e10cSrcweir else if ( nMode == EDIT_DELMODE_RESTOFCONTENT ) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir aSelection.Min() = 0; 746cdf0e10cSrcweir } 747cdf0e10cSrcweir else 748cdf0e10cSrcweir { 749cdf0e10cSrcweir sal_Int32 nCount = 1; 750cdf0e10cSrcweir aSelection.Min() = xBI->previousCharacters( maText, aSelection.Min(), GetSettings().GetLocale(), i18n::CharacterIteratorMode::SKIPCHARACTER, nCount, nCount ); 751cdf0e10cSrcweir } 752cdf0e10cSrcweir } 753cdf0e10cSrcweir else 754cdf0e10cSrcweir { 755cdf0e10cSrcweir if ( nMode == EDIT_DELMODE_RESTOFWORD ) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->nextWord( maText, aSelection.Max(), GetSettings().GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES ); 758cdf0e10cSrcweir aSelection.Max() = aBoundary.startPos; 759cdf0e10cSrcweir } 760cdf0e10cSrcweir else if ( nMode == EDIT_DELMODE_RESTOFCONTENT ) 761cdf0e10cSrcweir { 762cdf0e10cSrcweir aSelection.Max() = aText.Len(); 763cdf0e10cSrcweir } 764cdf0e10cSrcweir else 765cdf0e10cSrcweir { 766cdf0e10cSrcweir sal_Int32 nCount = 1; 767cdf0e10cSrcweir aSelection.Max() = xBI->nextCharacters( maText, aSelection.Max(), GetSettings().GetLocale(), i18n::CharacterIteratorMode::SKIPCHARACTER, nCount, nCount );; 768cdf0e10cSrcweir } 769cdf0e10cSrcweir } 770cdf0e10cSrcweir } 771cdf0e10cSrcweir 772cdf0e10cSrcweir maText.Erase( (xub_StrLen)aSelection.Min(), (xub_StrLen)aSelection.Len() ); 773cdf0e10cSrcweir maSelection.Min() = aSelection.Min(); 774cdf0e10cSrcweir maSelection.Max() = aSelection.Min(); 775cdf0e10cSrcweir ImplAlignAndPaint(); 776cdf0e10cSrcweir mbInternModified = sal_True; 777cdf0e10cSrcweir } 778cdf0e10cSrcweir 779cdf0e10cSrcweir // ----------------------------------------------------------------------- 780cdf0e10cSrcweir 781cdf0e10cSrcweir String Edit::ImplGetValidString( const String& rString ) const 782cdf0e10cSrcweir { 783cdf0e10cSrcweir String aValidString( rString ); 784cdf0e10cSrcweir aValidString.EraseAllChars( _LF ); 785cdf0e10cSrcweir aValidString.EraseAllChars( _CR ); 786cdf0e10cSrcweir aValidString.SearchAndReplaceAll( '\t', ' ' ); 787cdf0e10cSrcweir return aValidString; 788cdf0e10cSrcweir } 789cdf0e10cSrcweir 790cdf0e10cSrcweir // ----------------------------------------------------------------------- 791cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > Edit::ImplGetBreakIterator() const 792cdf0e10cSrcweir { 793cdf0e10cSrcweir //!! since we don't want to become incompatible in the next minor update 794cdf0e10cSrcweir //!! where this code will get integrated into, xISC will be a local 795cdf0e10cSrcweir //!! variable instead of a class member! 796cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI; 797cdf0e10cSrcweir // if ( !xBI.is() ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); 800cdf0e10cSrcweir uno::Reference < XInterface > xI = xMSF->createInstance( OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ); 801cdf0e10cSrcweir if ( xI.is() ) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XBreakIterator >*)0) ); 804cdf0e10cSrcweir x >>= xBI; 805cdf0e10cSrcweir } 806cdf0e10cSrcweir } 807cdf0e10cSrcweir return xBI; 808cdf0e10cSrcweir } 809cdf0e10cSrcweir // ----------------------------------------------------------------------- 810cdf0e10cSrcweir 811cdf0e10cSrcweir uno::Reference < i18n::XExtendedInputSequenceChecker > Edit::ImplGetInputSequenceChecker() const 812cdf0e10cSrcweir { 813cdf0e10cSrcweir //!! since we don't want to become incompatible in the next minor update 814cdf0e10cSrcweir //!! where this code will get integrated into, xISC will be a local 815cdf0e10cSrcweir //!! variable instead of a class member! 816cdf0e10cSrcweir uno::Reference < i18n::XExtendedInputSequenceChecker > xISC; 817cdf0e10cSrcweir // if ( !xISC.is() ) 818cdf0e10cSrcweir { 819cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); 820cdf0e10cSrcweir uno::Reference < XInterface > xI = xMSF->createInstance( OUString::createFromAscii( "com.sun.star.i18n.InputSequenceChecker" ) ); 821cdf0e10cSrcweir if ( xI.is() ) 822cdf0e10cSrcweir { 823cdf0e10cSrcweir Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XExtendedInputSequenceChecker >*)0) ); 824cdf0e10cSrcweir x >>= xISC; 825cdf0e10cSrcweir } 826cdf0e10cSrcweir } 827cdf0e10cSrcweir return xISC; 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830cdf0e10cSrcweir // ----------------------------------------------------------------------- 831cdf0e10cSrcweir 832cdf0e10cSrcweir void Edit::ShowTruncationWarning( Window* pParent ) 833cdf0e10cSrcweir { 834cdf0e10cSrcweir ResMgr* pResMgr = ImplGetResMgr(); 835cdf0e10cSrcweir if( pResMgr ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir WarningBox aBox( pParent, ResId( SV_EDIT_WARNING_BOX, *pResMgr ) ); 838cdf0e10cSrcweir aBox.Execute(); 839cdf0e10cSrcweir } 840cdf0e10cSrcweir } 841cdf0e10cSrcweir 842cdf0e10cSrcweir // ----------------------------------------------------------------------- 843cdf0e10cSrcweir 844cdf0e10cSrcweir bool Edit::ImplTruncateToMaxLen( rtl::OUString& rStr, sal_uInt32 nSelectionLen ) const 845cdf0e10cSrcweir { 846cdf0e10cSrcweir bool bWasTruncated = false; 847cdf0e10cSrcweir const sal_uInt32 nMaxLen = mnMaxTextLen < 65534 ? mnMaxTextLen : 65534; 848cdf0e10cSrcweir sal_uInt32 nLenAfter = static_cast<sal_uInt32>(maText.Len()) + rStr.getLength() - nSelectionLen; 849cdf0e10cSrcweir if ( nLenAfter > nMaxLen ) 850cdf0e10cSrcweir { 851cdf0e10cSrcweir sal_uInt32 nErasePos = nMaxLen - static_cast<sal_uInt32>(maText.Len()) + nSelectionLen; 852cdf0e10cSrcweir rStr = rStr.copy( 0, nErasePos ); 853cdf0e10cSrcweir bWasTruncated = true; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir return bWasTruncated; 856cdf0e10cSrcweir } 857cdf0e10cSrcweir 858cdf0e10cSrcweir // ----------------------------------------------------------------------- 859cdf0e10cSrcweir 860cdf0e10cSrcweir void Edit::ImplInsertText( const XubString& rStr, const Selection* pNewSel, sal_Bool bIsUserInput ) 861cdf0e10cSrcweir { 862cdf0e10cSrcweir Selection aSelection( maSelection ); 863cdf0e10cSrcweir aSelection.Justify(); 864cdf0e10cSrcweir 865cdf0e10cSrcweir rtl::OUString aNewText( ImplGetValidString( rStr ) ); 866cdf0e10cSrcweir ImplTruncateToMaxLen( aNewText, aSelection.Len() ); 867cdf0e10cSrcweir 868cdf0e10cSrcweir ImplClearLayoutData(); 869cdf0e10cSrcweir 870cdf0e10cSrcweir if ( aSelection.Len() ) 871cdf0e10cSrcweir maText.Erase( (xub_StrLen)aSelection.Min(), (xub_StrLen)aSelection.Len() ); 872cdf0e10cSrcweir else if ( !mbInsertMode && (aSelection.Max() < maText.Len()) ) 873cdf0e10cSrcweir maText.Erase( (xub_StrLen)aSelection.Max(), 1 ); 874cdf0e10cSrcweir 875cdf0e10cSrcweir // take care of input-sequence-checking now 876cdf0e10cSrcweir if (bIsUserInput && rStr.Len()) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir DBG_ASSERT( rStr.Len() == 1, "unexpected string length. User input is expected to providse 1 char only!" ); 879cdf0e10cSrcweir 880cdf0e10cSrcweir // determine if input-sequence-checking should be applied or not 881cdf0e10cSrcweir // 882cdf0e10cSrcweir static OUString sModule( OUString::createFromAscii( "/org.openoffice.Office.Common/I18N" ) ); 883cdf0e10cSrcweir static OUString sRelNode( OUString::createFromAscii( "CTL" ) ); 884cdf0e10cSrcweir static OUString sCTLSequenceChecking( OUString::createFromAscii( "CTLSequenceChecking" ) ); 885cdf0e10cSrcweir static OUString sCTLSequenceCheckingRestricted( OUString::createFromAscii( "CTLSequenceCheckingRestricted" ) ); 886cdf0e10cSrcweir static OUString sCTLSequenceCheckingTypeAndReplace( OUString::createFromAscii( "CTLSequenceCheckingTypeAndReplace" ) ); 887cdf0e10cSrcweir static OUString sCTLFont( OUString::createFromAscii( "CTLFont" ) ); 888cdf0e10cSrcweir // 889cdf0e10cSrcweir sal_Bool bCTLSequenceChecking = sal_False; 890cdf0e10cSrcweir sal_Bool bCTLSequenceCheckingRestricted = sal_False; 891cdf0e10cSrcweir sal_Bool bCTLSequenceCheckingTypeAndReplace = sal_False; 892cdf0e10cSrcweir sal_Bool bCTLFontEnabled = sal_False; 893cdf0e10cSrcweir sal_Bool bIsInputSequenceChecking = sal_False; 894cdf0e10cSrcweir // 895cdf0e10cSrcweir // get access to the configuration of this office module 896cdf0e10cSrcweir try 897cdf0e10cSrcweir { 898cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); 899cdf0e10cSrcweir uno::Reference< container::XNameAccess > xModuleCfg( ::comphelper::ConfigurationHelper::openConfig( 900cdf0e10cSrcweir xMSF, 901cdf0e10cSrcweir sModule, 902cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_READONLY ), 903cdf0e10cSrcweir uno::UNO_QUERY ); 904cdf0e10cSrcweir 905cdf0e10cSrcweir //!! get values from configuration. 906cdf0e10cSrcweir //!! we can't use SvtCTLOptions here since vcl must not be linked 907cdf0e10cSrcweir //!! against svtools. (It is already the other way around.) 908cdf0e10cSrcweir Any aCTLSequenceChecking = ::comphelper::ConfigurationHelper::readRelativeKey( xModuleCfg, sRelNode, sCTLSequenceChecking ); 909cdf0e10cSrcweir Any aCTLSequenceCheckingRestricted = ::comphelper::ConfigurationHelper::readRelativeKey( xModuleCfg, sRelNode, sCTLSequenceCheckingRestricted ); 910cdf0e10cSrcweir Any aCTLSequenceCheckingTypeAndReplace = ::comphelper::ConfigurationHelper::readRelativeKey( xModuleCfg, sRelNode, sCTLSequenceCheckingTypeAndReplace ); 911cdf0e10cSrcweir Any aCTLFontEnabled = ::comphelper::ConfigurationHelper::readRelativeKey( xModuleCfg, sRelNode, sCTLFont ); 912cdf0e10cSrcweir aCTLSequenceChecking >>= bCTLSequenceChecking; 913cdf0e10cSrcweir aCTLSequenceCheckingRestricted >>= bCTLSequenceCheckingRestricted; 914cdf0e10cSrcweir aCTLSequenceCheckingTypeAndReplace >>= bCTLSequenceCheckingTypeAndReplace; 915cdf0e10cSrcweir aCTLFontEnabled >>= bCTLFontEnabled; 916cdf0e10cSrcweir } 917cdf0e10cSrcweir catch(...) 918cdf0e10cSrcweir { 919cdf0e10cSrcweir bIsInputSequenceChecking = sal_False; // continue with inserting the new text 920cdf0e10cSrcweir } 921cdf0e10cSrcweir // 922cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI( ImplGetBreakIterator(), UNO_QUERY ); 923cdf0e10cSrcweir bIsInputSequenceChecking = rStr.Len() == 1 && 924cdf0e10cSrcweir bCTLFontEnabled && 925cdf0e10cSrcweir bCTLSequenceChecking && 926cdf0e10cSrcweir aSelection.Min() > 0 && /* first char needs not to be checked */ 927cdf0e10cSrcweir xBI.is() && i18n::ScriptType::COMPLEX == xBI->getScriptType( rStr, 0 ); 928cdf0e10cSrcweir 929cdf0e10cSrcweir 930cdf0e10cSrcweir uno::Reference < i18n::XExtendedInputSequenceChecker > xISC; 931cdf0e10cSrcweir if (bIsInputSequenceChecking && (xISC = ImplGetInputSequenceChecker()).is()) 932cdf0e10cSrcweir { 933cdf0e10cSrcweir sal_Unicode cChar = rStr.GetChar(0); 934cdf0e10cSrcweir xub_StrLen nTmpPos = static_cast< xub_StrLen >( aSelection.Min() ); 935cdf0e10cSrcweir sal_Int16 nCheckMode = bCTLSequenceCheckingRestricted ? 936cdf0e10cSrcweir i18n::InputSequenceCheckMode::STRICT : i18n::InputSequenceCheckMode::BASIC; 937cdf0e10cSrcweir 938cdf0e10cSrcweir // the text that needs to be checked is only the one 939cdf0e10cSrcweir // before the current cursor position 940cdf0e10cSrcweir rtl::OUString aOldText( maText.Copy(0, nTmpPos) ); 941cdf0e10cSrcweir rtl::OUString aTmpText( aOldText ); 942cdf0e10cSrcweir if (bCTLSequenceCheckingTypeAndReplace) 943cdf0e10cSrcweir { 944cdf0e10cSrcweir xISC->correctInputSequence( aTmpText, nTmpPos - 1, cChar, nCheckMode ); 945cdf0e10cSrcweir 946cdf0e10cSrcweir // find position of first character that has changed 947cdf0e10cSrcweir sal_Int32 nOldLen = aOldText.getLength(); 948cdf0e10cSrcweir sal_Int32 nTmpLen = aTmpText.getLength(); 949cdf0e10cSrcweir const sal_Unicode *pOldTxt = aOldText.getStr(); 950cdf0e10cSrcweir const sal_Unicode *pTmpTxt = aTmpText.getStr(); 951cdf0e10cSrcweir sal_Int32 nChgPos = 0; 952cdf0e10cSrcweir while ( nChgPos < nOldLen && nChgPos < nTmpLen && 953cdf0e10cSrcweir pOldTxt[nChgPos] == pTmpTxt[nChgPos] ) 954cdf0e10cSrcweir ++nChgPos; 955cdf0e10cSrcweir 956cdf0e10cSrcweir xub_StrLen nChgLen = static_cast< xub_StrLen >( nTmpLen - nChgPos ); 957cdf0e10cSrcweir String aChgText( aTmpText.copy( nChgPos ), nChgLen ); 958cdf0e10cSrcweir 959cdf0e10cSrcweir // remove text from first pos to be changed to current pos 960cdf0e10cSrcweir maText.Erase( static_cast< xub_StrLen >( nChgPos ), static_cast< xub_StrLen >( nTmpPos - nChgPos ) ); 961cdf0e10cSrcweir 962cdf0e10cSrcweir if (aChgText.Len()) 963cdf0e10cSrcweir { 964cdf0e10cSrcweir aNewText = aChgText; 965cdf0e10cSrcweir aSelection.Min() = nChgPos; // position for new text to be inserted 966cdf0e10cSrcweir } 967cdf0e10cSrcweir else 968cdf0e10cSrcweir aNewText = String::EmptyString(); 969cdf0e10cSrcweir } 970cdf0e10cSrcweir else 971cdf0e10cSrcweir { 972cdf0e10cSrcweir // should the character be ignored (i.e. not get inserted) ? 973cdf0e10cSrcweir if (!xISC->checkInputSequence( aOldText, nTmpPos - 1, cChar, nCheckMode )) 974cdf0e10cSrcweir aNewText = String::EmptyString(); 975cdf0e10cSrcweir } 976cdf0e10cSrcweir } 977cdf0e10cSrcweir 978cdf0e10cSrcweir // at this point now we will insert the non-empty text 'normally' some lines below... 979cdf0e10cSrcweir } 980cdf0e10cSrcweir 981cdf0e10cSrcweir if ( aNewText.getLength() ) 982cdf0e10cSrcweir maText.Insert( String( aNewText ), (xub_StrLen)aSelection.Min() ); 983cdf0e10cSrcweir 984cdf0e10cSrcweir if ( !pNewSel ) 985cdf0e10cSrcweir { 986cdf0e10cSrcweir maSelection.Min() = aSelection.Min() + aNewText.getLength(); 987cdf0e10cSrcweir maSelection.Max() = maSelection.Min(); 988cdf0e10cSrcweir } 989cdf0e10cSrcweir else 990cdf0e10cSrcweir { 991cdf0e10cSrcweir maSelection = *pNewSel; 992cdf0e10cSrcweir if ( maSelection.Min() > maText.Len() ) 993cdf0e10cSrcweir maSelection.Min() = maText.Len(); 994cdf0e10cSrcweir if ( maSelection.Max() > maText.Len() ) 995cdf0e10cSrcweir maSelection.Max() = maText.Len(); 996cdf0e10cSrcweir } 997cdf0e10cSrcweir 998cdf0e10cSrcweir ImplAlignAndPaint(); 999cdf0e10cSrcweir mbInternModified = sal_True; 1000cdf0e10cSrcweir } 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir // ----------------------------------------------------------------------- 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir void Edit::ImplSetText( const XubString& rText, const Selection* pNewSelection ) 1005cdf0e10cSrcweir { 1006cdf0e10cSrcweir // Der Text wird dadurch geloescht das der alte Text komplett 'selektiert' 1007cdf0e10cSrcweir // wird, dann InsertText, damit flackerfrei. 1008cdf0e10cSrcweir if ( ( rText.Len() <= mnMaxTextLen ) && ( (rText != maText) || (pNewSelection && (*pNewSelection != maSelection)) ) ) 1009cdf0e10cSrcweir { 1010cdf0e10cSrcweir ImplClearLayoutData(); 1011cdf0e10cSrcweir maSelection.Min() = 0; 1012cdf0e10cSrcweir maSelection.Max() = maText.Len(); 1013cdf0e10cSrcweir if ( mnXOffset || HasPaintEvent() ) 1014cdf0e10cSrcweir { 1015cdf0e10cSrcweir mnXOffset = 0; 1016cdf0e10cSrcweir maText = ImplGetValidString( rText ); 1017cdf0e10cSrcweir 1018cdf0e10cSrcweir // #i54929# recalculate mnXOffset before ImplSetSelection, 1019cdf0e10cSrcweir // else cursor ends up in wrong position 1020cdf0e10cSrcweir ImplAlign(); 1021cdf0e10cSrcweir 1022cdf0e10cSrcweir if ( pNewSelection ) 1023cdf0e10cSrcweir ImplSetSelection( *pNewSelection, sal_False ); 1024cdf0e10cSrcweir 1025cdf0e10cSrcweir if ( mnXOffset && !pNewSelection ) 1026cdf0e10cSrcweir maSelection.Max() = 0; 1027cdf0e10cSrcweir 1028cdf0e10cSrcweir Invalidate(); 1029cdf0e10cSrcweir } 1030cdf0e10cSrcweir else 1031cdf0e10cSrcweir ImplInsertText( rText, pNewSelection ); 1032cdf0e10cSrcweir 1033cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_EDIT_MODIFY ); 1034cdf0e10cSrcweir } 1035cdf0e10cSrcweir } 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir // ----------------------------------------------------------------------- 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir int Edit::ImplGetNativeControlType() 1040cdf0e10cSrcweir { 1041cdf0e10cSrcweir int nCtrl = 0; 1042cdf0e10cSrcweir Window *pControl = mbIsSubEdit ? GetParent() : this; 1043cdf0e10cSrcweir 1044cdf0e10cSrcweir switch( pControl->GetType() ) 1045cdf0e10cSrcweir { 1046cdf0e10cSrcweir case WINDOW_COMBOBOX: 1047cdf0e10cSrcweir case WINDOW_PATTERNBOX: 1048cdf0e10cSrcweir case WINDOW_NUMERICBOX: 1049cdf0e10cSrcweir case WINDOW_METRICBOX: 1050cdf0e10cSrcweir case WINDOW_CURRENCYBOX: 1051cdf0e10cSrcweir case WINDOW_DATEBOX: 1052cdf0e10cSrcweir case WINDOW_TIMEBOX: 1053cdf0e10cSrcweir case WINDOW_LONGCURRENCYBOX: 1054cdf0e10cSrcweir nCtrl = CTRL_COMBOBOX; 1055cdf0e10cSrcweir break; 1056cdf0e10cSrcweir 1057cdf0e10cSrcweir case WINDOW_MULTILINEEDIT: 1058cdf0e10cSrcweir if ( GetWindow( WINDOW_BORDER ) != this ) 1059cdf0e10cSrcweir nCtrl = CTRL_MULTILINE_EDITBOX; 1060cdf0e10cSrcweir else 1061cdf0e10cSrcweir nCtrl = CTRL_EDITBOX_NOBORDER; 1062cdf0e10cSrcweir break; 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir case WINDOW_EDIT: 1065cdf0e10cSrcweir case WINDOW_PATTERNFIELD: 1066cdf0e10cSrcweir case WINDOW_METRICFIELD: 1067cdf0e10cSrcweir case WINDOW_CURRENCYFIELD: 1068cdf0e10cSrcweir case WINDOW_DATEFIELD: 1069cdf0e10cSrcweir case WINDOW_TIMEFIELD: 1070cdf0e10cSrcweir case WINDOW_LONGCURRENCYFIELD: 1071cdf0e10cSrcweir case WINDOW_NUMERICFIELD: 1072cdf0e10cSrcweir case WINDOW_SPINFIELD: 1073cdf0e10cSrcweir if( pControl->GetStyle() & WB_SPIN ) 1074cdf0e10cSrcweir nCtrl = CTRL_SPINBOX; 1075cdf0e10cSrcweir else 1076cdf0e10cSrcweir { 1077cdf0e10cSrcweir if ( GetWindow( WINDOW_BORDER ) != this ) 1078cdf0e10cSrcweir nCtrl = CTRL_EDITBOX; 1079cdf0e10cSrcweir else 1080cdf0e10cSrcweir nCtrl = CTRL_EDITBOX_NOBORDER; 1081cdf0e10cSrcweir } 1082cdf0e10cSrcweir break; 1083cdf0e10cSrcweir 1084cdf0e10cSrcweir default: 1085cdf0e10cSrcweir nCtrl = CTRL_EDITBOX; 1086cdf0e10cSrcweir } 1087cdf0e10cSrcweir return nCtrl; 1088cdf0e10cSrcweir } 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir void Edit::ImplClearBackground( long nXStart, long nXEnd ) 1091cdf0e10cSrcweir { 1092cdf0e10cSrcweir /* 1093cdf0e10cSrcweir * note: at this point the cursor must be switched off already 1094cdf0e10cSrcweir */ 1095cdf0e10cSrcweir Point aTmpPoint; 1096cdf0e10cSrcweir Rectangle aRect( aTmpPoint, GetOutputSizePixel() ); 1097cdf0e10cSrcweir aRect.Left() = nXStart; 1098cdf0e10cSrcweir aRect.Right() = nXEnd; 1099cdf0e10cSrcweir 1100cdf0e10cSrcweir if( ImplUseNativeBorder( GetStyle() ) || IsPaintTransparent() ) 1101cdf0e10cSrcweir { 1102cdf0e10cSrcweir // draw the inner part by painting the whole control using its border window 1103cdf0e10cSrcweir Window *pControl = this; 1104cdf0e10cSrcweir Window *pBorder = GetWindow( WINDOW_BORDER ); 1105cdf0e10cSrcweir if( pBorder == this ) 1106cdf0e10cSrcweir { 1107cdf0e10cSrcweir // we have no border, use parent 1108cdf0e10cSrcweir pControl = mbIsSubEdit ? GetParent() : this; 1109cdf0e10cSrcweir pBorder = pControl->GetWindow( WINDOW_BORDER ); 1110cdf0e10cSrcweir if( pBorder == this ) 1111cdf0e10cSrcweir pBorder = GetParent(); 1112cdf0e10cSrcweir } 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir if( pBorder ) 1115cdf0e10cSrcweir { 1116cdf0e10cSrcweir // set proper clipping region to not overdraw the whole control 1117cdf0e10cSrcweir Region aClipRgn = GetPaintRegion(); 1118cdf0e10cSrcweir if( !aClipRgn.IsNull() ) 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir // transform clipping region to border window's coordinate system 1121cdf0e10cSrcweir if( IsRTLEnabled() != pBorder->IsRTLEnabled() && Application::GetSettings().GetLayoutRTL() ) 1122cdf0e10cSrcweir { 1123cdf0e10cSrcweir // need to mirror in case border is not RTL but edit is (or vice versa) 1124cdf0e10cSrcweir 1125cdf0e10cSrcweir // mirror 1126cdf0e10cSrcweir Rectangle aBounds( aClipRgn.GetBoundRect() ); 1127cdf0e10cSrcweir int xNew = GetOutputSizePixel().Width() - aBounds.GetWidth() - aBounds.Left(); 1128cdf0e10cSrcweir aClipRgn.Move( xNew - aBounds.Left(), 0 ); 1129cdf0e10cSrcweir 1130cdf0e10cSrcweir // move offset of border window 1131cdf0e10cSrcweir Point aBorderOffs; 1132cdf0e10cSrcweir aBorderOffs = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aBorderOffs ) ); 1133cdf0e10cSrcweir aClipRgn.Move( aBorderOffs.X(), aBorderOffs.Y() ); 1134cdf0e10cSrcweir } 1135cdf0e10cSrcweir else 1136cdf0e10cSrcweir { 1137cdf0e10cSrcweir // normal case 1138cdf0e10cSrcweir Point aBorderOffs; 1139cdf0e10cSrcweir aBorderOffs = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aBorderOffs ) ); 1140cdf0e10cSrcweir aClipRgn.Move( aBorderOffs.X(), aBorderOffs.Y() ); 1141cdf0e10cSrcweir } 1142cdf0e10cSrcweir 1143cdf0e10cSrcweir Region oldRgn( pBorder->GetClipRegion() ); 1144cdf0e10cSrcweir pBorder->SetClipRegion( aClipRgn ); 1145cdf0e10cSrcweir 1146cdf0e10cSrcweir pBorder->Paint( Rectangle() ); 1147cdf0e10cSrcweir 1148cdf0e10cSrcweir pBorder->SetClipRegion( oldRgn ); 1149cdf0e10cSrcweir } 1150cdf0e10cSrcweir else 1151cdf0e10cSrcweir pBorder->Paint( Rectangle() ); 1152cdf0e10cSrcweir 1153cdf0e10cSrcweir } 1154cdf0e10cSrcweir } 1155cdf0e10cSrcweir else 1156cdf0e10cSrcweir Erase( aRect ); 1157cdf0e10cSrcweir } 1158cdf0e10cSrcweir 1159cdf0e10cSrcweir // ----------------------------------------------------------------------- 1160cdf0e10cSrcweir 1161cdf0e10cSrcweir void Edit::ImplShowCursor( sal_Bool bOnlyIfVisible ) 1162cdf0e10cSrcweir { 1163cdf0e10cSrcweir if ( !IsUpdateMode() || ( bOnlyIfVisible && !IsReallyVisible() ) ) 1164cdf0e10cSrcweir return; 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir Cursor* pCursor = GetCursor(); 1167cdf0e10cSrcweir XubString aText = ImplGetText(); 1168cdf0e10cSrcweir 1169cdf0e10cSrcweir long nTextPos = 0; 1170cdf0e10cSrcweir 1171cdf0e10cSrcweir sal_Int32 nDXBuffer[256]; 1172cdf0e10cSrcweir sal_Int32* pDXBuffer = NULL; 1173cdf0e10cSrcweir sal_Int32* pDX = nDXBuffer; 1174cdf0e10cSrcweir 1175cdf0e10cSrcweir if( aText.Len() ) 1176cdf0e10cSrcweir { 1177cdf0e10cSrcweir if( 2*aText.Len() > xub_StrLen(sizeof(nDXBuffer)/sizeof(nDXBuffer[0])) ) 1178cdf0e10cSrcweir { 1179cdf0e10cSrcweir pDXBuffer = new sal_Int32[2*(aText.Len()+1)]; 1180cdf0e10cSrcweir pDX = pDXBuffer; 1181cdf0e10cSrcweir } 1182cdf0e10cSrcweir 1183cdf0e10cSrcweir GetCaretPositions( aText, pDX, 0, aText.Len() ); 1184cdf0e10cSrcweir 1185cdf0e10cSrcweir if( maSelection.Max() < aText.Len() ) 1186cdf0e10cSrcweir nTextPos = pDX[ 2*maSelection.Max() ]; 1187cdf0e10cSrcweir else 1188cdf0e10cSrcweir nTextPos = pDX[ 2*aText.Len()-1 ]; 1189cdf0e10cSrcweir } 1190cdf0e10cSrcweir 1191cdf0e10cSrcweir long nCursorWidth = 0; 1192cdf0e10cSrcweir if ( !mbInsertMode && !maSelection.Len() && (maSelection.Max() < aText.Len()) ) 1193cdf0e10cSrcweir nCursorWidth = GetTextWidth( aText, (xub_StrLen)maSelection.Max(), 1 ); 1194cdf0e10cSrcweir long nCursorPosX = nTextPos + mnXOffset + ImplGetExtraOffset(); 1195cdf0e10cSrcweir 1196cdf0e10cSrcweir // Cursor muss im sichtbaren Bereich landen: 1197cdf0e10cSrcweir const Size aOutSize = GetOutputSizePixel(); 1198cdf0e10cSrcweir if ( (nCursorPosX < 0) || (nCursorPosX >= aOutSize.Width()) ) 1199cdf0e10cSrcweir { 1200cdf0e10cSrcweir long nOldXOffset = mnXOffset; 1201cdf0e10cSrcweir 1202cdf0e10cSrcweir if ( nCursorPosX < 0 ) 1203cdf0e10cSrcweir { 1204cdf0e10cSrcweir mnXOffset = - nTextPos; 1205cdf0e10cSrcweir long nMaxX = 0; 1206cdf0e10cSrcweir mnXOffset += aOutSize.Width() / 5; 1207cdf0e10cSrcweir if ( mnXOffset > nMaxX ) 1208cdf0e10cSrcweir mnXOffset = nMaxX; 1209cdf0e10cSrcweir } 1210cdf0e10cSrcweir else 1211cdf0e10cSrcweir { 1212cdf0e10cSrcweir mnXOffset = (aOutSize.Width()-ImplGetExtraOffset()) - nTextPos; 1213cdf0e10cSrcweir // Etwas mehr? 1214cdf0e10cSrcweir if ( (aOutSize.Width()-ImplGetExtraOffset()) < nTextPos ) 1215cdf0e10cSrcweir { 1216cdf0e10cSrcweir long nMaxNegX = (aOutSize.Width()-ImplGetExtraOffset()) - GetTextWidth( aText ); 1217cdf0e10cSrcweir mnXOffset -= aOutSize.Width() / 5; 1218cdf0e10cSrcweir if ( mnXOffset < nMaxNegX ) // beides negativ... 1219cdf0e10cSrcweir mnXOffset = nMaxNegX; 1220cdf0e10cSrcweir } 1221cdf0e10cSrcweir } 1222cdf0e10cSrcweir 1223cdf0e10cSrcweir nCursorPosX = nTextPos + mnXOffset + ImplGetExtraOffset(); 1224cdf0e10cSrcweir if ( nCursorPosX == aOutSize.Width() ) // dann nicht sichtbar... 1225cdf0e10cSrcweir nCursorPosX--; 1226cdf0e10cSrcweir 1227cdf0e10cSrcweir if ( mnXOffset != nOldXOffset ) 1228cdf0e10cSrcweir ImplInvalidateOrRepaint(); 1229cdf0e10cSrcweir } 1230cdf0e10cSrcweir 1231cdf0e10cSrcweir const long nTextHeight = GetTextHeight(); 1232cdf0e10cSrcweir const long nCursorPosY = ImplGetTextYPosition(); 1233cdf0e10cSrcweir pCursor->SetPos( Point( nCursorPosX, nCursorPosY ) ); 1234cdf0e10cSrcweir pCursor->SetSize( Size( nCursorWidth, nTextHeight ) ); 1235cdf0e10cSrcweir pCursor->Show(); 1236cdf0e10cSrcweir 1237cdf0e10cSrcweir if( pDXBuffer ) 1238cdf0e10cSrcweir delete [] pDXBuffer; 1239cdf0e10cSrcweir } 1240cdf0e10cSrcweir 1241cdf0e10cSrcweir // ----------------------------------------------------------------------- 1242cdf0e10cSrcweir 1243cdf0e10cSrcweir void Edit::ImplAlign() 1244cdf0e10cSrcweir { 1245cdf0e10cSrcweir long nTextWidth = GetTextWidth( ImplGetText() ); 1246cdf0e10cSrcweir long nOutWidth = GetOutputSizePixel().Width(); 1247cdf0e10cSrcweir 1248cdf0e10cSrcweir if ( mnAlign == EDIT_ALIGN_LEFT ) 1249cdf0e10cSrcweir { 1250cdf0e10cSrcweir if( mnXOffset && ( nTextWidth < nOutWidth ) ) 1251cdf0e10cSrcweir mnXOffset = 0; 1252cdf0e10cSrcweir 1253cdf0e10cSrcweir } 1254cdf0e10cSrcweir else if ( mnAlign == EDIT_ALIGN_RIGHT ) 1255cdf0e10cSrcweir { 1256cdf0e10cSrcweir long nMinXOffset = nOutWidth - nTextWidth - 1 - ImplGetExtraOffset(); 1257cdf0e10cSrcweir bool bRTL = IsRTLEnabled(); 1258cdf0e10cSrcweir if( mbIsSubEdit && GetParent() ) 1259cdf0e10cSrcweir bRTL = GetParent()->IsRTLEnabled(); 1260cdf0e10cSrcweir if( bRTL ) 1261cdf0e10cSrcweir { 1262cdf0e10cSrcweir if( nTextWidth < nOutWidth ) 1263cdf0e10cSrcweir mnXOffset = nMinXOffset; 1264cdf0e10cSrcweir } 1265cdf0e10cSrcweir else 1266cdf0e10cSrcweir { 1267cdf0e10cSrcweir if( nTextWidth < nOutWidth ) 1268cdf0e10cSrcweir mnXOffset = nMinXOffset; 1269cdf0e10cSrcweir else if ( mnXOffset < nMinXOffset ) 1270cdf0e10cSrcweir mnXOffset = nMinXOffset; 1271cdf0e10cSrcweir } 1272cdf0e10cSrcweir } 1273cdf0e10cSrcweir else if( mnAlign == EDIT_ALIGN_CENTER ) 1274cdf0e10cSrcweir { 1275cdf0e10cSrcweir // Mit Abfrage schoener, wenn gescrollt, dann aber nicht zentriert im gescrollten Zustand... 1276cdf0e10cSrcweir // if ( nTextWidth < nOutWidth ) 1277cdf0e10cSrcweir mnXOffset = (nOutWidth - nTextWidth) / 2; 1278cdf0e10cSrcweir } 1279cdf0e10cSrcweir } 1280cdf0e10cSrcweir 1281cdf0e10cSrcweir 1282cdf0e10cSrcweir // ----------------------------------------------------------------------- 1283cdf0e10cSrcweir 1284cdf0e10cSrcweir void Edit::ImplAlignAndPaint() 1285cdf0e10cSrcweir { 1286cdf0e10cSrcweir ImplAlign(); 1287cdf0e10cSrcweir ImplInvalidateOrRepaint( 0, STRING_LEN ); 1288cdf0e10cSrcweir ImplShowCursor(); 1289cdf0e10cSrcweir } 1290cdf0e10cSrcweir 1291cdf0e10cSrcweir // ----------------------------------------------------------------------- 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir xub_StrLen Edit::ImplGetCharPos( const Point& rWindowPos ) const 1294cdf0e10cSrcweir { 1295cdf0e10cSrcweir xub_StrLen nIndex = STRING_LEN; 1296cdf0e10cSrcweir String aText = ImplGetText(); 1297cdf0e10cSrcweir 1298cdf0e10cSrcweir sal_Int32 nDXBuffer[256]; 1299cdf0e10cSrcweir sal_Int32* pDXBuffer = NULL; 1300cdf0e10cSrcweir sal_Int32* pDX = nDXBuffer; 1301cdf0e10cSrcweir if( 2*aText.Len() > xub_StrLen(sizeof(nDXBuffer)/sizeof(nDXBuffer[0])) ) 1302cdf0e10cSrcweir { 1303cdf0e10cSrcweir pDXBuffer = new sal_Int32[2*(aText.Len()+1)]; 1304cdf0e10cSrcweir pDX = pDXBuffer; 1305cdf0e10cSrcweir } 1306cdf0e10cSrcweir 1307cdf0e10cSrcweir GetCaretPositions( aText, pDX, 0, aText.Len() ); 1308cdf0e10cSrcweir long nX = rWindowPos.X() - mnXOffset - ImplGetExtraOffset(); 1309cdf0e10cSrcweir for( int i = 0; i < aText.Len(); i++ ) 1310cdf0e10cSrcweir { 1311cdf0e10cSrcweir if( (pDX[2*i] >= nX && pDX[2*i+1] <= nX) || 1312cdf0e10cSrcweir (pDX[2*i+1] >= nX && pDX[2*i] <= nX)) 1313cdf0e10cSrcweir { 1314cdf0e10cSrcweir nIndex = sal::static_int_cast<xub_StrLen>(i); 1315cdf0e10cSrcweir if( pDX[2*i] < pDX[2*i+1] ) 1316cdf0e10cSrcweir { 1317cdf0e10cSrcweir if( nX > (pDX[2*i]+pDX[2*i+1])/2 ) 1318cdf0e10cSrcweir nIndex++; 1319cdf0e10cSrcweir } 1320cdf0e10cSrcweir else 1321cdf0e10cSrcweir { 1322cdf0e10cSrcweir if( nX < (pDX[2*i]+pDX[2*i+1])/2 ) 1323cdf0e10cSrcweir nIndex++; 1324cdf0e10cSrcweir } 1325cdf0e10cSrcweir break; 1326cdf0e10cSrcweir } 1327cdf0e10cSrcweir } 1328cdf0e10cSrcweir if( nIndex == STRING_LEN ) 1329cdf0e10cSrcweir { 1330cdf0e10cSrcweir nIndex = 0; 1331cdf0e10cSrcweir long nDiff = Abs( pDX[0]-nX ); 1332cdf0e10cSrcweir for( int i = 1; i < aText.Len(); i++ ) 1333cdf0e10cSrcweir { 1334cdf0e10cSrcweir long nNewDiff = Abs( pDX[2*i]-nX ); 1335cdf0e10cSrcweir 1336cdf0e10cSrcweir if( nNewDiff < nDiff ) 1337cdf0e10cSrcweir { 1338cdf0e10cSrcweir nIndex = sal::static_int_cast<xub_StrLen>(i); 1339cdf0e10cSrcweir nDiff = nNewDiff; 1340cdf0e10cSrcweir } 1341cdf0e10cSrcweir } 1342cdf0e10cSrcweir if( nIndex == aText.Len()-1 && Abs( pDX[2*nIndex+1] - nX ) < nDiff ) 1343cdf0e10cSrcweir nIndex = STRING_LEN; 1344cdf0e10cSrcweir } 1345cdf0e10cSrcweir 1346cdf0e10cSrcweir if( pDXBuffer ) 1347cdf0e10cSrcweir delete [] pDXBuffer; 1348cdf0e10cSrcweir 1349cdf0e10cSrcweir return nIndex; 1350cdf0e10cSrcweir } 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir // ----------------------------------------------------------------------- 1353cdf0e10cSrcweir 1354cdf0e10cSrcweir void Edit::ImplSetCursorPos( xub_StrLen nChar, sal_Bool bSelect ) 1355cdf0e10cSrcweir { 1356cdf0e10cSrcweir Selection aSelection( maSelection ); 1357cdf0e10cSrcweir aSelection.Max() = nChar; 1358cdf0e10cSrcweir if ( !bSelect ) 1359cdf0e10cSrcweir aSelection.Min() = aSelection.Max(); 1360cdf0e10cSrcweir ImplSetSelection( aSelection ); 1361cdf0e10cSrcweir } 1362cdf0e10cSrcweir 1363cdf0e10cSrcweir // ----------------------------------------------------------------------- 1364cdf0e10cSrcweir 1365cdf0e10cSrcweir void Edit::ImplLoadRes( const ResId& rResId ) 1366cdf0e10cSrcweir { 1367cdf0e10cSrcweir Control::ImplLoadRes( rResId ); 1368cdf0e10cSrcweir 1369cdf0e10cSrcweir xub_StrLen nTextLength = ReadShortRes(); 1370cdf0e10cSrcweir if ( nTextLength ) 1371cdf0e10cSrcweir SetMaxTextLen( nTextLength ); 1372cdf0e10cSrcweir } 1373cdf0e10cSrcweir 1374cdf0e10cSrcweir // ----------------------------------------------------------------------- 1375cdf0e10cSrcweir 1376cdf0e10cSrcweir void Edit::ImplCopyToSelectionClipboard() 1377cdf0e10cSrcweir { 1378cdf0e10cSrcweir if ( GetSelection().Len() ) 1379cdf0e10cSrcweir { 1380cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::datatransfer::clipboard::XClipboard> aSelection(GetPrimarySelection()); 1381cdf0e10cSrcweir ImplCopy( aSelection ); 1382cdf0e10cSrcweir } 1383cdf0e10cSrcweir } 1384cdf0e10cSrcweir 1385cdf0e10cSrcweir void Edit::ImplCopy( uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard ) 1386cdf0e10cSrcweir { 1387cdf0e10cSrcweir ::vcl::unohelper::TextDataObject::CopyStringTo( GetSelected(), rxClipboard ); 1388cdf0e10cSrcweir } 1389cdf0e10cSrcweir 1390cdf0e10cSrcweir // ----------------------------------------------------------------------- 1391cdf0e10cSrcweir 1392cdf0e10cSrcweir void Edit::ImplPaste( uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard ) 1393cdf0e10cSrcweir { 1394cdf0e10cSrcweir if ( rxClipboard.is() ) 1395cdf0e10cSrcweir { 1396cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xDataObj; 1397cdf0e10cSrcweir 1398cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 1399cdf0e10cSrcweir 1400cdf0e10cSrcweir try 1401cdf0e10cSrcweir { 1402cdf0e10cSrcweir xDataObj = rxClipboard->getContents(); 1403cdf0e10cSrcweir } 1404cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir } 1407cdf0e10cSrcweir 1408cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 1409cdf0e10cSrcweir 1410cdf0e10cSrcweir if ( xDataObj.is() ) 1411cdf0e10cSrcweir { 1412cdf0e10cSrcweir datatransfer::DataFlavor aFlavor; 1413cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor ); 1414cdf0e10cSrcweir try 1415cdf0e10cSrcweir { 1416cdf0e10cSrcweir uno::Any aData = xDataObj->getTransferData( aFlavor ); 1417cdf0e10cSrcweir ::rtl::OUString aText; 1418cdf0e10cSrcweir aData >>= aText; 1419cdf0e10cSrcweir if( ImplTruncateToMaxLen( aText, maSelection.Len() ) ) 1420cdf0e10cSrcweir ShowTruncationWarning( const_cast<Edit*>(this) ); 1421cdf0e10cSrcweir ReplaceSelected( aText ); 1422cdf0e10cSrcweir } 1423cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1424cdf0e10cSrcweir { 1425cdf0e10cSrcweir } 1426cdf0e10cSrcweir } 1427cdf0e10cSrcweir } 1428cdf0e10cSrcweir } 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir // ----------------------------------------------------------------------- 1431cdf0e10cSrcweir 1432cdf0e10cSrcweir void Edit::MouseButtonDown( const MouseEvent& rMEvt ) 1433cdf0e10cSrcweir { 1434cdf0e10cSrcweir if ( mpSubEdit ) 1435cdf0e10cSrcweir { 1436cdf0e10cSrcweir Control::MouseButtonDown( rMEvt ); 1437cdf0e10cSrcweir return; 1438cdf0e10cSrcweir } 1439cdf0e10cSrcweir 1440cdf0e10cSrcweir xub_StrLen nChar = ImplGetCharPos( rMEvt.GetPosPixel() ); 1441cdf0e10cSrcweir Selection aSelection( maSelection ); 1442cdf0e10cSrcweir aSelection.Justify(); 1443cdf0e10cSrcweir 1444cdf0e10cSrcweir if ( rMEvt.GetClicks() < 4 ) 1445cdf0e10cSrcweir { 1446cdf0e10cSrcweir mbClickedInSelection = sal_False; 1447cdf0e10cSrcweir if ( rMEvt.GetClicks() == 3 ) 1448cdf0e10cSrcweir { 1449cdf0e10cSrcweir ImplSetSelection( Selection( 0, 0xFFFF ) ); 1450cdf0e10cSrcweir ImplCopyToSelectionClipboard(); 1451cdf0e10cSrcweir 1452cdf0e10cSrcweir } 1453cdf0e10cSrcweir else if ( rMEvt.GetClicks() == 2 ) 1454cdf0e10cSrcweir { 1455cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = ImplGetBreakIterator(); 1456cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->getWordBoundary( maText, aSelection.Max(), GetSettings().GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES, sal_True ); 1457cdf0e10cSrcweir ImplSetSelection( Selection( aBoundary.startPos, aBoundary.endPos ) ); 1458cdf0e10cSrcweir ImplCopyToSelectionClipboard(); 1459cdf0e10cSrcweir } 1460cdf0e10cSrcweir else if ( !rMEvt.IsShift() && HasFocus() && aSelection.IsInside( nChar ) ) 1461cdf0e10cSrcweir mbClickedInSelection = sal_True; 1462cdf0e10cSrcweir else if ( rMEvt.IsLeft() ) 1463cdf0e10cSrcweir ImplSetCursorPos( nChar, rMEvt.IsShift() ); 1464cdf0e10cSrcweir 1465cdf0e10cSrcweir if ( !mbClickedInSelection && rMEvt.IsLeft() && ( rMEvt.GetClicks() == 1 ) ) 1466cdf0e10cSrcweir StartTracking( STARTTRACK_SCROLLREPEAT ); 1467cdf0e10cSrcweir } 1468cdf0e10cSrcweir 1469cdf0e10cSrcweir mbInMBDown = sal_True; // Dann im GetFocus nicht alles selektieren 1470cdf0e10cSrcweir GrabFocus(); 1471cdf0e10cSrcweir mbInMBDown = sal_False; 1472cdf0e10cSrcweir } 1473cdf0e10cSrcweir 1474cdf0e10cSrcweir // ----------------------------------------------------------------------- 1475cdf0e10cSrcweir 1476cdf0e10cSrcweir void Edit::MouseButtonUp( const MouseEvent& rMEvt ) 1477cdf0e10cSrcweir { 1478cdf0e10cSrcweir if ( mbClickedInSelection && rMEvt.IsLeft() ) 1479cdf0e10cSrcweir { 1480cdf0e10cSrcweir xub_StrLen nChar = ImplGetCharPos( rMEvt.GetPosPixel() ); 1481cdf0e10cSrcweir ImplSetCursorPos( nChar, sal_False ); 1482cdf0e10cSrcweir mbClickedInSelection = sal_False; 1483cdf0e10cSrcweir } 1484cdf0e10cSrcweir else if ( rMEvt.IsMiddle() && !mbReadOnly && 1485cdf0e10cSrcweir ( GetSettings().GetMouseSettings().GetMiddleButtonAction() == MOUSE_MIDDLE_PASTESELECTION ) ) 1486cdf0e10cSrcweir { 1487cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::datatransfer::clipboard::XClipboard> aSelection(Window::GetPrimarySelection()); 1488cdf0e10cSrcweir ImplPaste( aSelection ); 1489cdf0e10cSrcweir ImplModified(); 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir } 1492cdf0e10cSrcweir 1493cdf0e10cSrcweir // ----------------------------------------------------------------------- 1494cdf0e10cSrcweir 1495cdf0e10cSrcweir void Edit::Tracking( const TrackingEvent& rTEvt ) 1496cdf0e10cSrcweir { 1497cdf0e10cSrcweir if ( rTEvt.IsTrackingEnded() ) 1498cdf0e10cSrcweir { 1499cdf0e10cSrcweir if ( mbClickedInSelection ) 1500cdf0e10cSrcweir { 1501cdf0e10cSrcweir xub_StrLen nChar = ImplGetCharPos( rTEvt.GetMouseEvent().GetPosPixel() ); 1502cdf0e10cSrcweir ImplSetCursorPos( nChar, sal_False ); 1503cdf0e10cSrcweir mbClickedInSelection = sal_False; 1504cdf0e10cSrcweir } 1505cdf0e10cSrcweir else if ( rTEvt.GetMouseEvent().IsLeft() ) 1506cdf0e10cSrcweir { 1507cdf0e10cSrcweir ImplCopyToSelectionClipboard(); 1508cdf0e10cSrcweir } 1509cdf0e10cSrcweir } 1510cdf0e10cSrcweir else 1511cdf0e10cSrcweir { 1512cdf0e10cSrcweir if( !mbClickedInSelection ) 1513cdf0e10cSrcweir { 1514cdf0e10cSrcweir xub_StrLen nChar = ImplGetCharPos( rTEvt.GetMouseEvent().GetPosPixel() ); 1515cdf0e10cSrcweir ImplSetCursorPos( nChar, sal_True ); 1516cdf0e10cSrcweir } 1517cdf0e10cSrcweir } 1518cdf0e10cSrcweir 1519cdf0e10cSrcweir if ( mpUpdateDataTimer && !mbIsSubEdit && mpUpdateDataTimer->IsActive() ) 1520cdf0e10cSrcweir mpUpdateDataTimer->Start();//do not update while the user is still travelling in the control 1521cdf0e10cSrcweir } 1522cdf0e10cSrcweir 1523cdf0e10cSrcweir // ----------------------------------------------------------------------- 1524cdf0e10cSrcweir 1525cdf0e10cSrcweir sal_Bool Edit::ImplHandleKeyEvent( const KeyEvent& rKEvt ) 1526cdf0e10cSrcweir { 1527cdf0e10cSrcweir sal_Bool bDone = sal_False; 1528cdf0e10cSrcweir sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); 1529cdf0e10cSrcweir KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); 1530cdf0e10cSrcweir 1531cdf0e10cSrcweir mbInternModified = sal_False; 1532cdf0e10cSrcweir 1533cdf0e10cSrcweir if ( eFunc != KEYFUNC_DONTKNOW ) 1534cdf0e10cSrcweir { 1535cdf0e10cSrcweir switch ( eFunc ) 1536cdf0e10cSrcweir { 1537cdf0e10cSrcweir case KEYFUNC_CUT: 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir if ( !mbReadOnly && maSelection.Len() && !(GetStyle() & WB_PASSWORD) ) 1540cdf0e10cSrcweir { 1541cdf0e10cSrcweir Cut(); 1542cdf0e10cSrcweir ImplModified(); 1543cdf0e10cSrcweir bDone = sal_True; 1544cdf0e10cSrcweir } 1545cdf0e10cSrcweir } 1546cdf0e10cSrcweir break; 1547cdf0e10cSrcweir 1548cdf0e10cSrcweir case KEYFUNC_COPY: 1549cdf0e10cSrcweir { 1550cdf0e10cSrcweir if ( !(GetStyle() & WB_PASSWORD) ) 1551cdf0e10cSrcweir { 1552cdf0e10cSrcweir Copy(); 1553cdf0e10cSrcweir bDone = sal_True; 1554cdf0e10cSrcweir } 1555cdf0e10cSrcweir } 1556cdf0e10cSrcweir break; 1557cdf0e10cSrcweir 1558cdf0e10cSrcweir case KEYFUNC_PASTE: 1559cdf0e10cSrcweir { 1560cdf0e10cSrcweir if ( !mbReadOnly ) 1561cdf0e10cSrcweir { 1562cdf0e10cSrcweir Paste(); 1563cdf0e10cSrcweir bDone = sal_True; 1564cdf0e10cSrcweir } 1565cdf0e10cSrcweir } 1566cdf0e10cSrcweir break; 1567cdf0e10cSrcweir 1568cdf0e10cSrcweir case KEYFUNC_UNDO: 1569cdf0e10cSrcweir { 1570cdf0e10cSrcweir if ( !mbReadOnly ) 1571cdf0e10cSrcweir { 1572cdf0e10cSrcweir Undo(); 1573cdf0e10cSrcweir bDone = sal_True; 1574cdf0e10cSrcweir } 1575cdf0e10cSrcweir } 1576cdf0e10cSrcweir break; 1577cdf0e10cSrcweir 1578cdf0e10cSrcweir default: // wird dann evtl. unten bearbeitet. 1579cdf0e10cSrcweir eFunc = KEYFUNC_DONTKNOW; 1580cdf0e10cSrcweir } 1581cdf0e10cSrcweir } 1582cdf0e10cSrcweir 1583cdf0e10cSrcweir if ( !bDone && rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsMod2() ) 1584cdf0e10cSrcweir { 1585cdf0e10cSrcweir if ( nCode == KEY_A ) 1586cdf0e10cSrcweir { 1587cdf0e10cSrcweir ImplSetSelection( Selection( 0, maText.Len() ) ); 1588cdf0e10cSrcweir bDone = sal_True; 1589cdf0e10cSrcweir } 1590cdf0e10cSrcweir else if ( rKEvt.GetKeyCode().IsShift() && (nCode == KEY_S) ) 1591cdf0e10cSrcweir { 1592cdf0e10cSrcweir if ( pImplFncGetSpecialChars ) 1593cdf0e10cSrcweir { 1594cdf0e10cSrcweir Selection aSaveSel = GetSelection(); // Falls jemand in Get/LoseFocus die Selektion verbiegt, z.B. URL-Zeile... 1595cdf0e10cSrcweir XubString aChars = pImplFncGetSpecialChars( this, GetFont() ); 1596cdf0e10cSrcweir SetSelection( aSaveSel ); 1597cdf0e10cSrcweir if ( aChars.Len() ) 1598cdf0e10cSrcweir { 1599cdf0e10cSrcweir ImplInsertText( aChars ); 1600cdf0e10cSrcweir ImplModified(); 1601cdf0e10cSrcweir } 1602cdf0e10cSrcweir bDone = sal_True; 1603cdf0e10cSrcweir } 1604cdf0e10cSrcweir } 1605cdf0e10cSrcweir } 1606cdf0e10cSrcweir 1607cdf0e10cSrcweir if ( eFunc == KEYFUNC_DONTKNOW && ! bDone ) 1608cdf0e10cSrcweir { 1609cdf0e10cSrcweir switch ( nCode ) 1610cdf0e10cSrcweir { 1611cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_ALL: 1612cdf0e10cSrcweir { 1613cdf0e10cSrcweir ImplSetSelection( Selection( 0, maText.Len() ) ); 1614cdf0e10cSrcweir bDone = sal_True; 1615cdf0e10cSrcweir } 1616cdf0e10cSrcweir break; 1617cdf0e10cSrcweir 1618cdf0e10cSrcweir case KEY_LEFT: 1619cdf0e10cSrcweir case KEY_RIGHT: 1620cdf0e10cSrcweir case KEY_HOME: 1621cdf0e10cSrcweir case KEY_END: 1622cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_FORWARD: 1623cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_FORWARD: 1624cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_BACKWARD: 1625cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_BACKWARD: 1626cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE: 1627cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_LINE: 1628cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE: 1629cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_LINE: 1630cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH: 1631cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH: 1632cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH: 1633cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH: 1634cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT: 1635cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT: 1636cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT: 1637cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_DOCUMENT: 1638cdf0e10cSrcweir { 1639cdf0e10cSrcweir if ( !rKEvt.GetKeyCode().IsMod2() ) 1640cdf0e10cSrcweir { 1641cdf0e10cSrcweir ImplClearLayoutData(); 1642cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = ImplGetBreakIterator(); 1643cdf0e10cSrcweir 1644cdf0e10cSrcweir Selection aSel( maSelection ); 1645cdf0e10cSrcweir bool bWord = rKEvt.GetKeyCode().IsMod1(); 1646cdf0e10cSrcweir bool bSelect = rKEvt.GetKeyCode().IsShift(); 1647cdf0e10cSrcweir bool bGoLeft = (nCode == KEY_LEFT); 1648cdf0e10cSrcweir bool bGoRight = (nCode == KEY_RIGHT); 1649cdf0e10cSrcweir bool bGoHome = (nCode == KEY_HOME); 1650cdf0e10cSrcweir bool bGoEnd = (nCode == KEY_END); 1651cdf0e10cSrcweir 1652cdf0e10cSrcweir switch( nCode ) 1653cdf0e10cSrcweir { 1654cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_FORWARD: 1655cdf0e10cSrcweir bGoRight = bWord = true;break; 1656cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_FORWARD: 1657cdf0e10cSrcweir bGoRight = bSelect = bWord = true;break; 1658cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_BACKWARD: 1659cdf0e10cSrcweir bGoLeft = bWord = true;break; 1660cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_BACKWARD: 1661cdf0e10cSrcweir bGoLeft = bSelect = bWord = true;break; 1662cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE: 1663cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH: 1664cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT: 1665cdf0e10cSrcweir bSelect = true; 1666cdf0e10cSrcweir // fallthrough intended 1667cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE: 1668cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH: 1669cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT: 1670cdf0e10cSrcweir bGoHome = true;break; 1671cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_LINE: 1672cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH: 1673cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_DOCUMENT: 1674cdf0e10cSrcweir bSelect = true; 1675cdf0e10cSrcweir // fallthrough intended 1676cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_LINE: 1677cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH: 1678cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT: 1679cdf0e10cSrcweir bGoEnd = true;break; 1680cdf0e10cSrcweir default: 1681cdf0e10cSrcweir break; 1682cdf0e10cSrcweir }; 1683cdf0e10cSrcweir 1684cdf0e10cSrcweir // Range wird in ImplSetSelection geprueft... 1685cdf0e10cSrcweir if ( bGoLeft && aSel.Max() ) 1686cdf0e10cSrcweir { 1687cdf0e10cSrcweir if ( bWord ) 1688cdf0e10cSrcweir { 1689cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->getWordBoundary( maText, aSel.Max(), GetSettings().GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES, sal_True ); 1690cdf0e10cSrcweir if ( aBoundary.startPos == aSel.Max() ) 1691cdf0e10cSrcweir aBoundary = xBI->previousWord( maText, aSel.Max(), GetSettings().GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES ); 1692cdf0e10cSrcweir aSel.Max() = aBoundary.startPos; 1693cdf0e10cSrcweir } 1694cdf0e10cSrcweir else 1695cdf0e10cSrcweir { 1696cdf0e10cSrcweir sal_Int32 nCount = 1; 1697cdf0e10cSrcweir aSel.Max() = xBI->previousCharacters( maText, aSel.Max(), GetSettings().GetLocale(), i18n::CharacterIteratorMode::SKIPCHARACTER, nCount, nCount ); 1698cdf0e10cSrcweir } 1699cdf0e10cSrcweir } 1700cdf0e10cSrcweir else if ( bGoRight && ( aSel.Max() < maText.Len() ) ) 1701cdf0e10cSrcweir { 1702cdf0e10cSrcweir if ( bWord ) 1703cdf0e10cSrcweir { 1704cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->nextWord( maText, aSel.Max(), GetSettings().GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES ); 1705cdf0e10cSrcweir aSel.Max() = aBoundary.startPos; 1706cdf0e10cSrcweir } 1707cdf0e10cSrcweir else 1708cdf0e10cSrcweir { 1709cdf0e10cSrcweir sal_Int32 nCount = 1; 1710cdf0e10cSrcweir aSel.Max() = xBI->nextCharacters( maText, aSel.Max(), GetSettings().GetLocale(), i18n::CharacterIteratorMode::SKIPCHARACTER, nCount, nCount ); 1711cdf0e10cSrcweir } 1712cdf0e10cSrcweir } 1713cdf0e10cSrcweir else if ( bGoHome ) 1714cdf0e10cSrcweir { 1715cdf0e10cSrcweir aSel.Max() = 0; 1716cdf0e10cSrcweir } 1717cdf0e10cSrcweir else if ( bGoEnd ) 1718cdf0e10cSrcweir { 1719cdf0e10cSrcweir aSel.Max() = 0xFFFF; 1720cdf0e10cSrcweir } 1721cdf0e10cSrcweir 1722cdf0e10cSrcweir if ( !bSelect ) 1723cdf0e10cSrcweir aSel.Min() = aSel.Max(); 1724cdf0e10cSrcweir 1725cdf0e10cSrcweir if ( aSel != GetSelection() ) 1726cdf0e10cSrcweir { 1727cdf0e10cSrcweir ImplSetSelection( aSel ); 1728cdf0e10cSrcweir ImplCopyToSelectionClipboard(); 1729cdf0e10cSrcweir } 1730cdf0e10cSrcweir 1731cdf0e10cSrcweir if ( bGoEnd && maAutocompleteHdl.IsSet() && !rKEvt.GetKeyCode().GetModifier() ) 1732cdf0e10cSrcweir { 1733cdf0e10cSrcweir if ( (maSelection.Min() == maSelection.Max()) && (maSelection.Min() == maText.Len()) ) 1734cdf0e10cSrcweir { 1735cdf0e10cSrcweir meAutocompleteAction = AUTOCOMPLETE_KEYINPUT; 1736cdf0e10cSrcweir maAutocompleteHdl.Call( this ); 1737cdf0e10cSrcweir } 1738cdf0e10cSrcweir } 1739cdf0e10cSrcweir 1740cdf0e10cSrcweir bDone = sal_True; 1741cdf0e10cSrcweir } 1742cdf0e10cSrcweir } 1743cdf0e10cSrcweir break; 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_BACKWARD: 1746cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_FORWARD: 1747cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_LINE: 1748cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_END_OF_LINE: 1749cdf0e10cSrcweir case KEY_BACKSPACE: 1750cdf0e10cSrcweir case KEY_DELETE: 1751cdf0e10cSrcweir { 1752cdf0e10cSrcweir if ( !mbReadOnly && !rKEvt.GetKeyCode().IsMod2() ) 1753cdf0e10cSrcweir { 1754cdf0e10cSrcweir sal_uInt8 nDel = (nCode == KEY_DELETE) ? EDIT_DEL_RIGHT : EDIT_DEL_LEFT; 1755cdf0e10cSrcweir sal_uInt8 nMode = rKEvt.GetKeyCode().IsMod1() ? EDIT_DELMODE_RESTOFWORD : EDIT_DELMODE_SIMPLE; 1756cdf0e10cSrcweir if ( (nMode == EDIT_DELMODE_RESTOFWORD) && rKEvt.GetKeyCode().IsShift() ) 1757cdf0e10cSrcweir nMode = EDIT_DELMODE_RESTOFCONTENT; 1758cdf0e10cSrcweir switch( nCode ) 1759cdf0e10cSrcweir { 1760cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_BACKWARD: 1761cdf0e10cSrcweir nDel = EDIT_DEL_LEFT; 1762cdf0e10cSrcweir nMode = EDIT_DELMODE_RESTOFWORD; 1763cdf0e10cSrcweir break; 1764cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_FORWARD: 1765cdf0e10cSrcweir nDel = EDIT_DEL_RIGHT; 1766cdf0e10cSrcweir nMode = EDIT_DELMODE_RESTOFWORD; 1767cdf0e10cSrcweir break; 1768cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_LINE: 1769cdf0e10cSrcweir nDel = EDIT_DEL_LEFT; 1770cdf0e10cSrcweir nMode = EDIT_DELMODE_RESTOFCONTENT; 1771cdf0e10cSrcweir break; 1772cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_END_OF_LINE: 1773cdf0e10cSrcweir nDel = EDIT_DEL_RIGHT; 1774cdf0e10cSrcweir nMode = EDIT_DELMODE_RESTOFCONTENT; 1775cdf0e10cSrcweir break; 1776cdf0e10cSrcweir default: break; 1777cdf0e10cSrcweir } 1778cdf0e10cSrcweir xub_StrLen nOldLen = maText.Len(); 1779cdf0e10cSrcweir ImplDelete( maSelection, nDel, nMode ); 1780cdf0e10cSrcweir if ( maText.Len() != nOldLen ) 1781cdf0e10cSrcweir ImplModified(); 1782cdf0e10cSrcweir bDone = sal_True; 1783cdf0e10cSrcweir } 1784cdf0e10cSrcweir } 1785cdf0e10cSrcweir break; 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir case KEY_INSERT: 1788cdf0e10cSrcweir { 1789cdf0e10cSrcweir if ( !mpIMEInfos && !mbReadOnly && !rKEvt.GetKeyCode().IsMod2() ) 1790cdf0e10cSrcweir { 1791cdf0e10cSrcweir SetInsertMode( !mbInsertMode ); 1792cdf0e10cSrcweir bDone = sal_True; 1793cdf0e10cSrcweir } 1794cdf0e10cSrcweir } 1795cdf0e10cSrcweir break; 1796cdf0e10cSrcweir 1797cdf0e10cSrcweir /* #i101255# disable autocomplete tab forward/backward 1798cdf0e10cSrcweir users expect tab/shif-tab to move the focus to other controls 1799cdf0e10cSrcweir not suddenly to cycle the autocompletion 1800cdf0e10cSrcweir case KEY_TAB: 1801cdf0e10cSrcweir { 1802cdf0e10cSrcweir if ( !mbReadOnly && maAutocompleteHdl.IsSet() && 1803cdf0e10cSrcweir maSelection.Min() && (maSelection.Min() == maText.Len()) && 1804cdf0e10cSrcweir !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsMod2() ) 1805cdf0e10cSrcweir { 1806cdf0e10cSrcweir // Kein Autocomplete wenn alles Selektiert oder Edit leer, weil dann 1807cdf0e10cSrcweir // keine vernuenftige Tab-Steuerung! 1808cdf0e10cSrcweir if ( rKEvt.GetKeyCode().IsShift() ) 1809cdf0e10cSrcweir meAutocompleteAction = AUTOCOMPLETE_TABBACKWARD; 1810cdf0e10cSrcweir else 1811cdf0e10cSrcweir meAutocompleteAction = AUTOCOMPLETE_TABFORWARD; 1812cdf0e10cSrcweir 1813cdf0e10cSrcweir maAutocompleteHdl.Call( this ); 1814cdf0e10cSrcweir 1815cdf0e10cSrcweir // Wurde nichts veraendert, dann TAB fuer DialogControl 1816cdf0e10cSrcweir if ( GetSelection().Len() ) 1817cdf0e10cSrcweir bDone = sal_True; 1818cdf0e10cSrcweir } 1819cdf0e10cSrcweir } 1820cdf0e10cSrcweir break; 1821cdf0e10cSrcweir */ 1822cdf0e10cSrcweir 1823cdf0e10cSrcweir default: 1824cdf0e10cSrcweir { 1825cdf0e10cSrcweir if ( IsCharInput( rKEvt ) ) 1826cdf0e10cSrcweir { 1827cdf0e10cSrcweir bDone = sal_True; // Auch bei ReadOnly die Zeichen schlucken. 1828cdf0e10cSrcweir if ( !mbReadOnly ) 1829cdf0e10cSrcweir { 1830cdf0e10cSrcweir ImplInsertText( rKEvt.GetCharCode(), 0, sal_True ); 1831cdf0e10cSrcweir if ( maAutocompleteHdl.IsSet() ) 1832cdf0e10cSrcweir { 1833cdf0e10cSrcweir if ( (maSelection.Min() == maSelection.Max()) && (maSelection.Min() == maText.Len()) ) 1834cdf0e10cSrcweir { 1835cdf0e10cSrcweir meAutocompleteAction = AUTOCOMPLETE_KEYINPUT; 1836cdf0e10cSrcweir maAutocompleteHdl.Call( this ); 1837cdf0e10cSrcweir } 1838cdf0e10cSrcweir } 1839cdf0e10cSrcweir } 1840cdf0e10cSrcweir } 1841cdf0e10cSrcweir } 1842cdf0e10cSrcweir } 1843cdf0e10cSrcweir } 1844cdf0e10cSrcweir 1845cdf0e10cSrcweir if ( mbInternModified ) 1846cdf0e10cSrcweir ImplModified(); 1847cdf0e10cSrcweir 1848cdf0e10cSrcweir return bDone; 1849cdf0e10cSrcweir } 1850cdf0e10cSrcweir 1851cdf0e10cSrcweir // ----------------------------------------------------------------------- 1852cdf0e10cSrcweir 1853cdf0e10cSrcweir void Edit::KeyInput( const KeyEvent& rKEvt ) 1854cdf0e10cSrcweir { 1855cdf0e10cSrcweir if ( mpUpdateDataTimer && !mbIsSubEdit && mpUpdateDataTimer->IsActive() ) 1856cdf0e10cSrcweir mpUpdateDataTimer->Start();//do not update while the user is still travelling in the control 1857cdf0e10cSrcweir 1858cdf0e10cSrcweir if ( mpSubEdit || !ImplHandleKeyEvent( rKEvt ) ) 1859cdf0e10cSrcweir Control::KeyInput( rKEvt ); 1860cdf0e10cSrcweir } 1861cdf0e10cSrcweir 1862cdf0e10cSrcweir // ----------------------------------------------------------------------- 1863cdf0e10cSrcweir 1864cdf0e10cSrcweir void Edit::FillLayoutData() const 1865cdf0e10cSrcweir { 1866cdf0e10cSrcweir mpControlData->mpLayoutData = new vcl::ControlLayoutData(); 1867cdf0e10cSrcweir const_cast<Edit*>(this)->ImplRepaint( 0, STRING_LEN, true ); 1868cdf0e10cSrcweir } 1869cdf0e10cSrcweir 1870cdf0e10cSrcweir // ----------------------------------------------------------------------- 1871cdf0e10cSrcweir 1872cdf0e10cSrcweir void Edit::Paint( const Rectangle& ) 1873cdf0e10cSrcweir { 1874cdf0e10cSrcweir if ( !mpSubEdit ) 1875cdf0e10cSrcweir ImplRepaint(); 1876cdf0e10cSrcweir } 1877cdf0e10cSrcweir 1878cdf0e10cSrcweir // ----------------------------------------------------------------------- 1879cdf0e10cSrcweir 1880cdf0e10cSrcweir void Edit::Resize() 1881cdf0e10cSrcweir { 1882cdf0e10cSrcweir if ( !mpSubEdit && IsReallyVisible() ) 1883cdf0e10cSrcweir { 1884cdf0e10cSrcweir Control::Resize(); 1885cdf0e10cSrcweir // Wegen vertikaler Zentrierung... 1886cdf0e10cSrcweir mnXOffset = 0; 1887cdf0e10cSrcweir ImplAlign(); 1888cdf0e10cSrcweir Invalidate(); 1889cdf0e10cSrcweir ImplShowCursor(); 1890cdf0e10cSrcweir } 1891cdf0e10cSrcweir } 1892cdf0e10cSrcweir 1893cdf0e10cSrcweir // ----------------------------------------------------------------------- 1894cdf0e10cSrcweir 1895cdf0e10cSrcweir void Edit::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) 1896cdf0e10cSrcweir { 1897cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True ); 1898cdf0e10cSrcweir 1899cdf0e10cSrcweir Point aPos = pDev->LogicToPixel( rPos ); 1900cdf0e10cSrcweir Size aSize = pDev->LogicToPixel( rSize ); 1901cdf0e10cSrcweir Font aFont = GetDrawPixelFont( pDev ); 1902cdf0e10cSrcweir OutDevType eOutDevType = pDev->GetOutDevType(); 1903cdf0e10cSrcweir 1904cdf0e10cSrcweir pDev->Push(); 1905cdf0e10cSrcweir pDev->SetMapMode(); 1906cdf0e10cSrcweir pDev->SetFont( aFont ); 1907cdf0e10cSrcweir pDev->SetTextFillColor(); 1908cdf0e10cSrcweir 1909cdf0e10cSrcweir // Border/Background 1910cdf0e10cSrcweir pDev->SetLineColor(); 1911cdf0e10cSrcweir pDev->SetFillColor(); 1912cdf0e10cSrcweir sal_Bool bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER); 1913cdf0e10cSrcweir sal_Bool bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground(); 1914cdf0e10cSrcweir if ( bBorder || bBackground ) 1915cdf0e10cSrcweir { 1916cdf0e10cSrcweir Rectangle aRect( aPos, aSize ); 1917cdf0e10cSrcweir if ( bBorder ) 1918cdf0e10cSrcweir { 1919cdf0e10cSrcweir ImplDrawFrame( pDev, aRect ); 1920cdf0e10cSrcweir } 1921cdf0e10cSrcweir if ( bBackground ) 1922cdf0e10cSrcweir { 1923cdf0e10cSrcweir pDev->SetFillColor( GetControlBackground() ); 1924cdf0e10cSrcweir pDev->DrawRect( aRect ); 1925cdf0e10cSrcweir } 1926cdf0e10cSrcweir } 1927cdf0e10cSrcweir 1928cdf0e10cSrcweir // Inhalt 1929cdf0e10cSrcweir if ( ( nFlags & WINDOW_DRAW_MONO ) || ( eOutDevType == OUTDEV_PRINTER ) ) 1930cdf0e10cSrcweir pDev->SetTextColor( Color( COL_BLACK ) ); 1931cdf0e10cSrcweir else 1932cdf0e10cSrcweir { 1933cdf0e10cSrcweir if ( !(nFlags & WINDOW_DRAW_NODISABLE ) && !IsEnabled() ) 1934cdf0e10cSrcweir { 1935cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 1936cdf0e10cSrcweir pDev->SetTextColor( rStyleSettings.GetDisableColor() ); 1937cdf0e10cSrcweir } 1938cdf0e10cSrcweir else 1939cdf0e10cSrcweir { 1940cdf0e10cSrcweir pDev->SetTextColor( GetTextColor() ); 1941cdf0e10cSrcweir } 1942cdf0e10cSrcweir } 1943cdf0e10cSrcweir 1944cdf0e10cSrcweir XubString aText = ImplGetText(); 1945cdf0e10cSrcweir long nTextHeight = pDev->GetTextHeight(); 1946cdf0e10cSrcweir long nTextWidth = pDev->GetTextWidth( aText ); 1947cdf0e10cSrcweir long nOnePixel = GetDrawPixel( pDev, 1 ); 1948cdf0e10cSrcweir long nOffX = 3*nOnePixel; 1949cdf0e10cSrcweir long nOffY = (aSize.Height() - nTextHeight) / 2; 1950cdf0e10cSrcweir 1951cdf0e10cSrcweir // Clipping? 1952cdf0e10cSrcweir if ( (nOffY < 0) || 1953cdf0e10cSrcweir ((nOffY+nTextHeight) > aSize.Height()) || 1954cdf0e10cSrcweir ((nOffX+nTextWidth) > aSize.Width()) ) 1955cdf0e10cSrcweir { 1956cdf0e10cSrcweir Rectangle aClip( aPos, aSize ); 1957cdf0e10cSrcweir if ( nTextHeight > aSize.Height() ) 1958cdf0e10cSrcweir aClip.Bottom() += nTextHeight-aSize.Height()+1; // Damit HP-Drucker nicht 'weg-optimieren' 1959cdf0e10cSrcweir pDev->IntersectClipRegion( aClip ); 1960cdf0e10cSrcweir } 1961cdf0e10cSrcweir 1962cdf0e10cSrcweir if ( GetStyle() & WB_CENTER ) 1963cdf0e10cSrcweir { 1964cdf0e10cSrcweir aPos.X() += (aSize.Width() - nTextWidth) / 2; 1965cdf0e10cSrcweir nOffX = 0; 1966cdf0e10cSrcweir } 1967cdf0e10cSrcweir else if ( GetStyle() & WB_RIGHT ) 1968cdf0e10cSrcweir { 1969cdf0e10cSrcweir aPos.X() += aSize.Width() - nTextWidth; 1970cdf0e10cSrcweir nOffX = -nOffX; 1971cdf0e10cSrcweir } 1972cdf0e10cSrcweir 1973cdf0e10cSrcweir pDev->DrawText( Point( aPos.X() + nOffX, aPos.Y() + nOffY ), aText ); 1974cdf0e10cSrcweir pDev->Pop(); 1975cdf0e10cSrcweir 1976cdf0e10cSrcweir if ( GetSubEdit() ) 1977cdf0e10cSrcweir { 1978cdf0e10cSrcweir GetSubEdit()->Draw( pDev, rPos, rSize, nFlags ); 1979cdf0e10cSrcweir } 1980cdf0e10cSrcweir } 1981cdf0e10cSrcweir 1982cdf0e10cSrcweir // ----------------------------------------------------------------------- 1983cdf0e10cSrcweir 1984cdf0e10cSrcweir void Edit::ImplInvalidateOutermostBorder( Window* pWin ) 1985cdf0e10cSrcweir { 1986cdf0e10cSrcweir // allow control to show focused state 1987cdf0e10cSrcweir Window *pInvalWin = pWin, *pBorder = pWin; 1988cdf0e10cSrcweir while( ( pBorder = pInvalWin->GetWindow( WINDOW_BORDER ) ) != pInvalWin && pBorder && 1989cdf0e10cSrcweir pInvalWin->ImplGetFrame() == pBorder->ImplGetFrame() ) 1990cdf0e10cSrcweir { 1991cdf0e10cSrcweir pInvalWin = pBorder; 1992cdf0e10cSrcweir } 1993cdf0e10cSrcweir 1994cdf0e10cSrcweir pInvalWin->Invalidate( INVALIDATE_CHILDREN | INVALIDATE_UPDATE ); 1995cdf0e10cSrcweir } 1996cdf0e10cSrcweir 1997cdf0e10cSrcweir void Edit::GetFocus() 1998cdf0e10cSrcweir { 1999cdf0e10cSrcweir if ( mpSubEdit ) 2000cdf0e10cSrcweir mpSubEdit->ImplGrabFocus( GetGetFocusFlags() ); 2001cdf0e10cSrcweir else if ( !mbActivePopup ) 2002cdf0e10cSrcweir { 2003cdf0e10cSrcweir maUndoText = maText; 2004cdf0e10cSrcweir 2005cdf0e10cSrcweir sal_uLong nSelOptions = GetSettings().GetStyleSettings().GetSelectionOptions(); 2006cdf0e10cSrcweir if ( !( GetStyle() & (WB_NOHIDESELECTION|WB_READONLY) ) 2007cdf0e10cSrcweir && ( GetGetFocusFlags() & (GETFOCUS_INIT|GETFOCUS_TAB|GETFOCUS_CURSOR|GETFOCUS_MNEMONIC) ) ) 2008cdf0e10cSrcweir { 2009cdf0e10cSrcweir if ( nSelOptions & SELECTION_OPTION_SHOWFIRST ) 2010cdf0e10cSrcweir { 2011cdf0e10cSrcweir maSelection.Min() = maText.Len(); 2012cdf0e10cSrcweir maSelection.Max() = 0; 2013cdf0e10cSrcweir } 2014cdf0e10cSrcweir else 2015cdf0e10cSrcweir { 2016cdf0e10cSrcweir maSelection.Min() = 0; 2017cdf0e10cSrcweir maSelection.Max() = maText.Len(); 2018cdf0e10cSrcweir } 2019cdf0e10cSrcweir if ( mbIsSubEdit ) 2020cdf0e10cSrcweir ((Edit*)GetParent())->ImplCallEventListeners( VCLEVENT_EDIT_SELECTIONCHANGED ); 2021cdf0e10cSrcweir else 2022cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_EDIT_SELECTIONCHANGED ); 2023cdf0e10cSrcweir } 2024cdf0e10cSrcweir 2025cdf0e10cSrcweir ImplShowCursor(); 2026cdf0e10cSrcweir 2027cdf0e10cSrcweir // FIXME: this is currently only on aqua 2028cdf0e10cSrcweir // check for other platforms that need similar handling 2029cdf0e10cSrcweir if( ImplGetSVData()->maNWFData.mbNoFocusRects && 2030cdf0e10cSrcweir IsNativeWidgetEnabled() && 2031cdf0e10cSrcweir IsNativeControlSupported( CTRL_EDITBOX, PART_ENTIRE_CONTROL ) ) 2032cdf0e10cSrcweir { 2033cdf0e10cSrcweir ImplInvalidateOutermostBorder( mbIsSubEdit ? GetParent() : this ); 2034cdf0e10cSrcweir } 2035cdf0e10cSrcweir else if ( maSelection.Len() ) 2036cdf0e10cSrcweir { 2037cdf0e10cSrcweir // Selektion malen 2038cdf0e10cSrcweir if ( !HasPaintEvent() ) 2039cdf0e10cSrcweir ImplInvalidateOrRepaint(); 2040cdf0e10cSrcweir else 2041cdf0e10cSrcweir Invalidate(); 2042cdf0e10cSrcweir } 2043cdf0e10cSrcweir 2044cdf0e10cSrcweir SetInputContext( InputContext( GetFont(), !IsReadOnly() ? INPUTCONTEXT_TEXT|INPUTCONTEXT_EXTTEXTINPUT : 0 ) ); 2045cdf0e10cSrcweir } 2046cdf0e10cSrcweir 2047cdf0e10cSrcweir Control::GetFocus(); 2048cdf0e10cSrcweir } 2049cdf0e10cSrcweir 2050cdf0e10cSrcweir // ----------------------------------------------------------------------- 2051cdf0e10cSrcweir 2052cdf0e10cSrcweir Window* Edit::GetPreferredKeyInputWindow() 2053cdf0e10cSrcweir { 2054cdf0e10cSrcweir if ( mpSubEdit ) 2055cdf0e10cSrcweir return mpSubEdit->GetPreferredKeyInputWindow(); 2056cdf0e10cSrcweir else 2057cdf0e10cSrcweir return this; 2058cdf0e10cSrcweir } 2059cdf0e10cSrcweir 2060cdf0e10cSrcweir // ----------------------------------------------------------------------- 2061cdf0e10cSrcweir 2062cdf0e10cSrcweir void Edit::LoseFocus() 2063cdf0e10cSrcweir { 2064cdf0e10cSrcweir if ( mpUpdateDataTimer && !mbIsSubEdit && mpUpdateDataTimer->IsActive() ) 2065cdf0e10cSrcweir { 2066cdf0e10cSrcweir //notify an update latest when the focus is lost 2067cdf0e10cSrcweir mpUpdateDataTimer->Stop(); 2068cdf0e10cSrcweir mpUpdateDataTimer->Timeout(); 2069cdf0e10cSrcweir } 2070cdf0e10cSrcweir 2071cdf0e10cSrcweir if ( !mpSubEdit ) 2072cdf0e10cSrcweir { 2073cdf0e10cSrcweir // FIXME: this is currently only on aqua 2074cdf0e10cSrcweir // check for other platforms that need similar handling 2075cdf0e10cSrcweir if( ImplGetSVData()->maNWFData.mbNoFocusRects && 2076cdf0e10cSrcweir IsNativeWidgetEnabled() && 2077cdf0e10cSrcweir IsNativeControlSupported( CTRL_EDITBOX, PART_ENTIRE_CONTROL ) ) 2078cdf0e10cSrcweir { 2079cdf0e10cSrcweir ImplInvalidateOutermostBorder( mbIsSubEdit ? GetParent() : this ); 2080cdf0e10cSrcweir } 2081cdf0e10cSrcweir 2082cdf0e10cSrcweir if ( !mbActivePopup && !( GetStyle() & WB_NOHIDESELECTION ) && maSelection.Len() ) 2083cdf0e10cSrcweir ImplInvalidateOrRepaint(); // Selektion malen 2084cdf0e10cSrcweir } 2085cdf0e10cSrcweir 2086cdf0e10cSrcweir Control::LoseFocus(); 2087cdf0e10cSrcweir } 2088cdf0e10cSrcweir 2089cdf0e10cSrcweir // ----------------------------------------------------------------------- 2090cdf0e10cSrcweir 2091cdf0e10cSrcweir void Edit::Command( const CommandEvent& rCEvt ) 2092cdf0e10cSrcweir { 2093cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 2094cdf0e10cSrcweir { 2095cdf0e10cSrcweir PopupMenu* pPopup = Edit::CreatePopupMenu(); 2096cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 2097cdf0e10cSrcweir if ( rStyleSettings.GetOptions() & STYLE_OPTION_HIDEDISABLED ) 2098cdf0e10cSrcweir pPopup->SetMenuFlags( MENU_FLAG_HIDEDISABLEDENTRIES ); 2099cdf0e10cSrcweir 2100cdf0e10cSrcweir if ( !maSelection.Len() ) 2101cdf0e10cSrcweir { 2102cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_CUT, sal_False ); 2103cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_COPY, sal_False ); 2104cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_DELETE, sal_False ); 2105cdf0e10cSrcweir } 2106cdf0e10cSrcweir 2107cdf0e10cSrcweir if ( IsReadOnly() ) 2108cdf0e10cSrcweir { 2109cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_CUT, sal_False ); 2110cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_PASTE, sal_False ); 2111cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_DELETE, sal_False ); 2112cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_INSERTSYMBOL, sal_False ); 2113cdf0e10cSrcweir } 2114cdf0e10cSrcweir else 2115cdf0e10cSrcweir { 2116cdf0e10cSrcweir // Paste nur, wenn Text im Clipboard 2117cdf0e10cSrcweir sal_Bool bData = sal_False; 2118cdf0e10cSrcweir uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetClipboard(); 2119cdf0e10cSrcweir if ( xClipboard.is() ) 2120cdf0e10cSrcweir { 2121cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 2122cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xDataObj = xClipboard->getContents(); 2123cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 2124cdf0e10cSrcweir if ( xDataObj.is() ) 2125cdf0e10cSrcweir { 2126cdf0e10cSrcweir datatransfer::DataFlavor aFlavor; 2127cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor ); 2128cdf0e10cSrcweir bData = xDataObj->isDataFlavorSupported( aFlavor ); 2129cdf0e10cSrcweir } 2130cdf0e10cSrcweir } 2131cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_PASTE, bData ); 2132cdf0e10cSrcweir } 2133cdf0e10cSrcweir 2134cdf0e10cSrcweir if ( maUndoText == maText ) 2135cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_UNDO, sal_False ); 2136cdf0e10cSrcweir if ( ( maSelection.Min() == 0 ) && ( maSelection.Max() == maText.Len() ) ) 2137cdf0e10cSrcweir pPopup->EnableItem( SV_MENU_EDIT_SELECTALL, sal_False ); 2138cdf0e10cSrcweir if ( !pImplFncGetSpecialChars ) 2139cdf0e10cSrcweir { 2140cdf0e10cSrcweir sal_uInt16 nPos = pPopup->GetItemPos( SV_MENU_EDIT_INSERTSYMBOL ); 2141cdf0e10cSrcweir pPopup->RemoveItem( nPos ); 2142cdf0e10cSrcweir pPopup->RemoveItem( nPos-1 ); 2143cdf0e10cSrcweir } 2144cdf0e10cSrcweir 2145cdf0e10cSrcweir mbActivePopup = sal_True; 2146cdf0e10cSrcweir Selection aSaveSel = GetSelection(); // Falls jemand in Get/LoseFocus die Selektion verbiegt, z.B. URL-Zeile... 2147cdf0e10cSrcweir Point aPos = rCEvt.GetMousePosPixel(); 2148cdf0e10cSrcweir if ( !rCEvt.IsMouseEvent() ) 2149cdf0e10cSrcweir { 2150cdf0e10cSrcweir // !!! Irgendwann einmal Menu zentriert in der Selektion anzeigen !!! 2151cdf0e10cSrcweir Size aSize = GetOutputSizePixel(); 2152cdf0e10cSrcweir aPos = Point( aSize.Width()/2, aSize.Height()/2 ); 2153cdf0e10cSrcweir } 2154cdf0e10cSrcweir sal_uInt16 n = pPopup->Execute( this, aPos ); 2155cdf0e10cSrcweir Edit::DeletePopupMenu( pPopup ); 2156cdf0e10cSrcweir SetSelection( aSaveSel ); 2157cdf0e10cSrcweir switch ( n ) 2158cdf0e10cSrcweir { 2159cdf0e10cSrcweir case SV_MENU_EDIT_UNDO: 2160cdf0e10cSrcweir Undo(); 2161cdf0e10cSrcweir ImplModified(); 2162cdf0e10cSrcweir break; 2163cdf0e10cSrcweir case SV_MENU_EDIT_CUT: 2164cdf0e10cSrcweir Cut(); 2165cdf0e10cSrcweir ImplModified(); 2166cdf0e10cSrcweir break; 2167cdf0e10cSrcweir case SV_MENU_EDIT_COPY: 2168cdf0e10cSrcweir Copy(); 2169cdf0e10cSrcweir break; 2170cdf0e10cSrcweir case SV_MENU_EDIT_PASTE: 2171cdf0e10cSrcweir Paste(); 2172cdf0e10cSrcweir ImplModified(); 2173cdf0e10cSrcweir break; 2174cdf0e10cSrcweir case SV_MENU_EDIT_DELETE: 2175cdf0e10cSrcweir DeleteSelected(); 2176cdf0e10cSrcweir ImplModified(); 2177cdf0e10cSrcweir break; 2178cdf0e10cSrcweir case SV_MENU_EDIT_SELECTALL: 2179cdf0e10cSrcweir ImplSetSelection( Selection( 0, maText.Len() ) ); 2180cdf0e10cSrcweir break; 2181cdf0e10cSrcweir case SV_MENU_EDIT_INSERTSYMBOL: 2182cdf0e10cSrcweir { 2183cdf0e10cSrcweir XubString aChars = pImplFncGetSpecialChars( this, GetFont() ); 2184cdf0e10cSrcweir SetSelection( aSaveSel ); 2185cdf0e10cSrcweir if ( aChars.Len() ) 2186cdf0e10cSrcweir { 2187cdf0e10cSrcweir ImplInsertText( aChars ); 2188cdf0e10cSrcweir ImplModified(); 2189cdf0e10cSrcweir } 2190cdf0e10cSrcweir } 2191cdf0e10cSrcweir break; 2192cdf0e10cSrcweir } 2193cdf0e10cSrcweir mbActivePopup = sal_False; 2194cdf0e10cSrcweir } 2195cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_VOICE ) 2196cdf0e10cSrcweir { 2197cdf0e10cSrcweir const CommandVoiceData* pData = rCEvt.GetVoiceData(); 2198cdf0e10cSrcweir if ( pData->GetType() == VOICECOMMANDTYPE_DICTATION ) 2199cdf0e10cSrcweir { 2200cdf0e10cSrcweir switch ( pData->GetCommand() ) 2201cdf0e10cSrcweir { 2202cdf0e10cSrcweir case DICTATIONCOMMAND_UNKNOWN: 2203cdf0e10cSrcweir { 2204cdf0e10cSrcweir ReplaceSelected( pData->GetText() ); 2205cdf0e10cSrcweir } 2206cdf0e10cSrcweir break; 2207cdf0e10cSrcweir case DICTATIONCOMMAND_LEFT: 2208cdf0e10cSrcweir { 2209cdf0e10cSrcweir ImplHandleKeyEvent( KeyEvent( 0, KeyCode( KEY_LEFT, KEY_MOD1 ) ) ); 2210cdf0e10cSrcweir } 2211cdf0e10cSrcweir break; 2212cdf0e10cSrcweir case DICTATIONCOMMAND_RIGHT: 2213cdf0e10cSrcweir { 2214cdf0e10cSrcweir ImplHandleKeyEvent( KeyEvent( 0, KeyCode( KEY_RIGHT, KEY_MOD1 ) ) ); 2215cdf0e10cSrcweir } 2216cdf0e10cSrcweir break; 2217cdf0e10cSrcweir case DICTATIONCOMMAND_UNDO: 2218cdf0e10cSrcweir { 2219cdf0e10cSrcweir Undo(); 2220cdf0e10cSrcweir } 2221cdf0e10cSrcweir break; 2222cdf0e10cSrcweir case DICTATIONCOMMAND_DEL: 2223cdf0e10cSrcweir { 2224cdf0e10cSrcweir ImplHandleKeyEvent( KeyEvent( 0, KeyCode( KEY_LEFT, KEY_MOD1|KEY_SHIFT ) ) ); 2225cdf0e10cSrcweir DeleteSelected(); 2226cdf0e10cSrcweir } 2227cdf0e10cSrcweir break; 2228cdf0e10cSrcweir } 2229cdf0e10cSrcweir } 2230cdf0e10cSrcweir } 2231cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_STARTEXTTEXTINPUT ) 2232cdf0e10cSrcweir { 2233cdf0e10cSrcweir DeleteSelected(); 2234cdf0e10cSrcweir delete mpIMEInfos; 2235cdf0e10cSrcweir xub_StrLen nPos = (xub_StrLen)maSelection.Max(); 2236cdf0e10cSrcweir mpIMEInfos = new Impl_IMEInfos( nPos, maText.Copy( nPos ) ); 2237cdf0e10cSrcweir mpIMEInfos->bWasCursorOverwrite = !IsInsertMode(); 2238cdf0e10cSrcweir } 2239cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_ENDEXTTEXTINPUT ) 2240cdf0e10cSrcweir { 2241cdf0e10cSrcweir sal_Bool bInsertMode = !mpIMEInfos->bWasCursorOverwrite; 2242cdf0e10cSrcweir delete mpIMEInfos; 2243cdf0e10cSrcweir mpIMEInfos = NULL; 2244cdf0e10cSrcweir // Font wieder ohne Attribute einstellen, wird jetzt im Repaint nicht 2245cdf0e10cSrcweir // mehr neu initialisiert 2246cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False ); 2247cdf0e10cSrcweir 2248cdf0e10cSrcweir SetInsertMode( bInsertMode ); 2249cdf0e10cSrcweir 2250cdf0e10cSrcweir ImplModified(); 2251cdf0e10cSrcweir 2252cdf0e10cSrcweir // #i25161# call auto complete handler for ext text commit also 2253cdf0e10cSrcweir if ( maAutocompleteHdl.IsSet() ) 2254cdf0e10cSrcweir { 2255cdf0e10cSrcweir if ( (maSelection.Min() == maSelection.Max()) && (maSelection.Min() == maText.Len()) ) 2256cdf0e10cSrcweir { 2257cdf0e10cSrcweir meAutocompleteAction = AUTOCOMPLETE_KEYINPUT; 2258cdf0e10cSrcweir maAutocompleteHdl.Call( this ); 2259cdf0e10cSrcweir } 2260cdf0e10cSrcweir } 2261cdf0e10cSrcweir } 2262cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_EXTTEXTINPUT ) 2263cdf0e10cSrcweir { 2264cdf0e10cSrcweir const CommandExtTextInputData* pData = rCEvt.GetExtTextInputData(); 2265cdf0e10cSrcweir 2266cdf0e10cSrcweir maText.Erase( mpIMEInfos->nPos, mpIMEInfos->nLen ); 2267cdf0e10cSrcweir maText.Insert( pData->GetText(), mpIMEInfos->nPos ); 2268cdf0e10cSrcweir if ( mpIMEInfos->bWasCursorOverwrite ) 2269cdf0e10cSrcweir { 2270cdf0e10cSrcweir sal_uInt16 nOldIMETextLen = mpIMEInfos->nLen; 2271cdf0e10cSrcweir sal_uInt16 nNewIMETextLen = pData->GetText().Len(); 2272cdf0e10cSrcweir if ( ( nOldIMETextLen > nNewIMETextLen ) && 2273cdf0e10cSrcweir ( nNewIMETextLen < mpIMEInfos->aOldTextAfterStartPos.Len() ) ) 2274cdf0e10cSrcweir { 2275cdf0e10cSrcweir // restore old characters 2276cdf0e10cSrcweir sal_uInt16 nRestore = nOldIMETextLen - nNewIMETextLen; 2277cdf0e10cSrcweir maText.Insert( mpIMEInfos->aOldTextAfterStartPos.Copy( nNewIMETextLen, nRestore ), mpIMEInfos->nPos + nNewIMETextLen ); 2278cdf0e10cSrcweir } 2279cdf0e10cSrcweir else if ( ( nOldIMETextLen < nNewIMETextLen ) && 2280cdf0e10cSrcweir ( nOldIMETextLen < mpIMEInfos->aOldTextAfterStartPos.Len() ) ) 2281cdf0e10cSrcweir { 2282cdf0e10cSrcweir // overwrite 2283cdf0e10cSrcweir sal_uInt16 nOverwrite = nNewIMETextLen - nOldIMETextLen; 2284cdf0e10cSrcweir if ( ( nOldIMETextLen + nOverwrite ) > mpIMEInfos->aOldTextAfterStartPos.Len() ) 2285cdf0e10cSrcweir nOverwrite = mpIMEInfos->aOldTextAfterStartPos.Len() - nOldIMETextLen; 2286cdf0e10cSrcweir maText.Erase( mpIMEInfos->nPos + nNewIMETextLen, nOverwrite ); 2287cdf0e10cSrcweir } 2288cdf0e10cSrcweir } 2289cdf0e10cSrcweir 2290cdf0e10cSrcweir 2291cdf0e10cSrcweir if ( pData->GetTextAttr() ) 2292cdf0e10cSrcweir { 2293cdf0e10cSrcweir mpIMEInfos->CopyAttribs( pData->GetTextAttr(), pData->GetText().Len() ); 2294cdf0e10cSrcweir mpIMEInfos->bCursor = pData->IsCursorVisible(); 2295cdf0e10cSrcweir } 2296cdf0e10cSrcweir else 2297cdf0e10cSrcweir { 2298cdf0e10cSrcweir mpIMEInfos->DestroyAttribs(); 2299cdf0e10cSrcweir } 2300cdf0e10cSrcweir 2301cdf0e10cSrcweir ImplAlignAndPaint(); 2302cdf0e10cSrcweir xub_StrLen nCursorPos = mpIMEInfos->nPos + pData->GetCursorPos(); 2303cdf0e10cSrcweir SetSelection( Selection( nCursorPos, nCursorPos ) ); 2304cdf0e10cSrcweir SetInsertMode( !pData->IsCursorOverwrite() ); 2305cdf0e10cSrcweir 2306cdf0e10cSrcweir if ( pData->IsCursorVisible() ) 2307cdf0e10cSrcweir GetCursor()->Show(); 2308cdf0e10cSrcweir else 2309cdf0e10cSrcweir GetCursor()->Hide(); 2310cdf0e10cSrcweir } 2311cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_CURSORPOS ) 2312cdf0e10cSrcweir { 2313cdf0e10cSrcweir if ( mpIMEInfos ) 2314cdf0e10cSrcweir { 2315cdf0e10cSrcweir xub_StrLen nCursorPos = (sal_uInt16)GetSelection().Max(); 2316cdf0e10cSrcweir SetCursorRect( NULL, GetTextWidth( 2317cdf0e10cSrcweir maText, nCursorPos, mpIMEInfos->nPos+mpIMEInfos->nLen-nCursorPos ) ); 2318cdf0e10cSrcweir } 2319cdf0e10cSrcweir else 2320cdf0e10cSrcweir { 2321cdf0e10cSrcweir SetCursorRect(); 2322cdf0e10cSrcweir } 2323cdf0e10cSrcweir } 2324cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_SELECTIONCHANGE ) 2325cdf0e10cSrcweir { 2326cdf0e10cSrcweir const CommandSelectionChangeData *pData = rCEvt.GetSelectionChangeData(); 2327cdf0e10cSrcweir Selection aSelection( pData->GetStart(), pData->GetEnd() ); 2328cdf0e10cSrcweir SetSelection(aSelection); 2329cdf0e10cSrcweir } 2330cdf0e10cSrcweir else 2331cdf0e10cSrcweir Control::Command( rCEvt ); 2332cdf0e10cSrcweir } 2333cdf0e10cSrcweir 2334cdf0e10cSrcweir // ----------------------------------------------------------------------- 2335cdf0e10cSrcweir 2336cdf0e10cSrcweir void Edit::StateChanged( StateChangedType nType ) 2337cdf0e10cSrcweir { 2338cdf0e10cSrcweir if ( nType == STATE_CHANGE_INITSHOW ) 2339cdf0e10cSrcweir { 2340cdf0e10cSrcweir if ( !mpSubEdit ) 2341cdf0e10cSrcweir { 2342cdf0e10cSrcweir mnXOffset = 0; // Falls vorher GrabFocus, als Groesse noch falsch. 2343cdf0e10cSrcweir ImplAlign(); 2344cdf0e10cSrcweir if ( !mpSubEdit ) 2345cdf0e10cSrcweir ImplShowCursor( sal_False ); 2346cdf0e10cSrcweir } 2347cdf0e10cSrcweir // update background (eventual SetPaintTransparent) 2348cdf0e10cSrcweir ImplInitSettings( sal_False, sal_False, sal_True ); 2349cdf0e10cSrcweir } 2350cdf0e10cSrcweir else if ( nType == STATE_CHANGE_ENABLE ) 2351cdf0e10cSrcweir { 2352cdf0e10cSrcweir if ( !mpSubEdit ) 2353cdf0e10cSrcweir { 2354cdf0e10cSrcweir // Es aendert sich nur die Textfarbe... 2355cdf0e10cSrcweir ImplInvalidateOrRepaint( 0, 0xFFFF ); 2356cdf0e10cSrcweir } 2357cdf0e10cSrcweir } 2358cdf0e10cSrcweir else if ( nType == STATE_CHANGE_STYLE || nType == STATE_CHANGE_MIRRORING ) 2359cdf0e10cSrcweir { 2360cdf0e10cSrcweir WinBits nStyle = GetStyle(); 2361cdf0e10cSrcweir if( nType == STATE_CHANGE_STYLE ) 2362cdf0e10cSrcweir { 2363cdf0e10cSrcweir nStyle = ImplInitStyle( GetStyle() ); 2364cdf0e10cSrcweir SetStyle( nStyle ); 2365cdf0e10cSrcweir } 2366cdf0e10cSrcweir 2367cdf0e10cSrcweir sal_uInt16 nOldAlign = mnAlign; 2368cdf0e10cSrcweir mnAlign = EDIT_ALIGN_LEFT; 2369cdf0e10cSrcweir 2370cdf0e10cSrcweir // --- RTL --- hack: right align until keyinput and cursor travelling works 2371cdf0e10cSrcweir // edits are always RTL disabled 2372cdf0e10cSrcweir // however the parent edits contain the correct setting 2373cdf0e10cSrcweir if( mbIsSubEdit && GetParent()->IsRTLEnabled() ) 2374cdf0e10cSrcweir { 2375cdf0e10cSrcweir if( GetParent()->GetStyle() & WB_LEFT ) 2376cdf0e10cSrcweir mnAlign = EDIT_ALIGN_RIGHT; 2377cdf0e10cSrcweir if ( nType == STATE_CHANGE_MIRRORING ) 2378cdf0e10cSrcweir SetLayoutMode( TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT ); 2379cdf0e10cSrcweir } 2380cdf0e10cSrcweir else if( mbIsSubEdit && !GetParent()->IsRTLEnabled() ) 2381cdf0e10cSrcweir { 2382cdf0e10cSrcweir if ( nType == STATE_CHANGE_MIRRORING ) 2383cdf0e10cSrcweir SetLayoutMode( TEXT_LAYOUT_BIDI_LTR | TEXT_LAYOUT_TEXTORIGIN_LEFT ); 2384cdf0e10cSrcweir } 2385cdf0e10cSrcweir 2386cdf0e10cSrcweir if ( nStyle & WB_RIGHT ) 2387cdf0e10cSrcweir mnAlign = EDIT_ALIGN_RIGHT; 2388cdf0e10cSrcweir else if ( nStyle & WB_CENTER ) 2389cdf0e10cSrcweir mnAlign = EDIT_ALIGN_CENTER; 2390cdf0e10cSrcweir if ( maText.Len() && ( mnAlign != nOldAlign ) ) 2391cdf0e10cSrcweir { 2392cdf0e10cSrcweir ImplAlign(); 2393cdf0e10cSrcweir Invalidate(); 2394cdf0e10cSrcweir } 2395cdf0e10cSrcweir 2396cdf0e10cSrcweir } 2397cdf0e10cSrcweir else if ( nType == STATE_CHANGE_ZOOM ) 2398cdf0e10cSrcweir { 2399cdf0e10cSrcweir if ( !mpSubEdit ) 2400cdf0e10cSrcweir { 2401cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False ); 2402cdf0e10cSrcweir ImplShowCursor( sal_True ); 2403cdf0e10cSrcweir Invalidate(); 2404cdf0e10cSrcweir } 2405cdf0e10cSrcweir } 2406cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFONT ) 2407cdf0e10cSrcweir { 2408cdf0e10cSrcweir if ( !mpSubEdit ) 2409cdf0e10cSrcweir { 2410cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False ); 2411cdf0e10cSrcweir ImplShowCursor(); 2412cdf0e10cSrcweir Invalidate(); 2413cdf0e10cSrcweir } 2414cdf0e10cSrcweir } 2415cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFOREGROUND ) 2416cdf0e10cSrcweir { 2417cdf0e10cSrcweir if ( !mpSubEdit ) 2418cdf0e10cSrcweir { 2419cdf0e10cSrcweir ImplInitSettings( sal_False, sal_True, sal_False ); 2420cdf0e10cSrcweir Invalidate(); 2421cdf0e10cSrcweir } 2422cdf0e10cSrcweir } 2423cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 2424cdf0e10cSrcweir { 2425cdf0e10cSrcweir if ( !mpSubEdit ) 2426cdf0e10cSrcweir { 2427cdf0e10cSrcweir ImplInitSettings( sal_False, sal_False, sal_True ); 2428cdf0e10cSrcweir Invalidate(); 2429cdf0e10cSrcweir } 2430cdf0e10cSrcweir } 2431cdf0e10cSrcweir 2432cdf0e10cSrcweir Control::StateChanged( nType ); 2433cdf0e10cSrcweir } 2434cdf0e10cSrcweir 2435cdf0e10cSrcweir // ----------------------------------------------------------------------- 2436cdf0e10cSrcweir 2437cdf0e10cSrcweir void Edit::DataChanged( const DataChangedEvent& rDCEvt ) 2438cdf0e10cSrcweir { 2439cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_FONTS) || 2440cdf0e10cSrcweir (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) || 2441cdf0e10cSrcweir ((rDCEvt.GetType() == DATACHANGED_SETTINGS) && 2442cdf0e10cSrcweir (rDCEvt.GetFlags() & SETTINGS_STYLE)) ) 2443cdf0e10cSrcweir { 2444cdf0e10cSrcweir if ( !mpSubEdit ) 2445cdf0e10cSrcweir { 2446cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True ); 2447cdf0e10cSrcweir ImplShowCursor( sal_True ); 2448cdf0e10cSrcweir Invalidate(); 2449cdf0e10cSrcweir } 2450cdf0e10cSrcweir } 2451cdf0e10cSrcweir 2452cdf0e10cSrcweir Control::DataChanged( rDCEvt ); 2453cdf0e10cSrcweir } 2454cdf0e10cSrcweir 2455cdf0e10cSrcweir // ----------------------------------------------------------------------- 2456cdf0e10cSrcweir 2457cdf0e10cSrcweir void Edit::ImplShowDDCursor() 2458cdf0e10cSrcweir { 2459cdf0e10cSrcweir if ( !mpDDInfo->bVisCursor ) 2460cdf0e10cSrcweir { 2461cdf0e10cSrcweir long nTextWidth = GetTextWidth( maText, 0, mpDDInfo->nDropPos ); 2462cdf0e10cSrcweir long nTextHeight = GetTextHeight(); 2463cdf0e10cSrcweir Rectangle aCursorRect( Point( nTextWidth + mnXOffset, (GetOutputSize().Height()-nTextHeight)/2 ), Size( 2, nTextHeight ) ); 2464cdf0e10cSrcweir mpDDInfo->aCursor.SetWindow( this ); 2465cdf0e10cSrcweir mpDDInfo->aCursor.SetPos( aCursorRect.TopLeft() ); 2466cdf0e10cSrcweir mpDDInfo->aCursor.SetSize( aCursorRect.GetSize() ); 2467cdf0e10cSrcweir mpDDInfo->aCursor.Show(); 2468cdf0e10cSrcweir mpDDInfo->bVisCursor = sal_True; 2469cdf0e10cSrcweir } 2470cdf0e10cSrcweir } 2471cdf0e10cSrcweir 2472cdf0e10cSrcweir // ----------------------------------------------------------------------- 2473cdf0e10cSrcweir 2474cdf0e10cSrcweir void Edit::ImplHideDDCursor() 2475cdf0e10cSrcweir { 2476cdf0e10cSrcweir if ( mpDDInfo && mpDDInfo->bVisCursor ) 2477cdf0e10cSrcweir { 2478cdf0e10cSrcweir mpDDInfo->aCursor.Hide(); 2479cdf0e10cSrcweir mpDDInfo->bVisCursor = sal_False; 2480cdf0e10cSrcweir } 2481cdf0e10cSrcweir } 2482cdf0e10cSrcweir 2483cdf0e10cSrcweir // ----------------------------------------------------------------------- 2484cdf0e10cSrcweir 2485cdf0e10cSrcweir void Edit::Modify() 2486cdf0e10cSrcweir { 2487cdf0e10cSrcweir if ( mbIsSubEdit ) 2488cdf0e10cSrcweir { 2489cdf0e10cSrcweir ((Edit*)GetParent())->Modify(); 2490cdf0e10cSrcweir } 2491cdf0e10cSrcweir else 2492cdf0e10cSrcweir { 2493cdf0e10cSrcweir if ( mpUpdateDataTimer ) 2494cdf0e10cSrcweir mpUpdateDataTimer->Start(); 2495cdf0e10cSrcweir 2496cdf0e10cSrcweir if ( ImplCallEventListenersAndHandler( VCLEVENT_EDIT_MODIFY, maModifyHdl, this ) ) 2497cdf0e10cSrcweir // have been destroyed while calling into the handlers 2498cdf0e10cSrcweir return; 2499cdf0e10cSrcweir 2500cdf0e10cSrcweir // #i13677# notify edit listeners about caret position change 2501cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_EDIT_SELECTIONCHANGED ); 2502cdf0e10cSrcweir 2503cdf0e10cSrcweir // FIXME: this is currently only on aqua 2504cdf0e10cSrcweir // check for other platforms that need similar handling 2505cdf0e10cSrcweir if( ImplGetSVData()->maNWFData.mbNoFocusRects && 2506cdf0e10cSrcweir IsNativeWidgetEnabled() && 2507cdf0e10cSrcweir IsNativeControlSupported( CTRL_EDITBOX, PART_ENTIRE_CONTROL ) ) 2508cdf0e10cSrcweir { 2509cdf0e10cSrcweir ImplInvalidateOutermostBorder( this ); 2510cdf0e10cSrcweir } 2511cdf0e10cSrcweir } 2512cdf0e10cSrcweir } 2513cdf0e10cSrcweir 2514cdf0e10cSrcweir // ----------------------------------------------------------------------- 2515cdf0e10cSrcweir 2516cdf0e10cSrcweir void Edit::UpdateData() 2517cdf0e10cSrcweir { 2518cdf0e10cSrcweir maUpdateDataHdl.Call( this ); 2519cdf0e10cSrcweir } 2520cdf0e10cSrcweir 2521cdf0e10cSrcweir // ----------------------------------------------------------------------- 2522cdf0e10cSrcweir 2523cdf0e10cSrcweir IMPL_LINK( Edit, ImplUpdateDataHdl, Timer*, EMPTYARG ) 2524cdf0e10cSrcweir { 2525cdf0e10cSrcweir UpdateData(); 2526cdf0e10cSrcweir return 0; 2527cdf0e10cSrcweir } 2528cdf0e10cSrcweir 2529cdf0e10cSrcweir // ----------------------------------------------------------------------- 2530cdf0e10cSrcweir 2531cdf0e10cSrcweir void Edit::EnableUpdateData( sal_uLong nTimeout ) 2532cdf0e10cSrcweir { 2533cdf0e10cSrcweir if ( !nTimeout ) 2534cdf0e10cSrcweir DisableUpdateData(); 2535cdf0e10cSrcweir else 2536cdf0e10cSrcweir { 2537cdf0e10cSrcweir if ( !mpUpdateDataTimer ) 2538cdf0e10cSrcweir { 2539cdf0e10cSrcweir mpUpdateDataTimer = new Timer; 2540cdf0e10cSrcweir mpUpdateDataTimer->SetTimeoutHdl( LINK( this, Edit, ImplUpdateDataHdl ) ); 2541cdf0e10cSrcweir } 2542cdf0e10cSrcweir 2543cdf0e10cSrcweir mpUpdateDataTimer->SetTimeout( nTimeout ); 2544cdf0e10cSrcweir } 2545cdf0e10cSrcweir } 2546cdf0e10cSrcweir 2547cdf0e10cSrcweir // ----------------------------------------------------------------------- 2548cdf0e10cSrcweir 2549cdf0e10cSrcweir void Edit::SetEchoChar( xub_Unicode c ) 2550cdf0e10cSrcweir { 2551cdf0e10cSrcweir mcEchoChar = c; 2552cdf0e10cSrcweir if ( mpSubEdit ) 2553cdf0e10cSrcweir mpSubEdit->SetEchoChar( c ); 2554cdf0e10cSrcweir } 2555cdf0e10cSrcweir 2556cdf0e10cSrcweir // ----------------------------------------------------------------------- 2557cdf0e10cSrcweir 2558cdf0e10cSrcweir void Edit::SetReadOnly( sal_Bool bReadOnly ) 2559cdf0e10cSrcweir { 2560cdf0e10cSrcweir if ( mbReadOnly != bReadOnly ) 2561cdf0e10cSrcweir { 2562cdf0e10cSrcweir mbReadOnly = bReadOnly; 2563cdf0e10cSrcweir if ( mpSubEdit ) 2564cdf0e10cSrcweir mpSubEdit->SetReadOnly( bReadOnly ); 2565cdf0e10cSrcweir 2566cdf0e10cSrcweir StateChanged( STATE_CHANGE_READONLY ); 2567cdf0e10cSrcweir } 2568cdf0e10cSrcweir } 2569cdf0e10cSrcweir 2570cdf0e10cSrcweir // ----------------------------------------------------------------------- 2571cdf0e10cSrcweir 2572cdf0e10cSrcweir void Edit::SetAutocompleteHdl( const Link& rHdl ) 2573cdf0e10cSrcweir { 2574cdf0e10cSrcweir maAutocompleteHdl = rHdl; 2575cdf0e10cSrcweir if ( mpSubEdit ) 2576cdf0e10cSrcweir mpSubEdit->SetAutocompleteHdl( rHdl ); 2577cdf0e10cSrcweir } 2578cdf0e10cSrcweir 2579cdf0e10cSrcweir // ----------------------------------------------------------------------- 2580cdf0e10cSrcweir 2581cdf0e10cSrcweir void Edit::SetInsertMode( sal_Bool bInsert ) 2582cdf0e10cSrcweir { 2583cdf0e10cSrcweir if ( bInsert != mbInsertMode ) 2584cdf0e10cSrcweir { 2585cdf0e10cSrcweir mbInsertMode = bInsert; 2586cdf0e10cSrcweir if ( mpSubEdit ) 2587cdf0e10cSrcweir mpSubEdit->SetInsertMode( bInsert ); 2588cdf0e10cSrcweir else 2589cdf0e10cSrcweir ImplShowCursor(); 2590cdf0e10cSrcweir } 2591cdf0e10cSrcweir } 2592cdf0e10cSrcweir 2593cdf0e10cSrcweir // ----------------------------------------------------------------------- 2594cdf0e10cSrcweir 2595cdf0e10cSrcweir sal_Bool Edit::IsInsertMode() const 2596cdf0e10cSrcweir { 2597cdf0e10cSrcweir if ( mpSubEdit ) 2598cdf0e10cSrcweir return mpSubEdit->IsInsertMode(); 2599cdf0e10cSrcweir else 2600cdf0e10cSrcweir return mbInsertMode; 2601cdf0e10cSrcweir } 2602cdf0e10cSrcweir 2603cdf0e10cSrcweir // ----------------------------------------------------------------------- 2604cdf0e10cSrcweir 2605cdf0e10cSrcweir void Edit::SetMaxTextLen( xub_StrLen nMaxLen ) 2606cdf0e10cSrcweir { 2607cdf0e10cSrcweir mnMaxTextLen = nMaxLen ? nMaxLen : EDIT_NOLIMIT; 2608cdf0e10cSrcweir 2609cdf0e10cSrcweir if ( mpSubEdit ) 2610cdf0e10cSrcweir mpSubEdit->SetMaxTextLen( mnMaxTextLen ); 2611cdf0e10cSrcweir else 2612cdf0e10cSrcweir { 2613cdf0e10cSrcweir if ( maText.Len() > mnMaxTextLen ) 2614cdf0e10cSrcweir ImplDelete( Selection( mnMaxTextLen, maText.Len() ), EDIT_DEL_RIGHT, EDIT_DELMODE_SIMPLE ); 2615cdf0e10cSrcweir } 2616cdf0e10cSrcweir } 2617cdf0e10cSrcweir 2618cdf0e10cSrcweir // ----------------------------------------------------------------------- 2619cdf0e10cSrcweir 2620cdf0e10cSrcweir void Edit::SetSelection( const Selection& rSelection ) 2621cdf0e10cSrcweir { 2622cdf0e10cSrcweir // Wenn von aussen z.B. im MouseButtonDown die Selektion geaendert wird, 2623cdf0e10cSrcweir // soll nicht gleich ein Tracking() zuschlagen und die Selektion aendern. 2624cdf0e10cSrcweir if ( IsTracking() ) 2625cdf0e10cSrcweir EndTracking(); 2626cdf0e10cSrcweir else if ( mpSubEdit && mpSubEdit->IsTracking() ) 2627cdf0e10cSrcweir mpSubEdit->EndTracking(); 2628cdf0e10cSrcweir 2629cdf0e10cSrcweir ImplSetSelection( rSelection ); 2630cdf0e10cSrcweir } 2631cdf0e10cSrcweir 2632cdf0e10cSrcweir // ----------------------------------------------------------------------- 2633cdf0e10cSrcweir 2634cdf0e10cSrcweir void Edit::ImplSetSelection( const Selection& rSelection, sal_Bool bPaint ) 2635cdf0e10cSrcweir { 2636cdf0e10cSrcweir if ( mpSubEdit ) 2637cdf0e10cSrcweir mpSubEdit->ImplSetSelection( rSelection ); 2638cdf0e10cSrcweir else 2639cdf0e10cSrcweir { 2640cdf0e10cSrcweir if ( rSelection != maSelection ) 2641cdf0e10cSrcweir { 2642cdf0e10cSrcweir Selection aOld( maSelection ); 2643cdf0e10cSrcweir Selection aNew( rSelection ); 2644cdf0e10cSrcweir 2645cdf0e10cSrcweir if ( aNew.Min() > maText.Len() ) 2646cdf0e10cSrcweir aNew.Min() = maText.Len(); 2647cdf0e10cSrcweir if ( aNew.Max() > maText.Len() ) 2648cdf0e10cSrcweir aNew.Max() = maText.Len(); 2649cdf0e10cSrcweir if ( aNew.Min() < 0 ) 2650cdf0e10cSrcweir aNew.Min() = 0; 2651cdf0e10cSrcweir if ( aNew.Max() < 0 ) 2652cdf0e10cSrcweir aNew.Max() = 0; 2653cdf0e10cSrcweir 2654cdf0e10cSrcweir if ( aNew != maSelection ) 2655cdf0e10cSrcweir { 2656cdf0e10cSrcweir ImplClearLayoutData(); 2657cdf0e10cSrcweir maSelection = aNew; 2658cdf0e10cSrcweir 2659cdf0e10cSrcweir if ( bPaint && ( aOld.Len() || aNew.Len() || IsPaintTransparent() ) ) 2660cdf0e10cSrcweir ImplInvalidateOrRepaint( 0, maText.Len() ); 2661cdf0e10cSrcweir ImplShowCursor(); 2662cdf0e10cSrcweir if ( mbIsSubEdit ) 2663cdf0e10cSrcweir ((Edit*)GetParent())->ImplCallEventListeners( VCLEVENT_EDIT_SELECTIONCHANGED ); 2664cdf0e10cSrcweir else 2665cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_EDIT_SELECTIONCHANGED ); 2666cdf0e10cSrcweir // #103511# notify combobox listeners of deselection 2667cdf0e10cSrcweir if( !maSelection && GetParent() && GetParent()->GetType() == WINDOW_COMBOBOX ) 2668cdf0e10cSrcweir ((Edit*)GetParent())->ImplCallEventListeners( VCLEVENT_COMBOBOX_DESELECT ); 2669cdf0e10cSrcweir } 2670cdf0e10cSrcweir } 2671cdf0e10cSrcweir } 2672cdf0e10cSrcweir } 2673cdf0e10cSrcweir 2674cdf0e10cSrcweir // ----------------------------------------------------------------------- 2675cdf0e10cSrcweir 2676cdf0e10cSrcweir const Selection& Edit::GetSelection() const 2677cdf0e10cSrcweir { 2678cdf0e10cSrcweir if ( mpSubEdit ) 2679cdf0e10cSrcweir return mpSubEdit->GetSelection(); 2680cdf0e10cSrcweir else 2681cdf0e10cSrcweir return maSelection; 2682cdf0e10cSrcweir } 2683cdf0e10cSrcweir 2684cdf0e10cSrcweir // ----------------------------------------------------------------------- 2685cdf0e10cSrcweir 2686cdf0e10cSrcweir void Edit::ReplaceSelected( const XubString& rStr ) 2687cdf0e10cSrcweir { 2688cdf0e10cSrcweir if ( mpSubEdit ) 2689cdf0e10cSrcweir mpSubEdit->ReplaceSelected( rStr ); 2690cdf0e10cSrcweir else 2691cdf0e10cSrcweir ImplInsertText( rStr ); 2692cdf0e10cSrcweir } 2693cdf0e10cSrcweir 2694cdf0e10cSrcweir // ----------------------------------------------------------------------- 2695cdf0e10cSrcweir 2696cdf0e10cSrcweir void Edit::DeleteSelected() 2697cdf0e10cSrcweir { 2698cdf0e10cSrcweir if ( mpSubEdit ) 2699cdf0e10cSrcweir mpSubEdit->DeleteSelected(); 2700cdf0e10cSrcweir else 2701cdf0e10cSrcweir { 2702cdf0e10cSrcweir if ( maSelection.Len() ) 2703cdf0e10cSrcweir ImplDelete( maSelection, EDIT_DEL_RIGHT, EDIT_DELMODE_SIMPLE ); 2704cdf0e10cSrcweir } 2705cdf0e10cSrcweir } 2706cdf0e10cSrcweir 2707cdf0e10cSrcweir // ----------------------------------------------------------------------- 2708cdf0e10cSrcweir 2709cdf0e10cSrcweir XubString Edit::GetSelected() const 2710cdf0e10cSrcweir { 2711cdf0e10cSrcweir if ( mpSubEdit ) 2712cdf0e10cSrcweir return mpSubEdit->GetSelected(); 2713cdf0e10cSrcweir else 2714cdf0e10cSrcweir { 2715cdf0e10cSrcweir Selection aSelection( maSelection ); 2716cdf0e10cSrcweir aSelection.Justify(); 2717cdf0e10cSrcweir return maText.Copy( (xub_StrLen)aSelection.Min(), (xub_StrLen)aSelection.Len() ); 2718cdf0e10cSrcweir } 2719cdf0e10cSrcweir } 2720cdf0e10cSrcweir 2721cdf0e10cSrcweir // ----------------------------------------------------------------------- 2722cdf0e10cSrcweir 2723cdf0e10cSrcweir void Edit::Cut() 2724cdf0e10cSrcweir { 2725cdf0e10cSrcweir if ( !(GetStyle() & WB_PASSWORD ) ) 2726cdf0e10cSrcweir { 2727cdf0e10cSrcweir Copy(); 2728cdf0e10cSrcweir ReplaceSelected( ImplGetSVEmptyStr() ); 2729cdf0e10cSrcweir } 2730cdf0e10cSrcweir } 2731cdf0e10cSrcweir 2732cdf0e10cSrcweir // ----------------------------------------------------------------------- 2733cdf0e10cSrcweir 2734cdf0e10cSrcweir void Edit::Copy() 2735cdf0e10cSrcweir { 2736cdf0e10cSrcweir if ( !(GetStyle() & WB_PASSWORD ) ) 2737cdf0e10cSrcweir { 2738cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipboard(GetClipboard()); 2739cdf0e10cSrcweir ImplCopy( aClipboard ); 2740cdf0e10cSrcweir } 2741cdf0e10cSrcweir } 2742cdf0e10cSrcweir 2743cdf0e10cSrcweir // ----------------------------------------------------------------------- 2744cdf0e10cSrcweir 2745cdf0e10cSrcweir void Edit::Paste() 2746cdf0e10cSrcweir { 2747cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipboard(GetClipboard()); 2748cdf0e10cSrcweir ImplPaste( aClipboard ); 2749cdf0e10cSrcweir } 2750cdf0e10cSrcweir 2751cdf0e10cSrcweir // ----------------------------------------------------------------------- 2752cdf0e10cSrcweir 2753cdf0e10cSrcweir void Edit::Undo() 2754cdf0e10cSrcweir { 2755cdf0e10cSrcweir if ( mpSubEdit ) 2756cdf0e10cSrcweir mpSubEdit->Undo(); 2757cdf0e10cSrcweir else 2758cdf0e10cSrcweir { 2759cdf0e10cSrcweir XubString aText( maText ); 2760cdf0e10cSrcweir ImplDelete( Selection( 0, aText.Len() ), EDIT_DEL_RIGHT, EDIT_DELMODE_SIMPLE ); 2761cdf0e10cSrcweir ImplInsertText( maUndoText ); 2762cdf0e10cSrcweir ImplSetSelection( Selection( 0, maUndoText.Len() ) ); 2763cdf0e10cSrcweir maUndoText = aText; 2764cdf0e10cSrcweir } 2765cdf0e10cSrcweir } 2766cdf0e10cSrcweir 2767cdf0e10cSrcweir // ----------------------------------------------------------------------- 2768cdf0e10cSrcweir 2769cdf0e10cSrcweir void Edit::SetText( const XubString& rStr ) 2770cdf0e10cSrcweir { 2771cdf0e10cSrcweir if ( mpSubEdit ) 2772cdf0e10cSrcweir mpSubEdit->SetText( rStr ); // Nicht direkt ImplSetText, falls SetText ueberladen 2773cdf0e10cSrcweir else 2774cdf0e10cSrcweir { 2775cdf0e10cSrcweir Selection aNewSel( 0, 0 ); // Damit nicht gescrollt wird 2776cdf0e10cSrcweir ImplSetText( rStr, &aNewSel ); 2777cdf0e10cSrcweir } 2778cdf0e10cSrcweir } 2779cdf0e10cSrcweir 2780cdf0e10cSrcweir // ----------------------------------------------------------------------- 2781cdf0e10cSrcweir 2782cdf0e10cSrcweir void Edit::SetText( const XubString& rStr, const Selection& rSelection ) 2783cdf0e10cSrcweir { 2784cdf0e10cSrcweir if ( mpSubEdit ) 2785cdf0e10cSrcweir mpSubEdit->SetText( rStr, rSelection ); 2786cdf0e10cSrcweir else 2787cdf0e10cSrcweir ImplSetText( rStr, &rSelection ); 2788cdf0e10cSrcweir } 2789cdf0e10cSrcweir 2790cdf0e10cSrcweir // ----------------------------------------------------------------------- 2791cdf0e10cSrcweir 2792cdf0e10cSrcweir XubString Edit::GetText() const 2793cdf0e10cSrcweir { 2794cdf0e10cSrcweir if ( mpSubEdit ) 2795cdf0e10cSrcweir return mpSubEdit->GetText(); 2796cdf0e10cSrcweir else 2797cdf0e10cSrcweir return maText; 2798cdf0e10cSrcweir } 2799cdf0e10cSrcweir 2800cdf0e10cSrcweir // ----------------------------------------------------------------------- 2801cdf0e10cSrcweir 2802cdf0e10cSrcweir void Edit::SetModifyFlag() 2803cdf0e10cSrcweir { 2804cdf0e10cSrcweir if ( mpSubEdit ) 2805cdf0e10cSrcweir mpSubEdit->mbModified = sal_True; 2806cdf0e10cSrcweir else 2807cdf0e10cSrcweir mbModified = sal_True; 2808cdf0e10cSrcweir } 2809cdf0e10cSrcweir 2810cdf0e10cSrcweir // ----------------------------------------------------------------------- 2811cdf0e10cSrcweir 2812cdf0e10cSrcweir void Edit::ClearModifyFlag() 2813cdf0e10cSrcweir { 2814cdf0e10cSrcweir if ( mpSubEdit ) 2815cdf0e10cSrcweir mpSubEdit->mbModified = sal_False; 2816cdf0e10cSrcweir else 2817cdf0e10cSrcweir mbModified = sal_False; 2818cdf0e10cSrcweir } 2819cdf0e10cSrcweir 2820cdf0e10cSrcweir // ----------------------------------------------------------------------- 2821cdf0e10cSrcweir 2822cdf0e10cSrcweir void Edit::SetSubEdit( Edit* pEdit ) 2823cdf0e10cSrcweir { 2824cdf0e10cSrcweir mpSubEdit = pEdit; 2825cdf0e10cSrcweir if ( mpSubEdit ) 2826cdf0e10cSrcweir { 2827cdf0e10cSrcweir SetPointer( POINTER_ARROW ); // Nur das SubEdit hat den BEAM... 2828cdf0e10cSrcweir mpSubEdit->mbIsSubEdit = sal_True; 2829cdf0e10cSrcweir 2830cdf0e10cSrcweir mpSubEdit->SetReadOnly( mbReadOnly ); 2831cdf0e10cSrcweir } 2832cdf0e10cSrcweir } 2833cdf0e10cSrcweir 2834cdf0e10cSrcweir // ----------------------------------------------------------------------- 2835cdf0e10cSrcweir 2836cdf0e10cSrcweir Size Edit::CalcMinimumSize() const 2837cdf0e10cSrcweir { 2838cdf0e10cSrcweir Size aSize ( GetTextWidth( GetText() ), GetTextHeight() ); 2839cdf0e10cSrcweir // do not create edit fields in which one cannot enter anything 2840cdf0e10cSrcweir // a default minimum width should exist for at least 3 characters 2841cdf0e10cSrcweir Size aMinSize ( CalcSize( 3 ) ); 2842cdf0e10cSrcweir if( aSize.Width() < aMinSize.Width() ) 2843cdf0e10cSrcweir aSize.Width() = aMinSize.Width(); 2844cdf0e10cSrcweir // add some space between text entry and border 2845cdf0e10cSrcweir aSize.Height() += 4; 2846cdf0e10cSrcweir 2847cdf0e10cSrcweir aSize = CalcWindowSize( aSize ); 2848cdf0e10cSrcweir 2849cdf0e10cSrcweir // ask NWF what if it has an opinion, too 2850cdf0e10cSrcweir ImplControlValue aControlValue; 2851cdf0e10cSrcweir Rectangle aRect( Point( 0, 0 ), aSize ); 2852cdf0e10cSrcweir Rectangle aContent, aBound; 2853cdf0e10cSrcweir if( const_cast<Edit*>(this)->GetNativeControlRegion( 2854cdf0e10cSrcweir CTRL_EDITBOX, PART_ENTIRE_CONTROL, 2855cdf0e10cSrcweir aRect, 0, aControlValue, rtl::OUString(), aBound, aContent) ) 2856cdf0e10cSrcweir { 2857cdf0e10cSrcweir if( aBound.GetHeight() > aSize.Height() ) 2858cdf0e10cSrcweir aSize.Height() = aBound.GetHeight(); 2859cdf0e10cSrcweir } 2860cdf0e10cSrcweir return aSize; 2861cdf0e10cSrcweir } 2862cdf0e10cSrcweir 2863cdf0e10cSrcweir Size Edit::GetMinimumEditSize() 2864cdf0e10cSrcweir { 2865cdf0e10cSrcweir Window* pDefWin = ImplGetDefaultWindow(); 2866cdf0e10cSrcweir Edit aEdit( pDefWin, WB_BORDER ); 2867cdf0e10cSrcweir Size aSize( aEdit.CalcMinimumSize() ); 2868cdf0e10cSrcweir return aSize; 2869cdf0e10cSrcweir } 2870cdf0e10cSrcweir 2871cdf0e10cSrcweir // ----------------------------------------------------------------------- 2872cdf0e10cSrcweir 2873cdf0e10cSrcweir Size Edit::GetOptimalSize(WindowSizeType eType) const 2874cdf0e10cSrcweir { 2875cdf0e10cSrcweir switch (eType) { 2876cdf0e10cSrcweir case WINDOWSIZE_MINIMUM: 2877cdf0e10cSrcweir return CalcMinimumSize(); 2878cdf0e10cSrcweir default: 2879cdf0e10cSrcweir return Control::GetOptimalSize( eType ); 2880cdf0e10cSrcweir } 2881cdf0e10cSrcweir } 2882cdf0e10cSrcweir 2883cdf0e10cSrcweir // ----------------------------------------------------------------------- 2884cdf0e10cSrcweir 2885cdf0e10cSrcweir Size Edit::CalcSize( xub_StrLen nChars ) const 2886cdf0e10cSrcweir { 2887cdf0e10cSrcweir // Breite fuer n Zeichen, unabhaengig vom Inhalt. 2888cdf0e10cSrcweir // Funktioniert nur bei FixedFont richtig, sonst Mittelwert. 2889cdf0e10cSrcweir Size aSz( GetTextWidth( XubString( 'x' ) ), GetTextHeight() ); 2890cdf0e10cSrcweir aSz.Width() *= nChars; 2891cdf0e10cSrcweir aSz = CalcWindowSize( aSz ); 2892cdf0e10cSrcweir return aSz; 2893cdf0e10cSrcweir } 2894cdf0e10cSrcweir 2895cdf0e10cSrcweir // ----------------------------------------------------------------------- 2896cdf0e10cSrcweir 2897cdf0e10cSrcweir xub_StrLen Edit::GetMaxVisChars() const 2898cdf0e10cSrcweir { 2899cdf0e10cSrcweir const Window* pW = mpSubEdit ? mpSubEdit : this; 2900cdf0e10cSrcweir long nOutWidth = pW->GetOutputSizePixel().Width(); 2901cdf0e10cSrcweir long nCharWidth = GetTextWidth( XubString( 'x' ) ); 2902cdf0e10cSrcweir return nCharWidth ? (xub_StrLen)(nOutWidth/nCharWidth) : 0; 2903cdf0e10cSrcweir } 2904cdf0e10cSrcweir 2905cdf0e10cSrcweir // ----------------------------------------------------------------------- 2906cdf0e10cSrcweir 2907cdf0e10cSrcweir xub_StrLen Edit::GetCharPos( const Point& rWindowPos ) const 2908cdf0e10cSrcweir { 2909cdf0e10cSrcweir return ImplGetCharPos( rWindowPos ); 2910cdf0e10cSrcweir } 2911cdf0e10cSrcweir 2912cdf0e10cSrcweir // ----------------------------------------------------------------------- 2913cdf0e10cSrcweir 2914cdf0e10cSrcweir void Edit::SetGetSpecialCharsFunction( FncGetSpecialChars fn ) 2915cdf0e10cSrcweir { 2916cdf0e10cSrcweir pImplFncGetSpecialChars = fn; 2917cdf0e10cSrcweir } 2918cdf0e10cSrcweir 2919cdf0e10cSrcweir // ----------------------------------------------------------------------- 2920cdf0e10cSrcweir 2921cdf0e10cSrcweir FncGetSpecialChars Edit::GetGetSpecialCharsFunction() 2922cdf0e10cSrcweir { 2923cdf0e10cSrcweir return pImplFncGetSpecialChars; 2924cdf0e10cSrcweir } 2925cdf0e10cSrcweir 2926cdf0e10cSrcweir // ----------------------------------------------------------------------- 2927cdf0e10cSrcweir 2928cdf0e10cSrcweir PopupMenu* Edit::CreatePopupMenu() 2929cdf0e10cSrcweir { 2930cdf0e10cSrcweir ResMgr* pResMgr = ImplGetResMgr(); 2931cdf0e10cSrcweir if( ! pResMgr ) 2932cdf0e10cSrcweir return new PopupMenu(); 2933cdf0e10cSrcweir 2934cdf0e10cSrcweir PopupMenu* pPopup = new PopupMenu( ResId( SV_RESID_MENU_EDIT, *pResMgr ) ); 2935cdf0e10cSrcweir pPopup->SetAccelKey( SV_MENU_EDIT_UNDO, KeyCode( KEYFUNC_UNDO ) ); 2936cdf0e10cSrcweir pPopup->SetAccelKey( SV_MENU_EDIT_CUT, KeyCode( KEYFUNC_CUT ) ); 2937cdf0e10cSrcweir pPopup->SetAccelKey( SV_MENU_EDIT_COPY, KeyCode( KEYFUNC_COPY ) ); 2938cdf0e10cSrcweir pPopup->SetAccelKey( SV_MENU_EDIT_PASTE, KeyCode( KEYFUNC_PASTE ) ); 2939cdf0e10cSrcweir pPopup->SetAccelKey( SV_MENU_EDIT_DELETE, KeyCode( KEYFUNC_DELETE ) ); 2940cdf0e10cSrcweir pPopup->SetAccelKey( SV_MENU_EDIT_SELECTALL, KeyCode( KEY_A, sal_False, sal_True, sal_False, sal_False ) ); 2941cdf0e10cSrcweir pPopup->SetAccelKey( SV_MENU_EDIT_INSERTSYMBOL, KeyCode( KEY_S, sal_True, sal_True, sal_False, sal_False ) ); 2942cdf0e10cSrcweir return pPopup; 2943cdf0e10cSrcweir } 2944cdf0e10cSrcweir 2945cdf0e10cSrcweir // ----------------------------------------------------------------------- 2946cdf0e10cSrcweir 2947cdf0e10cSrcweir void Edit::DeletePopupMenu( PopupMenu* pMenu ) 2948cdf0e10cSrcweir { 2949cdf0e10cSrcweir delete pMenu; 2950cdf0e10cSrcweir } 2951cdf0e10cSrcweir 2952cdf0e10cSrcweir // ::com::sun::star::datatransfer::dnd::XDragGestureListener 2953cdf0e10cSrcweir void Edit::dragGestureRecognized( const ::com::sun::star::datatransfer::dnd::DragGestureEvent& rDGE ) throw (::com::sun::star::uno::RuntimeException) 2954cdf0e10cSrcweir { 2955cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() ); 2956cdf0e10cSrcweir 2957cdf0e10cSrcweir if ( !IsTracking() && maSelection.Len() && 2958cdf0e10cSrcweir !(GetStyle() & WB_PASSWORD) && (!mpDDInfo || mpDDInfo->bStarterOfDD == sal_False) ) // Kein Mehrfach D&D 2959cdf0e10cSrcweir { 2960cdf0e10cSrcweir Selection aSel( maSelection ); 2961cdf0e10cSrcweir aSel.Justify(); 2962cdf0e10cSrcweir 2963cdf0e10cSrcweir // Nur wenn Maus in der Selektion... 2964cdf0e10cSrcweir Point aMousePos( rDGE.DragOriginX, rDGE.DragOriginY ); 2965cdf0e10cSrcweir xub_StrLen nChar = ImplGetCharPos( aMousePos ); 2966cdf0e10cSrcweir if ( (nChar >= aSel.Min()) && (nChar < aSel.Max()) ) 2967cdf0e10cSrcweir { 2968cdf0e10cSrcweir if ( !mpDDInfo ) 2969cdf0e10cSrcweir mpDDInfo = new DDInfo; 2970cdf0e10cSrcweir 2971cdf0e10cSrcweir mpDDInfo->bStarterOfDD = sal_True; 2972cdf0e10cSrcweir mpDDInfo->aDndStartSel = aSel; 2973cdf0e10cSrcweir 2974cdf0e10cSrcweir 2975cdf0e10cSrcweir if ( IsTracking() ) 2976cdf0e10cSrcweir EndTracking(); // Vor D&D Tracking ausschalten 2977cdf0e10cSrcweir 2978cdf0e10cSrcweir ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( GetSelected() ); 2979cdf0e10cSrcweir sal_Int8 nActions = datatransfer::dnd::DNDConstants::ACTION_COPY; 2980cdf0e10cSrcweir if ( !IsReadOnly() ) 2981cdf0e10cSrcweir nActions |= datatransfer::dnd::DNDConstants::ACTION_MOVE; 2982cdf0e10cSrcweir rDGE.DragSource->startDrag( rDGE, nActions, 0 /*cursor*/, 0 /*image*/, pDataObj, mxDnDListener ); 2983cdf0e10cSrcweir if ( GetCursor() ) 2984cdf0e10cSrcweir GetCursor()->Hide(); 2985cdf0e10cSrcweir 2986cdf0e10cSrcweir } 2987cdf0e10cSrcweir } 2988cdf0e10cSrcweir } 2989cdf0e10cSrcweir 2990cdf0e10cSrcweir // ::com::sun::star::datatransfer::dnd::XDragSourceListener 2991cdf0e10cSrcweir void Edit::dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent& rDSDE ) throw (::com::sun::star::uno::RuntimeException) 2992cdf0e10cSrcweir { 2993cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() ); 2994cdf0e10cSrcweir 2995cdf0e10cSrcweir if ( rDSDE.DropSuccess && ( rDSDE.DropAction & datatransfer::dnd::DNDConstants::ACTION_MOVE ) ) 2996cdf0e10cSrcweir { 2997cdf0e10cSrcweir Selection aSel( mpDDInfo->aDndStartSel ); 2998cdf0e10cSrcweir if ( mpDDInfo->bDroppedInMe ) 2999cdf0e10cSrcweir { 3000cdf0e10cSrcweir if ( aSel.Max() > mpDDInfo->nDropPos ) 3001cdf0e10cSrcweir { 3002cdf0e10cSrcweir long nLen = aSel.Len(); 3003cdf0e10cSrcweir aSel.Min() += nLen; 3004cdf0e10cSrcweir aSel.Max() += nLen; 3005cdf0e10cSrcweir } 3006cdf0e10cSrcweir } 3007cdf0e10cSrcweir ImplDelete( aSel, EDIT_DEL_RIGHT, EDIT_DELMODE_SIMPLE ); 3008cdf0e10cSrcweir ImplModified(); 3009cdf0e10cSrcweir } 3010cdf0e10cSrcweir 3011cdf0e10cSrcweir ImplHideDDCursor(); 3012cdf0e10cSrcweir delete mpDDInfo; 3013cdf0e10cSrcweir mpDDInfo = NULL; 3014cdf0e10cSrcweir } 3015cdf0e10cSrcweir 3016cdf0e10cSrcweir // ::com::sun::star::datatransfer::dnd::XDropTargetListener 3017cdf0e10cSrcweir void Edit::drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& rDTDE ) throw (::com::sun::star::uno::RuntimeException) 3018cdf0e10cSrcweir { 3019cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() ); 3020cdf0e10cSrcweir 3021cdf0e10cSrcweir sal_Bool bChanges = sal_False; 3022cdf0e10cSrcweir if ( !mbReadOnly && mpDDInfo ) 3023cdf0e10cSrcweir { 3024cdf0e10cSrcweir ImplHideDDCursor(); 3025cdf0e10cSrcweir 3026cdf0e10cSrcweir Selection aSel( maSelection ); 3027cdf0e10cSrcweir aSel.Justify(); 3028cdf0e10cSrcweir 3029cdf0e10cSrcweir if ( aSel.Len() && !mpDDInfo->bStarterOfDD ) 3030cdf0e10cSrcweir ImplDelete( aSel, EDIT_DEL_RIGHT, EDIT_DELMODE_SIMPLE ); 3031cdf0e10cSrcweir 3032cdf0e10cSrcweir mpDDInfo->bDroppedInMe = sal_True; 3033cdf0e10cSrcweir 3034cdf0e10cSrcweir aSel.Min() = mpDDInfo->nDropPos; 3035cdf0e10cSrcweir aSel.Max() = mpDDInfo->nDropPos; 3036cdf0e10cSrcweir ImplSetSelection( aSel ); 3037cdf0e10cSrcweir 3038cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xDataObj = rDTDE.Transferable; 3039cdf0e10cSrcweir if ( xDataObj.is() ) 3040cdf0e10cSrcweir { 3041cdf0e10cSrcweir datatransfer::DataFlavor aFlavor; 3042cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor ); 3043cdf0e10cSrcweir if ( xDataObj->isDataFlavorSupported( aFlavor ) ) 3044cdf0e10cSrcweir { 3045cdf0e10cSrcweir uno::Any aData = xDataObj->getTransferData( aFlavor ); 3046cdf0e10cSrcweir ::rtl::OUString aText; 3047cdf0e10cSrcweir aData >>= aText; 3048cdf0e10cSrcweir ImplInsertText( aText ); 3049cdf0e10cSrcweir bChanges = sal_True; 3050cdf0e10cSrcweir ImplModified(); 3051cdf0e10cSrcweir } 3052cdf0e10cSrcweir } 3053cdf0e10cSrcweir 3054cdf0e10cSrcweir if ( !mpDDInfo->bStarterOfDD ) 3055cdf0e10cSrcweir { 3056cdf0e10cSrcweir delete mpDDInfo; 3057cdf0e10cSrcweir mpDDInfo = NULL; 3058cdf0e10cSrcweir } 3059cdf0e10cSrcweir } 3060cdf0e10cSrcweir 3061cdf0e10cSrcweir rDTDE.Context->dropComplete( bChanges ); 3062cdf0e10cSrcweir } 3063cdf0e10cSrcweir 3064cdf0e10cSrcweir void Edit::dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& rDTDE ) throw (::com::sun::star::uno::RuntimeException) 3065cdf0e10cSrcweir { 3066cdf0e10cSrcweir if ( !mpDDInfo ) 3067cdf0e10cSrcweir { 3068cdf0e10cSrcweir mpDDInfo = new DDInfo; 3069cdf0e10cSrcweir } 3070cdf0e10cSrcweir // search for string data type 3071cdf0e10cSrcweir const Sequence< com::sun::star::datatransfer::DataFlavor >& rFlavors( rDTDE.SupportedDataFlavors ); 3072cdf0e10cSrcweir sal_Int32 nEle = rFlavors.getLength(); 3073cdf0e10cSrcweir mpDDInfo->bIsStringSupported = sal_False; 3074cdf0e10cSrcweir for( sal_Int32 i = 0; i < nEle; i++ ) 3075cdf0e10cSrcweir { 3076cdf0e10cSrcweir sal_Int32 nIndex = 0; 3077cdf0e10cSrcweir rtl::OUString aMimetype = rFlavors[i].MimeType.getToken( 0, ';', nIndex ); 3078cdf0e10cSrcweir if( aMimetype.equalsAscii( "text/plain" ) ) 3079cdf0e10cSrcweir { 3080cdf0e10cSrcweir mpDDInfo->bIsStringSupported = sal_True; 3081cdf0e10cSrcweir break; 3082cdf0e10cSrcweir } 3083cdf0e10cSrcweir } 3084cdf0e10cSrcweir } 3085cdf0e10cSrcweir 3086cdf0e10cSrcweir void Edit::dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& ) throw (::com::sun::star::uno::RuntimeException) 3087cdf0e10cSrcweir { 3088cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() ); 3089cdf0e10cSrcweir 3090cdf0e10cSrcweir ImplHideDDCursor(); 3091cdf0e10cSrcweir } 3092cdf0e10cSrcweir 3093cdf0e10cSrcweir void Edit::dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& rDTDE ) throw (::com::sun::star::uno::RuntimeException) 3094cdf0e10cSrcweir { 3095cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() ); 3096cdf0e10cSrcweir 3097cdf0e10cSrcweir Point aMousePos( rDTDE.LocationX, rDTDE.LocationY ); 3098cdf0e10cSrcweir 3099cdf0e10cSrcweir xub_StrLen nPrevDropPos = mpDDInfo->nDropPos; 3100cdf0e10cSrcweir mpDDInfo->nDropPos = ImplGetCharPos( aMousePos ); 3101cdf0e10cSrcweir 3102cdf0e10cSrcweir /* 3103cdf0e10cSrcweir Size aOutSize = GetOutputSizePixel(); 3104cdf0e10cSrcweir if ( ( aMousePos.X() < 0 ) || ( aMousePos.X() > aOutSize.Width() ) ) 3105cdf0e10cSrcweir { 3106cdf0e10cSrcweir // Scroll? 3107cdf0e10cSrcweir // No, I will not receive events in this case.... 3108cdf0e10cSrcweir } 3109cdf0e10cSrcweir */ 3110cdf0e10cSrcweir 3111cdf0e10cSrcweir Selection aSel( maSelection ); 3112cdf0e10cSrcweir aSel.Justify(); 3113cdf0e10cSrcweir 3114cdf0e10cSrcweir // Don't accept drop in selection or read-only field... 3115cdf0e10cSrcweir if ( IsReadOnly() || aSel.IsInside( mpDDInfo->nDropPos ) || ! mpDDInfo->bIsStringSupported ) 3116cdf0e10cSrcweir { 3117cdf0e10cSrcweir ImplHideDDCursor(); 3118cdf0e10cSrcweir rDTDE.Context->rejectDrag(); 3119cdf0e10cSrcweir } 3120cdf0e10cSrcweir else 3121cdf0e10cSrcweir { 3122cdf0e10cSrcweir // Alten Cursor wegzeichnen... 3123cdf0e10cSrcweir if ( !mpDDInfo->bVisCursor || ( nPrevDropPos != mpDDInfo->nDropPos ) ) 3124cdf0e10cSrcweir { 3125cdf0e10cSrcweir ImplHideDDCursor(); 3126cdf0e10cSrcweir ImplShowDDCursor(); 3127cdf0e10cSrcweir } 3128cdf0e10cSrcweir rDTDE.Context->acceptDrag( rDTDE.DropAction ); 3129cdf0e10cSrcweir } 3130cdf0e10cSrcweir } 3131cdf0e10cSrcweir 3132cdf0e10cSrcweir ImplSubEdit::ImplSubEdit( Edit* pParent, WinBits nStyle ) : 3133cdf0e10cSrcweir Edit( pParent, nStyle ) 3134cdf0e10cSrcweir { 3135cdf0e10cSrcweir pParent->SetSubEdit( this ); 3136cdf0e10cSrcweir } 3137cdf0e10cSrcweir 3138cdf0e10cSrcweir // ----------------------------------------------------------------------- 3139cdf0e10cSrcweir 3140cdf0e10cSrcweir void ImplSubEdit::Modify() 3141cdf0e10cSrcweir { 3142cdf0e10cSrcweir GetParent()->Modify(); 3143cdf0e10cSrcweir } 3144cdf0e10cSrcweir 3145cdf0e10cSrcweir XubString Edit::GetSurroundingText() const 3146cdf0e10cSrcweir { 3147cdf0e10cSrcweir if ( mpSubEdit ) 3148cdf0e10cSrcweir return mpSubEdit->GetSurroundingText(); 3149cdf0e10cSrcweir else 3150cdf0e10cSrcweir return maText; 3151cdf0e10cSrcweir } 3152cdf0e10cSrcweir 3153cdf0e10cSrcweir Selection Edit::GetSurroundingTextSelection() const 3154cdf0e10cSrcweir { 3155cdf0e10cSrcweir return GetSelection(); 3156cdf0e10cSrcweir } 3157