EditorGadget with Linenumbers

Just starting out? Need help? Post your questions and find answers here.
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Wow :D
/A litte Fanfare would be appropriate here / :)
Thats cool Sparkie 8)
I need a closer look on this, this should worke with both big-and smallfonts i think, no drawtext here, i try it out.
The only thing i see missing glanceing is if you paste text in with a diffrent fontsize, "the ability to check for that and update and reformat all text back to the default chosen fontsize"

i go' play with it

Ohe btw. what were you planing to do with "UseJPEGImageDecoder()" ??
Btw. btw Win98se


Best Regrads
Henrik.
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

@Sparkie
You asked
; --> This hides scrollbar in Linenumbers EditorGadget
; --> Maybe a better way????
;InvalidateRect_(GadgetID(#HideSB), 0, 1)
Funny on my win98 i don't need ContainerGadget as long as the Linenumber gadget's width is bigger than the width off the linenumber.
i tried to use ShowScrollBar_(GadgetID(#LineNumbers),#SB_BOTH,#False) insted off InvalidateRect_() but it flikers.
But in the pb editor when linenumber is > 1000 the linnumber-field resizes, so it's still fits..

Another interesting thing i notis is that the linenumber max is \wNumberingStart + 255 why is that ?

Night
Best Regards
Henrik
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks for the input Henrik :)
Henrik wrote:Ohe btw. what were you planing to do with "UseJPEGImageDecoder()" ??
I was using code from another EditorGadget project I had and it used a jpg in a DataSection for a background image. I just forgot to remove that line. :oops:
Henrik wrote:Another interesting thing i notis is that the linenumber max is \wNumberingStart + 255 why is that ?
Not sure about that one. :?

I've re-done the code and it works well on WinXP but I'm having some issues with Win98. I'm going to try another Win98 box when I get to work because I think my Win98 at home needs an overhaul. A simple scroll action in the PB editor is impossible. :cry:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

@Sparkie Looking forward to see what you have done..:D
Win98 Rulz... Lol, well i test it as soon as i can, my
vacation has just been cansled :evil: , maybe i can do some off the
worke home, but the next 2 dayes can't. :evil:
ah i was bored anyway, you know, eating, drinking having a good time who cares
...
..
eh..i do.. :cry:

Best regrads
Henrik
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Sorry to hear about your canceled vacation Henrik :(

I still dont' have the paste event working properly, and there's still some flickering in the numbers update, but most everything else seems to work on WinXPhome with PB 3.92.

I've been staring at this code too long. I need a fresh set of eyes to find other bugs/glitches. ;)

Code: Select all

; *************************************************************
; Title:          Sparkies EditorGadget with line numbers" 
; Author:         Spakie 
; Start Date:     December 24, 2004 9:50 AM 
; Version 0.17B:  December 28, 2004 9:55 AM 
; License:        Free to use, optimize, and modify at will :) 
; *************************************************************
#SCF_ALL = 4
#PFM_NUMBERINGSTART = $8000
#PFM_NUMBERINGSTYLE = $2000
#PFM_NUMBERINGTAB = $4000
Enumeration
  #LineNumbers
  #Editor
  #Lines_Conatiner
EndEnumeration
Procedure.l myWindowCallback(hwnd, msg, wparam, lparam) 
  Shared previousItems
  result = #PB_ProcessPureBasicEvents
  Select msg 
    Case #WM_COMMAND
      If lparam = GadgetID(#Editor)
        Select wparam >>16&$FFFF
          Case #EN_VSCROLL
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (clicking scroll buttons)
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT)
            ; --> Keep numbers from scrolling left
            egOne\x = 0
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne)
          Case #EN_UPDATE
            SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat)
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (dragging scroll thumb)
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT)
            ; --> Keep numbers from scrolling left
            egOne\x = 0
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne)
          Case #EN_CHANGE
            ; --> Keep linenumbers in sync with EditorGadget adding or removing items
            currentLine = SendMessage_(GadgetID(#Editor), #EM_LINEFROMCHAR, -1, 0)+1
            egItems = CountGadgetItems(#Editor)
            ; --> For now I just clear the entire number list when items are
            ; --> added or removed. Causes slight flicker so find a better way!
            If egItems <> previousItems
              ClearGadgetItemList(#LineNumbers)
              For i = 1 To egItems
                AddGadgetItem(#LineNumbers, i, RSet(Str(i), 4, "0"))
              Next i
            EndIf
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (dragging scroll thumb)
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT)
            ; --> Keep numbers from scrolling left
            egOne\x = 0
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne)
            previousItems = egItems
        EndSelect
      EndIf
  EndSelect
  ProcedureReturn result 
EndProcedure 
If OpenWindow(0, 0, 0, 700, 490, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "EditorGadget w/Line Numbers") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@myWindowCallback())
  ; --> Put Linenumbers in a narrow conatiner to hide scrollbars
  ContainerGadget(#Lines_Conatiner, 0, 0, 50, 490)
  EditorGadget(#LineNumbers, 3, 3, 75, 484)
  AddGadgetItem(#LineNumbers, -1, "0001")
  ; --> Set background color for numbers
  SendMessage_(GadgetID(#LineNumbers), #EM_SETBKGNDCOLOR, 0, RGB(248, 248, 220))
  ; --> readonly for linenumbers
  SendMessage_(GadgetID(#LineNumbers), #EM_SETREADONLY, 1, 0)
  CloseGadgetList()
  EditorGadget(#Editor, 50, 3, 647, 484)
  ; --> Set Editor to 64K text limit
  SendMessage_(GadgetID(#Editor), #EM_SETLIMITTEXT, 0, 0)
  ; --> Set background color for Editorgadget
  SendMessage_(GadgetID(#Editor), #EM_SETBKGNDCOLOR, 0, RGB(228, 228, 200))
  ; --> Set #EN_UPDATE, #EN_CHANGE and #EN_SCROLL event catching for EditorGadget
  SendMessage_(GadgetID(#Editor), #EM_SETEVENTMASK, 0, #ENM_UPDATE | #ENM_CHANGE | #ENM_SCROLL | #ENM_KEYEVENTS)
  ; --> CHARFORMAT structure used for basic text formatting
  egFormat.CHARFORMAT
  egFormat\cbSize = SizeOf(CHARFORMAT)
  ; --> we'll set our formatting members to change SIZE
  egFormat\dwMask =  #CFM_SIZE | #CFM_COLOR
  ; --> I'll use 12pt type (yHeight is twips 1/1440 of an inch | 1/20 of printer point)
  egFormat\yHeight = 12*20
  ; --> send info to both EditorGadgets
  egFormat\crTextColor = RGB(0, 80, 0)
  SendMessage_(GadgetID(#LineNumbers), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat)
  egFormat\crTextColor = RGB(0, 0, 80)
  SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat)
  Repeat
    event = WaitWindowEvent()
    ; --> Keep focus out of linenumbers
    If EventGadgetID() = #LineNumbers
      ActivateGadget(#Editor)
    EndIf
  Until event = #PB_Event_CloseWindow  
EndIf 
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

@Sparkie i think i got it working it must be a bug in RemoveGadgetItem() or the editorgadget
Btw. vacation stuff is okay i was prepared for this to happend
when i have cleand teh editor up i post the changes
But meanwhile Look at this code
as far i know it should have been RemoveGadgetItem(0, CountGadgetItems(0)-1) but it is -2?? am i right ??

Code: Select all

If OpenWindow(0,0,150,322,150,#PB_Window_SystemMenu,"EditorGadget") And CreateGadgetList(WindowID(0)) 
    EditorGadget (0,8,8,306,133,#PB_Container_Raised) 
    For a=0 To 5 
      AddGadgetItem(0,a,"Line "+Str(a)) 
    Next 
    Debug CountGadgetItems(0)
    
   StartTime = ElapsedMilliseconds() 
    Repeat :
    Event=WindowEvent() 
    If Event=0:Delay(1):endif
    If ElapsedMilliseconds()-StartTime >3000 
    ;RemoveGadgetItem(0, CountGadgetItems(0)-1)
    RemoveGadgetItem(0, CountGadgetItems(0)-2)
    Debug CountGadgetItems(0)
   StartTime = ElapsedMilliseconds() 
    EndIf
    Until Event=#PB_Event_CloseWindow 
  EndIf 
I just got home so i just say hello to the family :) and drink a cup off coffee with them.
Best regrads
Henrik
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

My best guess is that AddGadgetItem() and RemoveGadgetItem() both leave a CR/LF, leaving a blank line which counts as a valid item. Here's one workaround, using a Backspace after the last AddGadgetItem() and each RemoveGadgetItem(). Now the CountGadgetItems(0)-1 works as expected.

Code: Select all

If OpenWindow(0,0,150,322,150,#PB_Window_SystemMenu,"EditorGadget") And CreateGadgetList(WindowID(0)) 
  EditorGadget (0,8,8,306,133,#PB_Container_Raised) 
  For a=0 To 5 
    AddGadgetItem(0,a,"Line "+Str(a)) 
  Next 
  ; --> Remove the last CR/LF left behind by AddGadgetItem
  SendMessage_(GadgetID(0), #WM_KEYDOWN, #VK_BACK, 0)
  SendMessage_(GadgetID(0), #WM_KEYUP, #VK_BACK, 0)
  Debug CountGadgetItems(0) 
  
  StartTime = ElapsedMilliseconds() 
  Repeat : 
    event=WindowEvent() 
    If event=0:Delay(1):EndIf 
    If ElapsedMilliseconds()-StartTime >3000 
      RemoveGadgetItem(0, CountGadgetItems(0)-1) 
      ;RemoveGadgetItem(0, CountGadgetItems(0)-2) 
      ; --> Remove the CR/LF left behind by RemoveGadgetItem
      SendMessage_(GadgetID(0), #WM_KEYDOWN, #VK_BACK, 0)
      SendMessage_(GadgetID(0), #WM_KEYUP, #VK_BACK, 0)
      Debug CountGadgetItems(0) 
      StartTime = ElapsedMilliseconds() 
    EndIf 
  Until event=#PB_Event_CloseWindow 
EndIf 
I've got the paste problem solved, now I'm working on the drag-n-drop issue. I'll also go back and see if I can use the above workaround for anything productive. Thanks Henrik for opening my eyes. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Holy Crap weird, never would have guessed that 8O
My solution was to use 3 RemoveGadgetItem and a SetGadgetItemText
but thats messy ..

Code: Select all

RemoveGadgetItem(#LineNumbers, CountGadgetItems(#LineNumbers))
RemoveGadgetItem(#LineNumbers, CountGadgetItems(#LineNumbers)-1)
RemoveGadgetItem(#LineNumbers, CountGadgetItems(#LineNumbers)-2)
SetGadgetItemText(#LineNumbers, CountGadgetItems(#LineNumbers), Str(CountGadgetItems(#LineNumbers)), 0) 
I've got the paste problem solved, now I'm working on the drag-n-drop issue.
Thats very cool, i tried to catch WM_PASTE but couldn't ! gona be interesting how you do that :D

I see that it helps you, when i drink coffee with the family. :twisted:

Best regrads
Henrik..
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Ok Henrik, it's coffee time :)

This is turning into something semi-useful for me ;)

Still to do:
Check various content to enable / disable menu items.
Find a better way to handle numbering (right now I clear the list each change). :roll:
Add more features as they enter my head.

Code: Select all

; ************************************************************* 
; Title:          Sparkies EditorGadget with line numbers" 
; Author:         Spakie 
; Start Date:     December 24, 2004 9:50 AM 
; Version 0.21B:  December 28, 2004 5:30 PM 
; License:        Free to use, optimize, and modify at will :) 
; ************************************************************* 
#SES_EMULATESYSEDIT = 1
#SCF_ALL = 4 
#PFM_NUMBERINGSTART = $8000 
#PFM_NUMBERINGSTYLE = $2000 
#PFM_NUMBERINGTAB = $4000 
Enumeration
  #MainWin
EndEnumeration
Enumeration
  #StatusBar
  #MainMenu
  #EditorPopup
EndEnumeration
Enumeration 
  #LineNumbers 
  #Editor 
  #Lines_Conatiner 
EndEnumeration 
; --> For our Select All popup menu command
editSel.CHARRANGE 
; --> Main window callback procedure
Procedure.l myWindowCallback(hwnd, msg, wparam, lparam) 
  Shared previousItems 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_COMMAND 
      If lparam = GadgetID(#Editor) 
        Select wparam >>16&$FFFF 
          Case #EN_VSCROLL 
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (clicking scroll buttons) 
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT) 
            ; --> Keep numbers from scrolling left 
            egOne\x = 0 
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne) 
          Case #EN_UPDATE 
            SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat) 
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (dragging scroll thumb) 
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT) 
            ; --> Keep numbers from scrolling left 
            egOne\x = 0 
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne) 
          Case #EN_CHANGE 
            ; --> Keep linenumbers in sync with EditorGadget adding or removing items 
            currentLine = SendMessage_(GadgetID(#Editor), #EM_LINEFROMCHAR, -1, 0)+1 
            egItems = CountGadgetItems(#Editor) 
            ; --> For now I just clear the entire number list when items are 
            ; --> added or removed. >>>>>>>>>>>>>  Causes slight flicker so find a better way! <<<<<<<<<<<<<<
            If egItems <> previousItems 
              ClearGadgetItemList(#LineNumbers) 
              For i = 1 To egItems 
                AddGadgetItem(#LineNumbers, i, RSet(Str(i), 4, "0")) 
              Next i 
            EndIf 
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (dragging scroll thumb) 
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT) 
            ; --> Keep numbers from scrolling left 
            egOne\x = 0 
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne) 
            previousItems = egItems 
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
; --> Open a file procedure
Procedure openTheFile()
  oFile$ = OpenFileRequester("Select a File", "c:\", "Text file (.txt) | *.txt", 0)
  If FileSize(oFile$) > 0 And FileSize(oFile$) < 65535
    If ReadFile(0, oFile$)
      ClearGadgetItemList(#LineNumbers)
      ClearGadgetItemList(#Editor)
      While Eof(0) = 0
        egText$ + ReadString() + Chr(13)
      Wend
      AddGadgetItem(#Editor, -1, egText$)
      CloseFile(0)
    Else
      MessageRequester("Error", "Could not open file: " + oFile$, #MB_ICONERROR)
    EndIf
  Else
    MessageRequester("Error", "File not found: " + oFile$, #MB_ICONERROR)
  EndIf
EndProcedure
; --> Main window and gadgets
If OpenWindow(#MainWin, 0, 0, 700, 500, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "EditorGadget w/Line Numbers") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@myWindowCallback()) 
  CreateStatusBar(#StatusBar, WindowID(#MainWin))
  ; --> Main menu
  CreateMenu(#MainMenu, WindowID(#MainWin))
  MenuTitle("&File") 
  MenuItem(101, "&Open" + Chr(9 ) + "Ctrl+O") 
  MenuItem(102, "&Save")
  MenuItem(103, "S&ave as") 
  MenuItem(104, "&Quit" + Chr(9) + "Ctrl+Q") 
  MenuTitle("&Edit")
  MenuItem(111, "&Undo" + Chr(9 ) + "Ctrl+z") 
  MenuBar() 
  MenuItem(112, "&Cut" + Chr(9 ) + "Ctrl+X") 
  MenuItem(113, "C&opy" + Chr(9 ) + "Ctrl+C") 
  MenuItem(114, "&Paste" + Chr(9 ) + "Ctrl+V") 
  MenuBar() 
  MenuItem(115, "Select &All" + Chr(9 ) + "Ctrl+A") 
  AddKeyboardShortcut(#MainWin, #PB_Shortcut_Control | #PB_Shortcut_O, 101)
  ; disabled AddKeyboardShortcut(#MainWin, #PB_Shortcut_Control | #PB_Shortcut_S, 102)
  ; disabled AddKeyboardShortcut(#MainWin, #PB_Shortcut_Control | #PB_Shortcut_A, 103)
  AddKeyboardShortcut(#MainWin, #PB_Shortcut_Control | #PB_Shortcut_Q, 104)
  ; --> Disable save and save as for now
  DisableMenuItem(102, 1)
  DisableMenuItem(103, 1)
  ; --> Put Linenumbers in a narrow conatiner to hide scrollbars 
  ContainerGadget(#Lines_Conatiner, 0, 0, 50, 460) 
  EditorGadget(#LineNumbers, 3, 3, 75, 454) 
  AddGadgetItem(#LineNumbers, -1, "0001") 
  ; --> Set background color for numbers 
  SendMessage_(GadgetID(#LineNumbers), #EM_SETBKGNDCOLOR, 0, RGB(248, 248, 220)) 
  ; --> readonly for linenumbers 
  SendMessage_(GadgetID(#LineNumbers), #EM_SETREADONLY, 1, 0) 
  CloseGadgetList() 
  EditorGadget(#Editor, 50, 3, 647, 454) 
  ; --> Draft mode forces plain text
  SendMessage_(GadgetID(#Editor), #EM_SETEDITSTYLE , #SES_EMULATESYSEDIT, #SES_EMULATESYSEDIT)
  ; --> Set Editor to 64K text limit 
  SendMessage_(GadgetID(#Editor), #EM_SETLIMITTEXT, 0, 0) 
  ; --> Set background color for Editorgadget 
  SendMessage_(GadgetID(#Editor), #EM_SETBKGNDCOLOR, 0, RGB(228, 228, 200)) 
  ; --> Set #EN_UPDATE, #EN_CHANGE and #EN_SCROLL event catching for EditorGadget 
  SendMessage_(GadgetID(#Editor), #EM_SETEVENTMASK, 0, #ENM_UPDATE | #ENM_CHANGE | #ENM_SCROLL | #ENM_KEYEVENTS) 
  ; --> CHARFORMAT structure used for basic text formatting 
  egFormat.CHARFORMAT 
  egFormat\cbSize = SizeOf(CHARFORMAT) 
  ; --> we'll set our formatting members to change SIZE 
  egFormat\dwMask =  #CFM_SIZE | #CFM_COLOR 
  ; --> I'll use 12pt type (yHeight is twips 1/1440 of an inch | 1/20 of printer point) 
  egFormat\yHeight = 12*20 
  ; --> send info to both EditorGadgets 
  egFormat\crTextColor = RGB(0, 80, 0) 
  SendMessage_(GadgetID(#LineNumbers), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat) 
  egFormat\crTextColor = RGB(0, 0, 80) 
  SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat) 
  ; --> Create a popup menu for EditorGadget
  CreatePopupMenu(#EditorPopup) 
  MenuItem(201, "&Undo") 
  MenuBar() 
  MenuItem(202, "&Cut") 
  MenuItem(203, "C&opy") 
  MenuItem(204, "&Paste") 
  MenuBar() 
  MenuItem(205, "Select &All") 
  ; --> Main loop
  Repeat 
    event = WaitWindowEvent() 
    ; --> Keep focus out of linenumbers 
    If EventGadgetID() = #LineNumbers 
      ActivateGadget(#Editor) 
    EndIf 
    Select event
      Case #WM_RBUTTONDOWN 
        If EventGadgetID() = #Editor 
          GetCursorPos_(mouseP.POINT) 
          If Len(GetGadgetText(#Editor)) < 1 
            DisableMenuItem(201,1) 
            DisableMenuItem(202,1) 
            DisableMenuItem(203,1) 
            DisableMenuItem(205,1) 
            DisableMenuItem(206,1) 
          Else 
            DisableMenuItem(201,0) 
            DisableMenuItem(202,0) 
            DisableMenuItem(203,0) 
            DisableMenuItem(205,0) 
            DisableMenuItem(206,0) 
          EndIf 
          DisplayPopupMenu(#EditorPopup,WindowID(),mouseP\x, mouseP\y) 
        EndIf 
      Case #PB_EventMenu 
        Select EventMenuID()
          
          ; --> Main menu items 101 - 199
          Case 101
            openTheFile()
          Case 102
            Debug "Save disabled"
          Case 103
            Debug "Save as disabled"
          Case 104
            CloseWindow(#MainWin)
          Case 111
            SendMessage_(GadgetID(#Editor), #WM_UNDO, 0, 0)
          Case 112
            SendMessage_(GadgetID(#Editor), #WM_CUT, 0, 0) 
          Case 113
            SendMessage_(GadgetID(#Editor), #WM_COPY, 0, 0) 
            SendMessage_(GadgetID(#Editor), #EM_SETSEL, -1, 0)
            ActivateGadget(#Editor) 
          Case 114
            ; >>>>>> Still need to check for proper format do disable paste command as necessary <<<<<<
            SendMessage_(GadgetID(#Editor), #WM_PASTE, 0, 0)
          Case 115
            editSel\cpMin = 0 
            editSel\cpMax = -1 
            SendMessage_(GadgetID(#Editor), #EM_EXSETSEL, 0, @editSel)
            
          ; --> Popup menu items 201 - 299
          Case 201 
              SendMessage_(GadgetID(#Editor), #WM_UNDO, 0, 0) 
          Case 202 
            SendMessage_(GadgetID(#Editor), #WM_CUT, 0, 0) 
          Case 203 
            SendMessage_(GadgetID(#Editor), #WM_COPY, 0, 0) 
            SendMessage_(GadgetID(#Editor), #EM_SETSEL, -1, 0); 
            ActivateGadget(#Editor) 
          Case 204 
            ; >>>>>> Still need to check for proper format do disable paste command as necessary <<<<<<
            SendMessage_(GadgetID(#Editor), #WM_PASTE, 0, 0)
          Case 205 
            editSel\cpMin = 0 
            editSel\cpMax = -1 
            SendMessage_(GadgetID(#Editor), #EM_EXSETSEL, 0, @editSel) 
        EndSelect 
    EndSelect
  Until event = #PB_Event_CloseWindow  
EndIf 
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Oh nooo, no more coffee i can't sleep
Gonna look at this one, the paste tingie ting seems to work 8) not sure how you did that :D
Yes it's kind off addictive stuff, me likes :D

still have a few hours to play gonna mess about with your

Code: Select all

; --> Remove the last CR/LF left behind by AddGadgetItem
  SendMessage_(GadgetID(0), #WM_KEYDOWN, #VK_BACK, 0)
  SendMessage_(GadgetID(0), #WM_KEYUP, #VK_BACK, 0) 
in the new source instead..
C U
Best Regrads
Henrik..
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hmm i still think there is something fishy goging on here with RemoveGadgetItem()

But this will remove the flicker
Insted off this:

Code: Select all

Case #EN_CHANGE
 ; --> Keep linenumbers in sync with EditorGadget adding or removing items
currentLine = SendMessage_(GadgetID(#Editor), #EM_LINEFROMCHAR, -1, 0)+1
egItems = CountGadgetItems(#Editor)
; --> For now I just clear the entire number list when items are
; --> added or removed. >>>>>>>>>>>>>  Causes slight flicker so find a better way! <<<<<<<<<<<<<<
If egItems <> previousItems
ClearGadgetItemList(#LineNumbers)
For i = 1 To egItems
AddGadgetItem(#LineNumbers, i, RSet(Str(i), 4, "0"))
Next i
EndIf
 
This remove the flicker

Code: Select all

 Case #EN_CHANGE
                ; --> Keep linenumbers in sync with EditorGadget adding or removing items
                currentLine = SendMessage_(GadgetID(#Editor), #EM_LINEFROMCHAR, -1, 0)+1
                egItems = CountGadgetItems(#Editor)
                previousItems = egItems
                If CountGadgetItems(#LineNumbers) < previousItems
                    AddGadgetItem(#LineNumbers, previousItems,RSet(Str(egItems), 4, "0"))
                ElseIf CountGadgetItems(#LineNumbers) > previousItems
                    RemoveGadgetItem(#LineNumbers, previousItems)
                    RemoveGadgetItem(#LineNumbers, previousItems-1)
                    SetGadgetItemText(#LineNumbers, CountGadgetItems(#LineNumbers), RSet(Str(CountGadgetItems(#LineNumbers)), 4, "0"), 0)
                EndIf
Edit..Damn just noticed then the paste does'nt work. lol
have to wait tomorow ..


Night
Best Regrads
Henrik
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks for all the help Henrik :)

Here's what I now have. When you have time, see if the flicker is reduced for you.

Code: Select all

; ************************************************************* 
; Title:          Sparkies EditorGadget with line numbers" 
; Author:         Spakie 
; Start Date:     December 24, 2004 9:50 AM 
; Version 0.23B:  December 28, 2004 8:45 PM 
; License:        Free to use, optimize, and modify at will :) 
; ************************************************************* 
#SES_EMULATESYSEDIT = 1 
#SCF_ALL = 4 
#PFM_NUMBERINGSTART = $8000 
#PFM_NUMBERINGSTYLE = $2000 
#PFM_NUMBERINGTAB = $4000 
Enumeration 
  #MainWin 
EndEnumeration 
Enumeration 
  #StatusBar 
  #MainMenu 
  #EditorPopup 
EndEnumeration 
Enumeration 
  #LineNumbers 
  #Editor 
  #Lines_Conatiner 
EndEnumeration 
; --> For our Select All popup menu command 
editSel.CHARRANGE 
; --> Main window callback procedure 
Procedure.l myWindowCallback(hwnd, msg, wparam, lparam) 
  Shared previousItems 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_COMMAND 
      If lparam = GadgetID(#Editor) 
        Select wparam >>16&$FFFF 
          Case #EN_VSCROLL 
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (clicking scroll buttons) 
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT) 
            ; --> Keep numbers from scrolling left 
            egOne\x = 0 
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne) 
          Case #EN_UPDATE 
            SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat) 
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (dragging scroll thumb) 
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT) 
            ; --> Keep numbers from scrolling left 
            egOne\x = 0 
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne) 
          Case #EN_CHANGE 
            ; --> Keep linenumbers in sync with EditorGadget adding or removing items 
            currentLine = SendMessage_(GadgetID(#Editor), #EM_LINEFROMCHAR, -1, 0)+1 
            lnItems = CountGadgetItems(#LineNumbers) 
            egItems = CountGadgetItems(#Editor) 
            ; --> For now I just clear the entire number list when items are 
            ; --> added or removed. >>>>>>>>>>>>>  Causes slight flicker so find a better way! <<<<<<<<<<<<<< 
            If egItems > lnItems
              For i = lnItems+1 To egItems 
                AddGadgetItem(#LineNumbers, i, RSet(Str(i), 4, "0")) 
              Next i 
            EndIf 
            If egItems < lnItems
              For i = lnItems To egItems Step -1
                RemoveGadgetItem(#LineNumbers, i)
              Next i 
              ; --> Remove the last CR/LF left behind by RemoveGadgetItem 
              ; --> Readonly off for linenumbers 
              SendMessage_(GadgetID(#LineNumbers), #EM_SETREADONLY, 0, 0) 
              SendMessage_(GadgetID(#LineNumbers), #WM_KEYDOWN, #VK_BACK, 0) 
              SendMessage_(GadgetID(#LineNumbers), #WM_KEYUP, #VK_BACK, 0) 
              ; --> Readonly for linenumbers 
              SendMessage_(GadgetID(#LineNumbers), #EM_SETREADONLY, 1, 0) 
            EndIf 
            ; --> Keep linenumbers in sync with EditorGadget scrolling up or down (dragging scroll thumb) 
            SendMessage_(GadgetID(#Editor), #EM_GETSCROLLPOS, 0, @egOne.POINT) 
            ; --> Keep numbers from scrolling left 
            egOne\x = 0 
            SendMessage_(GadgetID(#LineNumbers), #EM_SETSCROLLPOS, 0, egOne) 
            previousItems = egItems 
            Debug CountGadgetItems(#LineNumbers)
            Debug CountGadgetItems(#Editor)
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
; --> Open a file procedure 
Procedure openTheFile() 
  oFile$ = OpenFileRequester("Select a File", "c:\", "Text file (.txt) | *.txt", 0) 
  If FileSize(oFile$) > 0 And FileSize(oFile$) < 65535 
    If ReadFile(0, oFile$) 
      ClearGadgetItemList(#LineNumbers) 
      ClearGadgetItemList(#Editor) 
      While Eof(0) = 0 
        egText$ + ReadString() + Chr(13) 
      Wend 
      AddGadgetItem(#Editor, -1, egText$) 
      CloseFile(0) 
    Else 
      MessageRequester("Error", "Could not open file: " + oFile$, #MB_ICONERROR) 
    EndIf 
  Else 
    MessageRequester("Error", "File not found: " + oFile$, #MB_ICONERROR) 
  EndIf 
EndProcedure 
; --> Main window and gadgets 
If OpenWindow(#MainWin, 0, 0, 700, 500, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "EditorGadget w/Line Numbers") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@myWindowCallback()) 
  CreateStatusBar(#StatusBar, WindowID(#MainWin)) 
  ; --> Main menu 
  CreateMenu(#MainMenu, WindowID(#MainWin)) 
  MenuTitle("&File") 
  MenuItem(101, "&Open" + Chr(9 ) + "Ctrl+O") 
  MenuItem(102, "&Save") 
  MenuItem(103, "S&ave as") 
  MenuItem(104, "&Quit" + Chr(9) + "Ctrl+Q") 
  MenuTitle("&Edit") 
  MenuItem(111, "&Undo" + Chr(9 ) + "Ctrl+z") 
  MenuBar() 
  MenuItem(112, "&Cut" + Chr(9 ) + "Ctrl+X") 
  MenuItem(113, "C&opy" + Chr(9 ) + "Ctrl+C") 
  MenuItem(114, "&Paste" + Chr(9 ) + "Ctrl+V") 
  MenuBar() 
  MenuItem(115, "Select &All" + Chr(9 ) + "Ctrl+A") 
  AddKeyboardShortcut(#MainWin, #PB_Shortcut_Control | #PB_Shortcut_O, 101) 
  ; disabled AddKeyboardShortcut(#MainWin, #PB_Shortcut_Control | #PB_Shortcut_S, 102) 
  ; disabled AddKeyboardShortcut(#MainWin, #PB_Shortcut_Control | #PB_Shortcut_A, 103) 
  AddKeyboardShortcut(#MainWin, #PB_Shortcut_Control | #PB_Shortcut_Q, 104) 
  ; --> Disable save and save as for now 
  DisableMenuItem(102, 1) 
  DisableMenuItem(103, 1) 
  ; --> Put Linenumbers in a narrow conatiner to hide scrollbars 
  ContainerGadget(#Lines_Conatiner, 0, 0, 50, 460) 
  EditorGadget(#LineNumbers, 3, 3, 75, 454) 
  AddGadgetItem(#LineNumbers, -1, "0001") 
  ; --> Set background color for numbers 
  SendMessage_(GadgetID(#LineNumbers), #EM_SETBKGNDCOLOR, 0, RGB(248, 248, 220)) 
  ; --> readonly for linenumbers 
  SendMessage_(GadgetID(#LineNumbers), #EM_SETREADONLY, 1, 0) 
  CloseGadgetList() 
  EditorGadget(#Editor, 50, 3, 647, 454) 
  ; --> Draft mode forces plain text 
  SendMessage_(GadgetID(#Editor), #EM_SETEDITSTYLE , #SES_EMULATESYSEDIT, #SES_EMULATESYSEDIT) 
  ; --> Set Editor to 64K text limit 
  SendMessage_(GadgetID(#Editor), #EM_SETLIMITTEXT, 0, 0) 
  ; --> Set background color for Editorgadget 
  SendMessage_(GadgetID(#Editor), #EM_SETBKGNDCOLOR, 0, RGB(228, 228, 200)) 
  ; --> Set #EN_UPDATE, #EN_CHANGE and #EN_SCROLL event catching for EditorGadget 
  SendMessage_(GadgetID(#Editor), #EM_SETEVENTMASK, 0, #ENM_UPDATE | #ENM_CHANGE | #ENM_SCROLL | #ENM_KEYEVENTS) 
  ; --> CHARFORMAT structure used for basic text formatting 
  egFormat.CHARFORMAT 
  egFormat\cbSize = SizeOf(CHARFORMAT) 
  ; --> we'll set our formatting members to change SIZE 
  egFormat\dwMask =  #CFM_SIZE | #CFM_COLOR 
  ; --> I'll use 12pt type (yHeight is twips 1/1440 of an inch | 1/20 of printer point) 
  egFormat\yHeight = 12*20 
  ; --> send info to both EditorGadgets 
  egFormat\crTextColor = RGB(0, 80, 0) 
  SendMessage_(GadgetID(#LineNumbers), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat) 
  egFormat\crTextColor = RGB(0, 0, 80) 
  SendMessage_(GadgetID(#Editor), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat) 
  ; --> Create a popup menu for EditorGadget 
  CreatePopupMenu(#EditorPopup) 
  MenuItem(201, "&Undo") 
  MenuBar() 
  MenuItem(202, "&Cut") 
  MenuItem(203, "C&opy") 
  MenuItem(204, "&Paste") 
  MenuBar() 
  MenuItem(205, "Select &All") 
  ; --> Main loop 
  Repeat 
    event = WaitWindowEvent() 
    ; --> Keep focus out of linenumbers 
    If EventGadgetID() = #LineNumbers 
      ActivateGadget(#Editor) 
    EndIf 
    Select event 
      Case #WM_RBUTTONDOWN 
        xPos = WindowMouseX()
        yPos = WindowMouseY()
        If xPos >= GadgetX(#Editor)+2 And xPos <= (GadgetX(#Editor)+ GadgetWidth(#Editor)-4)
          If yPos >= GadgetY(#Editor)+2 And yPos <= (GadgetY(#Editor)+ GadgetHeight(#Editor)-4)
            If Len(GetGadgetText(#Editor)) < 1 
              DisableMenuItem(201,1) 
              DisableMenuItem(202,1) 
              DisableMenuItem(203,1) 
              DisableMenuItem(205,1) 
              DisableMenuItem(206,1) 
            Else 
              DisableMenuItem(201,0) 
              DisableMenuItem(202,0) 
              DisableMenuItem(203,0) 
              DisableMenuItem(205,0) 
              DisableMenuItem(206,0) 
            EndIf 
            DisplayPopupMenu(#EditorPopup,WindowID(),xPos, yPos) 
          EndIf 
        EndIf
      Case #PB_EventMenu 
        Select EventMenuID() 
          
          ; --> Main menu items 101 - 199 
          Case 101 
            openTheFile() 
          Case 102 
            Debug "Save disabled" 
          Case 103 
            Debug "Save as disabled" 
          Case 104 
            CloseWindow(#MainWin) 
          Case 111 
            SendMessage_(GadgetID(#Editor), #WM_UNDO, 0, 0) 
          Case 112 
            SendMessage_(GadgetID(#Editor), #WM_CUT, 0, 0) 
          Case 113 
            SendMessage_(GadgetID(#Editor), #WM_COPY, 0, 0) 
            SendMessage_(GadgetID(#Editor), #EM_SETSEL, -1, 0) 
            ActivateGadget(#Editor) 
          Case 114 
            ; >>>>>> Still need to check for proper format do disable paste command as necessary <<<<<< 
            SendMessage_(GadgetID(#Editor), #WM_PASTE, 0, 0) 
          Case 115 
            editSel\cpMin = 0 
            editSel\cpMax = -1 
            SendMessage_(GadgetID(#Editor), #EM_EXSETSEL, 0, @editSel) 
            
            ; --> Popup menu items 201 - 299 
          Case 201 
            SendMessage_(GadgetID(#Editor), #WM_UNDO, 0, 0) 
          Case 202 
            SendMessage_(GadgetID(#Editor), #WM_CUT, 0, 0) 
          Case 203 
            SendMessage_(GadgetID(#Editor), #WM_COPY, 0, 0) 
            SendMessage_(GadgetID(#Editor), #EM_SETSEL, -1, 0); 
            ActivateGadget(#Editor) 
          Case 204 
            ; >>>>>> Still need to check for proper format do disable paste command as necessary <<<<<< 
            SendMessage_(GadgetID(#Editor), #WM_PASTE, 0, 0) 
          Case 205 
            editSel\cpMin = 0 
            editSel\cpMax = -1 
            SendMessage_(GadgetID(#Editor), #EM_EXSETSEL, 0, @editSel) 
        EndSelect 
    EndSelect 
  Until event = #PB_Event_CloseWindow  
EndIf 
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Deleted.... I didn't see Sparkie last post :oops:
no reason to confuse, my code did the same but in a clumsy way :lol:

Best Regrads
Henrik
Last edited by Henrik on Wed Dec 29, 2004 6:50 pm, edited 1 time in total.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Not sure why you had to add the paste flag. My original code works fine here with little or no flicker. I tried your code and see no visible difference. Maybe it's a Win98 thing?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Lol @Sparkie i didm't see your last post, duno maybe i didn't update /refresh the tread, doh 8O
Anyway Your code workes perfectly no flicker on win98 :P

I delete my nonflicker code cuss it's bad and only confuse the sobject
i just duno why it didn't work when i used

Code: Select all

SendMessage_(GadgetID(#LineNumbers), #WM_KEYDOWN, #VK_BACK, 0)
SendMessage_(GadgetID(#LineNumbers), #WM_KEYUP, #VK_BACK, 0)
I didn't save my go at it, so i never know what i did wrong :lol:

Anyway i gonna mess with your last code, but retain from posting abit, as this is turning out to be a tutorial on the subject, meaning the way you build this from scratch, changing bits and pieces here and there, giving a newbe -like me- something to compare with. :D
And no more work this year = lots off coffee :D

Doh .. the EM_SETREADONLY , of course :oops:
And your code is working very well indeed :D
I will be watching this tread, if you decide to post more..
But first Coffee :wink:
Thank you so much for all your help Sparkie i really appreciate it :D


Best Regrads
Henrik
Post Reply