[REVIEW-3-5] fdo#46355 sort SelectionTree control of Custom Setup with a custom action

Jesús Corrius jesus at softcatala.org
Mon May 7 01:31:39 PDT 2012


Hi Andras,

On Sun, May 6, 2012 at 10:34 PM, Andras Timar <timar74 at gmail.com> wrote:
>  Fortunately the tree control under Windows can receive
> a message that does the sort, so everything can be solved with pure
> Windows API calls.
>
> http://cgit.freedesktop.org/libreoffice/core/commit/?id=39bb77fd667f9d9fdaf374f3934b6eec7b7dc57a

The Windows code looks OK, but there's no error control anywhere and
that makes me shiver.

I know in theory it shouldn't fail, but I would prefer to use an error
logging mechaninsm instead of letting it crash. This is just a sketch,
not real code.

BOOL bDidItWork = FALSE;
HWND hwndMSI = FindWindow(TEXT("MsiDialogCloseClass"), NULL);
if (hwdMSI) {
  HWND hwndTV = FindWindowEx(hwndMSI, NULL, TEXT("SysTreeView32"), NULL);
  if (hwndTV)
  {
    HTREEITEM treeRoot = TreeView_GetRoot(hwndTV);
    if (treeRoot)
    {
      HTREEITEM optional = TreeView_GetNextSibling(hwndTV, treeRoot);
      if (optional)
      {
        HTREEITEM dicts = TreeView_GetChild(hwndTV, optional);
        if ( dicts)
        {
          TreeView_SortChildren(hwndTV, dicts, TRUE);
          HTREEITEM langs = TreeView_GetNextSibling(hwndTV, optional);
          if (langs)
          {
            TreeView_SortChildren(hwndTV, langs, TRUE);
            bDidItWork = TRUE;
          }
        }
      }
  }
}

if (!bDidItWork) MessageBox(NULL, L"Error", L"Something is wrong. Call
the ghostbusters!");

or even a more controversial version:

HWND hwndMSI = FindWindow(TEXT("MsiDialogCloseClass"), NULL);
if(!hwndMSI) goto error;
HWND hwndTV = FindWindowEx(hwndMSI, NULL, TEXT("SysTreeView32"), NULL);
if(!hwndTV) goto error;
HTREEITEM treeRoot = TreeView_GetRoot(hwndTV);
if(!treeRoot) goto error;
HTREEITEM optional = TreeView_GetNextSibling(hwndTV, treeRoot);
if(!optional) goto error;
HTREEITEM dicts = TreeView_GetChild(hwndTV, optional);
if(!dicts) goto error;
TreeView_SortChildren(hwndTV, dicts, TRUE);
HTREEITEM langs = TreeView_GetNextSibling(hwndTV, optional);
if(!langs) goto error;
TreeView_SortChildren(hwndTV, langs, TRUE);

return TRUE;

error:
MessageBox(NULL, L"Error", L"Something is wrong. Call the ghostbusters!");


-- 
Jesús Corrius <jesus at softcatala.org>


More information about the LibreOffice mailing list