AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AltSubmit and Label for listview

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Wed Apr 18, 2007 3:59 pm    Post subject: AltSubmit and Label for listview Reply with quote

The purpose of this small code is to toggle the check status of a row in one of two listviews with the MButton.

When AltSubmit in combination with gLabels for the Listviews is set it doesn't work. Without the AltSubmit or the gLabels, it is working correctly.

Have I done something wrong, or is this a bug?
Thanks for your help.
Code:
AltSubmit = AltSubmit             ;<=  comment this line to see it work correctly
Gui, 1:Add, ListView,vLV1 gLV %AltSubmit% -Multi Checked,Text
Loop, 4
    LV_Add("", A_Index)
Gui, 1:Add, ListView,vLV2 gLV %AltSubmit% x+20 -Multi Checked,Text
Loop, 4
    LV_Add("", A_Index)
Gui, 1:Show,, Gui1
Return

MButton::     ;click MButton to toggle check mark
  Click                                  ;select row
  GuiControlGet, ListViewName, FocusV    ;get focused listview
  Gui, 1:ListView, %ListViewName%        ;select the listview
  ItemInListView := LV_GetNext(0, "F")   ;get selected item
 
  ;find out if item is checked: see AHK help file; 4140 is LVM_GETITEMSTATE.  0xF000 is LVIS_STATEIMAGEMASK.
  Gui, 1:+LastFound
  SendMessage, 4140, ItemInListView - 1, 0xF000, % ListViewName = "LV1" ? "SysListView321" : "SysListView322"
  LV_Modify(ItemInListView, "Check" . !((ErrorLevel >> 12) - 1))   ;toggle check status

  ToolTip, %ListViewName% %ItemInListView%     ;for hint
Return

LV:
Return

GuiClose:
ExitApp

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Wed Apr 18, 2007 8:54 pm    Post subject: Reply with quote

I really think that AltSubmit should be specified when you get the value, not when you create the control. I usualy needed both ways in my code.

This has nothing to do with bug, but I just remind that maybe in 2.0 this can be changed to real time, and compatibility will not be broken if we use ALtSubmit on controls creation to specify default method.
_________________
Back to top
View user's profile Send private message MSN Messenger
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Wed Apr 18, 2007 10:26 pm    Post subject: Reply with quote

majkinetor wrote:
I really think that AltSubmit should be specified when you get the value, not when you create the control.
Listviews and treeviews do not react on Gui,Submit (getting the value). They send notifications if user interacts with the control. Thus it makes sense to specify AltSubmit at their creation.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Fri Apr 20, 2007 2:40 am    Post subject: Reply with quote

I get weird behavior both with and without AltSubmit (though AltSubmit does change the behavior slightly). Sending simulated mouse clicks from a script that receives notification of those same mouse clicks (via its gLabel) is likely to be the problem, though I don't know exactly why. Also, sending mouse clicks while another mouse button is being down (MButton in this case) has historically caused problems due to quirks in the OS and/or the common controls.

As possible workarounds, when added to the beginning of the MButton subroutine some of the following seem to alter the behavior:
Code:
KeyWait MButton
SetMouseDelay -1
Critical
However, even if they work on your system, they might not be reliable on others. So I'd recommend finding an alternative to the Click command such as ControlClick or the more advanced LVM_HITTEST Message.

Finally, I'm not sure this is worth investigating further because even if the cause is found, the fix is likely to be difficult and might have a risk of breaking other things. Also, the combination of circumstances here seems very rare.

In any case, it's good to have it mentioned here in case anyone else ever encounters something similar. Thanks.
Back to top
View user's profile Send private message Send e-mail
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Fri Apr 20, 2007 10:37 am    Post subject: Reply with quote

Thanks Chris,

I found a solution:
Code:
MButton::     ;click MButton to toggle check mark
  MouseGetPos, , , , ControlClassNN , 1  ;get control ClassNN that is clicked on
  GuiControl, Focus, %ControlClassNN%    ;focus control
  Click                                  ;select/focus row
  GuiControlGet, ListViewName, FocusV    ;get focused listview as control name
  Gui, 1:ListView, %ListViewName%        ;select the listview
  ItemInListView := LV_GetNext(0, "F")   ;get selected/focused item
  ;toggle check state
  LV_Modify(ItemInListView, (ItemInListView = LV_GetNext(ItemInListView - 1, "C") ? "-" : "") "Check")

  ToolTip, %ListViewName% %ItemInListView% %ControlClassNN%   ;for hint
Return
The only strange behavior left is that the checkmark and tooltip do not appear after I have moved the mouse. This is caused by the click command.
When you comment all other commands out, see below, you can see that the tooltip doesn't appear immediatly. Only after the mouse gets moved. I guess that the listview waits for something.
Code:
MButton::
  Click                         
  ToolTip, test
Return
Is there a way around that?
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Apr 21, 2007 2:48 am    Post subject: Reply with quote

For me, all the boxes get checked when I click directly inside of any single box. But if I click to the right of the box (on the item name), only one item becomes checked (but only after the next mouse-movement, as you said).

I'm not sure how to fix this, but it's probably best to avoid using Click to put checkmarks in the script's own ListViews. Perhaps ControlClick or that HitTest message mentioned earlier will work.
Back to top
View user's profile Send private message Send e-mail
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Sat Apr 21, 2007 6:29 am    Post subject: Reply with quote

Thanks for taking a lok at it. Unfortunately ControlClick doesn't improve it. But adding an additional hazzle to calculate the correct coordinate. So I leave it it as it is. Thanks.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group