1
0

mv_view.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * File : mv_view.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 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-09-17 Grissiom first version
  13. */
  14. #include <rtgui/rtgui.h>
  15. #include <rtgui/rtgui_mv_model.h>
  16. #include <rtgui/widgets/mv_view.h>
  17. static void _rtgui_mv_view_constructor(struct rtgui_mv_view *view)
  18. {
  19. view->model_number = 0;
  20. view->model = RT_NULL;
  21. }
  22. static void _rtgui_mv_view_destructor(struct rtgui_mv_view *view)
  23. {
  24. if (view->model_number == 1)
  25. {
  26. rtgui_mv_model_remove_view(view->model, view);
  27. }
  28. else if (view->model_number > 1)
  29. {
  30. void **model_arr = *(void ** *)view->model;
  31. int i;
  32. for (i = 0; i < view->model_number; i++)
  33. {
  34. rtgui_mv_model_remove_view(model_arr[i], view);
  35. }
  36. }
  37. }
  38. DEFINE_CLASS_TYPE(mv_view, "mv_view",
  39. RTGUI_WIDGET_TYPE,
  40. _rtgui_mv_view_constructor,
  41. _rtgui_mv_view_destructor,
  42. sizeof(struct rtgui_mv_view));
  43. struct rtgui_mv_view *rtgui_mv_view_create(void)
  44. {
  45. return RTGUI_MV_VIEW(rtgui_widget_create(RTGUI_MV_VIEW_TYPE));
  46. }
  47. void rtgui_mv_view_destroy(struct rtgui_mv_view *view)
  48. {
  49. rtgui_widget_destroy(RTGUI_WIDGET(view));
  50. }
  51. struct rtgui_mv_model *rtgui_mv_view_foreach_in_model(struct rtgui_mv_view *view, rt_uint32_t *iter)
  52. {
  53. struct rtgui_mv_model *model;
  54. RT_ASSERT(view);
  55. if (*iter >= view->model_number)
  56. return RT_NULL;
  57. if (view->model_number == 1)
  58. {
  59. model = view->model;
  60. }
  61. else
  62. {
  63. struct rtgui_mv_model **model_array = view->model;
  64. model = model_array[*iter];
  65. }
  66. (*iter)++;
  67. return model;
  68. }