rtgui_app.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * File : rtgui_app.h
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, 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. * 2012-01-13 Grissiom first version
  13. */
  14. #ifndef __RTGUI_APP_H__
  15. #define __RTGUI_APP_H__
  16. #include <rtthread.h>
  17. #include <rtgui/rtgui.h>
  18. #include <rtgui/event.h>
  19. #include <rtgui/rtgui_system.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. DECLARE_CLASS_TYPE(application);
  24. /** Gets the type of a application */
  25. #define RTGUI_APP_TYPE (RTGUI_TYPE(application))
  26. /** Casts the object to an rtgui_workbench */
  27. #define RTGUI_APP(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_APP_TYPE, struct rtgui_app))
  28. /** Checks if the object is an rtgui_workbench */
  29. #define RTGUI_IS_APP(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_APP_TYPE))
  30. enum rtgui_app_flag
  31. {
  32. RTGUI_APP_FLAG_EXITED = 0x04,
  33. RTGUI_APP_FLAG_SHOWN = 0x08,
  34. RTGUI_APP_FLAG_KEEP = 0x80,
  35. };
  36. typedef void (*rtgui_idle_func_t)(struct rtgui_object *obj, struct rtgui_event *event);
  37. struct rtgui_app
  38. {
  39. struct rtgui_object parent;
  40. /* application name */
  41. unsigned char *name;
  42. struct rtgui_image *icon;
  43. enum rtgui_app_flag state_flag;
  44. rt_uint16_t ref_count;
  45. rt_uint16_t exit_code;
  46. /* the thread id */
  47. rt_thread_t tid;
  48. /* the message queue of thread */
  49. rt_mq_t mq;
  50. /* event buffer */
  51. rt_uint8_t event_buffer[sizeof(union rtgui_event_generic)];
  52. /* if not RT_NULL, the main_object is the one will be activated when the
  53. * app recieves activate event. By default, it is the first window shown in
  54. * the app. */
  55. struct rtgui_object *main_object;
  56. /* on idle event handler */
  57. rtgui_idle_func_t on_idle;
  58. unsigned int window_cnt;
  59. void *user_data;
  60. };
  61. /**
  62. * create an application named @myname on current thread.
  63. *
  64. * @param name the name of the application
  65. *
  66. * @return a pointer to struct rtgui_app on success. RT_NULL on failure.
  67. */
  68. struct rtgui_app *rtgui_app_create(const char *name);
  69. void rtgui_app_destroy(struct rtgui_app *app);
  70. rt_bool_t rtgui_app_event_handler(struct rtgui_object *obj, rtgui_event_t *event);
  71. rt_base_t rtgui_app_run(struct rtgui_app *app);
  72. void rtgui_app_exit(struct rtgui_app *app, rt_uint16_t code);
  73. void rtgui_app_activate(struct rtgui_app *app);
  74. void rtgui_app_close(struct rtgui_app *app);
  75. void rtgui_app_sleep(struct rtgui_app *app, int millisecond);
  76. void rtgui_app_set_onidle(struct rtgui_app *app, rtgui_idle_func_t onidle);
  77. rtgui_idle_func_t rtgui_app_get_onidle(struct rtgui_app *app);
  78. /**
  79. * return the rtgui_app struct on current thread
  80. */
  81. struct rtgui_app *rtgui_app_self(void);
  82. rt_err_t rtgui_app_set_as_wm(struct rtgui_app *app);
  83. void rtgui_app_set_main_win(struct rtgui_app *app, struct rtgui_win *win);
  84. struct rtgui_win* rtgui_app_get_main_win(struct rtgui_app *app);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif /* end of include guard: __RTGUI_APP_H__ */