iup_canvas.e 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. class IUP_CANVAS
  2. -- Creates an interface element that is a canvas - a working area for your
  3. -- application.
  4. --
  5. -- Note that some keys might remove the focus from the canvas. To avoid this,
  6. -- return IGNORE in the K_ANY callback.
  7. --
  8. -- The mouse cursor position can be programmatically controlled using the
  9. -- global attribute CURSORPOS.
  10. --
  11. -- When the canvas is displayed for the first time, the callback call order is
  12. -- always:
  13. --
  14. -- MAP_CB()
  15. -- RESIZE_CB()
  16. -- ACTION()
  17. --
  18. -- When the canvas is resized the ACTION callback is always called after the
  19. -- RESIZE_CB callback.
  20. -- Using with the CD library
  21. --
  22. -- When using the CD library to draw in a IupCanvas, you can use the callbacks
  23. -- to manage the canvas. The simplest way is to do:
  24. --
  25. -- MAP_CB - calls cdCreateCanvas (current size is not available yet)
  26. -- UNMAP_CB - calls cdKillCanvas
  27. -- RESIZE_CB - Calling cdCanvasActivate and cdCanvasGetSize returns the same
  28. -- values as given by the callback parameters.
  29. -- Recalculate the drawing size, update the scrollbars if any.
  30. -- ACTION - calls cdCanvasActivate
  31. -- then use CD primitives to draw the scene,
  32. -- finally calls cdCanvasFlush if using double buffer
  33. -- SCROLL_CB - when using scrollbars,
  34. -- if this callback is defined the canvas must be manually redrawn,
  35. -- call yourself the action callback or call IupUpdate.
  36. -- In other words, if this callback is not defined
  37. -- the canvas is automatically redrawn.
  38. inherit
  39. IUP_CONTAINER
  40. undefine
  41. execute_dragbegin,
  42. execute_dragdatasize,
  43. execute_dragdata,
  44. execute_dragend,
  45. execute_dropdata,
  46. execute_dropmotion
  47. redefine
  48. execute_map,
  49. execute_unmap,
  50. execute_destroy,
  51. execute_getfocus,
  52. execute_killfocus,
  53. execute_enterwindow,
  54. execute_leavewindow,
  55. execute_k_any,
  56. execute_help,
  57. execute_action_fnff,
  58. execute_focus,
  59. execute_motion,
  60. execute_keypress,
  61. execute_scroll,
  62. execute_wheel,
  63. execute_dropfiles,
  64. execute_resize,
  65. execute_button
  66. end
  67. IUP_WIDGET_BGCOLOR
  68. IUP_WIDGET_ACTIVE
  69. IUP_WIDGET_FONT
  70. IUP_WIDGET_EXPAND
  71. IUP_WIDGET_SCREENPOSITION
  72. IUP_WIDGET_POSITION
  73. IUP_WIDGET_MAXMIN_SIZE
  74. IUP_WIDGET_TIP
  75. IUP_WIDGET_SIZE
  76. IUP_WIDGET_RASTERSIZE
  77. IUP_WIDGET_USERSIZE
  78. IUP_WIDGET_ZORDER
  79. IUP_WIDGET_VISIBLE
  80. IUP_WIDGET_CHILD
  81. IUP_WIDGET_NAME
  82. IUP_WIDGET_FOCUS
  83. IUP_WIDGET_PROPAGATEFOCUS
  84. IUP_DRAG_AND_DROP
  85. IUP_WIDGET_CUSTOM_ATTRIBUTES
  86. create {ANY}
  87. canvas
  88. feature {ANY}
  89. canvas
  90. -- Create a canvas.
  91. local
  92. a_canvas, p: detachable POINTER
  93. do
  94. a_canvas := int_create_canvas(p)
  95. set_widget(a_canvas)
  96. end
  97. -- Special attributes for CD
  98. get_cd_canvas: CD_IUP
  99. do
  100. Result := internal_canvas
  101. end
  102. get_front_cd_canvas: CD_IUP
  103. do
  104. Result := front_canvas
  105. end
  106. -- Attributes
  107. set_backing_store (state: BOOLEAN)
  108. -- [Motif Only]: Controls the canvas backing store flag. The default
  109. -- value is "True".
  110. do
  111. iup_open.set_attribute(Current, "BACKINGSTORE", boolean_to_yesno(state))
  112. end
  113. set_border (state: BOOLEAN)
  114. -- (creation only): Shows a border around the canvas. Default: "True".
  115. do
  116. iup_open.set_attribute(Current, "BORDER", boolean_to_yesno(state))
  117. end
  118. set_can_focus (state: BOOLEAN)
  119. -- (creation only) (non inheritable): enables the focus traversal of the
  120. -- control. In Windows the canvas will respect CANFOCUS differently to
  121. -- some other controls. Default: True.
  122. do
  123. iup_open.set_attribute(Current, "CANFOCUS", boolean_to_yesno(state))
  124. end
  125. -- Skip CAIRO_CR
  126. set_clip_rect (x1, y1, x2, y2: INTEGER)
  127. -- [Windows and GTK Only] (only during ACTION): Specifies a rectangle
  128. -- that has its region invalidated for painting, it could be used for
  129. -- clipping.
  130. local
  131. str: STRING
  132. do
  133. str := x1.out
  134. str.append_string(" ")
  135. str.append_string(y1.out)
  136. str.append_string(" ")
  137. str.append_string(x2.out)
  138. str.append_string(" ")
  139. str.append_string(y2.out)
  140. iup_open.set_attribute(Current, "CLIPRECT", str)
  141. end
  142. set_cursor (name: STRING)
  143. -- Defines the element's cursor. See documentation. Default: ARROW
  144. do
  145. iup_open.set_attribute(Current, "CURSOR", name)
  146. end
  147. set_as_drop_files_target (state: BOOLEAN)
  148. -- [Windows and GTK Only] (non inheritable): Enable or disable the drop
  149. -- of files. Default: False, but if DROPFILES_CB is defined when the
  150. -- element is mapped then it will be automatically enabled.
  151. do
  152. iup_open.set_attribute(Current, "DROPFILESTARGET", boolean_to_yesno(state))
  153. end
  154. get_draw_size: TUPLE[INTEGER, INTEGER]
  155. -- (non inheritable): The size of the drawing area in pixels. This size is
  156. -- also used in the RESIZE_CB callback.
  157. -- Notice that the drawing area size is not the same as RASTERSIZE. The
  158. -- SCROLLBAR and BORDER attributes affect the size of the drawing area.
  159. local
  160. size: STRING
  161. do
  162. size := iup_open.get_attribute(Current, "DRAWSIZE")
  163. Result := components_of_size(size)
  164. end
  165. set_scroll_bar (state: BOOLEAN)
  166. -- (creation only): Associates a horizontal and/or vertical scrollbar to
  167. -- the canvas. Default: "False". The secondary attributes are all non
  168. -- inheritable.
  169. do
  170. iup_open.set_attribute(Current, "SCROLLBAR", boolean_to_yesno(state))
  171. end
  172. -- Skip HDC_WMPAINT, HWND
  173. set_dx (dx: REAL)
  174. -- Size of the thumb in the horizontal scrollbar. Also the horizontal
  175. -- page size. Default: "0.1".
  176. require
  177. dx >= 0
  178. do
  179. iup_open.set_attribute(Current, "DX", dx.out)
  180. end
  181. set_dy (dy: REAL)
  182. -- Size of the thumb in the vertical scrollbar. Also the vertical page
  183. -- size. Default: "0.1".
  184. require
  185. dy >= 0
  186. do
  187. iup_open.set_attribute(Current, "DY", dy.out)
  188. end
  189. set_pos_x (pos: REAL)
  190. -- Position of the thumb in the horizontal scrollbar. Default: "0.0".
  191. require
  192. pos >= 0
  193. do
  194. iup_open.set_attribute(Current, "POSX", pos.out)
  195. end
  196. set_pos_y (pos: REAL)
  197. -- Position of the thumb in the vertical scrollbar. Default: "0.0".
  198. require
  199. pos >= 0
  200. do
  201. iup_open.set_attribute(Current, "POSY", pos.out)
  202. end
  203. set_x_min (value: REAL)
  204. -- Minimum value of the horizontal scrollbar. Default: "0.0".
  205. require
  206. value >= 0
  207. do
  208. iup_open.set_attribute(Current, "XMIN", value.out)
  209. end
  210. set_x_max (value: REAL)
  211. -- Maximum value of the horizontal scrollbar. Default: "1.0".
  212. require
  213. value >= 0
  214. do
  215. iup_open.set_attribute(Current, "XMAX", value.out)
  216. end
  217. set_y_min (value: REAL)
  218. -- Minimum value of the vertical scrollbar. Default: "0.0".
  219. require
  220. value >= 0
  221. do
  222. iup_open.set_attribute(Current, "YMIN", value.out)
  223. end
  224. set_y_max (value: REAL)
  225. -- Maximum value of the vertical scrollbar. Default: "1.0".
  226. require
  227. value >= 0
  228. do
  229. iup_open.set_attribute(Current, "YMAX", value.out)
  230. end
  231. set_line_x (value: REAL)
  232. -- The amount the thumb moves when an horizontal step is performed.
  233. -- Default: 1/10th of DX.
  234. require
  235. value >= 0
  236. do
  237. iup_open.set_attribute(Current, "LINEX", value.out)
  238. end
  239. set_line_y (value: REAL)
  240. -- The amount the thumb moves when a vertical step is performed.
  241. -- Default: 1/10th of DY.
  242. require
  243. value >= 0
  244. do
  245. iup_open.set_attribute(Current, "LINEY", value.out)
  246. end
  247. set_x_auto_hide (state: BOOLEAN)
  248. -- When enabled, if DX >= XMAX-XMIN then the horizontal scrollbar is
  249. -- hidden. Default: "True".
  250. do
  251. iup_open.set_attribute(Current, "XAUTOHIDE", boolean_to_yesno(state))
  252. end
  253. set_y_auto_hide (state: BOOLEAN)
  254. -- When enabled, if DY >= YMAX-YMIN then the vertical scrollbar is
  255. -- hidden. Default: "True".
  256. do
  257. iup_open.set_attribute(Current, "YAUTOHIDE", boolean_to_yesno(state))
  258. end
  259. --set_touch (state: BOOLEAN)
  260. -- [Windows 7 Only]: enable the multi-touch events processing.
  261. -- do
  262. -- iup_open.set_attribute(Current, "TOUCH", boolean_to_yesno(state))
  263. -- end
  264. set_wheel_drop_focus (state: BOOLEAN)
  265. -- If set to True when the wheel is used the focus control close any dropdown
  266. -- opened. The default is False.
  267. do
  268. iup_open.set_attribute(Current, "WHEELDROPFOCUS", boolean_to_yesno(state))
  269. end
  270. -- Skip XDISPLAY, XWINDOW.
  271. -- For the MDI Client
  272. set_mdi_client (state: BOOLEAN)
  273. -- (creation only) [Windows Only] (non inheritable): Configure the canvas
  274. -- as a MDI client. No callbacks will be called. This canvas will be used
  275. -- internally only by the MDI Frame and its MDI Children. The MDI frame
  276. -- must have one and only one MDI client. Default: "False".
  277. do
  278. iup_open.set_attribute(Current, "MDICLIENT", boolean_to_yesno(state))
  279. end
  280. set_mdi_menu (menu: STRING)
  281. -- (creation only) [Windows Only]: Name of a IUP_MENU to be used as the
  282. -- Window list of a MDI frame. The system will automatically add the
  283. -- list of MDI child windows there.
  284. do
  285. iup_open.set_attribute(Current, "MDIMENU", menu)
  286. end
  287. -- Callbacks
  288. -- Common
  289. set_cb_map (act: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING])
  290. -- Called right after an element is mapped and its attributes updated.
  291. local
  292. operation: INTEGER
  293. do
  294. cb_map := act
  295. if cb_map /= Void then
  296. operation := 1
  297. else
  298. operation := 0
  299. end
  300. iup_open.set_callback (Current, "MAP_CB", "NONEEDED", operation)
  301. end
  302. set_cb_unmap (act: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING])
  303. -- Called right before an element is unmapped.
  304. local
  305. operation: INTEGER
  306. do
  307. cb_unmap := act
  308. if cb_unmap /= Void then
  309. operation := 1
  310. else
  311. operation := 0
  312. end
  313. iup_open.set_callback (Current, "UNMAP_CB", "NONEEDED", operation)
  314. end
  315. set_cb_destroy (act: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING])
  316. -- Called right before an element is destroyed.
  317. local
  318. operation: INTEGER
  319. do
  320. cb_destroy := act
  321. if cb_destroy /= Void then
  322. operation := 1
  323. else
  324. operation := 0
  325. end
  326. iup_open.set_callback (Current, "DESTROY_CB", "NONEEDED", operation)
  327. end
  328. set_cb_get_focus (act: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING])
  329. -- Action generated when an element is given keyboard focus.
  330. -- This callback is called after the KILLFOCUS_CB of the element
  331. -- that loosed the focus. The {IUP}.get_focus function during the
  332. -- callback returns the element that loosed the focus.
  333. local
  334. operation: INTEGER
  335. do
  336. cb_getfocus := act
  337. if cb_getfocus /= Void then
  338. operation := 1
  339. else
  340. operation := 0
  341. end
  342. iup_open.set_callback (Current, "GETFOCUS_CB", "NONEEDED", operation)
  343. end
  344. set_cb_kill_focus (act: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING])
  345. -- Action generated when an element loses keyboard focus. This
  346. -- callback is called before the GETFOCUS_CB of the element that
  347. -- gets the focus.
  348. local
  349. operation: INTEGER
  350. do
  351. cb_killfocus := act
  352. if cb_killfocus /= Void then
  353. operation := 1
  354. else
  355. operation := 0
  356. end
  357. iup_open.set_callback (Current, "KILLFOCUS_CB", "NONEEDED", operation)
  358. end
  359. set_cb_enter_window (act: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING])
  360. -- Action generated when the mouse enters the native element.
  361. local
  362. operation: INTEGER
  363. do
  364. cb_enterwindow := act
  365. if cb_enterwindow /= Void then
  366. operation := 1
  367. else
  368. operation := 0
  369. end
  370. iup_open.set_callback (Current, "ENTERWINDOW_CB", "NONEEDED", operation)
  371. end
  372. set_cb_leave_window (act: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING])
  373. -- Action generated when the mouse leaves the native element.
  374. local
  375. operation: INTEGER
  376. do
  377. cb_leavewindow := act
  378. if cb_leavewindow /= Void then
  379. operation := 1
  380. else
  381. operation := 0
  382. end
  383. iup_open.set_callback (Current, "LEAVEWINDOW_CB", "NONEEDED", operation)
  384. end
  385. set_cb_k_any (act: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER], STRING])
  386. -- Action generated when a keyboard event occurs.
  387. -- IUP_WIDGET the element that activated the event.
  388. -- INTEGER identifier of typed key. Please refer to the Keyboard
  389. -- Codes table for a list of possible values.
  390. --
  391. -- Returns: If IUP_IGNORE is returned the key is ignored and not
  392. -- processed by the control and not propagated. If returns
  393. -- IUP_CONTINUE, the key will be processed and the event will be
  394. -- propagated to the parent of the element receiving it, this is
  395. -- the default behavior. If returns IUP_DEFAULT the key is processed
  396. -- but it is not propagated. IUP_CLOSE will be processed.
  397. local
  398. operation: INTEGER
  399. do
  400. cb_k_any := act
  401. if cb_k_any /= Void then
  402. operation := 1
  403. else
  404. operation := 0
  405. end
  406. iup_open.set_callback (Current, "K_ANY", "NONEEDED", operation)
  407. end
  408. set_cb_help (act: detachable PROCEDURE[TUPLE[IUP_CANVAS]])
  409. -- Action generated when the user press F1 at a control. In Motif
  410. -- is also activated by the Help button in some workstations
  411. -- keyboard.
  412. -- Returns: IUP_CLOSE will be processed.
  413. local
  414. operation: INTEGER
  415. do
  416. cb_help := act
  417. if cb_help /= Void then
  418. operation := 1
  419. else
  420. operation := 0
  421. end
  422. iup_open.set_callback (Current, "HELP_CB", "NONEEDED", operation)
  423. end
  424. -- Extra
  425. set_cb_canvas_action (act: detachable FUNCTION[TUPLE[IUP_CANVAS, REAL_32, REAL_32], STRING])
  426. -- Action generated when the canvas needs to be redrawn.
  427. local
  428. operation: INTEGER
  429. do
  430. cb_canvas_action := act
  431. if cb_canvas_action /= Void then
  432. operation := 1
  433. else
  434. operation := 0
  435. end
  436. iup_open.set_callback (Current, "ACTION", "Fnff", operation)
  437. end
  438. set_cb_button (act: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING])
  439. -- Action generated when any mouse button is pressed and when it is
  440. -- released. Both calls occur before the ACTION callback when button 1 is
  441. -- being used.
  442. --
  443. -- IUP_CANVAS: identifies the element that activated the event.
  444. -- button: identifies the activated mouse button:
  445. --
  446. -- 1 - left mouse button (button 1);
  447. -- 2 - middle mouse button (button 2);
  448. -- 3 - right mouse button (button 3).
  449. --
  450. -- pressed: indicates the state of the button:
  451. --
  452. -- 0 - mouse button was released;
  453. -- 1 - mouse button was pressed.
  454. --
  455. -- x, y: position in the canvas where the event has occurred, in pixels.
  456. --
  457. -- status: status of the mouse buttons and some keyboard keys at the
  458. -- moment the event is generated. The following IUP features must be used
  459. -- for verification:
  460. --
  461. -- is_shift(status)
  462. -- is_control(status)
  463. -- is_button_1(status)
  464. -- is_button_2(status)
  465. -- is_button_3(status)
  466. -- is_button_4(status)
  467. -- is_button_5(status)
  468. -- is_double(status)
  469. -- is_alt(status)
  470. -- is_sys(status)
  471. --
  472. -- Returns: IUP_CLOSE will be processed. On some controls if IUP_IGNORE
  473. -- is returned the action is ignored (this is system dependent).
  474. local
  475. operation: INTEGER
  476. do
  477. cb_button := act
  478. if cb_button /= Void then
  479. operation := 1
  480. else
  481. operation := 0
  482. end
  483. iup_open.set_callback (Current, "BUTTON_CB", "NONEEDED", operation)
  484. end
  485. set_cb_drop_files (act: detachable FUNCTION[TUPLE[IUP_CANVAS, STRING, INTEGER, INTEGER, INTEGER], STRING])
  486. -- [Windows and GTK Only]: Action generated when one or more files are
  487. -- dropped in the element.
  488. -- If defined after the element is mapped then the attribute
  489. -- DROPFILESTARGET must be set to YES. [Windows and GTK Only]
  490. local
  491. operation: INTEGER
  492. do
  493. cb_dropfiles := act
  494. if cb_dropfiles /= Void then
  495. operation := 1
  496. else
  497. operation := 0
  498. end
  499. iup_open.set_callback (Current, "DROPFILES_CB", "NONEEDED", operation)
  500. end
  501. set_cb_focus (act: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER], STRING])
  502. -- Called when the canvas gets or looses the focus. It is called after
  503. -- the common callbacks GETFOCUS_CB and KILL_FOCUS_CB.
  504. -- ih: identifier of the element that activated the event.
  505. -- focus: is non zero if the canvas is getting the focus, is zero if it
  506. -- is loosing the focus.
  507. local
  508. operation: INTEGER
  509. do
  510. cb_focus := act
  511. if cb_focus /= Void then
  512. operation := 1
  513. else
  514. operation := 0
  515. end
  516. iup_open.set_callback (Current, "FOCUS_CB", "NONEEDED", operation)
  517. end
  518. set_cb_motion (act: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, INTEGER, STRING], STRING])
  519. -- Action generated when the mouse moves.
  520. -- ih: identifier of the element that activated the event.
  521. -- x, y: position in the canvas where the event has occurred, in pixels.
  522. -- status: status of mouse buttons and certain keyboard keys at the
  523. -- moment the event was generated. The same macros used for BUTTON_CB can
  524. -- be used for this status.
  525. local
  526. operation: INTEGER
  527. do
  528. cb_motion := act
  529. if cb_motion /= Void then
  530. operation := 1
  531. else
  532. operation := 0
  533. end
  534. iup_open.set_callback (Current, "MOTION_CB", "NONEEDED", operation)
  535. end
  536. set_cb_key_press (act: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, INTEGER], STRING])
  537. -- Action generated when a key is pressed or released. If the key is
  538. -- pressed and held several calls will occur. It is called after the
  539. -- callback K_ANY is processed.
  540. -- ih: identifier of the element that activated the event.
  541. -- c: identifier of typed key. Please refer to the Keyboard Codes table
  542. -- for a list of possible values.
  543. -- press: 1 is the user pressed the key or 0 otherwise.
  544. --
  545. -- Returns: If IUP_IGNORE is returned the key is ignored by the system.
  546. -- IUP_CLOSE will be processed.
  547. local
  548. operation: INTEGER
  549. do
  550. cb_keypress := act
  551. if cb_keypress /= Void then
  552. operation := 1
  553. else
  554. operation := 0
  555. end
  556. iup_open.set_callback (Current, "KEYPRESS_CB", "NONEEDED", operation)
  557. end
  558. set_cb_resize (act: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, INTEGER], STRING])
  559. -- Action generated when the canvas or dialog size is changed.
  560. --
  561. -- ih: identifier of the element that activated the event.
  562. -- width: the width of the internal element size in pixels not
  563. -- considering the decorations (client size)
  564. -- height: the height of the internal element size in pixels not
  565. -- considering the decorations (client size)
  566. -- When XAUTOHIDE=Yes or YAUTOHIDE=Yes, if the canvas scrollbar is
  567. -- hidden/shown after changing the DX or DY attributes from inside the
  568. -- callback, the size of the drawing area will immediately change, so the
  569. -- parameters with and height will be invalid. To update the parameters
  570. -- consult the DRAWSIZE attribute. Also activate the drawing toolkit only
  571. -- after updating the DX or DY attributes.
  572. local
  573. operation: INTEGER
  574. do
  575. cb_resize := act
  576. if cb_resize /= Void then
  577. operation := 1
  578. else
  579. operation := 0
  580. end
  581. iup_open.set_callback (Current, "RESIZE_CB", "NONEEDED", operation)
  582. end
  583. set_cb_scroll (act: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, REAL_32, REAL_32], STRING])
  584. -- Called when some manipulation is made to the scrollbar. The canvas is
  585. -- automatically redrawn only if this callback is NOT defined.
  586. --
  587. -- (GTK 2.8) Also the POSX and POSY values will not be correctly updated
  588. -- for older GTK versions.
  589. --
  590. -- In Ubuntu, when liboverlay-scrollbar is enabled (the new tiny
  591. -- auto-hide scrollbar) only the IUP_SBPOSV and IUP_SBPOSH codes are used.
  592. --
  593. -- ih: identifier of the element that activated the event.
  594. -- op: indicates the operation performed on the scrollbar.
  595. --
  596. -- If the manipulation was made on the vertical scrollbar, it can have
  597. -- the following values:
  598. --
  599. -- 0 - line up
  600. -- 1 - line down
  601. -- 2 - page up
  602. -- 3 - page down
  603. -- 4 - vertical positioning
  604. -- 5 - vertical drag
  605. --
  606. -- If it was on the horizontal scrollbar, the following values are valid:
  607. --
  608. -- 6 - column left
  609. -- 7 - column right
  610. -- 8 - page left
  611. -- 9 - page right
  612. -- 10 - horizontal positioning
  613. -- 11 - horizontal drag
  614. --
  615. -- posx, posy: the same as the ACTION canvas callback (corresponding to
  616. -- the values of attributes POSX and POSY).
  617. --
  618. -- Notes:
  619. --
  620. -- vertical drag (5) and horizontal drag (11) are not supported in GTK.
  621. local
  622. operation: INTEGER
  623. do
  624. cb_scroll := act
  625. if cb_scroll /= Void then
  626. operation := 1
  627. else
  628. operation := 0
  629. end
  630. iup_open.set_callback (Current, "SCROLL_CB", "NONEEDED", operation)
  631. end
  632. set_cb_wheel (act: detachable FUNCTION[TUPLE[IUP_CANVAS, REAL_32, INTEGER, INTEGER, STRING], STRING])
  633. -- Action generated when the mouse wheel is rotated. If this callback is
  634. -- not defined the wheel will automatically scroll the canvas in the
  635. -- vertical direction by some lines, the SCROLL_CB callback if defined
  636. -- will be called with the IUP_SBDRAGV operation.
  637. --
  638. -- ih: identifier of the element that activated the event.
  639. -- delta: the amount the wheel was rotated in notches.
  640. -- x, y: position in the canvas where the event has occurred, in pixels.
  641. -- status: status of mouse buttons and certain keyboard keys at the
  642. -- moment the event was generated. The same macros used for BUTTON_CB can
  643. -- be used for this status.
  644. --
  645. -- In Motif and GTK delta is always 1 or -1. In Windows is some
  646. -- situations delta can reach the value of two. In the future with more
  647. -- precise wheels this increment can be changed.
  648. local
  649. operation: INTEGER
  650. do
  651. cb_wheel := act
  652. if cb_wheel /= Void then
  653. operation := 1
  654. else
  655. operation := 0
  656. end
  657. iup_open.set_callback (Current, "WHEEL_CB", "NONEEDED", operation)
  658. end
  659. -- Skip TOUCH_CB, MULTITOUCH_CB, WOM_CB
  660. feature {IUP}
  661. -- Internal handle of callbacks.
  662. -- Common callbacks
  663. execute_map: STRING
  664. do
  665. if attached cb_map as int_cb then
  666. Result := int_cb.item([Current])
  667. else
  668. Result := "IUP_DEFAULT"
  669. end
  670. end
  671. execute_unmap: STRING
  672. do
  673. if attached cb_unmap as int_cb then
  674. Result := int_cb.item([Current])
  675. else
  676. Result := "IUP_DEFAULT"
  677. end
  678. end
  679. execute_destroy: STRING
  680. do
  681. if attached cb_destroy as int_cb then
  682. Result := int_cb.item([Current])
  683. else
  684. Result := "IUP_DEFAULT"
  685. end
  686. end
  687. execute_getfocus: STRING
  688. do
  689. if attached cb_getfocus as int_cb then
  690. Result := int_cb.item([Current])
  691. else
  692. Result := "IUP_DEFAULT"
  693. end
  694. end
  695. execute_killfocus: STRING
  696. do
  697. if attached cb_killfocus as int_cb then
  698. Result := int_cb.item([Current])
  699. else
  700. Result := "IUP_DEFAULT"
  701. end
  702. end
  703. execute_enterwindow: STRING
  704. do
  705. if attached cb_enterwindow as int_cb then
  706. Result := int_cb.item([Current])
  707. else
  708. Result := "IUP_DEFAULT"
  709. end
  710. end
  711. execute_leavewindow: STRING
  712. do
  713. if attached cb_leavewindow as int_cb then
  714. Result := int_cb.item([Current])
  715. else
  716. Result := "IUP_DEFAULT"
  717. end
  718. end
  719. execute_k_any (c: INTEGER): STRING
  720. do
  721. if attached cb_k_any as int_cb then
  722. Result := int_cb.item([Current, c])
  723. else
  724. Result := "IUP_DEFAULT"
  725. end
  726. end
  727. execute_help
  728. do
  729. if attached cb_help as int_cb then
  730. int_cb.call([Current])
  731. end
  732. end
  733. -- Extra
  734. execute_action_fnff (posx, posy: REAL_32): STRING
  735. do
  736. if attached cb_canvas_action as int_cb then
  737. Result := int_cb.item([Current, posx, posy])
  738. else
  739. Result := "IUP_DEFAULT"
  740. end
  741. end
  742. execute_button (btn, pressed, x, y: INTEGER; status: STRING): STRING
  743. do
  744. if attached cb_button as int_cb then
  745. Result := int_cb.item([Current, btn, pressed, x, y, status])
  746. else
  747. Result := "IUP_DEFAULT"
  748. end
  749. end
  750. execute_dropfiles (filename: STRING; num: INTEGER; x: INTEGER; y: INTEGER): STRING
  751. do
  752. if attached cb_dropfiles as int_cb then
  753. Result := int_cb.item([Current, filename, num, x, y])
  754. else
  755. Result := "IUP_DEFAULT"
  756. end
  757. end
  758. execute_focus (focus: INTEGER): STRING
  759. do
  760. if attached cb_focus as int_cb then
  761. Result := int_cb.item([Current, focus])
  762. else
  763. Result := "IUP_DEFAULT"
  764. end
  765. end
  766. execute_motion (x, y: INTEGER; status: STRING): STRING
  767. do
  768. if attached cb_motion as int_cb then
  769. Result := int_cb.item([Current, x, y, status])
  770. else
  771. Result := "IUP_DEFAULT"
  772. end
  773. end
  774. execute_keypress (c, press: INTEGER): STRING
  775. do
  776. if attached cb_keypress as int_cb then
  777. Result := int_cb.item([Current, c, press])
  778. else
  779. Result := "IUP_DEFAULT"
  780. end
  781. end
  782. execute_resize (width, height: INTEGER): STRING
  783. do
  784. if attached cb_resize as int_cb then
  785. Result := int_cb.item([Current, width, height])
  786. else
  787. Result := "IUP_DEFAULT"
  788. end
  789. end
  790. execute_scroll (op: INTEGER; posx, posy: REAL_32): STRING
  791. do
  792. if attached cb_scroll as int_cb then
  793. Result := int_cb.item([Current, op, posx, posy])
  794. else
  795. Result := "IUP_DEFAULT"
  796. end
  797. end
  798. execute_wheel (delta: REAL_32; x, y: INTEGER; status: STRING): STRING
  799. do
  800. if attached cb_wheel as int_cb then
  801. Result := int_cb.item([Current, delta, x, y, status])
  802. else
  803. Result := "IUP_DEFAULT"
  804. end
  805. end
  806. feature {CD_IUP}
  807. set_cd_canvas (cd: CD_IUP)
  808. do
  809. internal_canvas := cd
  810. end
  811. set_back_and_front_cd_canvas (back_cd: CD_IUP)
  812. local
  813. fcd: CD_IUP
  814. p: POINTER
  815. do
  816. internal_canvas := back_cd
  817. p := iup_open.get_attribute_ihandle(Current, "")
  818. create fcd.create_with_front_cd_canvas(p)
  819. front_canvas := fcd
  820. end
  821. feature {NONE}
  822. -- For CD
  823. internal_canvas: CD_IUP
  824. attribute
  825. create Result.create_default
  826. end
  827. front_canvas: CD_IUP
  828. attribute
  829. create Result.create_default
  830. end
  831. -- For callbacks
  832. cb_map: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING]
  833. cb_unmap: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING]
  834. cb_destroy: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING]
  835. cb_getfocus: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING]
  836. cb_killfocus: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING]
  837. cb_enterwindow: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING]
  838. cb_leavewindow: detachable FUNCTION[TUPLE[IUP_CANVAS], STRING]
  839. cb_k_any: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER], STRING]
  840. cb_help: detachable PROCEDURE[TUPLE[IUP_CANVAS]]
  841. cb_canvas_action: detachable FUNCTION[TUPLE[IUP_CANVAS, REAL_32, REAL_32], STRING]
  842. cb_button: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING]
  843. cb_dropfiles: detachable FUNCTION[TUPLE[IUP_CANVAS, STRING, INTEGER, INTEGER, INTEGER], STRING]
  844. cb_focus: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER], STRING]
  845. cb_motion: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, INTEGER, STRING], STRING]
  846. cb_keypress: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, INTEGER], STRING]
  847. cb_resize: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, INTEGER], STRING]
  848. cb_scroll: detachable FUNCTION[TUPLE[IUP_CANVAS, INTEGER, REAL_32, REAL_32], STRING]
  849. cb_wheel: detachable FUNCTION[TUPLE[IUP_CANVAS, REAL_32, INTEGER, INTEGER, STRING], STRING]
  850. -- Internals
  851. int_create_canvas (action: POINTER): POINTER
  852. external
  853. "C inline use %"eiffel-iup.h%""
  854. alias
  855. "return IupCanvas ($action);"
  856. end
  857. end
  858. -- The MIT License (MIT)
  859. -- Copyright (c) 2016, 2017, 2019, 2020, 2021 by German A. Arias
  860. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  861. -- of this software and associated documentation files (the "Software"), to deal
  862. -- in the Software without restriction, including without limitation the rights
  863. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  864. -- copies of the Software, and to permit persons to whom the Software is
  865. -- furnished to do so, subject to the following conditions:
  866. --
  867. -- The above copyright notice and this permission notice shall be included in
  868. -- all copies or substantial portions of the Software.
  869. --
  870. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  871. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  872. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  873. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  874. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  875. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  876. -- SOFTWARE.