rtgui_app.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * File : rtgui_app.h
  3. * This file is part of RT-Thread GUI Engine
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2012-01-13 Grissiom first version
  23. */
  24. #ifndef __RTGUI_APP_H__
  25. #define __RTGUI_APP_H__
  26. #include <rtthread.h>
  27. #include <rtgui/rtgui.h>
  28. #include <rtgui/event.h>
  29. #include <rtgui/rtgui_system.h>
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. DECLARE_CLASS_TYPE(application);
  34. /** Gets the type of a application */
  35. #define RTGUI_APP_TYPE (RTGUI_TYPE(application))
  36. /** Casts the object to an rtgui_workbench */
  37. #define RTGUI_APP(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_APP_TYPE, struct rtgui_app))
  38. /** Checks if the object is an rtgui_workbench */
  39. #define RTGUI_IS_APP(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_APP_TYPE))
  40. enum rtgui_app_flag
  41. {
  42. RTGUI_APP_FLAG_EXITED = 0x04,
  43. RTGUI_APP_FLAG_SHOWN = 0x08,
  44. RTGUI_APP_FLAG_KEEP = 0x80,
  45. };
  46. typedef void (*rtgui_idle_func_t)(struct rtgui_object *obj, struct rtgui_event *event);
  47. struct rtgui_app
  48. {
  49. struct rtgui_object parent;
  50. /* application name */
  51. unsigned char *name;
  52. struct rtgui_image *icon;
  53. enum rtgui_app_flag state_flag;
  54. rt_uint16_t ref_count;
  55. rt_uint16_t exit_code;
  56. /* the thread id */
  57. rt_thread_t tid;
  58. /* the message queue of thread */
  59. rt_mq_t mq;
  60. /* event buffer */
  61. rt_uint8_t event_buffer[sizeof(union rtgui_event_generic)];
  62. /* if not RT_NULL, the main_object is the one will be activated when the
  63. * app recieves activate event. By default, it is the first window shown in
  64. * the app. */
  65. struct rtgui_object *main_object;
  66. /* on idle event handler */
  67. rtgui_idle_func_t on_idle;
  68. unsigned int window_cnt;
  69. void *user_data;
  70. };
  71. /**
  72. * create an application named @myname on current thread.
  73. *
  74. * @param name the name of the application
  75. *
  76. * @return a pointer to struct rtgui_app on success. RT_NULL on failure.
  77. */
  78. struct rtgui_app *rtgui_app_create(const char *name);
  79. void rtgui_app_destroy(struct rtgui_app *app);
  80. rt_bool_t rtgui_app_event_handler(struct rtgui_object *obj, rtgui_event_t *event);
  81. rt_base_t rtgui_app_run(struct rtgui_app *app);
  82. void rtgui_app_exit(struct rtgui_app *app, rt_uint16_t code);
  83. void rtgui_app_activate(struct rtgui_app *app);
  84. void rtgui_app_close(struct rtgui_app *app);
  85. void rtgui_app_sleep(struct rtgui_app *app, int millisecond);
  86. void rtgui_app_set_onidle(struct rtgui_app *app, rtgui_idle_func_t onidle);
  87. rtgui_idle_func_t rtgui_app_get_onidle(struct rtgui_app *app);
  88. /**
  89. * return the rtgui_app struct on current thread
  90. */
  91. struct rtgui_app *rtgui_app_self(void);
  92. rt_err_t rtgui_app_set_as_wm(struct rtgui_app *app);
  93. void rtgui_app_set_main_win(struct rtgui_app *app, struct rtgui_win *win);
  94. struct rtgui_win* rtgui_app_get_main_win(struct rtgui_app *app);
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* end of include guard: __RTGUI_APP_H__ */