Page 1 of 1

more tut about scintilla gadget

Posted: Wed Jun 04, 2003 8:49 pm
by eddy
:)

Posted: Wed Jun 04, 2003 9:08 pm
by GPI
http://www.scintilla.org/

Scintilla is no part of PureBasic.

GPI

Posted: Thu Mar 10, 2005 11:43 pm
by Progi1984
Personnaly, I think that eddy want to have tutorials on the use of Scintilla with Purebasic. I agree with him ! Can someone do a tut on that ?

Posted: Fri Mar 11, 2005 7:55 am
by Inner
I don't have time right now, but if anyone does write some good ones, I'd be happy to include them in the archive.

Posted: Sun Mar 13, 2005 6:48 pm
by Progi1984
Has someone time for us ? And Scintilla tuts ?

thanks now

Scintilla MDI Editor

Posted: Thu Jun 30, 2005 8:47 pm
by dontmailme
No Tutorial, but here's some Scintilla MDI Editor code.... It's pretty rough, but I couldn't find any other example on here so I thought I'd post.

Some of the code was borrowed off this board :) and some from japbe source code.

:)

Image

Code: Select all


;- Enumeration
Enumeration 1
  #MENU_TitleFile
  #MENU_New
  #MENU_Open
  #MENU_Close
  #MENU_Save
  #MENU_SaveAs
  #MENU_Exit
  #MENU_TitleEdit
  #MENU_Undo
  #MENU_Redo
  #MENU_Cut
  #MENU_Copy
  #MENU_Paste
  #MENU_Settings
  #MENU_TitleHelp
  #MENU_Help
  #MENU_About
  #MENU_Windows
  #MENU_Search
  #MENU_CloseAll
  #MENU_Arrange
  #MENU_TileV
  #MENU_TileH
  #MENU_Cascade
  #MENU_Previous
  #MENU_Next
  #TOOLBAR
EndEnumeration

;- Include Files
XIncludeFile "Scintilla.pbi"

;- Declare Procedures
Declare OpenSourceFile()
Declare SaveAsSourceFile()
Declare SaveSourceFile(FileName.s)
Declare CloseSourceFile()
Declare create_toolbar()

Global MDI_Win

;- Structures

Structure MDIWindow
  ; info about the loaded image
  Whnd.l
  ImageWidth.l
  ImageHeight.l
  ; gadget numbers
  ScintillaGadget.l
EndStructure

;- Lists

NewList MDIWindow.MDIWindow()

;- Main

Window_0=OpenWindow(#PB_Any,71,75,737,559,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget
|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered
|#PB_Window_WindowCentered|#PB_Window_Invisible,"Scintilla Demo")

If Window_0
  MenuBar_0=CreateMenu(#PB_Any,WindowID(Window_0))
  MenuTitle("File")
  MenuItem(#MENU_New,"New")
  MenuBar()
  MenuItem(#MENU_Open,"Open")
  MenuItem(#MENU_Close,"Close")
  MenuItem(#MENU_CloseAll,"Close All")
  MenuBar()
  MenuItem(#MENU_Save,"Save")
  MenuItem(#MENU_SaveAs,"Save As")
  MenuBar()
  MenuItem(#MENU_Exit,"Exit")
  
  MenuTitle("Edit") 
  MenuItem(#MENU_Undo,"Undo")
  MenuItem(#MENU_Redo,"Redo")
  MenuBar()
  MenuItem(#MENU_Cut,"Cut")
  MenuItem(#MENU_Copy,"Copy")
  MenuItem(#MENU_Paste,"Paste")
  MenuBar()
  MenuItem(#MENU_Settings,"Settings")
  
  ;- Setup MDI Window+Menu
  MenuTitle("Windows")
  MenuItem(#MENU_Arrange, "Arrange")
  MenuItem(#MENU_CloseAll, "Close All")
  MenuItem(#MENU_TileV, "Tile vertically")
  MenuItem(#MENU_TileH, "Tile horizontally")
  MenuItem(#MENU_Cascade, "Cascade")
  MenuItem(#MENU_Previous, "Previous")
  MenuItem(#MENU_Next, "Next")
  MenuTitle("MDI_Windows")
  
  MenuTitle("Help")
  MenuItem(#MENU_Help,"Help")
  MenuBar()
  MenuItem(#MENU_About,"About")

  If CreateGadgetList(WindowID(Window_0))
    HideWindow(Window_0,0)
  EndIf
  
  
  
  
  ;- Standard PB toolbar
  create_toolbar()   
  
  
  ;- Scintilla setup
  If InitSciEdit()=0
    MessageRequester("Error","No sciLexer.dll found",#PB_MessageRequester_Ok)
    End
  EndIf
  
  
  MDI_Win.l=MDIGadget(#PB_Any, 0, 0, 0, 0, 3, 2000, #PB_MDI_AutoSize)
  
  quit=0
  Repeat
    
    Win_no=GetGadgetState(MDI_Win)
    
    If Win_no>-1
      SelectElement(MDIWindow(), Win_no)
      SCI_UseGadget(MDIWindow()\ScintillaGadget)
    EndIf  
    
    EventID=WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow
        If EventWindowID()=Window_0
          quit=1
        EndIf
        
      Case #PB_Event_Menu
        Select EventMenuID()
          Case #MENU_New
            
            LastElement(MDIWindow())
            AddElement(MDIWindow())
            item = ListIndex(MDIWindow())
            
            Whnd.l=AddGadgetItem(MDI_Win, item, "Untitled")
            
            MDIWindow()\Whnd=Whnd
            MDIWindow()\ImageWidth  = GetGadgetItemAttribute(MDI_Win, item, #PB_MDI_ItemWidth)
            MDIWindow()\ImageHeight = GetGadgetItemAttribute(MDI_Win, item, #PB_MDI_ItemHeight)
            
            MDIWindow()\ScintillaGadget=SciEditGadget(Whnd,0,0,MDIWindow()\ImageWidth ,MDIWindow()\ImageHeight)
            
            SCI_ClearAll()
            SCI_SetSavePoint()
            
          Case #MENU_Open
            
            OpenSourceFile()
            
          Case #MENU_Close
            item = GetGadgetState(MDI_Win)
            If item <> -1          ;- Are any MDI windows open ?
              RemoveGadgetItem(MDI_Win, item)
              
              SelectElement(MDIWindow(), item)
              
              DeleteElement(MDIWindow())
            EndIf
            
          Case #MENU_CloseAll
            ClearGadgetItemList(MDI_Win)  
            ClearList(MDIWindow())
            
          Case #MENU_Save
            
            item = GetGadgetState(MDI_Win)
            If item<>-1
              filename$=GetGadgetItemText(MDI_Win, GetGadgetState(MDI_Win),0)  
              SaveSourceFile(filename$)
            EndIf
            
          Case #MENU_SaveAs 
            
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SaveAsSourceFile()
            EndIf
            
          Case #MENU_Exit
            quit=#True
            
          Case #MENU_Undo  
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SCI_Undo()
            EndIf
            
          Case #MENU_Redo
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SCI_Redo()
            EndIf
            
          Case #MENU_Cut
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SCI_Cut()
            EndIf
            
          Case #MENU_Copy
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SCI_Copy()
            EndIf
            
          Case #MENU_Paste
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SCI_Paste()
            EndIf
            
          Case #MENU_Settings
            
            
            
          Case #MENU_TileV
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SetGadgetState(MDI_Win, #PB_MDI_TileVertically)
            EndIf
            
          Case #MENU_TileH
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SetGadgetState(MDI_Win, #PB_MDI_TileHorizontally)
            EndIf
            
          Case #MENU_Cascade
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SetGadgetState(MDI_Win, #PB_MDI_Cascade)
            EndIf
            
          Case #MENU_Arrange
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SetGadgetState(MDI_Win, #PB_MDI_Arrange)
            EndIf
            
          Case #MENU_Previous
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SetGadgetState(MDI_Win, #PB_MDI_Previous)
            EndIf
            
          Case #MENU_Next
            item = GetGadgetState(MDI_Win)
            If item<>-1
              SetGadgetState(MDI_Win, #PB_MDI_Next)
            EndIf
            
          Case #MENU_Help
            
            
          Case #MENU_About
            
            
        EndSelect
        
      Case #PB_Event_Gadget
        
        mygadget.l=EventGadgetID()
        
        ;- MDI Window Events  
        
        Select EventType()  
          
          Case #PB_EventType_CloseItem
            
            CloseSourceFile()
            
            item = GetGadgetState(MDI_Win)
            If item <> -1          
              RemoveGadgetItem(MDI_Win, item)
              
              SelectElement(MDIWindow(), item)
              
              DeleteElement(MDIWindow())
            EndIf
            
            
          Case #PB_EventType_Focus  
            
            
          Case #PB_EventType_SizeItem  
            
            item = GetGadgetAttribute(MDI_Win, #PB_MDI_SizedItem)
            
            SelectElement(MDIWindow(), item)
            MDIWindow()\ImageWidth  = GetGadgetItemAttribute(MDI_Win, item, #PB_MDI_ItemWidth)
            MDIWindow()\ImageHeight = GetGadgetItemAttribute(MDI_Win, item, #PB_MDI_ItemHeight)
            
            ;- resize MDI window
            SetWindowPos_(MDIWindow()\ScintillaGadget,0,0,0,MDIWindow()\ImageWidth ,MDIWindow()\ImageHeight,0)
            
        EndSelect
        
    EndSelect
  Until quit
  CloseWindow(Window_0)
  
  ;- Close Scintilla library....
  ExitSciEdit()
  
EndIf


End










;-Procedures



       
Procedure OpenSourceFile()
  
  FileName.s = OpenFileRequester("Open File","","PureBasic file |*.PB| All Files |*.*",0)
  
  If OpenFile(1, FileName)
    
    LastElement(MDIWindow())
    AddElement(MDIWindow())
    item = ListIndex(MDIWindow())
    
    Whnd.l=AddGadgetItem(MDI_Win, item, "Untitled")
    
    MDIWindow()\Whnd=Whnd
    MDIWindow()\ImageWidth  = GetGadgetItemAttribute(MDI_Win, item, #PB_MDI_ItemWidth)
    MDIWindow()\ImageHeight = GetGadgetItemAttribute(MDI_Win, item, #PB_MDI_ItemHeight)
    
    MDIWindow()\ScintillaGadget=SciEditGadget(Whnd,1,1,MDIWindow()\ImageWidth-20 ,MDIWindow()\ImageHeight-10)
    
    SetGadgetItemText(MDI_Win, item, FileName,0) 
    
    SelectElement(MDIWindow(), item)
    SCI_UseGadget(MDIWindow()\ScintillaGadget)
    
    SCI_ClearAll()
    
    l=Lof()
    Mem_Load=AllocateMemory(l+1)
    If Mem_Load
      
      adr=Mem_Load+1
      ReadData(adr,l)
      CloseFile(1)
      
      *endadr=adr+l+1
      
      PokeB(*endadr, 0)
      
      SCI_SetText(adr)
      
      SCI_SetSavePoint()
      
      FreeMemory(*adr)
      
    Else
      MessageRequester("Error","Can't open file... Out of Memory ?!",0)
    EndIf  
    
  Else
    If Len(FileName) > 0
      MessageRequester("Error","Can't open file..."+FileName,0)
    EndIf
  EndIf
EndProcedure

Procedure SaveSourceFile(FileName.s)

  If FileName.s = "Untitled"
    FileName = SaveFileRequester("Save As",FileName,"PureBasic file |*.PB| All Files |*.*",0) + ".pb"
  EndIf
  
  If FileName = ".pb"
    FileName = "Untitled"
  Else
  
    DeleteFile(FileName + ".bak")
    If RenameFile(FileName, FileName + ".bak")
      DeleteFile(FileName)
    EndIf
    
    If CreateFile(1, FileName)
      Length=SCI_GetLength()
      adr=AllocateMemory(Length+1)
      If adr
        SCI_GetText(Length+1,adr)
        WriteData(adr,Length+1)
        FreeMemory(adr)
        
        SCI_SetSavePoint()
        
        SetGadgetItemText(MDI_Win, GetGadgetState(MDI_Win), FileName,0) 
        
      EndIf
      CloseFile(1)
      
    EndIf
    
  EndIf
  
EndProcedure

Procedure SaveAsSourceFile()
  FileName.s = SaveFileRequester("Save As",FileName,"PureBasic file |*.PB| All Files |*.*",0) + ".pb"
  SaveSourceFile(FileName.s)
EndProcedure

Procedure CloseSourceFile()
  
  If SCI_GetModify()
    
    FileName.s=GetGadgetItemText(MDI_Win, GetGadgetState(MDI_Win),0)  
    
    Result = MessageRequester(FileName.s,"File changed, save this file?",#PB_MessageRequester_YesNoCancel)
   
    If Result = 2 ; cancel
    Else
      If Result = 6  ; yes
        SaveSourceFile(FileName.s)
      EndIf
      SCI_ClearAll()
      SCI_SetSavePoint()
      
    EndIf
  Else
    SCI_ClearAll()
    SCI_SetSavePoint()
    
  EndIf
EndProcedure



Procedure create_toolbar()
  
  If CreateToolBar(#TOOLBAR, WindowID())
    
    ToolBarStandardButton(#MENU_New, #PB_ToolBarIcon_New)
    ToolBarToolTip(#MENU_New,"New file")
    
    ToolBarStandardButton(#MENU_Open, #PB_ToolBarIcon_Open)
    ToolBarToolTip(#MENU_Open,"Open file")
    
    ToolBarSeparator()
    
    ToolBarStandardButton(#MENU_Save, #PB_ToolBarIcon_Save)
    ToolBarToolTip(#MENU_Save,"Save current file")
    
    ToolBarStandardButton(#MENU_SaveAs, #PB_ToolBarIcon_Save)
    ToolBarToolTip(#MENU_SaveAs,"Save current file As ...")
    
    
    ToolBarSeparator()
    
    ToolBarImageButton(#MENU_Close, #PB_ToolBarIcon_Delete)
    ToolBarToolTip(#MENU_Close,"Close")
    
    ToolBarSeparator()
    
    
    i0=CreateImage(#PB_Any,16,16)  ;- Hack because no default < icon
    StartDrawing(ImageOutput())
    BackColor(204,204,204)
    DrawText(" < ")
    StopDrawing()
     ToolBarImageButton(#MENU_Previous, UseImage(i0))
    ToolBarToolTip(#MENU_Previous,"Previous")
    
    i1=CreateImage(#PB_Any,16,16) ;- Hack because no default > icon
    StartDrawing(ImageOutput())
    BackColor(204,204,204)
    DrawText(" > ")
    StopDrawing()
     ToolBarImageButton(#MENU_Next, UseImage(i1))
    ToolBarToolTip(#MENU_Next,"Next")
    
    ToolBarSeparator()
    
    ToolBarStandardButton(#MENU_Cut, #PB_ToolBarIcon_Cut)
    ToolBarToolTip(#MENU_Cut,"Cut")
    
    ToolBarStandardButton(#MENU_Copy, #PB_ToolBarIcon_Copy)
    ToolBarToolTip(#MENU_Copy,"Copy")
    
    ToolBarStandardButton(#MENU_Paste, #PB_ToolBarIcon_Paste)
    ToolBarToolTip(#MENU_Paste,"Paste")
    
    ToolBarSeparator()
    
    ToolBarStandardButton(#MENU_Undo, #PB_ToolBarIcon_Undo)
    ToolBarToolTip(#MENU_Undo,"Undo")
    
    ToolBarStandardButton(#MENU_Redo, #PB_ToolBarIcon_Redo)
    ToolBarToolTip(#MENU_Redo,"Redo")
    
    ToolBarSeparator()
    
  EndIf
  
EndProcedure

Posted: Thu Jun 30, 2005 10:54 pm
by Progi1984
@Dontmailme, which version of Scintilla do you use ?
Can send me via mail a zip of your dll ?

Posted: Fri Jul 01, 2005 12:10 am
by dontmailme
Hi

I have the latest one from the scintilla site....

It is here http://prdownloads.sourceforge.net/scin ... p?download

:)

Posted: Sun Jul 03, 2005 6:24 pm
by Progi1984
OK Thank you for your code and your answer

Posted: Tue Sep 27, 2005 4:43 am
by Shannara
Hmm 1/2 of the above code is missing ...

Code: Select all

;- Include Files
XIncludeFile "Scintilla.pbi"
Please include above file needed for the above sample to work :)

And before you guys say use Search, that tool is lucky to work 1/4th the time :) A simple search under "Scintilla.pbi" gives 100% false positives. IE, it returns a whole bunch of results with no "Scintilla.pbi" in there at all.

Posted: Tue Sep 27, 2005 5:06 am
by Paul
Shannara wrote:A simple search under "Scintilla.pbi" gives 100% false positives. IE, it returns a whole bunch of results with no "Scintilla.pbi" in there at all.
Hmm...

I type Scintilla.pbi into the search box and select "Search for all terms" and it returns 10 (and only 10) very relevant results. I think the common mistake is forgetting to check this option.

Looking at the results tells me that "Scintilla.pbi" is included in the source code for jaPBe. Specifically in the Include Pack.

Here's the file to make it a little easier :)
http://www.pureproject.net/FILES/Scintilla.pbi

Posted: Tue Sep 27, 2005 7:12 pm
by Shannara
That option must be it :) I dloaded the japbe exe file and the source but not the tools, and that is where the bugger must be hiding. Hmm, i dont know why phpbb is unable to search a single word .. that period must be another phpbb "quirk"