19f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 59f62ea84SAndrew Rist * distributed with this work for additional information 69f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 89f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 99f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 119f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 139f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 149f62ea84SAndrew Rist * software distributed under the License is distributed on an 159f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 179f62ea84SAndrew Rist * specific language governing permissions and limitations 189f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 209f62ea84SAndrew Rist *************************************************************/ 219f62ea84SAndrew Rist 229f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <tools/table.hxx> 28cdf0e10cSrcweir #include <tools/debug.hxx> 29cdf0e10cSrcweir #include <tools/rc.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <vcl/decoview.hxx> 32cdf0e10cSrcweir #include <vcl/lstbox.h> 33cdf0e10cSrcweir #include <vcl/button.hxx> 34cdf0e10cSrcweir #include <vcl/event.hxx> 35cdf0e10cSrcweir #include <vcl/combobox.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <svdata.hxx> 38cdf0e10cSrcweir #include <subedit.hxx> 39cdf0e10cSrcweir #include <ilstbox.hxx> 40cdf0e10cSrcweir #include <controldata.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir // ======================================================================= 43cdf0e10cSrcweir 44cdf0e10cSrcweir inline sal_uLong ImplCreateKey( sal_uInt16 nPos ) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir // Key = Pos+1, wegen Pos 0 47cdf0e10cSrcweir return nPos+1; 48cdf0e10cSrcweir } 49cdf0e10cSrcweir 50cdf0e10cSrcweir // ----------------------------------------------------------------------- 51cdf0e10cSrcweir 52cdf0e10cSrcweir static void lcl_GetSelectedEntries( Table& rSelectedPos, const XubString& rText, xub_Unicode cTokenSep, const ImplEntryList* pEntryList ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir for( xub_StrLen n = rText.GetTokenCount( cTokenSep ); n; ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir XubString aToken = rText.GetToken( --n, cTokenSep ); 57cdf0e10cSrcweir aToken.EraseLeadingAndTrailingChars( ' ' ); 58cdf0e10cSrcweir sal_uInt16 nPos = pEntryList->FindEntry( aToken ); 59cdf0e10cSrcweir if ( nPos != LISTBOX_ENTRY_NOTFOUND ) 60cdf0e10cSrcweir rSelectedPos.Insert( ImplCreateKey( nPos ), (void*)sal_IntPtr(1L) ); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir // ======================================================================= 65cdf0e10cSrcweir 66cdf0e10cSrcweir ComboBox::ComboBox( WindowType nType ) : 67cdf0e10cSrcweir Edit( nType ) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir ImplInitComboBoxData(); 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir // ----------------------------------------------------------------------- 73cdf0e10cSrcweir 74cdf0e10cSrcweir ComboBox::ComboBox( Window* pParent, WinBits nStyle ) : 75cdf0e10cSrcweir Edit( WINDOW_COMBOBOX ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir ImplInitComboBoxData(); 78cdf0e10cSrcweir ImplInit( pParent, nStyle ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir // ----------------------------------------------------------------------- 82cdf0e10cSrcweir 83cdf0e10cSrcweir ComboBox::ComboBox( Window* pParent, const ResId& rResId ) : 84cdf0e10cSrcweir Edit( WINDOW_COMBOBOX ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir ImplInitComboBoxData(); 87cdf0e10cSrcweir rResId.SetRT( RSC_COMBOBOX ); 88cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 89cdf0e10cSrcweir ImplInit( pParent, nStyle ); 90cdf0e10cSrcweir ImplLoadRes( rResId ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 93cdf0e10cSrcweir Show(); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir // ----------------------------------------------------------------------- 97cdf0e10cSrcweir 98cdf0e10cSrcweir ComboBox::~ComboBox() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir SetSubEdit( NULL ); 101cdf0e10cSrcweir delete mpSubEdit; 102cdf0e10cSrcweir 103cdf0e10cSrcweir delete mpImplLB; 104cdf0e10cSrcweir mpImplLB = NULL; 105cdf0e10cSrcweir 106cdf0e10cSrcweir delete mpFloatWin; 107cdf0e10cSrcweir delete mpBtn; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir // ----------------------------------------------------------------------- 111cdf0e10cSrcweir 112cdf0e10cSrcweir void ComboBox::ImplInitComboBoxData() 113cdf0e10cSrcweir { 114cdf0e10cSrcweir mpSubEdit = NULL; 115cdf0e10cSrcweir mpBtn = NULL; 116cdf0e10cSrcweir mpImplLB = NULL; 117cdf0e10cSrcweir mpFloatWin = NULL; 118cdf0e10cSrcweir 119cdf0e10cSrcweir mnDDHeight = 0; 120cdf0e10cSrcweir mbDDAutoSize = sal_True; 121cdf0e10cSrcweir mbSyntheticModify = sal_False; 122cdf0e10cSrcweir mbMatchCase = sal_False; 123cdf0e10cSrcweir mcMultiSep = ';'; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir // ----------------------------------------------------------------------- 127cdf0e10cSrcweir 128cdf0e10cSrcweir void ComboBox::ImplCalcEditHeight() 129cdf0e10cSrcweir { 130cdf0e10cSrcweir sal_Int32 nLeft, nTop, nRight, nBottom; 131cdf0e10cSrcweir GetBorder( nLeft, nTop, nRight, nBottom ); 132cdf0e10cSrcweir mnDDHeight = (sal_uInt16)(mpSubEdit->GetTextHeight() + nTop + nBottom + 4); 133cdf0e10cSrcweir if ( !IsDropDownBox() ) 134cdf0e10cSrcweir mnDDHeight += 4; 135cdf0e10cSrcweir 136cdf0e10cSrcweir Rectangle aCtrlRegion( Point( 0, 0 ), Size( 10, 10 ) ); 137cdf0e10cSrcweir Rectangle aBoundRegion, aContentRegion; 138cdf0e10cSrcweir ImplControlValue aControlValue; 139cdf0e10cSrcweir ControlType aType = IsDropDownBox() ? CTRL_COMBOBOX : CTRL_EDITBOX; 140cdf0e10cSrcweir if( GetNativeControlRegion( aType, PART_ENTIRE_CONTROL, 141cdf0e10cSrcweir aCtrlRegion, 142cdf0e10cSrcweir CTRL_STATE_ENABLED, 143cdf0e10cSrcweir aControlValue, rtl::OUString(), 144cdf0e10cSrcweir aBoundRegion, aContentRegion ) ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir const long nNCHeight = aBoundRegion.GetHeight(); 147cdf0e10cSrcweir if( mnDDHeight < nNCHeight ) 148cdf0e10cSrcweir mnDDHeight = sal::static_int_cast<sal_uInt16>( nNCHeight ); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir // ----------------------------------------------------------------------- 153cdf0e10cSrcweir 154cdf0e10cSrcweir void ComboBox::ImplInit( Window* pParent, WinBits nStyle ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir ImplInitStyle( nStyle ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir sal_Bool bNoBorder = ( nStyle & WB_NOBORDER ) ? sal_True : sal_False; 159cdf0e10cSrcweir if ( !(nStyle & WB_DROPDOWN) ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir nStyle &= ~WB_BORDER; 162cdf0e10cSrcweir nStyle |= WB_NOBORDER; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir else 165cdf0e10cSrcweir { 166cdf0e10cSrcweir if ( !bNoBorder ) 167cdf0e10cSrcweir nStyle |= WB_BORDER; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir Edit::ImplInit( pParent, nStyle ); 171cdf0e10cSrcweir SetBackground(); 172cdf0e10cSrcweir 173cdf0e10cSrcweir // DropDown ? 174cdf0e10cSrcweir WinBits nEditStyle = nStyle & ( WB_LEFT | WB_RIGHT | WB_CENTER ); 175cdf0e10cSrcweir WinBits nListStyle = nStyle; 176cdf0e10cSrcweir if( nStyle & WB_DROPDOWN ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir mpFloatWin = new ImplListBoxFloatingWindow( this ); 179cdf0e10cSrcweir mpFloatWin->SetAutoWidth( sal_True ); 180cdf0e10cSrcweir mpFloatWin->SetPopupModeEndHdl( LINK( this, ComboBox, ImplPopupModeEndHdl ) ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir mpBtn = new ImplBtn( this, WB_NOLIGHTBORDER | WB_RECTSTYLE ); 183cdf0e10cSrcweir ImplInitDropDownButton( mpBtn ); 184cdf0e10cSrcweir mpBtn->SetMBDownHdl( LINK( this, ComboBox, ImplClickBtnHdl ) ); 185cdf0e10cSrcweir mpBtn->Show(); 186cdf0e10cSrcweir 187cdf0e10cSrcweir nEditStyle |= WB_NOBORDER; 188cdf0e10cSrcweir nListStyle &= ~WB_BORDER; 189cdf0e10cSrcweir nListStyle |= WB_NOBORDER; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir else 192cdf0e10cSrcweir { 193cdf0e10cSrcweir if ( !bNoBorder ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir nEditStyle |= WB_BORDER; 196cdf0e10cSrcweir nListStyle &= ~WB_NOBORDER; 197cdf0e10cSrcweir nListStyle |= WB_BORDER; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir mpSubEdit = new Edit( this, nEditStyle ); 202cdf0e10cSrcweir mpSubEdit->EnableRTL( sal_False ); 203cdf0e10cSrcweir SetSubEdit( mpSubEdit ); 204cdf0e10cSrcweir mpSubEdit->SetPosPixel( Point() ); 205cdf0e10cSrcweir EnableAutocomplete( sal_True ); 206cdf0e10cSrcweir mpSubEdit->Show(); 207cdf0e10cSrcweir 208cdf0e10cSrcweir Window* pLBParent = this; 209cdf0e10cSrcweir if ( mpFloatWin ) 210cdf0e10cSrcweir pLBParent = mpFloatWin; 211cdf0e10cSrcweir mpImplLB = new ImplListBox( pLBParent, nListStyle|WB_SIMPLEMODE ); 212cdf0e10cSrcweir mpImplLB->SetPosPixel( Point() ); 213cdf0e10cSrcweir mpImplLB->SetSelectHdl( LINK( this, ComboBox, ImplSelectHdl ) ); 214cdf0e10cSrcweir mpImplLB->SetCancelHdl( LINK( this, ComboBox, ImplCancelHdl ) ); 215cdf0e10cSrcweir mpImplLB->SetDoubleClickHdl( LINK( this, ComboBox, ImplDoubleClickHdl ) ); 216cdf0e10cSrcweir mpImplLB->SetUserDrawHdl( LINK( this, ComboBox, ImplUserDrawHdl ) ); 217cdf0e10cSrcweir mpImplLB->SetSelectionChangedHdl( LINK( this, ComboBox, ImplSelectionChangedHdl ) ); 218ad3a95a3SSteve Yin mpImplLB->SetListItemSelectHdl( LINK( this, ComboBox, ImplListItemSelectHdl ) ); 219cdf0e10cSrcweir mpImplLB->Show(); 220cdf0e10cSrcweir 221cdf0e10cSrcweir if ( mpFloatWin ) 222cdf0e10cSrcweir mpFloatWin->SetImplListBox( mpImplLB ); 223cdf0e10cSrcweir else 224cdf0e10cSrcweir mpImplLB->GetMainWindow()->AllowGrabFocus( sal_True ); 225cdf0e10cSrcweir 226cdf0e10cSrcweir ImplCalcEditHeight(); 227cdf0e10cSrcweir 228cdf0e10cSrcweir SetCompoundControl( sal_True ); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir // ----------------------------------------------------------------------- 232cdf0e10cSrcweir 233cdf0e10cSrcweir WinBits ComboBox::ImplInitStyle( WinBits nStyle ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir if ( !(nStyle & WB_NOTABSTOP) ) 236cdf0e10cSrcweir nStyle |= WB_TABSTOP; 237cdf0e10cSrcweir if ( !(nStyle & WB_NOGROUP) ) 238cdf0e10cSrcweir nStyle |= WB_GROUP; 239cdf0e10cSrcweir return nStyle; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir // ----------------------------------------------------------------------- 243cdf0e10cSrcweir 244cdf0e10cSrcweir void ComboBox::ImplLoadRes( const ResId& rResId ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir Edit::ImplLoadRes( rResId ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir sal_uLong nNumber = ReadLongRes(); 249cdf0e10cSrcweir 250cdf0e10cSrcweir if( nNumber ) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nNumber; i++ ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir InsertEntry( ReadStringRes(), LISTBOX_APPEND ); 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir // ----------------------------------------------------------------------- 260cdf0e10cSrcweir 261cdf0e10cSrcweir void ComboBox::EnableAutocomplete( sal_Bool bEnable, sal_Bool bMatchCase ) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir mbMatchCase = bMatchCase; 264cdf0e10cSrcweir 265cdf0e10cSrcweir if ( bEnable ) 266cdf0e10cSrcweir mpSubEdit->SetAutocompleteHdl( LINK( this, ComboBox, ImplAutocompleteHdl ) ); 267cdf0e10cSrcweir else 268cdf0e10cSrcweir mpSubEdit->SetAutocompleteHdl( Link() ); 269cdf0e10cSrcweir } 270cdf0e10cSrcweir 271cdf0e10cSrcweir // ----------------------------------------------------------------------- 272cdf0e10cSrcweir 273cdf0e10cSrcweir sal_Bool ComboBox::IsAutocompleteEnabled() const 274cdf0e10cSrcweir { 275cdf0e10cSrcweir return mpSubEdit->GetAutocompleteHdl().IsSet(); 276cdf0e10cSrcweir } 277ad3a95a3SSteve Yin void ComboBox::SetMpSubEditAccessibleName(String &aName) 278ad3a95a3SSteve Yin { 279ad3a95a3SSteve Yin if(mpSubEdit!=NULL) 280ad3a95a3SSteve Yin mpSubEdit->SetAccessibleName(aName); 281ad3a95a3SSteve Yin } 282cdf0e10cSrcweir // ----------------------------------------------------------------------- 283cdf0e10cSrcweir 284cdf0e10cSrcweir IMPL_LINK( ComboBox, ImplClickBtnHdl, void*, EMPTYARG ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN ); 287cdf0e10cSrcweir mpSubEdit->GrabFocus(); 288cdf0e10cSrcweir if ( !mpImplLB->GetEntryList()->GetMRUCount() ) 289cdf0e10cSrcweir ImplUpdateFloatSelection(); 290cdf0e10cSrcweir else 291cdf0e10cSrcweir mpImplLB->SelectEntry( 0 , sal_True ); 292cdf0e10cSrcweir mpBtn->SetPressed( sal_True ); 293cdf0e10cSrcweir SetSelection( Selection( 0, SELECTION_MAX ) ); 294cdf0e10cSrcweir mpFloatWin->StartFloat( sal_True ); 295cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir ImplClearLayoutData(); 298cdf0e10cSrcweir if( mpImplLB ) 299cdf0e10cSrcweir mpImplLB->GetMainWindow()->ImplClearLayoutData(); 300cdf0e10cSrcweir 301cdf0e10cSrcweir return 0; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir // ----------------------------------------------------------------------- 305cdf0e10cSrcweir 306cdf0e10cSrcweir IMPL_LINK( ComboBox, ImplPopupModeEndHdl, void*, EMPTYARG ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir if( mpFloatWin->IsPopupModeCanceled() ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir if ( !mpImplLB->GetEntryList()->IsEntryPosSelected( mpFloatWin->GetPopupModeStartSaveSelection() ) ) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir mpImplLB->SelectEntry( mpFloatWin->GetPopupModeStartSaveSelection(), sal_True ); 313cdf0e10cSrcweir sal_Bool bTravelSelect = mpImplLB->IsTravelSelect(); 314cdf0e10cSrcweir mpImplLB->SetTravelSelect( sal_True ); 315cdf0e10cSrcweir Select(); 316cdf0e10cSrcweir mpImplLB->SetTravelSelect( bTravelSelect ); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir ImplClearLayoutData(); 321cdf0e10cSrcweir if( mpImplLB ) 322cdf0e10cSrcweir mpImplLB->GetMainWindow()->ImplClearLayoutData(); 323cdf0e10cSrcweir 324cdf0e10cSrcweir mpBtn->SetPressed( sal_False ); 325cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_DROPDOWN_CLOSE ); 326cdf0e10cSrcweir return 0; 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir // ----------------------------------------------------------------------- 330cdf0e10cSrcweir 331cdf0e10cSrcweir IMPL_LINK( ComboBox, ImplAutocompleteHdl, Edit*, pEdit ) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir Selection aSel = pEdit->GetSelection(); 334cdf0e10cSrcweir AutocompleteAction eAction = pEdit->GetAutocompleteAction(); 335cdf0e10cSrcweir 336cdf0e10cSrcweir /* If there is no current selection do not auto complete on 337cdf0e10cSrcweir Tab/Shift-Tab since then we would not cycle to the next field. 338cdf0e10cSrcweir */ 339cdf0e10cSrcweir if ( aSel.Len() || 340cdf0e10cSrcweir ((eAction != AUTOCOMPLETE_TABFORWARD) && (eAction != AUTOCOMPLETE_TABBACKWARD)) ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir XubString aFullText = pEdit->GetText(); 343cdf0e10cSrcweir XubString aStartText = aFullText.Copy( 0, (xub_StrLen)aSel.Max() ); 344cdf0e10cSrcweir sal_uInt16 nStart = mpImplLB->GetCurrentPos(); 345cdf0e10cSrcweir 346cdf0e10cSrcweir if ( nStart == LISTBOX_ENTRY_NOTFOUND ) 347cdf0e10cSrcweir nStart = 0; 348cdf0e10cSrcweir 349cdf0e10cSrcweir sal_Bool bForward = sal_True; 350cdf0e10cSrcweir if ( eAction == AUTOCOMPLETE_TABFORWARD ) 351cdf0e10cSrcweir nStart++; 352cdf0e10cSrcweir else if ( eAction == AUTOCOMPLETE_TABBACKWARD ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir bForward = sal_False; 355cdf0e10cSrcweir nStart = nStart ? nStart - 1 : mpImplLB->GetEntryList()->GetEntryCount()-1; 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND; 359cdf0e10cSrcweir if( ! mbMatchCase ) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir // Try match case insensitive from current position 362cdf0e10cSrcweir nPos = mpImplLB->GetEntryList()->FindMatchingEntry( aStartText, nStart, bForward, sal_True ); 363cdf0e10cSrcweir if ( nPos == LISTBOX_ENTRY_NOTFOUND ) 364cdf0e10cSrcweir // Try match case insensitive, but from start 365cdf0e10cSrcweir nPos = mpImplLB->GetEntryList()->FindMatchingEntry( aStartText, bForward ? 0 : (mpImplLB->GetEntryList()->GetEntryCount()-1), bForward, sal_True ); 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir if ( nPos == LISTBOX_ENTRY_NOTFOUND ) 369cdf0e10cSrcweir // Try match full from current position 370cdf0e10cSrcweir nPos = mpImplLB->GetEntryList()->FindMatchingEntry( aStartText, nStart, bForward, sal_False ); 371cdf0e10cSrcweir if ( nPos == LISTBOX_ENTRY_NOTFOUND ) 372cdf0e10cSrcweir // Match full, but from start 373cdf0e10cSrcweir nPos = mpImplLB->GetEntryList()->FindMatchingEntry( aStartText, bForward ? 0 : (mpImplLB->GetEntryList()->GetEntryCount()-1), bForward, sal_False ); 374cdf0e10cSrcweir 375cdf0e10cSrcweir if ( nPos != LISTBOX_ENTRY_NOTFOUND ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir XubString aText = mpImplLB->GetEntryList()->GetEntryText( nPos ); 378cdf0e10cSrcweir Selection aSelection( aText.Len(), aStartText.Len() ); 379cdf0e10cSrcweir pEdit->SetText( aText, aSelection ); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir } 382cdf0e10cSrcweir 383cdf0e10cSrcweir return 0; 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir // ----------------------------------------------------------------------- 387cdf0e10cSrcweir 388cdf0e10cSrcweir IMPL_LINK( ComboBox, ImplSelectHdl, void*, EMPTYARG ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir sal_Bool bPopup = IsInDropDown(); 391cdf0e10cSrcweir sal_Bool bCallSelect = sal_False; 392cdf0e10cSrcweir if ( mpImplLB->IsSelectionChanged() || bPopup ) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir XubString aText; 395cdf0e10cSrcweir if ( IsMultiSelectionEnabled() ) 396cdf0e10cSrcweir { 397cdf0e10cSrcweir aText = mpSubEdit->GetText(); 398cdf0e10cSrcweir 399cdf0e10cSrcweir // Alle Eintraege entfernen, zu denen es einen Entry gibt, der aber nicht selektiert ist. 400cdf0e10cSrcweir xub_StrLen nIndex = 0; 401cdf0e10cSrcweir while ( nIndex != STRING_NOTFOUND ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir xub_StrLen nPrevIndex = nIndex; 404cdf0e10cSrcweir XubString aToken = aText.GetToken( 0, mcMultiSep, nIndex ); 405cdf0e10cSrcweir xub_StrLen nTokenLen = aToken.Len(); 406cdf0e10cSrcweir aToken.EraseLeadingAndTrailingChars( ' ' ); 407cdf0e10cSrcweir sal_uInt16 nP = mpImplLB->GetEntryList()->FindEntry( aToken ); 408cdf0e10cSrcweir if ( (nP != LISTBOX_ENTRY_NOTFOUND) && (!mpImplLB->GetEntryList()->IsEntryPosSelected( nP )) ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir aText.Erase( nPrevIndex, nTokenLen ); 411cdf0e10cSrcweir nIndex = sal::static_int_cast<xub_StrLen>(nIndex - nTokenLen); 412cdf0e10cSrcweir if ( (nPrevIndex < aText.Len()) && (aText.GetChar( nPrevIndex ) == mcMultiSep) ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir aText.Erase( nPrevIndex, 1 ); 415cdf0e10cSrcweir nIndex--; 416cdf0e10cSrcweir } 417cdf0e10cSrcweir } 418cdf0e10cSrcweir aText.EraseLeadingAndTrailingChars( ' ' ); 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir // Fehlende Eintraege anhaengen... 422cdf0e10cSrcweir Table aSelInText; 423cdf0e10cSrcweir lcl_GetSelectedEntries( aSelInText, aText, mcMultiSep, mpImplLB->GetEntryList() ); 424cdf0e10cSrcweir sal_uInt16 nSelectedEntries = mpImplLB->GetEntryList()->GetSelectEntryCount(); 425cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < nSelectedEntries; n++ ) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir sal_uInt16 nP = mpImplLB->GetEntryList()->GetSelectEntryPos( n ); 428cdf0e10cSrcweir if ( !aSelInText.IsKeyValid( ImplCreateKey( nP ) ) ) 429cdf0e10cSrcweir { 430cdf0e10cSrcweir if ( aText.Len() && (aText.GetChar( aText.Len()-1 ) != mcMultiSep) ) 431cdf0e10cSrcweir aText += mcMultiSep; 432cdf0e10cSrcweir if ( aText.Len() ) 433cdf0e10cSrcweir aText += ' '; // etwas auflockern 434cdf0e10cSrcweir aText += mpImplLB->GetEntryList()->GetEntryText( nP ); 435cdf0e10cSrcweir aText += mcMultiSep; 436cdf0e10cSrcweir } 437cdf0e10cSrcweir } 438cdf0e10cSrcweir if ( aText.Len() && (aText.GetChar( aText.Len()-1 ) == mcMultiSep) ) 439cdf0e10cSrcweir aText.Erase( aText.Len()-1, 1 ); 440cdf0e10cSrcweir } 441cdf0e10cSrcweir else 442cdf0e10cSrcweir { 443cdf0e10cSrcweir aText = mpImplLB->GetEntryList()->GetSelectEntry( 0 ); 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir mpSubEdit->SetText( aText ); 447cdf0e10cSrcweir 448cdf0e10cSrcweir Selection aNewSelection( 0, aText.Len() ); 449cdf0e10cSrcweir if ( IsMultiSelectionEnabled() ) 450cdf0e10cSrcweir aNewSelection.Min() = aText.Len(); 451cdf0e10cSrcweir mpSubEdit->SetSelection( aNewSelection ); 452cdf0e10cSrcweir 453cdf0e10cSrcweir bCallSelect = sal_True; 454cdf0e10cSrcweir } 455cdf0e10cSrcweir 456cdf0e10cSrcweir // #84652# Call GrabFocus and EndPopupMode before calling Select/Modify, but after changing the text 457cdf0e10cSrcweir 458cdf0e10cSrcweir if ( bPopup && !mpImplLB->IsTravelSelect() && 459cdf0e10cSrcweir ( !IsMultiSelectionEnabled() || !mpImplLB->GetSelectModifier() ) ) 460cdf0e10cSrcweir { 461cdf0e10cSrcweir mpFloatWin->EndPopupMode(); 462cdf0e10cSrcweir GrabFocus(); 463cdf0e10cSrcweir } 464cdf0e10cSrcweir 465cdf0e10cSrcweir if ( bCallSelect ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir mpSubEdit->SetModifyFlag(); 468cdf0e10cSrcweir mbSyntheticModify = sal_True; 469cdf0e10cSrcweir Modify(); 470cdf0e10cSrcweir mbSyntheticModify = sal_False; 471cdf0e10cSrcweir Select(); 472cdf0e10cSrcweir } 473cdf0e10cSrcweir 474cdf0e10cSrcweir return 0; 475cdf0e10cSrcweir } 476ad3a95a3SSteve Yin IMPL_LINK( ComboBox, ImplListItemSelectHdl, void*, EMPTYARG ) 477ad3a95a3SSteve Yin { 478*6485ffd2SSteve Yin ImplCallEventListeners( VCLEVENT_DROPDOWN_SELECT ); 479ad3a95a3SSteve Yin return 1; 480ad3a95a3SSteve Yin } 481cdf0e10cSrcweir // ----------------------------------------------------------------------- 482cdf0e10cSrcweir 483cdf0e10cSrcweir IMPL_LINK( ComboBox, ImplCancelHdl, void*, EMPTYARG ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir if( IsInDropDown() ) 486cdf0e10cSrcweir mpFloatWin->EndPopupMode(); 487cdf0e10cSrcweir 488cdf0e10cSrcweir return 1; 489cdf0e10cSrcweir } 490cdf0e10cSrcweir 491cdf0e10cSrcweir // ----------------------------------------------------------------------- 492cdf0e10cSrcweir 493cdf0e10cSrcweir IMPL_LINK( ComboBox, ImplSelectionChangedHdl, void*, n ) 494cdf0e10cSrcweir { 495cdf0e10cSrcweir if ( !mpImplLB->IsTrackingSelect() ) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir sal_uInt16 nChanged = (sal_uInt16)(sal_uLong)n; 498cdf0e10cSrcweir if ( !mpSubEdit->IsReadOnly() && mpImplLB->GetEntryList()->IsEntryPosSelected( nChanged ) ) 499cdf0e10cSrcweir mpSubEdit->SetText( mpImplLB->GetEntryList()->GetEntryText( nChanged ) ); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir return 1; 502cdf0e10cSrcweir } 503cdf0e10cSrcweir 504cdf0e10cSrcweir // ----------------------------------------------------------------------- 505cdf0e10cSrcweir 506cdf0e10cSrcweir IMPL_LINK( ComboBox, ImplDoubleClickHdl, void*, EMPTYARG ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir DoubleClick(); 509cdf0e10cSrcweir return 0; 510cdf0e10cSrcweir } 511cdf0e10cSrcweir 512cdf0e10cSrcweir // ----------------------------------------------------------------------- 513cdf0e10cSrcweir 514cdf0e10cSrcweir void ComboBox::ToggleDropDown() 515cdf0e10cSrcweir { 516cdf0e10cSrcweir if( IsDropDownBox() ) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir if( mpFloatWin->IsInPopupMode() ) 519cdf0e10cSrcweir mpFloatWin->EndPopupMode(); 520cdf0e10cSrcweir else 521cdf0e10cSrcweir { 522cdf0e10cSrcweir mpSubEdit->GrabFocus(); 523cdf0e10cSrcweir if ( !mpImplLB->GetEntryList()->GetMRUCount() ) 524cdf0e10cSrcweir ImplUpdateFloatSelection(); 525cdf0e10cSrcweir else 526cdf0e10cSrcweir mpImplLB->SelectEntry( 0 , sal_True ); 527cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN ); 528cdf0e10cSrcweir mpBtn->SetPressed( sal_True ); 529cdf0e10cSrcweir SetSelection( Selection( 0, SELECTION_MAX ) ); 530cdf0e10cSrcweir mpFloatWin->StartFloat( sal_True ); 531cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN ); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir } 534cdf0e10cSrcweir } 535cdf0e10cSrcweir 536cdf0e10cSrcweir // ----------------------------------------------------------------------- 537cdf0e10cSrcweir 538cdf0e10cSrcweir void ComboBox::Select() 539cdf0e10cSrcweir { 540cdf0e10cSrcweir ImplCallEventListenersAndHandler( VCLEVENT_COMBOBOX_SELECT, maSelectHdl, this ); 541cdf0e10cSrcweir } 542cdf0e10cSrcweir 543cdf0e10cSrcweir // ----------------------------------------------------------------------- 544cdf0e10cSrcweir 545cdf0e10cSrcweir void ComboBox::DoubleClick() 546cdf0e10cSrcweir { 547cdf0e10cSrcweir ImplCallEventListenersAndHandler( VCLEVENT_COMBOBOX_DOUBLECLICK, maDoubleClickHdl, this ); 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir // ----------------------------------------------------------------------- 551cdf0e10cSrcweir 552cdf0e10cSrcweir void ComboBox::EnableAutoSize( sal_Bool bAuto ) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir mbDDAutoSize = bAuto; 555cdf0e10cSrcweir if ( mpFloatWin ) 556cdf0e10cSrcweir { 557cdf0e10cSrcweir if ( bAuto && !mpFloatWin->GetDropDownLineCount() ) 558a68b38dfSArmin Le Grand { 559a68b38dfSArmin Le Grand // Adapt to GetListBoxMaximumLineCount here; was on fixed number of five before 560a68b38dfSArmin Le Grand AdaptDropDownLineCountToMaximum(); 561a68b38dfSArmin Le Grand } 562cdf0e10cSrcweir else if ( !bAuto ) 563a68b38dfSArmin Le Grand { 564cdf0e10cSrcweir mpFloatWin->SetDropDownLineCount( 0 ); 565cdf0e10cSrcweir } 566cdf0e10cSrcweir } 567a68b38dfSArmin Le Grand } 568cdf0e10cSrcweir 569cdf0e10cSrcweir // ----------------------------------------------------------------------- 570cdf0e10cSrcweir 571cdf0e10cSrcweir void ComboBox::EnableDDAutoWidth( sal_Bool b ) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir if ( mpFloatWin ) 574cdf0e10cSrcweir mpFloatWin->SetAutoWidth( b ); 575cdf0e10cSrcweir } 576cdf0e10cSrcweir 577cdf0e10cSrcweir // ----------------------------------------------------------------------- 578cdf0e10cSrcweir 579cdf0e10cSrcweir sal_Bool ComboBox::IsDDAutoWidthEnabled() const 580cdf0e10cSrcweir { 581cdf0e10cSrcweir return mpFloatWin ? mpFloatWin->IsAutoWidth() : sal_False; 582cdf0e10cSrcweir } 583cdf0e10cSrcweir 584cdf0e10cSrcweir 585cdf0e10cSrcweir // ----------------------------------------------------------------------- 586cdf0e10cSrcweir 587cdf0e10cSrcweir void ComboBox::SetDropDownLineCount( sal_uInt16 nLines ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir if ( mpFloatWin ) 590cdf0e10cSrcweir mpFloatWin->SetDropDownLineCount( nLines ); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir // ----------------------------------------------------------------------- 594cdf0e10cSrcweir 595a68b38dfSArmin Le Grand void ComboBox::AdaptDropDownLineCountToMaximum() 596a68b38dfSArmin Le Grand { 597a68b38dfSArmin Le Grand // adapt to maximum allowed number 598a68b38dfSArmin Le Grand SetDropDownLineCount(std::min(GetEntryCount(), GetSettings().GetStyleSettings().GetListBoxMaximumLineCount())); 599a68b38dfSArmin Le Grand } 600a68b38dfSArmin Le Grand 601a68b38dfSArmin Le Grand // ----------------------------------------------------------------------- 602a68b38dfSArmin Le Grand 603cdf0e10cSrcweir sal_uInt16 ComboBox::GetDropDownLineCount() const 604cdf0e10cSrcweir { 605cdf0e10cSrcweir sal_uInt16 nLines = 0; 606cdf0e10cSrcweir if ( mpFloatWin ) 607cdf0e10cSrcweir nLines = mpFloatWin->GetDropDownLineCount(); 608cdf0e10cSrcweir return nLines; 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir // ----------------------------------------------------------------------- 612cdf0e10cSrcweir 613cdf0e10cSrcweir void ComboBox::SetPosSizePixel( long nX, long nY, long nWidth, long nHeight, 614cdf0e10cSrcweir sal_uInt16 nFlags ) 615cdf0e10cSrcweir { 616cdf0e10cSrcweir if( IsDropDownBox() && ( nFlags & WINDOW_POSSIZE_SIZE ) ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir Size aPrefSz = mpFloatWin->GetPrefSize(); 619cdf0e10cSrcweir if ( ( nFlags & WINDOW_POSSIZE_HEIGHT ) && ( nHeight >= 2*mnDDHeight ) ) 620cdf0e10cSrcweir aPrefSz.Height() = nHeight-mnDDHeight; 621cdf0e10cSrcweir if ( nFlags & WINDOW_POSSIZE_WIDTH ) 622cdf0e10cSrcweir aPrefSz.Width() = nWidth; 623cdf0e10cSrcweir mpFloatWin->SetPrefSize( aPrefSz ); 624cdf0e10cSrcweir 625cdf0e10cSrcweir if ( IsAutoSizeEnabled() && ! (nFlags & WINDOW_POSSIZE_DROPDOWN) ) 626cdf0e10cSrcweir nHeight = mnDDHeight; 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir Edit::SetPosSizePixel( nX, nY, nWidth, nHeight, nFlags ); 630cdf0e10cSrcweir } 631cdf0e10cSrcweir 632cdf0e10cSrcweir // ----------------------------------------------------------------------- 633cdf0e10cSrcweir 634cdf0e10cSrcweir void ComboBox::Resize() 635cdf0e10cSrcweir { 636cdf0e10cSrcweir Control::Resize(); 637cdf0e10cSrcweir 638cdf0e10cSrcweir Size aOutSz = GetOutputSizePixel(); 639cdf0e10cSrcweir if( IsDropDownBox() ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize(); 642cdf0e10cSrcweir long nTop = 0; 643cdf0e10cSrcweir long nBottom = aOutSz.Height(); 644cdf0e10cSrcweir 645cdf0e10cSrcweir Window *pBorder = GetWindow( WINDOW_BORDER ); 646cdf0e10cSrcweir ImplControlValue aControlValue; 647cdf0e10cSrcweir Point aPoint; 648cdf0e10cSrcweir Rectangle aContent, aBound; 649cdf0e10cSrcweir 650cdf0e10cSrcweir // use the full extent of the control 651cdf0e10cSrcweir Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() ); 652cdf0e10cSrcweir 653cdf0e10cSrcweir if ( GetNativeControlRegion(CTRL_COMBOBOX, PART_BUTTON_DOWN, 654cdf0e10cSrcweir aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) ) 655cdf0e10cSrcweir { 656cdf0e10cSrcweir // convert back from border space to local coordinates 657cdf0e10cSrcweir aPoint = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aPoint ) ); 658cdf0e10cSrcweir aContent.Move(-aPoint.X(), -aPoint.Y()); 659cdf0e10cSrcweir 660cdf0e10cSrcweir mpBtn->SetPosSizePixel( aContent.Left(), nTop, aContent.getWidth(), (nBottom-nTop) ); 661cdf0e10cSrcweir 662cdf0e10cSrcweir // adjust the size of the edit field 663cdf0e10cSrcweir if ( GetNativeControlRegion(CTRL_COMBOBOX, PART_SUB_EDIT, 664cdf0e10cSrcweir aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) ) 665cdf0e10cSrcweir { 666cdf0e10cSrcweir // convert back from border space to local coordinates 667cdf0e10cSrcweir aContent.Move(-aPoint.X(), -aPoint.Y()); 668cdf0e10cSrcweir 669cdf0e10cSrcweir // use the themes drop down size 670cdf0e10cSrcweir mpSubEdit->SetPosSizePixel( aContent.TopLeft(), aContent.GetSize() ); 671cdf0e10cSrcweir } 672cdf0e10cSrcweir else 673cdf0e10cSrcweir { 674cdf0e10cSrcweir // use the themes drop down size for the button 675cdf0e10cSrcweir aOutSz.Width() -= aContent.getWidth(); 676cdf0e10cSrcweir mpSubEdit->SetSizePixel( aOutSz ); 677cdf0e10cSrcweir } 678cdf0e10cSrcweir } 679cdf0e10cSrcweir else 680cdf0e10cSrcweir { 681cdf0e10cSrcweir nSBWidth = CalcZoom( nSBWidth ); 682cdf0e10cSrcweir mpSubEdit->SetPosSizePixel( Point( 0, 0 ), Size( aOutSz.Width() - nSBWidth, aOutSz.Height() ) ); 683cdf0e10cSrcweir mpBtn->SetPosSizePixel( aOutSz.Width() - nSBWidth, nTop, nSBWidth, (nBottom-nTop) ); 684cdf0e10cSrcweir } 685cdf0e10cSrcweir } 686cdf0e10cSrcweir else 687cdf0e10cSrcweir { 688cdf0e10cSrcweir mpSubEdit->SetSizePixel( Size( aOutSz.Width(), mnDDHeight ) ); 689cdf0e10cSrcweir mpImplLB->SetPosSizePixel( 0, mnDDHeight, aOutSz.Width(), aOutSz.Height() - mnDDHeight ); 690cdf0e10cSrcweir if ( GetText().Len() ) 691cdf0e10cSrcweir ImplUpdateFloatSelection(); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir 694cdf0e10cSrcweir // FloatingWindow-Groesse auch im unsichtbare Zustand auf Stand halten, 695cdf0e10cSrcweir // weil KEY_PGUP/DOWN ausgewertet wird... 696cdf0e10cSrcweir if ( mpFloatWin ) 697cdf0e10cSrcweir mpFloatWin->SetSizePixel( mpFloatWin->CalcFloatSize() ); 698cdf0e10cSrcweir } 699cdf0e10cSrcweir 700cdf0e10cSrcweir // ----------------------------------------------------------------------- 701cdf0e10cSrcweir 702cdf0e10cSrcweir void ComboBox::FillLayoutData() const 703cdf0e10cSrcweir { 704cdf0e10cSrcweir mpControlData->mpLayoutData = new vcl::ControlLayoutData(); 705cdf0e10cSrcweir AppendLayoutData( *mpSubEdit ); 706cdf0e10cSrcweir mpSubEdit->SetLayoutDataParent( this ); 707cdf0e10cSrcweir Control* pMainWindow = mpImplLB->GetMainWindow(); 708cdf0e10cSrcweir if( mpFloatWin ) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir // dropdown mode 711cdf0e10cSrcweir if( mpFloatWin->IsReallyVisible() ) 712cdf0e10cSrcweir { 713cdf0e10cSrcweir AppendLayoutData( *pMainWindow ); 714cdf0e10cSrcweir pMainWindow->SetLayoutDataParent( this ); 715cdf0e10cSrcweir } 716cdf0e10cSrcweir } 717cdf0e10cSrcweir else 718cdf0e10cSrcweir { 719cdf0e10cSrcweir AppendLayoutData( *pMainWindow ); 720cdf0e10cSrcweir pMainWindow->SetLayoutDataParent( this ); 721cdf0e10cSrcweir } 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir // ----------------------------------------------------------------------- 725cdf0e10cSrcweir 726cdf0e10cSrcweir void ComboBox::StateChanged( StateChangedType nType ) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir Edit::StateChanged( nType ); 729cdf0e10cSrcweir 730cdf0e10cSrcweir if ( nType == STATE_CHANGE_READONLY ) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir mpImplLB->SetReadOnly( IsReadOnly() ); 733cdf0e10cSrcweir if ( mpBtn ) 734cdf0e10cSrcweir mpBtn->Enable( IsEnabled() && !IsReadOnly() ); 735cdf0e10cSrcweir } 736cdf0e10cSrcweir else if ( nType == STATE_CHANGE_ENABLE ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir mpSubEdit->Enable( IsEnabled() ); 739cdf0e10cSrcweir mpImplLB->Enable( IsEnabled() && !IsReadOnly() ); 740cdf0e10cSrcweir if ( mpBtn ) 741cdf0e10cSrcweir mpBtn->Enable( IsEnabled() && !IsReadOnly() ); 742cdf0e10cSrcweir Invalidate(); 743cdf0e10cSrcweir } 744cdf0e10cSrcweir else if( nType == STATE_CHANGE_UPDATEMODE ) 745cdf0e10cSrcweir { 746cdf0e10cSrcweir mpImplLB->SetUpdateMode( IsUpdateMode() ); 747cdf0e10cSrcweir } 748cdf0e10cSrcweir else if ( nType == STATE_CHANGE_ZOOM ) 749cdf0e10cSrcweir { 750cdf0e10cSrcweir mpImplLB->SetZoom( GetZoom() ); 751cdf0e10cSrcweir mpSubEdit->SetZoom( GetZoom() ); 752cdf0e10cSrcweir ImplCalcEditHeight(); 753cdf0e10cSrcweir Resize(); 754cdf0e10cSrcweir } 755cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFONT ) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir mpImplLB->SetControlFont( GetControlFont() ); 758cdf0e10cSrcweir mpSubEdit->SetControlFont( GetControlFont() ); 759cdf0e10cSrcweir ImplCalcEditHeight(); 760cdf0e10cSrcweir Resize(); 761cdf0e10cSrcweir } 762cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFOREGROUND ) 763cdf0e10cSrcweir { 764cdf0e10cSrcweir mpImplLB->SetControlForeground( GetControlForeground() ); 765cdf0e10cSrcweir mpSubEdit->SetControlForeground( GetControlForeground() ); 766cdf0e10cSrcweir } 767cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 768cdf0e10cSrcweir { 769cdf0e10cSrcweir mpImplLB->SetControlBackground( GetControlBackground() ); 770cdf0e10cSrcweir mpSubEdit->SetControlBackground( GetControlBackground() ); 771cdf0e10cSrcweir } 772cdf0e10cSrcweir else if ( nType == STATE_CHANGE_STYLE ) 773cdf0e10cSrcweir { 774cdf0e10cSrcweir SetStyle( ImplInitStyle( GetStyle() ) ); 775cdf0e10cSrcweir mpImplLB->GetMainWindow()->EnableSort( ( GetStyle() & WB_SORT ) ? sal_True : sal_False ); 776cdf0e10cSrcweir } 777cdf0e10cSrcweir else if( nType == STATE_CHANGE_MIRRORING ) 778cdf0e10cSrcweir { 779cdf0e10cSrcweir if( mpBtn ) 780cdf0e10cSrcweir { 781cdf0e10cSrcweir mpBtn->EnableRTL( IsRTLEnabled() ); 782cdf0e10cSrcweir ImplInitDropDownButton( mpBtn ); 783cdf0e10cSrcweir } 784cdf0e10cSrcweir mpSubEdit->StateChanged( STATE_CHANGE_MIRRORING ); 785cdf0e10cSrcweir mpImplLB->EnableRTL( IsRTLEnabled() ); 786cdf0e10cSrcweir Resize(); 787cdf0e10cSrcweir } 788cdf0e10cSrcweir } 789cdf0e10cSrcweir 790cdf0e10cSrcweir // ----------------------------------------------------------------------- 791cdf0e10cSrcweir 792cdf0e10cSrcweir void ComboBox::DataChanged( const DataChangedEvent& rDCEvt ) 793cdf0e10cSrcweir { 794cdf0e10cSrcweir Control::DataChanged( rDCEvt ); 795cdf0e10cSrcweir 796cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_FONTS) || 797cdf0e10cSrcweir (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) || 798cdf0e10cSrcweir ((rDCEvt.GetType() == DATACHANGED_SETTINGS) && 799cdf0e10cSrcweir (rDCEvt.GetFlags() & SETTINGS_STYLE)) ) 800cdf0e10cSrcweir { 801cdf0e10cSrcweir if ( mpBtn ) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir mpBtn->SetSettings( GetSettings() ); 804cdf0e10cSrcweir ImplInitDropDownButton( mpBtn ); 805cdf0e10cSrcweir } 806cdf0e10cSrcweir Resize(); 807cdf0e10cSrcweir mpImplLB->Resize(); // Wird nicht durch ComboBox::Resize() gerufen, wenn sich die ImplLB nicht aendert. 808cdf0e10cSrcweir SetBackground(); // due to a hack in Window::UpdateSettings the background must be reset 809cdf0e10cSrcweir // otherwise it will overpaint NWF drawn comboboxes 810cdf0e10cSrcweir } 811cdf0e10cSrcweir } 812cdf0e10cSrcweir 813cdf0e10cSrcweir // ----------------------------------------------------------------------- 814cdf0e10cSrcweir 815cdf0e10cSrcweir long ComboBox::PreNotify( NotifyEvent& rNEvt ) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir 818cdf0e10cSrcweir return Edit::PreNotify( rNEvt ); 819cdf0e10cSrcweir } 820cdf0e10cSrcweir 821cdf0e10cSrcweir // ----------------------------------------------------------------------- 822cdf0e10cSrcweir 823cdf0e10cSrcweir long ComboBox::Notify( NotifyEvent& rNEvt ) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir long nDone = 0; 826cdf0e10cSrcweir if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && ( rNEvt.GetWindow() == mpSubEdit ) 827cdf0e10cSrcweir && !IsReadOnly() ) 828cdf0e10cSrcweir { 829cdf0e10cSrcweir KeyEvent aKeyEvt = *rNEvt.GetKeyEvent(); 830cdf0e10cSrcweir sal_uInt16 nKeyCode = aKeyEvt.GetKeyCode().GetCode(); 831cdf0e10cSrcweir switch( nKeyCode ) 832cdf0e10cSrcweir { 833cdf0e10cSrcweir case KEY_UP: 834cdf0e10cSrcweir case KEY_DOWN: 835cdf0e10cSrcweir case KEY_PAGEUP: 836cdf0e10cSrcweir case KEY_PAGEDOWN: 837cdf0e10cSrcweir { 838cdf0e10cSrcweir ImplUpdateFloatSelection(); 839cdf0e10cSrcweir if( ( nKeyCode == KEY_DOWN ) && mpFloatWin && !mpFloatWin->IsInPopupMode() && aKeyEvt.GetKeyCode().IsMod2() ) 840cdf0e10cSrcweir { 841cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_DROPDOWN_PRE_OPEN ); 842cdf0e10cSrcweir mpBtn->SetPressed( sal_True ); 843cdf0e10cSrcweir if ( mpImplLB->GetEntryList()->GetMRUCount() ) 844cdf0e10cSrcweir mpImplLB->SelectEntry( 0 , sal_True ); 845cdf0e10cSrcweir SetSelection( Selection( 0, SELECTION_MAX ) ); 846cdf0e10cSrcweir mpFloatWin->StartFloat( sal_False ); 847cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_DROPDOWN_OPEN ); 848cdf0e10cSrcweir nDone = 1; 849cdf0e10cSrcweir } 850cdf0e10cSrcweir else if( ( nKeyCode == KEY_UP ) && mpFloatWin && mpFloatWin->IsInPopupMode() && aKeyEvt.GetKeyCode().IsMod2() ) 851cdf0e10cSrcweir { 852cdf0e10cSrcweir mpFloatWin->EndPopupMode(); 853cdf0e10cSrcweir nDone = 1; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir else 856cdf0e10cSrcweir { 857cdf0e10cSrcweir nDone = mpImplLB->ProcessKeyInput( aKeyEvt ); 858cdf0e10cSrcweir } 859cdf0e10cSrcweir } 860cdf0e10cSrcweir break; 861cdf0e10cSrcweir 862cdf0e10cSrcweir case KEY_RETURN: 863cdf0e10cSrcweir { 864cdf0e10cSrcweir if( ( rNEvt.GetWindow() == mpSubEdit ) && IsInDropDown() ) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir mpImplLB->ProcessKeyInput( aKeyEvt ); 867cdf0e10cSrcweir nDone = 1; 868cdf0e10cSrcweir } 869cdf0e10cSrcweir } 870cdf0e10cSrcweir break; 871cdf0e10cSrcweir } 872cdf0e10cSrcweir } 873cdf0e10cSrcweir else if ( (rNEvt.GetType() == EVENT_LOSEFOCUS) && mpFloatWin ) 874cdf0e10cSrcweir { 875cdf0e10cSrcweir if( mpFloatWin->HasChildPathFocus() ) 876cdf0e10cSrcweir mpSubEdit->GrabFocus(); 877cdf0e10cSrcweir else if ( mpFloatWin->IsInPopupMode() && !HasChildPathFocus( sal_True ) ) 878cdf0e10cSrcweir mpFloatWin->EndPopupMode(); 879cdf0e10cSrcweir } 880cdf0e10cSrcweir else if( (rNEvt.GetType() == EVENT_COMMAND) && 881cdf0e10cSrcweir (rNEvt.GetCommandEvent()->GetCommand() == COMMAND_WHEEL) && 882cdf0e10cSrcweir (rNEvt.GetWindow() == mpSubEdit) ) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir sal_uInt16 nWheelBehavior( GetSettings().GetMouseSettings().GetWheelBehavior() ); 885cdf0e10cSrcweir if ( ( nWheelBehavior == MOUSE_WHEEL_ALWAYS ) 886cdf0e10cSrcweir || ( ( nWheelBehavior == MOUSE_WHEEL_FOCUS_ONLY ) 887cdf0e10cSrcweir && HasChildPathFocus() 888cdf0e10cSrcweir ) 889cdf0e10cSrcweir ) 890cdf0e10cSrcweir { 891cdf0e10cSrcweir nDone = mpImplLB->HandleWheelAsCursorTravel( *rNEvt.GetCommandEvent() ); 892cdf0e10cSrcweir } 893cdf0e10cSrcweir else 894cdf0e10cSrcweir { 895cdf0e10cSrcweir nDone = 0; // don't eat this event, let the default handling happen (i.e. scroll the context) 896cdf0e10cSrcweir } 897cdf0e10cSrcweir } 898cdf0e10cSrcweir else if( ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN ) && ( rNEvt.GetWindow() == mpImplLB->GetMainWindow() ) ) 899cdf0e10cSrcweir { 900cdf0e10cSrcweir mpSubEdit->GrabFocus(); 901cdf0e10cSrcweir } 902cdf0e10cSrcweir 903cdf0e10cSrcweir return nDone ? nDone : Edit::Notify( rNEvt ); 904cdf0e10cSrcweir } 905cdf0e10cSrcweir 906cdf0e10cSrcweir // ----------------------------------------------------------------------- 907cdf0e10cSrcweir 908cdf0e10cSrcweir void ComboBox::SetText( const XubString& rStr ) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_COMBOBOX_SETTEXT ); 911cdf0e10cSrcweir 912cdf0e10cSrcweir Edit::SetText( rStr ); 913cdf0e10cSrcweir ImplUpdateFloatSelection(); 914cdf0e10cSrcweir } 915cdf0e10cSrcweir 916cdf0e10cSrcweir // ----------------------------------------------------------------------- 917cdf0e10cSrcweir 918cdf0e10cSrcweir void ComboBox::SetText( const XubString& rStr, const Selection& rNewSelection ) 919cdf0e10cSrcweir { 920cdf0e10cSrcweir ImplCallEventListeners( VCLEVENT_COMBOBOX_SETTEXT ); 921cdf0e10cSrcweir 922cdf0e10cSrcweir Edit::SetText( rStr, rNewSelection ); 923cdf0e10cSrcweir ImplUpdateFloatSelection(); 924cdf0e10cSrcweir } 925cdf0e10cSrcweir 926cdf0e10cSrcweir // ----------------------------------------------------------------------- 927cdf0e10cSrcweir 928cdf0e10cSrcweir void ComboBox::Modify() 929cdf0e10cSrcweir { 930cdf0e10cSrcweir if ( !mbSyntheticModify ) 931cdf0e10cSrcweir ImplUpdateFloatSelection(); 932cdf0e10cSrcweir 933cdf0e10cSrcweir Edit::Modify(); 934cdf0e10cSrcweir } 935cdf0e10cSrcweir 936cdf0e10cSrcweir // ----------------------------------------------------------------------- 937cdf0e10cSrcweir 938cdf0e10cSrcweir void ComboBox::ImplUpdateFloatSelection() 939cdf0e10cSrcweir { 940cdf0e10cSrcweir // Text in der ListBox in den sichtbaren Bereich bringen 941cdf0e10cSrcweir mpImplLB->SetCallSelectionChangedHdl( sal_False ); 942cdf0e10cSrcweir if ( !IsMultiSelectionEnabled() ) 943cdf0e10cSrcweir { 944cdf0e10cSrcweir XubString aSearchStr( mpSubEdit->GetText() ); 945cdf0e10cSrcweir sal_uInt16 nSelect = LISTBOX_ENTRY_NOTFOUND; 946cdf0e10cSrcweir sal_Bool bSelect = sal_True; 947cdf0e10cSrcweir 948cdf0e10cSrcweir if ( mpImplLB->GetCurrentPos() != LISTBOX_ENTRY_NOTFOUND ) 949cdf0e10cSrcweir { 950cdf0e10cSrcweir XubString aCurrent = mpImplLB->GetEntryList()->GetEntryText( mpImplLB->GetCurrentPos() ); 951cdf0e10cSrcweir if ( aCurrent == aSearchStr ) 952cdf0e10cSrcweir nSelect = mpImplLB->GetCurrentPos(); 953cdf0e10cSrcweir } 954cdf0e10cSrcweir 955cdf0e10cSrcweir if ( nSelect == LISTBOX_ENTRY_NOTFOUND ) 956cdf0e10cSrcweir nSelect = mpImplLB->GetEntryList()->FindEntry( aSearchStr ); 957cdf0e10cSrcweir if ( nSelect == LISTBOX_ENTRY_NOTFOUND ) 958cdf0e10cSrcweir { 959cdf0e10cSrcweir nSelect = mpImplLB->GetEntryList()->FindMatchingEntry( aSearchStr ); 960cdf0e10cSrcweir bSelect = sal_False; 961cdf0e10cSrcweir } 962cdf0e10cSrcweir 963cdf0e10cSrcweir if( nSelect != LISTBOX_ENTRY_NOTFOUND ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir if ( !mpImplLB->IsVisible( nSelect ) ) 966cdf0e10cSrcweir mpImplLB->ShowProminentEntry( nSelect ); 967cdf0e10cSrcweir mpImplLB->SelectEntry( nSelect, bSelect ); 968cdf0e10cSrcweir } 969cdf0e10cSrcweir else 970cdf0e10cSrcweir { 971cdf0e10cSrcweir nSelect = mpImplLB->GetEntryList()->GetSelectEntryPos( 0 ); 972cdf0e10cSrcweir if( nSelect != LISTBOX_ENTRY_NOTFOUND ) 973cdf0e10cSrcweir mpImplLB->SelectEntry( nSelect, sal_False ); 974cdf0e10cSrcweir mpImplLB->ResetCurrentPos(); 975cdf0e10cSrcweir } 976cdf0e10cSrcweir } 977cdf0e10cSrcweir else 978cdf0e10cSrcweir { 979cdf0e10cSrcweir Table aSelInText; 980cdf0e10cSrcweir lcl_GetSelectedEntries( aSelInText, mpSubEdit->GetText(), mcMultiSep, mpImplLB->GetEntryList() ); 981cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < mpImplLB->GetEntryList()->GetEntryCount(); n++ ) 982cdf0e10cSrcweir mpImplLB->SelectEntry( n, aSelInText.IsKeyValid( ImplCreateKey( n ) ) ); 983cdf0e10cSrcweir } 984cdf0e10cSrcweir mpImplLB->SetCallSelectionChangedHdl( sal_True ); 985cdf0e10cSrcweir } 986cdf0e10cSrcweir 987cdf0e10cSrcweir // ----------------------------------------------------------------------- 988cdf0e10cSrcweir 989cdf0e10cSrcweir sal_uInt16 ComboBox::InsertEntry( const XubString& rStr, sal_uInt16 nPos ) 990cdf0e10cSrcweir { 991cdf0e10cSrcweir sal_uInt16 nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rStr ); 992cdf0e10cSrcweir nRealPos = sal::static_int_cast<sal_uInt16>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount()); 993cdf0e10cSrcweir CallEventListeners( VCLEVENT_COMBOBOX_ITEMADDED, (void*) sal_IntPtr(nRealPos) ); 994cdf0e10cSrcweir return nRealPos; 995cdf0e10cSrcweir } 996cdf0e10cSrcweir 997cdf0e10cSrcweir // ----------------------------------------------------------------------- 998cdf0e10cSrcweir 999cdf0e10cSrcweir sal_uInt16 ComboBox::InsertEntry( const XubString& rStr, const Image& rImage, sal_uInt16 nPos ) 1000cdf0e10cSrcweir { 1001cdf0e10cSrcweir sal_uInt16 nRealPos = mpImplLB->InsertEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), rStr, rImage ); 1002cdf0e10cSrcweir nRealPos = sal::static_int_cast<sal_uInt16>(nRealPos - mpImplLB->GetEntryList()->GetMRUCount()); 1003cdf0e10cSrcweir CallEventListeners( VCLEVENT_COMBOBOX_ITEMADDED, (void*) sal_IntPtr(nRealPos) ); 1004cdf0e10cSrcweir return nRealPos; 1005cdf0e10cSrcweir } 1006cdf0e10cSrcweir 1007cdf0e10cSrcweir // ----------------------------------------------------------------------- 1008cdf0e10cSrcweir 1009cdf0e10cSrcweir void ComboBox::RemoveEntry( const XubString& rStr ) 1010cdf0e10cSrcweir { 1011cdf0e10cSrcweir RemoveEntry( GetEntryPos( rStr ) ); 1012cdf0e10cSrcweir } 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir // ----------------------------------------------------------------------- 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir void ComboBox::RemoveEntry( sal_uInt16 nPos ) 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir mpImplLB->RemoveEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount() ); 1019cdf0e10cSrcweir CallEventListeners( VCLEVENT_COMBOBOX_ITEMREMOVED, (void*) sal_IntPtr(nPos) ); 1020cdf0e10cSrcweir } 1021cdf0e10cSrcweir 1022cdf0e10cSrcweir // ----------------------------------------------------------------------- 1023cdf0e10cSrcweir 1024cdf0e10cSrcweir void ComboBox::Clear() 1025cdf0e10cSrcweir { 1026cdf0e10cSrcweir mpImplLB->Clear(); 1027cdf0e10cSrcweir CallEventListeners( VCLEVENT_COMBOBOX_ITEMREMOVED, (void*) sal_IntPtr(-1) ); 1028cdf0e10cSrcweir } 1029cdf0e10cSrcweir // ----------------------------------------------------------------------- 1030cdf0e10cSrcweir 1031cdf0e10cSrcweir Image ComboBox::GetEntryImage( sal_uInt16 nPos ) const 1032cdf0e10cSrcweir { 1033cdf0e10cSrcweir if ( mpImplLB->GetEntryList()->HasEntryImage( nPos ) ) 1034cdf0e10cSrcweir return mpImplLB->GetEntryList()->GetEntryImage( nPos ); 1035cdf0e10cSrcweir return Image(); 1036cdf0e10cSrcweir } 1037cdf0e10cSrcweir 1038cdf0e10cSrcweir // ----------------------------------------------------------------------- 1039cdf0e10cSrcweir 1040cdf0e10cSrcweir sal_uInt16 ComboBox::GetEntryPos( const XubString& rStr ) const 1041cdf0e10cSrcweir { 1042cdf0e10cSrcweir sal_uInt16 nPos = mpImplLB->GetEntryList()->FindEntry( rStr ); 1043cdf0e10cSrcweir if ( nPos != LISTBOX_ENTRY_NOTFOUND ) 1044cdf0e10cSrcweir nPos = sal::static_int_cast<sal_uInt16>(nPos - mpImplLB->GetEntryList()->GetMRUCount()); 1045cdf0e10cSrcweir return nPos; 1046cdf0e10cSrcweir } 1047cdf0e10cSrcweir 1048cdf0e10cSrcweir // ----------------------------------------------------------------------- 1049cdf0e10cSrcweir 1050cdf0e10cSrcweir sal_uInt16 ComboBox::GetEntryPos( const void* pData ) const 1051cdf0e10cSrcweir { 1052cdf0e10cSrcweir sal_uInt16 nPos = mpImplLB->GetEntryList()->FindEntry( pData ); 1053cdf0e10cSrcweir if ( nPos != LISTBOX_ENTRY_NOTFOUND ) 1054cdf0e10cSrcweir nPos = sal::static_int_cast<sal_uInt16>(nPos - mpImplLB->GetEntryList()->GetMRUCount()); 1055cdf0e10cSrcweir return nPos; 1056cdf0e10cSrcweir } 1057cdf0e10cSrcweir 1058cdf0e10cSrcweir // ----------------------------------------------------------------------- 1059cdf0e10cSrcweir 1060cdf0e10cSrcweir XubString ComboBox::GetEntry( sal_uInt16 nPos ) const 1061cdf0e10cSrcweir { 1062cdf0e10cSrcweir return mpImplLB->GetEntryList()->GetEntryText( nPos + mpImplLB->GetEntryList()->GetMRUCount() ); 1063cdf0e10cSrcweir } 1064cdf0e10cSrcweir 1065cdf0e10cSrcweir // ----------------------------------------------------------------------- 1066cdf0e10cSrcweir 1067cdf0e10cSrcweir sal_uInt16 ComboBox::GetEntryCount() const 1068cdf0e10cSrcweir { 1069cdf0e10cSrcweir return mpImplLB->GetEntryList()->GetEntryCount() - mpImplLB->GetEntryList()->GetMRUCount(); 1070cdf0e10cSrcweir } 1071cdf0e10cSrcweir 1072cdf0e10cSrcweir // ----------------------------------------------------------------------- 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir sal_Bool ComboBox::IsTravelSelect() const 1075cdf0e10cSrcweir { 1076cdf0e10cSrcweir return mpImplLB->IsTravelSelect(); 1077cdf0e10cSrcweir } 1078cdf0e10cSrcweir 1079cdf0e10cSrcweir // ----------------------------------------------------------------------- 1080cdf0e10cSrcweir 1081cdf0e10cSrcweir sal_Bool ComboBox::IsInDropDown() const 1082cdf0e10cSrcweir { 1083cdf0e10cSrcweir return mpFloatWin && mpFloatWin->IsInPopupMode(); 1084cdf0e10cSrcweir } 1085cdf0e10cSrcweir 1086cdf0e10cSrcweir // ----------------------------------------------------------------------- 1087cdf0e10cSrcweir 1088cdf0e10cSrcweir void ComboBox::EnableMultiSelection( sal_Bool bMulti ) 1089cdf0e10cSrcweir { 1090cdf0e10cSrcweir mpImplLB->EnableMultiSelection( bMulti, sal_False ); 1091cdf0e10cSrcweir mpImplLB->SetMultiSelectionSimpleMode( sal_True ); 1092cdf0e10cSrcweir } 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir // ----------------------------------------------------------------------- 1095cdf0e10cSrcweir 1096cdf0e10cSrcweir sal_Bool ComboBox::IsMultiSelectionEnabled() const 1097cdf0e10cSrcweir { 1098cdf0e10cSrcweir return mpImplLB->IsMultiSelectionEnabled(); 1099cdf0e10cSrcweir } 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir // ----------------------------------------------------------------------- 1102cdf0e10cSrcweir 1103cdf0e10cSrcweir long ComboBox::CalcWindowSizePixel( sal_uInt16 nLines ) const 1104cdf0e10cSrcweir { 1105cdf0e10cSrcweir return mpImplLB->GetEntryHeight() * nLines; 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir 1108cdf0e10cSrcweir // ----------------------------------------------------------------------- 1109cdf0e10cSrcweir 1110cdf0e10cSrcweir Size ComboBox::GetOptimalSize(WindowSizeType eType) const 1111cdf0e10cSrcweir { 1112cdf0e10cSrcweir switch (eType) { 1113cdf0e10cSrcweir case WINDOWSIZE_MINIMUM: 1114cdf0e10cSrcweir return CalcMinimumSize(); 1115cdf0e10cSrcweir default: 1116cdf0e10cSrcweir return Edit::GetOptimalSize( eType ); 1117cdf0e10cSrcweir } 1118cdf0e10cSrcweir } 1119cdf0e10cSrcweir 1120cdf0e10cSrcweir // ----------------------------------------------------------------------- 1121cdf0e10cSrcweir 1122cdf0e10cSrcweir Size ComboBox::CalcMinimumSize() const 1123cdf0e10cSrcweir { 1124cdf0e10cSrcweir Size aSz; 1125cdf0e10cSrcweir if ( !IsDropDownBox() ) 1126cdf0e10cSrcweir { 1127cdf0e10cSrcweir aSz = mpImplLB->CalcSize( mpImplLB->GetEntryList()->GetEntryCount() ); 1128cdf0e10cSrcweir aSz.Height() += mnDDHeight; 1129cdf0e10cSrcweir } 1130cdf0e10cSrcweir else 1131cdf0e10cSrcweir { 1132cdf0e10cSrcweir aSz.Height() = mpImplLB->CalcSize( 1 ).Height(); 1133cdf0e10cSrcweir aSz.Width() = mpImplLB->GetMaxEntryWidth(); 1134cdf0e10cSrcweir aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize(); 1135cdf0e10cSrcweir } 1136cdf0e10cSrcweir 1137cdf0e10cSrcweir aSz = CalcWindowSize( aSz ); 1138cdf0e10cSrcweir return aSz; 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir 1141cdf0e10cSrcweir // ----------------------------------------------------------------------- 1142cdf0e10cSrcweir 1143cdf0e10cSrcweir Size ComboBox::CalcAdjustedSize( const Size& rPrefSize ) const 1144cdf0e10cSrcweir { 1145cdf0e10cSrcweir Size aSz = rPrefSize; 1146cdf0e10cSrcweir sal_Int32 nLeft, nTop, nRight, nBottom; 1147cdf0e10cSrcweir ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom ); 1148cdf0e10cSrcweir aSz.Height() -= nTop+nBottom; 1149cdf0e10cSrcweir if ( !IsDropDownBox() ) 1150cdf0e10cSrcweir { 1151cdf0e10cSrcweir long nEntryHeight = CalcSize( 1, 1 ).Height(); 1152cdf0e10cSrcweir long nLines = aSz.Height() / nEntryHeight; 1153cdf0e10cSrcweir if ( nLines < 1 ) 1154cdf0e10cSrcweir nLines = 1; 1155cdf0e10cSrcweir aSz.Height() = nLines * nEntryHeight; 1156cdf0e10cSrcweir aSz.Height() += mnDDHeight; 1157cdf0e10cSrcweir } 1158cdf0e10cSrcweir else 1159cdf0e10cSrcweir { 1160cdf0e10cSrcweir aSz.Height() = mnDDHeight; 1161cdf0e10cSrcweir } 1162cdf0e10cSrcweir aSz.Height() += nTop+nBottom; 1163cdf0e10cSrcweir 1164cdf0e10cSrcweir aSz = CalcWindowSize( aSz ); 1165cdf0e10cSrcweir return aSz; 1166cdf0e10cSrcweir } 1167cdf0e10cSrcweir 1168cdf0e10cSrcweir // ----------------------------------------------------------------------- 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir Size ComboBox::CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const 1171cdf0e10cSrcweir { 1172cdf0e10cSrcweir // ggf. werden ScrollBars eingeblendet 1173cdf0e10cSrcweir Size aMinSz = CalcMinimumSize(); 1174cdf0e10cSrcweir Size aSz; 1175cdf0e10cSrcweir 1176cdf0e10cSrcweir // Hoehe 1177cdf0e10cSrcweir if ( nLines ) 1178cdf0e10cSrcweir { 1179cdf0e10cSrcweir if ( !IsDropDownBox() ) 1180cdf0e10cSrcweir aSz.Height() = mpImplLB->CalcSize( nLines ).Height() + mnDDHeight; 1181cdf0e10cSrcweir else 1182cdf0e10cSrcweir aSz.Height() = mnDDHeight; 1183cdf0e10cSrcweir } 1184cdf0e10cSrcweir else 1185cdf0e10cSrcweir aSz.Height() = aMinSz.Height(); 1186cdf0e10cSrcweir 1187cdf0e10cSrcweir // Breite 1188cdf0e10cSrcweir if ( nColumns ) 1189cdf0e10cSrcweir aSz.Width() = nColumns * GetTextWidth( UniString( 'X' ) ); 1190cdf0e10cSrcweir else 1191cdf0e10cSrcweir aSz.Width() = aMinSz.Width(); 1192cdf0e10cSrcweir 1193cdf0e10cSrcweir if ( IsDropDownBox() ) 1194cdf0e10cSrcweir aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize(); 1195cdf0e10cSrcweir 1196cdf0e10cSrcweir if ( !IsDropDownBox() ) 1197cdf0e10cSrcweir { 1198cdf0e10cSrcweir if ( aSz.Width() < aMinSz.Width() ) 1199cdf0e10cSrcweir aSz.Height() += GetSettings().GetStyleSettings().GetScrollBarSize(); 1200cdf0e10cSrcweir if ( aSz.Height() < aMinSz.Height() ) 1201cdf0e10cSrcweir aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize(); 1202cdf0e10cSrcweir } 1203cdf0e10cSrcweir 1204cdf0e10cSrcweir aSz = CalcWindowSize( aSz ); 1205cdf0e10cSrcweir return aSz; 1206cdf0e10cSrcweir } 1207cdf0e10cSrcweir 1208cdf0e10cSrcweir // ----------------------------------------------------------------------- 1209cdf0e10cSrcweir 1210cdf0e10cSrcweir void ComboBox::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const 1211cdf0e10cSrcweir { 1212cdf0e10cSrcweir long nCharWidth = GetTextWidth( UniString( 'x' ) ); 1213cdf0e10cSrcweir if ( !IsDropDownBox() ) 1214cdf0e10cSrcweir { 1215cdf0e10cSrcweir Size aOutSz = mpImplLB->GetMainWindow()->GetOutputSizePixel(); 1216cdf0e10cSrcweir rnCols = (sal_uInt16)(aOutSz.Width()/nCharWidth); 1217cdf0e10cSrcweir rnLines = (sal_uInt16)(aOutSz.Height()/mpImplLB->GetEntryHeight()); 1218cdf0e10cSrcweir } 1219cdf0e10cSrcweir else 1220cdf0e10cSrcweir { 1221cdf0e10cSrcweir Size aOutSz = mpSubEdit->GetOutputSizePixel(); 1222cdf0e10cSrcweir rnCols = (sal_uInt16)(aOutSz.Width()/nCharWidth); 1223cdf0e10cSrcweir rnLines = 1; 1224cdf0e10cSrcweir } 1225cdf0e10cSrcweir } 1226cdf0e10cSrcweir 1227cdf0e10cSrcweir // ----------------------------------------------------------------------- 1228cdf0e10cSrcweir 1229cdf0e10cSrcweir void ComboBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) 1230cdf0e10cSrcweir { 1231cdf0e10cSrcweir mpImplLB->GetMainWindow()->ImplInitSettings( sal_True, sal_True, sal_True ); 1232cdf0e10cSrcweir 1233cdf0e10cSrcweir Point aPos = pDev->LogicToPixel( rPos ); 1234cdf0e10cSrcweir Size aSize = pDev->LogicToPixel( rSize ); 1235cdf0e10cSrcweir Font aFont = mpImplLB->GetMainWindow()->GetDrawPixelFont( pDev ); 1236cdf0e10cSrcweir OutDevType eOutDevType = pDev->GetOutDevType(); 1237cdf0e10cSrcweir 1238cdf0e10cSrcweir pDev->Push(); 1239cdf0e10cSrcweir pDev->SetMapMode(); 1240cdf0e10cSrcweir pDev->SetFont( aFont ); 1241cdf0e10cSrcweir pDev->SetTextFillColor(); 1242cdf0e10cSrcweir 1243cdf0e10cSrcweir // Border/Background 1244cdf0e10cSrcweir pDev->SetLineColor(); 1245cdf0e10cSrcweir pDev->SetFillColor(); 1246cdf0e10cSrcweir sal_Bool bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER); 1247cdf0e10cSrcweir sal_Bool bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground(); 1248cdf0e10cSrcweir if ( bBorder || bBackground ) 1249cdf0e10cSrcweir { 1250cdf0e10cSrcweir Rectangle aRect( aPos, aSize ); 1251cdf0e10cSrcweir // aRect.Top() += nEditHeight; 1252cdf0e10cSrcweir if ( bBorder ) 1253cdf0e10cSrcweir { 1254cdf0e10cSrcweir ImplDrawFrame( pDev, aRect ); 1255cdf0e10cSrcweir } 1256cdf0e10cSrcweir if ( bBackground ) 1257cdf0e10cSrcweir { 1258cdf0e10cSrcweir pDev->SetFillColor( GetControlBackground() ); 1259cdf0e10cSrcweir pDev->DrawRect( aRect ); 1260cdf0e10cSrcweir } 1261cdf0e10cSrcweir } 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir // Inhalt 1264cdf0e10cSrcweir if ( !IsDropDownBox() ) 1265cdf0e10cSrcweir { 1266cdf0e10cSrcweir long nOnePixel = GetDrawPixel( pDev, 1 ); 1267cdf0e10cSrcweir long nTextHeight = pDev->GetTextHeight(); 1268cdf0e10cSrcweir long nEditHeight = nTextHeight + 6*nOnePixel; 1269cdf0e10cSrcweir sal_uInt16 nTextStyle = TEXT_DRAW_VCENTER; 1270cdf0e10cSrcweir 1271cdf0e10cSrcweir // First, draw the edit part 1272cdf0e10cSrcweir mpSubEdit->Draw( pDev, aPos, Size( aSize.Width(), nEditHeight ), nFlags ); 1273cdf0e10cSrcweir 1274cdf0e10cSrcweir // Second, draw the listbox 1275cdf0e10cSrcweir if ( GetStyle() & WB_CENTER ) 1276cdf0e10cSrcweir nTextStyle |= TEXT_DRAW_CENTER; 1277cdf0e10cSrcweir else if ( GetStyle() & WB_RIGHT ) 1278cdf0e10cSrcweir nTextStyle |= TEXT_DRAW_RIGHT; 1279cdf0e10cSrcweir else 1280cdf0e10cSrcweir nTextStyle |= TEXT_DRAW_LEFT; 1281cdf0e10cSrcweir 1282cdf0e10cSrcweir if ( ( nFlags & WINDOW_DRAW_MONO ) || ( eOutDevType == OUTDEV_PRINTER ) ) 1283cdf0e10cSrcweir { 1284cdf0e10cSrcweir pDev->SetTextColor( Color( COL_BLACK ) ); 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir else 1287cdf0e10cSrcweir { 1288cdf0e10cSrcweir if ( !(nFlags & WINDOW_DRAW_NODISABLE ) && !IsEnabled() ) 1289cdf0e10cSrcweir { 1290cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 1291cdf0e10cSrcweir pDev->SetTextColor( rStyleSettings.GetDisableColor() ); 1292cdf0e10cSrcweir } 1293cdf0e10cSrcweir else 1294cdf0e10cSrcweir { 1295cdf0e10cSrcweir pDev->SetTextColor( GetTextColor() ); 1296cdf0e10cSrcweir } 1297cdf0e10cSrcweir } 1298cdf0e10cSrcweir 1299cdf0e10cSrcweir Rectangle aClip( aPos, aSize ); 1300cdf0e10cSrcweir pDev->IntersectClipRegion( aClip ); 1301cdf0e10cSrcweir sal_uInt16 nLines = (sal_uInt16) ( (aSize.Height()-nEditHeight) / nTextHeight ); 1302cdf0e10cSrcweir if ( !nLines ) 1303cdf0e10cSrcweir nLines = 1; 1304cdf0e10cSrcweir sal_uInt16 nTEntry = IsReallyVisible() ? mpImplLB->GetTopEntry() : 0; 1305cdf0e10cSrcweir 1306cdf0e10cSrcweir Rectangle aTextRect( aPos, aSize ); 1307cdf0e10cSrcweir 1308cdf0e10cSrcweir aTextRect.Left() += 3*nOnePixel; 1309cdf0e10cSrcweir aTextRect.Right() -= 3*nOnePixel; 1310cdf0e10cSrcweir aTextRect.Top() += nEditHeight + nOnePixel; 1311cdf0e10cSrcweir aTextRect.Bottom() = aTextRect.Top() + nTextHeight; 1312cdf0e10cSrcweir 1313cdf0e10cSrcweir // the drawing starts here 1314cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < nLines; n++ ) 1315cdf0e10cSrcweir { 1316cdf0e10cSrcweir pDev->DrawText( aTextRect, mpImplLB->GetEntryList()->GetEntryText( n+nTEntry ), nTextStyle ); 1317cdf0e10cSrcweir aTextRect.Top() += nTextHeight; 1318cdf0e10cSrcweir aTextRect.Bottom() += nTextHeight; 1319cdf0e10cSrcweir } 1320cdf0e10cSrcweir } 1321cdf0e10cSrcweir 1322cdf0e10cSrcweir pDev->Pop(); 1323cdf0e10cSrcweir 1324cdf0e10cSrcweir // Call Edit::Draw after restoring the MapMode... 1325cdf0e10cSrcweir if ( IsDropDownBox() ) 1326cdf0e10cSrcweir { 1327cdf0e10cSrcweir mpSubEdit->Draw( pDev, rPos, rSize, nFlags ); 1328cdf0e10cSrcweir // DD-Button ? 1329cdf0e10cSrcweir } 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir } 1332cdf0e10cSrcweir 1333cdf0e10cSrcweir // ----------------------------------------------------------------------- 1334cdf0e10cSrcweir 1335cdf0e10cSrcweir IMPL_LINK( ComboBox, ImplUserDrawHdl, UserDrawEvent*, pEvent ) 1336cdf0e10cSrcweir { 1337cdf0e10cSrcweir UserDraw( *pEvent ); 1338cdf0e10cSrcweir return 1; 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir // ----------------------------------------------------------------------- 1342cdf0e10cSrcweir 1343cdf0e10cSrcweir void ComboBox::UserDraw( const UserDrawEvent& ) 1344cdf0e10cSrcweir { 1345cdf0e10cSrcweir } 1346cdf0e10cSrcweir 1347cdf0e10cSrcweir // ----------------------------------------------------------------------- 1348cdf0e10cSrcweir 1349cdf0e10cSrcweir void ComboBox::SetUserItemSize( const Size& rSz ) 1350cdf0e10cSrcweir { 1351cdf0e10cSrcweir mpImplLB->GetMainWindow()->SetUserItemSize( rSz ); 1352cdf0e10cSrcweir } 1353cdf0e10cSrcweir 1354cdf0e10cSrcweir // ----------------------------------------------------------------------- 1355cdf0e10cSrcweir 1356cdf0e10cSrcweir const Size& ComboBox::GetUserItemSize() const 1357cdf0e10cSrcweir { 1358cdf0e10cSrcweir return mpImplLB->GetMainWindow()->GetUserItemSize(); 1359cdf0e10cSrcweir } 1360cdf0e10cSrcweir 1361cdf0e10cSrcweir // ----------------------------------------------------------------------- 1362cdf0e10cSrcweir 1363cdf0e10cSrcweir void ComboBox::EnableUserDraw( sal_Bool bUserDraw ) 1364cdf0e10cSrcweir { 1365cdf0e10cSrcweir mpImplLB->GetMainWindow()->EnableUserDraw( bUserDraw ); 1366cdf0e10cSrcweir } 1367cdf0e10cSrcweir 1368cdf0e10cSrcweir // ----------------------------------------------------------------------- 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir sal_Bool ComboBox::IsUserDrawEnabled() const 1371cdf0e10cSrcweir { 1372cdf0e10cSrcweir return mpImplLB->GetMainWindow()->IsUserDrawEnabled(); 1373cdf0e10cSrcweir } 1374cdf0e10cSrcweir 1375cdf0e10cSrcweir // ----------------------------------------------------------------------- 1376cdf0e10cSrcweir 1377cdf0e10cSrcweir void ComboBox::DrawEntry( const UserDrawEvent& rEvt, sal_Bool bDrawImage, sal_Bool bDrawText, sal_Bool bDrawTextAtImagePos ) 1378cdf0e10cSrcweir { 1379cdf0e10cSrcweir DBG_ASSERT( rEvt.GetDevice() == mpImplLB->GetMainWindow(), "DrawEntry?!" ); 1380cdf0e10cSrcweir mpImplLB->GetMainWindow()->DrawEntry( rEvt.GetItemId(), bDrawImage, bDrawText, bDrawTextAtImagePos ); 1381cdf0e10cSrcweir } 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir // ----------------------------------------------------------------------- 1384cdf0e10cSrcweir 1385cdf0e10cSrcweir void ComboBox::SetSeparatorPos( sal_uInt16 n ) 1386cdf0e10cSrcweir { 1387cdf0e10cSrcweir mpImplLB->SetSeparatorPos( n ); 1388cdf0e10cSrcweir } 1389cdf0e10cSrcweir 1390cdf0e10cSrcweir // ----------------------------------------------------------------------- 1391cdf0e10cSrcweir 1392cdf0e10cSrcweir void ComboBox::SetSeparatorPos() 1393cdf0e10cSrcweir { 1394cdf0e10cSrcweir mpImplLB->SetSeparatorPos( LISTBOX_ENTRY_NOTFOUND ); 1395cdf0e10cSrcweir } 1396cdf0e10cSrcweir 1397cdf0e10cSrcweir // ----------------------------------------------------------------------- 1398cdf0e10cSrcweir 1399cdf0e10cSrcweir sal_uInt16 ComboBox::GetSeparatorPos() const 1400cdf0e10cSrcweir { 1401cdf0e10cSrcweir return mpImplLB->GetSeparatorPos(); 1402cdf0e10cSrcweir } 1403cdf0e10cSrcweir 1404cdf0e10cSrcweir // ----------------------------------------------------------------------- 1405cdf0e10cSrcweir 1406cdf0e10cSrcweir void ComboBox::SetMRUEntries( const XubString& rEntries, xub_Unicode cSep ) 1407cdf0e10cSrcweir { 1408cdf0e10cSrcweir mpImplLB->SetMRUEntries( rEntries, cSep ); 1409cdf0e10cSrcweir } 1410cdf0e10cSrcweir 1411cdf0e10cSrcweir // ----------------------------------------------------------------------- 1412cdf0e10cSrcweir 1413cdf0e10cSrcweir XubString ComboBox::GetMRUEntries( xub_Unicode cSep ) const 1414cdf0e10cSrcweir { 1415cdf0e10cSrcweir return mpImplLB->GetMRUEntries( cSep ); 1416cdf0e10cSrcweir } 1417cdf0e10cSrcweir 1418cdf0e10cSrcweir // ----------------------------------------------------------------------- 1419cdf0e10cSrcweir 1420cdf0e10cSrcweir void ComboBox::SetMaxMRUCount( sal_uInt16 n ) 1421cdf0e10cSrcweir { 1422cdf0e10cSrcweir mpImplLB->SetMaxMRUCount( n ); 1423cdf0e10cSrcweir } 1424cdf0e10cSrcweir 1425cdf0e10cSrcweir // ----------------------------------------------------------------------- 1426cdf0e10cSrcweir 1427cdf0e10cSrcweir sal_uInt16 ComboBox::GetMaxMRUCount() const 1428cdf0e10cSrcweir { 1429cdf0e10cSrcweir return mpImplLB->GetMaxMRUCount(); 1430cdf0e10cSrcweir } 1431cdf0e10cSrcweir 1432ad3a95a3SSteve Yin sal_uInt16 ComboBox::GetMRUCount() const 1433ad3a95a3SSteve Yin { 1434ad3a95a3SSteve Yin return mpImplLB->GetEntryList()->GetMRUCount(); 1435ad3a95a3SSteve Yin } 1436cdf0e10cSrcweir // ----------------------------------------------------------------------- 1437cdf0e10cSrcweir 1438cdf0e10cSrcweir sal_uInt16 ComboBox::GetDisplayLineCount() const 1439cdf0e10cSrcweir { 1440cdf0e10cSrcweir return mpImplLB->GetDisplayLineCount(); 1441cdf0e10cSrcweir } 1442cdf0e10cSrcweir 1443cdf0e10cSrcweir // ----------------------------------------------------------------------- 1444cdf0e10cSrcweir 1445cdf0e10cSrcweir void ComboBox::SetEntryData( sal_uInt16 nPos, void* pNewData ) 1446cdf0e10cSrcweir { 1447cdf0e10cSrcweir mpImplLB->SetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount(), pNewData ); 1448cdf0e10cSrcweir } 1449cdf0e10cSrcweir 1450cdf0e10cSrcweir // ----------------------------------------------------------------------- 1451cdf0e10cSrcweir 1452cdf0e10cSrcweir void* ComboBox::GetEntryData( sal_uInt16 nPos ) const 1453cdf0e10cSrcweir { 1454cdf0e10cSrcweir return mpImplLB->GetEntryList()->GetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount() ); 1455cdf0e10cSrcweir } 1456cdf0e10cSrcweir 1457cdf0e10cSrcweir // ----------------------------------------------------------------------- 1458cdf0e10cSrcweir 1459cdf0e10cSrcweir void ComboBox::SetTopEntry( sal_uInt16 nPos ) 1460cdf0e10cSrcweir { 1461cdf0e10cSrcweir mpImplLB->SetTopEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount() ); 1462cdf0e10cSrcweir } 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir // ----------------------------------------------------------------------- 1465cdf0e10cSrcweir 1466cdf0e10cSrcweir void ComboBox::ShowProminentEntry( sal_uInt16 nPos ) 1467cdf0e10cSrcweir { 1468cdf0e10cSrcweir mpImplLB->ShowProminentEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount() ); 1469cdf0e10cSrcweir } 1470cdf0e10cSrcweir 1471cdf0e10cSrcweir // ----------------------------------------------------------------------- 1472cdf0e10cSrcweir 1473cdf0e10cSrcweir sal_uInt16 ComboBox::GetTopEntry() const 1474cdf0e10cSrcweir { 1475cdf0e10cSrcweir sal_uInt16 nPos = GetEntryCount() ? mpImplLB->GetTopEntry() : LISTBOX_ENTRY_NOTFOUND; 1476cdf0e10cSrcweir if ( nPos < mpImplLB->GetEntryList()->GetMRUCount() ) 1477cdf0e10cSrcweir nPos = 0; 1478cdf0e10cSrcweir return nPos; 1479cdf0e10cSrcweir } 1480cdf0e10cSrcweir 1481cdf0e10cSrcweir // ----------------------------------------------------------------------- 1482cdf0e10cSrcweir 1483cdf0e10cSrcweir void ComboBox::SetProminentEntryType( ProminentEntry eType ) 1484cdf0e10cSrcweir { 1485cdf0e10cSrcweir mpImplLB->SetProminentEntryType( eType ); 1486cdf0e10cSrcweir } 1487cdf0e10cSrcweir 1488cdf0e10cSrcweir // ----------------------------------------------------------------------- 1489cdf0e10cSrcweir 1490cdf0e10cSrcweir ProminentEntry ComboBox::GetProminentEntryType() const 1491cdf0e10cSrcweir { 1492cdf0e10cSrcweir return mpImplLB->GetProminentEntryType(); 1493cdf0e10cSrcweir } 1494cdf0e10cSrcweir 1495cdf0e10cSrcweir // ----------------------------------------------------------------------- 1496cdf0e10cSrcweir 1497cdf0e10cSrcweir Rectangle ComboBox::GetDropDownPosSizePixel() const 1498cdf0e10cSrcweir { 1499cdf0e10cSrcweir return mpFloatWin ? mpFloatWin->GetWindowExtentsRelative( const_cast<ComboBox*>(this) ) : Rectangle(); 1500cdf0e10cSrcweir } 1501cdf0e10cSrcweir 1502cdf0e10cSrcweir // ----------------------------------------------------------------------- 1503cdf0e10cSrcweir 1504cdf0e10cSrcweir Rectangle ComboBox::GetListPosSizePixel() const 1505cdf0e10cSrcweir { 1506cdf0e10cSrcweir return mpFloatWin ? Rectangle() : mpImplLB->GetMainWindow()->GetWindowExtentsRelative( const_cast<ComboBox*>(this) ); 1507cdf0e10cSrcweir } 1508cdf0e10cSrcweir 1509cdf0e10cSrcweir // ----------------------------------------------------------------------- 1510cdf0e10cSrcweir 1511cdf0e10cSrcweir const Wallpaper& ComboBox::GetDisplayBackground() const 1512cdf0e10cSrcweir { 1513cdf0e10cSrcweir if( ! mpSubEdit->IsBackground() ) 1514cdf0e10cSrcweir return Control::GetDisplayBackground(); 1515cdf0e10cSrcweir 1516cdf0e10cSrcweir const Wallpaper& rBack = mpSubEdit->GetBackground(); 1517cdf0e10cSrcweir if( ! rBack.IsBitmap() && 1518cdf0e10cSrcweir ! rBack.IsGradient() && 1519cdf0e10cSrcweir rBack.GetColor().GetColor() == COL_TRANSPARENT 1520cdf0e10cSrcweir ) 1521cdf0e10cSrcweir return Control::GetDisplayBackground(); 1522cdf0e10cSrcweir return rBack; 1523cdf0e10cSrcweir } 1524cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1525cdf0e10cSrcweir sal_uInt16 ComboBox::GetSelectEntryCount() const 1526cdf0e10cSrcweir { 1527cdf0e10cSrcweir return mpImplLB->GetEntryList()->GetSelectEntryCount(); 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1530cdf0e10cSrcweir sal_uInt16 ComboBox::GetSelectEntryPos( sal_uInt16 nIndex ) const 1531cdf0e10cSrcweir { 1532cdf0e10cSrcweir sal_uInt16 nPos = mpImplLB->GetEntryList()->GetSelectEntryPos( nIndex ); 1533cdf0e10cSrcweir if ( nPos != LISTBOX_ENTRY_NOTFOUND ) 1534cdf0e10cSrcweir { 1535cdf0e10cSrcweir if ( nPos < mpImplLB->GetEntryList()->GetMRUCount() ) 1536cdf0e10cSrcweir nPos = mpImplLB->GetEntryList()->FindEntry( mpImplLB->GetEntryList()->GetEntryText( nPos ) ); 1537cdf0e10cSrcweir nPos = sal::static_int_cast<sal_uInt16>(nPos - mpImplLB->GetEntryList()->GetMRUCount()); 1538cdf0e10cSrcweir } 1539cdf0e10cSrcweir return nPos; 1540cdf0e10cSrcweir } 1541cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1542cdf0e10cSrcweir sal_Bool ComboBox::IsEntryPosSelected( sal_uInt16 nPos ) const 1543cdf0e10cSrcweir { 1544cdf0e10cSrcweir return mpImplLB->GetEntryList()->IsEntryPosSelected( nPos + mpImplLB->GetEntryList()->GetMRUCount() ); 1545cdf0e10cSrcweir } 1546cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1547cdf0e10cSrcweir void ComboBox::SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect) 1548cdf0e10cSrcweir { 1549cdf0e10cSrcweir if ( nPos < mpImplLB->GetEntryList()->GetEntryCount() ) 1550cdf0e10cSrcweir mpImplLB->SelectEntry( nPos + mpImplLB->GetEntryList()->GetMRUCount(), bSelect ); 1551cdf0e10cSrcweir } 1552cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1553cdf0e10cSrcweir void ComboBox::SetNoSelection() 1554cdf0e10cSrcweir { 1555cdf0e10cSrcweir mpImplLB->SetNoSelection(); 1556cdf0e10cSrcweir mpSubEdit->SetText( String() ); 1557cdf0e10cSrcweir } 1558cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1559cdf0e10cSrcweir Rectangle ComboBox::GetBoundingRectangle( sal_uInt16 nItem ) const 1560cdf0e10cSrcweir { 1561cdf0e10cSrcweir Rectangle aRect = mpImplLB->GetMainWindow()->GetBoundingRectangle( nItem ); 1562cdf0e10cSrcweir Rectangle aOffset = mpImplLB->GetMainWindow()->GetWindowExtentsRelative( (Window*)this ); 1563cdf0e10cSrcweir aRect.Move( aOffset.TopLeft().X(), aOffset.TopLeft().Y() ); 1564cdf0e10cSrcweir return aRect; 1565cdf0e10cSrcweir } 1566cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1567cdf0e10cSrcweir 1568cdf0e10cSrcweir void ComboBox::SetBorderStyle( sal_uInt16 nBorderStyle ) 1569cdf0e10cSrcweir { 1570cdf0e10cSrcweir Window::SetBorderStyle( nBorderStyle ); 1571cdf0e10cSrcweir if ( !IsDropDownBox() ) 1572cdf0e10cSrcweir { 1573cdf0e10cSrcweir mpSubEdit->SetBorderStyle( nBorderStyle ); 1574cdf0e10cSrcweir mpImplLB->SetBorderStyle( nBorderStyle ); 1575cdf0e10cSrcweir } 1576cdf0e10cSrcweir } 1577cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1578cdf0e10cSrcweir 1579cdf0e10cSrcweir long ComboBox::GetIndexForPoint( const Point& rPoint, sal_uInt16& rPos ) const 1580cdf0e10cSrcweir { 1581cdf0e10cSrcweir if( !HasLayoutData() ) 1582cdf0e10cSrcweir FillLayoutData(); 1583cdf0e10cSrcweir 1584cdf0e10cSrcweir // check whether rPoint fits at all 1585cdf0e10cSrcweir long nIndex = Control::GetIndexForPoint( rPoint ); 1586cdf0e10cSrcweir if( nIndex != -1 ) 1587cdf0e10cSrcweir { 1588cdf0e10cSrcweir // point must be either in main list window 1589cdf0e10cSrcweir // or in impl window (dropdown case) 1590cdf0e10cSrcweir ImplListBoxWindow* pMain = mpImplLB->GetMainWindow(); 1591cdf0e10cSrcweir 1592cdf0e10cSrcweir // convert coordinates to ImplListBoxWindow pixel coordinate space 1593cdf0e10cSrcweir Point aConvPoint = LogicToPixel( rPoint ); 1594cdf0e10cSrcweir aConvPoint = OutputToAbsoluteScreenPixel( aConvPoint ); 1595cdf0e10cSrcweir aConvPoint = pMain->AbsoluteScreenToOutputPixel( aConvPoint ); 1596cdf0e10cSrcweir aConvPoint = pMain->PixelToLogic( aConvPoint ); 1597cdf0e10cSrcweir 1598cdf0e10cSrcweir // try to find entry 1599cdf0e10cSrcweir sal_uInt16 nEntry = pMain->GetEntryPosForPoint( aConvPoint ); 1600cdf0e10cSrcweir if( nEntry == LISTBOX_ENTRY_NOTFOUND ) 1601cdf0e10cSrcweir nIndex = -1; 1602cdf0e10cSrcweir else 1603cdf0e10cSrcweir rPos = nEntry; 1604cdf0e10cSrcweir } 1605cdf0e10cSrcweir 1606cdf0e10cSrcweir // get line relative index 1607cdf0e10cSrcweir if( nIndex != -1 ) 1608cdf0e10cSrcweir nIndex = ToRelativeLineIndex( nIndex ); 1609cdf0e10cSrcweir 1610cdf0e10cSrcweir return nIndex; 1611cdf0e10cSrcweir } 1612