123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733 |
- #include "./navigation.h"
- #include "./ml.h"
- #include "./ml_ipc_0313.h"
- #include "../nu/AutoChar.h"
- #include "../nu/AutoWide.h"
- #include "./skinning.h"
- #include "./stockobjects.h"
- #include "../winamp/wa_dlg.h"
- #include "../winamp/gen.h"
- #include "resource.h"
- #include "api__gen_ml.h"
- #include "../nu/CGlobalAtom.h"
- #include "../nu/trace.h"
- #include <windowsx.h>
- #include <strsafe.h>
- extern "C" winampGeneralPurposePlugin plugin;
- #ifndef LONGX86
- #ifdef _WIN64
- #define LONGX86 LONG_PTR
- #else /*_WIN64*/
- #define LONGX86 LONG
- #endif /*_WIN64*/
- #endif // LONGX86
- #define PACKVERSION(major,minor) MAKELONG(minor,major)
- #define SEPARATOR L'/'
- #define MLV_PREFIX_A L"mlv10_"
- #define EMPTY_ITEM_NAME L"<<empty>>"
- #define ITEM_SHORTNAME_MAX 512
- #define SAVEVIEW_BUFFER_MAX 1024
- #define ML_VIEW_MAX 32
- #define NAVITEM_RANGE_MIN 8000
- static CGlobalAtom NAVMGR_HWNDPROPW(L"NAVMNGR");
- static CGlobalAtom WNDPROP_SCCTRLW(L"SCCTRL");
- #define IREC_COUNT 3
- #define IREC_NORMAL 0x00
- #define IREC_SELECTED 0x01
- #define IREC_INACTIVE 0x02
- #define DRAGIMAGE_OFFSET_X 8
- #define DRAGIMAGE_OFFSET_Y 0
- typedef struct _SCEDIT
- {
- WNDPROC fnOldProc;
- BOOL fUnicode;
- }SCEDIT;
- typedef struct _SCTREE
- {
- WNDPROC fnOldProc;
- BOOL fUnicode;
- DWORD focused;
- BOOL supressEdit;
- }SCTREE;
- typedef struct _NAVITEMSTATEREC
- {
- LPWSTR pszFullName;
- INT fCollapsed;
- INT nOrder;
- } NAVITEMSTATEREC;
- typedef struct _NAVMNGR
- {
- HWND hwndHost;
- INT lastUsedId;
- C_Config *pConfig;
- HMLIMGLST hmlilImages;
- INT lockUpdate;
- HTREEITEM lockFirst;
- HTREEITEM lockSelected;
- INT lockSelPos;
- INT lastOrderIndex;
- NAVITEMSTATEREC *pStates;
- INT statesCount;
- UINT style;
- NAVITEMDRAW_I drawStruct;
- HFONT hfontOld;
- UINT drawInternal;
- // callbacks
- ONNAVITEMCLICK_I fnOnItemClick;
- ONNAVITEMSELECTED_I fnOnItemSelected;
- ONNAVCTRLKEYDOWN_I fnOnKeyDown;
- ONNAVCTRLBEGINDRAG_I fnOnBeginDrag;
- ONNAVITEMGETIMAGEINDEX_I fnOnItemGetImageIndex;
- ONNAVITEMBEGINTITLEEDIT_I fnOnBeginTitleEdit;
- ONNAVCTRLENDTITLEEDIT_I fnOnEndTitleEdit;
- ONNAVITEMDELETE_I fnOnItemDelete;
- ONNAVITEMDRAW_I fnOnCustomDraw;
- ONNAVITEMSETCURSOR_I fnOnSetCursor;
- ONNAVITEMHITTEST_I fnOnHitTest;
- ONNAVCTRLDESTROY_I fnOnDestroy;
- } NAVMNGR, *PNAVMNGR;
- typedef struct _NAVITM
- {
- INT id;
- INT iImage;
- INT iSelectedImage;
- WORD sortOrder;
- UINT style;
- HWND hwndTree;
- HTREEITEM hTreeItem;
- LPWSTR pszText;
- INT cchTextMax;
- LPWSTR pszInvariant;
- INT cchInvariantMax;
- HFONT hFont;
- BOOL fBlockInvalid; // if set to TRUE operation do not need to inavlidate item it will be invalidated later;
- LPARAM lParam;
- } NAVITM, *PNAVITM;
- typedef struct _TREEITEMSEARCH
- {
- TVITEMEXW item;
- INT_PTR itemData;
- BOOL fFound;
- UINT flags;
- } TREEITEMSEARCH;
- typedef struct _SAVEVIEWDATA
- {
- TVITEMEXW item;
- WCHAR buffer[SAVEVIEW_BUFFER_MAX];
- WCHAR mlview[ML_VIEW_MAX];
- C_Config *pConfig;
- INT counter_root;
- INT counter_write;
- }SAVEVIEWDATA;
- typedef struct _NAVENUMSTRUCT
- {
- TVITEMW item;
- NAVENUMPROC_I callback;
- LPARAM lParam;
- HNAVCTRL hNav;
- } NAVENUMSTRUCT;
- typedef BOOL (CALLBACK *TREEITEMCB)(HWND, HTREEITEM, LPVOID);
- #define ABS(x) (((x) > 0) ? (x) : (-x))
- #define NAVSTYLE_DEFAULT 0x0000
- #define NAVSTYLE_MOUSEDOWNSELECT 0x0001
- #define NAVSTYLE_FOCUSED 0x0002
- #define NAVSTYLE_EDITMODE 0x0004
- // helpers
- static BOOL GetItemColors(HNAVCTRL hNav, UINT itemState, COLORREF *rgbBk, COLORREF *rgbFg)
- {
- INT rgbBkIndex, rgbFgIndex;
- switch(itemState)
- {
- case (NIS_SELECTED_I | NIS_FOCUSED_I): rgbBkIndex = WADLG_SELBAR_BGCOLOR; rgbFgIndex = WADLG_SELBAR_FGCOLOR; break;
- case NIS_SELECTED_I: rgbBkIndex = WADLG_INACT_SELBAR_BGCOLOR; rgbFgIndex = WADLG_INACT_SELBAR_FGCOLOR; break;
- case NIS_DROPHILITED_I: rgbBkIndex = WADLG_INACT_SELBAR_BGCOLOR; rgbFgIndex = WADLG_INACT_SELBAR_FGCOLOR; break;
- default: rgbBkIndex = WADLG_ITEMBG; rgbFgIndex = WADLG_ITEMFG; break;
- }
- if (rgbBk) *rgbBk = WADlg_getColor(rgbBkIndex);
- if (rgbFg) *rgbFg = WADlg_getColor(rgbFgIndex);
- return TRUE;
- }
- static BOOL EnumerateTreeItems(HWND hwndTree, HTREEITEM hStart, TREEITEMCB pfnItemCallback, LPVOID user)
- {
- HTREEITEM hChild;
- if (!pfnItemCallback) return FALSE;
-
- if (NULL == hStart || TVI_ROOT == hStart)
- hStart = (HTREEITEM)SendMessageW(hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_ROOT, (LPARAM)0);
- while(NULL != hStart)
- {
- if (!pfnItemCallback(hwndTree, hStart, user))
- return FALSE;
- hChild = (HTREEITEM)SendMessageW(hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)hStart);
- if (NULL != hChild)
- {
- if (!EnumerateTreeItems(hwndTree, hChild, pfnItemCallback, user))
- return FALSE;
- }
- hStart = (HTREEITEM)SendMessageW(hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)hStart);
- }
- return TRUE;
- }
- static BOOL CALLBACK FindTreeItemByIdCB(HWND hwndTree, HTREEITEM hItem, LPVOID user)
- {
- if (!user) return FALSE;
- ((TREEITEMSEARCH*)user)->item.hItem = hItem;
- if ((BOOL)SendMessageW(hwndTree, TVM_GETITEMW, (WPARAM)0, (LPARAM)&((TREEITEMSEARCH*)user)->item))
- {
- if (((TREEITEMSEARCH*)user)->item.lParam &&
- (INT)((TREEITEMSEARCH*)user)->itemData == ((NAVITM*)((TREEITEMSEARCH*)user)->item.lParam)->id)
- {
- ((TREEITEMSEARCH*)user)->fFound = TRUE;
- return FALSE;
- }
- }
- return TRUE;
- }
- static INT CompareItemName(LCID Locale, UINT compFlags, LPCWSTR pszString, INT cchLength, HNAVITEM hItem)
- {
- INT result;
- if (!hItem || !pszString) return 0; // error
- if (NICF_INVARIANT_I & compFlags)
- {
- result = (((NAVITM*)hItem)->pszInvariant) ?
- CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, ((NAVITM*)hItem)->pszInvariant, -1, pszString, cchLength) :
- CSTR_LESS_THAN;
- if (CSTR_EQUAL == result) return CSTR_EQUAL;
- }
- if (NICF_DISPLAY_I & compFlags || 0 == (compFlags & ~NICF_IGNORECASE_I))
- {
- result = (((NAVITM*)hItem)->pszText) ?
- CompareStringW(Locale, (NICF_IGNORECASE_I & compFlags) ? NORM_IGNORECASE : 0, ((NAVITM*)hItem)->pszText, -1, pszString, cchLength) :
- CSTR_LESS_THAN;
- }
- return result;
- }
- static BOOL CALLBACK FindTreeItemByNameCB(HWND hwndTree, HTREEITEM hItem, LPVOID user)
- {
- if (!user) return FALSE;
- ((TREEITEMSEARCH*)user)->item.hItem = hItem;
- if ((BOOL)SendMessageW(hwndTree, TVM_GETITEMW, (WPARAM)0, (LPARAM)&((TREEITEMSEARCH*)user)->item))
- {
- if (CSTR_EQUAL == CompareItemName(((TREEITEMSEARCH*)user)->item.state, ((TREEITEMSEARCH*)user)->flags,
- (LPCWSTR)((TREEITEMSEARCH*)user)->itemData, ((TREEITEMSEARCH*)user)->item.cchTextMax,
- (NAVITM*)((TREEITEMSEARCH*)user)->item.lParam))
- {
- ((TREEITEMSEARCH*)user)->fFound = TRUE;
- return FALSE;
- }
- }
- return TRUE;
- }
- static BOOL CALLBACK ItemSizedCB(HWND hwndTree, HTREEITEM hItem, LPVOID user)
- {
- ((TVITEMW*)user)->hItem = hItem;
- if (!SendMessageW(hwndTree, TVM_GETITEMW, (WPARAM)0, (LPARAM)user)) return FALSE;
- if (((TVITEMW*)user)->lParam)
- {
- if (NIS_CUSTOMDRAW_I & ((NAVITM*)((TVITEMW*)user)->lParam)->style)
- {
- *(HTREEITEM*)((TVITEMW*)user)->pszText = hItem;
- if (SendMessageW(hwndTree, TVM_GETITEMRECT, FALSE, (LPARAM)((TVITEMW*)user)->pszText))
- {
- InvalidateRect(hwndTree, (RECT*)((TVITEMW*)user)->pszText, TRUE);
- }
- }
- }
- return TRUE;
- }
- static HNAVITEM FindNavItemByNavIdEx(HWND hwndTree, INT itemId, HTREEITEM hStart)
- {
- TREEITEMSEARCH search;
- search.fFound = FALSE;
- search.itemData = (INT_PTR)itemId;
- search.item.mask = TVIF_PARAM;
- search.flags = 0;
- EnumerateTreeItems(hwndTree, hStart, FindTreeItemByIdCB, &search);
- return (search.fFound) ? (HNAVITEM)search.item.lParam : NULL;
- }
- static INT GetNextFreeItemId(HNAVCTRL hNav)
- {
- if (!hNav) return 0;
- while (FindNavItemByNavIdEx(((NAVMNGR*)hNav)->hwndHost, ++((NAVMNGR*)hNav)->lastUsedId, TVI_ROOT));
- return ((NAVMNGR*)hNav)->lastUsedId;
- }
- static INT GetRealImageIndex(HNAVCTRL hNav, HNAVITEM hItem, INT imageType, COLORREF rgbBk, COLORREF rgbFg)
- {
- INT mlilIndex;
- if (!hNav) return -1;
- mlilIndex = NavItemI_GetImageIndex(hItem, imageType);
- if (-1 == mlilIndex )
- {
- if (((NAVMNGR*)hNav)->fnOnItemGetImageIndex) mlilIndex = ((NAVMNGR*)hNav)->fnOnItemGetImageIndex(hNav, hItem, imageType);
- if (-1 == mlilIndex) return -1;
- }
- return MLImageListI_GetRealIndex(((NAVMNGR*)hNav)->hmlilImages, mlilIndex, rgbBk, rgbFg);
- }
- static BOOL CALLBACK EnumNavItemCB(HWND hwndTree, HTREEITEM hItem, LPVOID user)
- {
- NAVENUMSTRUCT *pData;
- if (!user) return FALSE;
- pData = (NAVENUMSTRUCT*)user;
- pData->item.hItem = hItem;
- return (BOOL)SendMessageW(hwndTree, TVM_GETITEMW, (WPARAM)0, (LPARAM)&(pData->item)) ?
- pData->callback((HNAVITEM)pData->item.lParam, pData->lParam) : TRUE;
- }
- static BOOL CALLBACK SaveNavigationCB(HWND hwndTree, HTREEITEM hItem, LPVOID user)
- {
- if (!user) return FALSE; // very bad
- ((SAVEVIEWDATA*)user)->item.hItem = hItem;
- if ((BOOL)SendMessageW(hwndTree, TVM_GETITEMW, (WPARAM)0, (LPARAM)&((SAVEVIEWDATA*)user)->item))
- {
- INT order;
- BOOL bCollapsed = (SendMessageW(hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)hItem) && !(TVIS_EXPANDED & ((SAVEVIEWDATA*)user)->item.state));
- if (!SendMessageW(hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_PARENT, (LPARAM)hItem))
- {
- order = ++((SAVEVIEWDATA*)user)->counter_root;
- }
- else order = -1;
- if (order != -1 || bCollapsed || (TVIS_SELECTED & ((SAVEVIEWDATA*)user)->item.state))
- {
- INT remain = NavItemI_GetFullName((HNAVITEM)((SAVEVIEWDATA*)user)->item.lParam, ((SAVEVIEWDATA*)user)->buffer, SAVEVIEW_BUFFER_MAX);
- if (remain)
- {
- if ((order != -1 || bCollapsed) && remain < (SAVEVIEW_BUFFER_MAX - 8) )
- {
- if (S_OK == StringCchPrintfW(((SAVEVIEWDATA*)user)->buffer + remain, SAVEVIEW_BUFFER_MAX - remain, L",%d,%d", bCollapsed, order) &&
- S_OK == StringCchPrintfW(((SAVEVIEWDATA*)user)->mlview, ML_VIEW_MAX, MLV_PREFIX_A L"%02d", (((SAVEVIEWDATA*)user)->counter_write + 1)))
- {
- ((SAVEVIEWDATA*)user)->pConfig->WriteString(((SAVEVIEWDATA*)user)->mlview, ((SAVEVIEWDATA*)user)->buffer);
- ((SAVEVIEWDATA*)user)->counter_write++;
- }
- }
- }
- }
- }
- return TRUE;
- }
- static HNAVITEM GetNavItemFromTreeItem(HNAVCTRL hNav, HTREEITEM hTreeItem)
- {
- TVITEMW item;
- item.mask = TVIF_PARAM;
- item.hItem = hTreeItem;
- if (!hNav) return NULL;
- if (!SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETITEMW, (WPARAM)0, (LPARAM)&item)) return NULL;
- return (HNAVITEM)item.lParam;
- }
- static HNAVITEM NavItemI_GetNextEx(HNAVITEM hItem, UINT flag) // use TVGN_ as flags
- {
- TVITEMW treeItem;
- if (!hItem) return NULL;
- treeItem.hItem = (HTREEITEM)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETNEXTITEM, (WPARAM)flag, (LPARAM)((NAVITM*)hItem)->hTreeItem);
- if (!treeItem.hItem) return NULL;
- treeItem.mask = TVIF_PARAM;
- return (SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETITEMW, (WPARAM)0, (LPARAM)&treeItem)) ? (HNAVITEM)treeItem.lParam : NULL;
- }
- static void PerformCustomHitTest(HNAVCTRL hNav, POINT pt, UINT *pHitFlags, HNAVITEM *phItem) // returns nav hit test result
- {
- UINT flags, test;
- flags = 0;
- test = (pHitFlags) ? *pHitFlags : 1;
- if (TVHT_NOWHERE & test) flags |= NAVHT_NOWHERE_I;
- if (TVHT_ONITEMLABEL & test) flags |= NAVHT_ONITEM_I;
- if (TVHT_ONITEMINDENT & test) flags |= NAVHT_ONITEMINDENT_I;
- if (TVHT_ONITEMRIGHT & test) flags |= NAVHT_ONITEMRIGHT_I;
- if (TVHT_ABOVE & test) flags |= NAVHT_ABOVE_I;
- if (TVHT_BELOW & test) flags |= NAVHT_BELOW_I;
- if (TVHT_TORIGHT & test) flags |= NAVHT_TORIGHT_I;
- if (TVHT_TOLEFT & test) flags |= NAVHT_TOLEFT_I;
- if (pHitFlags) *pHitFlags = flags;
- if (hNav && phItem && *phItem && pHitFlags)
- {
- if (TVHT_ONITEMICON & test) *pHitFlags |= (SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM,
- (WPARAM)TVGN_CHILD, (LPARAM)((NAVITM*)(*phItem))->hTreeItem)) ?
- NAVHT_ONITEMBUTTON_I : NAVHT_ONITEM_I;
- if ((NIS_WANTHITTEST_I & ((NAVITM*)(*phItem))->style) && ((NAVMNGR*)hNav)->fnOnHitTest)
- {
- ((NAVMNGR*)hNav)->fnOnHitTest(hNav, pt, pHitFlags, phItem, ((NAVITM*)(*phItem))->lParam);
- }
- }
- }
- static HTREEITEM TreeItemFromCursor(HNAVCTRL hNav, HTREEITEM *phtiWantExpand)
- {
- HTREEITEM hTreeItem;
- TVHITTESTINFO hit;
- if (phtiWantExpand) *phtiWantExpand = NULL;
- if(!GetCursorPos(&hit.pt)) return NULL;
- MapWindowPoints(HWND_DESKTOP, ((NAVMNGR*)hNav)->hwndHost, &hit.pt, 1);
- hTreeItem = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_HITTEST, (WPARAM)0, (LPARAM)&hit);
- if (0 == (TVHT_ONITEM & hit.flags))
- {
- if ((TVHT_ONITEMRIGHT | TVHT_ONITEMINDENT) & hit.flags)
- {
- if (0 == (TVS_FULLROWSELECT & GetWindowLongPtrW(((NAVMNGR*)hNav)->hwndHost, GWL_STYLE))) hTreeItem = NULL;
- }
- }
- if(hTreeItem)
- {
- HNAVITEM hItem;
- hItem = GetNavItemFromTreeItem(hNav, hTreeItem);
- PerformCustomHitTest(hNav, hit.pt, &hit.flags, &hItem);
- hTreeItem = (hItem) ? ((NAVITM*)hItem)->hTreeItem : NULL;
- if (NAVHT_ONITEMBUTTON_I & hit.flags)
- {
- if (phtiWantExpand) *phtiWantExpand = hTreeItem;
- hTreeItem = NULL;
- }
- }
- return hTreeItem;
- }
- static NAVITEMSTATEREC *NavCtrlI_FindItemStateRec(HNAVCTRL hNav, HNAVITEM hItem, BOOL fClearOnSuccess)
- {
- wchar_t name[1024] = {0};
- if (!hNav || !hItem) return NULL;
- if (NavItemI_GetFullName(hItem, name, 1024))
- {
- for (INT idx = 0; idx < ((NAVMNGR*)hNav)->statesCount; idx++)
- {
- if (((NAVMNGR*)hNav)->pStates[idx].pszFullName &&
- CSTR_EQUAL == CompareStringW(LOCALE_USER_DEFAULT, 0, name, -1,
- ((NAVMNGR*)hNav)->pStates[idx].pszFullName, -1))
- {
- if (fClearOnSuccess)
- {
- free(((NAVMNGR*)hNav)->pStates[idx].pszFullName);
- ((NAVMNGR*)hNav)->pStates[idx].pszFullName = NULL;
- }
- return &((NAVMNGR*)hNav)->pStates[idx];
- }
- }
- }
- return NULL;
- }
- static LRESULT EditCtrlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- SCEDIT *pEdit;
- pEdit = (SCEDIT*)GetPropW(hwnd, WNDPROP_SCCTRLW);
- if (!pEdit) return (IsWindowUnicode(hwnd)) ? DefWindowProcW(hwnd, uMsg, wParam, lParam) : DefWindowProcA(hwnd, uMsg, wParam, lParam);
- switch(uMsg)
- {
- case WM_NCDESTROY: // detach
- RemovePropW(hwnd, WNDPROP_SCCTRLW);
- if (pEdit->fUnicode)
- {
- CallWindowProcW(pEdit->fnOldProc, hwnd, uMsg, wParam, lParam);
- SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)pEdit->fnOldProc);
- }
- else
- {
- CallWindowProcA(pEdit->fnOldProc, hwnd, uMsg, wParam, lParam);
- SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)pEdit->fnOldProc);
- }
- free(pEdit);
- return 0;
- case WM_ERASEBKGND: return 1;
- case WM_NCPAINT:
- {
- HDC hdc;
-
- hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_WINDOW | DCX_INTERSECTUPDATE | DCX_CLIPSIBLINGS);
- if (hdc)
- {
- RECT rc;
- GetClientRect(hwnd, &rc);
- FrameRect(hdc, &rc, (HBRUSH)MlStockObjects_Get(ITEMTEXT_BRUSH));
- ReleaseDC(hwnd, hdc);
- }
- return 0;
- }
- break;
- case WM_PAINT:
- {
- RECT rc, rv;
- GetClientRect(hwnd, &rc);
- SetRect(&rv, 0, 0, rc.right, 1);
- ValidateRect(hwnd, &rv);
- SetRect(&rv, 0, rc.bottom - 1, rc.right, rc.bottom);
- ValidateRect(hwnd, &rv);
- SetRect(&rv, 0, 1, 1, rc.bottom);
- ValidateRect(hwnd, &rv);
- SetRect(&rv, rc.right-1, 1, rc.right, rc.bottom);
- ValidateRect(hwnd, &rv);
- break;
- }
- case WM_GETDLGCODE:
- switch(wParam)
- {
- case VK_RETURN:
- SendMessageW(GetParent(hwnd), TVM_ENDEDITLABELNOW, FALSE, 0L); return 0; // tell trew-view that we done and return 0
- case VK_ESCAPE:
- SendMessageW(GetParent(hwnd), TVM_ENDEDITLABELNOW, TRUE, 0L); return 0; // tell trew-view that we done and return 0
- }
- break;
- case WM_SETCURSOR:
- if (HTCLIENT == LOWORD(lParam))
- {
- SetCursor(LoadCursor(NULL, IDC_IBEAM));
- return 0;
- }
- break;
- }
- return (pEdit->fUnicode) ? CallWindowProcW(pEdit->fnOldProc, hwnd, uMsg, wParam, lParam) :
- CallWindowProcA(pEdit->fnOldProc, hwnd, uMsg, wParam, lParam);
- }
- static LRESULT TreeViewWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- SCTREE *pTree;
- pTree = (SCTREE*)GetPropW(hwnd, WNDPROP_SCCTRLW);
- if (!pTree)
- return (IsWindowUnicode(hwnd)) ? DefWindowProcW(hwnd, uMsg, wParam, lParam) : DefWindowProcA(hwnd, uMsg, wParam, lParam);
-
- switch(uMsg)
- {
- case WM_NCDESTROY: // detach
- RemovePropW(hwnd, WNDPROP_SCCTRLW);
- if (pTree->fUnicode)
- {
- CallWindowProcW(pTree->fnOldProc, hwnd, uMsg, wParam, lParam);
- SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)pTree->fnOldProc);
- }
- else
- {
- CallWindowProcA(pTree->fnOldProc, hwnd, uMsg, wParam, lParam);
- SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)pTree->fnOldProc);
- }
- free(pTree);
- return 0;
- case WM_ERASEBKGND:
- if (wParam && (TVS_FULLROWSELECT & GetWindowLongPtrW(hwnd, GWL_STYLE)))
- {
- RECT rc;
- HTREEITEM hItem;
- GetClientRect(hwnd, &rc);
- hItem = (HTREEITEM)SendMessageW(hwnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
- if (hItem)
- {
- RECT ri;
- *(HTREEITEM*)&ri = hItem;
- if (SendMessageW(hwnd, TVM_GETITEMRECT, FALSE, (LPARAM)&ri)) rc.top = ri.bottom;
- }
- if (rc.top < rc.bottom)
- {
- SetBkColor((HDC)wParam, WADlg_getColor(WADLG_ITEMBG));
- ExtTextOutW((HDC)wParam, 0, 0, ETO_OPAQUE, &rc, L"", 0, 0);
- }
- return 1;
- }
- return 0;
- case WM_LBUTTONDOWN:
- case WM_RBUTTONDOWN:
- {
- TVHITTESTINFO hit;
- HNAVITEM hItem;
- NAVMNGR *pMngr;
- hit.pt.x = GET_X_LPARAM(lParam);
- hit.pt.y = GET_Y_LPARAM(lParam);
- SendMessageW(hwnd, TVM_HITTEST, (WPARAM)0, (LPARAM)&hit);
- pMngr = (NAVMNGR*)GetPropW(hwnd, NAVMGR_HWNDPROPW);
- if (hit.hItem)
- {
- hItem = GetNavItemFromTreeItem(pMngr, hit.hItem);
- PerformCustomHitTest(pMngr, hit.pt, &hit.flags, &hItem);
- if (hItem && pMngr && (NAVSTYLE_MOUSEDOWNSELECT & pMngr->style))
- {
- SendMessageW(hwnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)((NAVITM*)hItem)->hTreeItem);
- }
- }
- else
- hItem = NULL;
- if (!hItem)
- {
- SendMessageW(hwnd, TVM_ENDEDITLABELNOW, (WPARAM)TRUE, 0L);
- return 0;
- }
- else
- {
- HWND hEdit = FindWindowExW(hwnd, NULL, L"Edit", NULL);
- if (NULL != hEdit && IsWindowVisible(hEdit))
- {
- PostMessageW(hwnd, uMsg, wParam, lParam);
- }
- else
- {
- pTree->supressEdit = FALSE;
- if (0 != pTree->focused)
- {
- DWORD clicked = GetTickCount();
- if (clicked >= pTree->focused && (clicked - pTree->focused) < 200)
- pTree->supressEdit = TRUE;
-
- pTree->focused = 0;
- }
- }
- }
- }
- break;
- case WM_LBUTTONDBLCLK:
- if (TVS_FULLROWSELECT == (TVS_FULLROWSELECT & (UINT)GetWindowLongPtrW(hwnd, GWL_STYLE)))
- {
- TVHITTESTINFO test;
- test.pt.x = GET_X_LPARAM(lParam);
- test.pt.y = GET_Y_LPARAM(lParam);
- if(SendMessageW(hwnd, TVM_HITTEST, 0, (LPARAM)&test) && (TVHT_ONITEMRIGHT & test.flags))
- {
- HWND hParent;
- NMHDR hdr;
- hdr.code = NM_DBLCLK;
- hdr.hwndFrom = hwnd;
- hdr.idFrom = GetDlgCtrlID(hwnd);
- hParent = GetParent(hwnd);
- if (hParent) SendMessageW(hParent, WM_NOTIFY, hdr.idFrom, (LPARAM)&hdr);
- return 0;
- }
- }
- break;
- case WM_CTLCOLOREDIT:
- SetTextColor((HDC)wParam, WADlg_getColor(WADLG_ITEMFG));
- SetBkColor((HDC)wParam, WADlg_getColor(WADLG_ITEMBG));
- return (LRESULT)MlStockObjects_Get(ITEMBCK_BRUSH);
-
- case WM_SIZE:
- {
- TVITEMW item;
- RECT ri;
- item.mask = TVIF_PARAM;
- item.pszText = (LPWSTR)&ri;
- EnumerateTreeItems(hwnd, NULL, ItemSizedCB, &item);
- }
- break;
- case WM_CHAR:
- pTree->supressEdit = FALSE;
- return (VK_RETURN == wParam) ? 0 :
- ((pTree->fUnicode) ? CallWindowProcW(pTree->fnOldProc, hwnd, uMsg, wParam, lParam) :
- CallWindowProcA(pTree->fnOldProc, hwnd, uMsg, wParam, lParam));
- case WM_GETDLGCODE:
- {
- LRESULT r = (pTree->fUnicode) ? CallWindowProcW(pTree->fnOldProc, hwnd, uMsg, wParam, lParam) :
- CallWindowProcA(pTree->fnOldProc, hwnd, uMsg, wParam, lParam);
- if (lParam)
- {
- MSG *pMsg = (LPMSG)lParam;
- if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP)
- {
- switch(pMsg->wParam)
- {
- case VK_RETURN: r |= DLGC_WANTMESSAGE; break;
- case VK_TAB:
- case VK_ESCAPE: SendMessageW(hwnd, TVM_ENDEDITLABELNOW, TRUE, 0L); break;
- }
- }
- }
- return r;
- }
- case WM_SETFOCUS:
- pTree->focused = GetTickCount();
- break;
- case WM_TIMER:
- if (42 == wParam && FALSE != pTree->supressEdit)
- {
- KillTimer(hwnd, wParam);
- pTree->supressEdit = FALSE;
- return 0;
- }
- break;
- }
- return (pTree->fUnicode) ? CallWindowProcW(pTree->fnOldProc, hwnd, uMsg, wParam, lParam) :
- CallWindowProcA(pTree->fnOldProc, hwnd, uMsg, wParam, lParam);
- }
- static BOOL SubclassEditControl(HWND hwndEdit)
- {
- if (!hwndEdit || !IsWindow(hwndEdit)) return FALSE;
- SCEDIT *pEdit = (SCEDIT*)calloc(1, sizeof(SCEDIT));
- if (!pEdit) return FALSE;
- pEdit->fUnicode = IsWindowUnicode(hwndEdit);
- pEdit->fnOldProc = (WNDPROC)(LONG_PTR)((pEdit->fUnicode) ? SetWindowLongPtrW(hwndEdit, GWLP_WNDPROC, (LONGX86)(LONG_PTR)EditCtrlWndProc) :
- SetWindowLongPtrA(hwndEdit, GWLP_WNDPROC, (LONGX86)(LONG_PTR)EditCtrlWndProc));
- if (!pEdit->fnOldProc || !SetPropW(hwndEdit, WNDPROP_SCCTRLW, pEdit))
- {
- if (pEdit->fnOldProc)
- {
- if (pEdit->fUnicode) SetWindowLongPtrW(hwndEdit, GWLP_WNDPROC, (LONGX86)(LONG_PTR)pEdit->fnOldProc);
- else SetWindowLongPtrA(hwndEdit, GWLP_WNDPROC, (LONGX86)(LONG_PTR)pEdit->fnOldProc);
- }
- free(pEdit);
- return FALSE;
- }
- return TRUE;
- }
- static BOOL SubclassTreeView(HWND hwndTree)
- {
- if (!hwndTree || !IsWindow(hwndTree)) return FALSE;
- SCTREE *pTree = (SCTREE*)calloc(1, sizeof(SCTREE));
- if (!pTree) return FALSE;
- pTree->fUnicode = IsWindowUnicode(hwndTree);
- pTree->fnOldProc = (WNDPROC)(LONG_PTR)((pTree->fUnicode) ? SetWindowLongPtrW(hwndTree, GWLP_WNDPROC, (LONGX86)(LONG_PTR)TreeViewWndProc) :
- SetWindowLongPtrA(hwndTree, GWLP_WNDPROC, (LONGX86)(LONG_PTR)TreeViewWndProc));
- if (!pTree->fnOldProc || !SetPropW(hwndTree, WNDPROP_SCCTRLW, pTree))
- {
- if (pTree->fnOldProc)
- {
- if (pTree->fUnicode) SetWindowLongPtrW(hwndTree, GWLP_WNDPROC, (LONGX86)(LONG_PTR)pTree->fnOldProc);
- else SetWindowLongPtrA(hwndTree, GWLP_WNDPROC, (LONGX86)(LONG_PTR)pTree->fnOldProc);
- }
- free(pTree);
- return FALSE;
- }
- return TRUE;
- }
- static BOOL NavCtrlI_SaveStates(HNAVCTRL hNav)
- {
- BOOL result;
- SAVEVIEWDATA save;
- if (!hNav || !((NAVMNGR*)hNav)->pConfig) return FALSE;
- save.item.mask = TVIF_STATE | TVIF_PARAM;
- save.item.stateMask = TVIS_EXPANDED | TVIS_SELECTED;
- save.pConfig = ((NAVMNGR*)hNav)->pConfig;
- save.counter_root = 0;
- save.counter_write = 0;
- result = EnumerateTreeItems(((NAVMNGR*)hNav)->hwndHost, TVI_ROOT, SaveNavigationCB, &save);
- if (!result) save.counter_write = 0;
- ((NAVMNGR*)hNav)->pConfig->WriteInt(MLV_PREFIX_A L"count", save.counter_write);
- return result;
- }
- static BOOL NavCtrlI_DeleteStates(HNAVCTRL hNav)
- {
- if (!hNav) return FALSE;
- if (((NAVMNGR*)hNav)->pStates)
- {
- INT i;
- for (i =0; i < ((NAVMNGR*)hNav)->statesCount; i++)
- {
- if (((NAVMNGR*)hNav)->pStates[i].pszFullName) free(((NAVMNGR*)hNav)->pStates[i].pszFullName);
- }
- free(((NAVMNGR*)hNav)->pStates);
- ((NAVMNGR*)hNav)->pStates = NULL;
- }
- ((NAVMNGR*)hNav)->statesCount = 0;
- return TRUE;
- }
- static BOOL NavCtrlI_LoadStates(HNAVCTRL hNav)
- {
- INT index, count, len;
- wchar_t mlview[ML_VIEW_MAX] = {0};
- const wchar_t *data;
- if (!hNav || !((NAVMNGR*)hNav)->pConfig) return FALSE;
- if (!NavCtrlI_DeleteStates(hNav)) return FALSE;
- count = ((NAVMNGR*)hNav)->pConfig->ReadInt(MLV_PREFIX_A L"count", 0);
- if (count < 1) return TRUE;
- ((NAVMNGR*)hNav)->pStates = (NAVITEMSTATEREC*)calloc(count, sizeof(NAVITEMSTATEREC));
- if (!((NAVMNGR*)hNav)->pStates) return FALSE;
- for (index = 0; index < count; index++)
- {
- StringCchPrintfW(mlview, ML_VIEW_MAX, MLV_PREFIX_A L"%02d", index + 1);
- //AutoWide aw(((NAVMNGR*)hNav)->pConfig->ReadString(mlview, ""), CP_UTF8);
- data = ((NAVMNGR*)hNav)->pConfig->ReadString(mlview, L"");//(LPCWSTR)aw;
- if (data && *data)
- {
- len = lstrlenW(data);
- if (len > 4 && len < 4096)
- {
- while (len > 0 && data[len-1] != L',') len--;
- if (len)
- {
- ((NAVMNGR*)hNav)->pStates[index].nOrder = _wtoi(&data[len]);
- len--;
- while (len > 0 && data[len-1] != L',')len--;
- if (len) ((NAVMNGR*)hNav)->pStates[index].fCollapsed = ( 0 != _wtoi(&data[len]));
- if (len > 1)
- {
- ((NAVMNGR*)hNav)->pStates[index].pszFullName = (LPWSTR)calloc(len, sizeof(wchar_t));
- if (!((NAVMNGR*)hNav)->pStates[index].pszFullName) continue;
- if (S_OK == StringCchCopyNW(((NAVMNGR*)hNav)->pStates[index].pszFullName, len, data, len -1))
- {
- ((NAVMNGR*)hNav)->statesCount++;
- }
- }
- }
- }
- }
- }
- ((NAVMNGR*)hNav)->lastOrderIndex = ((NAVMNGR*)hNav)->statesCount;
- return (count == ((NAVMNGR*)hNav)->statesCount);
- }
- static BOOL OnNavTree_Click(HNAVCTRL hNav, INT actionId, LRESULT *pResult)
- {
- if (hNav && ((NAVMNGR*)hNav)->fnOnItemClick)
- {
- HTREEITEM hTreeItem, hTreeExpand = 0;
- if (ACTION_ENTER_I == actionId)
- {
- hTreeExpand = hTreeItem = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_CARET, (LPARAM)0L);
- }
- else
- {
- hTreeItem = TreeItemFromCursor(hNav, &hTreeExpand);
- }
- if (hTreeExpand || ((ACTION_DBLCLICKL_I == actionId) && hTreeItem && !hTreeExpand))
- {
- if (ACTION_CLICKL_I == actionId || (ACTION_DBLCLICKL_I == actionId && hTreeItem && !hTreeExpand))
- {
- if (ACTION_DBLCLICKL_I == actionId) hTreeExpand = hTreeItem;
- hTreeItem = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_CARET, (LPARAM)0L);
- while (hTreeItem)
- {
- hTreeItem = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_PARENT, (LPARAM)hTreeItem);
- if (hTreeItem == hTreeExpand) break;
- }
- if (hTreeItem == hTreeExpand &&
- (TVIS_EXPANDED == (TVIS_EXPANDED & SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETITEMSTATE, (WPARAM)hTreeExpand, (LPARAM)TVIS_EXPANDED))))
- {
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SELECTITEM, (WPARAM)TVGN_CARET, (LPARAM)hTreeExpand);
- }
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_EXPAND, (WPARAM)TVE_TOGGLE, (LPARAM)hTreeExpand);
- InvalidateRect(((NAVMNGR*)hNav)->hwndHost, NULL, TRUE);
- if (ACTION_DBLCLICKL_I == actionId)
- {
- HNAVITEM hItem;
- hItem = GetNavItemFromTreeItem(hNav, hTreeExpand);
- if (hItem) ((NAVMNGR*)hNav)->fnOnItemClick(hNav, hItem, actionId);
- }
- *pResult = TRUE;
- return (NULL == hTreeItem);
- }
- else if (ACTION_DBLCLICKL_I != actionId) hTreeItem = hTreeExpand;
- }
- if (hTreeItem)
- {
- HNAVITEM hItem;
- hItem = GetNavItemFromTreeItem(hNav, hTreeItem);
- if (hItem)
- {
- *pResult = ((NAVMNGR*)hNav)->fnOnItemClick(hNav, hItem, actionId);
- return (BOOL)*pResult;
- }
- return FALSE;
- }
- }
- return FALSE;
- }
- static BOOL OnTV_DeleteItem(HNAVCTRL hNav, TVITEMW *pItem)
- {
- if (pItem->lParam)
- {
- if (((NAVMNGR*)hNav)->fnOnItemDelete) ((NAVMNGR*)hNav)->fnOnItemDelete(hNav, (HNAVITEM)pItem->lParam);
- NavItemI_SetText((HNAVITEM)pItem->lParam, NULL);
- NavItemI_SetInvariantText((HNAVITEM)pItem->lParam, NULL);
- free((NAVITM*)pItem->lParam);
- }
- return FALSE;
- }
- static BOOL OnTV_CustomDraw(HNAVCTRL hNav, NMTVCUSTOMDRAW *cd, LRESULT *pResult)
- {
- NAVMNGR *manager;
- manager = (NAVMNGR*)hNav;
- *pResult = CDRF_DODEFAULT;
- switch (cd->nmcd.dwDrawStage)
- {
- case CDDS_PREPAINT:
- manager->drawStruct.hdc = cd->nmcd.hdc;
- manager->drawInternal = 0;
- if ((TVS_FULLROWSELECT & GetWindowLongPtrW(manager->hwndHost, GWL_STYLE))) manager->drawInternal |= 0x0001;
- if (0x8000 & GetAsyncKeyState( GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON)) manager->drawInternal |= 0x0010;
- *pResult = CDRF_NOTIFYITEMDRAW;
- break;
- case CDDS_ITEMPREPAINT:
- manager->drawStruct.drawStage = NIDS_PREPAINT_I;
- manager->drawStruct.prc = &cd->nmcd.rc;
- manager->drawStruct.iLevel = cd->iLevel;
- if (CDIS_SELECTED & cd->nmcd.uItemState)
- {
- manager->drawStruct.itemState = NIS_SELECTED_I;
-
- if (0 != (CDIS_FOCUS & cd->nmcd.uItemState) ||
- 0 != (NAVSTYLE_FOCUSED & manager->style))
- {
- manager->drawStruct.itemState |= NIS_FOCUSED_I;
- }
- }
- else
- {
- HTREEITEM hTreeItem;
- manager->drawStruct.itemState = NIS_NORMAL_I;
- if (0x0010 & manager->drawInternal) TreeItemFromCursor(hNav, &hTreeItem);
- else hTreeItem = NULL;
- if (!hTreeItem)
- {
- UINT state;
- state = (UINT)SendMessageW(cd->nmcd.hdr.hwndFrom, TVM_GETITEMSTATE,
- (WPARAM)cd->nmcd.dwItemSpec, TVIS_DROPHILITED);
- if (TVIS_DROPHILITED & state)
- manager->drawStruct.itemState = NIS_DROPHILITED_I;
- }
- }
- GetItemColors(hNav, manager->drawStruct.itemState, &cd->clrTextBk, &cd->clrText);
- if (0 == (0x0001 & manager->drawInternal))
- {
- COLORREF rgbBk, rgbFg;
- GetItemColors(hNav, NIS_NORMAL_I, &rgbBk, &rgbFg);
- SetBkColor(cd->nmcd.hdc, rgbBk);
- SetTextColor(cd->nmcd.hdc, rgbFg);
- }
- else
- {
- SetBkColor(cd->nmcd.hdc, cd->clrTextBk);
- SetTextColor(cd->nmcd.hdc, cd->clrText);
- }
- if (cd->nmcd.lItemlParam)
- {
- NAVITM *pItem;
- pItem = ((NAVITM*)cd->nmcd.lItemlParam);
- if (pItem->hFont) manager->drawStruct.hFont = pItem->hFont;
- else if ((NIS_BOLD_I | NIS_ITALIC_I | NIS_UNDERLINE_I) & pItem->style)
- {
- LOGFONTW lf = { 0 };
- manager->drawStruct.hFont = (HFONT)::SendMessageW(cd->nmcd.hdr.hwndFrom, WM_GETFONT, 0, 0);
- GetObjectW(manager->drawStruct.hFont, sizeof(LOGFONTW), &lf);
- if (NIS_BOLD_I & pItem->style) lf.lfWeight = FW_BOLD;
- if (NIS_ITALIC_I & pItem->style) lf.lfItalic = TRUE;
- if (NIS_UNDERLINE_I & pItem->style) lf.lfUnderline = TRUE;
- manager->drawStruct.hFont = CreateFontIndirectW(&lf);
- }
- else manager->drawStruct.hFont = NULL;
- if (manager->drawStruct.hFont)
- {
- manager->hfontOld = (HFONT)SelectObject(cd->nmcd.hdc, manager->drawStruct.hFont);
- *pResult |= CDRF_NEWFONT;
- if (pItem->hFont != manager->drawStruct.hFont) *pResult |= CDRF_NOTIFYPOSTPAINT;
- }
- if((NIS_CUSTOMDRAW_I & pItem->style) && manager->fnOnCustomDraw)
- {
- INT result;
- manager->drawStruct.clrTextBk = cd->clrTextBk;
- manager->drawStruct.clrText = cd->clrText;
- result = manager->fnOnCustomDraw(hNav, pItem, &manager->drawStruct, pItem->lParam);
- if (NICDRF_SKIPDEFAULT_I & result)
- {
- SelectObject(cd->nmcd.hdc, manager->hfontOld);
- DeleteObject(manager->drawStruct.hFont);
- manager->drawStruct.hFont = NULL;
- *pResult |= CDRF_SKIPDEFAULT;
- }
- if (NICDRF_NEWFONT_I & result) *pResult |= CDRF_NEWFONT;
- if (NICDRF_NOTIFYPOSTPAINT_I & result)
- {
- pItem->style |= NIS_WANTPOSTPAINT_I;
- *pResult |= CDRF_NOTIFYPOSTPAINT;
- }
- else pItem->style &= ~NIS_WANTPOSTPAINT_I;
- }
- }
- break;
- case CDDS_ITEMPOSTPAINT:
- if(NIS_WANTPOSTPAINT_I & ((NAVITM*)cd->nmcd.lItemlParam)->style)
- {
- INT result;
- manager->drawStruct.drawStage = NIDS_POSTPAINT_I;
- result = manager->fnOnCustomDraw(hNav, (HNAVITEM)cd->nmcd.lItemlParam, &manager->drawStruct, ((NAVITM*)cd->nmcd.lItemlParam)->lParam);
- if (NICDRF_SKIPDEFAULT_I & result) *pResult |= CDRF_SKIPDEFAULT;
- }
- if (manager->drawStruct.hFont && manager->drawStruct.hFont != ((NAVITM*)cd->nmcd.lItemlParam)->hFont)
- {
- SelectObject(cd->nmcd.hdc, manager->hfontOld);
- DeleteObject(manager->drawStruct.hFont);
- manager->drawStruct.hFont = NULL;
- }
- break;
- }
- return TRUE;
- }
- static BOOL OnTV_GetDispInfo(HNAVCTRL hNav, NMTVDISPINFOW *di, LRESULT *pResult)
- {
- BOOL handled;
- NAVMNGR *manager;
- manager = (NAVMNGR*)hNav;
- handled = FALSE;
- if((TVIF_IMAGE | TVIF_SELECTEDIMAGE) & di->item.mask)
- {
- if (di->item.lParam)
- {
- INT itemState;
- COLORREF rgbBk, rgbFg;
- itemState = NIS_NORMAL_I;
- if (TVS_FULLROWSELECT == (TVS_FULLROWSELECT & (UINT)GetWindowLongPtrW(manager->hwndHost, GWL_STYLE)))
- {
- itemState = di->item.state;
- if (TVIS_DROPHILITED & di->item.state)
- {
- if (0x8000 & GetAsyncKeyState( GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON))
- {
- HTREEITEM hTreeItem;
- TreeItemFromCursor(hNav, &hTreeItem);
- itemState = (hTreeItem) ? NIS_NORMAL_I : NIS_DROPHILITED_I;
- }
- else
- itemState = NIS_DROPHILITED_I;
- }
- else if (TVIS_SELECTED & di->item.state)
- {
- itemState = NIS_SELECTED_I;
- if (0 != ((NAVSTYLE_FOCUSED | NAVSTYLE_EDITMODE) & manager->style))
- itemState |= NIS_FOCUSED_I;
- }
- }
- GetItemColors(hNav, itemState, &rgbBk, &rgbFg);
- if (TVIF_IMAGE & di->item.mask)
- {
- di->item.iImage = GetRealImageIndex(hNav, (NAVITM*)di->item.lParam, IMAGE_NORMAL_I, rgbBk, rgbFg);
- }
- if (TVIF_SELECTEDIMAGE & di->item.mask)
- {
- di->item.iSelectedImage = ((TVIF_IMAGE & di->item.mask) &&
- ((NAVITM*)(di->item.lParam))->iImage == ((NAVITM*)(di->item.lParam))->iSelectedImage) ?
- di->item.iImage :
- GetRealImageIndex(hNav, (NAVITM*)di->item.lParam, IMAGE_SELECTED_I, rgbBk, rgbFg);
- }
- handled = TRUE;
-
- }
- }
- if (TVIF_CHILDREN & di->item.mask)
- {
- di->item.cChildren = (di->item.lParam) ? (NIS_HASCHILDREN_I & ((NAVITM*)di->item.lParam)->style) : 0;
- handled = TRUE;
- }
- if (TVIF_TEXT & di->item.mask)
- {
- di->item.pszText = (di->item.lParam) ?
- ((NAVITM*)di->item.lParam)->pszText : WASABI_API_LNGSTRINGW(IDS_BAD_ITEM);
- handled = TRUE;
- }
- return handled;
- }
- static BOOL OnTV_Click(HNAVCTRL hNav, NMHDR *pnmh, LRESULT *pResult)
- {
- return OnNavTree_Click(hNav, ACTION_CLICKL_I, pResult);
- }
- static BOOL OnTV_BeginDrag(HNAVCTRL hNav, NMTREEVIEWW *pnmtv)
- {
- if (hNav && ((NAVMNGR*)hNav)->fnOnBeginDrag)
- {
- ((NAVMNGR*)hNav)->fnOnBeginDrag(hNav, (HNAVITEM)pnmtv->itemNew.lParam, pnmtv->ptDrag);
- }
- return FALSE;
- }
- static BOOL OnTV_SelectionChanged(HNAVCTRL hNav, NMTREEVIEWW *pnmtv)
- {
- if (hNav && ((NAVMNGR*)hNav)->fnOnItemSelected)
- {
- ((NAVMNGR*)hNav)->fnOnItemSelected(hNav, (HNAVITEM)pnmtv->itemOld.lParam, (HNAVITEM)pnmtv->itemNew.lParam);
- MLSkinnedScrollWnd_UpdateBars(((NAVMNGR*)hNav)->hwndHost, TRUE);
- }
- return FALSE;
- }
- static BOOL OnTV_RightClick(HNAVCTRL hNav, NMHDR *pnmh, LRESULT *pResult)
- {
- return OnNavTree_Click(hNav, ACTION_CLICKR_I, pResult);
- }
- static BOOL OnTV_DoubleClick(HNAVCTRL hNav, NMHDR *pnmh, LRESULT *pResult)
- {
- return OnNavTree_Click(hNav, ACTION_DBLCLICKL_I, pResult);
- }
- static BOOL OnTV_KeyDown(HNAVCTRL hNav, NMTVKEYDOWN *ptvkd, LRESULT *pResult)
- {
- if (VK_RETURN == ptvkd->wVKey) return OnNavTree_Click(hNav, ACTION_ENTER_I, pResult);
- if (hNav && ((NAVMNGR*)hNav)->fnOnKeyDown)
- {
- HNAVITEM hItem;
- hItem = NavCtrlI_GetSelection(hNav);
- if (hItem)
- {
- *pResult = ((NAVMNGR*)hNav)->fnOnKeyDown(hNav, hItem, ptvkd);
- return (BOOL)*pResult;
- }
- }
- return FALSE;
- }
- static BOOL OnTV_BeginLabelEdit(HNAVCTRL hNav, NMTVDISPINFOW *di, LRESULT *pResult)
- {
- NAVMNGR *manager;
- NAVITM *item;
- manager = (NAVMNGR*)hNav;
- if (NULL == di)
- return FALSE;
- item = (NAVITM*)di->item.lParam;
- *pResult = TRUE;
- if (NULL != item &&
- 0 != (NIS_ALLOWEDIT_I & item->style))
- {
- if (NULL == manager->fnOnBeginTitleEdit ||
- FALSE != manager->fnOnBeginTitleEdit(hNav, (HNAVITEM)item))
- {
- HWND treeWindow, editWindow;
- treeWindow = manager->hwndHost;
- editWindow = (HWND)SendMessageW(treeWindow, TVM_GETEDITCONTROL, 0, 0);
- if (NULL != editWindow)
- SubclassEditControl(editWindow);
- manager->style |= NAVSTYLE_EDITMODE;
- *pResult = FALSE;
- }
- }
- return TRUE;
- }
- static BOOL OnTV_EndLabelEdit(HNAVCTRL hNav, NMTVDISPINFOW *di, LRESULT *pResult)
- {
- NAVMNGR *manager;
- manager = (NAVMNGR*)hNav;
- manager->style &= ~NAVSTYLE_EDITMODE;
- if (NULL != manager->fnOnEndTitleEdit &&
- FALSE == manager->fnOnEndTitleEdit(hNav, (HNAVITEM)di->item.lParam, di->item.pszText))
- {
- *pResult = FALSE;
- }
- else
- {
- *pResult = (NULL != di->item.pszText) ?
- NavItemI_SetText((HNAVITEM)di->item.lParam, di->item.pszText) :
- FALSE;
- }
- return TRUE;
- }
- static BOOL OnTV_SetCursor(HNAVCTRL hNav, NMMOUSE *pm, LRESULT *pResult)
- {
- if (!pm->dwItemData)
- {
- TVHITTESTINFO hit;
- if(GetCursorPos(&hit.pt))
- {
- HTREEITEM hTreeItem;
- MapWindowPoints(HWND_DESKTOP, ((NAVMNGR*)hNav)->hwndHost, &hit.pt, 1);
- hTreeItem = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_HITTEST, (WPARAM)0, (LPARAM)&hit);
- if (hTreeItem) pm->dwItemData = (DWORD_PTR)GetNavItemFromTreeItem(hNav, hTreeItem);
- }
- }
- if (pm->dwItemData)
- {
- if ((NIS_WANTSETCURSOR_I & ((NAVITM*)pm->dwItemData)->style) && ((NAVMNGR*)hNav)->fnOnSetCursor)
- {
- *pResult = ((NAVMNGR*)hNav)->fnOnSetCursor(hNav, (HNAVITEM)pm->dwItemData, ((NAVITM*)pm->dwItemData)->lParam);
- }
- }
- return TRUE;
- }
- static BOOL OnTV_SetFocus(HNAVCTRL hNav, NMHDR *pnmh)
- {
- NAVMNGR *manager = (NAVMNGR*)hNav;
- if (NULL == manager)
- return FALSE;
- if (0 == (NAVSTYLE_FOCUSED & manager->style))
- {
- manager->style |= NAVSTYLE_FOCUSED;
- HNAVITEM selectedItem = NavCtrlI_GetSelection(hNav);
- if (NULL != selectedItem)
- NavItemI_Invalidate(selectedItem, NULL, FALSE);
- }
- return TRUE;
- }
- static BOOL OnTV_KillFocus(HNAVCTRL hNav, NMHDR *pnmh)
- {
- NAVMNGR *manager = (NAVMNGR*)hNav;
- if (NULL == manager)
- return FALSE;
- if (0 != (NAVSTYLE_FOCUSED & manager->style))
- {
- manager->style &= ~NAVSTYLE_FOCUSED;
- HNAVITEM selectedItem = NavCtrlI_GetSelection(hNav);
- if (NULL != selectedItem)
- NavItemI_Invalidate(selectedItem, NULL, FALSE);
- }
- return TRUE;
- }
- // manager
- HNAVCTRL NavCtrlI_Create(HWND hwndParent)
- {
- PNAVMNGR pMngr = (PNAVMNGR)calloc(1, sizeof(NAVMNGR));
- if (!pMngr) return NULL;
- pMngr->hwndHost = CreateWindowExW(WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE,
- WC_TREEVIEWW, L"",
- WS_CHILD | WS_TABSTOP | TVS_SHOWSELALWAYS | TVS_FULLROWSELECT | TVS_NOHSCROLL | TVS_EDITLABELS,
- 0, 0, 1, 1, hwndParent, NULL, NULL, NULL);
- if (!IsWindow(pMngr->hwndHost) || !SetPropW(pMngr->hwndHost, NAVMGR_HWNDPROPW, pMngr))
- {
- NavCtrlI_Destroy(pMngr);
- return NULL;
- }
- pMngr->lastUsedId = NAVITEM_RANGE_MIN;
- pMngr->style = NAVSTYLE_DEFAULT;
- SubclassTreeView(pMngr->hwndHost); // need to be before Skinning
- if (SkinWindowEx(pMngr->hwndHost, SKINNEDWND_TYPE_SCROLLWND, SWS_USESKINFONT | SWS_USESKINCOLORS))
- {
- MLSkinnedScrollWnd_SetMode(pMngr->hwndHost, SCROLLMODE_TREEVIEW);
- HWND hTooltip = (HWND)SendMessageW(pMngr->hwndHost, TVM_GETTOOLTIPS, 0, 0L);
- if (NULL != hTooltip)
- {
- SkinWindowEx(hTooltip, SKINNEDWND_TYPE_TOOLTIP, SWS_USESKINFONT | SWS_USESKINCOLORS);
- }
- }
- SendMessageW(pMngr->hwndHost, (TV_FIRST + 44)/*TVM_SETEXTENDEDSTYLE*/,
- (WPARAM)pMngr->hwndHost, (LPARAM)0x0004/*TVS_EX_DOUBLEBUFFER*/);
- SendMessageW(pMngr->hwndHost, CCM_SETVERSION, 6, 0);
- SendMessageW(pMngr->hwndHost, TVM_SETSCROLLTIME, 200, 0);
- return (HNAVCTRL)pMngr;
- }
- BOOL NavCtrlI_SetRect(HNAVCTRL hNav, RECT *prc)
- {
- return (hNav && prc) ? SetWindowPos(((NAVMNGR*)hNav)->hwndHost, NULL,
- prc->left, prc->top, prc->right - prc->left, prc->bottom - prc->top,
- SWP_NOACTIVATE | SWP_NOZORDER) : FALSE;
- }
- BOOL NavCtrlI_Show(HNAVCTRL hNav, INT nCmdShow)
- {
- return (hNav) ? ShowWindow(((NAVMNGR*)hNav)->hwndHost, nCmdShow) : FALSE;
- }
- BOOL NavCtrlI_Enable(HNAVCTRL hNav, BOOL fEnable)
- {
- return (hNav) ? EnableWindow(((NAVMNGR*)hNav)->hwndHost, fEnable) : FALSE;
- }
- BOOL NavCtrlI_Destroy(HNAVCTRL hNav)
- {
- if (!hNav) return FALSE;
- if (NULL != ((NAVMNGR*)hNav)->fnOnDestroy)
- {
- ((NAVMNGR*)hNav)->fnOnDestroy(hNav);
- }
- NavCtrlI_SaveStates(hNav);
- if (((NAVMNGR*)hNav)->hwndHost)
- {
- RemovePropW(((NAVMNGR*)hNav)->hwndHost, NAVMGR_HWNDPROPW);
- DestroyWindow(((NAVMNGR*)hNav)->hwndHost);
- }
- NavCtrlI_DeleteStates(hNav);
- free(hNav);
- return TRUE;
- }
- BOOL NavCtrlI_Update(HNAVCTRL hNav)
- {
- return (hNav) ? UpdateWindow(((NAVMNGR*)hNav)->hwndHost) : FALSE;
- }
- C_Config *NavCtrlI_SetConfig(HNAVCTRL hNav, C_Config *pConfig)
- {
- C_Config *pTemp;
- if (!hNav) return NULL;
- pTemp = ((NAVMNGR*)hNav)->pConfig;
- ((NAVMNGR*)hNav)->pConfig = pConfig;
- if (pConfig) NavCtrlI_LoadStates(hNav);
- return pTemp;
- }
- HWND NavCtrlI_GetHWND(HNAVCTRL hNav)
- {
- return (hNav) ? ((NAVMNGR*)hNav)->hwndHost : NULL;
- }
- BOOL NavCtrlI_ProcessNotifications(HNAVCTRL hNav, LPNMHDR pnmh, LRESULT *pResult)
- {
- if (!hNav || pnmh->hwndFrom != ((PNAVMNGR)hNav)->hwndHost) return FALSE;
- switch(pnmh->code)
- {
- case TVN_KEYDOWN: return OnTV_KeyDown(hNav, (NMTVKEYDOWN*)pnmh, pResult);
- case TVN_SELCHANGEDW: return OnTV_SelectionChanged(hNav, (NMTREEVIEWW*)pnmh);
- case NM_RCLICK: return OnTV_RightClick(hNav, pnmh, pResult);
- case NM_DBLCLK: return OnTV_DoubleClick(hNav, pnmh, pResult);
- case TVN_BEGINDRAGW: return OnTV_BeginDrag(hNav, (NMTREEVIEWW*)pnmh);
- case NM_CLICK: return OnTV_Click(hNav, pnmh, pResult);
- case TVN_GETDISPINFOW: return OnTV_GetDispInfo(hNav, (NMTVDISPINFOW*)pnmh, pResult);
- case NM_CUSTOMDRAW: return OnTV_CustomDraw(hNav, (NMTVCUSTOMDRAW*)pnmh, pResult);
- case TVN_DELETEITEMW: return OnTV_DeleteItem(hNav, &((NMTREEVIEWW*)pnmh)->itemOld);
- case TVN_BEGINLABELEDITW: return OnTV_BeginLabelEdit(hNav, (NMTVDISPINFOW*)pnmh, pResult);
- case TVN_ENDLABELEDITW: return OnTV_EndLabelEdit(hNav, (NMTVDISPINFOW*)pnmh, pResult);
- case NM_SETCURSOR: return OnTV_SetCursor(hNav, (NMMOUSE*)pnmh, pResult);
- case NM_SETFOCUS: return OnTV_SetFocus(hNav, pnmh);
- case NM_KILLFOCUS: return OnTV_KillFocus(hNav, pnmh);
- }
- return FALSE;
- }
- LPVOID NavCtrlI_RegisterCallback(HNAVCTRL hNav, LPVOID fnCallback, INT cbType)
- {
- LPVOID temp;
- if (!hNav) return NULL;
- switch(cbType)
- {
- case CALLBACK_ONCLICK_I:
- temp = ((NAVMNGR*)hNav)->fnOnItemClick;
- ((NAVMNGR*)hNav)->fnOnItemClick = (ONNAVITEMCLICK_I)fnCallback;
- return temp;
- case CALLBACK_ONSELECTED_I:
- temp = ((NAVMNGR*)hNav)->fnOnItemSelected;
- ((NAVMNGR*)hNav)->fnOnItemSelected = (ONNAVITEMSELECTED_I)fnCallback;
- return temp;
- case CALLBACK_ONKEYDOWN_I:
- temp = ((NAVMNGR*)hNav)->fnOnKeyDown;
- ((NAVMNGR*)hNav)->fnOnKeyDown = (ONNAVCTRLKEYDOWN_I)fnCallback;
- return temp;
- case CALLBACK_ONBEGINDRAG_I:
- temp = ((NAVMNGR*)hNav)->fnOnBeginDrag;
- ((NAVMNGR*)hNav)->fnOnBeginDrag = (ONNAVCTRLBEGINDRAG_I)fnCallback;
- return temp;
- case CALLBACK_ONDESTROY_I:
- temp = ((NAVMNGR*)hNav)->fnOnDestroy;
- ((NAVMNGR*)hNav)->fnOnDestroy = (ONNAVCTRLDESTROY_I)fnCallback;
- return temp;
- case CALLBACK_ONGETIMAGEINDEX_I:
- temp = ((NAVMNGR*)hNav)->fnOnItemGetImageIndex;
- ((NAVMNGR*)hNav)->fnOnItemGetImageIndex = (ONNAVITEMGETIMAGEINDEX_I)fnCallback;
- return temp;
- case CALLBACK_ONBEGINTITLEEDIT_I:
- temp = ((NAVMNGR*)hNav)->fnOnBeginTitleEdit;
- ((NAVMNGR*)hNav)->fnOnBeginTitleEdit = (ONNAVITEMBEGINTITLEEDIT_I)fnCallback;
- return temp;
- case CALLBACK_ONENDTITLEEDIT_I:
- temp = ((NAVMNGR*)hNav)->fnOnEndTitleEdit;
- ((NAVMNGR*)hNav)->fnOnEndTitleEdit = (ONNAVCTRLENDTITLEEDIT_I)fnCallback;
- return temp;
- case CALLBACK_ONITEMDELETE_I:
- temp = ((NAVMNGR*)hNav)->fnOnItemDelete;
- ((NAVMNGR*)hNav)->fnOnItemDelete = (ONNAVITEMDELETE_I)fnCallback;
- return temp;
- case CALLBACK_ONITEMDRAW_I:
- temp = ((NAVMNGR*)hNav)->fnOnCustomDraw;
- ((NAVMNGR*)hNav)->fnOnCustomDraw = (ONNAVITEMDRAW_I)fnCallback;
- return temp;
- case CALLBACK_ONSETCURSOR_I:
- temp = ((NAVMNGR*)hNav)->fnOnSetCursor;
- ((NAVMNGR*)hNav)->fnOnSetCursor = (ONNAVITEMSETCURSOR_I)fnCallback;
- return temp;
- case CALLBACK_ONHITTEST_I:
- temp = ((NAVMNGR*)hNav)->fnOnHitTest;
- ((NAVMNGR*)hNav)->fnOnHitTest = (ONNAVITEMHITTEST_I)fnCallback;
- return temp;
- }
- return NULL;
- }
- BOOL NavCtrlI_UpdateLook(HNAVCTRL hNav)
- {
- INT minHeight;
- if (!hNav || !((NAVMNGR*)hNav)->hwndHost) return FALSE;
- minHeight = -1;
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SETBKCOLOR, (WPARAM)0, (LPARAM)WADlg_getColor(WADLG_ITEMBG));
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SETTEXTCOLOR, (WPARAM)0, (LPARAM)WADlg_getColor(WADLG_ITEMFG));
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SETINSERTMARKCOLOR, (WPARAM)0, (LPARAM)WADlg_getColor(WADLG_ITEMFG));
- MLSkinnedWnd_SkinChanged(((NAVMNGR*)hNav)->hwndHost, FALSE, FALSE);
- HFONT hFont = (HFONT)SendMessageW(((NAVMNGR*)hNav)->hwndHost, WM_GETFONT, 0, 0L);
- HDC hdc;
- hdc = GetDCEx(((NAVMNGR*)hNav)->hwndHost, NULL, DCX_CACHE);
- if (hdc)
- {
- if (NULL == hFont)
- hFont = (HFONT)MlStockObjects_Get(DEFAULT_FONT);
- TEXTMETRICW tm;
- if (hFont)
- {
- HFONT hfntOld = (HFONT)SelectObject(hdc, hFont);
- if (GetTextMetricsW(hdc, &tm)) minHeight = tm.tmHeight + 2/*Borders*/;
- SelectObject(hdc, hfntOld);
- }
- ReleaseDC(((NAVMNGR*)hNav)->hwndHost, hdc);
- }
- if (((NAVMNGR*)hNav)->pConfig)
- {
- BOOL fFullRowSelect;
- DWORD dwWndStyle;
- INT height;
- height = ((NAVMNGR*)hNav)->pConfig->ReadInt(L"Navigation_ItemHeight", 18);
- if (minHeight > 0 && height < minHeight) height = minHeight;
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SETITEMHEIGHT, (WPARAM)height, (LPARAM)0);
- ((NAVMNGR*)hNav)->style = (((NAVMNGR*)hNav)->style & ~NAVSTYLE_MOUSEDOWNSELECT) | ((0 != ((NAVMNGR*)hNav)->pConfig->ReadInt(L"Navigation_MouseDownSel", 0)) ? NAVSTYLE_MOUSEDOWNSELECT : 0);
- fFullRowSelect = (((NAVMNGR*)hNav)->pConfig->ReadInt(L"Navigation_FullRowSel", 1) != 0);
- dwWndStyle = (DWORD)GetWindowLongPtrW(((NAVMNGR*)hNav)->hwndHost, GWL_STYLE);
- if (fFullRowSelect != (TVS_FULLROWSELECT == (TVS_FULLROWSELECT & dwWndStyle)))
- {
- SetWindowLongPtrW(((NAVMNGR*)hNav)->hwndHost, GWL_STYLE,
- (dwWndStyle & ~TVS_FULLROWSELECT) | ((fFullRowSelect) ? TVS_FULLROWSELECT : 0));
- }
- NavCtrlI_SetImageList(hNav, ((NAVMNGR*)hNav)->hmlilImages);
- }
- return TRUE;
- }
- HMLIMGLST NavCtrlI_SetImageList(HNAVCTRL hNav, HMLIMGLST hmlil)
- {
- HMLIMGLST hmlilOld;
- HIMAGELIST hilTree, hilNew;
- if (!hNav) return NULL;
- hmlilOld = ((NAVMNGR*)hNav)->hmlilImages;
- ((NAVMNGR*)hNav)->hmlilImages = hmlil;
- hilNew = MLImageListI_GetRealList(hmlil);
- hilTree = (HIMAGELIST)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETIMAGELIST, (WPARAM)TVSIL_NORMAL, (LPARAM)0);
- if (!((NAVMNGR*)hNav)->pConfig || ((NAVMNGR*)hNav)->pConfig->ReadInt(L"Navigation_ShowIcons", 1))
- {
- if (hilTree != hilNew) SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SETIMAGELIST, (WPARAM)TVSIL_NORMAL, (LPARAM)hilNew);
- }
- else if (hilTree) SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SETIMAGELIST, (WPARAM)TVSIL_NORMAL, (LPARAM)NULL);
- return hmlilOld;
- }
- HMLIMGLST NavCtrlI_GetImageList(HNAVCTRL hNav)
- {
- return (hNav) ? ((NAVMNGR*)hNav)->hmlilImages : NULL;
- }
- HNAVITEM NavCtrlI_FindItem(HNAVCTRL hNav, INT itemId)
- {
- return (hNav) ? FindNavItemByNavIdEx(((NAVMNGR*)hNav)->hwndHost, itemId, TVI_ROOT) : NULL;
- }
- HNAVITEM NavCtrlI_FindItemByName(HNAVCTRL hNav, LCID Locale, UINT compFlags, LPCWSTR pszName, INT cchLength)
- {
- TREEITEMSEARCH search;
- if (!hNav || !pszName || !((NAVMNGR*)hNav)->hwndHost) return NULL;
- search.fFound = FALSE;
- search.itemData = (INT_PTR)pszName;
- search.item.mask = TVIF_PARAM;
- search.flags = compFlags;
- // pack extra info
- search.item.cchTextMax = cchLength;
- search.item.state = Locale;
- EnumerateTreeItems(((NAVMNGR*)hNav)->hwndHost, TVI_ROOT, FindTreeItemByNameCB, &search);
- return (search.fFound) ? (HNAVITEM)search.item.lParam : NULL;
- }
- HNAVITEM NavCtrlI_FindItemByFullName(HNAVCTRL hNav, LCID Locale, UINT compFlags, LPCWSTR pszFullName, INT cchLength, BOOL fAncestorOk)
- {
- INT len, separatorCount;
- WCHAR shortname[ITEM_SHORTNAME_MAX] = {0};
- LPCWSTR end;
- TVITEMW treeItem;
- HNAVITEM hNavParent;
- if (!hNav || !pszFullName || !((NAVMNGR*)hNav)->hwndHost) return NULL;
- hNavParent = NULL;
- len = (cchLength < 0)? lstrlenW(pszFullName) : cchLength;
- if (!len) return NULL;
- end = pszFullName + len;
- ZeroMemory(&treeItem, sizeof(TVITEMW));
- treeItem.mask = TVIF_PARAM;
- len = 0;
- separatorCount = 0;
- while (pszFullName != end + 1)
- {
- if (pszFullName == end) { separatorCount++; }
-
- if (SEPARATOR == *pszFullName) separatorCount++;
- else
- {
- if (separatorCount)
- {
- INT i;
- for (i = separatorCount/2; i > 0; i--)
- {
- if (len == ITEM_SHORTNAME_MAX -1) return NULL; // ugh...
- shortname[len++] = SEPARATOR;
- }
-
- if (separatorCount%2 && len)
- {
- if (CSTR_EQUAL != CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, EMPTY_ITEM_NAME, -1, shortname, len))
- {
- treeItem.hItem = (HTREEITEM)((NULL == hNavParent) ?
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_ROOT, (LPARAM)0) :
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)((NAVITM*)hNavParent)->hTreeItem));
- while(treeItem.hItem)
- {
- if (SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETITEMW, (WPARAM)0, (LPARAM)&treeItem))
- {
- if (CSTR_EQUAL == CompareItemName(Locale, compFlags, shortname, len, (HNAVITEM)treeItem.lParam))
- { // found!!!
- if (pszFullName == end) return (HNAVITEM)treeItem.lParam;
- break;
- }
- }
- treeItem.hItem = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)treeItem.hItem);
- }
- if (treeItem.hItem)
- {
- hNavParent = (HNAVITEM)treeItem.lParam;
- if (!hNavParent) return NULL; // thats bad
- }
- else return (fAncestorOk) ? hNavParent : NULL;
- }
- len = 0;
- }
- separatorCount = 0;
- }
- if (len == ITEM_SHORTNAME_MAX -1) return NULL; // ugh...
- shortname[len++] = *pszFullName;
- }
- pszFullName++;
- }
-
- return NULL;
- }
- HNAVITEM NavCtrlI_InsertItem(HNAVCTRL hNav, HNAVITEM hInsertAfter, HNAVITEM hParent, NAVITEM_I *pnis)
- {
- TVINSERTSTRUCTW is = {0};
- NAVITM *pNavItem = 0;
- HTREEITEM hItem = 0;
- if (!pnis) return NULL;
- if (NIMF_ITEMID_I & pnis->mask) { if (NavCtrlI_FindItem(hNav, pnis->id)) return NULL; }
- else pnis->id = GetNextFreeItemId(hNav);
- if (!pnis->id) return NULL;
- pNavItem = (NAVITM*)calloc(1, sizeof(NAVITM));
- if (!pNavItem) return NULL;
- is.hParent = (hParent) ? ((NAVITM*)hParent)->hTreeItem : TVI_ROOT;
- is.hInsertAfter = TVI_LAST;
- if (NCI_LAST_I == hInsertAfter) is.hInsertAfter = TVI_LAST;
- else if (NCI_FIRST_I == hInsertAfter) is.hInsertAfter = TVI_FIRST;
- else if (hInsertAfter && !IS_NAVITEMSORTORDER(hInsertAfter)) is.hInsertAfter = ((NAVITM*)hInsertAfter)->hTreeItem;
- if (is.hInsertAfter == is.hParent) is.hInsertAfter = TVI_FIRST;
- pNavItem->id = pnis->id;
- pNavItem->hwndTree = ((NAVMNGR*)hNav)->hwndHost;
- is.item.mask = TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_TEXT;
- is.item.lParam = (LPARAM)pNavItem;
- is.item.pszText = LPSTR_TEXTCALLBACKW;
- is.item.iImage = I_IMAGECALLBACK;
- is.item.iSelectedImage = I_IMAGECALLBACK;
- is.item.cChildren = I_CHILDRENCALLBACK;
- if (NIMF_STYLE_I & pnis->mask) NavItemI_SetStyle(pNavItem, pnis->style, pnis->styleMask);
- if (NIMF_TEXT_I & pnis->mask) NavItemI_SetText(pNavItem, pnis->pszText);
- if (NIMF_TEXTINVARIANT_I & pnis->mask) NavItemI_SetInvariantText(pNavItem, pnis->pszInvariant);
- if (NIMF_FONT_I & pnis->mask) NavItemI_SetFont(pNavItem, pnis->hFont);
- if (NIMF_PARAM_I & pnis->mask) pNavItem->lParam = pnis->lParam;
- NavItemI_SetImageIndex(pNavItem, (NIMF_IMAGE_I & pnis->mask) ? pnis->iImage : -1, IMAGE_NORMAL_I);
- NavItemI_SetImageIndex(pNavItem, (NIMF_IMAGESEL_I & pnis->mask) ? pnis->iSelectedImage : -1, IMAGE_SELECTED_I);
- NavCtrlI_BeginUpdate(hNav, NUF_LOCK_SELECTED_I);
- hItem = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_INSERTITEMW, (WPARAM)0, (LPARAM)&is);
- if (hItem)
- {
- UINT state, stateMask;
- NAVITEMSTATEREC *pRec;
- BOOL itemRecSearched;
- WORD order;
- UINT flags;
- pNavItem->hTreeItem = hItem;
- itemRecSearched = FALSE;
- order = (WORD)-1;
- flags = NOF_MOVEAFTER_I;
- if (hInsertAfter)
- {
- if (IS_NAVITEMSORTORDER(hInsertAfter)) { order = (WORD)hInsertAfter; flags = NOF_MOVEONEAFTER_I; }
- else
- {
- HTREEITEM hTreePrev;
- hTreePrev = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_PREVIOUS, (LPARAM)hItem);
- if (!hTreePrev) { order = 1; flags = NOF_MOVEONEBEFORE_I; }
- else
- {
- HNAVITEM hPrev;
- hPrev = GetNavItemFromTreeItem(hNav, hTreePrev);
- order = (hPrev) ? ((NAVITM*)hPrev)->sortOrder : (WORD)-1;
- flags = NOF_MOVEONEAFTER_I;
- }
- }
- }
- else
- {
- if (TVI_ROOT == is.hParent || !is.hParent)
- {
- pRec = NavCtrlI_FindItemStateRec(hNav, pNavItem, TRUE);
- order = (pRec) ? pRec->nOrder : ++((NAVMNGR*)hNav)->lastOrderIndex;
- flags = NOF_MOVEAFTER_I;
- itemRecSearched = TRUE;
- }
- }
- NavItemI_SetOrder(pNavItem, order, flags);
- if (NIMF_STATE_I & pnis->mask)
- {
- state = pnis->state;
- stateMask = pnis->stateMask;
- }
- else
- {
- state = 0;
- stateMask = 0;
- }
- if (0 == (NIS_EXPANDED_I & stateMask))
- {
- if (!itemRecSearched) pRec = NavCtrlI_FindItemStateRec(hNav, pNavItem, TRUE);
- state |= (pRec && pRec->fCollapsed) ? 0 : NIS_EXPANDED_I;
- stateMask |= NIS_EXPANDED_I;
- }
- NavItemI_SetState(pNavItem, state, stateMask);
- }
- else
- {
- NavItemI_SetText(pNavItem, NULL);
- NavItemI_SetInvariantText(pNavItem, NULL);
- free(pNavItem);
- pNavItem = NULL;
- }
- NavCtrlI_EndUpdate(hNav);
- return (HNAVITEM)pNavItem;
- }
- BOOL NavCtrlI_DeleteItem(HNAVCTRL hNav, HNAVITEM hItem)
- {
- return (hNav && hItem) ? (BOOL)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_DELETEITEM, 0, (LPARAM)((NAVITM*)hItem)->hTreeItem) : FALSE;
- }
- BOOL NavCtrlI_DeleteAll(HNAVCTRL hNav)
- {
- return (hNav) ? (BOOL)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT) : FALSE;
- }
- HNAVITEM NavCtrlI_GetRoot(HNAVCTRL hNav)
- {
- HTREEITEM hTreeChild;
- if (!hNav) return NULL;
- hTreeChild = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_ROOT, (LPARAM)0L);
- return (hTreeChild) ? GetNavItemFromTreeItem(hNav, hTreeChild) : NULL;
- }
- HNAVITEM NavCtrlI_GetSelection(HNAVCTRL hNav)
- {
- HTREEITEM hTreeChild;
- if (!hNav) return NULL;
- hTreeChild = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_CARET, (LPARAM)0L);
- return (hTreeChild) ? GetNavItemFromTreeItem(hNav, hTreeChild) : NULL;
- }
- HNAVITEM NavCtrlI_GetFirstVisible(HNAVCTRL hNav)
- {
- HTREEITEM hTreeChild;
- if (!hNav) return NULL;
- hTreeChild = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_FIRSTVISIBLE, (LPARAM)0L);
- return (hTreeChild) ? GetNavItemFromTreeItem(hNav, hTreeChild) : NULL;
- }
- HNAVITEM NavCtrlI_GetLastVisible(HNAVCTRL hNav)
- {
- HTREEITEM hTreeChild;
- if (!hNav) return NULL;
- hTreeChild = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, (WPARAM)TVGN_LASTVISIBLE, (LPARAM)0L);
- return (hTreeChild) ? GetNavItemFromTreeItem(hNav, hTreeChild) : NULL;
- }
- HNAVITEM NavCtrlI_HitTest(HNAVCTRL hNav, POINT *ppt, UINT *pFlags)
- {
- TVHITTESTINFO tvhi;
- HNAVITEM hItem;
- if (!hNav || !((NAVMNGR*)hNav)->hwndHost || !ppt)
- {
- if (pFlags) *pFlags = NAVHT_NOWHERE_I;
- return NULL;
- }
- tvhi.pt = *ppt;
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_HITTEST, (WPARAM)0, (LPARAM)&tvhi);
- hItem = (tvhi.hItem) ? GetNavItemFromTreeItem(hNav, tvhi.hItem) : NULL;
- PerformCustomHitTest(hNav, tvhi.pt, &tvhi.flags, (hItem) ? &hItem : NULL);
- if (pFlags) *pFlags = tvhi.flags;
- return hItem;
- }
- BOOL NavCtrlI_SetInsertMark(HNAVCTRL hNav, HNAVITEM hItem, BOOL fAfter)
- {
- return (hNav) ? (BOOL)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SETINSERTMARK,
- (WPARAM)fAfter,
- (hItem) ? (LPARAM)((NAVITM*)hItem)->hTreeItem : NULL) : FALSE;
- }
- BOOL NavCtrlI_EnumItems(HNAVCTRL hNav, NAVENUMPROC_I pEnumFunc, HNAVITEM hItemStart, LPARAM lParam)
- {
- NAVENUMSTRUCT navenum;
- if (!hNav || !pEnumFunc) return FALSE;
- navenum.hNav = hNav;
- navenum.callback = pEnumFunc;
- navenum.lParam = lParam;
- navenum.item.mask = TVIF_PARAM;
- return EnumerateTreeItems(((NAVMNGR*)hNav)->hwndHost, (hItemStart) ? ((NAVITM*)hItemStart)->hTreeItem : TVI_ROOT, EnumNavItemCB, &navenum);
- }
- INT NavCtrlI_BeginUpdate(HNAVCTRL hNav, UINT fRememberPos)
- {
- if (!hNav || !((NAVMNGR*)hNav)->hwndHost || !IsWindow(((NAVMNGR*)hNav)->hwndHost)) return -1;
- if (!((NAVMNGR*)hNav)->lockUpdate)
- {
- ((NAVMNGR*)hNav)->lockFirst = NULL;
- ((NAVMNGR*)hNav)->lockSelected = NULL;
- if (fRememberPos)
- {
- ((NAVMNGR*)hNav)->lockFirst = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, (LPARAM)TVI_ROOT);
- if (NUF_LOCK_SELECTED_I & fRememberPos)
- {
- ((NAVMNGR*)hNav)->lockSelected = (HTREEITEM)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETNEXTITEM, TVGN_CARET, (LPARAM)TVI_ROOT);
- if (((NAVMNGR*)hNav)->lockSelected)
- {
- RECT rc;
- *(HTREEITEM*)&rc = ((NAVMNGR*)hNav)->lockSelected;
- if (!SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETITEMRECT, FALSE, (LPARAM)&rc)) ((NAVMNGR*)hNav)->lockSelected = NULL;
- else ((NAVMNGR*)hNav)->lockSelPos = rc.top;
- }
- }
- }
- UpdateWindow(((NAVMNGR*)hNav)->hwndHost);
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, WM_SETREDRAW, (WPARAM)FALSE, 0L);
- }
- return ++((NAVMNGR*)hNav)->lockUpdate;
- }
- INT NavCtrlI_EndUpdate(HNAVCTRL hNav)
- {
- if (!hNav || !((NAVMNGR*)hNav)->hwndHost || !IsWindow(((NAVMNGR*)hNav)->hwndHost)) return -1;
- if (((NAVMNGR*)hNav)->lockUpdate)
- {
- ((NAVMNGR*)hNav)->lockUpdate--;
- if (!((NAVMNGR*)hNav)->lockUpdate)
- {
- SCROLLINFO si;
- si.cbSize = sizeof(SCROLLINFO);
- si.fMask = SIF_POS | SIF_RANGE;
- if (((NAVMNGR*)hNav)->lockSelected)
- {
- RECT rc;
- *(HTREEITEM*)&rc = ((NAVMNGR*)hNav)->lockSelected;
- if (!SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETITEMRECT, FALSE, (LPARAM)&rc))
- {
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_SELECTITEM, (WPARAM)TVGN_FIRSTVISIBLE, (LPARAM)((NAVMNGR*)hNav)->lockSelected);
- }
- else if (((NAVMNGR*)hNav)->lockSelPos != rc.top)
- {
- INT iHeight = (INT)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETITEMHEIGHT , 0, 0L);
- if (iHeight)
- {
- INT pos, oldPos;
- if (((NAVMNGR*)hNav)->lockSelPos > rc.top) iHeight = 0 - iHeight;
- WPARAM wCmd = MAKEWPARAM((((NAVMNGR*)hNav)->lockSelPos > rc.top) ? SB_LINEUP : SB_LINEDOWN, 0);
- oldPos = 0xFFFFFF;
- for(pos = ((NAVMNGR*)hNav)->lockSelPos; pos != rc.top; pos += iHeight)
- {
- if (ABS((oldPos - rc.top)) <= ABS((pos - rc.top))) break;
- oldPos = pos;
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, WM_VSCROLL, wCmd, 0L);
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, WM_VSCROLL, MAKEWPARAM(SB_ENDSCROLL, 0), 0L);
- }
- }
- }
- }
- else if (((NAVMNGR*)hNav)->lockFirst)
- {
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_ENSUREVISIBLE, (WPARAM)0, (LPARAM)((NAVMNGR*)hNav)->lockFirst);
- }
- ((NAVMNGR*)hNav)->lockFirst = NULL;
- ((NAVMNGR*)hNav)->lockSelected = NULL;
- if(GetScrollInfo(((NAVMNGR*)hNav)->hwndHost, SB_HORZ, &si) && (si.nMin != si.nPos))
- {
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, WM_HSCROLL, MAKEWPARAM(SB_LEFT, 0), NULL);
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, WM_HSCROLL, MAKEWPARAM(SB_ENDSCROLL, 0), NULL);
- }
- SendMessageW(((NAVMNGR*)hNav)->hwndHost, WM_SETREDRAW, (WPARAM)TRUE, 0L);
- }
- }
- return ((NAVMNGR*)hNav)->lockUpdate;
- }
- INT NavCtrlI_MapPointsTo(HNAVCTRL hNav, HWND hwndTo, POINT *ppt, UINT cPoints)
- {
- return (hNav) ? MapWindowPoints(((NAVMNGR*)hNav)->hwndHost, hwndTo, ppt, cPoints) : 0;
- }
- INT NavCtrlI_MapPointsFrom(HNAVCTRL hNav, HWND hwndFrom, POINT *ppt, UINT cPoints)
- {
- return (hNav) ? MapWindowPoints(hwndFrom, ((NAVMNGR*)hNav)->hwndHost, ppt, cPoints) : 0;
- }
- BOOL NavCtrlI_EndEditTitle(HNAVCTRL hNav, BOOL fCancel)
- {
- return (hNav) ? (BOOL)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_ENDEDITLABELNOW, (WPARAM)fCancel, 0L) : FALSE;
- }
- INT NavCtrlI_GetIndent(HNAVCTRL hNav)
- {
- return (hNav) ? (BOOL)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETINDENT, (WPARAM)0, 0L) : 0;
- }
- DWORD NavCtrlI_GetStyle(HNAVCTRL hNav)
- {
- DWORD style;
- style = NCS_NORMAL_I;
- if (hNav)
- {
- if (TVS_FULLROWSELECT == (TVS_FULLROWSELECT & (DWORD)GetWindowLongPtrW(((NAVMNGR*)hNav)->hwndHost, GWL_STYLE)))
- style |= NCS_FULLROWSELECT_I;
- if (NULL != (HIMAGELIST)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETIMAGELIST, (WPARAM)TVSIL_NORMAL, (LPARAM)0))
- style |= NCS_SHOWICONS_I;
- }
- return style;
- }
- BOOL NavItemI_EditTitle(HNAVITEM hItem)
- {
- NAVITM *item;
- HWND editWindow;
- if (NULL == hItem)
- return FALSE;
- item = (NAVITM*)hItem;
- if (0 == (NIS_ALLOWEDIT_I & item->style))
- return FALSE;
- SendMessageW(item->hwndTree, TVM_ENSUREVISIBLE, 0, (LPARAM)item->hTreeItem);
- editWindow = (HWND)SendMessageW(item->hwndTree, TVM_EDITLABELW, 0, (LPARAM)item->hTreeItem);
- return (NULL != editWindow);
- }
- INT NavItemI_GetId(HNAVITEM hItem)
- {
- return (hItem) ? ((NAVITM*)hItem)->id : 0;
- }
- HNAVITEM NavItemI_GetChild(HNAVITEM hItem)
- {
- return NavItemI_GetNextEx(hItem, TVGN_CHILD);
- }
- HNAVITEM NavItemI_GetNext(HNAVITEM hItem)
- {
- return NavItemI_GetNextEx(hItem, TVGN_NEXT);
- }
- HNAVITEM NavItemI_GetRoot(HNAVITEM hItem)
- {
- return NavItemI_GetNextEx(hItem, TVGN_ROOT);
- }
- HNAVITEM NavItemI_GetParent(HNAVITEM hItem)
- {
- return NavItemI_GetNextEx(hItem, TVGN_PARENT);
- }
- HNAVITEM NavItemI_GetPrevious(HNAVITEM hItem)
- {
- return NavItemI_GetNextEx(hItem, TVGN_PREVIOUS);
- }
- INT NavItemI_GetChildrenCount(HNAVITEM hItem)
- {
- HTREEITEM hChild;
- int counter;
- if (!hItem) return -1;
- hChild = (HTREEITEM)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)((NAVITM*)hItem)->hTreeItem);
- if (!hChild) return 0;
- counter = 1;
- while(NULL != (hChild = (HTREEITEM)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)hChild))) counter++;
- return counter;
- }
- BOOL NavItemI_IsExpanded(HNAVITEM hItem)
- {
- return (hItem && (TVIS_EXPANDED == (TVIS_EXPANDED & (UINT)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETITEMSTATE,
- (WPARAM)((NAVITM*)hItem)->hTreeItem, (LPARAM)TVIS_EXPANDED))));
- }
- INT NavItemI_GetImageIndex(HNAVITEM hItem, INT imageType)
- {
- NAVITM *item;
- item = (NAVITM*)hItem;
- if (NULL == item)
- return -1;
- if (0 != (NIS_DEFAULTIMAGE & item->style))
- return -1;
- switch(imageType)
- {
- case IMAGE_NORMAL_I: return ((NAVITM*)hItem)->iImage;
- case IMAGE_SELECTED_I: return ((NAVITM*)hItem)->iSelectedImage;
- }
- return -1;
- }
- BOOL NavItemI_GetIndirect(HNAVITEM hItem, NAVITEM_I *pnis)
- {
- NAVITM *pItem;
- if (!hItem || !pnis) return FALSE;
- pItem = (NAVITM*)hItem;
- if (NIMF_ITEMID_I & pnis->mask) pnis->id = pItem->id;
- if (NIMF_IMAGE_I & pnis->mask) pnis->iImage = pItem->iImage;
- if (NIMF_IMAGESEL_I & pnis->mask) pnis->iSelectedImage = pItem->iSelectedImage;
- if (NIMF_STYLE_I & pnis->mask) pnis->style = (pnis->styleMask & pItem->style);
- if (NIMF_TEXT_I & pnis->mask && !NavItemI_GetText(pItem, pnis->pszText, pnis->cchTextMax)) return FALSE;
- if (NIMF_TEXTINVARIANT_I & pnis->mask && !NavItemI_GetInvariantText(pItem, pnis->pszInvariant, pnis->cchInvariantMax)) return FALSE;
- if (NIMF_STATE_I & pnis->mask) pnis->state = NavItemI_GetState(pItem, 0xFFFFFFFF);
- if (NIMF_FONT_I & pnis->mask) pnis->hFont = NavItemI_GetFont(pItem);
- if (NIMF_PARAM_I & pnis->mask) pnis->lParam = pItem->lParam;
- return TRUE;
- }
- BOOL NavItemI_GetText(HNAVITEM hItem, LPWSTR pszText, INT cchMaxLen)
- {
- if (!hItem || !pszText) return FALSE;
- return (S_OK == StringCchCopyW(pszText, cchMaxLen, (((NAVITM*)hItem)->pszText) ? ((NAVITM*)hItem)->pszText : L""));
- }
- BOOL NavItemI_GetInvariantText(HNAVITEM hItem, LPWSTR pszText, INT cchMaxLen)
- {
- if (!hItem || !pszText) return FALSE;
- return (S_OK == StringCchCopyW(pszText, cchMaxLen, (((NAVITM*)hItem)->pszInvariant) ? ((NAVITM*)hItem)->pszInvariant : L""));
- }
- BOOL NavItemI_HasChildren(HNAVITEM hItem)
- {
- return (hItem && (0 != (NIS_HASCHILDREN_I & ((NAVITM*)hItem)->style)));
- }
- BOOL NavItemI_HasChildrenReal(HNAVITEM hItem)
- {
- return (hItem && SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_CHILD, (LPARAM)((NAVITM*)hItem)->hTreeItem));
- }
- BOOL NavItemI_IsSelected(HNAVITEM hItem)
- {
- return (NIS_SELECTED_I == NavItemI_GetState(hItem, NIS_SELECTED_I));
- }
- BOOL NavItemI_SetId(HNAVITEM hItem, INT itemId)
- {
- if (!hItem || itemId < 0) return FALSE;
- if (((NAVITM*)hItem)->id == itemId) return TRUE;
- if (FindNavItemByNavIdEx(((NAVITM*)hItem)->hwndTree, itemId, TVI_ROOT)) return FALSE;
- ((NAVITM*)hItem)->id = itemId;
- return TRUE;
- }
- BOOL NavItemI_SetImageIndex(HNAVITEM hItem, INT mlilIndex, INT imageType)
- {
- if (!hItem) return FALSE;
- switch(imageType)
- {
- case IMAGE_NORMAL_I: ((NAVITM*)hItem)->iImage = mlilIndex; break;
- case IMAGE_SELECTED_I: ((NAVITM*)hItem)->iSelectedImage = mlilIndex; break;
- default: return FALSE;
- }
- NavItemI_Invalidate(hItem, NULL, FALSE);
- return TRUE;
- }
- BOOL NavItemI_SetStyle(HNAVITEM hItem, UINT style, UINT mask)
- {
- UINT newStyle;
- if (!hItem) return FALSE;
- newStyle = (((NAVITM*)hItem)->style & ~mask) | style;
- if (((NAVITM*)hItem)->style != newStyle)
- {
- ((NAVITM*)hItem)->style = newStyle;
- NavItemI_Invalidate(hItem, NULL, FALSE);
- }
- return TRUE;
- }
- BOOL NavItemI_SetText(HNAVITEM hItem, LPCWSTR pszText)
- {
- if (!hItem) return FALSE;
- if (!pszText)
- {
- free(((NAVITM*)hItem)->pszText);
- ((NAVITM*)hItem)->pszText = NULL;
- ((NAVITM*)hItem)->cchTextMax = 0;
- }
- else
- {
- INT len = lstrlenW(pszText);
- if (len >= ((NAVITM*)hItem)->cchTextMax)
- {
- LPVOID data;
- data = realloc(((NAVITM*)hItem)->pszText, sizeof(WCHAR)*(len + 4));
- if (!data) return FALSE;
- ((NAVITM*)hItem)->pszText = (LPWSTR)data;
- ((NAVITM*)hItem)->cchTextMax = len + 4;
- }
- if (S_OK != StringCchCopyW(((NAVITM*)hItem)->pszText, ((NAVITM*)hItem)->cchTextMax, pszText)) return FALSE;
- }
- NavItemI_Invalidate(hItem, NULL, FALSE);
- return TRUE;
- }
- BOOL NavItemI_SetInvariantText(HNAVITEM hItem, LPCWSTR pszText)
- {
- if (!hItem) return FALSE;
- if (!pszText)
- {
- free(((NAVITM*)hItem)->pszInvariant);
- ((NAVITM*)hItem)->pszInvariant = NULL;
- ((NAVITM*)hItem)->cchInvariantMax = 0;
- }
- else
- {
- INT len = lstrlenW(pszText);
- if (len >= ((NAVITM*)hItem)->cchInvariantMax)
- {
- LPVOID data;
- data = realloc(((NAVITM*)hItem)->pszInvariant, sizeof(WCHAR)*(len + 4));
- if (!data) return FALSE;
- ((NAVITM*)hItem)->pszInvariant = (LPWSTR)data;
- ((NAVITM*)hItem)->cchInvariantMax = len + 4;
- }
- if (S_OK != StringCchCopyW(((NAVITM*)hItem)->pszInvariant, ((NAVITM*)hItem)->cchInvariantMax, pszText)) return FALSE;
- }
- return TRUE;
- }
- BOOL NavItemI_SetState(HNAVITEM hItem, UINT state, UINT stateMask)
- {
- TVITEMW item;
- if (!hItem) return FALSE;
- item.hItem = ((NAVITM*)hItem)->hTreeItem;
- item.mask = TVIF_STATE;
- item.state = 0;
- item.stateMask = 0;
- switch(state)
- {
- case NIS_SELECTED_I: item.state |= TVIS_SELECTED; break;
- case NIS_EXPANDED_I: item.state |= TVIS_EXPANDED; break;
- case NIS_DROPHILITED_I: item.state |= TVIS_DROPHILITED; break;
- }
- switch(stateMask)
- {
- case NIS_SELECTED_I: item.stateMask |= TVIS_SELECTED; break;
- case NIS_EXPANDED_I: item.stateMask |= TVIS_EXPANDED; break;
- case NIS_DROPHILITED_I: item.stateMask |= TVIS_DROPHILITED; break;
- }
- return (BOOL)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_SETITEMW, (WPARAM)0, (LPARAM)&item);
- }
- UINT NavItemI_GetState(HNAVITEM hItem, UINT stateMask)
- {
- UINT treeState, navState;
- if (!hItem) return 0;
- treeState = (UINT)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETITEMSTATE, (WPARAM)((NAVITM*)hItem)->hTreeItem, (LPARAM)0xFFFFFFFF);
- navState = 0;
- if (TVIS_SELECTED & treeState) navState |= NIS_SELECTED_I;
- if (TVIS_EXPANDED & treeState) navState |= NIS_EXPANDED_I;
- if (TVIS_DROPHILITED & treeState) navState |= NIS_DROPHILITED_I;
- return (navState & stateMask);
- }
- UINT NavItemI_GetStyle(HNAVITEM hItem, UINT styleMask)
- {
- return (hItem) ? (((NAVITM*)hItem)->style & styleMask) : 0;
- }
- BOOL NavItemI_SetIndirect(HNAVITEM hItem, NAVITEM_I *pnis)
- {
- if (!hItem || !pnis) return FALSE;
- BOOL fResult = TRUE;
- ((NAVITM*)hItem)->fBlockInvalid = TRUE;
- if (NIMF_ITEMID_I & pnis->mask && !NavItemI_SetId(hItem, pnis->id)) fResult = FALSE;
- if (NIMF_IMAGE_I & pnis->mask && !NavItemI_SetImageIndex(hItem, pnis->iImage, IMAGE_NORMAL_I)) fResult = FALSE;
- if (NIMF_IMAGESEL_I & pnis->mask && !NavItemI_SetImageIndex(hItem, pnis->iSelectedImage, IMAGE_SELECTED_I)) fResult = FALSE;
- if (NIMF_STYLE_I & pnis->mask && !NavItemI_SetStyle(hItem, pnis->style, pnis->styleMask)) fResult = FALSE;
- if (NIMF_TEXT_I & pnis->mask && !NavItemI_SetText(hItem, pnis->pszText)) fResult = FALSE;
- if (NIMF_TEXTINVARIANT_I & pnis->mask && !NavItemI_SetText(hItem, pnis->pszInvariant)) fResult = FALSE;
- if (NIMF_STATE_I & pnis->mask && !NavItemI_SetState(hItem, pnis->state, pnis->stateMask)) fResult = FALSE;
- if (NIMF_FONT_I & pnis->mask && !NavItemI_SetFont(hItem, pnis->hFont)) fResult = FALSE;
- if (NIMF_PARAM_I & pnis->mask) ((NAVITM*)hItem)->lParam = pnis->lParam;
- ((NAVITM*)hItem)->fBlockInvalid = FALSE;
- if (!NavItemI_Invalidate(hItem, NULL, FALSE)) fResult = FALSE;
- return fResult;
- }
- BOOL NavItemI_GetRect(HNAVITEM hItem, RECT *prc, BOOL fItemRect)
- {
- if (!hItem || !prc) return FALSE;
- *((HTREEITEM*)prc) = ((NAVITM*)hItem)->hTreeItem;
- return (BOOL)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETITEMRECT, (WPARAM)fItemRect, (LPARAM)prc);
- }
- BOOL NavItemI_Invalidate(HNAVITEM hItem, RECT *prc, BOOL fErase)
- {
- if (!hItem) return FALSE;
- if (!((NAVITM*)hItem)->fBlockInvalid)
- {
- RECT rc;
- if (NavItemI_GetRect(hItem, &rc, FALSE))
- {
- if (prc) IntersectRect(&rc, &rc, prc);
- InvalidateRect(((NAVITM*)hItem)->hwndTree, &rc, fErase);
- return TRUE;
- }
- }
- return TRUE;
- }
- BOOL NavItemI_Expand(HNAVITEM hItem, UINT flag)
- {
- UINT tiFlag;
- if (!hItem) return FALSE;
- switch(flag)
- {
- case NAVITEM_TOGGLE_I: tiFlag = TVE_TOGGLE; break;
- case NAVITEM_EXPAND_I: tiFlag = TVE_EXPAND; break;
- case NAVITEM_COLLAPSE_I: tiFlag = TVE_COLLAPSE; break;
- default: return FALSE;
- }
- return (BOOL)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_EXPAND, (WPARAM)tiFlag, (LPARAM)((NAVITM*)hItem)->hTreeItem);
- }
- INT NavItemI_GetFullName(HNAVITEM hItem, LPWSTR pszFullName, INT cchMaxLen)
- {
- wchar_t *current, *scanner, *text;
- INT remaining;
- if (!pszFullName || !hItem) return 0;
- pszFullName[0] = 0x00;
- remaining = cchMaxLen;
- current = pszFullName;
- while(hItem && remaining)
- {
- text = (((NAVITM*)hItem)->pszInvariant) ? ((NAVITM*)hItem)->pszInvariant : ((NAVITM*)hItem)->pszText;
- if (!text) text = EMPTY_ITEM_NAME;
- if (current != pszFullName)
- {
- *current = SEPARATOR;
- current++;
- remaining--;
- }
- scanner = text + lstrlenW(text) - 1;
- BOOL second = FALSE;
- while (scanner >= text && remaining)
- {
- *current = *scanner;
- current++;
- remaining--;
- if (SEPARATOR == *scanner && !second) { second = TRUE; continue; }
- second = FALSE;
- scanner--;
- }
- hItem = NavItemI_GetParent(hItem);
- }
- if (remaining)
- {
- *current = 0x00;
- current--;
- scanner = pszFullName;
- while (scanner < current)
- {
- wchar_t tmp = *scanner;
- *scanner = *current;
- *current = tmp;
- scanner++;
- current--;
- }
- }
- else
- {
- *pszFullName = 0x00;
- return 0;
- }
- return cchMaxLen - remaining;
- }
- BOOL NavItemI_Move(HNAVITEM hItem, HNAVITEM hItemDest, BOOL fAfter)
- {
- WORD order;
- UINT flags;
- HNAVCTRL hNav;
- if (!hItem) return FALSE;
- if (hItemDest)
- {
- order = ((NAVITM*)hItemDest)->sortOrder;
- flags = (fAfter) ? NOF_MOVEONEAFTER_I : NOF_MOVEONEBEFORE_I;
- }
- else
- {
- order = 1;
- flags = NOF_MOVEONEBEFORE_I;
- }
- hNav = (HNAVCTRL)GetPropW(((NAVITM*)hItem)->hwndTree, NAVMGR_HWNDPROPW);
- NavCtrlI_BeginUpdate(hNav, NUF_LOCK_NONE_I);
- order = NavItemI_SetOrder(hItem, order, flags);
- NavItemI_EnsureVisible(hItem);
- NavCtrlI_EndUpdate(hNav);
- return ((WORD)-1 != order);
- }
- static INT CALLBACK CommpareByOrderCB(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
- {
- if (lParam1 == lParam2) return 0;
- if (NULL == lParam1) return 1;
- return (((NAVITM*)lParam1)->sortOrder - ((NAVITM*)lParam2)->sortOrder);
- }
- static BOOL NavItemI_SetOrderWorker(HNAVITEM hItem, HTREEITEM hTreeFirst, WORD order, UINT flags)
- {
- bool bRecurse;
- if (!hItem) return FALSE;
- bRecurse = false;
- if (0 == order)
- {
- order = 1;
- flags = NOF_MOVEONEBEFORE_I;
- }
- if (((WORD)-1) == order || ((NAVITM*)hItem)->sortOrder != order)
- {
- TVITEMW treeItem; // keep it here so it will be released prior to recurtion
- ((NAVITM*)hItem)->sortOrder = (((WORD)-1) == order) ? 1 : order;
- treeItem.mask = TVIF_HANDLE | TVIF_PARAM;
- treeItem.hItem = hTreeFirst;
- while (treeItem.hItem)
- {
- if (treeItem.hItem != ((NAVITM*)hItem)->hTreeItem)
- {
- if (!SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETITEMW, (WPARAM)0, (LPARAM)&treeItem)) return FALSE;
- if (((WORD)-1) == order)
- {
- if (treeItem.lParam && ((NAVITM*)hItem)->sortOrder <= ((NAVITM*)treeItem.lParam)->sortOrder)
- ((NAVITM*)hItem)->sortOrder = ((NAVITM*)treeItem.lParam)->sortOrder + 1;
- }
- else
- {
- if (treeItem.lParam && ((NAVITM*)treeItem.lParam)->sortOrder == order)
- {
- switch(flags)
- {
- case NOF_MOVEONEBEFORE_I:
- hItem = (HNAVITEM)treeItem.lParam;
- order = ((NAVITM*)hItem)->sortOrder + 1;
- break;
- case NOF_MOVEONEAFTER_I:
- order++;
- flags = NOF_MOVEONEBEFORE_I;
- break;
- case NOF_MOVEBEFORE_I:
- if (1 == order)
- {
- hItem = (HNAVITEM)treeItem.lParam;
- order = ((NAVITM*)hItem)->sortOrder + 1;
- flags = NOF_MOVEONEBEFORE_I;
- }
- else order--;
- break;
- case NOF_MOVEAFTER_I:
- order++;
- break;
- default: return FALSE;
- }
- bRecurse = true;
- break;
- }
- }
- }
- treeItem.hItem = (HTREEITEM)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_NEXT, (LPARAM)treeItem.hItem);
- }
- }
- return (bRecurse) ? NavItemI_SetOrderWorker(hItem, hTreeFirst, order, flags) : TRUE;
- }
- WORD NavItemI_SetOrder(HNAVITEM hItem, WORD order, UINT flags)
- {
- HTREEITEM hTreeParent;
- if (!hItem) return (WORD)-1;
- hTreeParent = (HTREEITEM)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_PARENT, (LPARAM)((NAVITM*)hItem)->hTreeItem);
- if (NavItemI_SetOrderWorker(hItem,
- (HTREEITEM)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETNEXTITEM,
- (WPARAM)((hTreeParent) ? TVGN_CHILD : TVGN_ROOT), (LPARAM)hTreeParent),
- order, flags))
- {
- HNAVCTRL hNav;
- TVSORTCB sort;
- sort.hParent = hTreeParent;
- sort.lpfnCompare = CommpareByOrderCB;
- sort.lParam = 0;
- hNav = (HNAVCTRL)GetPropW(((NAVITM*)hItem)->hwndTree, NAVMGR_HWNDPROPW);
- NavCtrlI_BeginUpdate(hNav, NUF_LOCK_NONE_I);
- SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_SORTCHILDRENCB, (WPARAM)FALSE, (LPARAM)&sort);
- NavCtrlI_EndUpdate(hNav);
- }
- return ((NAVITM*)hItem)->sortOrder;
- }
- WORD NavItemI_GetOrder(HNAVITEM hItem)
- {
- return (hItem) ? ((NAVITM*)hItem)->sortOrder : 0xFFFF;
- }
- BOOL NavItemI_Select(HNAVITEM hItem)
- {
- BOOL fResult;
- if (!hItem) return FALSE;
- fResult = (BOOL)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_SELECTITEM, (WPARAM)TVGN_CARET, (LPARAM)((NAVITM*)hItem)->hTreeItem);
- SendMessageW(((NAVITM*)hItem)->hwndTree, WM_HSCROLL, MAKEWPARAM(SB_LEFT, 0), NULL);
- SendMessageW(((NAVITM*)hItem)->hwndTree, WM_HSCROLL, MAKEWPARAM(SB_ENDSCROLL, 0), NULL);
- return fResult;
- }
- BOOL NavItemI_EnsureVisible(HNAVITEM hItem)
- {
- BOOL fResult;
- if (!hItem) return FALSE;
- fResult = (BOOL)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_ENSUREVISIBLE, (WPARAM)0, (LPARAM)((NAVITM*)hItem)->hTreeItem);
- if (fResult)
- {
- SCROLLINFO si;
- si.cbSize = sizeof(SCROLLINFO);
- si.fMask = SIF_POS | SIF_RANGE;
- if(GetScrollInfo(((NAVITM*)hItem)->hwndTree, SB_HORZ, &si) && (si.nMin != si.nPos))
- {
- SendMessageW(((NAVITM*)hItem)->hwndTree, WM_HSCROLL, MAKEWPARAM(SB_LEFT, 0), NULL);
- SendMessageW(((NAVITM*)hItem)->hwndTree, WM_HSCROLL, MAKEWPARAM(SB_ENDSCROLL, 0), NULL);
- }
- }
- return fResult;
- }
- HFONT NavItemI_GetFont(HNAVITEM hItem)
- {
- return (hItem) ? ((NAVITM*)hItem)->hFont : NULL;
- }
- HFONT NavItemI_SetFont(HNAVITEM hItem, HFONT hFont)
- {
- HFONT hFontOld;
- if (!hItem) return NULL;
- hFontOld = ((NAVITM*)hItem)->hFont;
- ((NAVITM*)hItem)->hFont = hFont;
- NavItemI_Invalidate(hItem, NULL, FALSE);
- return hFontOld;
- }
- HIMAGELIST NavItemI_CreateDragImage(HNAVITEM hItem, LPCWSTR pszTipText)
- {
- HIMAGELIST hIL;
- HNAVCTRL hNav;
- HBITMAP hbmp;
- INT cy, cx, ilIndex;
- RECT rcImage, rcText, rcTip;
- HDC hdcMem, hdcScreen;
- HFONT hFont, hFontOld, hFontTip;
- BOOL fDestroyFont;
- fDestroyFont = FALSE;
- hFont = NULL;
- hFontTip = NULL;
- if (!hItem) return NULL;
- hNav = (HNAVCTRL)GetPropW(((NAVITM*)hItem)->hwndTree, NAVMGR_HWNDPROPW);
- if (!hNav) return NULL;
- cx = DRAGIMAGE_OFFSET_X;
- cy = (INT)SendMessageW(((NAVITM*)hItem)->hwndTree, TVM_GETITEMHEIGHT, (WPARAM)0, (LPARAM)0L) + 2*DRAGIMAGE_OFFSET_Y;
- if (!cy) return NULL;
- hdcScreen = GetDCEx(((NAVITM*)hItem)->hwndTree, NULL, DCX_WINDOW | DCX_CACHE);
- hdcMem = (hdcScreen) ? CreateCompatibleDC(NULL) : NULL;
- if (!hdcMem)
- {
- if (hdcScreen) ReleaseDC(((NAVITM*)hItem)->hwndTree, hdcScreen);
- return NULL;
- }
- SetRect(&rcText, 0,0,0,0);
- SetRect(&rcTip, 0,0,0,0);
- if (((NAVITM*)hItem)->pszText)
- {
- if (((NAVITM*)hItem)->hFont) hFont = ((NAVITM*)hItem)->hFont;
- else
- {
- hFont = (HFONT)::SendMessageW(((NAVITM*)hItem)->hwndTree, WM_GETFONT, 0, 0);
- if (NULL == hFont)
- hFont = (HFONT)MlStockObjects_Get(DEFAULT_FONT);
- if ((NIS_BOLD_I | NIS_ITALIC_I | NIS_UNDERLINE_I) & ((NAVITM*)hItem)->style)
- {
- LOGFONTW lf = { 0 };
- GetObjectW(hFont, sizeof(LOGFONTW), &lf);
- if (NIS_BOLD_I & ((NAVITM*)hItem)->style) lf.lfWeight = FW_BOLD;
- if (NIS_ITALIC_I & ((NAVITM*)hItem)->style) lf.lfItalic = TRUE;
- if (NIS_UNDERLINE_I & ((NAVITM*)hItem)->style) lf.lfUnderline = TRUE;
- hFont = CreateFontIndirectW(&lf);
- fDestroyFont = TRUE;
- }
- }
- if (hFont) hFontOld = (HFONT)SelectObject(hdcMem, hFont);
- DrawTextW(hdcMem, ((NAVITM*)hItem)->pszText, -1, &rcText, DT_CALCRECT | DT_NOPREFIX);
- if(rcText.bottom - rcText.top > cy) cy = (rcText.bottom - rcText.top) + 2;
- cx += ((rcText.right - rcText.left) + DRAGIMAGE_OFFSET_X);
- }
- ilIndex = -1;
- if (((NAVMNGR*)hNav)->hmlilImages)
- {
- hIL = (HIMAGELIST)SendMessageW(((NAVMNGR*)hNav)->hwndHost, TVM_GETIMAGELIST, (WPARAM)TVSIL_NORMAL, (LPARAM)0);
- if (hIL && MLImageListI_GetRealList(((NAVMNGR*)hNav)->hmlilImages) == hIL)
- {
- COLORREF rgbBk, rgbFg;
- GetItemColors(hNav, NIS_SELECTED_I | NIS_FOCUSED_I, &rgbBk, &rgbFg);
- ilIndex = GetRealImageIndex(hNav, (NAVITM*)hItem, IMAGE_SELECTED_I, rgbBk, rgbFg);
- }
- }
- else
- hIL = NULL;
- if (-1 != ilIndex && NULL != hIL)
- {
- IMAGEINFO ii;
- ImageList_GetImageInfo(hIL, ilIndex, &ii);
- cx += (ii.rcImage.right - ii.rcImage.left) + 5;
- SetRect(&rcImage, 0, 0, ii.rcImage.right - ii.rcImage.left, ii.rcImage.bottom - ii.rcImage.top);
- }
- else SetRect(&rcImage, 0,0,0,0);
- OffsetRect(&rcImage, DRAGIMAGE_OFFSET_X, ((cy - DRAGIMAGE_OFFSET_Y) - (rcImage.bottom - rcImage.top))/2);
- OffsetRect(&rcText, rcImage.right + ((rcImage.right != rcImage.left) ? 5 : 0), ((cy - DRAGIMAGE_OFFSET_Y) - (rcText.bottom - rcText.top))/2);
- if (pszTipText && *pszTipText)
- {
- HFONT hFontTmp;
- hFontTip = (HFONT)::SendMessageW(((NAVITM*)hItem)->hwndTree, WM_GETFONT, 0, 0);
- if (!hFontTip) hFontTip = (HFONT)MlStockObjects_Get(DEFAULT_FONT);
- hFontTmp = (HFONT)SelectObject(hdcMem, hFontTip);
- DrawTextW(hdcMem, pszTipText, -1, &rcTip, DT_CALCRECT | DT_NOPREFIX);
- SelectObject(hdcMem, hFontTmp);
- if (rcTip.right - rcTip.left > (cx - rcText.left + 3)) cx = rcText.left + (rcTip.right - rcTip.left) + 3;
- OffsetRect(&rcTip, rcText.left, cy + 1);
- cy += ((rcTip.bottom - rcTip.top) + 3);
- }
- hbmp = (3 != cx) ? CreateCompatibleBitmap(hdcScreen, cx, cy) : NULL;
- if (hbmp)
- {
- HGDIOBJ hgdiOld;
- RECT rc;
- hgdiOld = SelectObject(hdcMem, hbmp);
- SetBkColor(hdcMem, WADlg_getColor(WADLG_SELBAR_BGCOLOR));
- SetTextColor(hdcMem, WADlg_getColor(WADLG_SELBAR_FGCOLOR));
- SetRect(&rc, 0, 0, cx, cy);
- ExtTextOutW(hdcMem, 0, 0, ETO_OPAQUE, &rc, L"", 0, 0);
- if (hIL && -1 != ilIndex)
- {
- ImageList_DrawEx(hIL, ilIndex, hdcMem, rcImage.left, rcImage.top,
- (rcImage.right - rcImage.left), (rcImage.bottom - rcImage.top), CLR_DEFAULT, CLR_DEFAULT, ILD_NORMAL);
- }
- if (((NAVITM*)hItem)->pszText) DrawTextW(hdcMem, ((NAVITM*)hItem)->pszText, -1, &rcText, DT_NOPREFIX);
- if (pszTipText && *pszTipText)
- {
- HFONT hFontTmp;
- hFontTmp = (HFONT)SelectObject(hdcMem, hFontTip);
- DrawTextW(hdcMem, pszTipText, -1, &rcTip, DT_NOPREFIX);
- SelectObject(hdcMem, hFontTmp);
- }
- SelectObject(hdcMem, hgdiOld);
- hIL = ImageList_Create(cx, cy, ILC_COLOR24 | ILC_MASK, 0, 1);
- if (hIL && -1 == ImageList_Add(hIL, hbmp, NULL))
- {
- ImageList_Destroy(hIL);
- hIL = NULL;
- }
- DeleteObject(hbmp);
- }
- if (hFont)
- {
- SelectObject(hdcMem, hFontOld);
- if (fDestroyFont) DeleteObject(hFont);
- }
- // if (hFontTip) DeleteObject(hFontTip); // we not creating it...
- DeleteDC(hdcMem);
- ReleaseDC(((NAVITM*)hItem)->hwndTree, hdcScreen);
- return hIL;
- }
|