1
0

title.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * File : title.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #include <rtgui/widgets/title.h>
  15. #include <rtgui/rtgui_system.h>
  16. /* there is no event handler in wintitle but handle the event on topwin of server */
  17. static void _rtgui_wintitle_constructor(rtgui_wintitle_t* wintitle)
  18. {
  19. wintitle->title = RT_NULL;
  20. RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT;
  21. RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(wintitle)) = RTGUI_ALIGN_CENTER_VERTICAL;
  22. }
  23. static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t* wintitle)
  24. {
  25. rt_free(wintitle->title);
  26. wintitle->title = RT_NULL;
  27. }
  28. rtgui_type_t* rtgui_wintitle_type_get()
  29. {
  30. static rtgui_type_t *wintitle_type = RT_NULL;
  31. if (!wintitle_type)
  32. {
  33. wintitle_type = rtgui_type_create("wintitle", RTGUI_TOPLEVEL_TYPE,
  34. sizeof(rtgui_wintitle_t),
  35. RTGUI_CONSTRUCTOR(_rtgui_wintitle_constructor),
  36. RTGUI_DESTRUCTOR(_rtgui_wintitle_deconstructor));
  37. }
  38. return wintitle_type;
  39. }
  40. rtgui_wintitle_t* rtgui_wintitle_create(const char* title)
  41. {
  42. rtgui_wintitle_t* wintitle;
  43. wintitle = (rtgui_wintitle_t*)rtgui_widget_create(RTGUI_WINTITLE_TYPE);
  44. if (wintitle != RT_NULL)
  45. {
  46. rtgui_wintitle_set_title(wintitle, title);
  47. }
  48. return wintitle;
  49. }
  50. void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle)
  51. {
  52. rtgui_widget_destroy(RTGUI_WIDGET(wintitle));
  53. }
  54. void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title)
  55. {
  56. RT_ASSERT(wintitle != RT_NULL);
  57. if (wintitle->title != RT_NULL)
  58. {
  59. rtgui_free(wintitle->title);
  60. }
  61. if (title != RT_NULL) wintitle->title = (char*)rt_strdup((const char*)title);
  62. else wintitle->title = RT_NULL;
  63. }
  64. char *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle)
  65. {
  66. RT_ASSERT(wintitle != RT_NULL);
  67. return wintitle->title;
  68. }