1
0

title.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. DEFINE_CLASS_TYPE(wintitle, "wintitle",
  29. RTGUI_TOPLEVEL_TYPE,
  30. _rtgui_wintitle_constructor,
  31. _rtgui_wintitle_deconstructor,
  32. sizeof(struct rtgui_wintitle));
  33. rtgui_wintitle_t* rtgui_wintitle_create(const char* title)
  34. {
  35. rtgui_wintitle_t* wintitle;
  36. wintitle = (rtgui_wintitle_t*)rtgui_widget_create(RTGUI_WINTITLE_TYPE);
  37. if (wintitle != RT_NULL)
  38. {
  39. rtgui_wintitle_set_title(wintitle, title);
  40. }
  41. return wintitle;
  42. }
  43. void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle)
  44. {
  45. rtgui_widget_destroy(RTGUI_WIDGET(wintitle));
  46. }
  47. void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title)
  48. {
  49. RT_ASSERT(wintitle != RT_NULL);
  50. if (wintitle->title != RT_NULL)
  51. {
  52. rtgui_free(wintitle->title);
  53. }
  54. if (title != RT_NULL) wintitle->title = (char*)rt_strdup((const char*)title);
  55. else wintitle->title = RT_NULL;
  56. }
  57. char *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle)
  58. {
  59. RT_ASSERT(wintitle != RT_NULL);
  60. return wintitle->title;
  61. }