Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
5.5 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: cdevicecontrol.h
  3. //
  4. // Desc: CDeviceControl is a class that encapsulate the functionality of a
  5. // device control (or a callout). CDeviceView accesses it to retrieve/
  6. // save information about the control.
  7. //
  8. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  9. //-----------------------------------------------------------------------------
  10. #ifdef FORWARD_DECLS
  11. struct DEVICECONTROLSTRUCT;
  12. enum DEVCTRLHITRESULT;
  13. class CDeviceControl;
  14. #else // FORWARD_DECLS
  15. #ifndef __CDEVICECONTROL_H__
  16. #define __CDEVICECONTROL_H__
  17. const int MAX_DEVICECONTROL_LINEPOINTS = 5;
  18. #define CAF_LEFT 1
  19. #define CAF_RIGHT 2
  20. #define CAF_TOP 4
  21. #define CAF_BOTTOM 8
  22. #define CAF_TOPLEFT (CAF_TOP | CAF_LEFT)
  23. #define CAF_TOPRIGHT (CAF_TOP | CAF_RIGHT)
  24. #define CAF_BOTTOMLEFT (CAF_BOTTOM | CAF_LEFT)
  25. #define CAF_BOTTOMRIGHT (CAF_BOTTOM | CAF_RIGHT)
  26. struct DEVICECONTROLSTRUCT {
  27. DEVICECONTROLSTRUCT() : nLinePoints(0) {CopyStr(wszOverlayPath, "", MAX_PATH); SRECT r; rectOverlay = r.r;}
  28. DWORD dwDeviceControlOffset;
  29. int nLinePoints;
  30. POINT rgptLinePoint[MAX_DEVICECONTROL_LINEPOINTS];
  31. DWORD dwCalloutAlign;
  32. RECT rectCalloutMax;
  33. WCHAR wszOverlayPath[MAX_PATH];
  34. RECT rectOverlay;
  35. };
  36. enum DEVCTRLHITRESULT {
  37. DCHT_LINE,
  38. DCHT_CAPTION,
  39. DCHT_MAXRECT,
  40. DCHT_CONTROL,
  41. DCHT_NOHIT
  42. };
  43. class CDeviceControl
  44. {
  45. private:
  46. friend class CDeviceView; // CDeviceView has exclusive right to create/destroy views
  47. CDeviceControl(CDeviceUI &ui, CDeviceView &view);
  48. ~CDeviceControl();
  49. CDeviceView &m_view;
  50. CDeviceUI &m_ui;
  51. public:
  52. // Info
  53. int GetViewIndex() { return m_view.GetViewIndex(); }
  54. int GetControlIndex();
  55. // state information
  56. void SetCaption(LPCTSTR tszCaption, BOOL bFixed = FALSE);
  57. LPCTSTR GetCaption();
  58. BOOL IsFixed() { return m_bFixed; }
  59. void Unhighlight() {Highlight(FALSE);}
  60. void Highlight(BOOL bHighlight = TRUE);
  61. BOOL IsHighlighted() {return m_bHighlight;}
  62. void GetInfo(GUID &rGuid, DWORD &rdwOffset);
  63. DWORD GetOffset();
  64. BOOL IsOffsetAssigned();
  65. BOOL HasAction() { return lstrcmp(m_ptszCaption, g_tszUnassignedControlCaption); }
  66. void FillImageInfo(DIDEVICEIMAGEINFOW *pImgInfo); // This fills the structure info about this control
  67. BOOL IsMapped();
  68. int GetMinX() {return m_rectCallout.left;}
  69. int GetMaxX() {return m_rectCallout.right;}
  70. int GetMinY() {return m_rectCallout.top;}
  71. int GetMaxY() {return m_rectCallout.bottom;}
  72. const RECT &GetCalloutMaxRect() const { return m_rectCalloutMax; }
  73. // hit testing (in coord's relative to view's origin)
  74. DEVCTRLHITRESULT HitTest(POINT test);
  75. // simple notification
  76. void OnMouseOver(POINT point);
  77. void OnClick(POINT point, BOOL bLeft, BOOL bDoubleClick = FALSE);
  78. void OnPaint(HDC hDC);
  79. // redrawing
  80. void Invalidate();
  81. // editing
  82. //@@BEGIN_MSINTERNAL
  83. #ifdef DDKBUILD
  84. void ReselectControl();
  85. void SelectControl(BOOL bReselect = FALSE);
  86. #endif
  87. //@@END_MSINTERNAL
  88. void PlaceCalloutMaxCorner(int nCorner, POINT point);
  89. void ConsiderAlignment(POINT point);
  90. void FinalizeAlignment() { }
  91. void SetLastLinePoint(int nPoint, POINT point, BOOL bShiftDown);
  92. void Position(POINT point);
  93. BOOL ReachedMaxLinePoints() { return m_nLinePoints >= MAX_DEVICECONTROL_LINEPOINTS; }
  94. int GetNextLinePointIndex() { return m_nLinePoints; }
  95. BOOL HasOverlay() { return m_pbmOverlay != NULL; }
  96. //@@BEGIN_MSINTERNAL
  97. #ifdef DDKBUILD
  98. void SelectOverlay();
  99. void PositionOverlay(POINT point);
  100. #endif
  101. //@@END_MSINTERNAL
  102. // population
  103. void SetObjID(DWORD dwObjID) { m_dwDeviceControlOffset = dwObjID; m_bOffsetAssigned = TRUE; }
  104. void SetLinePoints(int n, POINT *rgpt);
  105. void SetCalloutMaxRect(const RECT &r) { m_rectCalloutMax = r; CalcCallout(); }
  106. void SetAlignment(DWORD a) { m_dwCalloutAlign = a; }
  107. void SetOverlayPath(LPCTSTR tszPath);
  108. void SetOverlayRect(const RECT &r);
  109. void Init();
  110. private:
  111. // editing vars/helpers
  112. POINT m_ptFirstCorner;
  113. BOOL m_bPlacedOnlyFirstCorner;
  114. // helpers
  115. void Unpopulate();
  116. BOOL m_bInit;
  117. BOOL m_bFixed; // Whether this control is assigned an action with DIA_APPFIXED flag.
  118. DEVICEUINOTIFY m_uin;
  119. BOOL HitControl(POINT point);
  120. BOOL DrawOverlay(HDC hDC);
  121. //@@BEGIN_MSINTERNAL
  122. #ifdef DDKBUILD
  123. void ManualLoadImage(LPCTSTR);
  124. #endif
  125. //@@END_MSINTERNAL
  126. // device information
  127. DWORD m_dwDeviceControlOffset;
  128. BOOL m_bOffsetAssigned;
  129. // location/indication/visualization...
  130. // (all relative to view's origin)
  131. // overlay
  132. LPTSTR m_ptszOverlayPath;
  133. CBitmap *m_pbmOverlay;
  134. CBitmap *m_pbmHitMask;
  135. POINT m_ptOverlay;
  136. POINT m_ptHitMask;
  137. // caption (allocated and stored here)
  138. LPTSTR m_ptszCaption;
  139. BOOL m_bCaptionClipped; // Whether the caption is clipped when drawn by DrawTextEx.
  140. // coloring
  141. BOOL m_bHighlight;
  142. // line points... first connects to callout, last points to control
  143. int m_nLinePoints;
  144. POINT m_rgptLinePoint[MAX_DEVICECONTROL_LINEPOINTS];
  145. // callout specs
  146. DWORD m_dwCalloutAlign; // where the line emerges from the callout
  147. RECT m_rectCallout, m_rectCalloutMax; // current callout rect, and max rect
  148. // gdi
  149. DWORD m_dwDrawTextFlags;
  150. int m_FontHeight;
  151. void PrepFont();
  152. BOOL PrepCaption();
  153. void PrepLinePoints();
  154. void CalcCallout();
  155. void PrepCallout();
  156. BOOL m_bCalledCalcCallout;
  157. //@@BEGIN_MSINTERNAL
  158. #ifdef DDKBUILD
  159. HRESULT ExportCodeTo(FILE *);
  160. #endif
  161. //@@END_MSINTERNAL
  162. };
  163. #endif //__CDEVICECONTROL_H__
  164. #endif // FORWARD_DECLS