Page 1 of 1

Posted: Thu Oct 24, 2002 3:14 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

Is it possible somehow to prevent the user to paste non numericals into the IPAddressGadget. Or at least be able to detect that there are non numericals in one of the fields and use SetGadgetState() to clear them out.

Posted: Thu Oct 24, 2002 4:37 pm
by BackupUser
Restored from previous forum. Originally posted by Jose.

NO,
I had a look at this, and it does not look like it's a BUG.
IPAddressGadget stops you from entering any letters but if
you right-click and paste some text, then this is allowed.
This one is for FRED to sort out, it's either got to not
accept any text or he must provide way to get back original string.

Only way arouns this, is to take the value from GetGadgetText
and insert it back into IPAddressGadget with MakeIPAddress, then
confirm with user that this is value they wanted.
Good luck
Jose

Registered PureBasic User

Posted: Thu Oct 24, 2002 4:56 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

If the GetGadgetItemText() command and SetGadgetItemText() would be able to operate on each individual field in the IPAddressGadget() this would be a piece of cake...

For now i've made a solution similar to the one you proposed, but it looks ugly and very unprofessional...

Anyone with API programing experience that knows how to intercept paste events to gadgets?

Posted: Thu Oct 24, 2002 5:14 pm
by BackupUser
Restored from previous forum. Originally posted by Jose.

Just thinking about it, why not just use four StringGadget() with
#PB_String_Numeric flag set, this may be cleaner and simpler, in the short term.
Jose

Registered PureBasic User

Posted: Thu Oct 24, 2002 5:21 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by Jose

Just thinking about it, why not just use four StringGadget() with
#PB_String_Numeric flag set, this may be cleaner and simpler, in the short term.
Yes, im considering creating four different stringgadgets with #PB_String_Numerical flag and limited to 3 characters each. You can still paste non numericals into them but you have much better control so it'll work out just fine. Just frustrating to have a special gadget for this purpose and still have to create something similar yourself..

Posted: Thu Oct 24, 2002 8:27 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

That's a limitation in MS gadgets, as I use the standard IP gadget in Windows. I've tried with the regular TCP/IP config dialog in XP and it does the same. I don't know if it's possible to do something...

Fred - AlphaSND

Posted: Thu Oct 24, 2002 9:06 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> I don't know if it's possible to do something...

The only thing you can do is remove any non-numerical characters as
they are typed/pasted in, like so:

Code: Select all

If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  StringGadget(1,20,20,180,20,"",#PB_String_Numeric)
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_EventGadget
      b$="" : a$=GetGadgetText(1)
      For r=1 To Len(a$)
        c$=Mid(a$,r,1)
        If Asc(c$)>47 And Asc(c$)<58
          b$=b$+c$
        EndIf
      Next
      SetGadgetText(1,b$)
      WindowEvent()
    EndIf
  Until ev=#PB_EventCloseWindow
EndIf
PB - Registered PureBasic Coder

Posted: Thu Oct 24, 2002 10:07 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by fred

That's a limitation in MS gadgets, as I use the standard IP gadget in Windows. I've tried with the regular TCP/IP config dialog in XP and it does the same. I don't know if it's possible to do something...
If you could access each field in the IPAddressGadget() as text it would be possible to use something similar to PB suggestion to get rid of unwanted characters. Two new additions is needed to accomplish that i.e:

text$ = GetGadgetItemText(#Gadget, 0, column) ; where column represents the field number(0-3)
SetGadgetItemText(#Gadget, 0, column, text$) ; same as above

with these two additions it would be possible to catch the paste event with 'If EventType() = #PB_EventType_Change' for the gadget in question and remove non numerical characters in the different fields.

Posted: Fri Oct 25, 2002 12:35 am
by BackupUser
Restored from previous forum. Originally posted by Justin.

An IP control is composed by 4 edit controls, you can get the edit handles and work with that.

this code does it, you can't paste non numerical values.

;IP Address avoids to paste non numbers
;Justin 10/02

;array for 4 edit handles
dim edithwnd.l (4)

;determines if a string is numbers only
procedure isstralpha(st$)
for x=1 to len(st$)
a=asc(Mid(st$,x,1))
if a57
procedurereturn 1 ;has non numbers
endif
next
procedurereturn 0 ;numbers only
endprocedure

;callback to get edit handles
editpos=0
procedure EnumChildProc(hwnd,lparam)
shared editpos
edithwnd(editpos)=hwnd
editpos+1
procedurereturn #true
endprocedure

hwnd=openwindow(1,100,100,300,300,#PB_Window_SystemMenu,"IP Address")
creategadgetlist(hwnd)

hip=IPAddressGadget(1,10,10,100,25)

;get 4 edit handles
EnumChildWindows_(hip,@EnumChildProc(),0)

repeat
event=waitwindowevent()

if event=#PB_EventGadget
Select EventGadgetID()
case 1 ;ip

;loop 4 edits and clear strings
for en=0 to 3
a$=space(4) ;3 digits
getwindowtext_(edithwnd(en),@a$,4)
if isstralpha(a$)=1 ;has letters
setwindowtext_(edithwnd(en),"")
endif
next

endselect
endif
until event=#PB_EventCloseWindow

Posted: Fri Oct 25, 2002 1:30 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

Thank you all for the time you took, i'll try you example in a moment Justin -i'm sure it will work out satisfactory, thank you!

Posted: Fri Oct 25, 2002 6:39 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

May be changing the style to #NUMERIC for the 4 stringdagets at initializtion will do the trick ?

Fred - AlphaSND

Posted: Fri Oct 25, 2002 7:26 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by fred

May be changing the style to #NUMERIC for the 4 stringdagets at initializtion will do the trick ?
How do you mean, for the 4 childs in the ip gadget or what? My experience is that setting the style ES_NUMBER doesn't prevent pasting non-numericals into a stringgadget, but i'm not really a experienced api programmer so i'm not totaly sure about stuff when questions concerning the api comes up.

I might be completely off with my reasoning above, please enlighten me if this is the case;)