Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple checkbox support #1

Closed
vincentparrett opened this issue Jan 21, 2015 · 14 comments
Closed

Multiple checkbox support #1

vincentparrett opened this issue Jan 21, 2015 · 14 comments

Comments

@vincentparrett
Copy link
Contributor

From a...@anse.de on June 14, 2009 06:25:24

Currently there is checkbox support for one (I think the main-) column.
Which is nice and useful.

There are several situtations where more than one checkbox per node is
needed. I have implemented a workaround for this in HeidiSQL, where a
checkbox image gets drawn in OnAfterCellPaint, and clicks are handled in
OnClick - not very nice code, and the checkbox doesn't behave exactly like
a normal checkbox does. For example the style of it is not adjusted to
Vista or XP. Or events like OnGetText set the cell text but that is not
displayed anywhere.

See also a forum discussion: http://support.soft-gems.net/forums/viewtopic.php?t=1526

Original issue: http://code.google.com/p/virtual-treeview/issues/detail?id=1

@vincentparrett
Copy link
Contributor Author

From mike.lischke on June 15, 2009 23:44:24

This change requires to store check state data in the node records. In order to
minimize impact on memory and still be effective when querying the states a sparse
array approach seems to be a good choice.

Labels: Effort-High Impact-Low Workaround-None Risk-Medium

@vincentparrett
Copy link
Contributor Author

From mike.lischke on June 15, 2009 23:47:02

Status: Accepted

@vincentparrett
Copy link
Contributor Author

From karah...@tele2.at on October 18, 2009 16:04:02

I describe a workaround in my Tutorial Part 2 - v0.08 in 2.18.6) without any
disadvantage and no change of the VirtualTrees.pas
Tested with VST 5.0.0 r229 http://www.delphipraxis.net/topic166359,0,asc,0.html The Tutorial is in german. If you need english, please ask me. I will try to
translate that sequence.

LG Wolfgang

@vincentparrett
Copy link
Contributor Author

From a...@anse.de on October 19, 2009 11:10:46

To be honest, in the meantime I'd become unsure if VT really needs per column
checkboxes as an out-of-the-box feature. It's a rare case to have checkboxes on more
than one column, and I also solved that in one situation with some few lines of code.
Hmm..

@vincentparrett
Copy link
Contributor Author

From karah...@tele2.at on October 20, 2009 00:01:24

Ok, so we have a new category of Issues: a wish ... and a clear, practicable and
flexible solution.
LG Wolfgang

@vincentparrett
Copy link
Contributor Author

From an...@rambler.ru on November 10, 2009 09:47:43

Wolfgang, could you please describe the method in a few
words? Currently I use bold dots (●) in the cells as a
kind of checkbox replacement.

@vincentparrett
Copy link
Contributor Author

From karah...@tele2.at on November 10, 2009 15:34:20

Ok, I will try it. I hope my english is clear enough. If something ist unclear,
please aks me.
See attached text and demo-project.
LG Wolfgang

Attachment: Issue 1 Workaround.rtf WZ_VST_TestDrive.zip

@vincentparrett
Copy link
Contributor Author

From an...@rambler.ru on November 10, 2009 23:22:20

Wolfgang, thank you a lot! Everything's clear.

@vincentparrett
Copy link
Contributor Author

From jchoo...@gmail.com on June 04, 2010 19:20:27

While drawing those images are functional, I wonder if you could make it "Theme
Aware" via
interface
...
procedure VST5AfterCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas;
Node: PVirtualNode; Column: TColumnIndex;
CellRect: TRect);
procedure DrawCheckBox(Sender: TBaseVirtualTree; const Canvas: TCanvas; const
Rect: TRect; const Checked: Boolean);
...

using
..., Themes, UxTheme;

procedure TGridForm.VST5AfterCellPaint(Sender: TBaseVirtualTree; TargetCanvas:
TCanvas; Node: PVirtualNode;
Column: TColumnIndex; CellRect: TRect);

begin
if Column = 0 then
with TargetCanvas do
begin
// Decorate the fixed indicator column by filling it with an edge similar to
that of TCustomGrid.
if toShowVertGridLines in VST5.TreeOptions.PaintOptions then
Inc(CellRect.Right);
if toShowHorzGridLines in VST5.TreeOptions.PaintOptions then
Inc(CellRect.Bottom);
DrawEdge(Handle, CellRect, BDR_RAISEDINNER, BF_RECT or BF_MIDDLE);
if Node = Sender.FocusedNode then
TreeImages.Draw(TargetCanvas, CellRect.Left + 4, CellRect.Top, 17);
end
else if Column =1 then
begin
DrawCheckBox(Sender as TVirtualStringTree, TargetCanvas, CellRect, (Node.Index
mod 2 = 0) );
end;

end;

procedure TGridForm.DrawCheckBox(Sender: TVirtualStringTree; const Canvas: TCanvas;
const Rect: TRect; const Checked: Boolean);
var
Details: TThemedElementDetails;
X, Y: Integer;
R: TRect;
NonThemedCheckBoxState: Cardinal;
const
CHECKBOX_SIZE = 13;
begin
if ( // if it's a TVirtualStringTree, then key off of the paint options
(Sender is TVirtualStringTree) and
(toThemeAware in TVirtualStringTree(Sender).TreeOptions.PaintOptions)
) or
// If it is not themed, but the OS is themed, you can check it like this
ThemeServices.ThemesEnabled then
begin

if Checked then
  Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal)
else
  Details := ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal);

X := Rect.Left + (Rect.Right - Rect.Left - CHECKBOX_SIZE) div 2;
Y := Rect.Top + (Rect.Bottom - Rect.Top - CHECKBOX_SIZE) div 2;
R := Types.Rect(X, Y, X + CHECKBOX_SIZE, Y + CHECKBOX_SIZE);
ThemeServices.DrawElement(Canvas.Handle, Details, R);
end

else
begin
// Fill the background
Canvas.FillRect(Rect);

NonThemedCheckBoxState := DFCS_BUTTONCHECK;

if Checked then
  NonThemedCheckBoxState := NonThemedCheckBoxState or DFCS_CHECKED;

X := Rect.Left + (Rect.Right - Rect.Left - CHECKBOX_SIZE) div 2;
Y := Rect.Top + (Rect.Bottom - Rect.Top - CHECKBOX_SIZE) div 2;
R := Types.Rect(X, Y, X + CHECKBOX_SIZE, Y + CHECKBOX_SIZE);
DrawFrameControl(Canvas.Handle, R, DFC_BUTTON, NonThemedCheckBoxState);
end;

end;

Note, this is just a tweak to the current demo code to get basic functionality of
drawing a check box. It could be enhanced to determine the "hot tracking" state, and
for logic to toggle the checked state.

@vincentparrett
Copy link
Contributor Author

From m.ton...@upscene.com on December 10, 2010 01:49:14

I would certainly like additional checkbox support without having to go through hoops for it. Drawing the checkboxes ain't that hard, but making them functional including "hot tracking" etc is getting annoying.

@vincentparrett
Copy link
Contributor Author

From joachim....@gmail.com on May 14, 2013 13:29:15

Status: New
Labels: -Type-Defect Type-Enhancement

@vincentparrett
Copy link
Contributor Author

From fr0st.br...@gmail.com on February 06, 2014 04:47:49

I propose adding an event:

TVTGetCellCheckEvent = procedure(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; out CheckType: TCheckType; out CheckState: TCheckState) of object;

which will be called in GetCheckImage (which will require adding Column parameter):

if Assigned(Node) then
begin
ImgCheckType := Node.CheckType;
ImgCheckState := Node.CheckState;
DoGetCellCheck(Node, Column, ImgCheckType, ImgCheckState);
...

so that it will be the user who fully controls check type/state like it is done for image index, for example. A sample use could look like this:

// assuming Node.CheckType is set to cbCheckBox; if not, just return it for those columns which need checkboxes
procedure TForm1.VTGetCellCheck(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; out CheckType: TCheckType; out CheckState: TCheckState);
var
Checked: Boolean;
begin
// checkboxes for columns #1 and #2
case Column of
1: Checked := PNodeRec(Sender.GetNodeDataPtr(Node)).Enabled;
2: Checked := PNodeRec(Sender.GetNodeDataPtr(Node)).Modified;
// no checkboxes for other columns
else begin CheckType := ctNone; Exit; end;
end;
if Checked then CheckState := csCheckedNormal else CheckState := csUncheckedNormal;
end;

I've started implementing this but then appeared pretty much little stuff like node hover/click handling, node selecting, node empty text display etc so I held it for a while.

@ralfiii
Copy link

ralfiii commented Aug 7, 2017

Help!!!
The links to the Tutorial at DelphiPraxis, to Workaround.rtf and to WZ_VST_TestDrive.zip are dead.
Can anymode help me where to get info on that issue?
I FREQUENTLY would need multiple checkbox-columns, so I highly disagree with "just a rare case".

Btw: I'd like to see the tutorial. We are using Delphi2010, so I am hoping for a solution that works with VST Version 5.

Thanks in advance!
Ralf

@joachimmarder
Copy link
Contributor

Being unresolved after almost 10 years, I am closing this feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants