home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / DIConfig / cdeviceui.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  6.0 KB  |  233 lines

  1. /******************************************************************************
  2.  * File: CDeviceUI.h
  3.  *
  4.  * Desc:
  5.  *
  6.  * CDeviceUI is a helper that holds all the views and a bunch of
  7.  * information for a specific device.  It has a CFlexWnd whose
  8.  * handler it sets to the CDeviceView for the current view,
  9.  * thus reusing one window to implement multiple pages.
  10.  *
  11.  * All CDeviceViews and CDeviceControls have a reference to the CDeviceUI
  12.  * that created them (m_ui).  Thus, they also have access to the
  13.  * CUIGlobals, since CDeviceUI has a reference to them (m_ui.m_uig).
  14.  * CDeviceUI also provides the following read-only public variables
  15.  * for convenience, all referring to the device this CDeviceUI
  16.  * represents:
  17.  * 
  18.  * const DIDEVICEINSTANCEW &m_didi;
  19.  * const LPDIRECTINPUTDEVICE8W &m_lpDID;
  20.  * const DIDEVOBJSTRUCT &m_os;
  21.  *
  22.  * See usefuldi.h for a description of DIDEVOBJSTRUCT.
  23.  *
  24.  * CDeviceUI communicates to the rest of the UI via the CDeviceUINotify
  25.  * abstract base class.  Another class (in our case CDIDeviceActionConfigPage)
  26.  * must derive from CDeviceUINotify, and define the DeviceUINotify() and
  27.  * IsControlMapped() virtual functions.  This derived class must be passed as
  28.  * the last parameter to CDeviceUI's Init() function.  All the views and 
  29.  * controls within the views notify the UI of user actions via m_ui.Notify(),
  30.  * so that all actionformat manipulation can be done in the page class.  The
  31.  * views and controls themselves never touch the actionformat.  See the
  32.  * DEVICEUINOTIFY structure below for information on the parameter passed
  33.  * through Notify()/DeviceUINotify().
  34.  *
  35.  * Copyright (C) 1999-2001 Microsoft Corporation. All Rights Reserved.
  36.  *
  37.  ***************************************************************************/
  38.  
  39.  
  40. #ifdef FORWARD_DECLS
  41.  
  42.  
  43.     struct DEVICEUINOTIFY;
  44.  
  45.     struct UIDELETENOTE;
  46.  
  47.     class CDeviceUINotify;
  48.     class CDeviceUI;
  49.  
  50.  
  51. #else // FORWARD_DECLS
  52.  
  53. #ifndef __CDEVICEUI_H__
  54. #define __CDEVICEUI_H__
  55.  
  56.  
  57. enum {
  58.     DEVUINM_NUMVIEWSCHANGED,
  59.     DEVUINM_ONCONTROLDESTROY,
  60.     DEVUINM_MOUSEOVER,
  61.     DEVUINM_CLICK,
  62.     DEVUINM_DOUBLECLICK,
  63.     DEVUINM_SELVIEW,
  64.     DEVUINM_INVALID,
  65.     DEVUINM_UNASSIGNCALLOUT,
  66.     DEVUINM_RENEWDEVICE
  67. };
  68.  
  69. enum {
  70.     DEVUINFROM_CONTROL,
  71.     DEVUINFROM_THUMBNAIL,
  72.     DEVUINFROM_SELWND,
  73.     DEVUINFROM_VIEWWND,
  74.     DEVUINFROM_INVALID
  75. };
  76.  
  77. struct DEVICEUINOTIFY {
  78.     DEVICEUINOTIFY() : msg(DEVUINM_INVALID), from(DEVUINFROM_INVALID) {}
  79.     int msg;
  80.     int from;
  81.     union {
  82.         struct {
  83.             CDeviceControl *pControl;
  84.         } control;
  85.         struct {
  86.             CDeviceView *pView;
  87.             BOOL bSelected;
  88.         } thumbnail;
  89.         struct {
  90.             int dummy;
  91.         } selwnd;
  92.         struct {
  93.             int dummy;
  94.         } viewwnd;
  95.     };
  96.     union {
  97.         struct {
  98.             int nView;
  99.         } selview;
  100.         struct {
  101.             POINT point;
  102.         } mouseover;
  103.         struct {
  104.             BOOL bLeftButton;
  105.         } click;
  106.     };
  107. };
  108.  
  109.  
  110. enum UIDELETENOTETYPE {
  111.     UIDNT_VIEW,
  112.     UIDNT_CONTROL,
  113. };
  114.  
  115. struct UIDELETENOTE {
  116.     UIDELETENOTETYPE eType;
  117.     int nViewIndex;
  118.     int nControlIndex;
  119.     DWORD dwObjID;
  120. };
  121.  
  122. typedef void (*DEVCTRLCALLBACK)(CDeviceControl *, LPVOID, BOOL);
  123.  
  124.  
  125. class CDeviceUINotify
  126. {
  127. public:
  128.     virtual void DeviceUINotify(const DEVICEUINOTIFY &) = 0;
  129.     virtual BOOL IsControlMapped(CDeviceControl *) = 0;
  130. };
  131.  
  132.  
  133. class CDeviceUI
  134. {
  135. public:
  136.     CDeviceUI(CUIGlobals &uig, IDIConfigUIFrameWindow &uif);
  137.     ~CDeviceUI();
  138.  
  139.     // intialization
  140.     HRESULT Init(const DIDEVICEINSTANCEW &didi, LPDIRECTINPUTDEVICE8W lpDID, HWND hWnd, CDeviceUINotify *pNotify);
  141.  
  142.     // view state
  143.     void SetView(int nView);
  144.     void SetView(CDeviceView *pView);
  145.     CDeviceView *GetView(int nView);
  146.     CDeviceView *GetCurView();
  147.     int GetViewIndex(CDeviceView *pView);
  148.     int GetCurViewIndex();
  149.     int GetNumViews() {return m_arpView.GetSize();}
  150.     void NextView() {SetView((GetCurViewIndex() + 1) % GetNumViews());}
  151.     void PrevView() {SetView((GetCurViewIndex() - 1 + GetNumViews()) % GetNumViews());}
  152.  
  153.     // gets the thumbnail for the specified view,
  154.     // using the selected version if the view is selected
  155.     CBitmap *GetViewThumbnail(int nView);
  156.     
  157.     // gets the thumbnail for the specified view,
  158.     // specifiying whether or not we want the selected version
  159.     CBitmap *GetViewThumbnail(int nView, BOOL bSelected);
  160.  
  161.     // for view/control to notify
  162.     void Notify(const DEVICEUINOTIFY &uin)
  163.         {if (m_pNotify != NULL) m_pNotify->DeviceUINotify(uin);}
  164.  
  165.     // device control access
  166.     void SetAllControlCaptionsTo(LPCTSTR tszCaption);
  167.     void SetCaptionForControlsAtOffset(DWORD dwOffset, LPCTSTR tszCaption, BOOL bFixed = FALSE);
  168.     void DoForAllControls(DEVCTRLCALLBACK callback, LPVOID pVoid, BOOL bFixed = FALSE);
  169.     void DoForAllControlsAtOffset(DWORD dwOffset, DEVCTRLCALLBACK callback, LPVOID pVoid, BOOL bFixed = FALSE);
  170.     
  171.     // page querying
  172.     BOOL IsControlMapped(CDeviceControl *);
  173.  
  174.     // other
  175.     void GetDeviceInstanceGuid(GUID &rGuid) {rGuid = m_didi.guidInstance;}
  176.     
  177.     // editing
  178.     void SetEditMode(BOOL bEdit = TRUE);
  179.     BOOL InEditMode() {return m_bInEditMode;}
  180.     void Remove(CDeviceView *pView);
  181.     void RemoveAll();
  182. #define NVT_USER 1
  183. #define NVT_POPULATE 2
  184. #define NVT_REQUIREATLEASTONE 3
  185.     CDeviceView *NewView();
  186.     CDeviceView *UserNewView();
  187.     void RequireAtLeastOneView();
  188.     void SetDevice(LPDIRECTINPUTDEVICE8W lpDID);  // Sets the device object that we are using
  189.  
  190.  
  191.     // drawing
  192.     void Invalidate();
  193.  
  194.     // clearing
  195.     void Unpopulate();
  196.  
  197. private:
  198.     // delete notes
  199.     CArray<UIDELETENOTE, UIDELETENOTE &> m_DeleteNotes;
  200.  
  201.     // who we're going to notify
  202.     CDeviceUINotify *m_pNotify;
  203.     HWND m_hWnd;
  204.  
  205.     // view state
  206.     CArray<CDeviceView *, CDeviceView *&> m_arpView;
  207.     CDeviceView *m_pCurView;
  208.     BOOL m_bInEditMode;
  209.     RECT m_ViewRect;
  210.     void NumViewsChanged();
  211.  
  212.     // device globals...
  213. public:
  214.     // full access to ui globals and frame
  215.     CUIGlobals &m_uig;
  216.     IDIConfigUIFrameWindow &m_UIFrame;
  217.  
  218.     // read only public access versions
  219.     const DIDEVICEINSTANCEW &m_didi;
  220.     const LPDIRECTINPUTDEVICE8W &m_lpDID;
  221.     const DIDEVOBJSTRUCT &m_os;
  222. private:
  223.     // private versions
  224.     DIDEVICEINSTANCEW m_priv_didi;
  225.     LPDIRECTINPUTDEVICE8W m_priv_lpDID;
  226.     DIDEVOBJSTRUCT m_priv_os;
  227. };
  228.  
  229.  
  230. #endif //__CDEVICEUI_H__
  231.  
  232. #endif // FORWARD_DECLS
  233.