]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_tree.cpp
Fix a warning
[vlc] / modules / gui / skins2 / controls / ctrl_tree.cpp
1 /*****************************************************************************
2  * ctrl_tree.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <math.h>
25 #include "ctrl_tree.hpp"
26 #include "../src/os_factory.hpp"
27 #include "../src/os_graphics.hpp"
28 #include "../src/generic_bitmap.hpp"
29 #include "../src/generic_font.hpp"
30 #include "../src/scaled_bitmap.hpp"
31 #include "../utils/position.hpp"
32 #include "../utils/ustring.hpp"
33 #include "../events/evt_key.hpp"
34 #include "../events/evt_mouse.hpp"
35 #include "../events/evt_scroll.hpp"
36 #include "vlc_keys.h"
37 #ifdef sun
38 #   include "solaris_specific.h" // for lrint
39 #endif
40
41 #define SCROLL_STEP 0.05
42 #define LINE_INTERVAL 1  // Number of pixels inserted between 2 lines
43
44
45 CtrlTree::CtrlTree( intf_thread_t *pIntf,
46                     VarTree &rTree,
47                     const GenericFont &rFont,
48                     const GenericBitmap *pBgBitmap,
49                     const GenericBitmap *pItemBitmap,
50                     const GenericBitmap *pOpenBitmap,
51                     const GenericBitmap *pClosedBitmap,
52                     uint32_t fgColor,
53                     uint32_t playColor,
54                     uint32_t bgColor1,
55                     uint32_t bgColor2,
56                     uint32_t selColor,
57                     const UString &rHelp,
58                     VarBool *pVisible ):
59     CtrlGeneric( pIntf,rHelp, pVisible), m_rTree( rTree), m_rFont( rFont ),
60     m_pBgBitmap( pBgBitmap ), m_pItemBitmap( pItemBitmap ),
61     m_pOpenBitmap( pOpenBitmap ), m_pClosedBitmap( pClosedBitmap ),
62     m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ),
63     m_bgColor2( bgColor2 ), m_selColor( selColor ),
64     m_pLastSelected( NULL ), m_pImage( NULL ), m_dontMove( false )
65 {
66     // Observe the tree and position variables
67     m_rTree.addObserver( this );
68     m_rTree.getPositionVar().addObserver( this );
69
70     m_firstPos = m_rTree.begin();
71
72     makeImage();
73 }
74
75 CtrlTree::~CtrlTree()
76 {
77     m_rTree.getPositionVar().delObserver( this );
78     m_rTree.delObserver( this );
79     if( m_pImage )
80     {
81         delete m_pImage;
82     }
83 }
84
85 int CtrlTree::itemHeight()
86 {
87     int itemHeight = m_rFont.getSize();
88     if( m_pClosedBitmap )
89     {
90         itemHeight = __MAX( m_pClosedBitmap->getHeight(), itemHeight );
91     }
92     if( m_pOpenBitmap )
93     {
94         itemHeight = __MAX( m_pOpenBitmap->getHeight(), itemHeight );
95     }
96     if( m_pItemBitmap )
97     {
98         itemHeight = __MAX( m_pItemBitmap->getHeight(), itemHeight );
99     }
100     itemHeight += LINE_INTERVAL;
101     return itemHeight;
102 }
103
104 int CtrlTree::itemImageWidth()
105 {
106     int bitmapWidth = 5;
107     if( m_pClosedBitmap )
108     {
109         bitmapWidth = __MAX( m_pClosedBitmap->getWidth(), bitmapWidth );
110     }
111     if( m_pOpenBitmap )
112     {
113         bitmapWidth = __MAX( m_pOpenBitmap->getWidth(), bitmapWidth );
114     }
115     if( m_pItemBitmap )
116     {
117         bitmapWidth = __MAX( m_pItemBitmap->getWidth(), bitmapWidth );
118     }
119     return bitmapWidth + 2;
120 }
121
122 int CtrlTree::maxItems()
123 {
124     const Position *pPos = getPosition();
125     if( !pPos )
126     {
127         return -1;
128     }
129     return pPos->getHeight() / itemHeight();
130 }
131
132
133 void CtrlTree::onUpdate( Subject<VarTree, tree_update*> &rTree,
134                          tree_update *arg )
135 {
136     if( arg->i_type == 0 ) // Item update
137     {
138         if( arg->b_active_item )
139         {
140             autoScroll();
141             ///\todo We should make image if we are visible in the view
142             makeImage();
143         }
144     }
145     /// \todo handle delete in a more clever way
146     else if ( arg->i_type == 1 ) // Global change or deletion
147     {
148         m_firstPos = m_rTree.begin();
149         makeImage();
150     }
151     else if ( arg->i_type == 2 ) // Item-append
152     {
153         /// \todo Check if the item is really visible in the view
154         // (we only check if it in the document)
155         if( arg->b_visible == true )
156         {
157             makeImage();
158         }
159     }
160     else if( arg->i_type == 3 ) // item-del
161     {
162         /* Make sure firstPos and lastSelected are still valid */
163         while( m_firstPos->m_deleted && m_firstPos != m_rTree.root()->begin() )
164         {
165             m_firstPos = m_rTree.getPrevVisibleItem( m_firstPos );
166         }
167         if( m_firstPos->m_deleted ) m_firstPos = m_rTree.root()->begin();
168
169         if( arg->b_visible == true )
170         {
171             makeImage();
172         }
173     }
174     notifyLayout();
175 }
176
177 void CtrlTree::onUpdate( Subject<VarPercent, void*> &rPercent, void* arg)
178 {
179     // Determine what is the first item to display
180     VarTree::Iterator it = m_rTree.begin();
181
182     if( m_dontMove ) return;
183
184     int excessItems = m_rTree.visibleItems() - maxItems();
185
186     if( excessItems > 0)
187     {
188         VarPercent &rVarPos = m_rTree.getPositionVar();
189         // a simple (int)(...) causes rounding errors !
190 #ifdef _MSC_VER
191 #   define lrint (int)
192 #endif
193         it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1);
194     }
195     if( m_firstPos != it )
196     {
197         // Redraw the control if the position has changed
198         m_firstPos = it;
199         makeImage();
200         notifyLayout();
201     }
202 }
203
204 void CtrlTree::onResize()
205 {
206     // Determine what is the first item to display
207     VarTree::Iterator it = m_rTree.begin();
208
209     int excessItems = m_rTree.visibleItems() - maxItems();
210
211     if( excessItems > 0)
212     {
213         VarPercent &rVarPos = m_rTree.getPositionVar();
214         // a simple (int)(...) causes rounding errors !
215 #ifdef _MSC_VER
216 #   define lrint (int)
217 #endif
218         it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1);
219     }
220     // Redraw the control if the position has changed
221     m_firstPos = it;
222     makeImage();
223     notifyLayout();
224 }
225
226 void CtrlTree::onPositionChange()
227 {
228     makeImage();
229     notifyLayout();
230 }
231
232 void CtrlTree::handleEvent( EvtGeneric &rEvent )
233 {
234     bool bChangedPosition = false;
235     VarTree::Iterator toShow; bool needShow = false;
236     if( rEvent.getAsString().find( "key:down" ) != string::npos )
237     {
238         int key = ((EvtKey&)rEvent).getKey();
239         VarTree::Iterator it;
240         bool previousWasSelected = false;
241
242         /* Delete the selection */
243         if( key == KEY_DELETE )
244         {
245             m_rTree.delSelected();
246         }
247         else if( key == KEY_PAGEDOWN )
248         {
249             it = m_firstPos;
250             int i = (int)(maxItems()*1.5);
251             while( i >= 0 )
252             {
253                 VarTree::Iterator it_old = it;
254                 it = m_rTree.getNextVisibleItem( it );
255                 /* End is already visible, dont' scroll */
256                 if( it == m_rTree.end() )
257                 {
258                     it = it_old;
259                     break;
260                 }
261                 needShow = true;
262                 i--;
263             }
264             if( needShow )
265             {
266                 ensureVisible( it );
267                 makeImage();
268                 notifyLayout();
269                 return;
270             }
271         }
272         else if (key == KEY_PAGEUP )
273         {
274             it = m_firstPos;
275             int i = maxItems();
276             while( i >= maxItems()/2 )
277             {
278                 it = m_rTree.getPrevVisibleItem( it );
279                 /* End is already visible, dont' scroll */
280                 if( it == m_rTree.begin() )
281                 {
282                     break;
283                 }
284                 i--;
285             }
286             ensureVisible( it );
287             makeImage();
288             notifyLayout();
289             return;
290         }
291
292
293         for( it = m_rTree.begin(); it != m_rTree.end();
294              it = m_rTree.getNextVisibleItem( it ) )
295         {
296             VarTree::Iterator next = m_rTree.getNextVisibleItem( it );
297             if( key == KEY_UP )
298             {
299                 // Scroll up one item
300                 if( ( it->parent()
301                       && it != it->parent()->begin() )
302                     || &*it != m_pLastSelected )
303                 {
304                     bool nextWasSelected = ( &*next == m_pLastSelected );
305                     it->m_selected = nextWasSelected;
306                     if( nextWasSelected )
307                     {
308                         m_pLastSelected = &*it;
309                         needShow = true; toShow = it;
310                     }
311                 }
312             }
313             else if( key == KEY_DOWN )
314             {
315                 // Scroll down one item
316                 if( ( it->parent()
317                       && next != it->parent()->end() )
318                     || &*it != m_pLastSelected )
319                 {
320                     (*it).m_selected = previousWasSelected;
321                 }
322                 if( previousWasSelected )
323                 {
324                     m_pLastSelected = &*it;
325                     needShow = true; toShow = it;
326                     previousWasSelected = false;
327                 }
328                 else
329                 {
330                     previousWasSelected = ( &*it == m_pLastSelected );
331                 }
332             }
333             else if( key == KEY_RIGHT )
334             {
335                 // Go down one level (and expand node)
336                 if( &*it == m_pLastSelected )
337                 {
338                     if( it->m_expanded )
339                     {
340                         if( it->size() )
341                         {
342                             it->m_selected = false;
343                             it->begin()->m_selected = true;
344                             m_pLastSelected = &*(it->begin());
345                         }
346                         else
347                         {
348                             m_rTree.action( &*it );
349                         }
350                     }
351                     else
352                     {
353                         it->m_expanded = true;
354                         bChangedPosition = true;
355                     }
356                 }
357             }
358             else if( key == KEY_LEFT )
359             {
360                 // Go up one level (and close node)
361                 if( &*it == m_pLastSelected )
362                 {
363                     if( it->m_expanded && it->size() )
364                     {
365                         it->m_expanded = false;
366                         bChangedPosition = true;
367                     }
368                     else
369                     {
370                         if( it->parent() && it->parent() != &m_rTree)
371                         {
372                             it->m_selected = false;
373                             m_pLastSelected = it->parent();
374                             m_pLastSelected->m_selected = true;
375                         }
376                     }
377                 }
378             }
379             else if( key == KEY_ENTER || key == KEY_SPACE )
380             {
381                 // Go up one level (and close node)
382                 if( &*it == m_pLastSelected )
383                 {
384                     m_rTree.action( &*it );
385                 }
386             }
387         }
388         if( needShow )
389             ensureVisible( toShow );
390
391         // Redraw the control
392         makeImage();
393         notifyLayout();
394     }
395
396     else if( rEvent.getAsString().find( "mouse:left" ) != string::npos )
397     {
398         EvtMouse &rEvtMouse = (EvtMouse&)rEvent;
399         const Position *pos = getPosition();
400         int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight();
401         int xPos = rEvtMouse.getXPos() - pos->getLeft();
402         VarTree::Iterator it;
403
404         if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) !=
405             string::npos )
406         {
407             VarTree::Iterator itClicked = findItemAtPos( yPos );
408             // Flag to know if the current item must be selected
409             bool select = false;
410             for( it = m_rTree.begin(); it != m_rTree.end();
411                  it = m_rTree.getNextVisibleItem( it ) )
412             {
413                 bool nextSelect = select;
414                 if( it == itClicked || &*it == m_pLastSelected )
415                 {
416                     if( select )
417                     {
418                         nextSelect = false;
419                     }
420                     else
421                     {
422                         select = true;
423                         nextSelect = true;
424                     }
425                 }
426                 it->m_selected = (*it).m_selected || select;
427                 select = nextSelect;
428             }
429         }
430         else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) !=
431                  string::npos )
432         {
433             // Invert the selection of the item
434             it = findItemAtPos( yPos );
435             if( it != m_rTree.end() )
436             {
437                 it->m_selected = !it->m_selected;
438                 m_pLastSelected = &*it;
439             }
440         }
441         else if( rEvent.getAsString().find( "mouse:left:down:shift" ) !=
442                  string::npos )
443         {
444             VarTree::Iterator itClicked = findItemAtPos( yPos );
445             // Flag to know if the current item must be selected
446             bool select = false;
447             for( it = m_rTree.begin(); it != m_rTree.end();
448                  it = m_rTree.getNextVisibleItem( it ) )
449             {
450                 bool nextSelect = select;
451                 if( it == itClicked || &*it == m_pLastSelected )
452                 {
453                     if( select )
454                     {
455                         nextSelect = false;
456                     }
457                     else
458                     {
459                         select = true;
460                         nextSelect = true;
461                     }
462                 }
463                 it->m_selected = select;
464                 select = nextSelect;
465             }
466         }
467         else if( rEvent.getAsString().find( "mouse:left:down" ) !=
468                  string::npos )
469         {
470             it = findItemAtPos(yPos);
471             if( it != m_rTree.end() )
472             {
473                 if( it->size() && xPos > (it->depth() - 1) * itemImageWidth()
474                     && xPos < it->depth() * itemImageWidth() )
475                 {
476                     // Fold/unfold the item
477                     it->m_expanded = !it->m_expanded;
478                     bChangedPosition = true;
479                 }
480                 else
481                 {
482                     // Unselect any previously selected item
483                     VarTree::Iterator it2;
484                     for( it2 = m_rTree.begin(); it2 != m_rTree.end();
485                          it2 = m_rTree.getNextVisibleItem( it2 ) )
486                     {
487                         it2->m_selected = false;
488                     }
489                     // Select the new item
490                     if( it != m_rTree.end() )
491                     {
492                         it->m_selected = true;
493                         m_pLastSelected = &*it;
494                     }
495                 }
496             }
497         }
498
499         else if( rEvent.getAsString().find( "mouse:left:dblclick" ) !=
500                  string::npos )
501         {
502             it = findItemAtPos(yPos);
503             if( it != m_rTree.end() )
504             {
505                // Execute the action associated to this item
506                m_rTree.action( &*it );
507             }
508         }
509         // Redraw the control
510         makeImage();
511         notifyLayout();
512     }
513
514     else if( rEvent.getAsString().find( "scroll" ) != string::npos )
515     {
516         int direction = ((EvtScroll&)rEvent).getDirection();
517
518         double percentage = m_rTree.getPositionVar().get();
519         double step = 2.0 / (double)m_rTree.visibleItems();
520         if( direction == EvtScroll::kUp )
521         {
522             percentage += step;
523         }
524         else
525         {
526             percentage -= step;
527         }
528         m_rTree.getPositionVar().set( percentage );
529     }
530
531     /* We changed the nodes, let's fix teh position var */
532     if( bChangedPosition )
533     {
534         VarTree::Iterator it;
535         int i = 0;
536         int iFirst = 0;
537         for( it = m_rTree.begin(); it != m_rTree.end();
538              it = m_rTree.getNextVisibleItem( it ) )
539         {
540             i++;
541             if( it == m_firstPos )
542             {
543                 iFirst = i;
544                 break;
545             }
546         }
547         iFirst += maxItems();
548         if( iFirst >= m_rTree.visibleItems() ) iFirst = m_rTree.visibleItems();
549         float f_new = (float)iFirst / (float)m_rTree.visibleItems();
550         m_dontMove = true;
551         m_rTree.getPositionVar().set( 1.0 - f_new );
552         m_dontMove = false;
553     }
554 }
555
556 bool CtrlTree::mouseOver( int x, int y ) const
557 {
558     const Position *pPos = getPosition();
559     return ( pPos
560        ? x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight()
561        : false);
562 }
563
564 void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest )
565 {
566     if( m_pImage )
567     {
568         rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
569     }
570 }
571
572 bool CtrlTree::ensureVisible( VarTree::Iterator item )
573 {
574     // Find the item to focus
575     int focusItemIndex = 0;
576     VarTree::Iterator it;
577
578     m_rTree.ensureExpanded( item );
579
580     for( it = m_rTree.begin(); it != m_rTree.end();
581          it = m_rTree.getNextVisibleItem( it ) )
582     {
583         if( it->m_id == item->m_id ) break;
584         focusItemIndex++;
585     }
586    return ensureVisible( focusItemIndex );
587 }
588
589 bool CtrlTree::ensureVisible( int focusItemIndex )
590 {
591     // Find  m_firstPos
592     VarTree::Iterator it;
593     int firstPosIndex = 0;
594     for( it = m_rTree.begin(); it != m_rTree.end();
595          it = m_rTree.getNextVisibleItem( it ) )
596     {
597         if( it == m_firstPos ) break;
598         firstPosIndex++;
599     }
600
601     if( it == m_rTree.end() ) return false;
602
603
604     if( it != m_rTree.end()
605         && ( focusItemIndex < firstPosIndex
606            || focusItemIndex > firstPosIndex + maxItems() ) )
607     {
608         // Scroll to have the wanted stream visible
609         VarPercent &rVarPos = m_rTree.getPositionVar();
610         rVarPos.set( 1.0 - (double)focusItemIndex /
611                            (double)m_rTree.visibleItems() );
612         return true;
613     }
614     return false;
615 }
616
617 void CtrlTree::autoScroll()
618 {
619     // Find the current playing stream
620     int playIndex = 0;
621     VarTree::Iterator it;
622
623     for( it = m_rTree.begin(); it != m_rTree.end();
624          it = m_rTree.getNextItem( it ) )
625     {
626         if( it->m_playing )
627         {
628            m_rTree.ensureExpanded( it );
629            break;
630         }
631     }
632     for( it = m_rTree.begin(); it != m_rTree.end();
633          it = m_rTree.getNextVisibleItem( it ) )
634     {
635         if( it->m_playing )
636            break;
637         playIndex++;
638     }
639
640     if( it == m_rTree.end() ) return;
641
642
643     ensureVisible( playIndex );
644 }
645
646
647 void CtrlTree::makeImage()
648 {
649     stats_TimerStart( getIntf(), "[Skins] Playlist image",
650                       STATS_TIMER_SKINS_PLAYTREE_IMAGE );
651     if( m_pImage )
652     {
653         delete m_pImage;
654     }
655
656     // Get the size of the control
657     const Position *pPos = getPosition();
658     if( !pPos )
659     {
660         stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );
661         return;
662     }
663     int width = pPos->getWidth();
664     int height = pPos->getHeight();
665
666     int i_itemHeight = itemHeight();
667
668     // Create an image
669     OSFactory *pOsFactory = OSFactory::instance( getIntf() );
670     m_pImage = pOsFactory->createOSGraphics( width, height );
671
672     VarTree::Iterator it = m_firstPos;
673
674     if( m_pBgBitmap )
675     {
676         // Draw the background bitmap
677         ScaledBitmap bmp( getIntf(), *m_pBgBitmap, width, height );
678         m_pImage->drawBitmap( bmp, 0, 0 );
679
680         for( int yPos = 0; yPos < height; yPos += i_itemHeight )
681         {
682             if( it != m_rTree.end() )
683             {
684                 if( (*it).m_selected )
685                 {
686                     int rectHeight = __MIN( i_itemHeight, height - yPos );
687                     m_pImage->fillRect( 0, yPos, width, rectHeight,
688                                         m_selColor );
689                 }
690                 do
691                 {
692                     it = m_rTree.getNextVisibleItem( it );
693                 } while( it->m_deleted );
694             }
695         }
696     }
697     else
698     {
699         // FIXME (TRYME)
700         // Fill background with background color
701         uint32_t bgColor = m_bgColor1;
702         m_pImage->fillRect( 0, 0, width, height, bgColor );
703         for( int yPos = 0; yPos < height; yPos += i_itemHeight )
704         {
705             int rectHeight = __MIN( i_itemHeight, height - yPos );
706             if( it != m_rTree.end() )
707             {
708                 uint32_t color = ( it->m_selected ? m_selColor : bgColor );
709                 m_pImage->fillRect( 0, yPos, width, rectHeight, color );
710                 do
711                 {
712                     it = m_rTree.getNextVisibleItem( it );
713                 } while( it->m_deleted );
714             }
715             else
716             {
717                 m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor );
718             }
719             bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 );
720         }
721     }
722
723     int bitmapWidth = itemImageWidth();
724
725     int yPos = 0;
726     it = m_firstPos;
727     while( it != m_rTree.end() && yPos < height )
728     {
729         const GenericBitmap *m_pCurBitmap;
730         UString *pStr = (UString*)(it->m_cString.get());
731         uint32_t color = ( it->m_playing ? m_playColor : m_fgColor );
732
733         // Draw the text
734         if( pStr != NULL )
735         {
736             int depth = it->depth();
737             GenericBitmap *pText = m_rFont.drawString( *pStr, color, width - bitmapWidth * depth );
738             if( !pText )
739             {
740                 stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );
741                 return;
742             }
743             if( it->size() )
744                 m_pCurBitmap = it->m_expanded ? m_pOpenBitmap : m_pClosedBitmap;
745             else
746                 m_pCurBitmap = m_pItemBitmap;
747
748             if( m_pCurBitmap )
749             {
750                 // Make sure we are centered on the line
751                 int yPos2 = yPos+(i_itemHeight-m_pCurBitmap->getHeight()+1)/2;
752                 if( yPos2 >= height )
753                 {
754                     delete pText;
755                     break;
756                 }
757                 m_pImage->drawBitmap( *m_pCurBitmap, 0, 0,
758                                       bitmapWidth * (depth - 1 ), yPos2,
759                                       m_pCurBitmap->getWidth(),
760                                       __MIN( m_pCurBitmap->getHeight(),
761                                              height -  yPos2), true );
762             }
763             yPos += i_itemHeight - pText->getHeight();
764             int ySrc = 0;
765             if( yPos < 0 )
766             {
767                 ySrc = - yPos;
768                 yPos = 0;
769             }
770             int lineHeight = __MIN( pText->getHeight() - ySrc, height - yPos );
771             m_pImage->drawBitmap( *pText, 0, ySrc, bitmapWidth * depth, yPos,
772                                   pText->getWidth(),
773                                   lineHeight, true );
774             yPos += (pText->getHeight() - ySrc );
775             delete pText;
776         }
777         do {
778         it = m_rTree.getNextVisibleItem( it );
779         } while( it->m_deleted );
780     }
781     stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );
782 }
783
784 VarTree::Iterator CtrlTree::findItemAtPos( int pos )
785 {
786     // The first item is m_firstPos.
787     // We decrement pos as we try the other items, until pos == 0.
788     VarTree::Iterator it;
789     for( it = m_firstPos; it != m_rTree.end() && pos != 0;
790          it = m_rTree.getNextVisibleItem( it ) )
791     {
792         pos--;
793     }
794
795     return it;
796 }