system.bmx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. Strict
  2. Rem
  3. bbdoc: System/System
  4. End Rem
  5. Module BRL.System
  6. ModuleInfo "Version: 1.29"
  7. ModuleInfo "Author: Mark Sibly, Simon Armstrong"
  8. ModuleInfo "License: zlib/libpng"
  9. ModuleInfo "Copyright: Blitz Research Ltd"
  10. ModuleInfo "Modserver: BRL"
  11. ModuleInfo "History: 1.29"
  12. ModuleInfo "History: Split out into BRL.System and BRL.SystemDefault modules."
  13. ModuleInfo "History: 1.28"
  14. ModuleInfo "History: Added custom format option to CurrentDate()."
  15. ModuleInfo "History: 1.27"
  16. ModuleInfo "History: Moved event enums from system.h to event.mod/event.h"
  17. ModuleInfo "Histroy: Moved keycode enums from system.h to keycodes.mod/keycodes.h"
  18. ModuleInfo "History: 1.26 Release"
  19. ModuleInfo "History: Fixed win32 filerequester causing activewindow dramas"
  20. ModuleInfo "History: 1.25 Release"
  21. ModuleInfo "History: Fixed unretained object issue with mouse tracking"
  22. ModuleInfo "History: 1.24 Release"
  23. ModuleInfo "History: Fixed windowed mode HideMouse issue"
  24. ModuleInfo "History: 1.23 Release"
  25. ModuleInfo "History: Fixed win32 requestfile default extension bug#2"
  26. ModuleInfo "History: 1.22 Release"
  27. ModuleInfo "History: Fixed win32 requestfile default extension bug"
  28. ModuleInfo "History: 1.21 Release"
  29. ModuleInfo "History: New Linux implementation of OpenURL"
  30. ModuleInfo "History: 1.20 Release"
  31. ModuleInfo "History: RequestFile now adds extension to filename on Windows"
  32. ModuleInfo "History: 1.19 Release"
  33. ModuleInfo "History: Added EVENT_GADGETLOSTFOCUS handling"
  34. ModuleInfo "History: 1.18 Release"
  35. ModuleInfo "History: Added EVENT_KEYREPEAT handling"
  36. ModuleInfo "History: 1.17 Release"
  37. ModuleInfo "History: OpenURL now attempts to fully qualify file / http url supplied"
  38. ModuleInfo "History: 1.16 Release"
  39. ModuleInfo "History: Fixed MacOS RequestFile to respect wild card filter"
  40. ModuleInfo "History: 1.15 Release"
  41. ModuleInfo "History: Fixed mouse hidden by default"
  42. ModuleInfo "History: 1.14 Release"
  43. ModuleInfo "History: Fixed HideMouse causing mouse to disappear when in non-client areas"
  44. ModuleInfo "History: 1.13 Release"
  45. ModuleInfo "History: Fixed Linux MoveMouse to be relative to the origin of the current Graphics window"
  46. ModuleInfo "History: 1.12 Release"
  47. ModuleInfo "History: Added Linux X11 import to remove glgraphics.mod dependency"
  48. ModuleInfo "History: Fixed linux middle button crash"
  49. ModuleInfo "History: 1.11 Release"
  50. ModuleInfo "History: Fixed win32 clipboard glitches with QS_ALLINPUT bbSystemWait mod"
  51. ModuleInfo "History: 1.11 Release"
  52. ModuleInfo "History: CGSetLocalEventsSuppressionInterval fix for MacOS bbSystemMoveMouse"
  53. ModuleInfo "History: 1.10 Release"
  54. ModuleInfo "History: Ripped out input stuff and added hook"
  55. ModuleInfo "History: 1.09 Release"
  56. ModuleInfo "History: Tweaked MacOS GetChar()"
  57. ModuleInfo "History: 1.07 Release"
  58. ModuleInfo "History: Added AppTitle support for requesters"
  59. ModuleInfo "History: 1.06 Release"
  60. ModuleInfo "History: Fixed MacOS RequestDir ignoring initial path"
  61. ModuleInfo "History: 1.05 Release"
  62. ModuleInfo "History: Added RequestDir support for MacOS"
  63. ModuleInfo "History: 1.04 Release"
  64. ModuleInfo "History: Added mouse capture to Win32"
  65. ModuleInfo "History: Fixed C Compiler warnings"
  66. Import BRL.Event
  67. Import BRL.KeyCodes
  68. Import BRL.Hook
  69. Import BRL.FileSystem
  70. Import Pub.StdC
  71. Import "driver.bmx"
  72. Private
  73. Global _busy
  74. Public
  75. Rem
  76. bbdoc: Poll operating system
  77. about:
  78. #PollSystem returns control back to the operating system, allowing such
  79. events as keystrokes and gadget actions to be processed. Control is then
  80. returned back to your program.
  81. If #PollSystem encounters a key, mouse or app suspend/resume/terminate
  82. event, an equivalent #TEvent object event will be generated which may be intercepted using
  83. the #EmitEventHook hook.
  84. End Rem
  85. Function PollSystem()
  86. If _busy Return
  87. _busy=True
  88. SystemDriver().Poll
  89. _busy=False
  90. End Function
  91. Rem
  92. bbdoc: Wait for operating system
  93. about:
  94. #WaitSystem returns control back to the operating system, waiting until
  95. an event such as a keystroke or gadget action occurs.
  96. Note that #WaitSystem may wait indefinitely if there is no possibility
  97. of any events occuring, so use with caution.
  98. If #WaitSystem encounters a key, mouse or app suspend/resume/terminate
  99. event, an equivalent #TEvent object will be generated which may be intercepted using
  100. the #EmitEventHook hook.
  101. End Rem
  102. Function WaitSystem()
  103. If _busy Return
  104. _busy=True
  105. SystemDriver().Wait
  106. _busy=False
  107. End Function
  108. Rem
  109. bbdoc: Move mouse pointer
  110. about:
  111. #MoveMouse positions the mouse cursor at a specific location within
  112. the current window or graphics display.
  113. End Rem
  114. Function MoveMouse( x,y )
  115. SystemDriver().MoveMouse x,y
  116. End Function
  117. Rem
  118. bbdoc: Make the mouse pointer visible
  119. End Rem
  120. Function ShowMouse()
  121. SystemDriver().SetMouseVisible True
  122. End Function
  123. Rem
  124. bbdoc: Make the mouse pointer invisible
  125. End Rem
  126. Function HideMouse()
  127. SystemDriver().SetMouseVisible False
  128. End Function
  129. Rem
  130. bbdoc: Notify user
  131. about:
  132. #Notify activates a simple user interface element informing the user of an event.
  133. The optional @serious flag can be used to indicate a 'critical' event.
  134. Note that a user interface may not be available when in graphics mode on some platforms.
  135. End Rem
  136. Function Notify( text:String,serious=False )
  137. SystemDriver().Notify text,serious
  138. End Function
  139. Rem
  140. bbdoc: Request user confirmation.
  141. returns: True or False depending on the user's selection
  142. about:
  143. #Confirm activates a simple user interface element requesting the user to select between
  144. YES and NO options. If the user selects YES, then #Confirm returns True. Otherwise,
  145. False is returned.
  146. Note that a user interface may not be available when in graphics mode on some platforms.
  147. End Rem
  148. Function Confirm( text:String,serious=False )
  149. Return SystemDriver().Confirm( text,serious )
  150. End Function
  151. Rem
  152. bbdoc: Request user confirmation or cancellation.
  153. returns: 1, 0 or -1 depending on the user's selection
  154. about:
  155. #Proceed activates a simple user interface element requesting the user to select between
  156. YES, NO and CANCEL options. If the user selects YES, then #Proceed return 1. If the user
  157. selects NO, then #Proceed returns 0. Otherwise, #Proceed returns -1.
  158. Note that a user interface may not be available when in graphics mode on some platforms.
  159. End Rem
  160. Function Proceed( text:String,serious=False )
  161. Return SystemDriver().Proceed( text,serious )
  162. End Function
  163. Rem
  164. bbdoc: Display system file requester.
  165. returns: The path of the selected file or an empty string if the operation was cancelled.
  166. about:
  167. @text is used as the title of the file requester.
  168. The optional @extensions string can either be a comma separated list of
  169. file extensions or as in the following example groups of extensions
  170. that begin with a "group:" and separated by a semicolon.
  171. @save_flag can be True to create a save-style requester, or False to create a load-style requester.
  172. @initial_path is the initial path for the file requester.
  173. Note that a user interface may not be available when in graphics mode on some platforms.
  174. End Rem
  175. Function RequestFile:String( text:String,extensions:String="",save_flag=False,initial_path:String="" )
  176. Return SystemDriver().RequestFile( text,extensions,save_flag,initial_path )
  177. End Function
  178. Rem
  179. bbdoc: Display system folder requester.
  180. returns: The path of the selected folder or an empty string if the operation was cancelled.
  181. about:
  182. @text is used as the title of the file requester.
  183. @initial_path is the initial path for the folder requester.
  184. Note that a user interface may not be available when in graphics mode on some platforms.
  185. End Rem
  186. Function RequestDir:String( text:String,initial_path:String="" )
  187. Return SystemDriver().RequestDir( text,initial_path )
  188. End Function
  189. Rem
  190. bbdoc: Opens a URL with the system's default web browser.
  191. about: Note that a user interface may not be available when in graphics mode on some platforms.
  192. End Rem
  193. Function OpenURL( url:String )
  194. Local dev:String,anchor:String
  195. dev=url[..5].toLower()
  196. If dev<>"http:" And dev<>"file:" And url[..6].ToLower()<>"https:"
  197. Local h=url.find("#")
  198. If h>-1
  199. anchor=url[h..]
  200. url=url[..h]
  201. EndIf
  202. Local f:String=RealPath(url)
  203. If FileType(f)
  204. url="file:"+f +anchor
  205. Else
  206. url="http:"+url+anchor
  207. EndIf
  208. EndIf
  209. Return SystemDriver().OpenURL( url )
  210. End Function
  211. Rem
  212. bbdoc: Get desktop width
  213. returns: Width of the desktop, in pixels
  214. End Rem
  215. Function DesktopWidth(display:Int = 0)
  216. Return SystemDriver().DesktopWidth(display)
  217. End Function
  218. Rem
  219. bbdoc: Get desktop height
  220. returns: Height of the desktop, in pixels
  221. End Rem
  222. Function DesktopHeight(display:Int = 0)
  223. Return SystemDriver().DesktopHeight(display)
  224. End Function
  225. Rem
  226. bbdoc: Get desktop depth
  227. returns: Bits per pixel depth of the desktop
  228. about:
  229. The depth of the desktop is the number of bits per pixel.
  230. Note that on some platforms this function may return 0 if the desktop depth cannot be determined.
  231. End Rem
  232. Function DesktopDepth(display:Int = 0)
  233. Return SystemDriver().DesktopDepth(display)
  234. End Function
  235. Rem
  236. bbdoc: Get desktop refresh rate
  237. returns: Refresh rate, in cycles per second, of the desktop
  238. about:
  239. Note that on some platforms this function may return 0 if the desktop refresh rate cannot be determined.
  240. End Rem
  241. Function DesktopHertz(display:Int = 0)
  242. Return SystemDriver().DesktopHertz(display)
  243. End Function
  244. 'End Extern