notebook.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. #include <rtgui/dc.h>
  2. #include <rtgui/rtgui.h>
  3. #include <rtgui/rtgui_system.h>
  4. #include <rtgui/widgets/notebook.h>
  5. #include <rtgui/widgets/window.h>
  6. #include <rtgui/image.h>
  7. #define RTGUI_NOTEBOOK_TAB_DEFAULT_WIDTH 80
  8. #define RTGUI_NOTEBOOK_TAB_DEFAULT_HEIGHT 25
  9. struct rtgui_notebook_tab
  10. {
  11. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  12. struct rtgui_image *pressed_image;
  13. struct rtgui_image *unpressed_image;
  14. #endif
  15. struct rtgui_widget *widget;
  16. char *title;
  17. };
  18. static void _rtgui_notebook_get_bar_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect);
  19. static void _rtgui_notebook_get_page_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect);
  20. static void _rtgui_notebook_constructor(struct rtgui_notebook *notebook)
  21. {
  22. notebook->flag = 0;
  23. notebook->childs = RT_NULL;
  24. notebook->count = 0;
  25. notebook->current = 0;
  26. notebook->tab_h = RTGUI_NOTEBOOK_TAB_DEFAULT_HEIGHT;
  27. notebook->tab_w = RTGUI_NOTEBOOK_TAB_DEFAULT_WIDTH;
  28. RTGUI_WIDGET(notebook)->gc.textalign = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
  29. rtgui_object_set_event_handler(RTGUI_OBJECT(notebook), rtgui_notebook_event_handler);
  30. }
  31. static void _rtgui_notebook_destructor(struct rtgui_notebook *notebook)
  32. {
  33. int index;
  34. if (notebook->childs != RT_NULL)
  35. {
  36. for (index = 0; index < notebook->count; index ++)
  37. {
  38. rtgui_widget_destroy(notebook->childs[index].widget);
  39. rt_free(notebook->childs[index].title);
  40. }
  41. rtgui_free(notebook->childs);
  42. }
  43. }
  44. DEFINE_CLASS_TYPE(notebook, "notebook",
  45. RTGUI_WIDGET_TYPE,
  46. _rtgui_notebook_constructor,
  47. _rtgui_notebook_destructor,
  48. sizeof(struct rtgui_notebook));
  49. /* Draw tab bars of @param notebook. @param dc should be initialized and
  50. * finished outside this function. Don't pass @param notebook or @param dc as
  51. * RT_NULL, it should be checked outside.
  52. */
  53. static void _rtgui_notebook_draw_bar(struct rtgui_notebook *notebook,
  54. struct rtgui_dc *dc)
  55. {
  56. int index;
  57. struct rtgui_rect rect;
  58. struct rtgui_rect text_rect;
  59. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  60. struct rtgui_image *image = RT_NULL;
  61. struct rtgui_rect image_rect;
  62. #endif
  63. RT_ASSERT((notebook != RT_NULL) && (dc != RT_NULL));
  64. if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
  65. return;
  66. _rtgui_notebook_get_bar_rect(notebook, &rect);
  67. rtgui_dc_fill_rect(dc, &rect);
  68. if (notebook->flag == RTGUI_NOTEBOOK_TOP ||
  69. notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
  70. {
  71. rect.x2 = rect.x1 + notebook->tab_w;
  72. /* draw tab bar */
  73. for (index = 0; index < notebook->count; index++)
  74. {
  75. if (notebook->current == index)
  76. {
  77. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  78. if (notebook->childs[index].pressed_image != RT_NULL)
  79. image = notebook->childs[index].pressed_image;
  80. else
  81. #endif
  82. rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
  83. }
  84. else
  85. {
  86. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  87. if (notebook->childs[index].unpressed_image != RT_NULL)
  88. image = notebook->childs[index].unpressed_image;
  89. else
  90. #endif
  91. rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
  92. }
  93. rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook),
  94. notebook->childs[index].title, &text_rect);
  95. rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
  96. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  97. if (image != RT_NULL)
  98. {
  99. image_rect.x1 = 0;
  100. image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
  101. image_rect.x2 = image_rect.x1 + image->w;
  102. image_rect.y2 = image_rect.y1 + image->h;
  103. rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
  104. rtgui_image_blit(image, dc, &image_rect);
  105. }
  106. if (image != RT_NULL)
  107. {
  108. int text_height = text_rect.y2 - text_rect.y1;
  109. text_rect.y1 = image_rect.y2 + RTGUI_WIDGET_DEFAULT_MARGIN;
  110. text_rect.y2 = text_rect.y1 + text_height;
  111. }
  112. image = RT_NULL;
  113. #endif
  114. rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);
  115. /* move to next tab */
  116. rect.x1 = rect.x2;
  117. rect.x2 = rect.x1 + notebook->tab_w;
  118. }
  119. }
  120. else
  121. {
  122. rect.y2 = rect.y1 + notebook->tab_h;
  123. /* draw tab bar */
  124. for (index = 0; index < notebook->count; index++)
  125. {
  126. if (notebook->current == index)
  127. {
  128. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  129. if (notebook->childs[index].pressed_image != RT_NULL)
  130. image = notebook->childs[index].pressed_image;
  131. else
  132. #endif
  133. rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
  134. }
  135. else
  136. {
  137. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  138. if (notebook->childs[index].unpressed_image != RT_NULL)
  139. image = notebook->childs[index].unpressed_image;
  140. else
  141. #endif
  142. rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
  143. }
  144. rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook),
  145. notebook->childs[index].title, &text_rect);
  146. rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
  147. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  148. if (image != RT_NULL)
  149. {
  150. image_rect.x1 = 0;
  151. image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
  152. image_rect.x2 = image->w;
  153. image_rect.y2 = image_rect.y1 + image->h;
  154. rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
  155. rtgui_image_blit(image, dc, &image_rect);
  156. }
  157. if (image != RT_NULL)
  158. {
  159. int text_height = text_rect.y2 - text_rect.y1;
  160. text_rect.y1 = image_rect.y2 + RTGUI_WIDGET_DEFAULT_MARGIN;
  161. text_rect.y2 = text_rect.y1 + text_height;
  162. }
  163. image = RT_NULL;
  164. #endif
  165. rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);
  166. /* move to next tab */
  167. rect.y1 = rect.y2;
  168. rect.y2 = rect.y1 + notebook->tab_h;
  169. }
  170. }
  171. }
  172. static void _rtgui_notebook_ondraw(struct rtgui_notebook *notebook)
  173. {
  174. struct rtgui_dc *dc;
  175. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
  176. if (dc == RT_NULL) return;
  177. if (notebook->count == 0)
  178. {
  179. rtgui_rect_t rect;
  180. rtgui_widget_get_rect(RTGUI_WIDGET(notebook), &rect);
  181. rtgui_dc_fill_rect(dc, &rect);
  182. }
  183. else
  184. {
  185. if (notebook->current == RTGUI_NOT_FOUND)
  186. notebook->current = 0;
  187. _rtgui_notebook_draw_bar(notebook, dc);
  188. /* draw current tab */
  189. rtgui_widget_update(notebook->childs[notebook->current].widget);
  190. }
  191. rtgui_dc_end_drawing(dc);
  192. }
  193. static void _rtgui_notebook_onmouse(struct rtgui_notebook *notebook, struct rtgui_event_mouse *emouse)
  194. {
  195. rtgui_rect_t rect;
  196. /* handle notebook bar */
  197. _rtgui_notebook_get_bar_rect(notebook, &rect);
  198. rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
  199. if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
  200. {
  201. int index;
  202. struct rtgui_dc *dc;
  203. if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM || notebook->flag == RTGUI_NOTEBOOK_TOP)
  204. {
  205. index = (emouse->x - rect.x1) / notebook->tab_w;
  206. if (index < notebook->count && index != notebook->current)
  207. {
  208. /* update tab bar */
  209. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
  210. if (dc == RT_NULL) return;
  211. rtgui_notebook_set_current_by_index(notebook, index);
  212. _rtgui_notebook_draw_bar(notebook, dc);
  213. rtgui_dc_end_drawing(dc);
  214. }
  215. }
  216. else
  217. {
  218. index = (emouse->y - rect.y1) / notebook->tab_h;
  219. if (index < notebook->count && index != notebook->current)
  220. {
  221. /* update tab bar */
  222. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
  223. if (dc == RT_NULL) return;
  224. rtgui_notebook_set_current_by_index(notebook, index);
  225. _rtgui_notebook_draw_bar(notebook, dc);
  226. rtgui_dc_end_drawing(dc);
  227. }
  228. }
  229. }
  230. else
  231. {
  232. /* handle on page */
  233. if (RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler != RT_NULL)
  234. RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler(
  235. RTGUI_OBJECT(notebook->childs[notebook->current].widget),
  236. &(emouse->parent));
  237. }
  238. }
  239. static void _rtgui_notebook_get_page_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect)
  240. {
  241. struct rtgui_rect tab_rect;
  242. RT_ASSERT(notebook != RT_NULL);
  243. RT_ASSERT(rect != RT_NULL);
  244. _rtgui_notebook_get_bar_rect(notebook, &tab_rect);
  245. rtgui_widget_get_rect(RTGUI_WIDGET(notebook), rect);
  246. if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
  247. return;
  248. else if (notebook->flag == RTGUI_NOTEBOOK_TOP)
  249. {
  250. rect->y1 = tab_rect.y2;
  251. }
  252. else if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
  253. {
  254. rect->y2 = tab_rect.y1;
  255. }
  256. else if (notebook->flag == RTGUI_NOTEBOOK_LEFT)
  257. {
  258. rect->x1 = tab_rect.x2;
  259. }
  260. else if (notebook->flag == RTGUI_NOTEBOOK_RIGHT)
  261. {
  262. rect->x2 = tab_rect.x1;
  263. }
  264. }
  265. static void _rtgui_notebook_get_bar_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect)
  266. {
  267. RT_ASSERT(notebook != RT_NULL);
  268. RT_ASSERT(rect != RT_NULL);
  269. rtgui_widget_get_rect(RTGUI_WIDGET(notebook), rect);
  270. if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
  271. {
  272. rect->x1 = rect->y1 = rect->x2 = rect->y2 = 0;
  273. }
  274. else if (notebook->flag == RTGUI_NOTEBOOK_TOP)
  275. {
  276. rect->y2 = rect->y1 + notebook->tab_h;
  277. }
  278. else if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
  279. {
  280. rect->y1 = rect->y2 - notebook->tab_h;
  281. }
  282. else if (notebook->flag == RTGUI_NOTEBOOK_LEFT)
  283. {
  284. rect->x2 = rect->x1 + notebook->tab_w;
  285. }
  286. else if (notebook->flag == RTGUI_NOTEBOOK_RIGHT)
  287. {
  288. rect->x1 = rect->x2 - notebook->tab_w;
  289. }
  290. }
  291. struct rtgui_notebook *rtgui_notebook_create(const rtgui_rect_t *rect, rt_uint8_t style)
  292. {
  293. struct rtgui_notebook *notebook;
  294. notebook = (struct rtgui_notebook *) rtgui_widget_create(RTGUI_NOTEBOOK_TYPE);
  295. if (notebook != RT_NULL)
  296. {
  297. notebook->flag = style;
  298. rtgui_widget_set_rect(RTGUI_WIDGET(notebook), rect);
  299. }
  300. return notebook;
  301. }
  302. void rtgui_notebook_destroy(struct rtgui_notebook *notebook)
  303. {
  304. rtgui_widget_destroy(RTGUI_WIDGET(notebook));
  305. }
  306. void rtgui_notebook_add(struct rtgui_notebook *notebook, const char *label, struct rtgui_widget *child)
  307. {
  308. rtgui_rect_t rect;
  309. RT_ASSERT(notebook != RT_NULL);
  310. notebook->count += 1;
  311. notebook->childs = (struct rtgui_notebook_tab *)
  312. rtgui_realloc(notebook->childs,
  313. sizeof(struct rtgui_notebook_tab) * notebook->count);
  314. notebook->childs[notebook->count - 1].title = rt_strdup(label);
  315. notebook->childs[notebook->count - 1].widget = child;
  316. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  317. notebook->childs[notebook->count - 1].pressed_image = RT_NULL;
  318. notebook->childs[notebook->count - 1].unpressed_image = RT_NULL;
  319. #endif
  320. /* set parent */
  321. rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));
  322. if (notebook->count - 1 != notebook->current)
  323. rtgui_widget_hide(child);
  324. _rtgui_notebook_get_page_rect(notebook, &rect);
  325. rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
  326. rtgui_widget_set_rect(child, &rect);
  327. if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
  328. RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
  329. {
  330. struct rtgui_event_update_toplvl eup;
  331. RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
  332. eup.toplvl = RTGUI_WIDGET(notebook)->toplevel;
  333. if (RTGUI_OBJECT(child)->event_handler)
  334. RTGUI_OBJECT(child)->event_handler(RTGUI_OBJECT(child), (struct rtgui_event *)&eup);
  335. }
  336. }
  337. #ifdef RTGUI_USING_NOTEBOOK_IMAGE
  338. void rtgui_notebook_add_image(struct rtgui_notebook *notebook, const char *label, struct rtgui_widget *child,
  339. struct rtgui_image *pressed_image, struct rtgui_image *unpressed_image)
  340. {
  341. rtgui_rect_t rect;
  342. RT_ASSERT(notebook != RT_NULL);
  343. notebook->count += 1;
  344. notebook->childs = (struct rtgui_notebook_tab *)
  345. rtgui_realloc(notebook->childs,
  346. sizeof(struct rtgui_notebook_tab) * notebook->count);
  347. notebook->childs[notebook->count - 1].title = rt_strdup(label);
  348. notebook->childs[notebook->count - 1].widget = child;
  349. notebook->childs[notebook->count - 1].pressed_image = pressed_image;
  350. notebook->childs[notebook->count - 1].unpressed_image = unpressed_image;
  351. /* set parent */
  352. rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));
  353. _rtgui_notebook_get_page_rect(notebook, &rect);
  354. rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
  355. rtgui_widget_set_rect(child, &rect);
  356. if (notebook->count - 1 != notebook->current)
  357. rtgui_widget_hide(child);
  358. if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
  359. RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
  360. {
  361. struct rtgui_event_update_toplvl eup;
  362. RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
  363. eup.toplvl = RTGUI_WIDGET(notebook)->toplevel;
  364. if (RTGUI_OBJECT(child)->event_handler)
  365. RTGUI_OBJECT(child)->event_handler(RTGUI_OBJECT(child), (struct rtgui_event *)&eup);
  366. }
  367. return;
  368. }
  369. #endif
  370. void rtgui_notebook_remove(struct rtgui_notebook *notebook, rt_uint16_t index)
  371. {
  372. struct rtgui_notebook_tab tab;
  373. rt_bool_t need_update = RT_FALSE;
  374. RT_ASSERT(notebook != RT_NULL);
  375. if (index < notebook->count)
  376. {
  377. if (notebook->count == 1)
  378. {
  379. tab = notebook->childs[0];
  380. rtgui_free(notebook->childs);
  381. notebook->childs = RT_NULL;
  382. notebook->count = 0;
  383. }
  384. else
  385. {
  386. if (notebook->current == index)
  387. need_update = RT_TRUE;
  388. tab = notebook->childs[index];
  389. for (; index < notebook->count - 1; index++)
  390. {
  391. notebook->childs[index] = notebook->childs[index + 1];
  392. }
  393. notebook->count -= 1;
  394. notebook->childs = (struct rtgui_notebook_tab *) rtgui_realloc(notebook->childs,
  395. sizeof(struct rtgui_notebook_tab) * notebook->count);
  396. }
  397. rt_free(tab.title);
  398. if (need_update)
  399. {
  400. if (notebook->current > notebook->count - 1)
  401. notebook->current = notebook->count - 1;
  402. rtgui_widget_hide(tab.widget);
  403. rtgui_widget_show(notebook->childs[notebook->current].widget);
  404. rtgui_widget_update(RTGUI_WIDGET(notebook));
  405. rtgui_widget_set_parent(tab.widget, RT_NULL);
  406. }
  407. }
  408. }
  409. int rtgui_notebook_get_count(struct rtgui_notebook *notebook)
  410. {
  411. RT_ASSERT(notebook != RT_NULL);
  412. return notebook->count;
  413. }
  414. void rtgui_notebook_get_client_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect)
  415. {
  416. _rtgui_notebook_get_page_rect(notebook, rect);
  417. rtgui_rect_moveto(rect, 0, 0);
  418. }
  419. struct rtgui_widget *rtgui_notebook_get_current(struct rtgui_notebook *notebook)
  420. {
  421. RT_ASSERT(notebook != RT_NULL);
  422. if (notebook->current != RTGUI_NOT_FOUND)
  423. return notebook->childs[notebook->current].widget;
  424. return RT_NULL;
  425. }
  426. rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook *notebook)
  427. {
  428. RT_ASSERT(notebook != RT_NULL);
  429. return notebook->current;
  430. }
  431. void rtgui_notebook_set_current(struct rtgui_notebook *notebook, struct rtgui_widget *widget)
  432. {
  433. rt_int16_t index;
  434. RT_ASSERT(notebook != RT_NULL);
  435. for (index = 0; index < notebook->count; index ++)
  436. {
  437. if (widget == notebook->childs[index].widget)
  438. {
  439. rtgui_notebook_set_current_by_index(notebook, index);
  440. return;
  441. }
  442. }
  443. }
  444. void rtgui_notebook_set_current_by_index(struct rtgui_notebook *notebook, rt_uint16_t index)
  445. {
  446. RT_ASSERT(notebook != RT_NULL);
  447. if ((index < notebook->count) && (notebook->current != index))
  448. {
  449. struct rtgui_widget *widget;
  450. if (notebook->current != RTGUI_NOT_FOUND)
  451. rtgui_widget_hide(notebook->childs[notebook->current].widget);
  452. notebook->current = index;
  453. widget = notebook->childs[notebook->current].widget;
  454. rtgui_widget_show(widget);
  455. rtgui_widget_update_clip(widget);
  456. /* the whole notebook need an update */
  457. rtgui_widget_update(RTGUI_WIDGET(notebook));
  458. rtgui_widget_focus(widget);
  459. }
  460. }
  461. struct rtgui_widget *rtgui_notebook_get_widget_at(struct rtgui_notebook *notebook, rt_uint16_t index)
  462. {
  463. RT_ASSERT(notebook != RT_NULL);
  464. if (index < notebook->count)
  465. return notebook->childs[index].widget;
  466. return RT_NULL;
  467. }
  468. static rt_bool_t _rtgui_notebook_current_widget_handle(struct rtgui_notebook *notebook,
  469. struct rtgui_event *event)
  470. {
  471. struct rtgui_widget *widget = rtgui_notebook_get_current(notebook);
  472. if (widget && widget != RTGUI_WIDGET(notebook))
  473. return RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget), event);
  474. else
  475. return RT_FALSE;
  476. }
  477. static void _rtgui_notebook_all_widget_handle(struct rtgui_notebook *notebook,
  478. struct rtgui_event *event)
  479. {
  480. struct rtgui_object *object;
  481. int i;
  482. for (i = 0; i < notebook->count; i++)
  483. {
  484. object = RTGUI_OBJECT(notebook->childs[i].widget);
  485. if (object->event_handler)
  486. object->event_handler(object, event);
  487. }
  488. }
  489. rt_bool_t rtgui_notebook_event_handler(struct rtgui_object *object, struct rtgui_event *event)
  490. {
  491. int page_index;
  492. rtgui_rect_t rect;
  493. struct rtgui_notebook *notebook;
  494. RT_ASSERT(object != RT_NULL);
  495. RT_ASSERT(event != RT_NULL);
  496. notebook = RTGUI_NOTEBOOK(object);
  497. switch (event->type)
  498. {
  499. case RTGUI_EVENT_PAINT:
  500. _rtgui_notebook_ondraw(notebook);
  501. break;
  502. case RTGUI_EVENT_MOUSE_BUTTON:
  503. _rtgui_notebook_onmouse(notebook, (struct rtgui_event_mouse *)event);
  504. break;
  505. case RTGUI_EVENT_SHOW:
  506. /* show myself */
  507. rtgui_widget_onshow(object, event);
  508. /* show the tab widget */
  509. return _rtgui_notebook_current_widget_handle(notebook, event);
  510. case RTGUI_EVENT_HIDE:
  511. /* hide myself */
  512. rtgui_widget_onhide(object, event);
  513. /* hide the tab widget */
  514. return _rtgui_notebook_current_widget_handle(notebook, event);
  515. case RTGUI_EVENT_KBD:
  516. return _rtgui_notebook_current_widget_handle(notebook, event);
  517. case RTGUI_EVENT_UPDATE_TOPLVL:
  518. /* update myself */
  519. rtgui_widget_onupdate_toplvl(object, event);
  520. /* update all the widgets in myself */
  521. _rtgui_notebook_all_widget_handle(notebook, event);
  522. return RT_FALSE;
  523. case RTGUI_EVENT_RESIZE:
  524. /* re-size page widget */
  525. _rtgui_notebook_get_page_rect(notebook, &rect);
  526. rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
  527. for (page_index = 0; page_index < notebook->count; page_index ++)
  528. {
  529. rtgui_widget_set_rect(notebook->childs[page_index].widget, &rect);
  530. }
  531. break;
  532. default:
  533. /* use parent event handler */
  534. return rtgui_widget_event_handler(object, event);
  535. }
  536. return RT_FALSE;
  537. }