March 28, 2024, 02:02:26 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


IWMask Development Updates

Started by LarryMc, June 13, 2013, 04:28:00 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

LarryMc

Progress updates will be posted in this thread.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

The command to create a masked edit control (MEC) is
IWM_Create(WINDOW win, UINT id, INT l, INT t, INT w, INT h, uint flags, string mask, string placeholder, opt string text="")
where:
win - the IWBasic parent window
id   - the id for the control
l     - location of left edge of control
t    - the top edge of the control
w   - the width of the control
h   - the height of the control
flags -used for configuration and style
mask - the input mask to be used
placeholder - the character to be used as a placeholder prompt
text - an optional initial input string to apply to the mask.

The following 4 lines are used to create the controls in the attached screen shot:
IWM_Create(main, 501, 20,20,200,30,0, "SSN: 000-00-0000", "_", "123456789")
IWM_Create(main, 502, 20,60,200,30,0, "D\ate: 00/00/0000", "_")
IWM_Create(main, 503, 20,100,200,30,0, "IP: 990.990.990.990", "_", "")
IWM_Create(main, 504, 20,140,200,30,0, "Phone: (000)000-0000", "_", "")


The mask rules are:
"0" (zero)  0-9  (required entry)
"9"            0-9, space, (optional entry)
"L"        .  A-Z, a-z (required entry)
"?"           A-Z, a-z, space, (optional entry)
"A"          A-Z, a-z, 0-9 (required entry)
"a"           A-Z, a-z, 0-9 (optional entry).
"&"         Any character or space,(asc codes from 32 to 255) (required entry)
"C"         Any character or space,(asc codes from 32 to 255) (optional entry)
" "          A blank space.
">"'        If input is a-z it will be converted to A-Z
"<"'        If input= A-Z it will be converted to a-z
"\"'         The "don't-format character' character ("\"). Used when one of the previous formatting characters is to be used in a static text portion of the mask.
            The "D\ate" in the 2nd example shows shows this useage.

Other commands that have been finished are:

IWM_GetFullText(WINDOW win, UINT id),string
Basically the same as GETCONTROLTEXT.  Returns the entire contents of the MEC window.
In the 1st example  "SSN: 123-45-6789" would be returned.

IWM_GetMinText(WINDOW win, UINT id),stringReturns the string that begins with the 1st variable character and ends with the last variable character.
Includes all characters, variable or not, between the two.
In the 1st example  "123-45-6789" would be returned.

IWM_GetRawText(WINDOW win, UINT id),string
Returns a string that contains only the variable characters.
In the 1st example  "123456789" would be returned.

IWM_SetText(WINDOW win, UINT id, string text)Causes the passed text to be placed in the MCE window.  Any passed characters that do not meet the defined mask formatting are discarded.
In the 1st example  if "aX123y45;678:9" is passed the result would be "SSN: 123-45-6789" .


It is only fair to say that portions of the underlying structure of my masked edit relies heavily on techniques developed over 8 years ago by another author on another forum for another programming language. It was code that was being freely shared to help others and not copyrighted.  I did not come up with the basic concepts for this from scratch.
 
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

The IWM_Create function (described above) has been modified to include a flags parameter used for configuration

The command to create a formatted,  currency  edit control (FCEC) is
IWMF_Create(WINDOW win, UINT id, INT l, INT t, INT w, INT h, int flags, string symbol, opt string text="")
where:
win - the IWBasic parent window
id   - the id for the control
l     - location of left edge of control
t    - the top edge of the control
w   - the width of the control
h   - the height of the control
flags -used for configuration and style
symbol - the character used to denote the type of currency,$ for US dollars, etc
text - an optional initial input numerical string to apply to the formatting.

The following line is used to create the control in the attached screen shot:
WMF_Create(main, 505, 20,180,200,30,0, "$", "-1234567890123.56")

Additional commands that have been finished are:

IWM_SetReadOnly(WINDOW win, UINT id,int ro)
Used to set the MEC or FCEC read-only. Default state is FALSE

IWM_SetRightAlign(WINDOW win, UINT id,int ra)
Used to set the MEC or FCEC text alignment.
Default is FALSE for MECs and TRUE for FCECs.

The following functions apply only to FCECs:

IWMF_SetNoShowSeparator(WINDOW win, UINT id,int sep)
When FALSE a thousands separator (,) is shown in the formatted text.
Default is FALSE

IWMF_SetNoAutoDecimal(WINDOW win, UINT id,int ad)
When  FALSE the formatted output is forced to have a decimal and the proper number of decimal digits even when
the raw input is a string representing a whole number.
Default is FALSE

IWMF_SetNegMinus(WINDOW win, UINT id,int ni)
When FALSE a negative 100 is represented as (100). TRUE is -100
Default is FALSE

IWMF_SetRoundDecimal(WINDOW win, UINT id,int rd)
When TRUE the raw input will rounded to the configured number of decimal places.
When FALSE the raw input will to truncated to the configured number of decimal places.

IWMF_SetDecimalPlaces(WINDOW win, UINT id,int dp)
Used to set the desired number of decimal places.

The following flags are used with the IWM_Create and IWMF_Create functions to set initial configurations to
something different than the defaults.

@IWM_READONLY
Sets the MEC or FCEC to read-only
Same as IWM_SetReadOnly( win,  id, TRUE)

@IWM_ALIGNRIGHT
Sets the MEC or FCEC text alignment to the right.
Same as IWM_SetRightAlign( win, ,TRUE)

@IWMF_NOSHOWSEPERATOR
Controls the use of the thousands separator
Same as IWMF_SetNoShowSeparator(win,  id, TRUE)
      
@IWMF_NOAUTODECIMAL
Controls the automatic decimal place feature.
Same as IWMF_SetNoAutoDecimal(win, id, TRUE)
         
@WMF_USEMINUS    
Controls how negativ numbers are displayed
Same as IWMF_SetNegMinus( win, id, TRUE)
   
@IWMF_ROUNDDEC
Controls whether extra decimal places are rounded or truncated.
Same as IWMF_SetRoundDecimal(win, id, TRUE)

In the attached zip are:
a test program
a lib file
a inc file.
Copy the lib file to your IWBDev\libs folder

Feedback is welcome.

My TODO list contains:
Fix copy, cut, and paste functions
Correct the action of some of the constants above(some don't do anything right now )
Another flag to control whether the $ is shown or not

Don't use this lib for anything important yet as it is a beta and things are subject to change between now
and official release.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Larry,

Zip file is missing the IWB file - you zipped up a project file, instead!

Brian

Brian

June 16, 2013, 06:36:20 AM #4 Last Edit: June 16, 2013, 06:41:44 AM by Brian Pugh
Larry,

I created a simple mask file:    IWM_Create(win,1,50,50,200,22,0,"TB012345","TB","0123456789")

If you position the cursor at the end of the input, and back delete, strange things happen. It
doesn't delete any characters, and then inserts a spurious character at position 3

Just so you are aware, I realise it is a work in progress . . .

Edit: Even worse, if you set the mask to "TB012345" it displays OK. If you set it to
"AB012345" it displays as "0B112345" !

Brian

LarryMc

Quote from: Brian Pugh on June 16, 2013, 04:56:08 AM
Larry,

Zip file is missing the IWB file - you zipped up a project file, instead!

Brian
Corrected and replaced attachment above.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bill-Bo

June 16, 2013, 10:21:40 AM #6 Last Edit: June 16, 2013, 10:24:00 AM by Bill-Bo
LarryMc,

What have I done to not be able to download your files above?

I'm denied access??????

Bill

P.S. You must have been updating just now. After I posted I
noticed the updates and I was able to download them.

LarryMc

Quote from: Bill-Bo on June 16, 2013, 10:21:40 AM
LarryMc,

What have I done to not be able to download your files above?

I'm denied access??????

Bill
I don't know.  I don't have any problem downloading it.
Try closing your browser and reopening it.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Larry,

Downloaded OK now, thanks

What's the difference between IWMF_Create and IWM_Create ?

Also, I changed the "$" in one example to "£" (pound) and it still kept the dollar sign

Brian

LarryMc

Quote from: Brian Pugh on June 16, 2013, 06:36:20 AM
Larry,

I created a simple mask file:    IWM_Create(win,1,50,50,200,22,0,"TB012345","TB","0123456789")

If you position the cursor at the end of the input, and back delete, strange things happen. It
doesn't delete any characters, and then inserts a spurious character at position 3

Just so you are aware, I realise it is a work in progress . . .

Edit: Even worse, if you set the mask to "TB012345" it displays OK. If you set it to
"AB012345" it displays as "0B112345" !

Brian
The problems you are having are because you are not following the rules.
Take IWM_Create(win,1,50,50,200,22,0,"TB012345","TB","0123456789")
You have set the mask to TB012345
The only "variable" character you have in your mask is the "0", the rest are constants.
So, when you backspace it is stepping over your mask characters(not deleting them) until you get to the variable slot and it deletes the character there. You say "inserts a spurious character at position 3". What it is doing is deleting the variable character and replacing it with the default placeholder "_" since you passed it an illegal placeholder, "TB". It has to be a single character.
You can correct the problems with this line: IWM_Create(win,1,50,50,200,22,0,"TB000000","_","0123456789")

You say, even worse
QuoteIf you set it to
"AB012345" it displays as "0B112345" !
The only difference between this and the previous is that you changed the T to A.
"A" is a formatting character for allowing an input of A-Z,a-z,0-9
And the "0" is still a formatting character for allowing 0-9
When applying your data to the input mask it takes the first character of your data and puts it in the first formatted slot it finds.  That's why the "A" changed to "0"
It then took the 2nd character of your data and put it into the 2nd formatted slot it found.  That's why the "0" became a "1".
If you want it to replace the "A" then the proper line would be  IWM_Create(win,1,50,50,200,22,0,"AB000000","_","0123456789")If you want to keep the "A" as a non formatted slot then the proper line would be  IWM_Create(win,1,50,50,200,22,0,"\AB000000","_","0123456789")

QuoteWhat's the difference between IWMF_Create and IWM_Create ?

Also, I changed the "$" in one example to "£" (pound) and it still kept the dollar sign

IWM_Create  creates an input mask edit control
IWMF_Create creates a formatted currency edit control - thus the F

The changing of the $ is on my TODO list but I failed to list it above.

A careful rereading of my 1st 2 post might eliminate some of your confusion.
Thanks for the feedback.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Thanks a lot. I must remember to RTFM !

Brian

LarryMc

Library updated
Fixed the CTRL-X and CTRL-C functions.  Still have issues with CTRL-V(pasting)

Renamed the following constants:
new - @IWMF_NOSHOWSEPERATOR
old -  @IWMF_SHOWSEPERATOR   

new - @IWMF_NOAUTODECIMAL
old -  @IWMF_AUTODECIMAL
      
new - @WMF_USEMINUS
old -  @IWMF_PFORNEG
Names and descriptions in previous post above were revised   

Added the following new constants:

@IWM_ALIGNLEFT   
Used to initially set the text alignment to the left.
This is for use with MECs only.
Same as IWMF_SetAlignLeft(win, id, TRUE)

@IWMF_NOSYMBOL
Used to initially turn off the currency symbol for FCECs
Only applies to FCECs.
Same as IWMF_SetNoSymbol(win, id, TRUE)   

Added the following functions:
IWMF_SetDecimalPlaces(WINDOW win, UINT id, int dp)Used to change the number of decimal places in FCECs
Default is 2.

IWMF_SetNoSymbol(WINDOW win, UINT id, int sym)Used to turn off the currency symbol in FCECs
Default is FALSE

IWMF_SetSymbol(WINDOW win, UINT id, string symbol)
Use set the currency symbol to display in FCECs.

The download posted above has been updated.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Larry,

In your new version, in the formatted example, I don't understand how having parentheses
round the text is helpful in any way. And when you click in the control, and type in some
text, eg, "123.45" you get nothing like that back

Am I missing something here? BTW, the "£" signs works now!

Brian

LarryMc

Quote from: Brian Pugh on June 18, 2013, 12:47:08 PM
...I don't understand how having parentheses round the text is helpful in any way.
It's common practice in business financial statements that companies issue and also in stock market statements for stocks, mutual funds etc..

Quote from: Brian Pugh on June 18, 2013, 12:47:08 PM
And when you click in the control, and type in some text, eg, "123.45" you get nothing like that back
Yeah, I know. When I fixed the "pasting" problem I broke that.
I've already got it fixed and it will be in the next update; probably tonight or tomorrow.
And I need to add an explanation of how pasting works.

Right know I'm adding some callback function features.

Thanks for the feedback.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

I've completed the 1st of 4 "callback" functions.
This one allows the User to write a subroutine to be called anytime the data changes.
It uses the same technique that is used in calling subroutines indirectly.
When a change is made the callback subroutine is passed the parents hwnd, the id of the MEC/FCEC, and the current raw text.

The intent is to allow the User to do custom testing of the data such as limiting max/min values
or taking the data applying some factor and displaying the result in another read only mask
ie, say you are a distributor of a product.
you have 3 MECs or FCECs
you enter your cost for an item,  your wholesale markup %, and your retail markup %

And you have 2 read-only MECs or FCECs containing the selling price at wholesale and retail.
Anytime you change one of the 1st 3, their callback routines are called which in turn recalculates the selling prices and updates those read-only controls.

ANYWAY, while testing this I discovered that on the FECEs I still have 2 problems.
1st- I can't add a number in front of the first displayed digit.
2nd - I can enter as many "-" at the left of the numbers as I want to. When the control loses focus it gets ride of all but the first one but it shouldn't be allowed to begin with.

So, no update tomorrow and it may even take me a few days
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Added the ability to assign up to 6 different user subroutines to be called when the associated event occurs within a specific control.
For a given type of event the User can designate one subroutine to handle all MECs and FCECs or each control can have its own dedicqated callback subroutine.
The callbacks are assigned with the following functions; each with the skeleton for the callback subroutine.
The User can select any name for the subroutines but the passed parameters have to be as shown:

IWM_SetChangeCallback(WINDOW win, UINT id, UINT callback)
Called any time the contents changes
global sub MySub(int hwnd, int id, string txt)

return
endsub


IWM_SetReturnCallback(WINDOW win, UINT id, UINT callback)
Called when the ENTER key is pressed
global sub MySub(int hwnd, int id, string txt)

return
endsub


IWM_SetLostFocusCallback(WINDOW win, UINT id, UINT callback)
Called when the control loses focus
global sub MySub(int hwnd, int id, string txt)

return
endsub


IWM_SetBadInputCallback(WINDOW win, UINT id, UINT callback)
Called when input, via keyboard or pasting, contains one or more illegal characters
global sub MySub(int hwnd, int id, string txt)

return
endsub


IWM_SetTabCallback(WINDOW win, UINT id, uint callback)
Called when the TAB key is pressed
global sub MySub(int hwnd, int id)

return
endsub


IWM_SetShiftTabCallback(WINDOW win, UINT id, uint callback)
Called when the SHIFT-TAB key is pressed
global sub MySub(int hwnd, int id)

return
endsub


The download posted above has been updated

Examples of all are shown in the demo.

While preparing the demo I discovered that the 'lost focus' callback is being called at times when it really shouldn't be called.
So, I've got to work on that.

As always, any feedback is appreciated.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Discovered why I was getting the extra 'lost focus' triggers.

When one of the controls are changed I had the change callback with a messagebox in it.
That messagebox causes focus to be shifted to it when it opens.  It is given focus so you can click the close button or hit ENTER to close it.
For the messagebox to get focus whoever has focus has to give it up; thus the lost focus call back trigger.

That means that if you need to use the 'lost focus' callback you might want to not put any messageboxes in your other callbacks or anything else that might capture focus.

Right now I don't see that there is any way around it because the focus messages are controlled by the OS.
Besides, if there was some way for a control to capture focus the way mouse input can be captured then you'd never be able to respond to a messagebox..

So, it's like to old country doctor said,"If it hurts when you do that then don't do that."

So, it appears that aside from building a little help file that describes everything, especially how the cutting and pasting works and the, for lack of a better word, "quirks" concerning insert and overtype I'm through.
That is if no one finds any bugs.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Got to thinking (yes, I know; that's dangerous)

Some may wonder why I added the callback function capability to the mask control when it would have been much easier to just send messages to the parent of the MECs and FCECs like the other controls do.
An then the User could respond how ever they wanted in the parent window.

Yes, it would have been much, much easier and the IWMask lib may (most likely) will end up that way so that they will work pretty much the way other controls work with @CONTROLID, @IDCONTROL, and @NOTIFYCODE..

But remember that I started on this "Mask" quest in support of my grid.
The grid control is going to be the parent of the MECs and FCECs and its message handler can't be seen by the user.

One of the secrets of the grid control is that it only has one edit control that handles all the cells of the grid that the User puts text in.  That  way I don't have to have all the unused overhead tied up for every cell.
All I need to account for is the configuration data for each configured cell and when the cell gets the focus I move the edit control to that cell's location and load the edit control with that cell's info.

So, in order to do things like add a column or row of cells or other math  operations I needed a way to be able to program that.  This scheme for the MECs and FCECs can be accomplished with these callback routines.
And as far as the  grid is concerned, all I have to store extra is the address of the callback subroutines.

So, there was a motive to my madness ;D ;D ;D
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

After playing around with the "optional" character versions of the mask I decided they are going to cause more problems than they are worth in the proper displaying of the data.
Therefore the following formatting characters will be removed:
"9"            0-9, space, (optional entry)
"?"           A-Z, a-z, space, (optional entry)
"a"           A-Z, a-z, 0-9 (optional entry).
"C"         Any character or space,(asc codes from 32 to 255) (optional entry)

Of course, as with anything in development, even that may be subject to change.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Well, I'm at a point with IWGrid I need to work on the mask edit type cells.
So that brings me back to the IWMask library and adapting it to work with the grid setup.

I was in the process of refreshing my memory(since it had been so long since I worked on the mask)
and I discovered a major problem
I was looking at an IP mask
worst case for an IP is 255.255.255.255
on the other end it can be 1.1.1.1
my problem is that if I try to load raw data when the mask edit is created of by setting it after the fact it
will only accept it if it is 12 numbers or more(if it is more then the extra is just ignored.)
If it is less then 12 numbers it won't accept it and the entry is blank

also if I imbed a "." it sees it as an illegal character and aborts and the entry is blank.

I may have to make an IP a special case for the grid version.
I'll be working on this for a while.

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Although I haven't worked on this project specifically, in quite some time, don't give up on me.

As soon as I get some of my medical issues lined out I will finish the doc for the IWGrid Control.  Then, because of all the work I did on the IWGrid Control I will be able to finish the IWMask Control.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library