PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 9 10 [11] 12

Author Topic: Josť, if you're bored...  (Read 4341 times)

Marc Pons

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 130
  • FF3 User
Re: Josť, if you're bored...
« Reply #150 on: September 07, 2018, 05:30:35 AM »

Hi Josť,

I've followed with interest your developments, as you probably remember i was very interested on your CWSTR

I've seen your extention to DWSTRING, and was curious to compare with my DWSTR proposal (intended to be for Win and linux)
in fact no big difference, at the end you followed my way on not having the codepage on the class , you simplified also  CWSTR that way,
the way you use **  when i prefer only * is still a difference, but not big point

I have done some speed comparaison, and the results were comparable
 only  big difference on one point : utf8 string

in fact the difference is because I use the UTFToWChar when you use 2 times MultiByteToWideChar to make the conversion

see that test under that shows the difference
Code: [Select]
#include ONCE "AFX/DWSTRING.bi"


'convert utf8 string to wstring 
PRIVATE FUNCTION pwstr_from_str(BYREF ansiStr AS STRING, BYVAL nCodePage AS LONG = 0)AS WSTRING PTR
   DIM as uinteger i1 = len(ansiStr)
   if i1 = 0 THEN return 0

   DIM ps2 as wstring ptr = allocate((i1 + 2) * 2 )
   if ps2 THEN
      IF nCodePage = CP_UTF8 THEN
         UTFToWChar(1, strptr(ansiStr), ps2, @i1)  ' **** much faster than 2 times MultiByteToWideChar (20 to 25%)
      ELSE
         MultiByteToWideChar(nCodePage, MB_PRECOMPOSED, STRPTR(ansiStr), i1, ps2 , i1 + 2)
      END IF
      RETURN ps2
   END IF
   return 0
END FUNCTION
 
 
 

dim as double z1,z2
dim i as long
Dim as string utf80, utf81

Print "Building utf8 string with euro symbols separated by spaces, with the 3 last 'characters' as euro"
print : print "please wait... (some seconds)" : print
'  just to create a long utf8 string
for i = 1 to 50000000
   utf80 &= !"\&he2\&h82\&hac"       ' euro symbol
   utf80 &= " "
next
utf80 &= !"\&he2\&h82\&hac"       ' euro symbol
utf80 &= !"\&he2\&h82\&hac"       ' euro symbol
utf80 &= !"\&he2\&h82\&hac"       ' euro symbol

'to have 2 separate strings, just in case
utf81 = utf80


' normal way
z1 = clock()
dim as DWSTRING dw0 =  Dwstring(utf80, CP_UTF8)
z2 = clock()
print "normal time    = " , str(z2-z1) & "ms", "len = " & len(dw0)
messagebox(0, right(**dw0,100), "normal", 0)


' optimized way
z1 = clock()
Dim AS WSTRING PTR pw1temp = pwstr_from_str(utf81, CP_UTF8)
dim as DWSTRING dw1 =  pw1temp
if pw1temp then
   deallocate pw1temp
   pw1temp = 0
end if
z2 = clock()
print "optimized time = " , str(z2-z1) & "ms", "len = " & len(dw1)
messagebox(0, right(**dw1,100), "optimized", 0)


messagebox(0, "end","close",0)

I put a very long utf8 string to show better the difference, on short strings is not visible
 I think as Paul is using CWSTR on his nice WinFBE ide , for utf8 files faster would be better. 
« Last Edit: September 07, 2018, 05:34:11 AM by Marc Pons »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #151 on: September 07, 2018, 06:48:53 AM »

I removed the code page because it was no longer needed when Paul added to the editor the option to save the file as UTF-16. If you work directly with UTF-16 then no code page is needed. Both the code page and UTF-8 were workarounds to allow to use unicode with ansi files.

With Windows, the use of UTF-8 is not needed at all. I just have support for it for the sake of completeness.

I use MultiByteToWideChar to make the conversion because a Chinese user reported problems if I did otherwise. Unfortunately, although I asked him for some testing code, he remains hermetic.

DWSTRING was an experiment to see if it was some interest in the Free Basic forum to work with Unicode. As I did suspect, there is none. Maybe just including a file is too easy and you may need to write it in C, provide libraries for both 32 and 64-bit and make its use as difficult as possible.

It also seems that there is no interest to work with COM, other that automating Office with disphelper.

I think that I already have provided all you need to work with unicode. People that don't need it can use ansi strings and the native ansi procedures for work with files if they want.

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #152 on: September 07, 2018, 07:06:41 AM »

>  I think as Paul is using CWSTR on his nice WinFBE ide , for utf8 files faster would be better.

To deal with UTF-8 in the editor, Paul is using his own procedures. They're only needed when loading or saving the file because the Scintilla control works with UTF-8.
« Last Edit: September 07, 2018, 07:08:14 AM by Josť Roca »
Logged

Marc Pons

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 130
  • FF3 User
Re: Josť, if you're bored...
« Reply #153 on: September 07, 2018, 11:04:18 AM »

>I removed the code page because it was no longer needed ...

in fact, as i was saying you previously, codepage on the class is never safe because, you could concatenate elements from different codepage together to create CWSTR/CWTRING
so  after what codepage was the one ?

but who cares?

Have good day Josť, be sure i'm still interrested on your code...

some time, i'll will rework on the COM features because current pdfcreator version totally changed their COM interfaces so if i want to update my exe i need to do it.
my current version was done with powerbasic, the future will be with freebasic
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #154 on: September 10, 2018, 07:55:22 PM »

I've finished the porting of the WinFBX documentation to the mark down format:

https://github.com/JoseRoca/WinFBX/tree/master/docs

I have excluded the documentation about the Windows common controls because I guess that everybody will use Paul's WinFormsX.

Some of the include files have been slightly modified. In particular, there was a bug in the Update method of the CADORecordset class.

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8613
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #155 on: September 10, 2018, 09:49:37 PM »

Wow, that was a lot of work! At least now it will be easier for you to maintain in the future. I plan to use github markdown as well for all of my documentation.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #156 on: September 13, 2018, 03:53:39 AM »

CMaskedit: First version of a Masked Edit Control. A Masked Edit Control is very useful for data entry.

Documentation: https://github.com/JoseRoca/WinFBX/blob/master/docs/Windows%20GUI/CMaskedEdit%20Class.md

BTW the code demosntrates how to create a custom control subclasing another control, in this case the standard Edit control.
« Last Edit: September 13, 2018, 10:23:41 AM by Josť Roca »
Logged

Chris Maher

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 24
  • New FF3 User
Re: Josť, if you're bored...
« Reply #157 on: September 13, 2018, 07:54:19 AM »

Hi Josť

Another excellent well-rounded control with lots of easy flexibility and applications. Thank you..

I think there are a couple of small typos in the Hex Mask sample within the SetValidChars section of the GitHub docs:
https://github.com/JoseRoca/WinFBX/blob/master/docs/Windows%20GUI/CMaskedEdit%20Class.md#setvalidchars
Code: [Select]
m_wndMaskEdit.EnableMask(" AAAA"), _   ' // Mask string
("0x____"), _   ' // Template string
('_')   ' // The default character that replaces the backspace character
m_wndMaskEdit.SetValidChars("1234567890ABCDEFabcdef")   ' // Valid string characters
m_wndMaskEdit.SetWindowText("0x01AF")

Should be:
Code: [Select]
m_wndMaskEdit.EnableMask("  AAAA"), _   ' // Mask string
("0x____"), _   ' // Template string
("_")   ' // The default character that replaces the backspace character
m_wndMaskEdit.SetValidChars("1234567890ABCDEFabcdef")   ' // Valid string characters
m_wndMaskEdit.SetWindowText("0x01AF")
  • There needs to be an extra space before the AAAA of the mask to allow for 0x.
  • The backspace replacement needs double quotes around it "_".
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #158 on: September 13, 2018, 10:35:30 AM »

You're right. I did copy it from the MSDN C++ documentation and modified it manually. This time I have tested it before the copy and paste operation. The good thing about the new documentation format is that I can update it as soon as a mistake is reported.

I have made several modifications. One of them is the use of the SetPos method . It will try to position the cursor in the first input place if you use a mask or at the begining of the edit control if you don't use it, or in the position that you indicate.

Therefore, the new testing code will be:

Code: [Select]
pMskEd.EnableMask("  AAAA"), _   ' // Mask string
("0x____"), _   ' // Template string
("_")   ' // The default character that replaces the backspace character
pMskEd.SetValidChars("1234567890ABCDEFabcdef")   ' // Valid string characters
pMskEd.SetWindowText("0x01AF")
pMskEd.SetPos

A masked edit control has always been in my ToDo list because of its usefulness. I also wanted to experiment on writing a custom control subclassing an existing one. Currently, Cut and Paste are disabled. Looks like implementing it would be very hard.
« Last Edit: September 13, 2018, 09:02:10 PM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #159 on: September 13, 2018, 11:09:41 AM »

By using "_" as a placeholder, we are free to use any other characters in the mask, e.g.

Code: [Select]
pMskEd.EnableMask("       cc       ddddd-dddd", "State: __, Zip: _____-____", " ")
SetWindowText pMskEd.m_hCtl, "State: NY, Zip: 12345-6789"

So we can do many things with just an small number of mask characters, instead of a long list impossible to remember.

By default, the GetWindowText method will return the inputed data without the mask, i.e. "NY123456789". If we call EnableGetMaskedCharsOnly(FALSE), then it will return it with the mask, i.e. "State: NY, Zip: 12345-6789". To clear the input fields, just call the SetWindowText method with an empty string.

Also, because it is a child of CWindow, it is DPI and Unicode aware, and because it is a subclassed Edit control, you can use the context menu available when you right click the mouse in the control. It also honors other features of the Edit control such the ES_UPPERCASE and ES_LOWERCASE styles, right to left reading and IME.


« Last Edit: September 13, 2018, 11:25:22 AM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #160 on: September 13, 2018, 06:28:37 PM »

Well, the Paste operation has been very easy to implement after I have figured how to do it.

In the WM_CHAR message, I detect if the user has pressed Ctrl+V and send a WM_PASTE message:

Code: [Select]
      CASE WM_CHAR
         ' // Handle Ctr+V - Decimal 22, Hex 16 - by sending a WM_PASTE message
         IF wParam = 22 THEN
            SendMessageW hwnd, WM_PASTE, 0, 0
            EXIT FUNCTION
         END IF

Then, when processing the WM_MESSAGE, I retrieve the text from the clipboard and send the characters, one by one, to the OnCharPrintchar method, that processes keystrokes and accepts or rejects them according the mask:

Code: [Select]
      CASE WM_PASTE
         DIM pthis AS CMaskedEdit PTR = CAST(CMaskedEdit PTR, dwRefData)
         IF pthis = NULL THEN EXIT FUNCTION
         DIM cwsText AS CWSTR = AfxGetClipboardText
         IF LEN(cwsText) THEN
            FOR i AS LONG = 1 TO LEN(cwsText)
               pthis->OnCharPrintchar(ASC(MID(**cwsText, i, 1))), 0, 0
            NEXT
         END IF
         EXIT FUNCTION

Works with Russian, Chinese, etc., too.

Now, let's go for Cut and Copy.
« Last Edit: September 13, 2018, 06:32:25 PM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #161 on: September 13, 2018, 06:54:20 PM »

Copy has been even easier.

Code: [Select]
      CASE WM_CHAR
         ' // Handle Ctrl+C - Decimal 3, Hex 3 - by sending a WM_COPY message
         IF wParam = 3 THEN
            SendMessageW hwnd, WM_COPY, 0, 0
            EXIT FUNCTION
         END IF

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #162 on: September 13, 2018, 09:04:57 PM »

I have implemented Cut, Copy, Paste and Undo. The control seems finished unless somebody finds a bug or has suggestions.
« Last Edit: September 14, 2018, 07:53:49 AM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #163 on: September 14, 2018, 07:57:05 AM »

Added an overloaded GetWindowText with a boolean parameter to get the text with or without mask.

Mosified the code to get Undo working also after a Cut or Paste operation.
« Last Edit: September 14, 2018, 09:53:06 AM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3103
    • Jos
Re: Josť, if you're bored...
« Reply #164 on: September 14, 2018, 10:33:03 AM »

If Paul decides to add this control to the Visual Designer, besides the standard settings for an Edit control, he will need to add the following fields in the Properties:

* A field for the Mask
* A field for the Input Mask
* A field for the Valid Characters (optional; the default is to allow all the characters)
* A Boolean for enabling to set masked characters only (default: TRUE)
* A Boolean for enabling to get masked characters only (default: FALSE)
« Last Edit: September 14, 2018, 10:35:25 AM by Josť Roca »
Logged
Pages: 1 ... 9 10 [11] 12