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