gtkgui.bmx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. ' Copyright (c) 2006-2020 Bruce A Henderson
  2. '
  3. ' Permission is hereby granted, free of charge, to any person obtaining a copy
  4. ' of this software and associated documentation files (the "Software"), to deal
  5. ' in the Software without restriction, including without limitation the rights
  6. ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. ' copies of the Software, and to permit persons to whom the Software is
  8. ' furnished to do so, subject to the following conditions:
  9. '
  10. ' The above copyright notice and this permission notice shall be included in
  11. ' all copies or substantial portions of the Software.
  12. '
  13. ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. ' THE SOFTWARE.
  20. '
  21. SuperStrict
  22. Import "gtkcommon.bmx"
  23. Import "gtkgadget.bmx"
  24. ?linux
  25. Import "fdhandler.c"
  26. ?
  27. Import "gtkglue.c"
  28. Import "gdkevents.c"
  29. Global GTK3Driver:TGTK3GUIDriver =New TGTK3GUIDriver
  30. Type TGTK3GuiSystemDriver Extends TGTK3SystemDriver
  31. Field gui:TGTK3GUIDriver
  32. ?linux
  33. Field gsource:Byte Ptr
  34. ?
  35. Method Poll()
  36. While gtk_events_pending()
  37. gtk_main_iteration_do(False)
  38. ' bbSystemPoll() ' dont't think we need this now?
  39. Wend
  40. ?Not linux
  41. Super.Wait()
  42. ?
  43. End Method
  44. Method Wait()
  45. gtk_main_iteration_do(True)
  46. End Method
  47. Function Create:TGTK3GuiSystemDriver(host:TGTK3GUIDriver)
  48. Local guisystem:TGTK3GuiSystemDriver
  49. guisystem=New TGTK3GuiSystemDriver
  50. guisystem.gui=host
  51. ?linux
  52. ' attach max's fd to a glib event source so things like timers can work
  53. guisystem.gsource = bmx_gtk_event_source_new(bbSystemAsyncFD())
  54. ?
  55. Return guisystem
  56. End Function
  57. End Type
  58. ?bmxng
  59. Type TGTK3SystemDriver Extends TSystemDriver Implements IWrappedSystemDriver
  60. ?Not bmxng
  61. Type TGTK3SystemDriver Extends TSystemDriver
  62. ?
  63. Field NativeDriver:TSystemDriver
  64. Field _desktop:TGTKDesktop
  65. ?Not bmxng
  66. Method New()
  67. NativeDriver=brl.System.Driver
  68. End Method
  69. ?bmxng
  70. Method SetDriver(driver:TSystemDriver)
  71. NativeDriver = driver
  72. End Method
  73. Method GetDriver:TSystemDriver()
  74. Return NativeDriver
  75. End Method
  76. Method Name:String()
  77. Return "GTK3SystemDriver"
  78. End Method
  79. ?
  80. Method Poll()
  81. NativeDriver.Poll()
  82. End Method
  83. Method Wait()
  84. NativeDriver.Wait()
  85. End Method
  86. Method Emit( osevent:Byte Ptr,source:Object )
  87. Throw "oops"
  88. End Method
  89. Method IsFullScreen:Int()
  90. Return False
  91. End Method
  92. Method SetMouseVisible(bool:Int)
  93. NativeDriver.SetMouseVisible bool
  94. End Method
  95. Method MoveMouse( x:Int, y:Int )
  96. NativeDriver.MoveMouse x,y
  97. End Method
  98. Rem
  99. internal: Notify user.
  100. End Rem
  101. Method Notify( text:String, serious:Int )
  102. If text = Null Then
  103. text = ""
  104. End If
  105. serious = Max(0,Min(serious, 1))
  106. Local textPtr:Byte Ptr = text.ToUTF8String()
  107. Local req:Byte Ptr = gtk_message_dialog_new(Null, GTK_DIALOG_MODAL, serious, GTK_BUTTONS_OK, textPtr)
  108. MemFree(textPtr)
  109. Local res:Int = gtk_dialog_run(req)
  110. gtk_widget_destroy(req)
  111. End Method
  112. Rem
  113. internal: Request user confirmation.
  114. End Rem
  115. Method Confirm:Int( text:String, serious:Int )
  116. If text = Null Then
  117. text = ""
  118. End If
  119. serious = Max(0,Min(serious, 1))
  120. Local textPtr:Byte Ptr = text.ToUTF8String()
  121. Local req:Byte Ptr = gtk_message_dialog_new(Null, GTK_DIALOG_MODAL, serious, GTK_BUTTONS_YES_NO, textPtr)
  122. MemFree(textPtr)
  123. Local res:Int = gtk_dialog_run(req)
  124. gtk_widget_destroy(req)
  125. If res = GTK_RESPONSE_YES Then
  126. Return True
  127. Else
  128. Return False
  129. End If
  130. End Method
  131. Rem
  132. internal: Request user confirmation or cancellation.
  133. End Rem
  134. Method Proceed:Int( text:String, serious:Int )
  135. If text = Null Then
  136. text = ""
  137. End If
  138. serious = Max(0,Min(serious, 1))
  139. If Not serious Then
  140. serious = GTK_MESSAGE_QUESTION
  141. End If
  142. Local textPtr:Byte Ptr = text.ToUTF8String()
  143. Local req:Byte Ptr = gtk_message_dialog_new(Null, GTK_DIALOG_MODAL, serious, GTK_BUTTONS_YES_NO, textPtr)
  144. MemFree(textPtr)
  145. ' add a cancel button
  146. gtk_dialog_add_button(req, "_Cancel", GTK_RESPONSE_CANCEL)
  147. Local res:Int = gtk_dialog_run(req)
  148. gtk_widget_destroy(req)
  149. Select res
  150. Case GTK_RESPONSE_YES
  151. Return True
  152. Case GTK_RESPONSE_NO
  153. Return False
  154. Case GTK_RESPONSE_CANCEL
  155. Return -1
  156. End Select
  157. End Method
  158. Method RequestFile:String( text:String,exts:String, Save:Int,file:String )
  159. Local req:Byte Ptr
  160. Local f:String
  161. Local opensave:Int
  162. Local reqButton:String
  163. If Save Then
  164. opensave = GTK_FILE_CHOOSER_ACTION_SAVE
  165. reqButton = "_Save"
  166. Else
  167. opensave = GTK_FILE_CHOOSER_ACTION_OPEN
  168. reqButton = "_Open"
  169. End If
  170. If text = Null Or text.length = 0 Then
  171. req = gtk_file_chooser_dialog_new(Null, Null, ..
  172. opensave, "_Cancel", GTK_RESPONSE_CANCEL, ..
  173. reqButton, GTK_RESPONSE_ACCEPT, Null)
  174. Else
  175. Local textPtr:Byte Ptr = text.ToUTF8String()
  176. req = gtk_file_chooser_dialog_new(textPtr, Null, ..
  177. opensave, "_Cancel", GTK_RESPONSE_CANCEL, ..
  178. reqButton, GTK_RESPONSE_ACCEPT, Null)
  179. MemFree(textPtr)
  180. End If
  181. Local Current:String = CurrentDir()
  182. Local currentPtr:Byte Ptr = Current.ToUTF8String()
  183. gtk_file_chooser_set_current_folder(req, currentPtr)
  184. MemFree(currentPtr)
  185. ' set the path if there was one.
  186. If file <> Null And file.length > 0 Then
  187. If Not save And Not FileType(file) Then
  188. file = ""
  189. End If
  190. Local filePtr:Byte Ptr = file.ToUTF8String()
  191. gtk_file_chooser_set_filename(req, filePtr)
  192. MemFree(filePtr)
  193. End If
  194. ' set up filters, if any
  195. 'The optional extensions String can either be a comma separated list of file extensions
  196. 'or as in the following example groups of extensions that begin with a "group:" and separated
  197. 'by a semicolon.
  198. If exts Then
  199. Local groups:String[] = exts.Split(";")
  200. For Local group:Int = 0 Until groups.length
  201. If groups[group].length > 0 Then
  202. Local pairs:String[] = groups[group].Split(":")
  203. Local name:String = Null
  204. Local ex:String[]
  205. If pairs.length = 1 Then
  206. ex = pairs[0].Split(",")
  207. Else
  208. name = pairs[0]
  209. ex = pairs[1].Split(",")
  210. End If
  211. ' add a filter
  212. Local filter:Byte Ptr = gtk_file_filter_new()
  213. If name <> Null Then
  214. Local namePtr:Byte Ptr = name.ToUTF8String()
  215. gtk_file_filter_set_name(filter, namePtr)
  216. MemFree(namePtr)
  217. End If
  218. For Local i:Int = 0 Until ex.length
  219. Local s:String = ex[i].Trim()
  220. If s <> "*" Then
  221. s = "*." + s
  222. End If
  223. Local sPtr:Byte Ptr = s.ToUTF8String()
  224. gtk_file_filter_add_pattern(filter, sPtr)
  225. MemFree(sPtr)
  226. Next
  227. gtk_file_chooser_add_filter(req, filter)
  228. ' we don't need to clean up the filter object, as gtk takes ownership of it when
  229. ' we add it to the chooser.
  230. End If
  231. Next
  232. End If
  233. Local res:Int = gtk_dialog_run(req)
  234. If res = GTK_RESPONSE_ACCEPT Then
  235. Local fptr:Byte Ptr = gtk_file_chooser_get_filename(req)
  236. If fptr Then
  237. f = String.FromUTF8String(fptr)
  238. g_free(fptr)
  239. End If
  240. End If
  241. gtk_widget_destroy(req)
  242. Return f
  243. End Method
  244. Method RequestDir:String( text:String, path:String )
  245. Local p:String = Null
  246. Local req:Byte Ptr
  247. If text = Null Or text.length = 0 Then
  248. req = gtk_file_chooser_dialog_new(Null, Null, ..
  249. GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Cancel", GTK_RESPONSE_CANCEL, ..
  250. "_Open", GTK_RESPONSE_ACCEPT, Null)
  251. Else
  252. Local textPtr:Byte Ptr = text.ToUTF8String()
  253. req = gtk_file_chooser_dialog_new(textPtr, Null, ..
  254. GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Cancel", GTK_RESPONSE_CANCEL, ..
  255. "_Open", GTK_RESPONSE_ACCEPT, Null)
  256. MemFree(textPtr)
  257. End If
  258. ' set the path if there was one.
  259. If path <> Null And path.length > 0 Then
  260. ' just in case the path is bad.. we'll set it to current
  261. If Not FileType(path) Then
  262. path = CurrentDir()
  263. End If
  264. Else
  265. path = CurrentDir()
  266. End If
  267. Local pathPtr:Byte Ptr = path.ToUTF8String()
  268. gtk_file_chooser_set_current_folder(req, pathPtr)
  269. gtk_file_chooser_set_filename(req, pathPtr)
  270. MemFree(pathPtr)
  271. Local res:Int = gtk_dialog_run(req)
  272. If res = GTK_RESPONSE_ACCEPT Then
  273. Local f:Byte Ptr = gtk_file_chooser_get_filename(req)
  274. If f Then
  275. p = String.FromUTF8String(f)
  276. g_free(f)
  277. End If
  278. End If
  279. gtk_widget_destroy(req)
  280. Return p
  281. End Method
  282. Method OpenURL:Int( url:String )
  283. Return NativeDriver.OpenURL(url)
  284. End Method
  285. Method DesktopWidth:Int(display:Int) Override
  286. If Not _desktop Then
  287. _desktop = TGTKDesktop.CreateDesktop()
  288. End If
  289. Return _desktop.ClientWidth()
  290. End Method
  291. Method DesktopHeight:Int(display:Int) Override
  292. If Not _desktop Then
  293. _desktop = TGTKDesktop.CreateDesktop()
  294. End If
  295. Return _desktop.ClientHeight()
  296. End Method
  297. Method DesktopDepth:Int(display:Int) Override
  298. If Not _desktop Then
  299. _desktop = TGTKDesktop.CreateDesktop()
  300. End If
  301. Return _desktop.GetDepth()
  302. End Method
  303. Method DesktopHertz:Int(display:Int) Override
  304. If Not _desktop Then
  305. _desktop = TGTKDesktop.CreateDesktop()
  306. End If
  307. Return _desktop.GetHertz()
  308. End Method
  309. End Type
  310. Type TGTK3GUIDriver Extends TMaxGUIDriver
  311. Method New()
  312. ?bmxng
  313. InitSystemDriver(TGTK3GuiSystemDriver.Create(Self))
  314. ?Not bmxng
  315. brl.System.Driver=TGTK3GuiSystemDriver.Create(Self)
  316. ?
  317. gtk_init(Null, Null)
  318. maxgui_driver=Self
  319. End Method
  320. Method LoadFont:TGuiFont(name:String, size:Int, flags:Int)
  321. Local font:TGuiFont = New TGTKGuiFont
  322. font.name = name
  323. font.size = size
  324. font.style = flags
  325. Return DoLoadFont(font)
  326. End Method
  327. Method DoLoadFont:TGuiFont(font:TGuiFont, automaticFallback:Int = False )
  328. Local widget:Byte Ptr = gtk_label_new(Null)
  329. Local _context:Byte Ptr = gtk_widget_get_pango_context(widget)
  330. getPangoDescriptionFromGuiFont(TGtkGuiFont(font))
  331. 'Local fontdesc:Byte Ptr = font.fontDesc
  332. Local _fontset:Byte Ptr = pango_context_load_fontset(_context, TGtkGuiFont(font).fontDesc, Null)
  333. If automaticFallback
  334. pango_fontset_foreach(_fontset, fontforeachFallback, font)
  335. Else
  336. pango_fontset_foreach(_fontset, fontforeach, font)
  337. EndIf
  338. 'pango_font_description_free(fontdesc)
  339. gtk_widget_destroy(widget)
  340. g_object_unref(_context)
  341. If font.path = "OK!" Then
  342. font.path = ""
  343. Return font
  344. Else
  345. Select font.name
  346. Case "Lucida"
  347. font.name = "DejaVu Sans Mono"
  348. clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
  349. font = DoLoadFont(font)
  350. Case "DejaVu Sans Mono"
  351. font.name = "Droid Sans Mono"
  352. clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
  353. font = DoLoadFont(font)
  354. Case "Droid Sans Mono"
  355. font.name = "FreeMono"
  356. clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
  357. font = DoLoadFont(font)
  358. Case "FreeMono"
  359. font.name = "Monospace"
  360. clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
  361. font = DoLoadFont(font, True)
  362. Case "MonoSpace"
  363. Return Null
  364. Default ' try a default...
  365. font.name = "Lucida"
  366. clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
  367. font = DoLoadFont(font)
  368. End Select
  369. If font Then
  370. Return font
  371. End If
  372. Return Null
  373. End If
  374. End Method
  375. Method LibraryFont:TGuiFont( fontType:Int = GUIFONT_SYSTEM, size:Double = 0, style:Int = FONT_NORMAL )
  376. If fontType = GUIFONT_SYSTEM Then
  377. Local widget:Byte Ptr = gtk_label_new(Null)
  378. Local defaultStyle:Byte Ptr = gtk_widget_get_style_context(widget)
  379. Local font:Byte Ptr = bmx_gtk3_stylecontext_get_fontdesc(defaultStyle)
  380. Local f:TGuiFont = getGuiFontFromPangoDescription(font)
  381. TGtkGuiFont(f).fontDesc = Null
  382. gtk_widget_destroy(widget)
  383. If size <= 0 Then
  384. size = f.size
  385. End If
  386. Return LoadFontWithDouble( f.name, size, f.style | style )
  387. Else
  388. Return Super.LibraryFont( fontType, size, style )
  389. EndIf
  390. End Method
  391. Method LoadFontWithDouble:TGuiFont(name:String, size:Double, flags:Int)
  392. Local font:TGuiFont = New TGTKGuiFont
  393. font.name = name
  394. font.size = size
  395. font.style = flags
  396. Return DoLoadFont(font)
  397. End Method
  398. Function fontforeach:Int(fontset:Byte Ptr, _font:Byte Ptr, data:Object)
  399. Local fontdesc:Byte Ptr = pango_font_describe(_font)
  400. Local thisfont:TGuiFont = getGuiFontFromPangoDescription(fontdesc)
  401. If thisfont.name.toLower() = TGuiFont(data).name.tolower() Then
  402. TGuiFont(data).name = thisfont.name
  403. TGuiFont(data).path = "OK!"
  404. Return True
  405. End If
  406. End Function
  407. Function fontforeachFallback:Int(fontset:Byte Ptr, _font:Byte Ptr, data:Object)
  408. Local fontdesc:Byte Ptr = pango_font_describe(_font)
  409. Local thisfont:TGuiFont = getGuiFontFromPangoDescription(fontdesc)
  410. TGuiFont(data).name = thisfont.name
  411. TGuiFont(data).path = "OK!"
  412. Return True
  413. End Function
  414. Method CreateGadget:TGadget(GadgetClass:Int, name:String, x:Int, y:Int, w:Int, h:Int,group:TGadget, style:Int)
  415. Local gadget:TGTKGadget
  416. Local gtkclass:Int = -1
  417. Local gtkGroup:TGTKGadget
  418. Select GadgetClass
  419. Case GADGET_DESKTOP
  420. Return TGTKDesktop.CreateDesktop()
  421. Case GADGET_WINDOW
  422. gtkclass = GTK_WINDOW
  423. Case GADGET_BUTTON
  424. gtkclass = GTK_BUTTON
  425. Select style
  426. Case BUTTON_CHECKBOX,BUTTON_CHECKBOX|BUTTON_PUSH
  427. gtkclass = GTK_CHECKBUTTON
  428. Case BUTTON_RADIO,BUTTON_RADIO|BUTTON_PUSH
  429. gtkclass = GTK_RADIOBUTTON
  430. Case BUTTON_OK
  431. Case BUTTON_CANCEL
  432. End Select
  433. Case GADGET_PANEL
  434. gtkclass = GTK_PANEL
  435. Case GADGET_TEXTFIELD
  436. gtkclass = GTK_TEXTFIELD
  437. Case GADGET_TEXTAREA
  438. gtkclass = GTK_TEXTAREA
  439. Case GADGET_COMBOBOX
  440. gtkclass = GTK_COMBOBOX
  441. Case GADGET_LISTBOX
  442. gtkclass = GTK_LISTBOX
  443. Case GADGET_TOOLBAR
  444. gtkclass = GTK_TOOLBAR
  445. Case GADGET_TABBER
  446. gtkclass = GTK_TABBER
  447. Case GADGET_TREEVIEW
  448. gtkclass = GTK_TREEVIEW
  449. Case GADGET_HTMLVIEW
  450. gtkclass = GTK_HTMLVIEW
  451. Case GADGET_LABEL
  452. gtkclass = GTK_LABEL
  453. Case GADGET_SLIDER
  454. If style & SLIDER_STEPPER Then
  455. gtkclass = GTK_STEPPER
  456. Else If style & SLIDER_TRACKBAR Then
  457. gtkclass = GTK_TRACKBAR
  458. Else
  459. gtkclass = GTK_SCROLLBAR
  460. End If
  461. Case GADGET_PROGBAR
  462. gtkclass = GTK_PROGRESSBAR
  463. Case GADGET_MENUITEM
  464. gtkclass = GTK_MENUITEM
  465. Case GADGET_CANVAS
  466. gtkclass = GTK_CANVAS
  467. End Select
  468. gtkgroup = TGTKGadget(group)
  469. If gtkclass > -1 Then
  470. gadget = TGTKGadget.Create(gtkclass, x, y, w, h, name, gtkgroup, style, GadgetClass)
  471. End If
  472. Return gadget
  473. End Method
  474. Rem
  475. internal: Returns the currently active gadget.
  476. End Rem
  477. Method ActiveGadget:TGadget()
  478. For Local w:TGTKWindow = EachIn gtkWindows
  479. ' get the focussed widget for the window
  480. Local widget:Byte Ptr = gtk_window_get_focus(w.handle)
  481. If widget Then ' we need a gadget to test!
  482. ' but is this window currently in focus (belonging to the toplevel window?)
  483. If gtk_widget_has_focus(widget) Then
  484. Return GadgetFromHandle(widget)
  485. End If
  486. End If
  487. Next
  488. End Method
  489. Rem
  490. internal: Pops up a color requester
  491. End Rem
  492. Method RequestColor:Int(r:Int, g:Int, b:Int)
  493. Local argb:Int = Null
  494. Local color:GdkRGBA = New GdkRGBA
  495. color.red = r / 255.0
  496. color.green = g / 255.0
  497. color.blue = b / 255.0
  498. Local req:Byte Ptr = gtk_color_selection_dialog_new("Select color")
  499. Local colsel:Byte Ptr = gtk_color_selection_dialog_get_color_selection(req)
  500. gtk_color_selection_set_current_rgba(colsel, color)
  501. Local res:Int = gtk_dialog_run(req)
  502. If res = GTK_RESPONSE_OK Then
  503. gtk_color_selection_get_current_rgba(colsel, color)
  504. argb = $ff000000 | (color.red * 255) Shl 16 | (color.green * 255) Shl 8 | (color.blue * 255)
  505. End If
  506. gtk_widget_destroy(req)
  507. Return argb
  508. End Method
  509. Rem
  510. internal: Pops up a font requester.
  511. End Rem
  512. Method RequestFont:TGuiFont(font:TGuiFont)
  513. Local req:Byte Ptr = gtk_font_chooser_dialog_new("Choose font", Null)
  514. If font Then
  515. getPangoDescriptionFromGuiFont(TGtkGuiFont(font))
  516. gtk_font_chooser_set_font_desc(req, TGtkGuiFont(font).fontDesc)
  517. End If
  518. Local res:Int = gtk_dialog_run(req)
  519. If res = GTK_RESPONSE_OK Then
  520. ' the requestor returns a Pango font description... so we need to
  521. Local fontdesc:Byte Ptr = gtk_font_chooser_get_font_desc(req)
  522. font = getGuiFontFromPangoDescription(fontdesc)
  523. End If
  524. gtk_widget_destroy(req)
  525. Return font
  526. End Method
  527. Method SetPointer:Int(shape:Int)
  528. Local screen:Byte Ptr = gdk_screen_get_default()
  529. Local cursorType:Int
  530. Select shape
  531. 'Case POINTER_DEFAULT
  532. 'Case POINTER_ARROW
  533. Case POINTER_IBEAM
  534. cursorType = GDK_XTERM
  535. Case POINTER_WAIT
  536. cursorType = GDK_WATCH
  537. Case POINTER_CROSS
  538. cursorType = GDK_CROSSHAIR
  539. Case POINTER_UPARROW
  540. cursorType = GDK_CENTER_PTR
  541. Case POINTER_SIZENWSE
  542. cursorType = GDK_TOP_LEFT_CORNER
  543. Case POINTER_SIZENESW
  544. cursorType = GDK_TOP_RIGHT_CORNER
  545. Case POINTER_SIZEWE
  546. cursorType = GDK_SB_H_DOUBLE_ARROW
  547. Case POINTER_SIZENS
  548. cursorType = GDK_SB_V_DOUBLE_ARROW
  549. Case POINTER_SIZEALL
  550. cursorType = GDK_FLEUR
  551. Case POINTER_NO
  552. cursorType = GDK_PIRATE
  553. Case POINTER_HAND
  554. cursorType = GDK_HAND2
  555. Case POINTER_APPSTARTING
  556. cursorType = GDK_WATCH
  557. Case POINTER_HELP
  558. cursorType = GDK_QUESTION_ARROW
  559. Default
  560. cursorType = GDK_LEFT_PTR
  561. End Select
  562. Local cursor:Byte Ptr = gdk_cursor_new_for_display(gdk_screen_get_display(screen), cursorType)
  563. For Local window:TGTKWindow = EachIn gtkWindows
  564. If gtk_widget_get_window(window.handle) Then
  565. gdk_window_set_cursor(gtk_widget_get_window(window.handle), cursor)
  566. End If
  567. Next
  568. End Method
  569. Method LoadIconStrip:TIconStrip(source:Object)
  570. Return TGTKIconStrip.Create(source)
  571. End Method
  572. Method UserName$()
  573. End Method
  574. Method ComputerName$()
  575. End Method
  576. Rem
  577. bbdoc: Sets the clipboard with the current text
  578. End Rem
  579. Method SetClipboardText(text:String)
  580. Local clipboard:Byte Ptr = gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", True))
  581. Local textPtr:Byte Ptr = text.ToUTF8String()
  582. gtk_clipboard_set_text(clipboard, textPtr, -1)
  583. MemFree(textPtr)
  584. End Method
  585. Rem
  586. bbdoc: Gets the text from the clipboard
  587. End Rem
  588. Method ClipboardText:String()
  589. Local clipboard:Byte Ptr = gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", True))
  590. Local txtPtr:Byte Ptr = gtk_clipboard_wait_for_text(clipboard)
  591. Local s:String = String.FromUTF8String(txtPtr)
  592. g_free(txtPtr)
  593. Return s
  594. End Method
  595. End Type
  596. Function GadgetFromHandle:TGTKGadget( handle:Byte Ptr )
  597. Return TGTKGadget( GadgetMap.ValueForKey( handle ) )
  598. End Function
  599. Rem
  600. bbdoc: Sets the tooltip text for the gadget.
  601. about: Note: Until BRL add gadget tooltip functionality, consider this function API volatile.
  602. <p>Parameters:
  603. <ul>
  604. <li><b>gadget</b> : the gadget to apply the tooltip</li>
  605. <li><b>tip</b> : the tooltip text or Null to clear</li>
  606. </ul>
  607. </p>
  608. End Rem
  609. 'Function SetGadgetToolTip(gadget:TGadget, tip:String)
  610. ' TGTKGadget(gadget).setToolTip(tip)
  611. 'End Function
  612. Rem
  613. bbdoc: Sets the application icon.
  614. about: Note: Until BRL add app icon functionality, consider this function API volatile.
  615. End Rem
  616. Function SetAppIcon(pix:TPixmap)
  617. ' If pix <> Null Then
  618. ' Local pixmap:TPixmap
  619. ' If pix.format <> PF_RGBA8888 Then
  620. ' pixmap = pix.convert( PF_RGBA8888 )
  621. ' Else
  622. ' pixmap = pix
  623. ' End If
  624. '
  625. ' Local icon:Byte Ptr = gdk_pixbuf_new_from_data(pixmap.pixels, GDK_COLORSPACE_RGB, True, 8, ..
  626. ' pixmap.width, pixmap.height, pixmap.Pitch, Null, Null)
  627. ' gtk_window_set_default_icon(icon)
  628. ' End If
  629. End Function
  630. Rem
  631. bbdoc: Sets the button image using the specified pixmap.
  632. about: Note: Until BRL add button image functionality, consider this function API volatile.
  633. End Rem
  634. Function SetButtonPixmap(gadget:TGadget, pixmap:TPixmap)
  635. ' If TGTKButtonPush(gadget) And pixmap Then
  636. ' TGTKButtonPush(gadget).setPixmap(pixmap)
  637. ' End If
  638. End Function
  639. Rem
  640. bbdoc: Returns pointer coordinates relative to window.
  641. End Rem
  642. Function GetWindowPointerPos(window:TGadget, x:Int Var, y:Int Var)
  643. 'If TGTKWindow(window) Then
  644. ' gtk_widget_get_pointer(TGTKWindow(window).handle, x, y)
  645. 'End If
  646. End Function
  647. Rem
  648. bbdoc: Returns pointer coordinates relative to the screen.
  649. End Rem
  650. Function GetScreenPointerPos(x:Int Var, y:Int Var)
  651. ' gdk_display_get_pointer(gdk_display_get_default(), Null, x, y, Null)
  652. End Function
  653. ?linux
  654. Extern
  655. Function bmx_gtk_event_source_new:Byte Ptr(fd:Int)
  656. End Extern
  657. ?