/*
 * Copyright 2010 Justin Chevrier
 * Copyright 2023 Katayama Hirofumi MZ
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifndef DO_NO_IMPORTS
import "oaidl.idl";
#ifdef __midl
import "msctf.idl";
#endif
#endif

cpp_quote("#define TF_FLOATINGLANGBAR_WNDTITLEW L\"TF_FloatingLangBar_WndTitle\"")
cpp_quote("#define TF_FLOATINGLANGBAR_WNDTITLEA \"TF_FloatingLangBar_WndTitle\"")
cpp_quote("#ifdef UNICODE")
cpp_quote("#define TF_FLOATINGLANGBAR_WNDTITLE TF_FLOATINGLANGBAR_WNDTITLEW")
cpp_quote("#else")
cpp_quote("#define TF_FLOATINGLANGBAR_WNDTITLE TF_FLOATINGLANGBAR_WNDTITLEA")
cpp_quote("#endif")

/* Flags for ITfLangBarItemSink::OnUpdate */
cpp_quote("#define TF_LBI_ICON      0x00000001")
cpp_quote("#define TF_LBI_TEXT      0x00000002")
cpp_quote("#define TF_LBI_TOOLTIP   0x00000004")
cpp_quote("#define TF_LBI_BITMAP    0x00000008")
cpp_quote("#define TF_LBI_BALLOON   0x00000010")
cpp_quote("#define TF_LBI_CUSTOMUI  0x00000020")
cpp_quote("#define TF_LBI_BTNALL    (TF_LBI_TEXT | TF_LBI_ICON | TF_LBI_TOOLTIP)")
cpp_quote("#define TF_LBI_BMPBTNALL (TF_LBI_TEXT | TF_LBI_BITMAP | TF_LBI_TOOLTIP)")
cpp_quote("#define TF_LBI_BMPALL    (TF_LBI_BITMAP | TF_LBI_TOOLTIP)")
cpp_quote("#define TF_LBI_STATUS    0x00010000")

/* Flags for ITfLangBarItem::GetInfo */
cpp_quote("#define TF_LBI_STYLE_HIDDENSTATUSCONTROL 0x00000001")
cpp_quote("#define TF_LBI_STYLE_SHOWNINTRAY         0x00000002")
cpp_quote("#define TF_LBI_STYLE_HIDEONNOOTHERITEMS  0x00000004")
cpp_quote("#define TF_LBI_STYLE_SHOWNINTRAYONLY     0x00000008")
cpp_quote("#define TF_LBI_STYLE_HIDDENBYDEFAULT     0x00000010")
cpp_quote("#define TF_LBI_STYLE_TEXTCOLORICON       0x00000020")
cpp_quote("#define TF_LBI_STYLE_BTN_BUTTON          0x00010000")
cpp_quote("#define TF_LBI_STYLE_BTN_MENU            0x00020000")
cpp_quote("#define TF_LBI_STYLE_BTN_TOGGLE          0x00040000")

/* Flags for ITfLangBarItem::GetStatus */
cpp_quote("#define TF_LBI_STATUS_HIDDEN      0x00000001")
cpp_quote("#define TF_LBI_STATUS_DISABLED    0x00000002")
cpp_quote("#define TF_LBI_STATUS_BTN_TOGGLED 0x00010000")

cpp_quote("#define TF_LBI_BMPF_VERTICAL 0x00000001")

/* Flags for ShowFloating */
cpp_quote("#define TF_SFT_SHOWNORMAL              0x00000001")
cpp_quote("#define TF_SFT_DOCK                    0x00000002")
cpp_quote("#define TF_SFT_MINIMIZED               0x00000004")
cpp_quote("#define TF_SFT_HIDDEN                  0x00000008")
cpp_quote("#define TF_SFT_NOTRANSPARENCY          0x00000010")
cpp_quote("#define TF_SFT_LOWTRANSPARENCY         0x00000020")
cpp_quote("#define TF_SFT_HIGHTRANSPARENCY        0x00000040")
cpp_quote("#define TF_SFT_LABELS                  0x00000080")
cpp_quote("#define TF_SFT_NOLABELS                0x00000100")
cpp_quote("#define TF_SFT_EXTRAICONSONMINIMIZED   0x00000200")
cpp_quote("#define TF_SFT_NOEXTRAICONSONMINIMIZED 0x00000400")
cpp_quote("#define TF_SFT_DESKBAND                0x00000800")

/* OnMenuSelect flags */
cpp_quote("#define TF_INVALIDMENUITEM (UINT)(-1)")

/* SystemDeviceTypeLangbarItem flag */
cpp_quote("#define TF_DTLBI_USEPROFILEICON         0x00000001")

typedef enum
{
    TF_LBI_CLK_RIGHT = 1,
    TF_LBI_CLK_LEFT = 2
} TfLBIClick;

interface ITfLangBarEventSink;
interface ITfLangBarItemMgr;
interface ITfInputProcessorProfiles;
interface IEnumTfLangBarItems;
interface ITfLangBarItem;
interface ITfLangBarItemSink;
interface ITfLangBarItemBalloon;
interface ITfLangBarItemBitmap;
interface ITfLangBarItemBitmapButton;
interface ITfLangBarItemButton;
interface ITfMenu;
interface ITfSystemDeviceTypeLangBarItem;
interface ITfSystemLangBarItem;
interface ITfSystemLangBarItemSink;
interface ITfSystemLangBarItemText;

[
    object,
    uuid(87955690-e627-11d2-8ddb-00105a2799b5),
    pointer_default(unique)
]
interface ITfLangBarMgr: IUnknown
{
    HRESULT AdviseEventSink(
        [in] ITfLangBarEventSink *pSink,
        [in] HWND hwnd,
        [in] DWORD dwflags,
        [in] DWORD *pdwCookie);

    HRESULT UnAdviseEventSink(
        [in] DWORD dwCookie);

    HRESULT GetThreadMarshalInterface(
        [in] DWORD dwThreadId,
        [in] DWORD dwType,
        [in] REFIID riid,
        [out] IUnknown **ppunk);

    HRESULT GetThreadLangBarItemMgr(
        [in] DWORD dwThreadId,
        [out] ITfLangBarItemMgr **pplbie,
        [out] DWORD *pdwThreadid);

    HRESULT GetInputProcessorProfiles(
        [in] DWORD dwThreadId,
        [out] ITfInputProcessorProfiles **ppaip,
        [out] DWORD *pdwThreadid);

    HRESULT RestoreLastFocus(
        [out] DWORD *dwThreadId,
        [in] BOOL fPrev);

    HRESULT SetModalInput(
        [in] ITfLangBarEventSink *pSink,
        [in] DWORD dwThreadId,
        [in] DWORD dwFlags);

    HRESULT ShowFloating(
        [in] DWORD dwFlags);

    HRESULT GetShowFloatingStatus(
        [out] DWORD *pdwFlags);
}

[
  object,
  uuid(18a4e900-e0ae-11d2-afdd-00105a2799b5),
  pointer_default(unique)
]
interface ITfLangBarEventSink: IUnknown
{
    HRESULT OnSetFocus(
        [in] DWORD dwThreadId);

    HRESULT OnThreadTerminate(
        [in] DWORD dwThreadId);

    HRESULT OnThreadItemChange(
        [in] DWORD dwThreadId);

    HRESULT OnModalInput(
        [in] DWORD dwThreadId,
        [in] UINT uMsg, 
        [in] WPARAM wParam, 
        [in] LPARAM lParam);

    HRESULT ShowFloating(
        [in] DWORD dwFlags);

    HRESULT GetItemFloatingRect(
        [in] DWORD dwThreadId,
        [in] REFGUID rguid,
        [out] RECT *prc);
}

const ULONG TF_LBI_DESC_MAXLEN = 32;

typedef [uuid(12a1d29f-a065-440c-9746-eb2002c8bd19)] struct TF_LANGBARITEMINFO
{
    CLSID clsidService;
    GUID guidItem;
    DWORD dwStyle;
    ULONG ulSort;
    WCHAR szDescription[TF_LBI_DESC_MAXLEN];
} TF_LANGBARITEMINFO;

[
  object,
  uuid(ba468c55-9956-4fb1-a59d-52a7dd7cc6aa),
  pointer_default(unique)
]
interface ITfLangBarItemMgr : IUnknown
{
    HRESULT EnumItems(
        [out] IEnumTfLangBarItems **ppEnum);

    HRESULT GetItem(
        [in] REFGUID rguid, 
        [out] ITfLangBarItem **ppItem);

    HRESULT AddItem(
        [in] ITfLangBarItem *punk);

    HRESULT RemoveItem(
        [in] ITfLangBarItem *punk);

    HRESULT AdviseItemSink(
        [in] ITfLangBarItemSink *punk, 
        [out] DWORD *pdwCookie, 
        [in] REFGUID rguidItem);

    HRESULT UnadviseItemSink(
        [in] DWORD dwCookie);

    HRESULT GetItemFloatingRect(
        [in] DWORD dwThreadId,
        [in] REFGUID rguid,
        [out] RECT *prc);

    HRESULT GetItemsStatus(
        [in] ULONG ulCount,
        [in, size_is(ulCount)] const GUID *prgguid,
        [out, size_is(ulCount)] DWORD *pdwStatus);

    HRESULT GetItemNum(
        [out] ULONG *pulCount);

    HRESULT GetItems(
        [in] ULONG ulCount, 
        [out, size_is(ulCount), length_is(*pcFetched)] ITfLangBarItem **ppItem, 
        [out, size_is(ulCount), length_is(*pcFetched)] TF_LANGBARITEMINFO *pInfo,
        [out, size_is(ulCount), length_is(*pcFetched)] DWORD *pdwStatus,
        [in, out, unique] ULONG *pcFetched);

    HRESULT AdviseItemsSink(
        [in] ULONG ulCount,
        [in, size_is(ulCount)] ITfLangBarItemSink **ppunk, 
        [in, size_is(ulCount)] const GUID *pguidItem,
        [out, size_is(ulCount)] DWORD *pdwCookie);

    HRESULT UnadviseItemsSink(
        [in] ULONG ulCount,
        [in, size_is(ulCount)] DWORD *pdwCookie);
}

[
  object,
  uuid(583f34d0-de25-11d2-afdd-00105a2799b5),
  pointer_default(unique)
]
interface IEnumTfLangBarItems : IUnknown
{
    HRESULT Clone(
        [out] IEnumTfLangBarItems **ppEnum);

    HRESULT Next(
        [in] ULONG ulCount, 
        [out, size_is(ulCount)] ITfLangBarItem **ppItem, 
        [in, out, unique] ULONG *pcFetched);

    HRESULT Reset();

    HRESULT Skip(
        [in] ULONG ulCount);
}

[
  object,
  uuid(73540d69-edeb-4ee9-96c9-23aa30b25916),
  pointer_default(unique)
]
interface ITfLangBarItem : IUnknown
{
    HRESULT GetInfo(
        [out] TF_LANGBARITEMINFO *pInfo);

    HRESULT GetStatus(
        [out] DWORD *pdwStatus);

    HRESULT Show(
        [in] BOOL fShow);

    HRESULT GetTooltipString(
        [out] BSTR *pbstrToolTip);
}

[
  object,
  uuid(57dbe1a0-de25-11d2-afdd-00105a2799b5),
  pointer_default(unique)
]
interface ITfLangBarItemSink : IUnknown
{
    HRESULT OnUpdate(
        [in] DWORD dwFlags);
}

[
  object,
  uuid(01c2d285-d3c7-4b7b-b5b5-d97411d0c283),
  pointer_default(unique)
]
interface ITfLangBarItemBalloon : IUnknown
{
    HRESULT OnClick(
        [in] TfLBIClick click,
        [in] POINT      pt,
        [in] const RECT *prcArea);

    HRESULT GetPreferredSize(
        [in]  const SIZE *pszDefault,
        [out] SIZE       *psz);

    typedef enum
    {
        TF_LB_BALLOON_RECO = 0,
        TF_LB_BALLOON_SHOW = 1,
        TF_LB_BALLOON_MISS = 2
    } TfLBBalloonStyle;

    typedef struct TF_LBBALLOONINFO
    {
        TfLBBalloonStyle style;
        BSTR             bstrText;
    } TF_LBBALLOONINFO;

    HRESULT GetBalloonInfo(
        [out] TF_LBBALLOONINFO *pInfo);
}

[
  object,
  uuid(73830352-d722-4179-ada5-f045c98df355),
  pointer_default(unique)
]
interface ITfLangBarItemBitmap : IUnknown
{
    HRESULT OnClick(
        [in] TfLBIClick click,
        [in] POINT      pt,
        [in] const RECT *prcArea);

    HRESULT GetPreferredSize(
        [in]  const SIZE *pszDefault,
        [out] SIZE       *psz);

    HRESULT DrawBitmap(
        [in]  LONG    bmWidth,
        [in]  LONG    bmHeight,
        [in]  DWORD   dwFlags,
        [out] HBITMAP *phbmp,
        [out] HBITMAP *phbmpMask);
}

[
  object,
  uuid(a26a0525-3fae-4fa0-89ee-88a964f9f1b5),
  pointer_default(unique)
]
interface ITfLangBarItemBitmapButton : IUnknown
{
    HRESULT OnClick(
        [in] TfLBIClick click,
        [in] POINT      pt,
        [in] const RECT *prcArea);

    HRESULT InitMenu(
        [in] ITfMenu *pMenu);

    HRESULT OnMenuSelect(
        [in] UINT wID);

    HRESULT GetPreferredSize(
        [in]  const SIZE *pszDefault,
        [out] SIZE       *psz);

    HRESULT DrawBitmap(
        [in]  LONG    bmWidth,
        [in]  LONG    bmHeight,
        [in]  DWORD   dwFlags,
        [out] HBITMAP *phbmp,
        [out] HBITMAP *phbmpMask);

    HRESULT GetText(
        [out] BSTR *pbstrText);
}

[
  object,
  uuid(28c7f1d0-de25-11d2-afdd-00105a2799b5),
  pointer_default(unique)
]
interface ITfLangBarItemButton : IUnknown
{
    HRESULT OnClick(
        [in] TfLBIClick click,
        [in] POINT      pt,
        [in] const RECT *prcArea);

    HRESULT InitMenu(
        [in] ITfMenu *pMenu);

    HRESULT OnMenuSelect(
        [in] UINT wID);

    HRESULT GetIcon(
        [out] HICON *phIcon);

    HRESULT GetText(
        [out] BSTR *pbstrText);
}

[
  object,
  uuid(6f8a98e4-aaa0-4f15-8c5b-07e0df0a3dd8),
  pointer_default(unique)
]
interface ITfMenu : IUnknown
{
    const DWORD TF_LBMENUF_CHECKED      = 0x00000001;
    const DWORD TF_LBMENUF_SUBMENU      = 0x00000002;
    const DWORD TF_LBMENUF_SEPARATOR    = 0x00000004;
    const DWORD TF_LBMENUF_RADIOCHECKED = 0x00000008;
    const DWORD TF_LBMENUF_GRAYED       = 0x00000010;

    HRESULT AddMenuItem(
        [in] UINT        uId,
        [in] DWORD       dwFlags,
        [in] HBITMAP     hbmp,
        [in] HBITMAP     hbmpMask,
        [in] const WCHAR *pch,
        [in] ULONG       cch,
             ITfMenu     **ppMenu);
}

[
  object,
  uuid(45672eb9-9059-46a2-838d-4530355f6a77),
  pointer_default(unique)
]
interface ITfSystemDeviceTypeLangBarItem : IUnknown
{
    HRESULT SetIconMode(
        [in] DWORD dwFlags);

    HRESULT GetIconMode(
        [out] DWORD *pdwFlags);
}

[
  object,
  uuid(1e13e9ec-6b33-4d4a-b5eb-8a92f029f356),
  pointer_default(unique)
]
interface ITfSystemLangBarItem : IUnknown
{
    HRESULT SetIcon(
        [in] HICON hIcon);

    HRESULT SetTooltipString(
        [in] WCHAR *pchToolTip,
        [in] ULONG cch);
}

[
  object,
  uuid(1449d9ab-13cf-4687-aa3e-8d8b18574396),
  pointer_default(unique)
]
interface ITfSystemLangBarItemSink : IUnknown
{
    HRESULT InitMenu(
        [in] ITfMenu *pMenu);

    HRESULT OnMenuSelect(
        [in] UINT wID);
}

[
  object,
  uuid(5c4ce0e5-ba49-4b52-ac6b-3b397b4f701f),
  pointer_default(unique)
]
interface ITfSystemLangBarItemText : IUnknown
{
    HRESULT SetItemText(
        [in] const WCHAR *pch,
        [in] ULONG       cch);

    HRESULT GetItemText(
        [out] BSTR *pbstrText);
}
