title.c 1.8 KB

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