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