window.c 20 KB

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