From fb2c7800115902280220483e5fd5c8bd7bd9ea77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Mon, 29 Oct 2012 01:20:44 +0000 Subject: [PATCH] [EXAMPLES] * NEW: Merge the new PDFViewer example made by Bernd Brinkmann. git-svn-id: svn://localhost/gambas/trunk@5261 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- app/src/gambas3/.lang/.pot | 22 +- app/src/gambas3/.src/Debug/FProfile.class | 1 - examples/examples/Misc/PDFViewer/.project | 5 +- .../examples/Misc/PDFViewer/.src/FMain.class | 381 +++++++++++++++--- .../examples/Misc/PDFViewer/.src/FMain.form | 109 +++-- .../examples/Misc/PDFViewer/.src/Fabout.form | 34 +- 6 files changed, 435 insertions(+), 117 deletions(-) diff --git a/app/src/gambas3/.lang/.pot b/app/src/gambas3/.lang/.pot index 21125c171..24f21a012 100644 --- a/app/src/gambas3/.lang/.pot +++ b/app/src/gambas3/.lang/.pot @@ -1373,7 +1373,7 @@ msgstr "" msgid "Expression" msgstr "" -#: FDebugInfo.class:60 FProfile.class:599 +#: FDebugInfo.class:60 FProfile.class:598 msgid "Function" msgstr "" @@ -3557,43 +3557,43 @@ msgstr "" msgid "Callers" msgstr "" -#: FProfile.class:153 +#: FProfile.class:152 msgid "Bad profile file format" msgstr "" -#: FProfile.class:383 +#: FProfile.class:382 msgid "&1 Mb" msgstr "" -#: FProfile.class:383 +#: FProfile.class:382 msgid "Total time &1 μs" msgstr "" -#: FProfile.class:402 +#: FProfile.class:401 msgid "Unable to load profile file: &1" msgstr "" -#: FProfile.class:601 +#: FProfile.class:600 msgid "Calls" msgstr "" -#: FProfile.class:603 +#: FProfile.class:602 msgid "Duration" msgstr "" -#: FProfile.class:605 +#: FProfile.class:604 msgid "Self" msgstr "" -#: FProfile.class:607 +#: FProfile.class:606 msgid "Average" msgstr "" -#: FProfile.class:975 +#: FProfile.class:974 msgid "Profile files" msgstr "" -#: FProfile.class:982 +#: FProfile.class:981 msgid "Unable to save profile." msgstr "" diff --git a/app/src/gambas3/.src/Debug/FProfile.class b/app/src/gambas3/.src/Debug/FProfile.class index d76d736ba..e07dfbdc8 100644 --- a/app/src/gambas3/.src/Debug/FProfile.class +++ b/app/src/gambas3/.src/Debug/FProfile.class @@ -43,7 +43,6 @@ Private Sub GetClass(sFunc As String) As String End - Fast Private Sub EnterFunction(sWhere As String, iTime As Long) As CProfile Dim hProf As CProfile diff --git a/examples/examples/Misc/PDFViewer/.project b/examples/examples/Misc/PDFViewer/.project index 9bca32212..5e5dd4b1e 100644 --- a/examples/examples/Misc/PDFViewer/.project +++ b/examples/examples/Misc/PDFViewer/.project @@ -1,9 +1,9 @@ # Gambas Project File 3.0 -# Compiled with Gambas 3.0.0 +# Compiled with Gambas 3.3.90 Title=PdfViewer Startup=FMain Icon=pdf.png -Version=3.0.0 +Version=3.3.90 VersionFile=1 Component=gb.image Component=gb.gui @@ -19,3 +19,4 @@ Maintainer=benoit Vendor=Princeton Address=benoit@localhost License=General Public Licence +Packager=1 diff --git a/examples/examples/Misc/PDFViewer/.src/FMain.class b/examples/examples/Misc/PDFViewer/.src/FMain.class index 5454e8058..584840726 100644 --- a/examples/examples/Misc/PDFViewer/.src/FMain.class +++ b/examples/examples/Misc/PDFViewer/.src/FMain.class @@ -6,9 +6,9 @@ ' ' PdfViewer gb.pdf component example ' -' (C) 2007 Daniel Campos Fernández -' -' +' (C) 2007 Daniel Campos Fernández +' 2012 Bernd Brinkmann (modifications on the search and zoom function) +' ' This program is free software; you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by ' the Free Software Foundation; either version 1, or (at your option) @@ -31,9 +31,21 @@ '*************************************************************************** Public hPdf As New PdfDocument +Private timer_count As Integer Public cIndex As Integer Public CurrentPage As Integer -Public CurrentZoom As Float +Public CurrentZoom As Float = 1.0 +Private bExit As Boolean +Private pdf_path As String +Private Embedded_In_Form As String +Private currentSearchResult As Short = 0 'Contains the information which of the search results on this page is marked +Private NumberOfSearchResults As Integer +Private currentSearchResultSynonyms As Short = 0 +Private Product_Information_Dir As String +Private Synonyms As New String[20, 20] +Private ScrollXPositionBeforeZoom As Float +Private ScrollYPositionBeforeZoom As Float + Public Sub BtOpen_Click() @@ -56,16 +68,18 @@ Public Sub BtOpen_Click() Else BtNext.Enabled = False End If + txtGotoPage.Enabled = True btZoomIn.Enabled = True btZoomOut.Enabled = True btRotate.Enabled = True pBox.Visible = True - TxtFind.Enabled = True + txtFind.Enabled = True tvIndex.Clear() If hPdf.HasIndex Then tvIndex.Visible = True AddIndex(0, "") + splIndex.Layout = [1, 3] Else tvIndex.Visible = False End If @@ -106,72 +120,95 @@ Public Sub tvIndex_Click() End -Public Sub RenderPage() - - Dim hPic As Picture - Dim Bc As Integer - - hPdf.Zoom = CurrentZoom - LblInfo.Text = CurrentPage & " " & ("From") & " " & hPdf.Count - - ViewPort.Scroll(0, 0) - hPic = hPdf[CurrentPage].Image.Picture +Public Sub RenderPage(Optional FoundText As String, Optional Casesensetivity As Boolean) + '--------------------------------------------------------------------------- + 'This function is called everytime something changed for example a new search result has to be displayed or the page + 'has canged the parameters FoundText and Casesensetivity are only of interrest if the funktion is called from a search frunction + '-------------------------------------------------------------------------- + Dim hPic As Picture + Dim Bc As Integer + + ScrollXPositionBeforeZoom = ViewPort.ScrollX / ViewPort.ScrollWidth + ScrollYPositionBeforeZoom = ViewPort.ScrollY / ViewPort.ScrollHeight - If TxtFind.Text <> "" Then - - hPdf[CurrentPage].Find(TxtFind.Text) - Paint.Begin(hPic) - Paint.Brush = Paint.Color(Color.RGB(0, 0, 255, 192)) - For Bc = 0 To hPdf[CurrentPage].Result.Count - 1 - Paint.Rectangle(hPdf[CurrentPage].Result[Bc].Left, hPdf[CurrentPage].Result[Bc].Top, hPdf[CurrentPage].Result[Bc].Width, hPdf[CurrentPage].Result[Bc].Height) - Next - Paint.Fill - Paint.End - - End If - - PBox.Picture = hPic - PBox.Resize(hPdf[CurrentPage].Width, hPdf[CurrentPage].Height) - Form_Resize() - + If CurrentZoom > 0.0 Then + hPdf.Zoom = CurrentZoom + Else + Message.Error("Can't set zoom to " & CurrentZoom, "OK") + Endif + + lblInfo.Text = " of" & " " & hPdf.Count + If txtGotoPage.text <> CurrentPage Then txtGotoPage.text = CurrentPage 'if the parameter currentPage is different from the current page the current page gets changed + If currentSearchResult = 0 Then 'if a search result is highlighted the focus will not be changed to the top + ViewPort.Scroll(0, 0) + Endif + + hPic = hPdf[CurrentPage].Image.Picture + + 'the search result gets highlighted here and the focus is set to the right position again if something has changed for example the zoomfactor + If currentSearchResult > 0 And FoundText <> "" Then ' resets the mark on the current search result + hPdf[CurrentPage].Find(FoundText, Casesensetivity) + Paint.Begin(hPic) + Paint.Brush = Paint.Color(Color.RGB(0, 0, 255, 192)) + Paint.Rectangle(hPdf[CurrentPage].Result[currentSearchResult - 1].Left, hPdf[CurrentPage].Result[currentSearchResult - 1].Top, hPdf[CurrentPage].Result[currentSearchResult - 1].Width, hPdf[CurrentPage].Result[currentSearchResult - 1].Height) + ViewPort.ScrollY = ViewPort.ScrollHeight * (hPdf[CurrentPage].Result[currentSearchResult - 1].Top / Paint.Height) + Paint.Fill + Paint.End + PBox.Picture = hPic + Endif + + PBox.Picture = hPic + PBox.Resize(hPdf[CurrentPage].Width, hPdf[CurrentPage].Height) + Form_Resize() + Catch - - Balloon.Error(Error.Text, TxtFind) - + Message.Info("An error occurred whilst trying to view the document.\n\nIf this persists please report this problem.") + End + Public Sub Form_Resize() If CurrentPage = 0 Then Return - pBox.Left = (ViewPort.Width - hPdf[CurrentPage].Width) / 2 + ViewPort.ScrollX = ScrollXPositionBeforeZoom * ViewPort.ScrollWidth + ViewPort.Scrolly = ScrollYPositionBeforeZoom * ViewPort.ScrollHeight End -Public Sub HSplit1_Resize() +Public Sub splIndex_Resize() Form_Resize() End Public Sub BtNext_Click() - - Inc CurrentPage - If CurrentPage = hPdf.Count Then BtNext.Enabled = False - BtPrev.Enabled = True - RenderPage() - + + Inc CurrentPage + currentSearchResult = 0 + currentSearchResultSynonyms = 0 + If CurrentPage = hPdf.Count Then + BtNext.Enabled = False + End If + BtPrev.Enabled = True + BtPrev.SetFocus + txtGotoPage.text = CurrentPage 'this automatically calls the function txtGotoPage_Change and changes the page to the new "currentPage" + End Public Sub BtPrev_Click() - - Dec CurrentPage - If CurrentPage = 1 Then BtPrev.Enabled = False - BtNext.Enabled = True - RenderPage() - + + Dec CurrentPage + currentSearchResult = 0 + currentSearchResultSynonyms = 0 + If CurrentPage = 1 Then + BtPrev.Enabled = False + End If + BtNext.Enabled = True + BtNext.SetFocus + txtGotoPage.text = CurrentPage 'this automatically calls the function txtGotoPage_Change and changes the page to the new "currentPage" + End - Public Sub btZoomIn_Click() If CurrentZoom < 3 Then CurrentZoom += 0.1 @@ -219,9 +256,245 @@ Public Sub btRotate_Click() End -Public Sub TxtFind_Change() - - RenderPage() - +Public Sub txtGotoPage_Change() + + '--------------------------------------------------------------------------- + 'This function changes the page to the page number written in the textbox "txtGotoPage" + 'the text in this textbox can be changed by the user for example by klicking on the next button or other funktions such as + 'a search funktion + '-------------------------------------------------------------------------- + ' + If Bexit Or Last.text = "" Then Return + 'the last search results get removed by the next four lines + BtSearchNext.Enabled = False + BtSearchPrev.Enabled = False + currentSearchResult = 0 + If Val(Last.text) > hPdf.Count Or Val(Last.text) = hPdf.Count Then 'hPdf.count contains the length of the pdf document + bExit = True + txtGotoPage.text = hPdf.Count + BtNext.Enabled = False 'because the last page is now displayed the next page button gets disabled + BtPrev.Enabled = True + bExit = False + Else + BtNext.Enabled = True + If Val(Last.text) = 1 Or Val(Last.text) < 1 Then + bExit = True + txtGotoPage.text = 1 + bExit = False + BtPrev.Enabled = False + Else + BtPrev.Enabled = True + End If + End If + currentPage = Val(Last.text) + Bexit = False + RenderPage() + +End + +Public Sub txtGotoPage_KeyPress() + + ' If modUtil.AllowKeys(const.AllowKeys_NumbersOnly, Key.code) = False Then + ' Stop Event + ' Return + ' End If + +End + +Public Sub txtFind_Activate() + + '--------------------------------------------------------------------------- + 'This function is called if the user wants fo find the string inside the textbox "TxtFind" by hitting the enter key + '-------------------------------------------------------------------------- + + If Bexit Then Return + If txtFind.Text <> "" Then + If currentSearchResult > 0 Then + If currentSearchResult = NumberOfSearchResults Then + If currentpage = hPdf.Count Then + CurrentPage = 1 + Else + CurrentPage = CurrentPage + 1 + Endif + FindNext() + Else + currentSearchResult = currentSearchResult + 1 + RenderPage(txtFind.Text) + Endif + Else + FindNext() + Endif + End If + +End + +Public Sub txtFind_Click() + + txtFind_Activate + +End + + +Private Sub FindNext() + '--------------------------------------------------------------------------- + ' This function finds the next string in the pdf matching the search string located after the current search result + '--------------------------------------------------------------------------- + Dim hPic As Picture + Dim Bc As Integer + Dim currentSearchPage As Short = CurrentPage ' contains the information on which page the search funktion searched the last time + Dim LastPageToSearch As Short ' contains the information which page is the last page for the find function + + If CurrentPage = 1 Then + LastPageToSearch = 1 + Else + LastPageToSearch = CurrentPage + + Endif + currentSearchResultSynonyms = 0 + currentSearchResult = 0 + BtSearchNext.Enabled = False + BtSearchPrev.Enabled = False + Repeat + hPic = hPdf[currentSearchPage].Image.Picture + hPdf[currentSearchPage].Find(txtFind.Text, False) + + If hPdf[currentSearchPage].Result.Count > 0 Then + CurrentPage = currentsearchPage + currentSearchResult = 1 + Else + If currentSearchPage = hPdf.Count Then + currentSearchPage = 1 + Else + currentSearchPage = currentSearchPage + 1 + Endif + Endif + Until currentSearchResult <> 0 Or currentSearchPage = LastPageToSearch + If hPdf[currentSearchPage].Result.Count > 0 Then + CurrentPage = currentSearchPage + + txtGotoPage.text = CurrentPage + currentSearchResult = 1 + NumberOfSearchResults = hPdf[currentSearchPage].Result.Count + BtSearchNext.Enabled = True + BtSearchPrev.Enabled = True + + + RenderPage(txtFind.Text) + + Else + txtFind.Background = Color.Lighter(16711680) '16711680 = Red + RenderPage() + + Endif + +Catch + Message.Info("An error occurred whilst trying to view the document.\n\nIf this persists please report this problem.") + +End + +Private Sub FindPrevious() + '--------------------------------------------------------------------------- + ' This function finds the next string in the pdf matching the search string located before the current search result + '--------------------------------------------------------------------------- + Dim hPic As Picture + Dim Bc As Integer + Dim currentSearchPage As Short = CurrentPage ' contains the information on which page the search funktion searched the last time + Dim LastPageToSearch As Short ' contains the information which page is the last page for the find function + + If CurrentPage = hPdf.Count Then + LastPageToSearch = 0 + Else + LastPageToSearch = CurrentPage + Endif + currentSearchResultSynonyms = 0 + currentSearchResult = 0 + BtSearchNext.Enabled = False + BtSearchPrev.Enabled = False + + Repeat + hPic = hPdf[currentSearchPage].Image.Picture + hPdf[currentSearchPage].Find(txtFind.Text, False) + If hPdf[currentSearchPage].Result.Count > 0 Then + CurrentPage = currentsearchPage + currentSearchResult = 1 + Else + If currentSearchPage = 1 Then + currentSearchPage = hPdf.Count + Else + currentSearchPage = currentSearchPage - 1 + Endif + Endif + Until currentSearchResult <> 0 Or currentSearchPage = LastPageToSearch + + If hPdf[currentSearchPage].Result.Count > 0 Then + CurrentPage = currentSearchPage + + txtGotoPage.text = CurrentPage + currentSearchResult = hPdf[currentSearchPage].Result.Count + NumberOfSearchResults = hPdf[currentSearchPage].Result.Count + BtSearchNext.Enabled = True + BtSearchPrev.Enabled = True + RenderPage(txtFind.Text) + Endif + +Catch + Message.Info("An error occurred whilst trying to view the document.\n\nIf this persists please report this problem.") + +End + +Public Sub BtSearchNext_Click() + '--------------------------------------------------------------------------- + 'This funktion is highlighting the next seach string located after the current search string + '--------------------------------------------------------------------------- + If currentSearchResult = NumberOfSearchResults Then + If currentpage = hPdf.Count Then + CurrentPage = 1 + Else + CurrentPage = CurrentPage + 1 + Endif + FindNext() + Else + currentSearchResult = currentSearchResult + 1 + RenderPage(txtFind.Text) + Endif + +End + +Public Sub BtSearchPrev_Click() + '--------------------------------------------------------------------------- + 'This funktion is highlighting the next seach string located before the current search string + '--------------------------------------------------------------------------- + If currentSearchResult > 0 Then + If currentpage = 1 Then + currentpage = hPdf.Count + Else + CurrentPage = CurrentPage - 1 + Endif + FindPrevious() + Else + currentSearchResult = currentSearchResult - 1 + RenderPage(txtFind.Text) + Endif + +End + +Public Sub txtFind_Change() + '--------------------------------------------------------------------------- + 'When the user starts to type in a new search string this function removes all previous search results and in case + 'the last search was not successful it turns the bachground color from red back to white + '--------------------------------------------------------------------------- + + If txtFind.Background = Color.Lighter(16711680) Then + txtFind.Background = Color.White + + Endif + + currentSearchResult = 0 + currentSearchResultSynonyms = 0 + BtSearchNext.Enabled = False + BtSearchPrev.Enabled = False + + RenderPage() + End diff --git a/examples/examples/Misc/PDFViewer/.src/FMain.form b/examples/examples/Misc/PDFViewer/.src/FMain.form index 375875d60..fb055f2c7 100644 --- a/examples/examples/Misc/PDFViewer/.src/FMain.form +++ b/examples/examples/Misc/PDFViewer/.src/FMain.form @@ -5,91 +5,122 @@ Text = ("Simple PDF document viewer") Arrangement = Arrange.Vertical { HBox1 HBox - MoveScaled(0,1,76,4) + MoveScaled(1,2,95,4) { BtOpen ToolButton MoveScaled(0,0,4,4) ToolTip = ("Open file...") - Text = ("") Picture = Picture["icon:/small/open"] } { Button1 ToolButton - MoveScaled(6,0,4,4) + MoveScaled(4,0,4,4) ToolTip = ("About...") - Text = ("") Picture = Picture["icon:/small/question"] } { btRotate ToolButton - MoveScaled(10,0,4,4) + MoveScaled(8,0,4,4) Enabled = False ToolTip = ("Rotate") - Text = ("") Picture = Picture["icon:/small/rotate-right"] } { btZoomOut ToolButton - MoveScaled(14,0,4,4) + MoveScaled(12,0,4,4) Enabled = False ToolTip = ("Zoom out") - Text = ("") Picture = Picture["icon:/small/zoom-out"] } { btZoomIn ToolButton - MoveScaled(18,0,4,4) + MoveScaled(16,0,4,4) Enabled = False ToolTip = ("Zoom in") - Text = ("") Picture = Picture["icon:/small/zoom-in"] } - { TxtFind TextBox - MoveScaled(24,0,12,4) + { Separator3 Separator + MoveScaled(22,0,0,4) + } + { txtFind ButtonBox + MoveScaled(24,0,15,4) Enabled = False ToolTip = ("Find text") Expand = True - Text = ("") + Picture = Picture["icon:/small/find"] + Border = False } - { LblInfo Label - MoveScaled(44,0,15,4) - Expand = True - Text = ("") - Alignment = Align.Right + { Panel1 Panel + MoveScaled(40,0,8,4) + Visible = False + Background = Color.TextBackground + { BtSearchPrev Button + MoveScaled(0,0,4,4) + Enabled = False + ToolTip = ("Previous page") + Picture = Picture["icon:/small/left"] + Border = False + } + { BtSearchNext Button + MoveScaled(4,0,4,4) + Enabled = False + Background = Color.TextBackground + ToolTip = ("Next Found") + Picture = Picture["icon:/small/right"] + Border = False + } } { Separator1 Separator - MoveScaled(60,0,1,4) + MoveScaled(51,0,0,4) } { BtPrev ToolButton - MoveScaled(61,0,4,4) + MoveScaled(54,0,4,4) Enabled = False ToolTip = ("Previous page") - Text = ("") Picture = Picture["icon:/small/left"] } + { Page Label + MoveScaled(59,0,4,4) + AutoResize = True + Text = ("Page") + Alignment = Align.Right + } + { Panel2 Panel + MoveScaled(64,0,1,4) + } + { txtGotoPage TextBox + MoveScaled(66,0,9,4) + Enabled = False + ToolTip = ("Go to this page") + Alignment = Align.Center + Border = False + } + { lblInfo Label + MoveScaled(75,0,7,4) + AutoResize = True + } { BtNext ToolButton - MoveScaled(68,0,4,4) + MoveScaled(84,0,4,4) Enabled = False ToolTip = ("Next page") - Text = ("") Picture = Picture["icon:/small/right"] } } - { HBox2 HBox - MoveScaled(1,10,75,38) + { Separator2 Separator + MoveScaled(36,8,27,0) + } + { splIndex HSplit + MoveScaled(9,11,81,60) Expand = True - { HSplit1 HSplit - MoveScaled(4,3,66,35) + { tvIndex TreeView + MoveScaled(0,0,19,25) + Visible = False + Border = False + } + { ViewPort ScrollView + MoveScaled(36,5,30,32) + Background = Color.TextBackground Expand = True - { tvIndex TreeView - MoveScaled(0,0,19,25) + Border = False + { PBox PictureBox + MoveScaled(3,3,24,21) Visible = False } - { ViewPort ScrollView - MoveScaled(21,1,30,32) - Background = Color.TextBackground - Expand = True - Border = False - { PBox PictureBox - MoveScaled(3,2,24,21) - Visible = False - } - } } } } diff --git a/examples/examples/Misc/PDFViewer/.src/Fabout.form b/examples/examples/Misc/PDFViewer/.src/Fabout.form index 3e6d86c5f..1b8565a2f 100644 --- a/examples/examples/Misc/PDFViewer/.src/Fabout.form +++ b/examples/examples/Misc/PDFViewer/.src/Fabout.form @@ -1,18 +1,32 @@ # Gambas Form File 3.0 { Form Form - MoveScaled(0,0,65,18) - Text = ("") + MoveScaled(0,0,48,22) Resizable = False - { btOK Button - MoveScaled(21,13,23,4) - Text = ("OK") - Default = True - Cancel = True - } + Arrangement = Arrange.Vertical + Spacing = True + Margin = True { TextLabel1 TextLabel - MoveScaled(0,0,65,11) - Text = ("Simple PDF document viewer.

Gambas example by Daniel Campos Fern\xC3\xA1ndez ") + MoveScaled(2,2,45,13) + Expand = True + Text = ("

Simple PDF document viewer

Gambas example by Daniel Campos Fernández and Bernd Brinkmann") Alignment = Align.Center } + { Panel1 HBox + MoveScaled(13,16,32,4) + { Panel2 Panel + MoveScaled(4,0,2,4) + Expand = True + } + { btOK Button + MoveScaled(10,0,15,4) + Text = ("OK") + Default = True + Cancel = True + } + { Panel3 Panel + MoveScaled(26,0,2,4) + Expand = True + } + } }