window.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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/rtgui_server.h>
  19. #include <rtgui/rtgui_app.h>
  20. #include <rtgui/widgets/window.h>
  21. #include <rtgui/widgets/button.h>
  22. static void _rtgui_win_constructor(rtgui_win_t *win)
  23. {
  24. RTGUI_WIDGET(win)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
  25. win->parent_window = RT_NULL;
  26. /* init window attribute */
  27. win->on_activate = RT_NULL;
  28. win->on_deactivate = RT_NULL;
  29. win->on_close = RT_NULL;
  30. win->on_key = RT_NULL;
  31. win->title = RT_NULL;
  32. win->modal_code = RTGUI_MODAL_OK;
  33. /* initialize last mouse event handled widget */
  34. win->last_mevent_widget = RT_NULL;
  35. win->focused_widget = RT_NULL;
  36. /* set window hide */
  37. RTGUI_WIDGET_HIDE(win);
  38. /* set window style */
  39. win->style = RTGUI_WIN_STYLE_DEFAULT;
  40. win->flag = RTGUI_WIN_FLAG_INIT;
  41. rtgui_object_set_event_handler(RTGUI_OBJECT(win), rtgui_win_event_handler);
  42. /* init user data */
  43. win->user_data = 0;
  44. }
  45. static void _rtgui_win_destructor(rtgui_win_t* win)
  46. {
  47. struct rtgui_event_win_destroy edestroy;
  48. if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
  49. {
  50. /* destroy in server */
  51. RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy);
  52. edestroy.wid = win;
  53. if (rtgui_server_post_event_sync(RTGUI_EVENT(&edestroy),
  54. sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
  55. {
  56. /* destroy in server failed */
  57. return;
  58. }
  59. }
  60. /* release field */
  61. if (win->title != RT_NULL)
  62. rt_free(win->title);
  63. }
  64. static rt_bool_t _rtgui_win_create_in_server(struct rtgui_win *win)
  65. {
  66. if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
  67. {
  68. struct rtgui_event_win_create ecreate;
  69. RTGUI_EVENT_WIN_CREATE_INIT(&ecreate);
  70. /* send win create event to server */
  71. ecreate.parent_window = win->parent_window;
  72. ecreate.wid = win;
  73. ecreate.parent.user = win->style;
  74. #ifndef RTGUI_USING_SMALL_SIZE
  75. ecreate.extent = RTGUI_WIDGET(win)->extent;
  76. rt_strncpy((char*)ecreate.title, (char*)win->title, RTGUI_NAME_MAX);
  77. #endif
  78. if (rtgui_server_post_event_sync(RTGUI_EVENT(&ecreate),
  79. sizeof(struct rtgui_event_win_create)
  80. ) != RT_EOK)
  81. {
  82. rt_kprintf("create win: %s failed\n", win->title);
  83. return RT_FALSE;
  84. }
  85. win->flag |= RTGUI_WIN_FLAG_CONNECTED;
  86. }
  87. return RT_TRUE;
  88. }
  89. DEFINE_CLASS_TYPE(win, "win",
  90. RTGUI_TOPLEVEL_TYPE,
  91. _rtgui_win_constructor,
  92. _rtgui_win_destructor,
  93. sizeof(struct rtgui_win));
  94. rtgui_win_t* rtgui_win_create(struct rtgui_win* parent_window,
  95. const char* title,
  96. rtgui_rect_t *rect,
  97. rt_uint16_t style)
  98. {
  99. struct rtgui_win* win;
  100. /* allocate win memory */
  101. win = RTGUI_WIN(rtgui_widget_create(RTGUI_WIN_TYPE));
  102. if (win == RT_NULL)
  103. return RT_NULL;
  104. /* set parent toplevel */
  105. win->parent_window = parent_window;
  106. /* set title, rect and style */
  107. if (title != RT_NULL)
  108. win->title = rt_strdup(title);
  109. else
  110. win->title = RT_NULL;
  111. rtgui_widget_set_rect(RTGUI_WIDGET(win), rect);
  112. win->style = style;
  113. if (_rtgui_win_create_in_server(win) == RT_FALSE)
  114. {
  115. goto __on_err;
  116. }
  117. return win;
  118. __on_err:
  119. rtgui_widget_destroy(RTGUI_WIDGET(win));
  120. return RT_NULL;
  121. }
  122. RTM_EXPORT(rtgui_win_create);
  123. rtgui_win_t* rtgui_mainwin_create(struct rtgui_win *parent_window, const char* title, rt_uint16_t style)
  124. {
  125. struct rtgui_rect rect;
  126. /* get rect of main window */
  127. rtgui_get_mainwin_rect(&rect);
  128. return rtgui_win_create(parent_window, title, &rect, style);
  129. }
  130. RTM_EXPORT(rtgui_mainwin_create);
  131. static rt_bool_t _rtgui_win_deal_close(struct rtgui_win *win,
  132. struct rtgui_event *event,
  133. rt_bool_t force_close)
  134. {
  135. if (win->on_close != RT_NULL)
  136. {
  137. if ((win->on_close(RTGUI_OBJECT(win), event) == RT_FALSE) && !force_close)
  138. return RT_FALSE;
  139. }
  140. rtgui_win_hiden(win);
  141. win->flag |= RTGUI_WIN_FLAG_CLOSED;
  142. if (win->flag & RTGUI_WIN_FLAG_MODAL)
  143. {
  144. rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
  145. }
  146. else if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
  147. {
  148. rtgui_win_destroy(win);
  149. }
  150. return RT_TRUE;
  151. }
  152. void rtgui_win_destroy(struct rtgui_win* win)
  153. {
  154. /* close the window first if it's not. */
  155. if (!(win->flag & RTGUI_WIN_FLAG_CLOSED))
  156. {
  157. struct rtgui_event_win_close eclose;
  158. RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
  159. eclose.wid = win;
  160. if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
  161. {
  162. _rtgui_win_deal_close(win,
  163. (struct rtgui_event*)&eclose,
  164. RT_TRUE);
  165. return;
  166. }
  167. else
  168. _rtgui_win_deal_close(win,
  169. (struct rtgui_event*)&eclose,
  170. RT_TRUE);
  171. }
  172. if (win->flag & RTGUI_WIN_FLAG_MODAL)
  173. {
  174. /* set the RTGUI_WIN_STYLE_DESTROY_ON_CLOSE flag so the window will be
  175. * destroyed after the event_loop */
  176. win->style |= RTGUI_WIN_STYLE_DESTROY_ON_CLOSE;
  177. rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
  178. }
  179. else
  180. {
  181. rtgui_widget_destroy(RTGUI_WIDGET(win));
  182. }
  183. }
  184. RTM_EXPORT(rtgui_win_destroy);
  185. /* send a close event to myself to get a consistent behavior */
  186. rt_bool_t rtgui_win_close(struct rtgui_win* win)
  187. {
  188. struct rtgui_event_win_close eclose;
  189. RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
  190. eclose.wid = win;
  191. return _rtgui_win_deal_close(win,
  192. (struct rtgui_event*)&eclose,
  193. RT_FALSE);
  194. }
  195. RTM_EXPORT(rtgui_win_close);
  196. rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
  197. {
  198. rt_base_t exit_code = -1;
  199. struct rtgui_app *app;
  200. struct rtgui_event_win_show eshow;
  201. app = rtgui_app_self();
  202. RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
  203. eshow.wid = win;
  204. if (win == RT_NULL)
  205. return exit_code;
  206. /* if it does not register into server, create it in server */
  207. if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
  208. {
  209. if (_rtgui_win_create_in_server(win) == RT_FALSE)
  210. return exit_code;
  211. }
  212. /* set window unhidden before notify the server */
  213. rtgui_widget_show(RTGUI_WIDGET(win));
  214. if (rtgui_server_post_event_sync(RTGUI_EVENT(&eshow),
  215. sizeof(struct rtgui_event_win_show)) != RT_EOK)
  216. {
  217. /* It could not be shown if a parent window is hidden. */
  218. rtgui_widget_hide(RTGUI_WIDGET(win));
  219. return exit_code;
  220. }
  221. if (win->focused_widget == RT_NULL)
  222. rtgui_widget_focus(RTGUI_WIDGET(win));
  223. /* set main window */
  224. if (app->main_object == RT_NULL)
  225. rtgui_app_set_main_win(win);
  226. if (is_modal == RT_TRUE)
  227. {
  228. struct rtgui_app *app;
  229. struct rtgui_event_win_modal_enter emodal;
  230. RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal);
  231. emodal.wid = win;
  232. app = rtgui_app_self();
  233. RT_ASSERT(app != RT_NULL);
  234. win->flag |= RTGUI_WIN_FLAG_MODAL;
  235. if (rtgui_server_post_event_sync((struct rtgui_event*)&emodal,
  236. sizeof(emodal)) != RT_EOK)
  237. return exit_code;
  238. app->modal_object = RTGUI_OBJECT(win);
  239. exit_code = rtgui_app_run(app);
  240. app->modal_object = RT_NULL;
  241. win->flag &= ~RTGUI_WIN_FLAG_MODAL;
  242. if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
  243. {
  244. rtgui_win_destroy(win);
  245. }
  246. }
  247. return exit_code;
  248. }
  249. RTM_EXPORT(rtgui_win_show);
  250. void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
  251. {
  252. if (win == RT_NULL || !(win->flag & RTGUI_WIN_FLAG_MODAL))
  253. return;
  254. rtgui_app_exit(rtgui_app_self(), modal_code);
  255. /* remove modal mode */
  256. win->flag &= ~RTGUI_WIN_FLAG_MODAL;
  257. }
  258. RTM_EXPORT(rtgui_win_end_modal);
  259. void rtgui_win_hiden(struct rtgui_win* win)
  260. {
  261. RT_ASSERT(win != RT_NULL);
  262. if (!RTGUI_WIDGET_IS_HIDE(win) &&
  263. win->flag & RTGUI_WIN_FLAG_CONNECTED)
  264. {
  265. /* send hidden message to server */
  266. struct rtgui_event_win_hide ehide;
  267. RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
  268. ehide.wid = win;
  269. if (rtgui_server_post_event_sync(RTGUI_EVENT(&ehide),
  270. sizeof(struct rtgui_event_win_hide)) != RT_EOK)
  271. {
  272. rt_kprintf("hide win: %s failed\n", win->title);
  273. return;
  274. }
  275. rtgui_widget_hide(RTGUI_WIDGET(win));
  276. win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
  277. }
  278. }
  279. RTM_EXPORT(rtgui_win_hiden);
  280. rt_err_t rtgui_win_activate(struct rtgui_win *win)
  281. {
  282. struct rtgui_event_win_activate eact;
  283. RTGUI_EVENT_WIN_ACTIVATE_INIT(&eact);
  284. eact.wid = win;
  285. return rtgui_server_post_event_sync(RTGUI_EVENT(&eact),
  286. sizeof(eact));
  287. }
  288. RTM_EXPORT(rtgui_win_activate);
  289. rt_bool_t rtgui_win_is_activated(struct rtgui_win* win)
  290. {
  291. RT_ASSERT(win != RT_NULL);
  292. if (win->flag & RTGUI_WIN_FLAG_ACTIVATE) return RT_TRUE;
  293. return RT_FALSE;
  294. }
  295. RTM_EXPORT(rtgui_win_is_activated);
  296. void rtgui_win_move(struct rtgui_win* win, int x, int y)
  297. {
  298. struct rtgui_event_win_move emove;
  299. RTGUI_EVENT_WIN_MOVE_INIT(&emove);
  300. if (win == RT_NULL)
  301. return;
  302. /* move window to logic position */
  303. rtgui_widget_move_to_logic(RTGUI_WIDGET(win),
  304. x - RTGUI_WIDGET(win)->extent.x1,
  305. y - RTGUI_WIDGET(win)->extent.y1);
  306. if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
  307. {
  308. /* set win hide firstly */
  309. rtgui_widget_hide(RTGUI_WIDGET(win));
  310. emove.wid = win;
  311. emove.x = x;
  312. emove.y = y;
  313. if (rtgui_server_post_event_sync(RTGUI_EVENT(&emove),
  314. sizeof(struct rtgui_event_win_move)) != RT_EOK)
  315. {
  316. return;
  317. }
  318. }
  319. /* set window visible */
  320. rtgui_widget_show(RTGUI_WIDGET(win));
  321. return;
  322. }
  323. RTM_EXPORT(rtgui_win_move);
  324. static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win)
  325. {
  326. struct rtgui_dc* dc;
  327. struct rtgui_rect rect;
  328. struct rtgui_event_paint event;
  329. /* begin drawing */
  330. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win));
  331. if (dc == RT_NULL)
  332. return RT_FALSE;
  333. /* get window rect */
  334. rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect);
  335. /* fill area */
  336. rtgui_dc_fill_rect(dc, &rect);
  337. /* paint each widget */
  338. RTGUI_EVENT_PAINT_INIT(&event);
  339. event.wid = RT_NULL;
  340. rtgui_container_dispatch_event(RTGUI_CONTAINER(win),
  341. (rtgui_event_t*)&event);
  342. rtgui_dc_end_drawing(dc);
  343. return RT_FALSE;
  344. }
  345. rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_event* event)
  346. {
  347. struct rtgui_win* win;
  348. RT_ASSERT(object != RT_NULL);
  349. RT_ASSERT(event != RT_NULL);
  350. win = RTGUI_WIN(object);
  351. switch (event->type)
  352. {
  353. case RTGUI_EVENT_WIN_SHOW:
  354. rtgui_win_show(win, RT_FALSE);
  355. break;
  356. case RTGUI_EVENT_WIN_HIDE:
  357. rtgui_win_hiden(win);
  358. break;
  359. case RTGUI_EVENT_WIN_CLOSE:
  360. _rtgui_win_deal_close(win, event, RT_FALSE);
  361. /* don't broadcast WIN_CLOSE event to others */
  362. return RT_TRUE;
  363. case RTGUI_EVENT_WIN_MOVE:
  364. {
  365. struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event;
  366. /* move window */
  367. rtgui_win_move(win, emove->x, emove->y);
  368. }
  369. break;
  370. case RTGUI_EVENT_WIN_ACTIVATE:
  371. if (RTGUI_WIDGET_IS_HIDE(win))
  372. {
  373. /* activate a hide window */
  374. return RT_TRUE;
  375. }
  376. win->flag |= RTGUI_WIN_FLAG_ACTIVATE;
  377. #ifndef RTGUI_USING_SMALL_SIZE
  378. if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
  379. RTGUI_WIDGET(object)->on_draw(object, event);
  380. else
  381. #endif
  382. rtgui_widget_update(RTGUI_WIDGET(win));
  383. if (win->on_activate != RT_NULL)
  384. {
  385. win->on_activate(RTGUI_OBJECT(object), event);
  386. }
  387. break;
  388. case RTGUI_EVENT_WIN_DEACTIVATE:
  389. if (win->flag & RTGUI_WIN_FLAG_MODAL)
  390. {
  391. /* FIXME: make modal concept clear and easy. See the comment of
  392. * rtgui_topwin_modal_enter. */
  393. /* There are various reason that a modal window got deactivated:
  394. * 1, it has child windows and the user activate one of them.
  395. * 2, the application has more than one root window and the
  396. * user switched to one of the others.
  397. *
  398. * In any of the cases, we have nothing to do here.
  399. */
  400. }
  401. else
  402. {
  403. win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
  404. #ifndef RTGUI_USING_SMALL_SIZE
  405. if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
  406. RTGUI_WIDGET(object)->on_draw(object, event);
  407. else
  408. #endif
  409. rtgui_widget_update(RTGUI_WIDGET(win));
  410. if (win->on_deactivate != RT_NULL)
  411. {
  412. win->on_deactivate(RTGUI_OBJECT(object), event);
  413. }
  414. }
  415. break;
  416. case RTGUI_EVENT_PAINT:
  417. #ifndef RTGUI_USING_SMALL_SIZE
  418. if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
  419. RTGUI_WIDGET(object)->on_draw(object, event);
  420. else
  421. #endif
  422. rtgui_win_ondraw(win);
  423. break;
  424. case RTGUI_EVENT_MOUSE_BUTTON:
  425. /* check whether has widget which handled mouse event before */
  426. if (win->last_mevent_widget != RT_NULL)
  427. {
  428. RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
  429. RTGUI_OBJECT(win->last_mevent_widget),
  430. event);
  431. /* clean last mouse event handled widget */
  432. win->last_mevent_widget = RT_NULL;
  433. }
  434. else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
  435. (struct rtgui_event_mouse*)event) == RT_FALSE)
  436. {
  437. #ifndef RTGUI_USING_SMALL_SIZE
  438. if (RTGUI_WIDGET(object)->on_mouseclick != RT_NULL)
  439. {
  440. return RTGUI_WIDGET(object)->on_mouseclick(object, event);
  441. }
  442. #endif
  443. }
  444. break;
  445. case RTGUI_EVENT_MOUSE_MOTION:
  446. #if 0
  447. if (rtgui_widget_dispatch_mouse_event(widget,
  448. (struct rtgui_event_mouse*)event) == RT_FALSE)
  449. {
  450. #ifndef RTGUI_USING_SMALL_SIZE
  451. /* handle event in current widget */
  452. if (widget->on_mousemotion != RT_NULL)
  453. {
  454. return widget->on_mousemotion(widget, event);
  455. }
  456. #endif
  457. }
  458. else return RT_TRUE;
  459. #endif
  460. break;
  461. case RTGUI_EVENT_KBD:
  462. /* we should dispatch key event firstly */
  463. if (!(win->flag & RTGUI_WIN_FLAG_HANDLE_KEY))
  464. {
  465. struct rtgui_widget *widget;
  466. rt_bool_t res = RT_FALSE;
  467. /* we should dispatch the key event just once. Once entered the
  468. * dispatch mode, we should swtich to key handling mode. */
  469. win->flag |= RTGUI_WIN_FLAG_HANDLE_KEY;
  470. /* dispatch the key event */
  471. for (widget = win->focused_widget;
  472. widget && !res;
  473. widget = widget->parent)
  474. {
  475. if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
  476. res = RTGUI_OBJECT(widget)->event_handler(
  477. RTGUI_OBJECT(widget), event);
  478. }
  479. win->flag &= ~RTGUI_WIN_FLAG_HANDLE_KEY;
  480. return res;
  481. }
  482. else
  483. {
  484. /* in key handling mode(it may reach here in
  485. * win->focused_widget->event_handler call) */
  486. if (win->on_key != RT_NULL)
  487. return win->on_key(RTGUI_OBJECT(win), event);
  488. }
  489. break;
  490. default:
  491. /* call parent event handler */
  492. return rtgui_toplevel_event_handler(object, event);
  493. }
  494. return RT_FALSE;
  495. }
  496. RTM_EXPORT(rtgui_win_event_handler);
  497. void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
  498. {
  499. struct rtgui_event_win_resize event;
  500. if (win == RT_NULL || rect == RT_NULL) return;
  501. RTGUI_WIDGET(win)->extent = *rect;
  502. if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
  503. {
  504. /* set window resize event to server */
  505. RTGUI_EVENT_WIN_RESIZE_INIT(&event);
  506. event.wid = win;
  507. event.rect = *rect;
  508. rtgui_server_post_event(&(event.parent), sizeof(struct rtgui_event_win_resize));
  509. }
  510. }
  511. RTM_EXPORT(rtgui_win_set_rect);
  512. void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
  513. {
  514. if (win != RT_NULL)
  515. {
  516. win->on_activate = handler;
  517. }
  518. }
  519. RTM_EXPORT(rtgui_win_set_onactivate);
  520. void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
  521. {
  522. if (win != RT_NULL)
  523. {
  524. win->on_deactivate = handler;
  525. }
  526. }
  527. RTM_EXPORT(rtgui_win_set_ondeactivate);
  528. void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler)
  529. {
  530. if (win != RT_NULL)
  531. {
  532. win->on_close = handler;
  533. }
  534. }
  535. RTM_EXPORT(rtgui_win_set_onclose);
  536. void rtgui_win_set_onkey(rtgui_win_t* win, rtgui_event_handler_ptr handler)
  537. {
  538. if (win != RT_NULL)
  539. {
  540. win->on_key = handler;
  541. }
  542. }
  543. RTM_EXPORT(rtgui_win_set_onkey);
  544. void rtgui_win_set_title(rtgui_win_t* win, const char *title)
  545. {
  546. /* send title to server */
  547. if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
  548. {
  549. }
  550. /* modify in local side */
  551. if (win->title != RT_NULL)
  552. {
  553. rtgui_free(win->title);
  554. win->title = RT_NULL;
  555. }
  556. if (title != RT_NULL)
  557. {
  558. win->title = rt_strdup(title);
  559. }
  560. }
  561. RTM_EXPORT(rtgui_win_set_title);
  562. char* rtgui_win_get_title(rtgui_win_t* win)
  563. {
  564. RT_ASSERT(win != RT_NULL);
  565. return win->title;
  566. }
  567. RTM_EXPORT(rtgui_win_get_title);