Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[module] RaGrid 2.0.1.6-4


  • Please log in to reply
57 replies to this topic
freakkk
  • Members
  • 182 posts
  • Last active: Dec 16 2014 06:23 PM
  • Joined: 29 Jul 2005

The only thing I didn't wrap are notification handlers for text change, button clicks etc. This is fairly trivial to add, but I didn't have time now.

I was recently using this control for something, & needed to wrap the notification interface for some simple stuff.

;----------------------------------------------------------------------------------------------------
; Function: SetEvents
;			Set notification events
;
; Parameters:
;			func	- Subroutine that will be called on events.
;			e		- White space separated list of events to monitor (by default, null).
;
; Globals:
;			RG_EVENT	- Specifies event that occurred. Event must be registered to be able to monitor them.
;     RG_ROW    - String containing zero based row number.
;     RG_COLUMN - String containing zero based column number.

; Events & Infos:
;			HEADERCLICK	- Sent when user clicks header.
;			BUTTONCLICK - Sent when user clicks the button in a button cell.
;			CHECKCLICK - Sent when user double clicks the checkbox in a checkbox cell. 
;			IMAGECLICK - Sent when user double clicks the image in an image cell. 
;			BEFORESELCHANGE - (not implemented) Sent when user request a selection change. 
;			AFTERSELCHANGE - Sent after a selection change. 
;			BEFOREEDIT - Sent before the cell edit control shows. 
;			AFTEREDIT - Sent when the cell edit control is about to close. 
;			BEFOREUPDATE - (not implemented) Sent before a cell updates grid data. 
;			AFTERUPDATE - (not implemented) Sent after grid data has been updated. 
;			USERCONVERT - (not implemented) Sent when user cell needs to be converted.
;
; Returns:
;			"OK" if succesiful, error string otherwise
;
RG_SetEvents(hGrd, func, e=""){
	local old, hmask
  static GN_HEADERCLICK=0x1,GN_BUTTONCLICK=0x2,GN_CHECKCLICK=0x3,GN_IMAGECLICK=0x4
        ,GN_BEFORESELCHANGE=0x5,GN_AFTERSELCHANGE=0x6,GN_BEFOREEDIT=0x7,GN_AFTEREDIT=0x8
        ,GN_BEFOREUPDATE=0x9,GN_AFTERUPDATE=0xa,GN_USERCONVERT=0xb, WM_NOTIFY:=0x4E
  static events="HEADERCLICK,BUTTONCLICK,CHECKCLICK,IMAGECLICK,BEFORESELCHANGE,AFTERSELCHANGE,BEFOREEDIT,AFTEREDIT,BEFOREUPDATE,AFTERUPDATE,USERCONVERT"

	if !IsLabel(func)
		return "Err: label doesn't exist`n`n" func

  RG_%hGrd%_mask := "" ; clear any previous set mask
	loop, parse, e, %A_Tab%%A_Space%
	{
		IfEqual, A_LoopField, , continue
		if A_LoopField not in %events%
			return "Err: unknown event - '" A_LoopField "'"
		RG_%hGrd%_mask .= RG_%hGrd%_mask ? "," . GN_%A_LOOPFIELD% : GN_%A_LOOPFIELD%
	}
	IfEqual, RG_%hGrd%_mask,, return   ; not monitoring any events


	old := OnMessage(WM_NOTIFY, "RG_onNotify") ; set RaGrid msg handler and remember old one
	if (old != "RG_onNotify")
		RG_oldNotify := RegisterCallback(old)    ; store callable old message handler

  hGrd += 0
	RG_%hGrd%_func := func
	return "OK"
}


RG_onNotify(wparam, lparam, msg, hwnd) {
	local code, hw, row,col,mask
  static pInfo
  static GN_HEADERCLICK=0x1,GN_BUTTONCLICK=0x2,GN_CHECKCLICK=0x3,GN_IMAGECLICK=0x4
        ,GN_BEFORESELCHANGE=0x5,GN_AFTERSELCHANGE=0x6,GN_BEFOREEDIT=0x7
        ,GN_AFTEREDIT=0x8,GN_BEFOREUPDATE=0x9,GN_AFTERUPDATE=0xa,GN_USERCONVERT=0xb

  ; Call previous set WM_NOTIFY
  RG_oldNotify ? DllCall(RG_oldNotify, "uint", wparam, "uint", lparam, "uint", msg, "uint", hwnd) : ""

	hw	 := NumGet(lparam+0)   ; control sending the message - this RaGrid
  mask := RG_%hw%_mask       ; current events monitoring for

  SetFormat, integer, hex
	code   :=  NumGet(lparam+8)	;-
  SetFormat, integer, d

  if code not in %mask%
    return

  RG_ROW := NumGet(lparam+16),  RG_COLUMN := NumGet(lparam+12)

	if (code = GN_HEADERCLICK) {
		RG_EVENT := "HEADERCLICK", RG_ROW := ""
		GoSub % RG_%hw%_func
		return
	}

	if (code = GN_BUTTONCLICK) {
		RG_EVENT := "BUTTONCLICK"
		GoSub % RG_%hw%_func
		return
	}

	if (code = GN_CHECKCLICK) {
		RG_EVENT := "CHECKCLICK"
		GoSub % RG_%hw%_func
		return
	}

	if (code = GN_IMAGECLICK) {
		RG_EVENT := "IMAGECLICK"
		GoSub % RG_%hw%_func
		return
	}

; 	if (code = GN_BEFORESELCHANGE) {
; 		RG_EVENT := "BEFORESELCHANGE"
; 		GoSub % RG_%hw%_func
; 		return
; 	}

	if (code = GN_AFTERSELCHANGE) {
    IfEqual, pInfo, %RG_ROW%|%RG_COLUMN%, return  ; filter out mutiple dup message calls
    pInfo = %RG_ROW%|%RG_COLUMN%                  ; store info for comparison in next iteration
		RG_EVENT := "AFTERSELCHANGE" 
		GoSub % RG_%hw%_func
		return
	}

	if (code = GN_BEFOREEDIT) {
		RG_EVENT := "BEFOREEDIT" 
		GoSub % RG_%hw%_func
		return
	}

	if (code = GN_AFTEREDIT) {
		RG_EVENT := "AFTEREDIT" 
		GoSub % RG_%hw%_func
		return
	}

; 	if (code = GN_BEFOREUPDATE) {
; 		RG_EVENT := "BEFOREUPDATE" 
; 		GoSub % RG_%hw%_func
; 		return
; 	}

; 	if (code = GN_AFTERUPDATE) {
; 		RG_EVENT := "AFTERUPDATE" 
; 		GoSub % RG_%hw%_func
; 		return
; 	}

}

I tried implementing your stacking techniques, as not to screw up any other wrappers that use WM_NOTIFY message. It seems to test out okay, but you may want to double check it though, to make sure I got it right (if you get a chance that is..) :wink:

#Include RaGrid.ahk
#SingleInstance, force

	Gui, +LastFound  
	hwnd := WinExist()

;EDITTEXT,EDITLONG,	CHECKBOX,	COMBOBOX,	HOTKEY,	BUTTON,	IMAGE,	DATE,	TIME,	USER,	EDITBUTTON
	hGrd := RG_Add(hwnd, 0, 30, 800, 500, "GRIDFRAME VGRIDLINES NOSEL" )

	RG_AddColumn(hGrd, "cap=zero" , "w=150", "ha=1", "ca=0", "type=EditText" )
	RG_AddColumn(hGrd, "cap=one"  , "w=150" ,"ha=1", "ca=0", "type=EditText" )
	RG_AddColumn(hGrd, "cap=two"  , "w=180" ,"ha=1", "ca=0", "type=EditText" )
	RG_AddColumn(hGrd, "cap=three", "w=150" ,"ha=1", "ca=0", "type=EditText" )
	RG_SetFont(hGrd, "s10 bold, Arial")
	RG_SetHdrHeight(hGrd, 30), RG_SetRowHeight(hGrd, 22)

  Loop, 20
  {
    aCol1 := aCol2 := aCol3 := aCol4 := "Row=" A_Index - 1 "  Col="
    aCol1 .= 0, aCol2 .= 1, aCol3 .= 2, aCol4 .= 3
    RG_AddRow(hGrd, "aCol")
  }
	Gui, Show, h500 w800
	
; -- Set events...
; "HEADERCLICK,BUTTONCLICK,CHECKCLICK,IMAGECLICK,BEFORESELCHANGE,AFTERSELCHANGE,BEFOREEDIT
; ,AFTEREDIT,BEFOREUPDATE,AFTERUPDATE,USERCONVERT"
  RG_SetEvents(hGrd, "OnRgEvent", "HEADERCLICK AFTERSELCHANGE BEFOREEDIT AFTEREDIT")


;-- Demonstrate that WM_NOTIFY events are stacked: Experiment w/ the order to see
  Alternate_WM_NOTIFY(func, 1, 0, 0)
  RG_SetEvents(hGrd, "OnRgEvent", "AFTERSELCHANGE AFTEREDIT") ; Change previous set event notifiers
  Alternate_WM_NOTIFY2(func, 1, 0, 0)


;   RG_SetEvents(hGrd, "OnRgEvent", "") ; Turn event notification off (or change)
return

^l::reload

OnRgEvent:
  ToolTip, % A_Now " - " RG_EVENT " | " RG_ROW "  " RG_COLUMN, 20, 40, 1
;   OutputDebug % RG_EVENT " | " RG_ROW "  " RG_COLUMN
return


Alternate_WM_NOTIFY(wparam, lparam, msg, hwnd){
  static WM_NOTIFY := 0x4E, old=0, user

  if !old {
    old := OnMessage(WM_NOTIFY, "Alternate_WM_NOTIFY"), user := wparam
    old := old = "Alternate_WM_NOTIFY" ? "-" : RegisterCallback(old, "", 4)
    return
  }
  if old != -
    DllCall(old, "uint", wparam, "uint", lparam, "uint", msg, "uint", hwnd)

  ;Test message handler here ....
  ToolTip, % A_Now " - Message stacking test notifier", 20, 20, 2
}
Alternate_WM_NOTIFY2(wparam, lparam, msg, hwnd){
  static WM_NOTIFY := 0x4E, old=0, user

  if !old {
    old := OnMessage(WM_NOTIFY, "Alternate_WM_NOTIFY2"), user := wparam
    old := old = "Alternate_WM_NOTIFY2" ? "-" : RegisterCallback(old, "", 4)
    return
  }
  if old != -
    DllCall(old, "uint", wparam, "uint", lparam, "uint", msg, "uint", hwnd)

  ;Test message handler here ....
  ToolTip, % A_Now " - Message stacking test notifier2", 20, 60, 3
}


;- still used within in RaGrid.ahk..
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
    Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
        DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}

ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
{
    Loop %pSize%  ; Build the integer by adding up its bytes.
        result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
    if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
        return result  ; Signed vs. unsigned doesn't matter in these cases.
    ; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
    return -(0xFFFFFFFF - result + 1)
}


majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Thanks man. I added this info on first page for now.
Thx for following stacking principle too. :)

I will merge this as soon as I have time to get back to AHK.
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Version 2.0.1.6-1
+ Entire RaGrid API available.
+ All globals removed.
+ Documentation
Posted Image

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
The ResetColumns function is missing.

:) Skrommel

/*
  Function: ResetColumns
    Reset columns of the control.
*/
RG_ResetColumns(hGrd) {
  static GM_RESETCOLUMNS=0x429
  SendMessage,GM_RESETCOLUMNS,,,, ahk_id %hGrd%
  return ErrorLevel
}


majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Thx Ill add it.

I thought there is no big difference to Reset function but I guess it un-dos user settings.
Posted Image

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
why isnt the grid showing? what am i doing wrong?

#NoEnv
SetWorkingDir %A_ScriptDir%
#SingleInstance, force

#Include Data\RaGrid.ahk

  GoSub MAINGUI
RETURN


MAINGUI:
  Gui 1: +LastFound +Resize
  MLWIN_ID := WinExist() 
  Gui 1: Show,h401 w520 Center, Test Script
  hGrd := RG_Add(MLWIN_ID, "5", "20", "410", "336", "HGRIDLINES VGRIDLINES", "RAGridEvents")
  RG_SetFont(hGrd, "s8, Courier New")
    
  RG_SetHdrHeight(hGrd, 20), RG_SetRowHeight(hGrd, 20)	
  
  RG_AddColumn(hGrd, "txt=Title",  "w=490", "hdral=1",	"txtal=0", "type=EditText")
  RG_AddColumn(hGrd, "txt=Path",  "w=150", "hdral=1",	"txtal=0", "type=EditButton")
  RG_AddColumn(hGrd, "txt=IMDb",  "w=100", "hdral=1",	"txtal=0", "type=EditText")
  RG_AddColumn(hGrd, "txt=Type",  "w=100", "hdral=1",	"txtal=0", "type=ComboBox", "items=Action|Adventure|Comedy|War|Drama|TV Series|Animation|Fantasy|History|Biography|Horror|Mystery|Romance|Thriller|Western|Crime|Family|Documentary|XXX")
  RG_AddColumn(hGrd, "txt=Year",  "w=100", "hdral=1",	"txtal=0", "type=EditText")
  RG_AddColumn(hGrd, "txt=Quality",  "w=100", "hdral=1",	"txtal=0", "type=ComboBox", "items=DVD Rip|R5|BD Rip|TV Rip|Cam|DVD Screener|Screener|Telesync|VHS Rip|Telecine|Workprint|Blu Ray|DVD|High Definition")
  RG_AddRow(hGrd, 0, "C1", "C1", "C1", "C1", "C1", "C1")
RETURN

RAGridEvents(HCtrl, Event, Col, Row, Data="") {
	static s
	;SB_SetText( s .= " | " col " " row " " event )
	if StrLen(s)>120
		s := ""
		
	if (Event = "BeforeEdit")
		;SetTimer, ResizeTimer, -1		;resize editing control
	
	if (Event = "HeaderClick")
		RG_Sort(HCtrl, Col)
    if (Event = "ButtonClick")
    msgbox you clicked a button
}


QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Its showing. Add more rows then 1 to see it.
Posted Image

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008

Its showing. Add more rows then 1 to see it.


i did but its still not showing...
but why is this happening?
on another example i have no rows at all and it still showed
QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
I don't know. It shows here normally woth code you gave.

on another example i have no rows at all and it still showed

I don't know how that happens. Grid lines show only up to the point where there are rows, which is normal. Parts of control that don't have rows are blank with no grid lines.

I suggest you try it on another computer
Posted Image

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
i found the problem.
on the example i posted here i used #Include RaGrid.ahk but on my pc i have #Include Data\RaGrid.ahk thats why it didnt work(i supposed it would work with both as it does everytime i have used #include by now)
you have any idea why this is happening?

on the script im making i want to have all includes and other stuff in the folder Data and not in the same dir as the main script
QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
That can only mean that RaGrid control wasn't created at all since dll wasnt found.

If you put both dll and module in the same dir u should include it as:

#include Data
#include RaGrid.ahk

or, if you keep them separate then you need to specify last parameter of Add function.
Posted Image

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
ok thanks :)

this custom control is great btw...many thanks for it and for you great work
im thinking of using it instead of listview in my movie database script
QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05

chahk
  • Members
  • 1 posts
  • Last active: Jan 26 2010 07:47 AM
  • Joined: 26 Jan 2010
first of all, thank you very much for RAGrid!

I believe I've found a problem with using the DATE type and RG_AddRow.

in RG_AddRow the line
if type in COMBOBOX,CHECKBOX,EDITLONG,IMAGE
should be
if type in COMBOBOX,CHECKBOX,DATE,EDITLONG,IMAGE


majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Ty

Version 2.0.1.6-3
! Bug in RG_AddRow with DATE,TIME & HOTKEY fixed.
Posted Image

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
i dont know if im missing something but is there a way to make the combobox behave like the autohotkeys combobox?...where you can also type in data? the combobox in ragrid behaves more like a drop down list
QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05