window.c 15 KB

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