uo_toolbar.sru 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. $PBExportHeader$uo_toolbar.sru
  2. $PBExportComments$Simple ToolBar
  3. forward
  4. global type uo_toolbar from userobject
  5. end type
  6. type uo_topline from uo_toolbar_menuseperator within uo_toolbar
  7. end type
  8. type uo_bottomline from uo_toolbar_menuseperator within uo_toolbar
  9. end type
  10. type ln_2 from line within uo_toolbar
  11. end type
  12. type ln_4 from line within uo_toolbar
  13. end type
  14. type ln_3 from line within uo_toolbar
  15. end type
  16. type ln_1 from line within uo_toolbar
  17. end type
  18. end forward
  19. global type uo_toolbar from userobject
  20. integer width = 2386
  21. integer height = 200
  22. boolean border = true
  23. long backcolor = 67108864
  24. long tabtextcolor = 33554432
  25. long picturemaskcolor = 536870912
  26. event ue_paint pbm_paint
  27. uo_topline uo_topline
  28. uo_bottomline uo_bottomline
  29. ln_2 ln_2
  30. ln_4 ln_4
  31. ln_3 ln_3
  32. ln_1 ln_1
  33. end type
  34. global uo_toolbar uo_toolbar
  35. type variables
  36. Public:
  37. string TextAlign ='Right' //Right,None
  38. integer Picture_Size = 32
  39. protectedwrite uo_toolbar_button iuo_buttons[]
  40. Protected:
  41. uo_toolbar_space iuo_spaces[]
  42. window iw_parent
  43. integer ButtonCnt
  44. long ButtonHeight
  45. long Minwidth
  46. long il_space = 3
  47. end variables
  48. forward prototypes
  49. public subroutine of_readmenu (readonly menu am_menu)
  50. public subroutine of_getparentwin ()
  51. public subroutine of_setalign (string as_align)
  52. public subroutine of_setsize ()
  53. public subroutine of_setposition ()
  54. public subroutine of_draw ()
  55. public subroutine of_showbottom ()
  56. public subroutine of_minwidth ()
  57. public subroutine of_hidebottom ()
  58. public subroutine of_setbuttonsize (integer ai_size)
  59. public subroutine of_setenabled (integer ai_index, boolean ab_enabled)
  60. public subroutine of_setenabled (menu am_menu, boolean ab_enabled)
  61. public subroutine of_resize ()
  62. public function boolean of_getenabled (integer ai_index)
  63. public function boolean of_getenabled (menu am_menu)
  64. end prototypes
  65. event ue_paint;integer li_loop
  66. FOR li_loop = 1 TO upperbound(iuo_buttons)
  67. IF NOT iuo_buttons[li_loop].enabled THEN
  68. iuo_buttons[li_loop].of_drawdisabled()
  69. END IF
  70. NEXT
  71. end event
  72. public subroutine of_readmenu (readonly menu am_menu);long ll_beginx,ll_btnheight
  73. integer li_btnpos,li_spacepos
  74. string ls_bitmapFilename
  75. menu lm_submenu,lm_menu
  76. IF isvalid (am_menu) = false THEN
  77. //Not a valid menu , hide toolbar.
  78. this.hide()
  79. ELSE
  80. integer li_menucnt,li_loop,li_loop2
  81. li_menucnt = UpperBound(am_menu.item)
  82. ll_beginx =this.x+ 40
  83. FOR li_loop = 1 TO li_menucnt
  84. lm_submenu = am_menu.item[li_loop] //sub menu
  85. FOR li_loop2 =1 TO UpperBound(lm_submenu.item)
  86. lm_menu = lm_submenu.item[li_loop2] //menu
  87. ls_bitmapFilename = lm_menu.ToolbarItemName
  88. IF lm_menu.ToolbarItemSpace > 0 then
  89. li_spacepos = upperbound(iuo_spaces) + 1
  90. iw_parent.openuserobject(iuo_spaces[li_spacepos],ll_beginx, this.y + 10)
  91. iw_parent.control[Upperbound(iw_parent.control)+1] = iuo_spaces[li_spacepos]
  92. iuo_spaces[li_spacepos].backcolor = iw_parent.backcolor
  93. ll_beginx = ll_beginx + iuo_spaces[li_spacepos].width + il_space
  94. END IF
  95. li_btnpos = Upperbound(iuo_buttons)+1
  96. IF ls_bitmapFilename <> "" THEN
  97. iw_parent.openuserobject(iuo_buttons[li_btnpos],ll_beginx,this.y + 10)
  98. ELSE
  99. CONTINUE
  100. END IF
  101. iuo_buttons[li_btnpos].ButtonText = trim(lm_menu.ToolbarItemText)
  102. iuo_buttons[li_btnpos].TextAlign = TextAlign
  103. iuo_buttons[li_btnpos].ToolTip = trim(lm_menu.MicroHelp)
  104. iuo_buttons[li_btnpos].enabled = lm_menu.Enabled
  105. iuo_buttons[li_btnpos].Picture_Name = ls_bitmapfilename
  106. iuo_buttons[li_btnpos].Picture_size = Picture_size
  107. iuo_buttons[li_btnpos].Bringtotop = true
  108. iuo_buttons[li_btnpos].visible = this.visible
  109. iuo_buttons[li_btnpos].of_setparent(this)
  110. iuo_buttons[li_btnpos].of_setmenu(lm_menu)
  111. iuo_buttons[li_btnpos].of_setbkcolor(this.backcolor)
  112. IF UpperBound(lm_menu.item)>0 THEN
  113. iuo_buttons[li_btnpos].of_childmenu(true)
  114. END IF
  115. iuo_buttons[li_btnpos].triggerevent('Constructor')
  116. ll_beginx = ll_beginx + iuo_buttons[li_btnpos].width + il_space
  117. IF iuo_buttons[li_btnpos].height>ll_btnheight THEN ll_btnheight = iuo_buttons[li_btnpos].height
  118. IF lower(lm_menu.tag) = 'checked' THEN
  119. iuo_buttons[li_btnpos].ButtonType = 'Checked'
  120. IF lm_menu.checked THEN iuo_buttons[li_btnpos].of_checked()
  121. ELSEIF left(lower(lm_menu.tag),10) = 'radiogroup' THEN
  122. iuo_buttons[li_btnpos].ButtonType = 'RadioButton'
  123. iuo_buttons[li_btnpos].of_setgroup(integer(mid(lm_menu.tag,11)))
  124. IF lm_menu.checked THEN iuo_buttons[li_btnpos].of_checked()
  125. END IF
  126. IF lm_menu.ToolbarItemSpace > 0 THEN
  127. iuo_spaces[li_spacepos].height = iuo_buttons[li_btnpos].height - 10
  128. iuo_spaces[li_spacepos].bringtotop = true
  129. END IF
  130. iw_parent.control[Upperbound(iw_parent.control)+1] = iuo_buttons[li_btnpos]
  131. NEXT
  132. NEXT
  133. END IF
  134. ButtonHeight = ll_btnheight
  135. MinWidth = ll_beginx - this.x
  136. of_setsize()
  137. of_setposition()
  138. end subroutine
  139. public subroutine of_getparentwin ();powerobject lpo_tmp
  140. userobject luo_tmp
  141. lpo_tmp = this.getparent()
  142. DO While lpo_tmp.typeof() <> Window!
  143. luo_tmp = lpo_tmp
  144. lpo_tmp= luo_tmp.getparent()
  145. LOOP
  146. iw_parent = lpo_tmp
  147. end subroutine
  148. public subroutine of_setalign (string as_align);IF TextAlign = as_align THEN RETURN
  149. IF pos('Right;None;',as_align)>0 THEN
  150. TextAlign = as_align
  151. IF TextAlign='None' THEN uo_bottomline.visible = false
  152. ELSE
  153. TextAlign = 'Bottom'
  154. END IF
  155. integer li_loop,li_loop2
  156. long ll_beginx
  157. ll_beginx = this.x + 40
  158. IF upperbound(iuo_buttons)>0 THEN
  159. ButtonHeight = 0
  160. Minwidth = 0
  161. FOR li_loop = 1 TO upperbound(iuo_buttons)
  162. iuo_buttons[li_loop].of_setalign(TextAlign)
  163. iuo_buttons[li_loop].y = this.y + 10
  164. IF iuo_buttons[li_loop].of_getmenu().ToolbarItemSpace>0 THEN
  165. li_loop2 ++
  166. iuo_spaces[li_loop2].x = ll_beginx
  167. iuo_spaces[li_loop2].y = this.y + 10
  168. iuo_spaces[li_loop2].height = iuo_buttons[li_loop].height - 10
  169. ll_beginx = ll_beginx + iuo_spaces[li_loop2].width + il_space
  170. END IF
  171. iuo_buttons[li_loop].x = ll_beginx
  172. ll_beginx = ll_beginx + iuo_buttons[li_loop].width + il_space
  173. IF iuo_buttons[li_loop].height>ButtonHeight THEN ButtonHeight = iuo_buttons[li_loop].height
  174. NEXT
  175. Minwidth = ll_beginx - this.x
  176. END IF
  177. of_SetSize()
  178. of_SetPosition()
  179. end subroutine
  180. public subroutine of_setsize ();IF this.width < minwidth THEN this.width = minwidth
  181. CHOOSE CASE TextAlign
  182. CASE 'Bottom'
  183. this.height = ButtonHeight + 25
  184. uo_Bottomline.visible = true
  185. CASE 'Right'
  186. this.height = ButtonHeight + 25
  187. uo_Bottomline.visible = true
  188. CASE 'None'
  189. this.height = ButtonHeight + 25
  190. END CHOOSE
  191. ln_1.endy = this.height - 20
  192. ln_2.endy = this.height - 20
  193. ln_3.endy = this.height - 20
  194. ln_4.endy = this.height - 20
  195. uo_topline.width = this.width
  196. uo_bottomline.width = this.width
  197. end subroutine
  198. public subroutine of_setposition ();uo_bottomline.y = this.height - 10
  199. end subroutine
  200. public subroutine of_draw ();of_setalign(TextAlign)
  201. of_setsize()
  202. of_setposition()
  203. end subroutine
  204. public subroutine of_showbottom ();of_setsize()
  205. of_setposition()
  206. uo_bottomline.visible = true
  207. end subroutine
  208. public subroutine of_minwidth ();this.width = minwidth
  209. end subroutine
  210. public subroutine of_hidebottom ();uo_bottomline.visible = false
  211. end subroutine
  212. public subroutine of_setbuttonsize (integer ai_size);IF ai_size = 24 THEN
  213. Picture_Size = 24
  214. ELSE
  215. picture_size = 16
  216. END IF
  217. end subroutine
  218. public subroutine of_setenabled (integer ai_index, boolean ab_enabled);IF ai_index > 0 THEN
  219. iuo_buttons[ai_index].of_enabled( ab_enabled )
  220. iuo_buttons[ai_index].of_enabledmenu(ab_enabled)
  221. END IF
  222. end subroutine
  223. public subroutine of_setenabled (menu am_menu, boolean ab_enabled);integer li_index
  224. IF am_menu.enabled = ab_enabled THEN
  225. RETURN
  226. ELSE
  227. am_menu.enabled = ab_enabled
  228. FOR li_index = 1 TO upperbound(iuo_buttons)
  229. IF iuo_buttons[li_index].of_getmenu() = am_menu THEN
  230. iuo_buttons[li_index].of_enabled(ab_enabled)
  231. EXIT
  232. END IF
  233. END FOR
  234. END IF
  235. end subroutine
  236. public subroutine of_resize ();IF this.width < minwidth THEN this.width = minwidth
  237. CHOOSE CASE TextAlign
  238. CASE 'Bottom'
  239. this.height = ButtonHeight + 25
  240. uo_Bottomline.visible = true
  241. CASE 'Right'
  242. this.height = ButtonHeight + 25
  243. uo_Bottomline.visible = true
  244. CASE 'None'
  245. this.height = ButtonHeight + 25
  246. END CHOOSE
  247. ln_1.endy = this.height - 20
  248. ln_2.endy = this.height - 20
  249. ln_3.endy = this.height - 20
  250. ln_4.endy = this.height - 20
  251. uo_topline.width = this.width
  252. uo_bottomline.width = this.width
  253. end subroutine
  254. public function boolean of_getenabled (integer ai_index);IF ai_index > 0 THEN
  255. return iuo_buttons[ai_index].enabled
  256. END IF
  257. return false
  258. end function
  259. public function boolean of_getenabled (menu am_menu);return am_menu.enabled
  260. end function
  261. on uo_toolbar.create
  262. this.uo_topline=create uo_topline
  263. this.uo_bottomline=create uo_bottomline
  264. this.ln_2=create ln_2
  265. this.ln_4=create ln_4
  266. this.ln_3=create ln_3
  267. this.ln_1=create ln_1
  268. this.Control[]={this.uo_topline,&
  269. this.uo_bottomline,&
  270. this.ln_2,&
  271. this.ln_4,&
  272. this.ln_3,&
  273. this.ln_1}
  274. end on
  275. on uo_toolbar.destroy
  276. destroy(this.uo_topline)
  277. destroy(this.uo_bottomline)
  278. destroy(this.ln_2)
  279. destroy(this.ln_4)
  280. destroy(this.ln_3)
  281. destroy(this.ln_1)
  282. end on
  283. event constructor;of_getparentwin()
  284. this.backcolor = iw_parent.backcolor
  285. end event
  286. type uo_topline from uo_toolbar_menuseperator within uo_toolbar
  287. integer width = 2208
  288. integer taborder = 10
  289. end type
  290. on uo_topline.destroy
  291. call uo_toolbar_menuseperator::destroy
  292. end on
  293. type uo_bottomline from uo_toolbar_menuseperator within uo_toolbar
  294. boolean visible = false
  295. integer y = 176
  296. integer width = 2203
  297. integer taborder = 20
  298. end type
  299. on uo_bottomline.destroy
  300. call uo_toolbar_menuseperator::destroy
  301. end on
  302. type ln_2 from line within uo_toolbar
  303. long linecolor = 8421504
  304. integer linethickness = 4
  305. integer beginx = 14
  306. integer beginy = 20
  307. integer endx = 14
  308. integer endy = 168
  309. end type
  310. type ln_4 from line within uo_toolbar
  311. long linecolor = 8421504
  312. integer linethickness = 4
  313. integer beginx = 27
  314. integer beginy = 20
  315. integer endx = 27
  316. integer endy = 168
  317. end type
  318. type ln_3 from line within uo_toolbar
  319. long linecolor = 16777215
  320. integer linethickness = 4
  321. integer beginx = 23
  322. integer beginy = 20
  323. integer endx = 23
  324. integer endy = 168
  325. end type
  326. type ln_1 from line within uo_toolbar
  327. long linecolor = 31910120
  328. integer linethickness = 8
  329. integer beginx = 9
  330. integer beginy = 20
  331. integer endx = 9
  332. integer endy = 168
  333. end type