On 26/06/07, Robert May <[EMAIL PROTECTED]> wrote:
On 22/06/07, Salvador Ortiz García <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> This is my first post to the list, so forgive me if this was discussed
> before.
I don't think it has been discussed before, but I have noticed it
myself. I didn't find it enough of an issue to want to deal with it.
>
> Reflecting the Win32 API, Win32::GUI::TreeView has a GetParent method to
> get the parent node (HTREEITEM) of a node, nothing related with the
> GetParent common method of Win32::GUI.
>
> The common call
>
> my $parentWin = $SomeControl->GetParent();
>
> simply don't work when $SomeContros isa TreeView, so right now when I
> need the parent window of the TV control we must use an ugly workaround:
>
> my $parentWin = Win32::GUI::GetParent($TreeView);
>
> The following patch cures that, properly subclassing the TreeView with
> only minimal semantic changes IMHO:
>
> When called without NODE or with NODE equal zero (NULL, an invalid
> HTREEITEM value anyway) now TreeView::GetParent() returns the parent
> window, if any, or undef as Win32::GUI::GetParent() does.
>
> Any other value for NODE returns the handler of the parent NODE (or NULL
> at the root NODE) as documented.
>
> So the following works as spected:
>
> sub TV_NodeClick { # Click on a node, OEM form
> my($TreeView, $node) = @_;
> my $parentWin = $TreeView->GetParent();
> my $parentNode = $TreeView->GetParent($node);
> ...
>
> Comments?
I'm a bit short of time at the moment, but I'd like to give this some
more though, as one of the things I strive for is backwards
compatibility and I'm not completely convinced. I think the idea is
OK, but I'd like to tinker with the implementation a little ... give
me a couple of weeks to mull it over.
Many thanks for the contribution.
Regards,
Rob.
OK, having thought about it I propose the following. The only
significant change is how I determine the behaviour. There is
probably code like this in the field:
my $parent_node = $tv->GetParent($node);
where $node is calculated. It would be surprising if when $node is 0
(or indeed undef) to get back a Win32::GUI::Window object. So I check
the number of items actually passed, and only fallback to the
GetParent() window method if no arguments are passed:
my $parent_window_object = $tv->GetParent();
Regards,
Rob.
I haven't actually compiled and tested this yet:
###########################################################################
# (@)METHOD:GetParent(NODE)
# Returns the handle of the parent node for the given B<NODE>.
#
# NOTE: With no B<NODE> parameter this is the standard
# L<GetParent()|Win32::GUI::Reference::Methods/GetParent>
# method, returning the parent window.
HTREEITEM
GetParent(handle,item = NULL)
HWND handle
HTREEITEM item
CODE:
if(items == 1) { /* NOTE this is the XS defined 'items' var, not 'item' */
SV *SvParent;
HWND parentHandle = GetParent(handle);
if (parentHandle && (SvParent =
SV_SELF_FROM_WINDOW(parentHandle)) && SvROK(SvParent)) {
XPUSHs(SvParent);
XSRETURN(1);
}
else {
XSRETURN_UNDEF;
}
}
else {
RETVAL = TreeView_GetParent(handle, item);
}
OUTPUT:
RETVAL