home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / wtoolbar.hpp < prev    next >
C/C++ Source or Header  |  1996-11-27  |  14KB  |  435 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. /*************************************************************************
  12.  *
  13.  * WToolbar -- Wrapper for the Windows 95 Toolbar control.
  14.  *
  15.  *   Events:
  16.  *
  17.  *       Click --
  18.  *
  19.  *       ToolbarDragBegin --
  20.  *
  21.  *       ToolbarDragEnd --
  22.  *
  23.  *************************************************************************/
  24.  
  25. #ifndef _WTOOLBAR_HPP_INCLUDED
  26. #define _WTOOLBAR_HPP_INCLUDED
  27.  
  28. #ifndef _WNO_PRAGMA_PUSH
  29. #pragma pack(push,8);
  30. #pragma enum int;
  31. #endif
  32.  
  33. #ifndef _WBITMAP_HPP_INCLUDED
  34. #  include "wbitmap.hpp"
  35. #endif
  36. #ifndef _WCONTROL_HPP_INCLUDED
  37. #  include "wcontrol.hpp"
  38. #endif
  39. #ifndef _WPOINT_HPP_INCLUDED
  40. #  include "wpoint.hpp"
  41. #endif
  42. #ifndef _WWINDOW_HPP_INCLUDED
  43. #  include "wwindow.hpp"
  44. #endif
  45. #ifndef _WVECTOR_HPP_INCLUDED
  46. #  include "wvector.hpp"
  47. #endif
  48. #ifndef _WSIZE_HPP_INCLUDED
  49. #  include "wsize.hpp"
  50. #endif
  51. #ifndef _WARRAY_HPP_INCLUDED
  52. #  include "warray.hpp"
  53. #endif
  54.  
  55. class WToolbar;
  56.  
  57. typedef void WCMDEF (WObject::*WToolTipCallback)( WToolbar * w, WLong id, WString & str );
  58.  
  59. enum WToolbarStandardBitmap {
  60.     WTBStdBmpCut                = 0,
  61.     WTBStdBmpCopy               = 1,
  62.     WTBStdBmpPaste              = 2,
  63.     WTBStdBmpUndo               = 3,
  64.     WTBStdBmpRedo               = 4,
  65.     WTBStdBmpDelete             = 5,
  66.     WTBStdBmpFileNew            = 6,
  67.     WTBStdBmpFileOpen           = 7,
  68.     WTBStdBmpFileSave           = 8,
  69.     WTBStdBmpPrintPreview       = 9,
  70.     WTBStdBmpProperties         = 10,
  71.     WTBStdBmpHelp               = 11,
  72.     WTBStdBmpFind               = 12,
  73.     WTBStdBmpReplace            = 13,
  74.     WTBStdBmpPrint              = 14,
  75. };
  76.  
  77. enum WToolbarViewBitmap {
  78.     WTBViewBmpLargeIcons        = 0,
  79.     WTBViewBmpSmallIcons        = 1,
  80.     WTBViewBmpList              = 2,
  81.     WTBViewBmpDetails           = 3,
  82.     WTBViewBmpSortName          = 4,
  83.     WTBViewBmpSortSize          = 5,
  84.     WTBViewBmpSortDate          = 6,
  85.     WTBViewBmpSortType          = 7,
  86.     WTBViewBmpParentFolder      = 8,
  87.     WTBViewBmpNetConnect        = 9,
  88.     WTBViewBmpNetDisconnect     = 10,
  89.     WTBViewBmpNewFolder         = 11,
  90. };
  91.  
  92. enum WToolbarItemStyle {
  93.     WTBBPushButton              = 0x00,
  94.     WTBBSeparator               = 0x01,
  95.     WTBBCheckButton             = 0x02,
  96.     WTBBGroupButton             = 0x04,
  97.     WTBBCheckGroupButton        = 0x06,
  98. };
  99.  
  100. enum WToolbarItemHandle { NULLHTBITEM  = 0,  LASTHTBITEM = LAST_16TO32BIT };
  101.  
  102. struct WToolbarEventData : public WEventData {
  103.     WToolbarItemHandle  item;
  104. };
  105.  
  106. struct WToolbarDragBeginEventData : public WEventData {
  107.     WToolbarItemHandle  item;
  108.     WWindow *           over;
  109. };
  110.  
  111. struct WToolbarDragEndEventData : public WEventData {
  112.     WToolbarItemHandle  item;
  113.     WWindow *           over;
  114. };
  115.  
  116. class WCMCLASS WToolbarItemInfo {
  117.  
  118.     public:
  119.  
  120.         /**********************************************************
  121.          * Constructors and Destructors
  122.          *********************************************************/
  123.  
  124.         WToolbarItemInfo();
  125.         WToolbarItemInfo( const WToolbarItemInfo & info );
  126.  
  127.         ~WToolbarItemInfo();
  128.  
  129.         /**********************************************************
  130.          * Methods
  131.          *********************************************************/
  132.  
  133.         void Init();
  134.  
  135.         /**********************************************************
  136.          * Operators
  137.          *********************************************************/
  138.  
  139.         WToolbarItemInfo& operator=( const WToolbarItemInfo & info );
  140.  
  141.     public:
  142.  
  143.         /**********************************************************
  144.          * Data Members
  145.          *********************************************************/
  146.  
  147.         WToolbarItemStyle       style;
  148.         WInt                    bitmapIndex;
  149.         WInt                    stringIndex;
  150.         WBool                   enabled;
  151.         WBool                   checked;
  152.         WBool                   pressed;
  153.         WBool                   indeterminate;
  154.         WBool                   hidden;
  155.         WBool                   lineBreak;
  156.         void *                  userData;
  157.         WInt                    commandID;
  158.         WBool                   inToolbar;
  159.         WString                 text;
  160.         WString                 toolTipText;
  161. };
  162.  
  163. extern template WArrayReference<WToolbarItemInfo>;
  164. extern template WArray<WToolbarItemInfo>;
  165. typedef WArray<WToolbarItemInfo>        WToolbarItemInfoArray;
  166.  
  167. //
  168. // Toolbar styles
  169. //
  170.  
  171. #define WTOOLBSDefault          ((WStyle)0x50000271L) // WS_VISIBLE|WS_CHILD|CCS_NOHILITE|CCS_NODIVIDER|CCS_TOP|CCS_ADJUSTABLE
  172. #define WTOOLBSAltDrag          ((WStyle)0x00000400L) // TBSTYLE_ALTDRAG
  173. #define WTOOLBSWrapable         ((WStyle)0x00000200L) // TBSTYLE_WRAPABLE
  174. #define WTOOLBSToolTips         ((WStyle)0x00000100L) // TBSTYLE_TOOLTIPS
  175. #define WTOOLBSMultiline        ((WStyle)0x00000200L) // TBSTYLE_WRAPABLE
  176. #define WTOOLBSFlat             ((WStyle)0x00000800L) // LBS_EXTENDEDSEL
  177. #define WTOOLBSExDefault        ((WStyle)0x00000000L) // WS_OVERLAPPED
  178.  
  179. class WCMCLASS WToolbar : public WControl {
  180.     WDeclareSubclass( WToolbar, WControl );
  181.  
  182.     public:
  183.  
  184.         /**********************************************************
  185.          * Constructors and Destructors
  186.          *********************************************************/
  187.     
  188.         WToolbar();
  189.     
  190.         ~WToolbar();
  191.  
  192.         /**********************************************************
  193.          * Properties
  194.          *********************************************************/
  195.  
  196.         // AutoSize
  197.  
  198.         virtual WBool SetAutoSize( WBool on );
  199.         virtual WBool GetAutoSize() const;
  200.  
  201.         // BitmapSize
  202.         //
  203.         //     Note: Default size is 16x15
  204.  
  205.         WBool SetBitmapSize( const WSize & bitmapSize );
  206.         WSize GetBitmapSize();
  207.  
  208.         // ButtonSize
  209.         //
  210.         //     Note: Default size is 24x22
  211.  
  212.         WBool SetButtonSize( const WSize & buttonSize );
  213.         WSize GetButtonSize( WBool calculate=TRUE );
  214.  
  215.         // Count
  216.  
  217.         WInt GetCount() const;
  218.  
  219.         // ToolTip
  220.  
  221.         virtual WToolTip * GetToolTip() const;
  222.         virtual WBool SetToolTip( WToolTip * toolTip );
  223.  
  224.         /**********************************************************
  225.          * Methods
  226.          *********************************************************/
  227.  
  228.         // Add
  229.  
  230.         WToolbarItemHandle Add( WToolbarItemInfo & info, WInt index );
  231.         WBool              Add( WToolbarItemInfoArray & infoArray );
  232.  
  233.         // AddBitmap
  234.  
  235.         WBool AddBitmap( const WResourceID & bitmapID, WInt numBitmaps,
  236.                          WInt * index=NULL );
  237.         WBool AddBitmap( const WBitmap & bitmap, WInt numBitmaps,
  238.                          WInt * index=NULL );
  239.         WBool AddBitmap( WBool standard=TRUE, WBool large=TRUE,
  240.                          WInt * index=NULL );
  241.  
  242.         // AddBitmaps
  243.  
  244.         WBool AddBitmaps( const WResourceIDArray & bitmapIDArray,
  245.                           WIntArray * index=NULL );
  246.         WBool AddBitmaps( const WBitmapArray & bitmapArray,
  247.                           WIntArray * index=NULL );
  248.  
  249.         // Change Bitmap
  250.  
  251.         WBool ChangeBitmap( WToolbarItemHandle item,
  252.                             WInt bitmapIndex );
  253.         
  254.         // AddString
  255.  
  256.         WBool AddString( const WString & text, WInt * index=NULL );
  257.  
  258.         // AutoSize
  259.  
  260.         virtual void AutoSize();
  261.  
  262.         // CalculateSize
  263.  
  264.         virtual WRect CalculateSize( const WRect & size, WBool adjust );
  265.  
  266.         // Customize
  267.  
  268.         void Customize();
  269.  
  270.         // Delete
  271.  
  272.         WBool Delete( WToolbarItemHandle item );
  273.         WBool Delete( WInt index );
  274.  
  275.         // Hide
  276.  
  277.         WBool Hide( WToolbarItemHandle item );
  278.  
  279.         // Retrieve
  280.  
  281.         WToolbarItemHandle Retrieve( WInt index );
  282.  
  283.         // Show
  284.  
  285.         WBool Show( WToolbarItemHandle item );
  286.  
  287.         /**********************************************************
  288.          * Item Properties
  289.          *********************************************************/
  290.  
  291.         // ButtonStyle
  292.  
  293.         WToolbarItemStyle GetButtonStyle( WToolbarItemHandle item );
  294.  
  295.         // Checked
  296.  
  297.         WBool SetChecked( WToolbarItemHandle item, WBool checked=TRUE );
  298.         WBool GetChecked( WToolbarItemHandle item );
  299.  
  300.         // Enabled
  301.  
  302.         WBool SetEnabled( WToolbarItemHandle item, WBool enable=TRUE );
  303.         WBool GetEnabled( WToolbarItemHandle item );
  304.  
  305.         // Indeterminate
  306.  
  307.         WBool SetIndeterminate( WToolbarItemHandle item, WBool indeterminate=TRUE );
  308.         WBool GetIndeterminate( WToolbarItemHandle item );
  309.  
  310.         // LineBreak
  311.  
  312.         WBool SetLineBreak( WToolbarItemHandle item, WBool lineBreak=FALSE );
  313.         WBool GetLineBreak( WToolbarItemHandle item );
  314.  
  315.         // Pressed
  316.  
  317.         WBool SetPressed( WToolbarItemHandle item, WBool pressed=TRUE );
  318.         WBool GetPressed( WToolbarItemHandle item );
  319.  
  320.         // Rectangle
  321.  
  322.         WRect GetRectangle( WToolbarItemHandle item );
  323.  
  324.         // UserData
  325.         //
  326.         //     Get per-item data.
  327.  
  328.         void * GetUserData( WToolbarItemHandle item ) const;
  329.     
  330.         /**********************************************************
  331.          * Overrides
  332.          *********************************************************/
  333.     
  334.         virtual WBool SetEnabled( WBool enabled );
  335.  
  336.         virtual WBool GetEnabled() const;
  337.  
  338.         virtual WBool SetVisible( WBool visible );
  339.  
  340.         virtual WBool GetVisible() const;
  341.  
  342.         virtual WRect GetRectangle( WBool absolute=FALSE ) const;
  343.  
  344.         virtual WBool Move( const WRect & rectangle, WBool update=TRUE );
  345.  
  346.         virtual WBool Move( const WRect & rectangle, WDeferMoveHandle & dwp );
  347.  
  348.         virtual WBool Move( const WPoint & point, WBool update=TRUE );
  349.  
  350.         virtual WBool Move( const WPoint & point, WDeferMoveHandle & dwp );
  351.  
  352.         virtual WBool Update( WBool force=FALSE );
  353.     
  354.         virtual WBool SetParent( const WWindow * parent );
  355.  
  356.         virtual WWindow * GetParent() const;
  357.  
  358.         virtual void * GetUserData() const;
  359.  
  360.         virtual WStyle GetDefaultStyle() const;
  361.  
  362.         virtual WStyle GetDefaultExtendedStyle() const;
  363.  
  364.         virtual const WChar * InitializeClass();
  365.  
  366.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  367.                                    void * data=NULL );
  368.  
  369.         virtual WBool WantsDragMessage( WULong whichButton ) const;
  370.         virtual WBool FillDragEventData( WDragEventData & event ) const;
  371.  
  372.     protected:
  373.     
  374.         virtual WBool ProcessCommand( WUInt id, WNotify code,
  375.                                       WNotifyInfo info, WLong & returns );
  376.  
  377.         virtual WBool ProcessNotify( WUInt id, WNotify code, WNotifyInfo info,
  378.                                      WLong & returns );
  379.  
  380.         virtual WBool MakeWindow( WWindow * parent, WUInt id,
  381.                                   const WChar * className,
  382.                                   const WChar * title, const WRect & r,
  383.                                   WStyle wstyle, WStyle exStyle,
  384.                                   void * data=NULL );
  385.  
  386.         /**********************************************************
  387.          * Other
  388.          *********************************************************/
  389.     
  390.         WBool GetLineBreakByIndex( WInt index );
  391.  
  392.     protected:
  393.  
  394.         WBool PositionChangingEventHandler( WWindow * window,
  395.                                             WMoveEventData * event );
  396.  
  397.         WBool NeedToolTipTextEventHandler( WWindow * source,
  398.                                            WToolTipTextEventData * event );
  399.  
  400.         WBool BackingNeedToolTipTextEventHandler( WWindow * source,
  401.                                            WToolTipTextEventData * event );
  402.  
  403.         void MapFromToolbarItem( WToolbarItemInfo const * button,
  404.                                  void * info );
  405.  
  406.         void MapToToolbarItem( WToolbarItemInfo * button,
  407.                                void const * info );
  408.  
  409.         void PrepareForCustomization();
  410.  
  411.         /**********************************************************
  412.          * Data members
  413.          *********************************************************/
  414.     
  415.     private:
  416.  
  417.         WToolbarItemHandle      _lastCommandID;
  418.         WBool                   _autoSize;
  419.         WSize                   _bitmapSize;
  420.         WSize                   _buttonSize;
  421.         WULong                  _buttonCount;
  422.         void *                  _internalData;
  423.         WForm *                 _backing;
  424.         WRect                   _lastCalcRequest;
  425.         WRect                   _lastCalcResult;
  426.         WBool                   _lastCalcAdjust;
  427. };
  428.  
  429. #ifndef _WNO_PRAGMA_PUSH
  430. #pragma enum pop;
  431. #pragma pack(pop);
  432. #endif
  433.  
  434. #endif // _WTOOLBAR_HPP_INCLUDED
  435.