system.bmx 9.3 KB

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