Input Box by Greg Haberek

new topic     » topic index » view thread      » older message » newer message

------=_Part_3869_16648547.1120388047096
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

Hi Greg or anyone who can help,
I have begun using you input box routine although I did have to modify lines 
60 to 75 and have added it below.

Anyway my problem is if I call input box and set style to password all is 
great but if I then call the routine again later and don't want password 
style it won't change. It remains as password, I'm guessing because the 
object does not get re-created?

How can I fix this?


[code]
-- input_box.ew
-- by Greg Haberek <ghaberek at gmail.com>
-- creates an popup message box that requires user input

integer Popup_Window, Popup_LText, Popup_EditText,
Popup_PushButton1, Popup_PushButton2

Popup_Window = 0 -- Main Window
Popup_LText = 0 -- Prompt Text
Popup_EditText = 0 -- Input Text
Popup_PushButton1 = 0 -- 'OK' Button
Popup_PushButton2 = 0 -- 'Cancel' Button

sequence Popup_ReturnText
Popup_ReturnText = "" -- Text returned to user

procedure Popup_Handler( integer pSelf, integer pEvent, sequence pParams )

if pSelf = Popup_Window then
-- play the message_box sound
--Beep( MB_OK )
Beep( MB_ICONQUESTION)

elsif pSelf = Popup_EditText then
if pParams[1] = VK_ENTER then
-- Enter = OK
VOID = invokeHandler( Popup_PushButton1, w32HClick, {} )
elsif pParams[1] = VK_ESCAPE then
-- Escape = Cancel
VOID = invokeHandler( Popup_PushButton1, w32HClick, {} )
end if

elsif pSelf = Popup_PushButton1 then -- OK clicked
-- get the return text
Popup_ReturnText = getText( Popup_EditText )
-- close the window
destroy(Popup_EditText)
closeWindow( Popup_Window )

elsif pSelf = Popup_PushButton2 then -- Cancel clicked
-- set the return text to nothing
Popup_ReturnText = ""
-- close the window
destroy(Popup_EditText)
closeWindow( Popup_Window )

end if

end procedure

global function input_box( sequence pPrompt, sequence pTitle, integer pStyle 
)
-- pPrompt is either a single sequence for the user prompt,
-- or a sequence of two sequences in the form {prompt, def_text}
-- where def_text is the default text for the input box
--
-- pTitle is the title of the input box
--
-- pStyle sets the style of the EditText (ES_NUMERIC, ES_PASSWORD)
-- Example:
-- -- only accept numeric characters
-- text = input_box( "Give me a number", "User Input", ES_NUMERIC )
sequence defText

if Popup_Window = 0 then
-- window not created
-- create the controls
Popup_Window = create( Window, "", 0, Center, Center, 340, 120, 
{WS_SYSMENU,WS_DLGFRAME} )
Popup_LText = create( LText, "", Popup_Window, 10, 10, {w32Edge,-100}, 40, 0 
)
if pStyle=ES_PASSWORD then
Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, 
{w32Edge,-10}, 20, w32or_all({ES_PASSWORD}) ,0)
elsif pStyle = ES_NUMERIC then
Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, 
{w32Edge,-10}, 20, w32or_all({ES_NUMERIC}) ,0)
else
Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, 
{w32Edge,-10}, 20, 0 ,0)
end if
Popup_PushButton1 = create( DefPushButton, "OK", Popup_Window, 
{w32AltEdge,-100}, 10, 90, 20, 0 )
Popup_PushButton2 = create( PushButton, "Cancel", Popup_Window, 
{w32AltEdge,-100}, 30, 90, 20, 0 )
-- set the event handlers
setHandler( Popup_Window, w32HActivate, routine_id("Popup_Handler") )
setHandler( Popup_EditText, w32HKeyDown, routine_id("Popup_Handler") )
setHandler( {Popup_PushButton1, Popup_PushButton2}, w32HClick, 
routine_id("Popup_Handler") )
end if

-- determine if pPrompt is just a prompt or {prompt, def_text}
if length(pPrompt) = 2 and sequence(pPrompt[1]) and sequence(pPrompt[2]) 
then
-- pPrompt = {prompt, def_text}
defText = pPrompt[2]
pPrompt = pPrompt[1]
else
defText = ""
end if

-- set the text for the controls
setText( Popup_Window, pTitle )
setText( Popup_LText, pPrompt )
setText( Popup_EditText, defText )

-- add the style if necessary
if pStyle then
addStyle( Popup_EditText, pStyle )
end if

-- open the window as a dialog
-- set focus to the text box
openDialog( {Popup_Window, Popup_EditText} )

-- remove the style
if pStyle then
removeStyle( Popup_EditText, pStyle )
end if

-- return the text
return Popup_ReturnText
end function

------=_Part_3869_16648547.1120388047096
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

Hi Greg or anyone who can help,<br>
I have begun using you input box routine although I did have to modify lines 60
to 75 and have added it below.<br>
<br>
Anyway my problem is if I call input box and set style to password all
is great but if I then call the routine again later and don't want
password style it won't change. It remains as password, I'm guessing
because the object does not get re-created?<br>
<br>
How can I fix this?<br>
<br>
<br>
[code]<br>
-- input_box.ew<br>
-- by Greg Haberek &lt;<a href="mailto:ghaberek at gmail.com">ghaberek at
gmail.com</a>&gt;<br>
-- creates an popup message box that requires user input<br>
<br>
integer Popup_Window, Popup_LText, Popup_EditText,<br>
&nbsp;&nbsp;&nbsp; Popup_PushButton1, Popup_PushButton2<br>
<br>
&nbsp;&nbsp;&nbsp; Popup_Window = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --
Main Window<br>
&nbsp;&nbsp;&nbsp; Popup_LText =
0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Prompt Text<br>
&nbsp;&nbsp;&nbsp; Popup_EditText = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Input
Text<br>
&nbsp;&nbsp;&nbsp; Popup_PushButton1 = 0&nbsp;&nbsp; -- 'OK' Button<br>
&nbsp;&nbsp;&nbsp; Popup_PushButton2 = 0&nbsp;&nbsp; -- 'Cancel' Button<br>
<br>
sequence Popup_ReturnText<br>
&nbsp;&nbsp;&nbsp; Popup_ReturnText = &quot;&quot;&nbsp;&nbsp; -- Text returned
to user<br>
<br>
procedure Popup_Handler( integer pSelf, integer pEvent, sequence pParams )<br>
<br>
&nbsp;&nbsp;&nbsp; if pSelf = Popup_Window then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- play the message_box sound<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --Beep( MB_OK )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Beep( MB_ICONQUESTION)<br>
<br>
&nbsp;&nbsp;&nbsp; elsif pSelf = Popup_EditText then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if pParams[1] = VK_ENTER then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Enter =
OK<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VOID =
invokeHandler( Popup_PushButton1, w32HClick, {} )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elsif pParams[1] = VK_ESCAPE then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Escape =
Cancel<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VOID =
invokeHandler( Popup_PushButton1, w32HClick, {} )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if<br>
<br>
&nbsp;&nbsp;&nbsp; elsif pSelf = Popup_PushButton1 then -- OK clicked<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- get the return text<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Popup_ReturnText = getText(
Popup_EditText )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- close the window<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; destroy(Popup_EditText)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; closeWindow( Popup_Window )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; elsif pSelf = Popup_PushButton2 then&nbsp;&nbsp;&nbsp; --
Cancel clicked<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- set the return text to nothing<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Popup_ReturnText = &quot;&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- close the window<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; destroy(Popup_EditText)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; closeWindow( Popup_Window )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; end if<br>
<br>
end procedure<br>
<br>
global function input_box( sequence pPrompt, sequence pTitle, integer pStyle
)<br>
--&nbsp;&nbsp;&nbsp; pPrompt is either a single sequence for the user
prompt,<br>
--&nbsp;&nbsp;&nbsp; &nbsp; or a sequence of two sequences in the form {prompt,
def_text}<br>
--&nbsp;&nbsp;&nbsp; &nbsp; where def_text is the default text for the input
box<br>
--<br>
--&nbsp;&nbsp;&nbsp; pTitle is the title of the input box<br>
--<br>
--&nbsp;&nbsp;&nbsp; pStyle sets the style of the EditText (ES_NUMERIC,
ES_PASSWORD)<br>
--&nbsp;&nbsp;&nbsp; &nbsp; Example:<br>
--&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- only accept numeric characters<br>
--&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; text = input_box( &quot;Give me a
number&quot;, &quot;User Input&quot;, ES_NUMERIC )<br>
sequence defText<br>
<br>
&nbsp;&nbsp;&nbsp; if Popup_Window = 0 then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- window not created<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- create the controls<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Popup_Window = create(
Window, &quot;&quot;, 0, Center, Center, 340, 120, {WS_SYSMENU,WS_DLGFRAME}
)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Popup_LText = create( LText,
&quot;&quot;, Popup_Window, 10, 10, {w32Edge,-100}, 40, 0 )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if pStyle=ES_PASSWORD then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
Popup_EditText = createEx( EditText, &quot;&quot;, Popup_Window, 10,
{w32AltEdge,-30}, {w32Edge,-10}, 20,&nbsp; w32or_all({ES_PASSWORD}) ,0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elsif pStyle = ES_NUMERIC then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
Popup_EditText = createEx( EditText, &quot;&quot;, Popup_Window, 10,
{w32AltEdge,-30}, {w32Edge,-10}, 20,&nbsp; w32or_all({ES_NUMERIC}) ,0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
Popup_EditText = createEx( EditText, &quot;&quot;, Popup_Window, 10,
{w32AltEdge,-30}, {w32Edge,-10}, 20, 0 ,0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Popup_PushButton1 = create(
DefPushButton, &quot;OK&quot;, Popup_Window, {w32AltEdge,-100}, 10, 90, 20, 0
)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Popup_PushButton2 = create(
PushButton, &quot;Cancel&quot;, Popup_Window, {w32AltEdge,-100}, 30, 90, 20, 0
)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- set the event handlers<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setHandler( Popup_Window,
w32HActivate, routine_id(&quot;Popup_Handler&quot;) )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setHandler( Popup_EditText,
w32HKeyDown, routine_id(&quot;Popup_Handler&quot;) )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setHandler(
{Popup_PushButton1, Popup_PushButton2}, w32HClick,
routine_id(&quot;Popup_Handler&quot;) )<br>
&nbsp;&nbsp;&nbsp; end if<br>
<br>
&nbsp;&nbsp;&nbsp; -- determine if pPrompt is just a prompt or {prompt,
def_text}<br>
&nbsp;&nbsp;&nbsp; if length(pPrompt) = 2 and sequence(pPrompt[1]) and
sequence(pPrompt[2]) then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- pPrompt = {prompt, def_text}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defText = pPrompt[2]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pPrompt = pPrompt[1]<br>
&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defText = &quot;&quot;<br>
&nbsp;&nbsp;&nbsp; end if<br>
<br>
&nbsp;&nbsp;&nbsp; -- set the text for the controls<br>
&nbsp;&nbsp;&nbsp; setText( Popup_Window, pTitle )<br>
&nbsp;&nbsp;&nbsp; setText( Popup_LText, pPrompt )<br>
&nbsp;&nbsp;&nbsp; setText( Popup_EditText, defText )<br>
<br>
&nbsp;&nbsp;&nbsp; -- add the style if necessary<br>
&nbsp;&nbsp;&nbsp; if pStyle then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addStyle( Popup_EditText, pStyle
)<br>
&nbsp;&nbsp;&nbsp; end if<br>
<br>
&nbsp;&nbsp;&nbsp; -- open the window as a dialog<br>
&nbsp;&nbsp;&nbsp; -- set focus to the text box<br>
&nbsp;&nbsp;&nbsp; openDialog( {Popup_Window, Popup_EditText} )<br>
<br>
&nbsp;&nbsp;&nbsp; -- remove the style<br>
&nbsp;&nbsp;&nbsp; if pStyle then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; removeStyle( Popup_EditText, pStyle
)<br>
&nbsp;&nbsp;&nbsp; end if<br>
<br>
&nbsp;&nbsp;&nbsp; -- return the text<br>
&nbsp;&nbsp;&nbsp; return Popup_ReturnText<br>
end function<br>
<br>


------=_Part_3869_16648547.1120388047096--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu