122 lines
3.1 KiB
C++
122 lines
3.1 KiB
C++
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <mdiwin/string.hpp>
|
|
#include <mdiwin/owner.hpp>
|
|
|
|
OwnerDraw::OwnerDraw()
|
|
: mhLibrary(0)
|
|
{
|
|
String dllPathFileName;
|
|
|
|
dllPathFileName.reserve(String::MaxString);
|
|
::GetWindowsDirectory(dllPathFileName,String::MaxString-1);
|
|
#if defined(__FLAT__)
|
|
dllPathFileName+="\\RESLIB32.DLL";
|
|
#else
|
|
dllPathFileName+="\\RESLIB16.DLL";
|
|
#endif
|
|
mhLibrary=::LoadLibrary(dllPathFileName);
|
|
if((UINT)mhLibrary<32)
|
|
::MessageBox(NULL,(LPSTR)"Could not load resource library!",(LPSTR)"RESOURCE ERROR",MB_ICONSTOP|MB_APPLMODAL);
|
|
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,(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<size;i++)if(mLinkedButtons[i]==ctlID)return i+1;
|
|
return 0;
|
|
}
|
|
|
|
// *******************************************************************************
|
|
|
|
int OwnerDraw::associate(int ctlID,String &bitmapName)
|
|
{
|
|
int itemIndex;
|
|
|
|
if(!(itemIndex=locateLinkedBitmap(ctlID)))mLinkedBitmaps.insert(&LinkedBitmap(ctlID,bitmapName,mhLibrary));
|
|
else
|
|
{
|
|
itemIndex--;
|
|
mLinkedBitmaps[itemIndex].referenceCount(mLinkedBitmaps[itemIndex].referenceCount()+1);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void OwnerDraw::drawBitmap(int ctlID,HWND hWnd,RECT locationRect)
|
|
{
|
|
int itemIndex;
|
|
HDC hDC;
|
|
|
|
::SetRect((RECT FAR *)&locationRect,0,0,0,0);
|
|
if(!(itemIndex=locateLinkedBitmap(ctlID)))return;
|
|
--itemIndex;
|
|
hDC=::GetDC(hWnd);
|
|
mLinkedBitmaps[itemIndex].drawBitmap(hDC,locationRect);
|
|
}
|
|
|
|
void OwnerDraw::drawBitmap(int ctlID)
|
|
{
|
|
int itemIndex;
|
|
|
|
if(!(itemIndex=locateLinkedBitmap(ctlID)))return;
|
|
--itemIndex;
|
|
mLinkedBitmaps[itemIndex].drawBitmap();
|
|
}
|
|
|
|
void OwnerDraw::freeBitmap(int ctlID)
|
|
{
|
|
int itemIndex;
|
|
|
|
if(!(itemIndex=locateLinkedBitmap(ctlID)))return;
|
|
--itemIndex;
|
|
if(mLinkedBitmaps[itemIndex].referenceCount()-1<=0)mLinkedBitmaps.remove(itemIndex);
|
|
else mLinkedBitmaps[itemIndex].referenceCount(mLinkedBitmaps[itemIndex].referenceCount()-1);
|
|
}
|
|
|
|
int OwnerDraw::locateLinkedBitmap(int ctlID)
|
|
{
|
|
size_t size((int)mLinkedBitmaps.size());
|
|
|
|
for(int i=0;i<size;i++)if(mLinkedBitmaps[i]==ctlID)return i+1;
|
|
return 0;
|
|
} |