From: Glenn W M. <gwm...@gm...> - 2007-04-24 18:26:11
|
Glenn, I wouldn't expect it to prevent it from being checked. Do you expect this behaviour from the Windows control itself or from Win32::GUI? Certain actions for some controls have a "pre-change" notification (e.g. the TCN_SELCHANGING notification sent when a tab is *about* to change), which can be used to prevent the change, but I don't see anything like that on MSDN for a checkbox. Or do you expect this from Win32::GUI? I know a return value of 0 prevents the "default action" from taking place, but I see that as a "post-change" action, if that makes sense. (I'm not sure where that action is defined). Or am I missing your point entirely? Glenn2 > -----Original Message----- > From: per...@li... [mailto:perl- > win...@li...] On Behalf Of Glenn > Linderman > Sent: 24 April 2007 13:39 > To: GUI > Subject: [perl-win32-gui-users] disabling the check on a checkbox??? > > use strict; > use warnings; > > use Win32::GUI(); > > my $mw; > > $mw = new Win32::GUI::Window( > -name => "mw", > -title => "Checkbox default action", > -pos => [100, 100], > -size => [200, 200], > -dialogui => 1, > ); > > $mw->AddCheckbox( > -name => "cb", > -text => 'click me', > -pos => [10, 20], > -tabstop => 1, > -onClick => sub { return 0; }, > ); > > > $mw->Show(); > Win32::GUI::Dialog(); > > > Why does the above program allow the checkbox to be checked and > unchecked? Why doesn't the -onClick handler, which returns 0, prevent > the box from being checked? > > -- > Glenn -- http://nevcal.com/ > =========================== > A protocol is complete when there is nothing left to remove. > -- Stuart Cheshire, Apple Computer, regarding Zero Configuration > Networking > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > http://perl-win32-gui.sourceforge.net/ |
From: Robert M. <rob...@us...> - 2007-04-24 19:23:40
|
On 24/04/07, Glenn Linderman <pe...@ne...> wrote: > $mw->AddCheckbox( > -name => "cb", > -text => 'click me', > -pos => [10, 20], > -tabstop => 1, > -onClick => sub { return 0; }, > ); > > Why does the above program allow the checkbox to be checked and > unchecked? Why doesn't the -onClick handler, which returns 0, prevent > the box from being checked? Because the _Click() events are generated by the Button control AFTER it sees a mouse down and up combination. At this point the control has seen a "click" and sends a BTN_CLICK (IIRC) notification to it's parent - it's already done all the other processing. You could achieve what you are trying here by catching the _MouseDown event, and preventing that being delivered to the Button control. You could also achieve what (I think) you are looking for by creating the control with the BS_CHECKBOX style, rather than the default BS_AUTOCHECKBOX. Then the control does not re-drw itself, and you have to tell it how it should look. Regards, Rob. |
From: Robert M. <rob...@us...> - 2007-04-25 01:06:09
|
Glenn Linderman wrote: >>> -remstyle => BS_AUTOCHECKBOX, >>> -addstyle => BS_CHECKBOX, > > Is there a better way to do this operation? There are no 'options' to do this, if that's what you mean. > Not only does it require > BS_ constants, the order matters... the code shown works in the test > program, but not in my "real" program which runs the parameters through > a hash, which reorders the parameters :( Causing the checkboxes to > actually come out as buttons! The button's 'type' is the bottom 4 bits of the style (see BS_TYPEMASK). A Win32::GUI::Checkbox is type BS_AUTOCHECKBOX (=3) and you want BS_CHECKBOX (=2). (3 & ~3) | 2 = 2 (BS_CHECKBOX) but (3 | 2) & ~3 = 0 (0 = BS_PUSHBUTTON) -remstyle => 1 should do what you want: 3 & ~1 = 2 but it'll need a good comment to make it maintainable :-( As an alternative you might be able to use a button, and add BS_CHECKBOX, and then re-bless the resulting object into the checkbox class. Something like this (untested): my $cb = $mw->AddButton( -addstyle => BS_CHECKBOX, ... ); bless $cb, "Win32::GUI::Checkbox"; The bless may be unnecessary, depending on which class methods you need to be able to call. Regards, Rob. |
From: Roode, E. <er...@ba...> - 2007-04-24 18:35:18
|
For what it's worth, I have always been unclear on what the Win32::GUI doco means by "the event is not passed to the default event processor". Any clarification, anywhere, would be useful.=20 Eric -----Original Message----- From: per...@li... [mailto:per...@li...] On Behalf Of Glenn W Munroe Sent: Tuesday, April 24, 2007 2:27 PM To: 'Glenn Linderman'; 'GUI' Subject: Re: [perl-win32-gui-users] disabling the check on a checkbox??? Glenn, I wouldn't expect it to prevent it from being checked. Do you expect this behaviour from the Windows control itself or from Win32::GUI? Certain actions for some controls have a "pre-change" notification (e.g. the TCN_SELCHANGING notification sent when a tab is *about* to change), which can be used to prevent the change, but I don't see anything like that on MSDN for a checkbox. Or do you expect this from Win32::GUI? I know a return value of 0 prevents the "default action" from taking place, but I see that as a "post-change" action, if that makes sense. (I'm not sure where that action is defined).=20 Or am I missing your point entirely? Glenn2 > -----Original Message----- > From: per...@li... [mailto:perl- > win...@li...] On Behalf Of Glenn=20 > Linderman > Sent: 24 April 2007 13:39 > To: GUI > Subject: [perl-win32-gui-users] disabling the check on a checkbox??? >=20 > use strict; > use warnings; >=20 > use Win32::GUI(); >=20 > my $mw; >=20 > $mw =3D new Win32::GUI::Window( > -name =3D> "mw", > -title =3D> "Checkbox default action", > -pos =3D> [100, 100], > -size =3D> [200, 200], > -dialogui =3D> 1, > ); >=20 > $mw->AddCheckbox( > -name =3D> "cb", > -text =3D> 'click me', > -pos =3D> [10, 20], > -tabstop =3D> 1, > -onClick =3D> sub { return 0; }, > ); >=20 >=20 > $mw->Show(); > Win32::GUI::Dialog(); >=20 >=20 > Why does the above program allow the checkbox to be checked and=20 > unchecked? Why doesn't the -onClick handler, which returns 0, prevent > the box from being checked? >=20 > -- > Glenn -- http://nevcal.com/ > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D > A protocol is complete when there is nothing left to remove. > -- Stuart Cheshire, Apple Computer, regarding Zero Configuration=20 > Networking >=20 >=20 > ---------------------------------------------------------------------- > --- This SF.net email is sponsored by DB2 Express Download DB2 Express > C - the FREE version of DB2 express and take control of your XML. No=20 > limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > http://perl-win32-gui.sourceforge.net/ ------------------------------------------------------------------------ - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Perl-Win32-GUI-Users mailing list Per...@li... https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users http://perl-win32-gui.sourceforge.net/ |
From: Robert M. <rob...@us...> - 2007-04-24 19:40:31
|
On 24/04/07, Roode, Eric <er...@ba...> wrote: > For what it's worth, I have always been unclear on what the Win32::GUI > doco means by "the event is not passed to the default event processor". > Any clarification, anywhere, would be useful. OK. The default handling of an event depends on the control. For example, consider a left mouse click (_MouseDown). For a Window, the default processing does nothing, so being able to stop it is, o be honest, not very useful. But, for a button, the default processing of a left mouse down (performed by the control itself), is to re-draw the button in the depressed state, and capture the mouse, waiting for a mouse up event to occur. In this case intercepting the _MouseDown event, before the button sees it and preventing it being passed to it's 'default handler' it would have the effect of stopping the user clicking the button. In general it's always advisable to allow messages to be passed on to their default handler's, and only prevent that if there are known side-effects that you want to stop. Regards, Rob. |
From: Robert M. <rob...@us...> - 2007-04-24 23:35:44
|
Glenn Linderman wrote: > > At this point the control > > has seen a "click" and sends a BTN_CLICK (IIRC) notification to it's > > parent - it's already done all the other processing. You could > > achieve what you are trying here by catching the _MouseDown event, and > > preventing that being delivered to the Button control. > > So I changed -onClick to > > -onMouseDown => sub { return 0; }, > > and it helps... but not quite enough... slow, individual clicks no > longer check the box... but a pair of rapid clicks will! > > So I added > > -onMouseUp => sub { return 0; }, You could instead catch and ignore the _MouseDblClick events. When clicking on a window/control the event sequence is: (1) MouseDown (2) MouseUp (3) MouseDblClick (if it happens soon enough after (1) and the window/control's Windows Class has the CS_DBLCLCKS style) (4) MouseUp > and it helps to the extent that the a pair of rapid clicks makes the > white part of the check box go grey when the mouse is over it... and > also has the extremely surprising side effect that the program no longer > terminates when clicking the close box... even though the handlers are > only on the Checkbox. I have to ^C from the console window to terminate > it! So this is extremely undesirable, and also not understood. I can explain it now that I've seen it, but wouldn't have predicted it - it shows the dangers of not passing things to their default handlers :-( The effect you see is not only that the close button doesn't work, but that you can't click anywhere in the window, including to move and resize the window - you can fix this by clicking on another window or the desktop. This happens because on a double-click (and click) the buttom does a SetCapture(), so that it can see the eventual mouse up message even if you then drag the mouse off the button - so that it can redraw it in it's un-pushed state (try with a real button rather than a check box, it's more obvious. If it didn't do this, then it wouldn't know if you let let the button up outside the button. In this case you're not letting the button see mouse up messages, so it never does a ReleaseCapture() - fortunately you can get the system to do it for you by clicking in another window - the system allows this to prevent an application taking over the mouse forever (you'd need a system-wide hook to achieve this :-). > > You could also > > achieve what (I think) you are looking for by creating the control > > with the BS_CHECKBOX style, rather than the default BS_AUTOCHECKBOX. > > Then the control does not re-drw itself, and you have to tell it how > > it should look. > > I'm not sure what you mean here... is it that you have to call > Checked(0) or Checked(1), or that you have to supply a user-draw routine > (I hope not!). Some experimentation, below, proves you mean the > former! This technique looks very workable. Yes, that was what I meant. Rob. |