PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/TeXmacs-1.0.7.11-src/src/Plugins/Widkit/Basic/widkit_wrapper.cpp

#
C++ | 849 lines | 707 code | 101 blank | 41 comment | 68 complexity | 864a168e69467fc065225846ac6aead1 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /******************************************************************************
  2. * MODULE : widkit_wrapper.hpp
  3. * DESCRIPTION: Conversions between widget and wk_widget
  4. * COPYRIGHT : (C) 2007 Joris van der Hoeven
  5. *******************************************************************************
  6. * This software falls under the GNU general public license version 3 or later.
  7. * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
  8. * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
  9. ******************************************************************************/
  10. #include "promise.hpp"
  11. #include "url.hpp"
  12. #include "Widkit/wk_widget.hpp"
  13. #include "message.hpp"
  14. #include "window.hpp"
  15. #include "dictionary.hpp"
  16. #define THIS wk_widget (this)
  17. static void noop () {}
  18. widget box_widget (scheme_tree p, string s, color col, bool trans, bool ink);
  19. /******************************************************************************
  20. * Type conversions
  21. ******************************************************************************/
  22. array<widget>
  23. abstract (array<wk_widget> a) {
  24. int i, n= N(a);
  25. array<widget> b (n);
  26. for (i=0; i<n; i++) b[i]= abstract (a[i]);
  27. return b;
  28. }
  29. array<wk_widget>
  30. concrete (array<widget> a) {
  31. int i, n= N(a);
  32. array<wk_widget> b (n);
  33. for (i=0; i<n; i++) b[i]= concrete (a[i]);
  34. return b;
  35. }
  36. class abstract_promise_rep: public promise_rep<widget> {
  37. promise<wk_widget> p;
  38. public:
  39. abstract_promise_rep (promise<wk_widget> p2): p (p2) {}
  40. tm_ostream& print (tm_ostream& out) { return out << p; }
  41. widget eval () { return abstract (p ()); }
  42. };
  43. promise<widget>
  44. abstract (promise<wk_widget> pw) {
  45. return tm_new<abstract_promise_rep> (pw);
  46. }
  47. class concrete_promise_rep: public promise_rep<wk_widget> {
  48. promise<widget> p;
  49. public:
  50. concrete_promise_rep (promise<widget> p2): p (p2) {}
  51. tm_ostream& print (tm_ostream& out) { return out << p; }
  52. wk_widget eval () { return concrete (p ()); }
  53. };
  54. promise<wk_widget>
  55. concrete (promise<widget> pw) {
  56. return tm_new<concrete_promise_rep> (pw);
  57. }
  58. /******************************************************************************
  59. * Exported special widgets
  60. ******************************************************************************/
  61. widget
  62. extend (widget w, array<widget> a) {
  63. return abstract (extend (concrete (w), concrete (a)));
  64. }
  65. widget
  66. horizontal_list (array<widget> a) {
  67. return abstract (horizontal_list (concrete (a)));
  68. }
  69. widget
  70. vertical_list (array<widget> a) {
  71. return abstract (vertical_list (concrete (a)));
  72. }
  73. widget
  74. horizontal_menu (array<widget> a) {
  75. return abstract (horizontal_list (concrete (a)));
  76. //return abstract (horizontal_array (concrete (a), -1));
  77. }
  78. widget
  79. vertical_menu (array<widget> a) {
  80. return abstract (vertical_menu (concrete (a)));
  81. }
  82. widget
  83. tile_menu (array<widget> a, int cols) {
  84. return abstract (tile (concrete (a), cols));
  85. }
  86. widget
  87. minibar_widget (widget w) {
  88. return abstract (minibar_widget (concrete (w)));
  89. }
  90. widget
  91. minibar_menu (array<widget> a) {
  92. return minibar_widget (horizontal_menu (a));
  93. }
  94. widget
  95. switch_widget (array<widget> a, array<string> name, int init) {
  96. return abstract (switch_widget (concrete (a), name, init));
  97. }
  98. widget
  99. optional_widget (widget w, bool on) {
  100. return abstract (optional_widget (concrete (w), on));
  101. }
  102. widget
  103. empty_widget () {
  104. return abstract (glue_wk_widget (false, false, 0, 0));
  105. }
  106. widget
  107. glue_widget (bool hx, bool vx, SI w, SI h) {
  108. return abstract (glue_wk_widget (hx, vx, w, h));
  109. }
  110. widget
  111. glue_widget (tree col, bool hx, bool vx, SI w, SI h) {
  112. return abstract (glue_wk_widget (col, hx, vx, w, h));
  113. }
  114. widget
  115. menu_separator (bool vert) {
  116. return abstract (separator_wk_widget (2*PIXEL, 2*PIXEL, vert));
  117. }
  118. widget
  119. menu_text_widget (string s, int style, color col, bool tsp, bool tt) {
  120. return abstract (menu_text_wk_widget (s, style, col, tsp, tt));
  121. }
  122. widget
  123. text_widget (string s, int style, color col, bool tsp) {
  124. return menu_text_widget (s, style, col, tsp, false);
  125. }
  126. widget
  127. xpm_widget (url file_name) {
  128. return abstract (xpm_wk_widget (file_name, true));
  129. }
  130. widget
  131. command_button (widget w, command cmd, int style) {
  132. return abstract (command_button (concrete (w), cmd, style));
  133. }
  134. widget
  135. command_button (widget lw, widget cw, widget rw, command cmd, int style) {
  136. return abstract (command_button (concrete (lw), concrete (cw),
  137. concrete (rw), cmd, style));
  138. }
  139. widget
  140. menu_group (string name, int style) {
  141. widget lw= empty_widget ();
  142. widget cw= text_widget (name, style, dark_grey, false);
  143. widget rw= empty_widget ();
  144. return command_button (lw, cw, rw, noop,
  145. WIDGET_STYLE_INERT | WIDGET_STYLE_CENTERED);
  146. }
  147. widget
  148. menu_button (widget w, command cmd, string pre, string ks, int style) {
  149. bool ok= (style & WIDGET_STYLE_INERT) == 0;
  150. if (pre == "" && ks == "")
  151. return command_button (w, cmd, style);
  152. else {
  153. color c = ok? black: dark_grey;
  154. widget lw= empty_widget ();
  155. widget rw= menu_text_widget (ks, 0, c, true, true);
  156. if (pre != "") {
  157. string s= "";
  158. if (pre == "v") s= "<checked>";
  159. if (pre == "o") s= "<circ>";
  160. if (pre == "*") s= "<bullet>";
  161. if (s != "") lw= box_widget (tree (TUPLE), s, c, true, false);
  162. }
  163. return command_button (lw, w, rw, cmd, style);
  164. }
  165. }
  166. widget
  167. pulldown_button (widget w, promise<widget> pw) {
  168. return abstract (pulldown_button (concrete (w), concrete (pw)));
  169. }
  170. widget
  171. pullright_button (widget w, promise<widget> pw) {
  172. return abstract (pullright_button (concrete (w), concrete (pw)));
  173. }
  174. widget
  175. popup_widget (widget w) {
  176. return abstract (popup_widget (concrete (w), center));
  177. }
  178. widget
  179. canvas_widget (widget w) {
  180. return abstract (canvas_widget (concrete (w), north_west, true));
  181. }
  182. widget
  183. input_text_widget (command call_back, string type, array<string> def,
  184. int style, string width) {
  185. return abstract (input_text_wk_widget (call_back, type, def, style, width));
  186. }
  187. widget
  188. inputs_list_widget (command call_back, array<string> prompts) {
  189. return abstract (inputs_list_wk_widget (call_back, prompts));
  190. }
  191. widget
  192. file_chooser_widget (command cmd, string type, bool save) {
  193. return abstract (file_chooser_wk_widget (cmd, type));
  194. }
  195. widget
  196. printer_widget (command cmd, url u) {
  197. return menu_button (text_widget ("Cancel", 0, black), cmd, "", "", 0);
  198. }
  199. widget
  200. color_picker_widget (command cmd, bool bg, array<tree> proposals) {
  201. return abstract (color_picker_wk_widget (cmd, bg, proposals));
  202. }
  203. widget
  204. balloon_widget (widget w, widget help) {
  205. return abstract (balloon_widget (concrete (w), concrete (help)));
  206. }
  207. widget
  208. wait_widget (SI w, SI h, string message) {
  209. return abstract (wait_wk_widget (w, h, message));
  210. }
  211. widget
  212. texmacs_widget (int mask, command quit) {
  213. return abstract (texmacs_wk_widget (mask, quit));
  214. }
  215. widget
  216. plain_window_widget (widget wid, string s) {
  217. return abstract (plain_window_widget (concrete (wid), s));
  218. }
  219. widget
  220. popup_window_widget (widget wid, string s) {
  221. return abstract (popup_window_widget (concrete (wid), s));
  222. }
  223. void
  224. destroy_window_widget (widget w) {
  225. destroy_window_widget (concrete (w));
  226. }
  227. /******************************************************************************
  228. * Type checking
  229. ******************************************************************************/
  230. void
  231. check_type_void (blackbox bb, string s) {
  232. if (!is_nil (bb)) {
  233. cerr << "\nslot type= " << s << "\n";
  234. FAILED ("type mismatch");
  235. }
  236. }
  237. template<class T> void
  238. check_type (blackbox bb, string s) {
  239. if (type_box (bb) != type_helper<T>::id) {
  240. cerr << "\nslot type= " << s << "\n";
  241. FAILED ("type mismatch");
  242. }
  243. }
  244. template<class T1, class T2> inline void
  245. check_type (blackbox bb, string s) {
  246. check_type<pair<T1,T2> > (bb, s);
  247. }
  248. /******************************************************************************
  249. * Widget geometry
  250. ******************************************************************************/
  251. SI get_dx (gravity grav, SI w);
  252. SI get_dy (gravity grav, SI h);
  253. void
  254. principal_widget_check (wk_widget wid) {
  255. // FIXME: Positions should really be computed relative to parent widgets.
  256. // Currently, we only allow geometry access of the unique child of
  257. // a window widget.
  258. if (wid->win != NULL && wid != concrete (wid->win->get_widget ()) [0]) {
  259. cerr << "Widget= " << wid << "\n";
  260. FAILED ("invalid geometry access");
  261. }
  262. }
  263. void
  264. set_geometry (wk_widget wid, SI x, SI y, SI w, SI h) {
  265. if (wid->is_window_widget ()) {
  266. wid->win->set_position (x, y);
  267. wid->win->set_size (w, h);
  268. }
  269. else {
  270. principal_widget_check (wid); // FIXME: we should use parent's coordinates
  271. wid << emit_position (x, y, w, h, north_west);
  272. }
  273. }
  274. void
  275. get_geometry (wk_widget wid, SI& x, SI& y, SI& w, SI& h) {
  276. if (wid->is_window_widget ()) {
  277. wid->win->get_position (x, y);
  278. wid->win->get_size (w, h);
  279. }
  280. else {
  281. principal_widget_check (wid); // FIXME: we should use parent's coordinates
  282. x= wid->ox - get_dx (wid->grav, wid->w);
  283. y= wid->oy - get_dy (wid->grav, wid->h);
  284. w= wid->w;
  285. h= wid->h;
  286. }
  287. }
  288. /******************************************************************************
  289. * Sending messages
  290. ******************************************************************************/
  291. void
  292. send_bool (wk_widget w, string key, blackbox val) {
  293. ASSERT (type_box (val) == type_helper<bool>::id, "type mismatch");
  294. w << set_string (key, open_box<bool> (val)? string ("on"): string ("off"));
  295. }
  296. void
  297. send_int (wk_widget w, string key, blackbox val) {
  298. ASSERT (type_box (val) == type_helper<int>::id, "type mismatch");
  299. w << set_integer (key, open_box<int> (val));
  300. }
  301. void
  302. send_string (wk_widget w, string key, blackbox val) {
  303. ASSERT (type_box (val) == type_helper<string>::id, "type mismatch");
  304. w << set_string (key, open_box<string> (val));
  305. }
  306. void
  307. send_coord2 (wk_widget w, string key, blackbox val) {
  308. typedef pair<SI,SI> coord2;
  309. ASSERT (type_box (val) == type_helper<coord2>::id, "type mismatch");
  310. coord2 p= open_box<coord2> (val);
  311. w << set_coord2 (key, p.x1, p.x2);
  312. }
  313. void
  314. send_coord4 (wk_widget w, string key, blackbox val) {
  315. typedef quartet<SI,SI,SI,SI> coord4;
  316. ASSERT (type_box (val) == type_helper<coord4>::id, "type mismatch");
  317. coord4 p= open_box<coord4> (val);
  318. w << set_coord4 (key, p.x1, p.x2, p.x3, p.x4);
  319. }
  320. void
  321. send_position (wk_widget w, blackbox val) {
  322. typedef pair<SI,SI> coord2;
  323. ASSERT (type_box (val) == type_helper<coord2>::id, "type mismatch");
  324. coord2 p= open_box<coord2> (val);
  325. if (w->is_window_widget ()) w->win->set_position (p.x1, p.x2);
  326. else {
  327. SI x, y, W, H;
  328. get_geometry (w, x, y, W, H);
  329. set_geometry (w, p.x1, p.x2, W, H);
  330. }
  331. }
  332. void
  333. send_size (wk_widget w, blackbox val) {
  334. typedef pair<SI,SI> coord2;
  335. ASSERT (type_box (val) == type_helper<coord2>::id, "type mismatch");
  336. coord2 p= open_box<coord2> (val);
  337. if (w->is_window_widget ()) w->win->set_size (p.x1, p.x2);
  338. else {
  339. SI x, y, W, H;
  340. get_geometry (w, x, y, W, H);
  341. set_geometry (w, x, y, p.x1, p.x2);
  342. }
  343. }
  344. void
  345. send_update (wk_widget w, blackbox val) {
  346. ASSERT (is_nil (val), "type mismatch");
  347. w << emit_update ();
  348. }
  349. void
  350. send_keyboard (wk_widget w, blackbox val) {
  351. typedef pair<string,time_t> keypress;
  352. ASSERT (type_box (val) == type_helper<keypress>::id, "type mismatch");
  353. keypress k= open_box<keypress> (val);
  354. w << emit_keypress (k.x1, k.x2);
  355. }
  356. void
  357. send_keyboard_focus (wk_widget w, blackbox val) {
  358. ASSERT (type_box (val) == type_helper<bool>::id, "type mismatch");
  359. w->win->set_keyboard_focus (abstract (w), open_box<bool> (val));
  360. }
  361. void
  362. send_mouse (wk_widget w, blackbox val) {
  363. typedef quintuple<string,SI,SI,int,time_t> mouse;
  364. ASSERT (type_box (val) == type_helper<mouse>::id, "type mismatch");
  365. mouse m= open_box<mouse> (val);
  366. // FIXME: we should assume the position in the local coordinates
  367. w << emit_mouse (m.x1, m.x2, m.x3, m.x4, m.x5);
  368. }
  369. void
  370. send_mouse_grab (wk_widget w, blackbox val) {
  371. ASSERT (type_box (val) == type_helper<bool>::id, "type mismatch");
  372. w->win->set_mouse_grab (abstract (w), open_box<bool> (val));
  373. }
  374. void
  375. send_mouse_pointer (wk_widget w, blackbox val) {
  376. typedef pair<string,string> change_pointer;
  377. ASSERT (type_box (val) == type_helper<change_pointer>::id, "type mismatch");
  378. change_pointer cp= open_box<change_pointer> (val);
  379. w->win->set_mouse_pointer (abstract (w), cp.x1, cp.x2);
  380. }
  381. void
  382. send_invalidate (wk_widget w, blackbox val) {
  383. typedef quartet<SI,SI,SI,SI> coord4;
  384. ASSERT (type_box (val) == type_helper<coord4>::id, "type mismatch");
  385. coord4 p= open_box<coord4> (val);
  386. w << emit_invalidate (w->ox + p.x1, w->oy + p.x2,
  387. w->ox + p.x3, w->oy + p.x4);
  388. }
  389. void
  390. send_invalidate_all (wk_widget w, blackbox val) {
  391. ASSERT (is_nil (val), "type mismatch");
  392. w << emit_invalidate_all ();
  393. }
  394. void
  395. send_repaint (wk_widget w, blackbox val) {
  396. typedef quartet<SI,SI,SI,SI> repaint;
  397. ASSERT (type_box (val) == type_helper<repaint>::id, "type mismatch");
  398. repaint r= open_box<repaint> (val);
  399. bool stop_flag= false;
  400. // FIXME: we should assume local coordinates for repainting
  401. w << emit_repaint (r.x1, r.x2, r.x3, r.x4, stop_flag);
  402. }
  403. void
  404. send_delayed_message (wk_widget w, blackbox val) {
  405. typedef pair<string,time_t> delayed;
  406. ASSERT (type_box (val) == type_helper<delayed>::id, "type mismatch");
  407. delayed dm= open_box<delayed> (val);
  408. w << emit_alarm (dm.x1, dm.x2);
  409. }
  410. void
  411. send_destroy (wk_widget w, blackbox val) {
  412. ASSERT (is_nil (val), "type mismatch");
  413. w << emit_destroy ();
  414. }
  415. void
  416. wk_widget_rep::send (slot s, blackbox val) {
  417. switch (s) {
  418. case SLOT_IDENTIFIER:
  419. check_type<int> (val, "SLOT_IDENTIFIER");
  420. THIS << emit_attach_window (get_window (open_box<int> (val)));
  421. break;
  422. case SLOT_VISIBILITY:
  423. check_type<bool> (val, "SLOT_VISIBILITY");
  424. win->set_visibility (open_box<bool> (val));
  425. break;
  426. case SLOT_FULL_SCREEN:
  427. check_type<bool> (val, "SLOT_FULL_SCREEN");
  428. win->set_full_screen (open_box<bool> (val));
  429. break;
  430. case SLOT_NAME:
  431. send_string (THIS, "window name", val);
  432. break;
  433. case SLOT_SIZE:
  434. send_size (THIS, val);
  435. break;
  436. case SLOT_POSITION:
  437. send_position (THIS, val);
  438. break;
  439. case SLOT_UPDATE:
  440. send_update (THIS, val);
  441. break;
  442. case SLOT_KEYBOARD:
  443. send_keyboard (THIS, val);
  444. break;
  445. case SLOT_KEYBOARD_FOCUS:
  446. send_keyboard_focus (THIS, val);
  447. break;
  448. case SLOT_MOUSE:
  449. send_mouse (THIS, val);
  450. break;
  451. case SLOT_MOUSE_GRAB:
  452. send_mouse_grab (THIS, val);
  453. break;
  454. case SLOT_MOUSE_POINTER:
  455. send_mouse_pointer (THIS, val);
  456. break;
  457. case SLOT_INVALIDATE:
  458. send_invalidate (THIS, val);
  459. break;
  460. case SLOT_INVALIDATE_ALL:
  461. send_invalidate_all (THIS, val);
  462. break;
  463. case SLOT_REPAINT:
  464. send_repaint (THIS, val);
  465. break;
  466. case SLOT_DELAYED_MESSAGE:
  467. send_delayed_message (THIS, val);
  468. break;
  469. case SLOT_DESTROY:
  470. send_destroy (THIS, val);
  471. break;
  472. case SLOT_CURSOR:
  473. // send_coord2 (THIS, "cursor", val);
  474. // this message is currently ignored. Used only in TeXmacs/Qt
  475. break;
  476. case SLOT_SHRINKING_FACTOR:
  477. send_int (THIS, "shrinking factor", val);
  478. break;
  479. case SLOT_EXTENTS:
  480. send_coord4 (THIS, "extents", val);
  481. break;
  482. case SLOT_SCROLLBARS_VISIBILITY:
  483. send_int (THIS, "scrollbars", val);
  484. break;
  485. case SLOT_SCROLL_POSITION:
  486. send_coord2 (THIS, "scroll position", val);
  487. break;
  488. case SLOT_HEADER_VISIBILITY:
  489. send_bool (THIS, "header", val);
  490. break;
  491. case SLOT_MAIN_ICONS_VISIBILITY:
  492. send_bool (THIS, "main icons", val);
  493. break;
  494. case SLOT_MODE_ICONS_VISIBILITY:
  495. send_bool (THIS, "mode icons", val);
  496. break;
  497. case SLOT_FOCUS_ICONS_VISIBILITY:
  498. send_bool (THIS, "focus icons", val);
  499. break;
  500. case SLOT_USER_ICONS_VISIBILITY:
  501. send_bool (THIS, "user icons", val);
  502. break;
  503. case SLOT_FOOTER_VISIBILITY:
  504. send_bool (THIS, "footer flag", val);
  505. break;
  506. case SLOT_LEFT_FOOTER:
  507. send_string (THIS, "left footer", val);
  508. break;
  509. case SLOT_RIGHT_FOOTER:
  510. send_string (THIS, "right footer", val);
  511. break;
  512. case SLOT_INTERACTIVE_MODE:
  513. send_bool (THIS, "interactive mode", val);
  514. break;
  515. case SLOT_STRING_INPUT:
  516. send_string (THIS, "input", val);
  517. break;
  518. case SLOT_INPUT_TYPE:
  519. send_string (THIS, "type", val);
  520. break;
  521. case SLOT_INPUT_PROPOSAL:
  522. send_string (THIS, "default", val);
  523. break;
  524. case SLOT_FILE:
  525. send_string (THIS, "file", val);
  526. break;
  527. case SLOT_DIRECTORY:
  528. send_string (THIS, "directory", val);
  529. break;
  530. default:
  531. FAILED ("cannot handle slot type");
  532. }
  533. }
  534. /******************************************************************************
  535. * Querying
  536. ******************************************************************************/
  537. blackbox
  538. query_bool (wk_widget w, string key, int type_id) {
  539. ASSERT (type_id == type_helper<bool>::id, "type mismatch");
  540. string s;
  541. w << get_string (key, s);
  542. return close_box<bool> (s == "on");
  543. }
  544. blackbox
  545. query_int (wk_widget w, string key, int type_id) {
  546. ASSERT (type_id == type_helper<int>::id, "type mismatch");
  547. int i;
  548. w << get_integer (key, i);
  549. return close_box<int> (i);
  550. }
  551. blackbox
  552. query_string (wk_widget w, string key, int type_id) {
  553. ASSERT (type_id == type_helper<string>::id, "type mismatch");
  554. string s;
  555. w << get_string (key, s);
  556. return close_box<string> (s);
  557. }
  558. blackbox
  559. query_coord2 (wk_widget w, string key, int type_id) {
  560. typedef pair<SI,SI> coord2;
  561. ASSERT (type_id == type_helper<coord2>::id, "type mismatch");
  562. SI c1, c2;
  563. w << get_coord2 (key, c1, c2);
  564. return close_box<coord2> (coord2 (c1, c2));
  565. }
  566. blackbox
  567. query_coord4 (wk_widget w, string key, int type_id) {
  568. typedef quartet<SI,SI,SI,SI> coord4;
  569. ASSERT (type_id == type_helper<coord4>::id, "type mismatch");
  570. SI c1, c2, c3, c4;
  571. w << get_coord4 (key, c1, c2, c3, c4);
  572. return close_box<coord4> (coord4 (c1, c2, c3, c4));
  573. }
  574. blackbox
  575. query_size (wk_widget w, int type_id) {
  576. typedef pair<SI,SI> coord2;
  577. ASSERT (type_id == type_helper<coord2>::id, "type mismatch");
  578. SI x, y, W, H;
  579. get_geometry (w, x, y, W, H);
  580. return close_box<coord2> (coord2 (W, H));
  581. }
  582. blackbox
  583. query_position (wk_widget w, int type_id) {
  584. typedef pair<SI,SI> coord2;
  585. ASSERT (type_id == type_helper<coord2>::id, "type mismatch");
  586. SI x, y, W, H;
  587. get_geometry (w, x, y, W, H);
  588. return close_box<coord2> (coord2 (x, y));
  589. }
  590. blackbox
  591. query_keyboard_focus (wk_widget w, int type_id) {
  592. ASSERT (type_id == type_helper<bool>::id, "type mismatch");
  593. return close_box<bool> (w->win->get_keyboard_focus (abstract (w)));
  594. }
  595. blackbox
  596. query_mouse_grab (wk_widget w, int type_id) {
  597. ASSERT (type_id == type_helper<bool>::id, "type mismatch");
  598. return close_box<bool> (w->win->get_mouse_grab (abstract (w)));
  599. }
  600. blackbox
  601. wk_widget_rep::query (slot s, int type_id) {
  602. switch (s) {
  603. case SLOT_IDENTIFIER:
  604. ASSERT (type_id == type_helper<int>::id,
  605. "int expected (SLOT_IDENTIFIER)");
  606. return close_box<int> (get_identifier (win));
  607. case SLOT_RENDERER:
  608. ASSERT (type_id == type_helper<renderer>::id,
  609. "renderer expected (SLOT_RENDERER)");
  610. return close_box<renderer> (win->get_renderer ());
  611. case SLOT_SIZE:
  612. return query_size (THIS, type_id);
  613. case SLOT_POSITION:
  614. return query_position (THIS, type_id);
  615. case SLOT_KEYBOARD_FOCUS:
  616. return query_keyboard_focus (THIS, type_id);
  617. case SLOT_MOUSE_GRAB:
  618. return query_mouse_grab (THIS, type_id);
  619. case SLOT_EXTENTS:
  620. return query_coord4 (THIS, "extents", type_id);
  621. case SLOT_VISIBLE_PART:
  622. return query_coord4 (THIS, "visible", type_id);
  623. case SLOT_SCROLLBARS_VISIBILITY:
  624. return query_int (THIS, "scrollbars", type_id);
  625. case SLOT_SCROLL_POSITION:
  626. return query_coord2 (THIS, "scroll position", type_id);
  627. case SLOT_HEADER_VISIBILITY:
  628. return query_bool (THIS, "header", type_id);
  629. case SLOT_MAIN_ICONS_VISIBILITY:
  630. return query_bool (THIS, "main icons", type_id);
  631. case SLOT_MODE_ICONS_VISIBILITY:
  632. return query_bool (THIS, "mode icons", type_id);
  633. case SLOT_FOCUS_ICONS_VISIBILITY:
  634. return query_bool (THIS, "focus icons", type_id);
  635. case SLOT_USER_ICONS_VISIBILITY:
  636. return query_bool (THIS, "user icons", type_id);
  637. case SLOT_FOOTER_VISIBILITY:
  638. return query_bool (THIS, "footer flag", type_id);
  639. case SLOT_INTERACTIVE_MODE:
  640. return query_bool (THIS, "interactive mode", type_id);
  641. case SLOT_INTERACTIVE_INPUT:
  642. return query_string (THIS, "interactive input", type_id);
  643. case SLOT_STRING_INPUT:
  644. return query_string (THIS, "input", type_id);
  645. default:
  646. FAILED ("cannot handle slot type");
  647. return blackbox ();
  648. }
  649. }
  650. /******************************************************************************
  651. * Notification of state changes
  652. ******************************************************************************/
  653. void
  654. notify_keyboard_focus (wk_widget w, blackbox val) {
  655. ASSERT (type_box (val) == type_helper<bool>::id, "type mismatch");
  656. w << emit_keyboard_focus (open_box<bool> (val));
  657. }
  658. void
  659. notify_mouse_grab (wk_widget w, blackbox val) {
  660. ASSERT (type_box (val) == type_helper<bool>::id, "type mismatch");
  661. w << emit_mouse_grab (open_box<bool> (val));
  662. }
  663. void
  664. wk_widget_rep::notify (slot s, blackbox new_val) {
  665. switch (s) {
  666. case SLOT_SIZE:
  667. check_type<SI,SI> (new_val, "SLOT_SIZE");
  668. THIS << emit_resize ();
  669. if (is_window_widget ())
  670. send_size (THIS [0], new_val);
  671. break;
  672. case SLOT_POSITION:
  673. check_type<SI,SI> (new_val, "SLOT_POSITION");
  674. THIS << emit_move ();
  675. break;
  676. case SLOT_KEYBOARD_FOCUS:
  677. notify_keyboard_focus (THIS, new_val);
  678. break;
  679. case SLOT_MOUSE_GRAB:
  680. notify_mouse_grab (THIS, new_val);
  681. break;
  682. default:
  683. break;
  684. }
  685. widget_rep::notify (s, new_val);
  686. }
  687. /******************************************************************************
  688. * Read and write access of subwidgets
  689. ******************************************************************************/
  690. widget
  691. wk_widget_rep::read (slot s, blackbox index) {
  692. switch (s) {
  693. case SLOT_WINDOW:
  694. check_type_void (index, "SLOT_WINDOW");
  695. return win -> get_widget ();
  696. case SLOT_FORM_FIELD:
  697. check_type<int> (index, "SLOT_FORM_FIELD");
  698. return abstract (THIS [0] ["inputs"] [2*open_box<int> (index)] ["input"]);
  699. case SLOT_FILE:
  700. check_type_void (index, "SLOT_FILE");
  701. return abstract (THIS [0] ["file"] ["input"]);
  702. case SLOT_DIRECTORY:
  703. check_type_void (index, "SLOT_DIRECTORY");
  704. return abstract (THIS [0] ["directory"] ["input"]);
  705. default:
  706. FAILED ("cannot handle slot type");
  707. return widget ();
  708. }
  709. }
  710. void
  711. wk_widget_rep::write (slot s, blackbox index, widget w) {
  712. switch (s) {
  713. case SLOT_MAIN_MENU:
  714. check_type_void (index, "SLOT_MAIN_MENU");
  715. THIS << set_widget ("menu bar", concrete (w));
  716. break;
  717. case SLOT_MAIN_ICONS:
  718. check_type_void (index, "SLOT_MAIN_ICONS");
  719. THIS << set_widget ("main icons bar", concrete (w));
  720. break;
  721. case SLOT_MODE_ICONS:
  722. check_type_void (index, "SLOT_MODE_ICONS");
  723. THIS << set_widget ("mode icons bar", concrete (w));
  724. break;
  725. case SLOT_FOCUS_ICONS:
  726. check_type_void (index, "SLOT_FOCUS_ICONS");
  727. THIS << set_widget ("focus icons bar", concrete (w));
  728. break;
  729. case SLOT_USER_ICONS:
  730. check_type_void (index, "SLOT_USER_ICONS");
  731. THIS << set_widget ("user icons bar", concrete (w));
  732. break;
  733. case SLOT_CANVAS:
  734. check_type_void (index, "SLOT_CANVAS");
  735. THIS << set_widget ("scrollable", concrete (w));
  736. break;
  737. case SLOT_INTERACTIVE_PROMPT:
  738. check_type_void (index, "SLOT_INTERACTIVE_PROMPT");
  739. THIS << set_widget ("interactive prompt", concrete (w));
  740. break;
  741. case SLOT_INTERACTIVE_INPUT:
  742. check_type_void (index, "SLOT_INTERACTIVE_INPUT");
  743. THIS << set_widget ("interactive input", concrete (w));
  744. break;
  745. default:
  746. FAILED ("cannot handle slot type");
  747. }
  748. }