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.

113 lines
3.7 KiB

  1. /*
  2. * Layout
  3. */
  4. #ifndef DUI_CORE_LAYOUT_H_INCLUDED
  5. #define DUI_CORE_LAYOUT_H_INCLUDED
  6. #pragma once
  7. namespace DirectUI
  8. {
  9. // Global layout positions
  10. #define LP_None -3
  11. #define LP_Absolute -2
  12. #define LP_Auto -1
  13. ////////////////////////////////////////////////////////
  14. // Alignment enumerations
  15. #define ALIGN_LEFT 0
  16. #define ALIGN_TOP 0
  17. #define ALIGN_RIGHT 1
  18. #define ALIGN_BOTTOM 1
  19. #define ALIGN_CENTER 2
  20. #define ALIGN_JUSTIFY 3
  21. // Forward declarations
  22. class Element;
  23. typedef DynamicArray<Element*> ElementList;
  24. struct NavReference;
  25. struct NavScoring
  26. {
  27. BOOL TrackScore(Element* peTest, Element* peChild);
  28. void Init(Element* peRelative, int iNavDir, NavReference const* pnr);
  29. BOOL Try(Element* peChild, int iNavDir, NavReference const* pnr, bool fKeyableOnly);
  30. int iHighScore;
  31. Element* peWinner;
  32. private:
  33. int iBaseIndex;
  34. int iLow;
  35. int iHigh;
  36. int iMajorityScore;
  37. };
  38. /**
  39. * NOTE: Layouts are currently single context only (non-shareable). All contexts passed in to
  40. * callbacks (Element* pec) will be the same.
  41. */
  42. ////////////////////////////////////////////////////////
  43. // Base layout
  44. class Layout
  45. {
  46. public:
  47. static HRESULT Create(Layout** ppLayout);
  48. void Destroy() { HDelete<Layout>(this); }
  49. // Layout callbacks
  50. virtual void DoLayout(Element* pec, int dWidth, int dHeight);
  51. virtual SIZE UpdateDesiredSize(Element* pec, int dConstW, int dConstH, Surface* psrf);
  52. virtual void OnAdd(Element* pec, Element** ppeAdd, UINT cCount);
  53. virtual void OnRemove(Element* pec, Element** ppeRemove, UINT cCount);
  54. virtual void OnLayoutPosChanged(Element* pec, Element* peChanged, int dOldLP, int dNewLP);
  55. virtual void Attach(Element* pec);
  56. virtual void Detach(Element* pec);
  57. // Layout client query methods (omits absolute children)
  58. UINT GetLayoutChildCount(Element* pec);
  59. int GetLayoutIndexFromChild(Element* pec, Element* peChild);
  60. Element* GetChildFromLayoutIndex(Element* pec, int iLayoutIdx, ElementList* peList = NULL);
  61. virtual Element* GetAdjacent(Element* pec, Element* peFrom, int iNavDir, NavReference const* pnr, bool bKeyableOnly);
  62. Layout() { }
  63. void Initialize();
  64. virtual ~Layout();
  65. protected:
  66. static void UpdateLayoutRect(Element* pec, int cxContainer, int cyContainer, Element* peChild, int xElement, int yElement, int cxElement, int cyElement);
  67. // Dirty bit
  68. // This exists in base Layout merely as a convenience for derived Layout Managers.
  69. // Some LMs cache data during an UpdateDesiredSize call. This cached data is used
  70. // during DoLayout and is usually dependent on number of children and/or layout
  71. // position of children. This means that if UpdateDesiredSize doesn't get called
  72. // on these LMs, the cache will be invalid for the DoLayout. Since UpdateDesiredSize is
  73. // always called by LMs, you cannot assume that you will always get an UpdateDesiredSize
  74. // before a DoLayout. LMs may terminate UpdateDesiredSize passes because they
  75. // ran out of room, or couldn't make an allocation. This bit is used to mark
  76. // if a cache is valid. It is automatically invalidated in the base in the following
  77. // methods: OnAdd, OnRemove, OnLayoutPosChanged, Attach, and Detach.
  78. bool IsCacheDirty() { return _fCacheDirty; }
  79. void SetCacheDirty() { _fCacheDirty = true; }
  80. void ClearCacheDirty() { _fCacheDirty = false; }
  81. // TODO: Make shareable (supports only 1 context currently)
  82. Element* _peClient;
  83. // TODO: Multiple contexts
  84. DynamicArray<Element*>* _pdaIgnore;
  85. private:
  86. bool _fCacheDirty;
  87. };
  88. } // namespace DirectUI
  89. #endif // DUI_CORE_LAYOUT_H_INCLUDED