window.c 16 KB

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