util.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /** @file
  2. * Header file for some utility functions.
  3. *
  4. * @author mandy.wu 2010/12/06 (Add duplicate controls' core struct)
  5. * @author tzungming.lin 2009/09/28 (Control/Child scaling)
  6. * @version 0.1
  7. */
  8. #ifndef _GUIENG_UTIL
  9. #define _GUIENG_UTIL
  10. #include "gl_types.h"
  11. #include "stddefs.h"
  12. #include "datatypes.h"
  13. #include "gui_engine.h"
  14. #define GENG_SET_ALIGN(oriAlign, hAlign) oriAlign = ((oriAlign & ~FONT_ALIGN_MASK) | hAlign)
  15. #define GENG_SET_V_ALIGN(oriAlign, vAlign) oriAlign = ((oriAlign & ~FONT_V_ALIGN_MASK) | vAlign)
  16. #define CHECK_DISLIST(list,total) \
  17. if( (list) == NULL && (total) > 0 ) \
  18. { \
  19. ERROR(PRINT("%s: Disabled list is NULL\n", __FUNCTION__)); \
  20. return; \
  21. } \
  22. else if( (total) == 0 ) \
  23. return;
  24. #define BAK_REGION_INFO(sdHandle, stOriArea) \
  25. { \
  26. stOriArea = gRegionDetails[sdHandle].rect; \
  27. }
  28. #define RESTORE_REGION_INFO(sdHandle, stOriArea) \
  29. { \
  30. gRegionDetails[sdHandle].rect = stOriArea; \
  31. }
  32. /** Transparent color. */
  33. extern const Color_t gTransColor;
  34. /** icon_info_t with ICON_ID_INVALID of each state. */
  35. extern const icon_info_t gInvalidIcon;
  36. /** color_info_t with transparent color of each state. */
  37. extern const color_info_t gTransColorInfo;
  38. /** text_color_info_t with transparent color of each state. */
  39. extern const text_color_info_t gTransTextColorInfo;
  40. /**************************************************************************/
  41. /* Accessors. */
  42. /**************************************************************************/
  43. /**
  44. * Get a 4-byte-aligned width from the input image data.
  45. *
  46. * @param pstImgData Pointer to the target image data.
  47. * @return A 4 bytes aligned width for a bitmap.
  48. */
  49. UINT16 GUIENG_GetBmpAlignedWidth(const PIMAGEHDR pstImgData);
  50. /**
  51. * Get parent with type of CLASS_WINDOW or CLASS_POPUP.
  52. *
  53. * @param handle Handle of a control.
  54. * @return Pointer to the handle of parent menu/popup.
  55. */
  56. HWND GUIENG_GetParentMenu(HWND handle);
  57. /**
  58. * Get font style enum value according to the state of widget
  59. *
  60. * @param pstCtrl Control of target widget.
  61. * @param dState Specific state.
  62. * @return Font style enumeration value.
  63. */
  64. FontStyle_e GUIENG_GetFontStyle(WinControl_t *pstCtrl, UINT32 dState);
  65. /**
  66. * Get font size according to the state of widget
  67. *
  68. * @param pstCtrl Control of target widget.
  69. * @param dState Specific state.
  70. * @return Font size in pt(or pixel).
  71. */
  72. FONTSize_t GUIENG_GetFontSize(WinControl_t *pstCtrl, UINT32 dState);
  73. #define GUIENG_GetEndStyle(control) ((GET_WIDGET_STYLE(control) & S_TXT_END_MASK) >> 4)
  74. /**
  75. * Get text style.
  76. * @param pstCtrl Control of target control.
  77. * @return Text style enum value.
  78. */
  79. GEL_TextStyle_e GUIENG_GetTextStyle(WinControl_t *pstCtrl);
  80. /**
  81. * Get text style of button group or listview.
  82. * @param pstCtrl Control of target control.
  83. * @param dState Desired state of the control.
  84. * @return Text style enum value.
  85. */
  86. GEL_TextStyle_e GUIENG_GetGroupTextStyle(WinControl_t *pstCtrl, UINT32 dState);
  87. /**
  88. * Get AA information from the style of parent control.
  89. *
  90. * @param handle Handle to a control.
  91. * @param pstTextInfo Text information structure.
  92. * @return GUI_SUCCESS if succeed, error code otherwise.
  93. */
  94. GUIResult_e GUIENG_GetAAInfo(HWND handle, GENG_TextInfo_t *pstTextInfo);
  95. /**
  96. * Get font alignment(horizontal and vertical) according to the style of a widget.
  97. *
  98. * @param dStyle Common style of a widget.
  99. * @return Result alignment flag.
  100. */
  101. UINT8 GUIENG_GetFontAlign(UINT32 dCommStyle);
  102. /**************************************************************************/
  103. /* Basic drawing functions. */
  104. /**************************************************************************/
  105. /**
  106. * Draw child controls to be background extension.
  107. *
  108. * @param hdc Handle of device context.
  109. * @param handle Handle of parent control.
  110. * @param dParentState State of the parent control.
  111. */
  112. void GUIENG_DrawChildBg(HDC hdc, HWND handle, UINT32 dParentState, UINT32 parentParam);
  113. /**
  114. * Draw child controls to be the border.
  115. *
  116. * @param hdc Handle of device context.
  117. * @param handle Handle of parent control.
  118. * @param dParentState State of the parent control.
  119. */
  120. void GUIENG_DrawChildBorder(HDC hdc, HWND handle, UINT32 dParentState, UINT32 parentParam);
  121. /**
  122. * Draw the background color of the parent, not the whole widget.
  123. *
  124. * @param hdc Handle to the device context.
  125. * @param stTargetRect Rectangle of the parent.
  126. * @param stColor Color of background.
  127. */
  128. void GUIENG_FillDesignateColor(HDC hdc, RECT stTargetRect, Color_t stColor, INT32 *pBlockId);
  129. /**
  130. * Draw background icon of a widget.
  131. *
  132. * @param hdc Handle to a device context.
  133. * @param pstTargetRect Target rectangle area.
  134. * @param swIconId Icon id of background icon.
  135. * @param wSideSize Side size of background icon.
  136. * @param pDynPal Dynamic set source palette.
  137. * @param dStyle Style of this widget.
  138. */
  139. void GUIENG_DrawBgIcon(HDC hdc, PRECT pstTargetRect , INT16 swIconId,
  140. UINT16 wSideSize, PALENTRY *pDynPal, UINT32 dStyle, INT32 *pBlockId);
  141. /**************************************************************************/
  142. /* Marquee Related APIs. */
  143. /**************************************************************************/
  144. /**
  145. * Create a temp buffer to draw the prepared foreground for marquee style.
  146. *
  147. * @param hdc Handle to a device context.
  148. * @param pstControl Pointer to a WinControl_t of the control.
  149. * @return GUI_SUCCESS if succeed, error codes otherwise.
  150. */
  151. GUIResult_e GUIENG_CreateMarqueeFgBuf(HDC hdc, WinControl_t *pstControl);
  152. /**
  153. * Create a buffer to backup the background of a marquee.
  154. *
  155. * @param hdc Handle to a device context.
  156. * @param pstControl Pointer to a WinControl_t of the control.
  157. * @param pstMarqInfo Pointer to a marquee information of target control.
  158. * @param pstBgRect The background rect to be backup.
  159. * @param dControlFlags To indecate if its a region buffer rendering.
  160. * @return GUI_SUCCESS if succeed, error codes otherwise.
  161. */
  162. GUIResult_e GUIENG_CreateMarqueeBgBuf(HDC hdc, WinControl_t *pstControl, marquee_info_t *pstMarqInfo,
  163. PRECT pstBgRect, UINT32 dControlFlags);
  164. /**
  165. * Destroy the foreground buffer of animation.
  166. *
  167. * @param hdc Handle to a device context.
  168. * @param pstMarqInfo Pointer to a marquee information of target control.
  169. */
  170. void GUIENG_DestroyMarqueeFgBuf(HDC hdc, marquee_info_t *pstMarqInfo);
  171. /**
  172. * Destroy the bakcground of an animation/marquee.
  173. *
  174. * @param hdc Handle to a device context.
  175. * @param pstControl Pointer to a WinControl_t of the control.
  176. * @param pstMarqInfo Pointer to a marquee information of target control.
  177. */
  178. void GUIENG_DestroyMarqueeBgBuf(HDC hdc, WinControl_t *pstControl, marquee_info_t *pstMarqInfo);
  179. /**
  180. * Draw foreground text to perform marquee effect.
  181. *
  182. * @param hdc Handle to the device context.
  183. * @param handle Handle to the control.
  184. * @param marquee Pointer to a marquee information.
  185. * @param wTextWidth Width of area of foreground text.
  186. * @param pstBgColor Background color of the specific text position.
  187. */
  188. void GUIENG_DrawMarquee(HDC hdc, HWND handle, marquee_info_t *marquee, UINT16 wTextWidth, color_info_t *pstBgColor, INT32 *pBlockId);
  189. /**************************************************************************/
  190. /* Boolean functions. */
  191. /**************************************************************************/
  192. /**
  193. * Check if there exists transparent color in all states of the input color info
  194. *
  195. * @param eRgnFormat Region format.
  196. * @param pstColor Colors of each state.
  197. * @return TRUE if it contains transparent color, FALSE otherwise.
  198. */
  199. BOOLEAN GUIENG_ContainTransparentBg(PixelFormat_e eRgnFormat, color_info_t *pstColor);
  200. /**
  201. * Check if there exists transparent color in a prog_color_t.
  202. *
  203. * @param eRgnFormat Region format.
  204. * @param pstProgColor Colors of each state of progress bar/scroll bar.
  205. * @return TRUE if it contains transparent color, FALSE otherwise.
  206. */
  207. BOOLEAN GUIENG_ContainTransparentBarBg(PixelFormat_e eRgnFormat, prog_color_t *pstProgColor);
  208. /**
  209. * Check if input parent control has child icon or not.
  210. *
  211. * @param parent Handle of parent control
  212. * @return TRUE if it has at least one child icon, FALSE otherwise.
  213. */
  214. BOOLEAN GUIENG_HasChildIcon(HWND parent);
  215. /**
  216. * Perform height scaling only.
  217. *
  218. * @param stArea Given area that needs to be scaling.
  219. * @param control Control of a widget.
  220. * @return GUI_SUCCESS if succeed, error codes otherwise.
  221. */
  222. GUIResult_e GUIENG_HeightScaling(PRECT stArea, WinControl_t *control);
  223. /**
  224. * Perform width scaling only.
  225. *
  226. * @param stArea Given area that needs to be scaling.
  227. * @param control Control of a widget.
  228. * @return GUI_SUCCESS if succeed, error codes otherwise.
  229. */
  230. GUIResult_e GUIENG_WidthScaling(PRECT stArea, WinControl_t *control);
  231. /**
  232. * Perform area scaling.
  233. *
  234. * @param stArea Given area that needs to be scaling.
  235. * @param control Control of a widget.
  236. * @return GUI_SUCCESS if succeed, error codes otherwise.
  237. */
  238. GUIResult_e GUIENG_AreaScaling(PRECT stArea, WinControl_t *control);
  239. void gel_WaitForMsgDone(void);
  240. void gel_WaitForSelfDone(HWND pHandle);
  241. /**************************************************************************/
  242. /* Move control related functions. */
  243. /**************************************************************************/
  244. INT32 GUIENG_4Bpp_FillBmp(RECT stSrcRect, RECT stDstRect, PIMAGEHDR pstImgData, UINT8* u8OutBuffer, UINT32 u32OutBufferLen);
  245. INT32 GUIENG_4Bpp_HasSideSize_Hrepeate(RECT stSrcRect, RECT stDstRect, PIMAGEHDR pstImgData, UINT32 side, UINT8* u8OutBuffer, UINT32 u32OutBufferLen);
  246. void GUIENG_ChildScaling(HWND parent, RECT stChildPos[3]);
  247. void GUIENG_ChildRestorePos(HWND handle, RECT stChildPos[3]);
  248. INT32 text_GetHdc(HWND handle, HDC *hdc);
  249. void GUIENG_DrawFocusedStrBorder(HWND handle, TextInfo_t *pstTextInfo);
  250. void GUIENG_DrawFocusedBorder(HWND handle, RECT rect);
  251. INT32 GUIENG_SateToIndex(INT32 state);
  252. IMAGEHDR GUIENG_GetRepeatImageByID(HDC hdc, INT16 swIconId, UINT16 wSideSize, UINT32 dStyle, RECT destRect, PIMAGEHDR pTargetImage);
  253. IMAGEHDR GUIENG_GetRepeatImage(PIMAGEHDR pSrcImage, UINT16 sideSize, UINT32 dStyle, RECT destRect, PIMAGEHDR pTargetImage);
  254. #endif //#ifndef _GUIENG_UTIL