Hi all,

This is my first post to the list, so forgive me if this was discussed
before.

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?

========= CUT ==========
--- Win32-GUI/TreeView.xs       2006-04-13 17:17:07.000000000 -0500
+++ /home/sog/dosdir/work/Win32-GUI-1.05_01/TreeView.xs 2007-06-22
00:59:20.000000000 -0500
@@ -583,15 +583,32 @@


###########################################################################     
# (@)METHOD:GetParent(NODE)
-    # Returns the handle of the parent node for the given B<NODE>.
-HTREEITEM
-GetParent(handle,item)
+    # Returns the handle of the parent node for the B<NODE>, if given
+    # or the parent window of the TV control if not.
+void
+GetParent(handle,item = 0)
     HWND handle
     HTREEITEM item
-CODE:
-    RETVAL = TreeView_GetParent(handle, item);
-OUTPUT:
-    RETVAL
+PREINIT:
+    HWND parentHandle;
+    SV* SvParent;
+PPCODE:
+    if (item) {
+       XSRETURN_IV((long) TreeView_GetParent(handle, item));
+    } else {
+      parentHandle = GetParent(handle);
+      if (parentHandle != NULL) {
+        SvParent = SV_SELF_FROM_WINDOW(parentHandle);
+       if (SvParent != NULL && SvROK(SvParent)) {
+          XPUSHs(SvParent);
+       } else {
+          XSRETURN_UNDEF;
+        }
+      } else {
+         XSRETURN_UNDEF;
+      }
+    }
+


###########################################################################     
# (@)METHOD:GetPrevSibling(NODE)
=========== CUT ==============


Bests Regards.

-- 
Salvador Ortiz.


Reply via email to