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

  1. /****************************************************************************
  2. ** $Id:  qt/qstyle.h   3.0.0   edited Oct 8 02:30 $
  3. **
  4. ** Definition of QStyle class
  5. **
  6. ** Created : 980616
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the kernel 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. #ifndef QSTYLE_H
  38. #define QSTYLE_H
  39.  
  40. #ifndef QT_H
  41. #include "qobject.h"
  42. #endif // QT_H
  43.  
  44.  
  45. #ifndef QT_NO_STYLE
  46.  
  47. class QPopupMenu;
  48. class QStylePrivate;
  49. class QMenuItem;
  50. class QTab;
  51. class QListViewItem;
  52.  
  53. class QStyleOption {
  54. public:
  55.     enum StyleOptionDefault { Default };
  56.  
  57.     QStyleOption(StyleOptionDefault=Default) : def(TRUE) {}
  58.  
  59.     // Note: we don't use default arguments since that is unnecessary
  60.     // initialization.
  61.     QStyleOption(int in1, int in2) :
  62.     def(FALSE), i1(in1), i2(in2) {}
  63.     QStyleOption(int in1, int in2, int in3, int in4) :
  64.     def(FALSE), i1(in1), i2(in2), i3(in3), i4(in4) {}
  65.     QStyleOption(QMenuItem* m) : def(FALSE), mi(m) {}
  66.     QStyleOption(QMenuItem* m, int in1) : def(FALSE), mi(m), i1(in1) {}
  67.     QStyleOption(QMenuItem* m, int in1, int in2) : def(FALSE), mi(m), i1(in1), i2(in2) {}
  68.     QStyleOption(const QColor& c) : def(FALSE), cl(&c) {}
  69.     QStyleOption(QTab* t) : def(FALSE), tb(t) {}
  70.     QStyleOption(QListViewItem* i) : def(FALSE), li(i) {}
  71.     QStyleOption(Qt::ArrowType a) : def(FALSE), i1((int)a) {}
  72.  
  73.     bool isDefault() const { return def; }
  74.  
  75.     int lineWidth() const { return i1; }
  76.     int midLineWidth() const { return i2; }
  77.     int frameShape() const { return i3; }
  78.     int frameShadow() const { return i4; }
  79.  
  80.     QMenuItem* menuItem() const { return mi; }
  81.     int maxIconWidth() const { return i1; }
  82.     int tabWidth() const { return i2; }
  83.  
  84.     const QColor& color() const { return *cl; }
  85.  
  86.     QTab* tab() const { return tb; }
  87.  
  88.     QListViewItem* listViewItem() const { return li; }
  89.  
  90.     Qt::ArrowType arrowType() const { return (Qt::ArrowType)i1; }
  91.  
  92. private:
  93.     // NOTE: none of these components have constructors.
  94.     bool def;
  95.     bool b1,b2,b3; // reserved
  96.     QMenuItem* mi;
  97.     QTab* tb;
  98.     QListViewItem* li;
  99.     const QColor* cl;
  100.     int i1, i2, i3, i4;
  101.     int i5, i6; // reserved
  102.     void *p1, *p2, *p3, *p4, *p5; // reserved
  103.     // (padded to 64 bytes on some architectures)
  104. };
  105.  
  106. class QStyleHintReturn; // not defined yet
  107.  
  108. class Q_EXPORT QStyle: public QObject
  109. {
  110.     Q_OBJECT
  111.  
  112. public:
  113.     QStyle();
  114.     virtual ~QStyle();
  115.  
  116.     // New QStyle API - most of these should probably be pure virtual
  117.  
  118.     virtual void polish( QWidget * );
  119.     virtual void unPolish( QWidget * );
  120.  
  121.     virtual void polish( QApplication * );
  122.     virtual void unPolish( QApplication * );
  123.  
  124.     virtual void polish( QPalette & );
  125.  
  126.     virtual void polishPopupMenu( QPopupMenu* ) = 0;
  127.  
  128.     virtual QRect itemRect( QPainter *p, const QRect &r,
  129.                 int flags, bool enabled,
  130.                 const QPixmap *pixmap,
  131.                 const QString &text, int len = -1 ) const;
  132.  
  133.     virtual void drawItem( QPainter *p, const QRect &r,
  134.                int flags, const QColorGroup &g, bool enabled,
  135.                const QPixmap *pixmap, const QString &text,
  136.                int len = -1, const QColor *penColor = 0 ) const;
  137.  
  138.  
  139.     enum PrimitiveElement {
  140.     PE_ButtonCommand,
  141.     PE_ButtonDefault,
  142.     PE_ButtonBevel,
  143.     PE_ButtonTool,
  144.     PE_ButtonDropDown,
  145.  
  146.     PE_FocusRect,
  147.  
  148.     PE_ArrowUp,
  149.     PE_ArrowDown,
  150.     PE_ArrowRight,
  151.     PE_ArrowLeft,
  152.  
  153.     PE_SpinWidgetUp,
  154.     PE_SpinWidgetDown,
  155.     PE_SpinWidgetPlus,
  156.     PE_SpinWidgetMinus,
  157.  
  158.     PE_Indicator,
  159.     PE_IndicatorMask,
  160.     PE_ExclusiveIndicator,
  161.     PE_ExclusiveIndicatorMask,
  162.  
  163.     PE_DockWindowHandle,
  164.     PE_DockWindowSeparator,
  165.     PE_DockWindowResizeHandle,
  166.  
  167.     PE_Splitter,
  168.  
  169.     PE_Panel,
  170.     PE_PanelPopup,
  171.     PE_PanelMenuBar,
  172.     PE_PanelDockWindow,
  173.  
  174.     PE_TabBarBase,
  175.  
  176.     PE_HeaderSection,
  177.     PE_HeaderArrow,
  178.     PE_StatusBarSection,
  179.  
  180.     PE_GroupBoxFrame,
  181.  
  182.     PE_Separator,
  183.  
  184.     PE_SizeGrip,
  185.  
  186.     PE_CheckMark,
  187.  
  188.     PE_ScrollBarAddLine,
  189.     PE_ScrollBarSubLine,
  190.     PE_ScrollBarAddPage,
  191.     PE_ScrollBarSubPage,
  192.     PE_ScrollBarSlider,
  193.     PE_ScrollBarFirst,
  194.     PE_ScrollBarLast,
  195.  
  196.     PE_ProgressBarChunk,
  197.  
  198.     // do not add any values below/greater this
  199.     PE_CustomBase =            0xf000000
  200.     };
  201.  
  202.     enum StyleFlags {
  203.     Style_Default =         0x00000000,
  204.     Style_Enabled =         0x00000001,
  205.     Style_Raised =            0x00000002,
  206.     Style_Sunken =             0x00000004,
  207.     Style_Off =            0x00000008,
  208.     Style_NoChange =        0x00000010,
  209.     Style_On =            0x00000020,
  210.     Style_Down =            0x00000040,
  211.     Style_Horizontal =        0x00000080,
  212.     Style_HasFocus =        0x00000100,
  213.     Style_Top =            0x00000200,
  214.     Style_Bottom =            0x00000400,
  215.     Style_FocusAtBorder =        0x00000800,
  216.     Style_AutoRaise =        0x00001000,
  217.     Style_MouseOver =        0x00002000,
  218.     Style_Up =            0x00004000,
  219.     Style_Selected =         0x00008000,
  220.     Style_Active =            0x00010000,
  221.     Style_ButtonDefault =        0x00020000
  222.     };
  223.     typedef uint SFlags;
  224.  
  225.     virtual void drawPrimitive( PrimitiveElement pe,
  226.                 QPainter *p,
  227.                 const QRect &r,
  228.                 const QColorGroup &cg,
  229.                 SFlags flags = Style_Default,
  230.                 const QStyleOption& = QStyleOption::Default ) const = 0;
  231.  
  232.  
  233.     enum ControlElement {
  234.     CE_PushButton,
  235.     CE_PushButtonLabel,
  236.  
  237.     CE_CheckBox,
  238.     CE_CheckBoxLabel,
  239.  
  240.     CE_RadioButton,
  241.     CE_RadioButtonLabel,
  242.  
  243.     CE_TabBarTab,
  244.     CE_TabBarLabel,
  245.  
  246.     CE_ProgressBarGroove,
  247.     CE_ProgressBarContents,
  248.     CE_ProgressBarLabel,
  249.  
  250.     CE_PopupMenuItem,
  251.     CE_MenuBarItem,
  252.  
  253.     CE_ToolButtonLabel,
  254.  
  255.     // do not add any values below/greater than this
  256.     CE_CustomBase =        0xf0000000
  257.     };
  258.  
  259.     virtual void drawControl( ControlElement element,
  260.                   QPainter *p,
  261.                   const QWidget *widget,
  262.                   const QRect &r,
  263.                   const QColorGroup &cg,
  264.                   SFlags how = Style_Default,
  265.                   const QStyleOption& = QStyleOption::Default ) const = 0;
  266.     virtual void drawControlMask( ControlElement element,
  267.                   QPainter *p,
  268.                   const QWidget *widget,
  269.                   const QRect &r,
  270.                   const QStyleOption& = QStyleOption::Default ) const = 0;
  271.  
  272.     enum SubRect {
  273.     SR_PushButtonContents,
  274.     SR_PushButtonFocusRect,
  275.  
  276.     SR_CheckBoxIndicator,
  277.     SR_CheckBoxContents,
  278.     SR_CheckBoxFocusRect,
  279.  
  280.     SR_RadioButtonIndicator,
  281.     SR_RadioButtonContents,
  282.     SR_RadioButtonFocusRect,
  283.  
  284.     SR_ComboBoxFocusRect,
  285.  
  286.     SR_SliderFocusRect,
  287.  
  288.     SR_DockWindowHandleRect,
  289.  
  290.     SR_ProgressBarGroove,
  291.     SR_ProgressBarContents,
  292.     SR_ProgressBarLabel,
  293.  
  294.     SR_ToolButtonContents,
  295.  
  296.     // do not add any values below/greater than this
  297.     SR_CustomBase =        0xf0000000
  298.     };
  299.  
  300.     virtual QRect subRect( SubRect r, const QWidget *widget ) const = 0;
  301.  
  302.  
  303.     enum ComplexControl{
  304.     CC_SpinWidget,
  305.     CC_ComboBox,
  306.     CC_ScrollBar,
  307.     CC_Slider,
  308.     CC_ToolButton,
  309.     CC_TitleBar,
  310.     CC_ListView,
  311.  
  312.     // do not add any values below/greater than this
  313.     CC_CustomBase =        0xf0000000
  314.     };
  315.  
  316.     enum SubControl {
  317.     SC_None =            0x00000000,
  318.  
  319.     SC_ScrollBarAddLine =        0x00000001,
  320.     SC_ScrollBarSubLine =        0x00000002,
  321.     SC_ScrollBarAddPage =        0x00000004,
  322.     SC_ScrollBarSubPage =        0x00000008,
  323.     SC_ScrollBarFirst =        0x00000010,
  324.     SC_ScrollBarLast =        0x00000020,
  325.     SC_ScrollBarSlider =        0x00000040,
  326.     SC_ScrollBarGroove =        0x00000080,
  327.  
  328.     SC_SpinWidgetUp =        0x00000001,
  329.     SC_SpinWidgetDown =        0x00000002,
  330.     SC_SpinWidgetFrame =        0x00000004,
  331.     SC_SpinWidgetEditField =    0x00000008,
  332.     SC_SpinWidgetButtonField =    0x00000010,
  333.  
  334.     SC_ComboBoxFrame =        0x00000001,
  335.     SC_ComboBoxEditField =        0x00000002,
  336.     SC_ComboBoxArrow =        0x00000004,
  337.  
  338.     SC_SliderGroove =        0x00000001,
  339.     SC_SliderHandle =         0x00000002,
  340.     SC_SliderTickmarks =         0x00000004,
  341.  
  342.     SC_ToolButton =            0x00000001,
  343.     SC_ToolButtonMenu =        0x00000002,
  344.  
  345.     SC_TitleBarLabel =        0x00000001,
  346.     SC_TitleBarSysMenu =        0x00000002,
  347.     SC_TitleBarMinButton =        0x00000004,
  348.     SC_TitleBarMaxButton =        0x00000008,
  349.     SC_TitleBarCloseButton =    0x00000010,
  350.     SC_TitleBarNormalButton =    0x00000020,
  351.     SC_TitleBarShadeButton =    0x00000040,
  352.     SC_TitleBarUnshadeButton =    0x00000080,
  353.  
  354.     SC_ListView =            0x00000001,
  355.     SC_ListViewBranch =        0x00000002,
  356.     SC_ListViewExpand =        0x00000004,
  357.  
  358.     SC_All =            0xffffffff
  359.     };
  360.     typedef uint SCFlags;
  361.  
  362.  
  363.     virtual void drawComplexControl( ComplexControl control,
  364.                      QPainter *p,
  365.                      const QWidget *widget,
  366.                      const QRect &r,
  367.                      const QColorGroup &cg,
  368.                      SFlags how = Style_Default,
  369.                      SCFlags sub = SC_All,
  370.                      SCFlags subActive = SC_None,
  371.                      const QStyleOption& = QStyleOption::Default ) const = 0;
  372.     virtual void drawComplexControlMask( ComplexControl control,
  373.                      QPainter *p,
  374.                      const QWidget *widget,
  375.                      const QRect &r,
  376.                      const QStyleOption& = QStyleOption::Default ) const = 0;
  377.  
  378.     virtual QRect querySubControlMetrics( ComplexControl control,
  379.                       const QWidget *widget,
  380.                       SubControl sc,
  381.                       const QStyleOption& = QStyleOption::Default ) const = 0;
  382.     virtual SubControl querySubControl( ComplexControl control,
  383.                     const QWidget *widget,
  384.                     const QPoint &pos,
  385.                     const QStyleOption& = QStyleOption::Default ) const = 0;
  386.  
  387.  
  388.     enum PixelMetric {
  389.     PM_ButtonMargin,
  390.     PM_ButtonDefaultIndicator,
  391.     PM_MenuButtonIndicator,
  392.     PM_ButtonShiftHorizontal,
  393.     PM_ButtonShiftVertical,
  394.  
  395.     PM_DefaultFrameWidth,
  396.     PM_SpinBoxFrameWidth,
  397.  
  398.     PM_MaximumDragDistance,
  399.  
  400.     PM_ScrollBarExtent,
  401.     PM_ScrollBarSliderMin,
  402.  
  403.     PM_SliderThickness,               // total slider thickness
  404.     PM_SliderControlThickness,        // thickness of the business part
  405.     PM_SliderLength,        // total length of slider
  406.     PM_SliderTickmarkOffset,    //
  407.     PM_SliderSpaceAvailable,    // available space for slider to move
  408.  
  409.     PM_DockWindowSeparatorExtent,
  410.     PM_DockWindowHandleExtent,
  411.     PM_DockWindowFrameWidth,
  412.  
  413.     PM_MenuBarFrameWidth,
  414.  
  415.     PM_TabBarTabOverlap,
  416.     PM_TabBarTabHSpace,
  417.     PM_TabBarTabVSpace,
  418.     PM_TabBarBaseHeight,
  419.     PM_TabBarBaseOverlap,
  420.  
  421.     PM_ProgressBarChunkWidth,
  422.  
  423.     PM_SplitterWidth,
  424.     PM_TitleBarHeight,
  425.  
  426.     PM_IndicatorWidth,
  427.     PM_IndicatorHeight,
  428.     PM_ExclusiveIndicatorWidth,
  429.     PM_ExclusiveIndicatorHeight,
  430.  
  431.     // do not add any values below/greater than this
  432.     PM_CustomBase =        0xf0000000
  433.     };
  434.  
  435.     virtual int pixelMetric( PixelMetric metric,
  436.                  const QWidget *widget = 0 ) const = 0;
  437.  
  438.  
  439.     enum ContentsType {
  440.     CT_PushButton,
  441.     CT_CheckBox,
  442.     CT_RadioButton,
  443.     CT_ToolButton,
  444.     CT_ComboBox,
  445.     CT_Splitter,
  446.     CT_DockWindow,
  447.     CT_ProgressBar,
  448.     CT_PopupMenuItem,
  449.  
  450.     // do not add any values below/greater than this
  451.     CT_CustomBase =        0xf0000000
  452.     };
  453.  
  454.     virtual QSize sizeFromContents( ContentsType contents,
  455.                     const QWidget *widget,
  456.                     const QSize &contentsSize,
  457.                     const QStyleOption& = QStyleOption::Default ) const = 0;
  458.  
  459.     enum StyleHint  {
  460.     // ...
  461.     // the general hints
  462.     // ...
  463.            // disabled text should be etched, ala Windows
  464.     SH_EtchDisabledText,
  465.  
  466.     // the GUI style enum, argh!
  467.     SH_GUIStyle,
  468.  
  469.     // ...
  470.     // widget specific hints
  471.     // ...
  472.     SH_ScrollBar_BackgroundMode,
  473.     SH_ScrollBar_MiddleClickAbsolutePosition,
  474.     SH_ScrollBar_ScrollWhenPointerLeavesControl,
  475.  
  476.     // QEvent::Type - which mouse event to select a tab
  477.     SH_TabBar_SelectMouseType,
  478.  
  479.     SH_TabBar_Alignment,
  480.  
  481.     SH_Header_ArrowAlignment,
  482.  
  483.     // bool - sliders snap to values while moving, ala Windows
  484.     SH_Slider_SnapToValue,
  485.  
  486.     // bool - key presses handled in a sloppy manner - ie. left on a vertical
  487.     // slider subtracts a line
  488.     SH_Slider_SloppyKeyEvents,
  489.  
  490.     // bool - center button on progress dialogs, ala Motif, else right aligned
  491.     // perhaps this should be a Qt::Alignment value
  492.     SH_ProgressDialog_CenterCancelButton,
  493.  
  494.     // Qt::AlignmentFlags - text label alignment in progress dialogs
  495.     // Center on windows, Auto|VCenter otherwize
  496.     SH_ProgressDialog_TextLabelAlignment,
  497.  
  498.     // bool - right align buttons on print dialog, ala Windows
  499.     SH_PrintDialog_RightAlignButtons,
  500.  
  501.     // bool - 1 or 2 pixel space between the menubar and the dockarea, ala Windows
  502.     // this *REALLY* needs a better name
  503.     SH_MainWindow_SpaceBelowMenuBar,
  504.  
  505.     // bool - select the text in the line edit about the listbox when selecting
  506.     // an item from the listbox, or when the line edit receives focus, ala Windows
  507.     SH_FontDialog_SelectAssociatedText,
  508.  
  509.     // bool - allows disabled menu items to be active
  510.     SH_PopupMenu_AllowActiveAndDisabled,
  511.  
  512.     // bool - pressing space activates item, ala Motif
  513.     SH_PopupMenu_SpaceActivatesItem,
  514.  
  515.     // int - number of milliseconds to wait before opening a submenu
  516.     // 256 on windows, 96 on motif
  517.     SH_PopupMenu_SubMenuPopupDelay,
  518.  
  519.     // bool - should scrollviews draw their frame only around contents (ala Motif),
  520.     // or around contents, scrollbars and corner widgets (ala Windows) ?
  521.     SH_ScrollView_FrameOnlyAroundContents,
  522.  
  523.     // bool - menubars items are navigatable by pressing alt, followed by using
  524.     // the arrow keys to select the desired item
  525.     SH_MenuBar_AltKeyNavigation,
  526.  
  527.     // bool - mouse tracking in combobox dropdown lists
  528.     SH_ComboBox_ListMouseTracking,
  529.  
  530.     // bool - mouse tracking in popupmenus
  531.     SH_PopupMenu_MouseTracking,
  532.  
  533.     // bool - mouse tracking in menubars
  534.     SH_MenuBar_MouseTracking,
  535.  
  536.     // bool - gray out selected items when loosing focus
  537.     SH_ItemView_ChangeHighlightOnFocus,
  538.  
  539.     // bool - supports shared activation among modeless widgets
  540.     SH_Widget_ShareActivation,
  541.  
  542.     // bool - workspace should just maximize the client area
  543.     SH_Workspace_FillSpaceOnMaximize,
  544.  
  545.     // bool - supports popup menu comboboxes
  546.     SH_ComboBox_Popup, 
  547.  
  548.     // do not add any values below/greater than this
  549.     SH_CustomBase =        0xf0000000
  550.     };
  551.  
  552.     virtual int styleHint( StyleHint stylehint,
  553.                const QWidget *widget = 0,
  554.                const QStyleOption& = QStyleOption::Default,
  555.                QStyleHintReturn* returnData = 0
  556.                ) const = 0;
  557.  
  558.  
  559.     enum StylePixmap {
  560.     SP_TitleBarMinButton,
  561.     SP_TitleBarMaxButton,
  562.     SP_TitleBarCloseButton,
  563.     SP_TitleBarNormalButton,
  564.     SP_TitleBarShadeButton,
  565.     SP_TitleBarUnshadeButton,
  566.     SP_DockWindowCloseButton,
  567.     SP_MessageBoxInformation,
  568.     SP_MessageBoxWarning,
  569.     SP_MessageBoxCritical,
  570.  
  571.     // do not add any values below/greater than this
  572.     SP_CustomBase =        0xf0000000
  573.     };
  574.  
  575.     virtual QPixmap stylePixmap( StylePixmap stylepixmap,
  576.                  const QWidget *widget = 0,
  577.                  const QStyleOption& = QStyleOption::Default ) const = 0;
  578.  
  579.  
  580.     static QRect visualRect( const QRect &logical, const QWidget *w );
  581.  
  582.     static QRect visualRect( const QRect &logical, const QRect &bounding );
  583.  
  584.  
  585.  
  586.  
  587.     // Old 2.x QStyle API
  588.  
  589. #ifndef QT_NO_COMPAT
  590.     int defaultFrameWidth() const
  591.     {
  592.     return pixelMetric( PM_DefaultFrameWidth );
  593.     }
  594.     void tabbarMetrics( const QWidget* t,
  595.             int& hf, int& vf, int& ov ) const
  596.     {
  597.     hf = pixelMetric( PM_TabBarTabHSpace, t );
  598.     vf = pixelMetric( PM_TabBarTabVSpace, t );
  599.     ov = pixelMetric( PM_TabBarBaseOverlap, t );
  600.     }
  601.     QSize scrollBarExtent() const
  602.     {
  603.     return QSize(pixelMetric(PM_ScrollBarExtent),
  604.              pixelMetric(PM_ScrollBarExtent));
  605.     }
  606. #endif
  607.  
  608.  
  609. private:
  610.     QStylePrivate * d;
  611.  
  612. #if defined(Q_DISABLE_COPY)
  613.     QStyle( const QStyle & );
  614.     QStyle& operator=( const QStyle & );
  615. #endif
  616. };
  617.  
  618. #endif // QT_NO_STYLE
  619. #endif // QSTYLE_H
  620.