EditorGadget "#ES_NOSCROLL"?

Just starting out? Need help? Post your questions and find answers here.
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

EditorGadget "#ES_NOSCROLL"?

Post by offsides »

There is a wealth of information about how to control and enhance scrolling in the EditorGadget. But is there a way to force an EditorGadget to NOT scroll, to act like a TextGadget that can still handle RTF?

Thanks,
Bill
PB 5.72 (32-bit) on Win 10.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: EditorGadget "#ES_NOSCROLL"?

Post by PB »

> is there a way to force an EditorGadget to NOT scroll

Don't fill it with more text than it can display? :shock:

If it doesn't scroll, then what happens with the unseen text?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EditorGadget "#ES_NOSCROLL"?

Post by IdeasVacuum »

There doesn't seem to be an easy way to do it, basically you have to ensure the text does not exceed the size of the Editor. It is possible, using the 2D Drawing functions, to work out how much text will fit the width of the Editor, and how many lines will fit the height. That's not too dissimilar to this post: http://www.purebasic.fr/english/viewtop ... =7&t=61128

Of course, RTF is going to complicate things, especially if you want more than one font style/size. You might consider using a WebGadget, or a CanvasGadget instead.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: EditorGadget "#ES_NOSCROLL"?

Post by offsides »

Don't fill it with more text than it can display? :shock:
If it doesn't scroll, then what happens with the unseen text?
Haha.
Guess I should explain: I'm currently using a TextGadget. The text going in is measured for pixel width and length and the TG is then sized to fit. Along with the TG are some StringGadgets which are accepting input. This whole "assembly" can be taller than the window but it's plopped in a ScrollAreaGadget, which provides for scrolling the text while keeping the StringGadgets properly aligned. This works nicely. Now, I'd like to add RTF capability. I can do this using an EditorGadget but you can end up with dueling scrollbars. I just thought it would be cleaner if you could turn off scrolling for the EG.

IdeasVacuum, yes, the WebGadget would certainly provide all the text customization but I was hoping for the snappier speed of the EditorGadget. Also, was wanting RTF.

Thanks,
Bill
PB 5.72 (32-bit) on Win 10.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EditorGadget "#ES_NOSCROLL"?

Post by IdeasVacuum »

In that case, this just about works:

Code: Select all

EnableExplicit
Enumeration
#Win
#Editor
#BtnExit
#WinHdn
#EditorHdn
EndEnumeration

Global       igDpi.i = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX)
Global      igFS18.i = ((18 * 100) / igDpi)
Global    igFont18.i = LoadFont(0, "Microsoft Sans Serif", igFS18, #PB_Font_Bold | #PB_Font_HighQuality + 2)

Procedure.i GetTxtLineHgt(iWin.i, iFont.i)
;-----------------------------------------
Protected iLineHgt.i = 0

              If StartDrawing(WindowOutput(iWin))

                      DrawingMode(#PB_2DDrawing_Default)
                      DrawingFont(iFont)
                      iLineHgt = TextHeight("MyĚ")
                      StopDrawing()
              EndIf

              ProcedureReturn(iLineHgt)
EndProcedure

Procedure.i GdtHgt(sTxt.s, iFont.i)
;----------------------------------
Protected iGdtHgt.i, iLineTotal, iLineHgt.i

               If OpenWindow(#WinHdn, 0, 0, 800, 800, "", #PB_Window_Invisible | #PB_Window_ScreenCentered)

                            EditorGadget(#EditorHdn,  0, 0, 300,  800, #PB_Editor_WordWrap)
                           SetGadgetFont(#EditorHdn, iFont)
                           SetGadgetText(#EditorHdn, sTxt)

                           iLineTotal = CountGadgetItems(#EditorHdn) + 1
                             iLineHgt = GetTxtLineHgt(#WinHdn, iFont) + 1
                              iGdtHgt = iLineHgt * iLineTotal
               EndIf

               ProcedureReturn(iGdtHgt)
EndProcedure

Procedure Win()
;--------------
Protected iGdtHgt.i, iExit.i = #False
Protected    sTxt.s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
               sTxt = sTxt + "Nullam molestie commodo magna, id rutrum enim suscipit ac. "
               sTxt = sTxt + "Nunc tempor faucibus magna, vel volutpat tellus luctus et."

               If OpenWindow(#Win, 0, 0, 400, 400, "", #PB_Window_Invisible | #PB_Window_ScreenCentered)

                          SetWindowColor(#Win, RGB(192,192,192))

                            EditorGadget(#Editor,  0,   0, 300,  100, #PB_Editor_WordWrap)
                            ButtonGadget(#BtnExit, 300, 0, 100,   26, "Exit")
                           SetGadgetFont(#Editor, igFont18)

                               iGdtHgt = GdtHgt(sTxt.s, igFont18)

                            ResizeGadget(#Editor, #PB_Ignore, #PB_Ignore, #PB_Ignore, iGdtHgt)
                           SetGadgetText(#Editor, sTxt)
                              HideWindow(#Win, #False)

                         Repeat

                                Select WaitWindowEvent(1)

                                      Case #PB_Event_Gadget

                                          Select EventGadget()

                                              Case #BtnExit: iExit = #True

                                          EndSelect

                                EndSelect

                         Until iExit = #True
               EndIf
EndProcedure

      Win()

End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: EditorGadget "#ES_NOSCROLL"?

Post by offsides »

IdeasVacuum, thanks but the wordwrap won't work in my case. But it doesn't have to, as the text comes pre-formatted. The issue is when you have two nested scrolling gadgets, if the inner one can't be made non-scrollable, you can create some odd looking displays. You can "disable" the EdGadget by being very careful of your Editor/Scroll gadget sizing. Looks like the way I'll have to go.
BTW, thanks for your code, above. Some nice touches in there.

Bill
PB 5.72 (32-bit) on Win 10.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4941
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget "#ES_NOSCROLL"?

Post by RASHAD »

Workaround maybe it will suit you.

Code: Select all

If OpenWindow(0, 0, 0, 300, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(0,10,10,280,130,#PB_Container_Flat)
   EditorGadget(1, -1, -1, 280 + 20,130,#PB_Editor_WordWrap)
CloseGadgetList()
SendMessage_(GadgetID(1), #EM_SETMARGINS, #EC_LEFTMARGIN, 5|0<<16)
SendMessage_(GadgetID(1), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|20<<16)
 
SetGadgetColor(1,#PB_Gadget_BackColor,$E7FEFD)
SetGadgetColor(1,#PB_Gadget_FrontColor,$FF0402)

a.s="{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0 Arial;}}{\colortbl ;\red255\green0\blue0;\red0\green0\blue0;}"
a.s=a.s+"{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20 Hello, this is \cf1\b\fs32 RTF\cf2\b0\fs20 direct!\cf0\par}"

CompilerIf #PB_Compiler_Unicode
  *MemoryBuffer = AllocateMemory(Len(a.s)+1)
  PokeS(*MemoryBuffer, a.s, Len(a.s)+1,#PB_Ascii)
  For x = 0 To 6
      AddGadgetItem(1,x,PeekS(*MemoryBuffer ,Len(a.s)+1,#PB_Unicode))
  Next
CompilerElse
  For x = 0 To 6
      AddGadgetItem(1,x,a.s)
  Next
CompilerEndIf

   Repeat
   Select WaitWindowEvent(10)
         Case #PB_Event_CloseWindow
                 Quit = 1
                 
         Case #PB_Event_Gadget
            Select EventGadget()
              Case 1
                  result = SendMessage_(GadgetID(1), #EM_GETLINECOUNT, 0, 0)
                  If result >= 4
                      RemoveGadgetItem(1,4)
                      HideCaret_(GadgetID(1))
                  EndIf
                                
            EndSelect
      EndSelect
   Until Quit = 1
EndIf

Egypt my love
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: EditorGadget "#ES_NOSCROLL"?

Post by offsides »

Rashad, your usual elegant and concise code.

No, it's not exactly what I'm after but you have set me on the path.
Thank you, thank you.

Bill
PB 5.72 (32-bit) on Win 10.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EditorGadget "#ES_NOSCROLL"?

Post by IdeasVacuum »

Pre-formatted is good - is the content always the same?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: EditorGadget "#ES_NOSCROLL"?

Post by offsides »

No, anything can end up in there, from plain text to rtf.

Bill
PB 5.72 (32-bit) on Win 10.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EditorGadget "#ES_NOSCROLL"?

Post by IdeasVacuum »

Hmm, the difficulty is that the line/row heights can differ greatly in the same paragraph.
Another suggestion, which sounds more complex than it really is:
1) Using a hidden Editor known to be an oversized height, load the text.
2) Change the background and foreground RTF colour of the text (both to black for example).
3) Use the 2D drawing function Point(x, y) to find the first pixel that is the colour of the Editor Gadget.
You then have the maximum height required for your 'real' Editor.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4941
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget "#ES_NOSCROLL"?

Post by RASHAD »

Hi Bill
While I am not sure enough about your request
But the next snippet for RTF Editor = GadgetEditor() No Val Scroll No Hal Scroll hope it will get you close to your aim

Code: Select all

If OpenWindow(0, 0, 0, 300, 200, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
hInstance = GetModuleHandle_(0) 
If OpenLibrary(0,"msftedit.dll")
    Class_Name$ = "RichEdit50W"
  ElseIf OpenLibrary(0,"Riched20.dll") And Class_Name$ = ""
    Class_Name$ = "RichEdit20W"
  ElseIf OpenLibrary(0,"Riched32.dll") And Class_Name$ = ""
    Class_Name$ = "RichEdit"
  Else
    MessageRequester("Error","Sorry ,RichEdit Can not be created",#MB_ICONWARNING)
  EndIf  
 EditText = CreateWindowEx_(#WS_EX_STATICEDGE,Class_Name$,"", #WS_VISIBLE | #WS_CHILDWINDOW | #ES_MULTILINE , 10,10,280,130,WindowID(0),300,hInstance,0) 

ButtonGadget(1,5,170,60,20,"Copy")
ButtonGadget(2,70,170,60,20,"Paste")

a$="{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0 Arial;}}{\colortbl ;\red255\green0\blue0;\red0\green0\blue0;}"
a$=a$+"{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20 Hello, this is \cf1\b\fs32 RTF\cf2\b0\fs20 direct!\cf0\par}"

CompilerIf #PB_Compiler_Unicode
    *Buffer = AllocateMemory(StringByteLength(a$, #PB_Ascii) + 1)
    PokeS(*Buffer, a$, -1, #PB_Ascii)
    SendMessage_(EditText,#EM_REPLACESEL,0,PeekS(*Buffer))
CompilerElse
    SendMessage_(EditText,#EM_SETTEXTEX,0,a$)
CompilerEndIf

Repeat
   Select WaitWindowEvent(10)
         Case #PB_Event_CloseWindow
                 Quit = 1
                 
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
              ClearClipboard()
              SendMessage_( EditText,#EM_SETSEL,0,26)
              SendMessage_( EditText,#WM_COPY,0,0)
              SendMessage_( EditText,#EM_SETSEL,0,0)
             
        Case 2
              SendMessage_( EditText,#WM_PASTE,0,0)
             
      EndSelect
  EndSelect
Until Quit = 1
DestroyWindow_(EditText)
CloseLibrary(0)
EndIf
Egypt my love
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: EditorGadget "#ES_NOSCROLL"?

Post by offsides »

Hi, Rashad.
So, when a gadget doesn't do what you want, you just conjure up one that does, eh? Pretty clever! Something doesn't work on my end, though. Everything looks like I would expect except nothing appears in the window. Entered text doesn't scroll though.

IdeasVacuum,
After contemplating a parser to disassemble a line and attempt to derive values from the internals, I thought about how to work with the rendered text, to look for the text boundaries, and size the EdGadget to fit . Now that you've legitimized the idea I think that's the direction I'll take.

Thanks very much to both of you.
Bill
PB 5.72 (32-bit) on Win 10.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: EditorGadget "#ES_NOSCROLL"?

Post by electrochrisso »

offsides you can use #ES_AUTOVSCROLL switch to apply the scroll with the cursor.

Code: Select all

  EditText = CreateWindowEx_(#WS_EX_STATICEDGE,Class_Name$,"", #WS_VISIBLE | #WS_CHILDWINDOW | #ES_MULTILINE | #ES_AUTOVSCROLL, 10,10,280,130,WindowID(0),300,hInstance,0) 
Not sure why you get nothing in your window I can copy and paste with no problems. Yes I can see what you mean now, set compiler options to create unicode exe.
PureBasic! Purely the best 8)
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: EditorGadget "#ES_NOSCROLL"?

Post by offsides »

electrochrisso,
Yes, unicode must be on. Mine didn't work with unicode off. Nevertheless, it's pretty darn clever.

I have to apologize to everybody. I'm always afraid of being overly verbose so, in the interest of brevity, I did a crummy job of describing my goal. Consequently, everyone who's tried to help has to guess what I was doing. Maybe this is better:

Let's say we have a TextGadget of dimensions 400 x 2000 that we've filled with text. It is well formatted so CR/LFs are placed to prevent wraparound. If you place this in a ScrollAreaGadget whose scroll window is 400 x 400 high but whose scroll area is 400 x 2000, you can scroll up and down in the same manner as an EditorGadget. Additionally, and this is the key part, you can place StringGadgets for user input. The whole thing scrolls up and down nicely; it looks and works well.

Now, say we want to use rich text...
The tool we need is a "RTFTextGadget" for which you can disable the scroll function and, therefore, the scrollbars. You'd use the same setup as above and be done. So, why not just make the EdGadget a bit wider and use the vertical scroll that it provides? Because the StringGadgets won't "stick to the surface" of an EdGadget when they scroll out of view. You pretty much need to do it the way, above.

It is nice when you can autosize the text dimension as you import your text. This is easy with a single font text file but deriving the pixel dimensions of a rich edit file appears to be very difficult. Although you have to know in advance the size of your text, fixing the EdGadget size so it can't scroll is the next option, and Rashad's solution above nails that down. I've tinkered with the "look for the boundaries" approach IdeasVacuum described and have discovered difficulties, mostly, I'm sure because of my ignorance of 2D drawing stuff.

Thanks,
Bill
PB 5.72 (32-bit) on Win 10.
Post Reply