home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qlistbox.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  14KB  |  430 lines

  1. /**********************************************************************
  2. ** $Id:  qt/qlistbox.h   3.0.0   edited Oct 1 13:46 $
  3. **
  4. ** Definition of QListBox widget class
  5. **
  6. ** Created : 941121
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the widgets module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QLISTBOX_H
  39. #define QLISTBOX_H
  40.  
  41. #ifndef QT_H
  42. #include "qscrollview.h"
  43. #include "qpixmap.h"
  44. #endif // QT_H
  45.  
  46. #ifndef QT_NO_LISTBOX
  47.  
  48.  
  49. class QListBoxPrivate;
  50. class QListBoxItem;
  51. class QString;
  52. class QStrList;
  53. class QStringList;
  54.  
  55.  
  56. class Q_EXPORT QListBox : public QScrollView
  57. {
  58.     friend class QListBoxItem;
  59.     friend class QListBoxPrivate;
  60.  
  61.     Q_OBJECT
  62.     Q_ENUMS( SelectionMode LayoutMode )
  63.     Q_PROPERTY( uint count READ count )
  64.     Q_PROPERTY( int numItemsVisible READ numItemsVisible )
  65.     Q_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem DESIGNABLE false )
  66.     Q_PROPERTY( QString currentText READ currentText )
  67.     Q_PROPERTY( int topItem READ topItem WRITE setTopItem DESIGNABLE false )
  68.     Q_PROPERTY( SelectionMode selectionMode READ selectionMode WRITE setSelectionMode )
  69.     Q_PROPERTY( bool multiSelection READ isMultiSelection WRITE setMultiSelection DESIGNABLE false )
  70.     Q_PROPERTY( LayoutMode columnMode READ columnMode WRITE setColumnMode )
  71.     Q_PROPERTY( LayoutMode rowMode READ rowMode WRITE setRowMode )
  72.     Q_PROPERTY( int numColumns READ numColumns )
  73.     Q_PROPERTY( int numRows READ numRows )
  74.     Q_PROPERTY( bool variableWidth READ variableWidth WRITE setVariableWidth )
  75.     Q_PROPERTY( bool variableHeight READ variableHeight WRITE setVariableHeight )
  76.  
  77. public:
  78.     QListBox( QWidget* parent=0, const char* name=0, WFlags f=0  );
  79.     ~QListBox();
  80.  
  81.     virtual void setFont( const QFont & );
  82.  
  83.     uint count() const;
  84.  
  85.     void insertStringList( const QStringList&, int index=-1 );
  86.     void insertStrList( const QStrList *, int index=-1 );
  87.     void insertStrList( const QStrList &, int index=-1 );
  88.     void insertStrList( const char **,
  89.             int numStrings=-1, int index=-1 );
  90.  
  91.     void insertItem( const QListBoxItem *, int index=-1 );
  92.     void insertItem( const QListBoxItem *, const QListBoxItem *after );
  93.     void insertItem( const QString &text, int index=-1 );
  94.     void insertItem( const QPixmap &pixmap, int index=-1 );
  95.     void insertItem( const QPixmap &pixmap, const QString &text, int index=-1 );
  96.  
  97.     void removeItem( int index );
  98.  
  99.     QString text( int index )    const;
  100.     const QPixmap *pixmap( int index )    const;
  101.  
  102.     void changeItem( const QListBoxItem *, int index );
  103.     void changeItem( const QString &text, int index );
  104.     void changeItem( const QPixmap &pixmap, int index );
  105.     void changeItem( const QPixmap &pixmap, const QString &text, int index );
  106.  
  107.     void takeItem( const QListBoxItem * );
  108.  
  109.     int numItemsVisible() const;
  110.  
  111.     int currentItem() const;
  112.     QString currentText() const { return text(currentItem()); }
  113.     virtual void setCurrentItem( int index );
  114.     virtual void setCurrentItem( QListBoxItem * );
  115.     void centerCurrentItem() { ensureCurrentVisible(); }
  116.     int topItem() const;
  117.     virtual void setTopItem( int index );
  118.     virtual void setBottomItem( int index );
  119.  
  120.     long maxItemWidth() const;
  121.  
  122.     enum SelectionMode { Single, Multi, Extended, NoSelection };
  123.     virtual void setSelectionMode( SelectionMode );
  124.     SelectionMode selectionMode() const;
  125.  
  126.     void setMultiSelection( bool multi );
  127.     bool isMultiSelection() const;
  128.  
  129.     virtual void setSelected( QListBoxItem *, bool );
  130.     void setSelected( int, bool );
  131.     bool isSelected( int ) const;
  132.     bool isSelected( const QListBoxItem * ) const;
  133.  
  134.     QSize sizeHint() const;
  135.     QSize    minimumSizeHint() const;
  136.  
  137.     QListBoxItem *item( int index ) const;
  138.     int index( const QListBoxItem * ) const;
  139.     QListBoxItem *findItem( const QString &text, ComparisonFlags compare = BeginsWith ) const;
  140.  
  141.     void triggerUpdate( bool doLayout );
  142.  
  143.     bool itemVisible( int index );
  144.     bool itemVisible( const QListBoxItem * );
  145.  
  146.     enum LayoutMode { FixedNumber,
  147.               FitToWidth, FitToHeight = FitToWidth,
  148.               Variable };
  149.     virtual void setColumnMode( LayoutMode );
  150.     virtual void setColumnMode( int );
  151.     virtual void setRowMode( LayoutMode );
  152.     virtual void setRowMode( int );
  153.  
  154.     LayoutMode columnMode() const;
  155.     LayoutMode rowMode() const;
  156.  
  157.     int numColumns() const;
  158.     int numRows() const;
  159.  
  160.     bool variableWidth() const;
  161.     virtual void setVariableWidth( bool );
  162.  
  163.     bool variableHeight() const;
  164.     virtual void setVariableHeight( bool );
  165.  
  166.     void viewportPaintEvent( QPaintEvent * );
  167.  
  168. #ifndef QT_NO_COMPAT
  169.     bool dragSelect() const { return TRUE; }
  170.     void setDragSelect( bool ) {}
  171.     bool autoScroll() const { return TRUE; }
  172.     void setAutoScroll( bool ) {}
  173.     bool autoScrollBar() const { return vScrollBarMode() == Auto; }
  174.     void setAutoScrollBar( bool enable ) { setVScrollBarMode( enable ? Auto : AlwaysOff ); }
  175.     bool scrollBar() const { return vScrollBarMode() != AlwaysOff; }
  176.     void setScrollBar( bool enable ) { setVScrollBarMode( enable ? AlwaysOn : AlwaysOff ); }
  177.     bool autoBottomScrollBar() const { return hScrollBarMode() == Auto; }
  178.     void setAutoBottomScrollBar( bool enable ) { setHScrollBarMode( enable ? Auto : AlwaysOff ); }
  179.     bool bottomScrollBar() const { return hScrollBarMode() != AlwaysOff; }
  180.     void setBottomScrollBar( bool enable ) { setHScrollBarMode( enable ? AlwaysOn : AlwaysOff ); }
  181.     bool smoothScrolling() const { return FALSE; }
  182.     void setSmoothScrolling( bool ) {}
  183.     bool autoUpdate() const { return TRUE; }
  184.     void setAutoUpdate( bool ) {}
  185.     void setFixedVisibleLines( int lines ) { setRowMode( lines ); }
  186.     int inSort( const QListBoxItem * );
  187.     int inSort( const QString& text );
  188.     int cellHeight( int i ) const { return itemHeight(i); }
  189.     int cellHeight() const { return itemHeight(); }
  190.     int cellWidth() const { return maxItemWidth(); }
  191.     int cellWidth(int i) const { Q_ASSERT(i==0); return maxItemWidth(); }
  192.     int    numCols() const { return numColumns(); }
  193. #endif
  194.  
  195.     int itemHeight( int index = 0 ) const;
  196.     QListBoxItem * itemAt( const QPoint & ) const;
  197.  
  198.     QRect itemRect( QListBoxItem *item ) const;
  199.  
  200.     QListBoxItem *firstItem() const;
  201.  
  202.     void sort( bool ascending = TRUE );
  203.  
  204. public slots:
  205.     void clear();
  206.     virtual void ensureCurrentVisible();
  207.     virtual void clearSelection();
  208.     virtual void selectAll( bool select );
  209.     virtual void invertSelection();
  210.  
  211. signals:
  212.     void highlighted( int index );
  213.     void selected( int index );
  214.     void highlighted( const QString &);
  215.     void selected( const QString &);
  216.     void highlighted( QListBoxItem * );
  217.     void selected( QListBoxItem * );
  218.  
  219.     void selectionChanged();
  220.     void selectionChanged( QListBoxItem * );
  221.     void currentChanged( QListBoxItem * );
  222.     void clicked( QListBoxItem * );
  223.     void clicked( QListBoxItem *, const QPoint & );
  224.     void pressed( QListBoxItem * );
  225.     void pressed( QListBoxItem *, const QPoint & );
  226.  
  227.     void doubleClicked( QListBoxItem * );
  228.     void returnPressed( QListBoxItem * );
  229.     void rightButtonClicked( QListBoxItem *, const QPoint & );
  230.     void rightButtonPressed( QListBoxItem *, const QPoint & );
  231.     void mouseButtonPressed( int, QListBoxItem*, const QPoint& );
  232.     void mouseButtonClicked( int, QListBoxItem*, const QPoint& );
  233.  
  234.     void contextMenuRequested( QListBoxItem *, const QPoint & );
  235.  
  236.     void onItem( QListBoxItem *item );
  237.     void onViewport();
  238.  
  239. protected:
  240.     void mousePressEvent( QMouseEvent * );
  241.     void mouseReleaseEvent( QMouseEvent * );
  242.     void mouseDoubleClickEvent( QMouseEvent * );
  243.     void mouseMoveEvent( QMouseEvent * );
  244.     void contentsContextMenuEvent( QContextMenuEvent * );
  245.  
  246.     void keyPressEvent( QKeyEvent *e );
  247.     void focusInEvent( QFocusEvent *e );
  248.     void focusOutEvent( QFocusEvent *e );
  249.     void resizeEvent( QResizeEvent * );
  250.     void showEvent( QShowEvent * );
  251.  
  252.     bool eventFilter( QObject *o, QEvent *e );
  253.  
  254.     void updateItem( int index );
  255.     void updateItem( QListBoxItem * );
  256.  
  257. #ifndef QT_NO_COMPAT
  258.     void updateCellWidth() { }
  259.     int totalWidth() const { return contentsWidth(); }
  260.     int totalHeight() const { return contentsHeight(); }
  261. #endif
  262.  
  263.     virtual void paintCell( QPainter *, int row, int col );
  264.  
  265.     void toggleCurrentItem();
  266.     bool isRubberSelecting() const;
  267.  
  268.     void doLayout() const;
  269.  
  270.     void windowActivationChange( bool );
  271.  
  272. #ifndef QT_NO_COMPAT
  273.     bool itemYPos( int index, int *yPos ) const;
  274.     int findItem( int yPos ) const { return index(itemAt(QPoint(0,yPos)) ); }
  275. #endif
  276.  
  277. protected slots:
  278.     void clearInputString();
  279.  
  280. private slots:
  281.     void refreshSlot();
  282.     void doAutoScroll();
  283.     void adjustItems();
  284.  
  285. private:
  286.     void mousePressEventEx( QMouseEvent * );
  287.     void tryGeometry( int, int ) const;
  288.     int currentRow() const;
  289.     int currentColumn() const;
  290.     void updateSelection();
  291.     void drawRubber();
  292.     void doRubberSelection( const QRect &old, const QRect &rubber );
  293.     void handleItemChange( QListBoxItem *old, bool shift, bool control );
  294.     void selectRange( QListBoxItem *from, QListBoxItem *to, bool invert, bool includeFirst, bool clearSel = FALSE );
  295.  
  296.     void emitChangedSignal( bool );
  297.  
  298.     int columnAt( int ) const;
  299.     int rowAt( int ) const;
  300.  
  301.     QListBoxPrivate * d;
  302.  
  303.     static QListBox * changedListBox;
  304.  
  305. private:    // Disabled copy constructor and operator=
  306. #if defined(Q_DISABLE_COPY)
  307.     QListBox( const QListBox & );
  308.     QListBox &operator=( const QListBox & );
  309. #endif
  310. };
  311.  
  312.  
  313. class Q_EXPORT QListBoxItem
  314. {
  315. public:
  316.     QListBoxItem( QListBox* listbox = 0 );
  317.     QListBoxItem( QListBox* listbox, QListBoxItem *after );
  318.     virtual ~QListBoxItem();
  319.  
  320.     virtual QString text() const;
  321.     virtual const QPixmap *pixmap() const;
  322.  
  323.     virtual int     height( const QListBox * ) const;
  324.     virtual int     width( const QListBox * )  const;
  325.  
  326.     bool isSelected() const { return s; }
  327.     bool isCurrent() const;
  328.  
  329. #ifndef QT_NO_COMPAT
  330.     bool selected() const { return isSelected(); }
  331.     bool current() const { return isCurrent(); }
  332. #endif
  333.  
  334.     QListBox *listBox() const;
  335.  
  336.     void setSelectable( bool b );
  337.     bool isSelectable() const;
  338.  
  339.     QListBoxItem *next() const;
  340.     QListBoxItem *prev() const;
  341.  
  342.     virtual int rtti() const;
  343.     static int RTTI;
  344.  
  345. protected:
  346.     virtual void paint( QPainter * ) = 0;
  347.     virtual void setText( const QString &text ) { txt = text; }
  348.     void setCustomHighlighting( bool );
  349.  
  350. private:
  351.     QString txt;
  352.     uint s:1;
  353.     uint dirty:1;
  354.     uint custom_highlight : 1;
  355.     int x, y;
  356.     QListBoxItem * p, * n;
  357.     QListBox* lbox;
  358.     friend class QListBox;
  359.     friend class QListBoxPrivate;
  360.     friend class QComboBox;
  361.  
  362. private:    // Disabled copy constructor and operator=
  363. #if defined(Q_DISABLE_COPY)
  364.     QListBoxItem( const QListBoxItem & );
  365.     QListBoxItem &operator=( const QListBoxItem & );
  366. #endif
  367. };
  368.  
  369.  
  370. class Q_EXPORT QListBoxText : public QListBoxItem
  371. {
  372. public:
  373.     QListBoxText( QListBox* listbox, const QString & text=QString::null );
  374.     QListBoxText( const QString & text=QString::null );
  375.     QListBoxText( QListBox* listbox, const QString & text, QListBoxItem *after );
  376.    ~QListBoxText();
  377.  
  378.     int     height( const QListBox * ) const;
  379.     int     width( const QListBox * )  const;
  380.  
  381.     int rtti() const;
  382.     static int RTTI;
  383.  
  384. protected:
  385.     void  paint( QPainter * );
  386.  
  387. private:    // Disabled copy constructor and operator=
  388. #if defined(Q_DISABLE_COPY)
  389.     QListBoxText( const QListBoxText & );
  390.     QListBoxText &operator=( const QListBoxText & );
  391. #endif
  392. };
  393.  
  394.  
  395. class Q_EXPORT QListBoxPixmap : public QListBoxItem
  396. {
  397. public:
  398.     QListBoxPixmap( QListBox* listbox, const QPixmap & );
  399.     QListBoxPixmap( const QPixmap & );
  400.     QListBoxPixmap( QListBox* listbox, const QPixmap & pix, QListBoxItem *after );
  401.     QListBoxPixmap( QListBox* listbox, const QPixmap &, const QString& );
  402.     QListBoxPixmap( const QPixmap &, const QString& );
  403.     QListBoxPixmap( QListBox* listbox, const QPixmap & pix, const QString&, QListBoxItem *after );
  404.    ~QListBoxPixmap();
  405.  
  406.     const QPixmap *pixmap() const { return ± }
  407.  
  408.     int     height( const QListBox * ) const;
  409.     int     width( const QListBox * )  const;
  410.  
  411.     int rtti() const;
  412.     static int RTTI;
  413.  
  414. protected:
  415.     void paint( QPainter * );
  416.  
  417. private:
  418.     QPixmap pm;
  419. private:    // Disabled copy constructor and operator=
  420. #if defined(Q_DISABLE_COPY)
  421.     QListBoxPixmap( const QListBoxPixmap & );
  422.     QListBoxPixmap &operator=( const QListBoxPixmap & );
  423. #endif
  424. };
  425.  
  426.  
  427. #endif // QT_NO_LISTBOX
  428.  
  429. #endif // QLISTBOX_H
  430.