+static void show_opendropdown(FileDialogImpl *This)
+{
+ HWND open_hwnd;
+ RECT open_rc;
+ MSG msg;
+
+ open_hwnd = GetDlgItem(This->dlg_hwnd, IDOK);
+
+ GetWindowRect(open_hwnd, &open_rc);
+
+ if (TrackPopupMenu(This->hmenu_opendropdown, 0, open_rc.left, open_rc.bottom, 0, This->dlg_hwnd, NULL) &&
+ PeekMessageW(&msg, This->dlg_hwnd, WM_MENUCOMMAND, WM_MENUCOMMAND, PM_REMOVE))
+ {
+ MENUITEMINFOW mii;
+
+ This->opendropdown_has_selection = TRUE;
+
+ mii.cbSize = sizeof(mii);
+ mii.fMask = MIIM_ID;
+ GetMenuItemInfoW((HMENU)msg.lParam, msg.wParam, TRUE, &mii);
+ This->opendropdown_selection = mii.wID;
+
+ if(SUCCEEDED(on_default_action(This)))
+ EndDialog(This->dlg_hwnd, S_OK);
+ else
+ This->opendropdown_has_selection = FALSE;
+ }
+}
+
+/**************************************************************************
+ * Control item functions.
+ */
+
+static void item_free(cctrl_item *item)
+{
+ DestroyWindow(item->hwnd);
+ HeapFree(GetProcessHeap(), 0, item->label);
+ HeapFree(GetProcessHeap(), 0, item);
+}
+
+static cctrl_item* get_item(customctrl* parent, DWORD itemid, CDCONTROLSTATEF visible_flags, DWORD* position)
+{
+ DWORD dummy;
+ cctrl_item* item;
+
+ if (!position) position = &dummy;
+
+ *position = 0;
+
+ LIST_FOR_EACH_ENTRY(item, &parent->sub_items, cctrl_item, entry)
+ {
+ if (item->id == itemid)
+ return item;
+
+ if ((item->cdcstate & visible_flags) == visible_flags)
+ (*position)++;
+ }
+
+ return NULL;
+}
+
+static cctrl_item* get_first_item(customctrl* parent)
+{
+ cctrl_item* item;
+
+ LIST_FOR_EACH_ENTRY(item, &parent->sub_items, cctrl_item, entry)
+ {
+ if ((item->cdcstate & (CDCS_VISIBLE|CDCS_ENABLED)) == (CDCS_VISIBLE|CDCS_ENABLED))
+ return item;
+ }
+
+ return NULL;
+}
+
+static HRESULT add_item(customctrl* parent, DWORD itemid, LPCWSTR label, cctrl_item** result)
+{
+ cctrl_item* item;
+ LPWSTR label_copy;
+
+ if (get_item(parent, itemid, 0, NULL))
+ return E_INVALIDARG;
+
+ item = HeapAlloc(GetProcessHeap(), 0, sizeof(*item));
+ label_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(label)+1)*sizeof(WCHAR));
+
+ if (!item || !label_copy)
+ {
+ HeapFree(GetProcessHeap(), 0, item);
+ HeapFree(GetProcessHeap(), 0, label_copy);
+ return E_OUTOFMEMORY;
+ }
+
+ item->id = itemid;
+ item->parent_id = parent->id;
+ lstrcpyW(label_copy, label);
+ item->label = label_copy;
+ item->cdcstate = CDCS_VISIBLE|CDCS_ENABLED;
+ item->hwnd = NULL;
+ list_add_tail(&parent->sub_items, &item->entry);
+
+ *result = item;
+
+ return S_OK;
+}
+