window.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * File : window.c
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, 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. * 2009-10-04 Bernard first version
  13. */
  14. #include <rtgui/dc.h>
  15. #include <rtgui/color.h>
  16. #include <rtgui/image.h>
  17. #include <rtgui/rtgui_system.h>
  18. #include <rtgui/widgets/window.h>
  19. #include <rtgui/widgets/button.h>
  20. #include <rtgui/widgets/workbench.h>
  21. static void _rtgui_win_constructor(rtgui_win_t *win)
  22. {
  23. /* init window attribute */
  24. win->on_activate = RT_NULL;
  25. win->on_deactivate = RT_NULL;
  26. win->on_close = RT_NULL;
  27. win->title = RT_NULL;
  28. win->modal_code = RTGUI_MODAL_OK;
  29. win->modal_widget = RT_NULL;
  30. /* set window hide */
  31. RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
  32. /* set window style */
  33. win->style = RTGUI_WIN_STYLE_DEFAULT;
  34. rtgui_widget_set_event_handler(RTGUI_WIDGET(win), rtgui_win_event_handler);
  35. /* init user data */
  36. win->user_data = 0;
  37. }
  38. static void _rtgui_win_destructor(rtgui_win_t* win)
  39. {
  40. struct rtgui_event_win_destroy edestroy;
  41. if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
  42. {
  43. /* destroy in server */
  44. RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy);
  45. edestroy.wid = win;
  46. if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&edestroy),
  47. sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
  48. {
  49. /* destroy in server failed */
  50. return;
  51. }
  52. }
  53. /* release field */
  54. rt_free(win->title);
  55. }
  56. static rt_bool_t _rtgui_win_create_in_server(rtgui_win_t* win)
  57. {
  58. if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
  59. {
  60. rt_thread_t server;
  61. struct rtgui_event_win_create ecreate;
  62. RTGUI_EVENT_WIN_CREATE_INIT(&ecreate);
  63. /* get server thread id */
  64. server = rtgui_thread_get_server();
  65. if (server == RT_NULL)
  66. {
  67. rt_kprintf("RTGUI server is not running...\n");
  68. return RT_FALSE;
  69. }
  70. /* send win create event to server */
  71. ecreate.wid = win;
  72. ecreate.parent.user = win->style;
  73. #ifndef RTGUI_USING_SMALL_SIZE
  74. ecreate.extent = RTGUI_WIDGET(win)->extent;
  75. rt_strncpy((char*)ecreate.title, (char*)win->title, RTGUI_NAME_MAX);
  76. #endif
  77. if (rtgui_thread_send_sync(server, RTGUI_EVENT(&ecreate),
  78. sizeof(struct rtgui_event_win_create)) != RT_EOK)
  79. {
  80. rt_kprintf("create win: %s failed\n", win->title);
  81. return RT_FALSE;
  82. }
  83. /* set server */
  84. RTGUI_TOPLEVEL(win)->server = server;
  85. }
  86. return RT_TRUE;
  87. }
  88. DEFINE_CLASS_TYPE(win, "win",
  89. RTGUI_TOPLEVEL_TYPE,
  90. _rtgui_win_constructor,
  91. _rtgui_win_destructor,
  92. sizeof(struct rtgui_win));
  93. rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title, rtgui_rect_t *rect, rt_uint8_t style)
  94. {
  95. struct rtgui_win* win;
  96. /* allocate win memory */
  97. win = (struct rtgui_win*) rtgui_widget_create (RTGUI_WIN_TYPE);
  98. if (win != RT_NULL)
  99. {
  100. /* set parent toplevel */
  101. win->parent_toplevel = parent_toplevel;
  102. /* set title, rect and style */
  103. if (title != RT_NULL) win->title = rt_strdup(title);
  104. else win->title = RT_NULL;
  105. rtgui_widget_set_rect(RTGUI_WIDGET(win), rect);
  106. win->style = style;
  107. if (_rtgui_win_create_in_server(win) == RT_FALSE)
  108. {
  109. rtgui_widget_destroy(RTGUI_WIDGET(win));
  110. return RT_NULL;
  111. }
  112. }
  113. return win;
  114. }
  115. void rtgui_win_destroy(struct rtgui_win* win)
  116. {
  117. if (win->style & RTGUI_WIN_STYLE_MODAL)
  118. {
  119. /* end modal */
  120. rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
  121. }
  122. else
  123. {
  124. rtgui_widget_destroy(RTGUI_WIDGET(win));
  125. }
  126. }
  127. void rtgui_win_close(struct rtgui_win* win)
  128. {
  129. win->style |= RTGUI_WIN_STYLE_CLOSED;
  130. }
  131. rtgui_modal_code_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
  132. {
  133. rtgui_modal_code_t result;
  134. RT_ASSERT(win != RT_NULL);
  135. result = RTGUI_MODAL_CANCEL;
  136. /* if it does not register into server, create it in server */
  137. if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
  138. {
  139. if (_rtgui_win_create_in_server(win) == RT_FALSE)
  140. return result;
  141. }
  142. if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)))
  143. {
  144. /* send show message to server */
  145. struct rtgui_event_win_show eshow;
  146. RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
  147. eshow.wid = win;
  148. if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
  149. sizeof(struct rtgui_event_win_show)) != RT_EOK)
  150. {
  151. /* hide window failed */
  152. return result;
  153. }
  154. /* set window unhidden */
  155. RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
  156. }
  157. else rtgui_widget_update(RTGUI_WIDGET(win));
  158. if (is_modal == RT_TRUE)
  159. {
  160. if (win->parent_toplevel != RT_NULL)
  161. {
  162. rtgui_widget_t *parent_widget;
  163. /* set style */
  164. win->style |= RTGUI_WIN_STYLE_MODAL;
  165. /* get root toplevel */
  166. parent_widget = RTGUI_WIDGET(win->parent_toplevel);
  167. if (RTGUI_IS_WORKBENCH(parent_widget))
  168. {
  169. rtgui_workbench_t* workbench;
  170. workbench = RTGUI_WORKBENCH(win->parent_toplevel);
  171. workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE;
  172. workbench->modal_widget = RTGUI_WIDGET(win);
  173. rtgui_workbench_event_loop(workbench);
  174. result = workbench->modal_code;
  175. workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
  176. workbench->modal_widget = RT_NULL;
  177. }
  178. else if (RTGUI_IS_WIN(parent_widget))
  179. {
  180. rtgui_win_t* parent_win;
  181. parent_win = RTGUI_WIN(win->parent_toplevel);
  182. parent_win->style |= RTGUI_WIN_STYLE_UNDER_MODAL;
  183. parent_win->modal_widget = RTGUI_WIDGET(win);
  184. rtgui_win_event_loop(parent_win);
  185. result = parent_win->modal_code;
  186. parent_win->style &= ~RTGUI_WIN_STYLE_UNDER_MODAL;
  187. parent_win->modal_widget = RT_NULL;
  188. }
  189. }
  190. else
  191. {
  192. /* which is a root window */
  193. win->style |= RTGUI_WIN_STYLE_MODAL;
  194. rtgui_win_event_loop(win);
  195. result = win->modal_code;
  196. win->style &= ~RTGUI_WIN_STYLE_MODAL;
  197. }
  198. }
  199. return result;
  200. }
  201. void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
  202. {
  203. if (win->parent_toplevel != RT_NULL)
  204. {
  205. if (RTGUI_IS_WORKBENCH(win->parent_toplevel))
  206. {
  207. rtgui_workbench_t* workbench;
  208. /* which is shown under workbench */
  209. workbench = RTGUI_WORKBENCH(win->parent_toplevel);
  210. workbench->modal_code = modal_code;
  211. workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
  212. }
  213. else if (RTGUI_IS_WIN(win->parent_toplevel))
  214. {
  215. rtgui_win_t* parent_win;
  216. /* which is shown under win */
  217. parent_win = RTGUI_WIN(win->parent_toplevel);
  218. parent_win->modal_code = modal_code;
  219. parent_win->style &= ~RTGUI_WIN_STYLE_UNDER_MODAL;
  220. }
  221. }
  222. else
  223. {
  224. /* which is a stand alone window */
  225. win->modal_code = modal_code;
  226. }
  227. /* remove modal mode */
  228. win->style &= ~RTGUI_WIN_STYLE_MODAL;
  229. }
  230. void rtgui_win_hiden(struct rtgui_win* win)
  231. {
  232. RT_ASSERT(win != RT_NULL);
  233. if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) &&
  234. RTGUI_TOPLEVEL(win)->server != RT_NULL)
  235. {
  236. /* send hidden message to server */
  237. struct rtgui_event_win_hide ehide;
  238. RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
  239. ehide.wid = win;
  240. if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&ehide),
  241. sizeof(struct rtgui_event_win_hide)) != RT_EOK)
  242. {
  243. rt_kprintf("hide win: %s failed\n", win->title);
  244. return;
  245. }
  246. /* set window hide and deactivated */
  247. RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
  248. win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
  249. }
  250. }
  251. rt_bool_t rtgui_win_is_activated(struct rtgui_win* win)
  252. {
  253. RT_ASSERT(win != RT_NULL);
  254. if (win->style & RTGUI_WIN_STYLE_ACTIVATE) return RT_TRUE;
  255. return RT_FALSE;
  256. }
  257. void rtgui_win_move(struct rtgui_win* win, int x, int y)
  258. {
  259. struct rtgui_event_win_move emove;
  260. RTGUI_EVENT_WIN_MOVE_INIT(&emove);
  261. if (win == RT_NULL) return;
  262. if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
  263. {
  264. /* set win hide firstly */
  265. RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
  266. emove.wid = win;
  267. emove.x = x;
  268. emove.y = y;
  269. if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&emove),
  270. sizeof(struct rtgui_event_win_move)) != RT_EOK)
  271. {
  272. return;
  273. }
  274. }
  275. /* move window to logic position */
  276. rtgui_widget_move_to_logic(RTGUI_WIDGET(win),
  277. x - RTGUI_WIDGET(win)->extent.x1,
  278. y - RTGUI_WIDGET(win)->extent.y1);
  279. /* set window visible */
  280. RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
  281. return;
  282. }
  283. static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win)
  284. {
  285. struct rtgui_dc* dc;
  286. struct rtgui_rect rect;
  287. struct rtgui_event_paint event;
  288. /* begin drawing */
  289. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win));
  290. if (dc == RT_NULL) return RT_FALSE;
  291. /* get window rect */
  292. rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect);
  293. /* fill area */
  294. rtgui_dc_fill_rect(dc, &rect);
  295. /* paint each widget */
  296. RTGUI_EVENT_PAINT_INIT(&event);
  297. event.wid = RT_NULL;
  298. rtgui_container_dispatch_event(RTGUI_CONTAINER(win), (rtgui_event_t*)&event);
  299. rtgui_dc_end_drawing(dc);
  300. return RT_FALSE;
  301. }
  302. rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
  303. {
  304. struct rtgui_win* win = (struct rtgui_win*)widget;
  305. RT_ASSERT((win != RT_NULL) && (event != RT_NULL));
  306. switch (event->type)
  307. {
  308. case RTGUI_EVENT_WIN_SHOW:
  309. rtgui_win_show(win, RT_FALSE);
  310. break;
  311. case RTGUI_EVENT_WIN_HIDE:
  312. rtgui_win_hiden(win);
  313. break;
  314. case RTGUI_EVENT_WIN_CLOSE:
  315. if (win->on_close != RT_NULL)
  316. {
  317. if (win->on_close(widget, event) == RT_FALSE) return RT_TRUE;
  318. }
  319. if (win->style & RTGUI_WIN_STYLE_MODAL)
  320. {
  321. rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
  322. }
  323. else
  324. {
  325. /* destroy window */
  326. rtgui_win_destroy(win);
  327. }
  328. /* exit event loop */
  329. return RT_TRUE;
  330. case RTGUI_EVENT_WIN_MOVE:
  331. {
  332. struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event;
  333. /* move window */
  334. rtgui_win_move(win, emove->x, emove->y);
  335. }
  336. break;
  337. case RTGUI_EVENT_WIN_ACTIVATE:
  338. if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)))
  339. {
  340. /* activate a hide window */
  341. return RT_TRUE;
  342. }
  343. win->style |= RTGUI_WIN_STYLE_ACTIVATE;
  344. #ifndef RTGUI_USING_SMALL_SIZE
  345. if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
  346. else
  347. #endif
  348. rtgui_widget_update(RTGUI_WIDGET(win));
  349. if (win->on_activate != RT_NULL)
  350. {
  351. win->on_activate(widget, event);
  352. }
  353. break;
  354. case RTGUI_EVENT_WIN_DEACTIVATE:
  355. if (win->style & RTGUI_WIN_STYLE_MODAL)
  356. {
  357. /* do not deactivate a modal win, re-send win-show event */
  358. struct rtgui_event_win_show eshow;
  359. RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
  360. eshow.wid = win;
  361. rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
  362. sizeof(struct rtgui_event_win_show));
  363. }
  364. else
  365. {
  366. win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
  367. #ifndef RTGUI_USING_SMALL_SIZE
  368. if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
  369. else
  370. #endif
  371. rtgui_win_ondraw(win);
  372. if (win->on_deactivate != RT_NULL)
  373. {
  374. win->on_deactivate(widget, event);
  375. }
  376. }
  377. break;
  378. case RTGUI_EVENT_PAINT:
  379. #ifndef RTGUI_USING_SMALL_SIZE
  380. if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
  381. else
  382. #endif
  383. rtgui_win_ondraw(win);
  384. break;
  385. case RTGUI_EVENT_MOUSE_BUTTON:
  386. /* check whether has widget which handled mouse event before */
  387. if (RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win) != RT_NULL)
  388. {
  389. struct rtgui_event_mouse* emouse;
  390. emouse = (struct rtgui_event_mouse*)event;
  391. RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win)->event_handler(RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win), event);
  392. if (rtgui_rect_contains_point(&(RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win)->extent),
  393. emouse->x, emouse->y) == RT_EOK)
  394. {
  395. RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win) = RT_NULL;
  396. break; /* mouse event is inside of widget, do not handle it anymore */
  397. }
  398. /* clean last mouse event handled widget */
  399. RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win) = RT_NULL;
  400. }
  401. if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL)
  402. {
  403. if (win->modal_widget != RT_NULL)
  404. return win->modal_widget->event_handler(win->modal_widget, event);
  405. }
  406. else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
  407. (struct rtgui_event_mouse*)event) == RT_FALSE)
  408. {
  409. #ifndef RTGUI_USING_SMALL_SIZE
  410. if (widget->on_mouseclick != RT_NULL)
  411. {
  412. return widget->on_mouseclick(widget, event);
  413. }
  414. #endif
  415. }
  416. break;
  417. case RTGUI_EVENT_MOUSE_MOTION:
  418. #if 0
  419. if (rtgui_widget_dispatch_mouse_event(widget,
  420. (struct rtgui_event_mouse*)event) == RT_FALSE)
  421. {
  422. #ifndef RTGUI_USING_SMALL_SIZE
  423. /* handle event in current widget */
  424. if (widget->on_mousemotion != RT_NULL)
  425. {
  426. return widget->on_mousemotion(widget, event);
  427. }
  428. #endif
  429. }
  430. else return RT_TRUE;
  431. #endif
  432. break;
  433. case RTGUI_EVENT_KBD:
  434. if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL)
  435. {
  436. if (win->modal_widget != RT_NULL)
  437. return win->modal_widget->event_handler(win->modal_widget, event);
  438. }
  439. else if (RTGUI_CONTAINER(win)->focused != widget &&
  440. RTGUI_CONTAINER(win)->focused != RT_NULL)
  441. {
  442. RTGUI_CONTAINER(win)->focused->event_handler(RTGUI_CONTAINER(win)->focused, event);
  443. }
  444. break;
  445. default:
  446. /* call parent event handler */
  447. return rtgui_toplevel_event_handler(widget, event);
  448. }
  449. return RT_FALSE;
  450. }
  451. /* windows event loop */
  452. void rtgui_win_event_loop(rtgui_win_t* wnd)
  453. {
  454. rt_err_t result;
  455. rtgui_thread_t* tid;
  456. struct rtgui_event* event;
  457. tid = rtgui_thread_self();
  458. RT_ASSERT(tid != RT_NULL);
  459. /* point to event buffer */
  460. event = (struct rtgui_event*)tid->event_buffer;
  461. if (wnd->style & RTGUI_WIN_STYLE_UNDER_MODAL)
  462. {
  463. while (wnd->style & RTGUI_WIN_STYLE_UNDER_MODAL)
  464. {
  465. if (tid->on_idle != RT_NULL)
  466. {
  467. result = rtgui_thread_recv_nosuspend(event, RTGUI_EVENT_BUFFER_SIZE);
  468. if (result == RT_EOK)
  469. {
  470. /* perform event handler */
  471. RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
  472. }
  473. else if (result == -RT_ETIMEOUT)
  474. {
  475. tid->on_idle(RTGUI_WIDGET(wnd), RT_NULL);
  476. }
  477. }
  478. else
  479. {
  480. result = rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE);
  481. if (result == RT_EOK)
  482. {
  483. /* perform event handler */
  484. RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
  485. }
  486. }
  487. }
  488. }
  489. else
  490. {
  491. while (!(wnd->style & RTGUI_WIN_STYLE_CLOSED))
  492. {
  493. if (tid->on_idle != RT_NULL)
  494. {
  495. result = rtgui_thread_recv_nosuspend(event, RTGUI_EVENT_BUFFER_SIZE);
  496. if (result == RT_EOK)
  497. {
  498. /* perform event handler */
  499. RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
  500. }
  501. else if (result == -RT_ETIMEOUT)
  502. {
  503. tid->on_idle(RTGUI_WIDGET(wnd), RT_NULL);
  504. }
  505. }
  506. else
  507. {
  508. result = rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE);
  509. if (result == RT_EOK)
  510. {
  511. /* perform event handler */
  512. RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
  513. }
  514. }
  515. }
  516. }
  517. /* destroy window */
  518. rtgui_widget_destroy(RTGUI_WIDGET(wnd));
  519. }
  520. void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
  521. {
  522. struct rtgui_event_win_resize event;
  523. if (win == RT_NULL || rect == RT_NULL) return;
  524. RTGUI_WIDGET(win)->extent = *rect;
  525. if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
  526. {
  527. /* set window resize event to server */
  528. RTGUI_EVENT_WIN_RESIZE_INIT(&event);
  529. event.wid = win;
  530. event.rect = *rect;
  531. rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, &(event.parent), sizeof(struct rtgui_event_win_resize));
  532. }
  533. }
  534. #ifndef RTGUI_USING_SMALL_SIZE
  535. void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box)
  536. {
  537. if (win == RT_NULL || box == RT_NULL) return;
  538. rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(box));
  539. rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(win)->extent));
  540. }
  541. #endif
  542. void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
  543. {
  544. if (win != RT_NULL)
  545. {
  546. win->on_activate = handler;
  547. }
  548. }
  549. void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
  550. {
  551. if (win != RT_NULL)
  552. {
  553. win->on_deactivate = handler;
  554. }
  555. }
  556. void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler)
  557. {
  558. if (win != RT_NULL)
  559. {
  560. win->on_close = handler;
  561. }
  562. }
  563. void rtgui_win_set_title(rtgui_win_t* win, const char *title)
  564. {
  565. /* send title to server */
  566. if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
  567. {
  568. }
  569. /* modify in local side */
  570. if (win->title != RT_NULL)
  571. {
  572. rtgui_free(win->title);
  573. win->title = RT_NULL;
  574. }
  575. if (title != RT_NULL)
  576. {
  577. win->title = rt_strdup(title);
  578. }
  579. }
  580. char* rtgui_win_get_title(rtgui_win_t* win)
  581. {
  582. RT_ASSERT(win != RT_NULL);
  583. return win->title;
  584. }