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 

LVX: Row highlighting and cell editing for ListView controls
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
aw1ace



Joined: 14 May 2008
Posts: 6

PostPosted: Wed May 21, 2008 5:16 pm    Post subject: Reply with quote

@ Tekl

Quote:
So I have to use LV_ColorInitiate instead of LVX_Setup?


Yes,
LV_ColorInitiate(LvVar, Color=255, Gui_Number=1, Control="")
Just delcare this line after the gui%#%, show

Quote:
Can I call it for the same Control more than one time or how do I specify to wich ListView (I want to use more than one) the LVX_SetColour is send?


Example:
For Default GUI and LV:
LV_ColorInitiate("MyListViewVar", 0xebf02f)
For #1 GUI:
LV_ColorInitiate("MyListViewVar", 0xebf02f, 1, "WhateverControl")
For #2 GUI:
LV_ColorInitiate("MyListViewVar", 0xebf02f, 2, "WhateverControl")
_________________
-Ace
Back to top
View user's profile Send private message
Tekl



Joined: 24 Sep 2004
Posts: 813
Location: Germany

PostPosted: Wed May 21, 2008 5:18 pm    Post subject: Reply with quote

And I can mix it up?

After Changing Gui 1 and 2 I want to change Gui 1 again.
_________________
Tekl
Back to top
View user's profile Send private message Visit poster's website
aw1ace



Joined: 14 May 2008
Posts: 6

PostPosted: Wed May 21, 2008 5:21 pm    Post subject: Reply with quote

@ Tekl

Sorry, I have not tested swapping back and forth from GUI. I do not see that being a problem, as I said, as long as WM_Nofity is updating there should not be an issue. Just try calling the LV_ColorInitiate after each gui, show ?
_________________
-Ace
Back to top
View user's profile Send private message
Tekl



Joined: 24 Sep 2004
Posts: 813
Location: Germany

PostPosted: Wed May 21, 2008 5:22 pm    Post subject: Reply with quote

Ok, I'll try it. With the original code it is not working even with one GUI and calling the LVX_Setup twice.
_________________
Tekl
Back to top
View user's profile Send private message Visit poster's website
aw1ace



Joined: 14 May 2008
Posts: 6

PostPosted: Wed May 21, 2008 5:29 pm    Post subject: Reply with quote

@ Tekl

Actually, All you need to do is call
LV_ColorInitiate(0xebf02f)
I am not sure why I had the listview var in there, only need to specify control if using a different one. I re-copied an updated code below.


Code:
/*
    HiLite - Ace
           *Enable onClick Highlighting and Scroll Highlighting
        *Made for the Listviews without altsubmit as there is no "Normal" events fired

      Remarks:
         LV_ColorInitiate( HiLite_Color)  - is to be added in your startup to initialize Highlighting
        *Use Color in Hex format, Example Call -  LV_ColorInitiate(0xebf02f)

      Buffer - Set number of lines visible above or below highlighted line while scrolling
        *Default value = 1

      Call MouseDown() and MouseUp() in your WheelUp/WheelDown Hotkeys or whatever you want to make the ListView Scroll with

      -----Do Not need to add but can enhance preformance-----
      -----I used -0x8 because of click+drag ablitiy on my listview----
      #MaxHotkeysPerInterval - Set this or the Scroll hotkeys will trigger Interval Errors
      -0x8 - Add this to listview , will disable Listview highlighting, this is needed if you have g_label for listview and want other events fired
*/

LV_ColorInitiate(Color=255, Gui_Number=1, Control="")   {           ; initiatize listview color change procedure, Default HiLite_Color = Blue (255) BGR
  Global
 HiLite_Color := Color                             
  If !Control
    Control = SysListView321
  Gui, %Gui_Number%:+Lastfound
  Gui_ID := WinExist()
  ControlGet, hw_LVX_HiLite, HWND,, %Control%, Ahk_ID %Gui_ID%
  OnMessage( 0x4E, "WM_NOTIFY" )
}

MouseDown(Buffer=1) {
  Global
    DllCall("GetScrollRange", "uint", hw_LVX_HiLite, "int", 1, "int*", min, "int*", max)  ;Used in place of lv_getcount() because it also retrieves minimum range as well as maximum range
    If !ScrollPos                                             ; Set ScrollPos to 1 if empty, this is used inplace of lv_getnext()
      ScrollPos = 1
    If ScrollPos > %max%                                      ; Ensure that LvX function does not draw in row that doest not exist and error out
      Return
    ScrollPos++                                               ; Increment Scrolldown position by 1
    LV_Modify(ScrollPos + Buffer, "+vis")                     ; Add buffer to bottom of highlighted text - Increase "Buffer" to add more lines
    LVX_SetColour(ScrollPos, HiLite_Color)                    ; Highlights current selected row, ScrollPos, Background_Color
Return
}

MouseUp(Buffer=1) {
  Global
    DllCall("GetScrollRange", "uint", hw_LVX_HiLite, "int", 1, "int*", min, "int*", max)  ;Used in place of lv_getcount() because it also retrieves minimum range as well as maximum range
    min+=1                                                    ; Set min = to 1 or LvX function tries to draw on line 0 and errors out
    If ScrollPos < %min% or !ScrollPos                        ; Ensure that LvX function does not draw at row 0 and error
      Return
    ScrollPos--                                               ; DeIncrement Scrolldown position by 1
    LV_Modify(ScrollPos - Buffer, "+vis")                     ; Add buffer to Top of highlighted text - Incraese "Buffer" to add more lines
    LVX_SetColour(ScrollPos, HiLite_Color)                    ; Highlights current selected row, ScrollPos, Background_Color
Return
}

WM_NOTIFY( p_w, p_l, p_m )  {
  Global
  Critical
    Current_Line := NumGet(p_l + 36)+1                                           ; Get Current Selected Row
      If ( DllCall("GetFocus") = hw_LVX_HiLite ) {                               ; Control has Keyboard Focus?
        SendMessage, 4140, Current_Line-1, 2, , Ahk_ID %hw_LVX_HiLite%           ; LVM_GETITEMSTATE
          If ( ErrorLevel = 2 ) {                                                ; LVIS_SELECTED
            NumPut(0x2, p_l + 16)                                                ; LVITEM->stateMask ; LVIS_SELECTED
            SendMessage, 4139, Current_Line-1, p_l, , Ahk_ID %hw_LVX_HiLite%     ; Disable Highlighting
            ScrollPos := Current_Line                                            ; Set Clicked Highlighted line = scrollposition
            LVX_SetColour(Current_Line, HiLite_Color)                            ; Color Current_Line + Background   +Text color is available but not sent in this case
          Return, 0x00000010                                                     ; CDRF_NOTIFYPOSTPAINT
          }
      }
  If (NumGet(p_l + 0) == NumGet(lvx))
    Return, LVX_Notify(p_w, p_l, p_m)
}

/*   Function: LVX_Notify
         Handler for WM_NOTIFY events on ListView controls. Do not use this function.
*/
LVX_Notify(p_w, p_l, p_m) {
   Global lvx
   If (NumGet(p_l + 0) == NumGet(lvx) and NumGet(p_l + 8, 0, "Int") == -12) {
      st := NumGet(p_l + 12)
      If st = 1
         Return, 0x20
      Else If (st == 0x10001) {
         a := NumGet(p_l + 36) * 9 + 9
         If NumGet(lvx, a)
          NumPut(NumGet(lvx, a - 4), p_l + 48), NumPut(NumGet(lvx, a), p_l + 52)
      }
   }
}

/*   Function: LVX_SetColour
         Set the background and/or text colour of a specific row on a ListView control.

      Parameters:
         index - row index (1-based)
         back - (optional) background row colour, must be hex code in RGB format (default: 0xffffff)
         text - (optional) similar to above, except for font colour (default: 0x000000)

      Remarks:
         Sorting will not affect coloured rows.
*/
LVX_SetColour(Index, HiLite=255, Text="") {
   Global lvx, hw_LVX_HiLite
     LVX_SetEditHotkeys()                           ; Enable Default Hotkeys
     SendMessage,4100,0,0, ,Ahk_ID %hw_LVX_HiLite%  ; Get Total Number of rows for highlighting VarCapacity
      VarSetCapacity(lvx, 4 + ErrorLevel * 9, 0)     ; Total rows is needed when capacity is initialized so all rows can be drawn on
     NumPut(hw_LVX_HiLite + 0, lvx)
     A := (Index - 1) * 9 + 5
     If Text
      NumPut(LVX_RevBGR(Text) + 0, lvx, A)
     NumPut(LVX_RevBGR(HiLite) + 0, lvx, A + 4)
     WinSet, Redraw, ,Ahk_ID %hw_LVX_HiLite%
}


/*      Function: LVX_RevBGR
         Helper function for internal use. Converts RGB to BGR.

      Parameters:
         i - BGR hex code
*/
LVX_RevBGR(i) {
   Return, (i & 0xff) << 16 | (i & 0xffff) >> 8 << 8 | i >> 16
}

/*      Function: LVX_SetEditHotkeys
         Change accept/cancel hotkeys in cell editing mode.

      Parameters:
         enter - comma seperated list of hotkey names/modifiers that will save
            the current input text and close editing mode
         esc - same as above but will ignore text entry (i.e. to cancel)

      Remarks:
         The default hotkeys are Enter and Esc (Escape) respectively,
            and such will be used if either parameter is blank or omitted.
*/
LVX_SetEditHotkeys(enter = "Enter,NumpadEnter", esc = "Esc") {
   Global lvx, lvxb
   Static h1, h0
   If (enter == ~1) {
      If esc > 0
      {
         lvxb = 0
         Hotkey, IfWinNotActive, Ahk_ID %esc%
      }
      Loop, Parse, h1, `,
         Hotkey, %A_LoopField%, _lvxb
      Loop, Parse, h0, `,
         Hotkey, %A_LoopField%, _lvxc
      Hotkey, IfWinActive
      Return
   }
   If !enter
      h1 = %enter%
   If !esc
      h0 = %esc%
}

_lvxc: ; these labels are for internal use:
lvxb++
_lvxb:
lvxb++
LVX_SetEditHotkeys(~1, -1)
Return

;----------------------------------------------------------------------------------
;LvX - Titan
; License:
;    o Version 1.04 by Titan <http://www.autohotkey.net/~Titan/#lvx>
;    o zlib License <http://www.autohotkey.net/~Titan/zlib.txt>
; http://www.autohotkey.com/forum/topic26541.html&highlight=lvx

_________________
-Ace
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
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