appmgr.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "appmgr.h"
  2. #include <rtgui/widgets/panel.h>
  3. #include <rtgui/widgets/notebook.h>
  4. #include <rtgui/widgets/listbox.h>
  5. #include "apps_list.h"
  6. #include "block_panel.h"
  7. #include "statusbar.h"
  8. #include "xpm/home.xpm"
  9. #include "xpm/home_gray.xpm"
  10. rt_bool_t event_handler(struct rtgui_object* object, rtgui_event_t* event)
  11. {
  12. rt_bool_t result;
  13. RT_ASSERT(object != RT_NULL);
  14. RT_ASSERT(event != RT_NULL);
  15. result = RT_TRUE;
  16. switch (event->type)
  17. {
  18. case RTGUI_EVENT_APP_CREATE:
  19. case RTGUI_EVENT_APP_DESTROY:
  20. return apps_list_event_handler(object, event);
  21. default:
  22. /* invoke parent event handler */
  23. result = rtgui_app_event_handler(object, event);
  24. break;
  25. }
  26. return result;
  27. }
  28. void app_mgr_win_init(void)
  29. {
  30. struct rtgui_win* win;
  31. rtgui_rect_t rect;
  32. struct rtgui_notebook *notebook;
  33. struct rtgui_image* pressed_image;
  34. struct rtgui_image* unpressed_image;
  35. int font_size;
  36. struct block_panel* block;
  37. int angle_y;
  38. /* create main window of Application Manager */
  39. win = rtgui_mainwin_create(RT_NULL, "AppMgr", RTGUI_WIN_STYLE_MAINWIN);
  40. RTGUI_WIDGET_BACKGROUND(win) = RTGUI_RGB(241, 241, 241);
  41. /* create icon image */
  42. pressed_image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)home_xpm, sizeof(home_xpm), RT_FALSE);
  43. unpressed_image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)home_gray_xpm, sizeof(home_gray_xpm), RT_FALSE);
  44. rtgui_font_get_metrics(RTGUI_WIDGET_FONT(win), "AppMgr", &rect);
  45. font_size = rtgui_rect_height(rect);
  46. /* create notebook */
  47. rtgui_widget_get_extent(RTGUI_WIDGET(win), &rect);
  48. notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_LEFT);
  49. RTGUI_WIDGET_BACKGROUND(notebook) = RTGUI_RGB(241, 241, 241);
  50. rtgui_notebook_set_tab_height(notebook, pressed_image->h + font_size + 4 * RTGUI_WIDGET_DEFAULT_MARGIN);
  51. rtgui_notebook_set_tab_width(notebook, 80);
  52. angle_y = rect.x1;
  53. /* create navigation */
  54. block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
  55. RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
  56. #ifdef _WIN32
  57. rtgui_notebook_add_image(notebook, "Programs", RTGUI_WIDGET(block),
  58. pressed_image, unpressed_image);
  59. #endif
  60. #ifndef _WIN32
  61. program_create(RTGUI_PANEL(block));
  62. #endif
  63. angle_y += notebook->tab_h;
  64. rtgui_notebook_get_client_rect(notebook, &rect);
  65. block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
  66. RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
  67. #ifdef _WIN32
  68. rtgui_notebook_add_image(notebook, "Task", RTGUI_WIDGET(block),
  69. pressed_image, unpressed_image);
  70. #endif
  71. apps_list_create(RTGUI_PANEL(block));
  72. angle_y += notebook->tab_h;
  73. block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
  74. RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
  75. #ifdef _WIN32
  76. rtgui_notebook_add_image(notebook, "Setting", RTGUI_WIDGET(block),
  77. pressed_image, unpressed_image);
  78. #endif
  79. angle_y += notebook->tab_h;
  80. rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(notebook));
  81. rtgui_win_show(win, RT_FALSE);
  82. /* set as main window */
  83. rtgui_app_set_main_win(win);
  84. }
  85. void app_mgr_entry(void* parameter)
  86. {
  87. struct rtgui_app* application;
  88. application = rtgui_app_create(rt_thread_self(), "AppMgr");
  89. if (application != RT_NULL)
  90. {
  91. /* set as window manager */
  92. rtgui_app_set_as_wm();
  93. /* initialize status bar */
  94. statusbar_init();
  95. app_mgr_win_init();
  96. /* set our event handler */
  97. rtgui_object_set_event_handler(RTGUI_OBJECT(application),
  98. event_handler);
  99. rtgui_app_run(application);
  100. rtgui_app_destroy(application);
  101. }
  102. }
  103. void app_mgr_init(void)
  104. {
  105. rt_thread_t tid;
  106. tid = rt_thread_create("app_mgr", app_mgr_entry, RT_NULL, 4096, 20, 20);
  107. if (tid != RT_NULL)
  108. rt_thread_startup(tid);
  109. }