#include #include #include #include #include OwnerDraw::OwnerDraw(OwnerDraw::Usage sourceResource) : mhLibrary(0), mhInstance(0) { String dllPathFileName; mhInstance=instanceData(); if(OwnerDraw::UseLibrary==sourceResource) { ::GetWindowsDirectory(dllPathFileName,String::MaxString-1); #if defined(__FLAT__) dllPathFileName+="\\RESLIB32.DLL"; #else dllPathFileName+="\\RESLIB16.DLL"; #endif mhLibrary=::LoadLibrary(dllPathFileName); if((UINT)mhLibrary<32)mhLibrary=0; } return; } OwnerDraw::~OwnerDraw() { if(0!=mhLibrary)::FreeLibrary(mhLibrary); } int OwnerDraw::associate(int ctlID,String &focusUp,String &noFocusUp,String &focusDown,FocusItem focusItem) { int itemIndex; if(!(itemIndex=locateLinkedButton(ctlID)))mLinkedButtons.insert(&LinkedButton(ctlID,focusUp,noFocusUp,focusDown,mhLibrary?mhLibrary:mhInstance,(LinkedButton::FocusItem)focusItem)); else { itemIndex--; mLinkedButtons[itemIndex].referenceCount(mLinkedButtons[itemIndex].referenceCount()+1); } return TRUE; } int OwnerDraw::associate(int ctlID,String &focusUp,String &noFocusUp,String &focusDown,String &noFocusDisabled,FocusItem focusItem) { int itemIndex; if(!(itemIndex=locateLinkedButton(ctlID)))mLinkedButtons.insert(&LinkedButton(ctlID,focusUp,noFocusUp,focusDown,noFocusDisabled,mhLibrary?mhLibrary:mhInstance,(LinkedButton::FocusItem)focusItem)); else { itemIndex--; mLinkedButtons[itemIndex].referenceCount(mLinkedButtons[itemIndex].referenceCount()+1); } return TRUE; } int OwnerDraw::handleOwnerButton(int ctlID,LPARAM lParam) { int itemIndex; LPDRAWITEMSTRUCT lpControlData((LPDRAWITEMSTRUCT)lParam); if(!(itemIndex=locateLinkedButton(ctlID)))return FALSE; return mLinkedButtons[--itemIndex].drawButton(lpControlData); } void OwnerDraw::freeButton(int ctlID) { int itemIndex; if(!(itemIndex=locateLinkedButton(ctlID)))return; --itemIndex; if(mLinkedButtons[itemIndex].referenceCount()-1<=0)mLinkedButtons.remove(itemIndex); else mLinkedButtons[itemIndex].referenceCount(mLinkedButtons[itemIndex].referenceCount()-1); } int OwnerDraw::locateLinkedButton(int ctlID) { size_t size((int)mLinkedButtons.size()); for(int i=0;i