1 ; +------------------+
2 ; | PureHTML Windows |
3 ; +------------------+
4
5 ;-
6 ;- Constants
7
8
9 ; Special "Gadget Height" Constant,
10 ; OS-dependent and affects most property fields
11 #GH = WLMO(22, 20, 22, 20)
12
13
14
15 ; Gadget IDs
16 Enumeration
17 #PHG_IOFrame
18 #PHG_InFileOption
19 #PHG_InFile
20 #PHG_InFileBrowse
21 #PHG_InFileOpen
22 #PHG_OutFileText
23 #PHG_OutFile
24 #PHG_OutFileBrowse
25 #PHG_OutFileOpen
26 #PHG_InPathOption
27 #PHG_InPath
28 #PHG_InPathBrowse
29 #PHG_InPathOpen
30
31 #PHG_ConfigFrame
32 #PHG_FontText
33 #PHG_FontName
34 #PHG_FontSize
35 #PHG_FontPick
36 #PHG_BGText
37 #PHG_BGColor
38 #PHG_TabText
39 #PHG_TabLength
40 #PHG_LineNumbers
41 #PHG_LNColor
42 #PHG_HideIDE
43 #PHG_Links
44
45 #PHG_StyleFrame
46 #PHG_StyleText
47 #PHG_StyleBox
48 #PHG_StyleColorText
49 #PHG_StyleColor
50 #PHG_StyleBold
51 #PHG_StyleItalic
52 #PHG_StyleUnderline
53 #PHG_StyleStrike
54
55 #PHG_Generate
56 #PHG_OpenDone
57 #PHG_Close
58 #PHG_Import
59 #PHG_Export
60 #PHG_About
61 EndEnumeration
62
63 ; Menu Item IDs
64 Enumeration
65 #PHM_Generate
66 #PHM_Close
67 #PHM_About
68 ;
69 #PHM_CopyRGB
70 #PHM_PasteRGB
71 #PHM_CopyBGR
72 #PHM_PasteBGR
73 #PHM_Invert
74 ;
75 #PHM_Nothing
76 EndEnumeration
77
78 ; Window IDs
79 Enumeration
80 #PHW_Main
81 #PHW_Canvas
82 EndEnumeration
83
84
85
86
87 ;- Variables
88
89 Global ClickedCanvas.i = #Null
90
91
92
93
94 ;-
95 ;- Procedures
96
97 Declare.s CSSColor(Color.i)
98
99 ; Color a CanvasGadget and store color in GadgetData
100 Procedure ColorCanvas(Gadget.i, Color.i)
101 If (StartDrawing(CanvasOutput(Gadget)))
102 Box(0, 0, OutputWidth(), OutputHeight(), Color)
103 StopDrawing()
104 EndIf
105 SetGadgetData(Gadget, Color)
106 EndProcedure
107
108 Procedure CanvasMenu(ID.i)
109 If (IsGadget(ID))
110 ClickedCanvas = ID
111 SetMenuItemText(#PHW_Canvas, #PHM_Nothing, "Value: " + CSSColor(GetGadgetData(ID)))
112 DisplayPopupMenu(#PHW_Canvas, WindowID(#PHW_Main))
113 Else
114 ClickedCanvas = #Null
115 EndIf
116 EndProcedure
117
118 Procedure.i SwapRGB(Color.i)
119 ProcedureReturn RGB(Blue(Color), Green(Color), Red(Color))
120 EndProcedure
121
122 Procedure CopyCanvas(RRGGBB.i = #True)
123 If (ClickedCanvas)
124 If (RRGGBB)
125 SetClipboardText("#" + RSet(Hex(SwapRGB(GetGadgetData(ClickedCanvas))), 6, "0"))
126 Else
127 SetClipboardText("$" + RSet(Hex(GetGadgetData(ClickedCanvas)), 6, "0"))
128 EndIf
129 ClickedCanvas = #Null
130 EndIf
131 EndProcedure
132
133 Procedure PasteCanvas(RRGGBB.i = #True)
134 Protected Input.s = GetClipboardText()
135
136 CompilerIf (#True)
137 If (Left(Input, 1) = "#")
138 RRGGBB = #True
139 ElseIf (Left(Input, 1) = "$")
140 RRGGBB = #False
141 EndIf
142 CompilerEndIf
143
144 Input = Trim(Input, "#")
145 Input = Trim(Input, "$")
146
147 If (ClickedCanvas And (Len(Input) = 6))
148 If (RRGGBB)
149 ColorCanvas(ClickedCanvas, SwapRGB(Val("$" + Input)))
150 Else
151 ColorCanvas(ClickedCanvas, Val("$" + Input))
152 EndIf
153 If (ClickedCanvas = #PHG_StyleColor)
154 Style(GetGadgetState(#PHG_StyleBox))\Color = GetGadgetData(ClickedCanvas)
155 EndIf
156 ClickedCanvas = #Null
157 EndIf
158 EndProcedure
159
160 Procedure InvertCanvas()
161 If (ClickedCanvas)
162 ColorCanvas(ClickedCanvas, #White - GetGadgetData(ClickedCanvas))
163 If (ClickedCanvas = #PHG_StyleColor)
164 Style(GetGadgetState(#PHG_StyleBox))\Color = GetGadgetData(ClickedCanvas)
165 EndIf
166 ClickedCanvas = #Null
167 EndIf
168 EndProcedure
169
170
171
172 ;-
173 ;- Main Window
174
175
176 ; Update Main Window gadgets as appropriate
177 Procedure UpdateMainWindow()
178 Protected i.i
179
180 ; Single-file Mode
181 If (GetGadgetState(#PHG_InFileOption))
182 SetGadgetState(#PHG_InPathOption, #False)
183 DisableGadget(#PHG_InFile, #False)
184 DisableGadget(#PHG_OutFile, #False)
185 DisableGadget(#PHG_InPath, #True)
186
187 ; Multi-file (folder) Mode
188 Else
189 SetGadgetState(#PHG_InPathOption, #True)
190 DisableGadget(#PHG_InFile, #True)
191 DisableGadget(#PHG_OutFile, #True)
192 DisableGadget(#PHG_InPath, #False)
193 EndIf
194
195 ; InFile Open
196 If (GetGadgetText(#PHG_InFile))
197 DisableGadget(#PHG_InFileOpen, #False)
198 Else
199 DisableGadget(#PHG_InFileOpen, #True)
200 EndIf
201
202 ; OutFile Open
203 If (GetGadgetText(#PHG_OutFile))
204 DisableGadget(#PHG_OutFileOpen, #False)
205 Else
206 DisableGadget(#PHG_OutFileOpen, #True)
207 EndIf
208
209 ; InPath Open
210 If (GetGadgetText(#PHG_InPath))
211 DisableGadget(#PHG_InPathOpen, #False)
212 Else
213 DisableGadget(#PHG_InPathOpen, #True)
214 EndIf
215
216 EndProcedure
217
218
219 ; Update all style gadgets with the current configuration
220 Procedure UpdateForm()
221 Protected i.i
222
223 ; Update Settings Frame
224 SetGadgetText(#PHG_FontName, Config\FontName)
225 SetGadgetText(#PHG_FontSize, Str(Config\FontSize))
226 ColorCanvas(#PHG_BGColor, Config\BGColor)
227 SetGadgetText(#PHG_TabLength, Str(Config\TabLength))
228 SetGadgetState(#PHG_LineNumbers, Config\LineNumbers)
229 If (Config\LineNumbers)
230 HideGadget(#PHG_LNColor, #False)
231 Else
232 HideGadget(#PHG_LNColor, #True)
233 EndIf
234 ColorCanvas(#PHG_LNColor, Config\LNColor)
235 SetGadgetState(#PHG_HideIDE, Config\HideIDE)
236 SetGadgetState(#PHG_Links, Config\IncludeLinks)
237
238 ; Update Style Frame
239 i = GetGadgetState(#PHG_StyleBox)
240 ColorCanvas(#PHG_StyleColor, Style(i)\Color)
241 SetGadgetState(#PHG_StyleBold, Style(i)\Bold)
242 SetGadgetState(#PHG_StyleItalic, Style(i)\Italic)
243 SetGadgetState(#PHG_StyleUnderline, Style(i)\Underline)
244 SetGadgetState(#PHG_StyleStrike, Style(i)\Strike)
245
246 EndProcedure
247
248
249
250
251
252 ; Create main window, menu, and shortcuts
253 Procedure.i CreateMainWindow()
254 Protected Result.i = #False
255 Protected Flags.i, Parent.i
256 Protected y.i, i.i
257
258 ; Open main window
259 Parent = Val(GetEnvironmentVariable("PB_TOOL_MainWindow"))
260 Flags = #PB_Window_MinimizeGadget
261 If (Parent)
262 Flags | #PB_Window_WindowCentered
263 Else
264 Flags | #PB_Window_ScreenCentered
265 EndIf
266 Flags | #PB_Window_Invisible
267 If (OpenWindow(#PHW_Main, 0, 0, 480, 360, #PH_Title + " " + VersionString(#PH_Version), Flags, Parent))
268
269
270 ; Input/Output frame
271 Frame3DGadget(#PHG_IOFrame, 10, 10, 460, 105, "Input/Output")
272 y = 30
273 OptionGadget(#PHG_InFileOption, 20, y, 100, #GH, "Input File:")
274 SetGadgetState(#PHG_InFileOption, #True)
275 OptionGadget(#PHG_InPathOption, 20, y + 2*#GH + 5, 100, #GH, "Input Folder:")
276
277 ; Input file selection
278 StringGadget(#PHG_InFile, 120, y, 240, #GH, "")
279 ButtonGadget(#PHG_InFileBrowse, 360, y, #GH, #GH, "...")
280 ButtonGadget(#PHG_InFileOpen, 370 + #GH, y, 60, #GH, "Open") : y + #GH
281 TextGadget(#PHG_OutFileText, 37, y+3, 80, #GH, "Output File:")
282 StringGadget(#PHG_OutFile, 120, y, 240, #GH, "")
283 ButtonGadget(#PHG_OutFileBrowse, 360, y, #GH, #GH, "...")
284 ButtonGadget(#PHG_OutFileOpen, 370 + #GH, y, 60, #GH, "Open") : y + #GH + 5
285 StringGadget(#PHG_InPath, 120, y, 240, #GH, "")
286 ButtonGadget(#PHG_InPathBrowse, 360, y, #GH, #GH, "...")
287 ButtonGadget(#PHG_InPathOpen, 370 + #GH, y, 60, #GH, "Open") : y + #GH
288
289
290 ; Settings frame
291 Frame3DGadget(#PHG_ConfigFrame, 10, 120, 225, 165, "Settings")
292 y = 140
293 TextGadget(#PHG_FontText, 20, y+3, 40, #GH-3, "Font:")
294 StringGadget(#PHG_FontName, 60, y, 90, #GH, "Courier New")
295 StringGadget(#PHG_FontSize, 155, y, 30, #GH, "11", #PB_String_Numeric)
296 ButtonGadget(#PHG_FontPick, 190, y, 30, #GH, "...")
297 y + #GH
298 TextGadget(#PHG_BGText, 40, y+3, 110, #GH-3, "Background Color:")
299 CanvasGadget(#PHG_BGColor, 155, y+1, 65, #GH-2, #PB_Canvas_Border)
300 ColorCanvas(#PHG_BGColor, Config\BGColor)
301 y + #GH
302 TextGadget(#PHG_TabText, 40, y+3, 110, #GH-3, "Tab Size (Spaces):")
303 StringGadget(#PHG_TabLength, 155, y, 65, #GH, "", #PB_String_Numeric)
304 y + #GH
305 CheckBoxGadget(#PHG_LineNumbers, 20, y, 135, #GH, "Show Line Numbers")
306 SetGadgetState(#PHG_LineNumbers, #True)
307 CanvasGadget(#PHG_LNColor, 155, y+1, 65, #GH-2, #PB_Canvas_Border)
308 ColorCanvas(#PHG_LNColor, Config\LNColor)
309 y + #GH
310 CheckBoxGadget(#PHG_HideIDE, 20, y, 205, #GH, "Hide Appended IDE Options") : y + #GH
311 SetGadgetState(#PHG_HideIDE, #True)
312 CheckBoxGadget(#PHG_Links, 20, y, 205, #GH, "IncludeFile Links") : y + #GH
313 SetGadgetState(#PHG_Links, #False)
314
315 ; Syntax Styles frame
316 Frame3DGadget(#PHG_StyleFrame, 245, 120, 225, 165, "Syntax Styles")
317 y = 150
318 TextGadget(#PHG_StyleText, 255, y+3, 100, #GH-3, "Modify Style:", #PB_Text_Center)
319 ComboBoxGadget(#PHG_StyleBox, 355, y, 100, #GH)
320 For i = 0 To #PHS_Count - 1
321 AddGadgetItem(#PHG_StyleBox, i, StyleName(i))
322 Next i
323 SetGadgetState(#PHG_StyleBox, 0)
324 y + #GH
325 TextGadget(#PHG_StyleColorText, 255, y+3, 100, #GH-3, "Color:", #PB_Text_Center)
326 CanvasGadget(#PHG_StyleColor, 355, y+1, 100, #GH-2, #PB_Canvas_Border) : y + #GH + 5
327 CheckBoxGadget(#PHG_StyleBold, 295, y, 60, #GH, "Bold") : y + #GH
328 CheckBoxGadget(#PHG_StyleItalic, 295, y, 60, #GH, "Italic") : y - #GH
329 CheckBoxGadget(#PHG_StyleUnderline, 355, y, 90, #GH, "Underline") : y + #GH
330 CheckBoxGadget(#PHG_StyleStrike, 355, y, 90, #GH, "Strikethrough") : y - #GH
331
332 ; Bottom gadget row
333 ButtonGadget(#PHG_Generate, 20, 295, 100, #GH, "Generate", #PB_Button_Default)
334 CheckBoxGadget(#PHG_OpenDone, 20, 300 + #GH, 120, #GH, "Open when done")
335 SetGadgetState(#PHG_OpenDone, #True)
336 ButtonGadget(#PHG_Import, WindowWidth(#PHW_Main)/2 - 60, 295, 120, #GH, "Import Settings")
337 ButtonGadget(#PHG_Export, WindowWidth(#PHW_Main)/2 - 60, 295 + #GH, 120, #GH, "Export Settings")
338 ButtonGadget(#PHG_Close, 360, 295, 100, #GH, "Close")
339 ButtonGadget(#PHG_About, WindowWidth(#PHW_Main)-#GH, WindowHeight(#PHW_Main)-#GH, #GH, #GH, "?")
340
341 ; Keyboard shortcuts
342 AddKeyboardShortcut(#PHW_Main, #PB_Shortcut_F5, #PHM_Generate)
343 AddKeyboardShortcut(#PHW_Main, #PB_Shortcut_Escape, #PHM_Close )
344 AddKeyboardShortcut(#PHW_Main, #PB_Shortcut_F1, #PHM_About )
345
346 ; Create ColorCanvas popup menu
347 If (CreatePopupMenu(#PHW_Canvas))
348 MenuItem(#PHM_Nothing, "")
349 MenuBar()
350 MenuItem(#PHM_CopyRGB, "Copy #RRGGBB")
351 MenuItem(#PHM_PasteRGB, "Paste #RRGGBB")
352 MenuBar()
353 MenuItem(#PHM_CopyBGR, "Copy $BBGGRR")
354 MenuItem(#PHM_PasteBGR, "Paste $BBGGRR")
355 MenuBar()
356 MenuItem(#PHM_Invert, "Invert Color")
357 EndIf
358
359 Result = #True
360 EndIf
361
362 ProcedureReturn (Result)
363 EndProcedure
364
365 ; Determine the default path to browse for input files
366 Procedure.s DefaultBrowsePath()
367 Static Path.s = ""
368
369 If (Path = "")
370 Path = GetEnvironmentVariable("PB_TOOL_FileList")
371 If (Path)
372 Path = GetPathPart(StringField(Path, 1, #LF$))
373 EndIf
374 EndIf
375
376 If (Path = "")
377 Path = GetCurrentDirectory()
378 EndIf
379
380 ProcedureReturn (Path)
381 EndProcedure
382
383
384
385
386
387
388
389
390
391
392 ;-
393 Procedure MainWindowEvent(Event.i, Gadget.i, Type.i, Menu.i)
394 Protected File.s, i.i, k.i
395
396 ;- - Gadget Events
397 If (Event = #PB_Event_Gadget)
398 Select (Gadget)
399
400 ; Update main window
401 Case #PHG_InFileOption, #PHG_InPathOption
402 UpdateMainWindow()
403 Case #PHG_InFile, #PHG_OutFile, #PHG_InPath
404 If (Type = #PB_EventType_Change)
405 UpdateMainWindow()
406 EndIf
407
408 ; Input file options
409 Case #PHG_InFileBrowse
410 File = GetGadgetText(#PHG_InFile)
411 If (File = "")
412 File = DefaultBrowsePath()
413 EndIf
414 File = OpenFileRequester("Input File", File, #PH_SourcePattern, 0)
415 If (File)
416 SetGadgetText(#PHG_InFile, File)
417 SetGadgetText(#PHG_OutFile, File + ".htm")
418 SetGadgetState(#PHG_InFileOption, #True)
419 UpdateMainWindow()
420 EndIf
421 Case #PHG_InFileOpen
422 File = GetGadgetText(#PHG_InFile)
423 If (FileSize(File) > 0)
424 RunProgram(File)
425 EndIf
426
427 ; Output file settings
428 Case #PHG_OutFileBrowse
429 File = GetGadgetText(#PHG_OutFile)
430 If ((File = "") And GetGadgetText(#PHG_InFile))
431 File = GetGadgetText(#PHG_InFile) + ".htm"
432 EndIf
433 If (File = "")
434 File = DefaultBrowsePath()
435 EndIf
436 File = SaveFileRequester("Output File", File, #PH_OutputPattern, 0)
437 If (File)
438 If (SelectedFilePattern() = 0)
439 Select (LCase(GetExtensionPart(File)))
440 Case "htm", "html"
441 Default
442 File + ".htm"
443 EndSelect
444 EndIf
445 SetGadgetText(#PHG_OutFile, File)
446 SetGadgetState(#PHG_InFileOption, #True)
447 UpdateMainWindow()
448 EndIf
449 Case #PHG_OutFileOpen
450 File = GetGadgetText(#PHG_OutFile)
451 If (FileSize(File) > 0)
452 RunProgram(File)
453 EndIf
454
455 ; Input folder
456 Case #PHG_InPathBrowse
457 File = GetGadgetText(#PHG_InPath)
458 If (File = "")
459 File = GetPathPart(GetGadgetText(#PHG_InFile))
460 EndIf
461 If (File = "")
462 File = DefaultBrowsePath()
463 EndIf
464 File = PathRequester("Input Folder", File)
465 If (File)
466 SetGadgetText(#PHG_InPath, File)
467 SetGadgetState(#PHG_InFileOption, #False)
468 UpdateMainWindow()
469 EndIf
470 Case #PHG_InPathOpen
471 File = GetGadgetText(#PHG_InPath)
472 If (FileSize(File) = -2)
473 RunProgram(File)
474 EndIf
475
476 ; General settings
477 Case #PHG_FontPick
478 If (FontRequester(GetGadgetText(#PHG_FontName), Val(GetGadgetText(#PHG_FontName)), 0))
479 SetGadgetText(#PHG_FontName, SelectedFontName())
480 SetGadgetText(#PHG_FontSize, Str(SelectedFontSize()))
481 EndIf
482 Case #PHG_BGColor
483 If (Type = #PB_EventType_LeftClick)
484 k = ColorRequester(GetGadgetData(#PHG_BGColor))
485 If (k >= 0)
486 ColorCanvas(#PHG_BGColor, k)
487 EndIf
488 ElseIf (Type = #PB_EventType_RightClick)
489 CanvasMenu(Gadget)
490 EndIf
491 Case #PHG_LineNumbers
492 If (GetGadgetState(#PHG_LineNumbers))
493 HideGadget(#PHG_LNColor, #False)
494 Else
495 HideGadget(#PHG_LNColor, #True)
496 EndIf
497 Case #PHG_LNColor
498 If (Type = #PB_EventType_LeftClick)
499 k = ColorRequester(GetGadgetData(#PHG_LNColor))
500 If (k >= 0)
501 ColorCanvas(#PHG_LNColor, k)
502 EndIf
503 ElseIf (Type = #PB_EventType_RightClick)
504 CanvasMenu(Gadget)
505 EndIf
506
507 ; Style Frame
508 Case #PHG_StyleBox
509 If (Type = #PB_EventType_Change)
510 UpdateForm()
511 EndIf
512 Case #PHG_StyleColor
513 If (Type = #PB_EventType_LeftClick)
514 k = ColorRequester(GetGadgetData(#PHG_StyleColor))
515 If (k >= 0)
516 ColorCanvas(#PHG_StyleColor, k)
517 Style(GetGadgetState(#PHG_StyleBox))\Color = k
518 EndIf
519 ElseIf (Type = #PB_EventType_RightClick)
520 CanvasMenu(Gadget)
521 EndIf
522 Case #PHG_StyleBold, #PHG_StyleItalic, #PHG_StyleUnderline, #PHG_StyleStrike
523 Style(GetGadgetState(#PHG_StyleBox))\Bold = GetGadgetState(#PHG_StyleBold )
524 Style(GetGadgetState(#PHG_StyleBox))\Italic = GetGadgetState(#PHG_StyleItalic )
525 Style(GetGadgetState(#PHG_StyleBox))\Underline = GetGadgetState(#PHG_StyleUnderline)
526 Style(GetGadgetState(#PHG_StyleBox))\Strike = GetGadgetState(#PHG_StyleStrike )
527 SetActiveGadget(#PHG_StyleBox)
528
529 ; Bottom row functions
530 Case #PHG_Generate
531 TryHighlight()
532 Case #PHG_Import
533 TryImport()
534 Case #PHG_Export
535 TryExport()
536 Case #PHG_Close
537 ExitFlag = #PHE_Quit
538
539 Case #PHG_About
540 About()
541
542 EndSelect
543
544 ;- - Menu Events
545 ElseIf (Event = #PB_Event_Menu)
546 Select (Menu)
547 Case #PHM_Generate
548 TryHighlight()
549 Case #PHM_Close
550 ExitFlag = #PHE_Quit
551 Case #PHM_About
552 About()
553
554 Case #PHM_CopyRGB
555 CopyCanvas(#True)
556 Case #PHM_CopyBGR
557 CopyCanvas(#False)
558 Case #PHM_PasteRGB
559 PasteCanvas(#True)
560 Case #PHM_PasteBGR
561 PasteCanvas(#False)
562 Case #PHM_Invert
563 InvertCanvas()
564 Case #PHM_Nothing
565 ClickedCanvas = #Null
566
567 EndSelect
568
569 ;- - Window Events
570 ElseIf (Event = #PB_Event_CloseWindow)
571 ExitFlag = #PHE_Quit
572 EndIf
573
574 EndProcedure
575
576 ;-
577 ; EOF