bigsearch.bmx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. Import MaxGui.Drivers
  2. AppTitle = "BigSearch"
  3. Const Views = 1'3 ' Update this if you add more searches in DefData lines below!
  4. Global HTML:TGadget [Views]
  5. Global HTMLTitle$ [Views]
  6. Global HTMLURL$ [Views]
  7. gadheight = 24
  8. For site = 0 To Views - 1
  9. ReadData HTMLTitle (site)
  10. ReadData HTMLURL (site)
  11. Next
  12. ' Some random examples...
  13. 'DefData "Google", "http://www.google.com/search?q="
  14. 'DefData "Yahoo", "http://search.yahoo.com/search?p="
  15. DefData "Merriam-Webster Dictionary", "http://www.m-w.com/cgi-bin/dictionary?"
  16. Load = ReadFile ("window.dat")
  17. If Load
  18. x = Int (ReadLine (Load))
  19. y = Int (ReadLine (Load))
  20. width = Int (ReadLine (Load))
  21. height = Int (ReadLine (Load))
  22. EndIf
  23. If x < 0 Then x = 0
  24. If x > GadgetWidth (Desktop ()) x = 0
  25. If y < 0 Then x = 0
  26. If y > GadgetHeight (Desktop ()) x = 0
  27. If width <= 0 width = 640
  28. If height <= 0 height = 480
  29. window:TGadget = CreateWindow ("BigSearch", x, y, width, height)
  30. htmlheight = (ClientHeight (window) - gadheight) / Views
  31. If window
  32. file:TGadget = CreateMenu ("&File", 0, WindowMenu (window))
  33. xit:TGadget = CreateMenu ("E&xit", 1, file)
  34. help:TGadget = CreateMenu ("&Help", 2, WindowMenu (window))
  35. about:TGadget = CreateMenu ("&About...", 3, help)
  36. UpdateWindowMenu window
  37. search:TGadget = CreateTextField (4, 4, ClientWidth (window) - 152, gadheight, window)
  38. go:TGadget = CreateButton ("Search!", ClientWidth (window) - 144, 4, 140, gadheight, window, BUTTON_OK)
  39. SetGadgetLayout search, 1, 1, 1, 0
  40. SetGadgetLayout go, 0, 1, 1, 0
  41. tab:TGadget = CreateTabber (0, gadheight+4, ClientWidth (window), ClientHeight (window) - gadheight - 4, window)
  42. panel:TGadget = CreatePanel (0, 0, ClientWidth (tab), ClientHeight (tab), tab)
  43. SetGadgetLayout tab, 1, 1, 1, 1
  44. SetGadgetLayout panel, 1, 1, 1, 1
  45. For loop = 0 To Views - 1
  46. HTML (loop) = CreateHTMLView (0, 0, ClientWidth (panel), ClientHeight (panel), panel)
  47. SetGadgetLayout HTML (loop), 1, 1, 1, 1
  48. HideGadget HTML (loop)
  49. AddGadgetItem (tab, HTMLTitle (loop))
  50. Next
  51. ShowGadget HTML (0)
  52. SetStatusText window, "Done"
  53. urltimer:TTimer = CreateTimer (1)
  54. ActivateGadget search
  55. Repeat
  56. Select WaitEvent ()
  57. ' Print currentevent.toString()
  58. ' Select EventID()
  59. Case EVENT_GADGETACTION
  60. If (EventSource () = go)' Or ((EventSource () = search) And (EventData () = KEY_ENTER))
  61. For site = 0 To Views - 1
  62. HtmlViewGo HTML (site), HTMLURL (site) + TextFieldText (search)
  63. Next
  64. EndIf
  65. If EventSource () = tab
  66. For loop = 0 To Views - 1
  67. HideGadget HTML (loop)
  68. Next
  69. ShowGadget HTML (SelectedGadgetItem (tab))
  70. ActivateGadget HTML (SelectedGadgetItem (tab))
  71. EndIf
  72. Case EVENT_WINDOWCLOSE
  73. SaveWindow (window); End
  74. ' ****** Not working!
  75. Case EVENT_TIMERTICK
  76. ' DebugLog HtmlViewStatus (HTML (SelectedGadgetItem (tab)))
  77. If HtmlViewStatus (HTML (SelectedGadgetItem (tab)))
  78. SetStatusText window, "Loading..."
  79. Else
  80. SetStatusText window, "Done"
  81. EndIf
  82. ' Case EVENT_GADGETDONE
  83. ' DebugLog HtmlViewStatus (HTML (SelectedGadgetItem (tab)))
  84. Case EVENT_MENUACTION
  85. If EventData () = 1 Then SaveWindow (window); End
  86. If EventData () = 3 Then Notify ("BigSearch: it searches [tm]")
  87. End Select
  88. Forever
  89. EndIf
  90. Function SaveWindow (window:TGadget)
  91. If window
  92. save = WriteFile ("window.dat")
  93. If save
  94. WriteLine save, GadgetX (window)
  95. WriteLine save, GadgetY (window)
  96. WriteLine save, GadgetWidth (window)
  97. WriteLine save, GadgetHeight (window)
  98. CloseFile save
  99. EndIf
  100. EndIf
  101. End Function