www.pudn.com > 1.rar > I2Control.cpp
// I2Control.cpp: implementation of the CI2WBControl class.
#include "stdafx.h"
#include "e:\src\iaspwb\iaspwb.h"
#include "resource.h"
//I2MemoryFileStream g_imgfile(1024);
CI2WBControl::CI2WBControl(INT cid,VOID* pwb,HWND hwnd)
{
m_pttrackstart.x=0;
m_pttrackstart.y=0;
m_prev.x=-1;
m_prev.y=-1;
m_cid=cid;
m_csid=CSID_Draw;
m_state=0;
m_wb=(CI2WBBaseWB *)pwb;
m_wb->get_LineWidth(&cinfo.m_linewidth);
m_wb->get_LineStyle(&cinfo.m_linestyle);
m_wb->get_Color(&cinfo.m_color);
m_wb->get_BKColor(&cinfo.m_bkcolor);
m_wb->get_Font(&cinfo.m_font,WB_FONT_ALL);
m_rect.left=-1;
m_grprect.left=-1;
m_property=0;
switch(cid)
{
case Draw_Pen:
m_type=dtPen;
break;
case Draw_Line:
m_type=dtLine;
m_property=m_property|WB_PROP_CHANGE;
break;
case Draw_HRect:
m_type=dtHRect;
m_property=m_property|WB_PROP_CHANGE;
break;
case Draw_Rect:
m_type=dtRect;
m_property=m_property|WB_PROP_CHANGE;
break;
case Draw_HCirc:
m_type=dtHCirc;
m_property=m_property|WB_PROP_CHANGE;
break;
case Draw_Circ:
m_type=dtCirc;
m_property=m_property|WB_PROP_CHANGE;
break;
case Draw_HPoly:
m_type=dtHPoly;
break;
case Draw_Poly:
m_type=dtPoly;
break;
case Draw_Text:
m_type=dtText;
break;
case Draw_Image:
m_type=dtImage;
break;
case Draw_ImageGif:
m_type=dtImageGif;
break;
case Draw_ImageJpeg:
m_type=dtImageJpeg;
break;
case Draw_ImageMeta:
m_type=dtImageMeta;
break;
}
m_prev.x=-1;
m_prev.y=-1;
m_pos.x=-1;
m_pos.y=-1;
m_name[0]='\0';
m_grpname[0]='\0';
m_text=NULL;
m_state=0;
m_imgfile=new I2MemoryFileStream(1024);
m_hdc=NULL;
m_hwnd=hwnd;
}
CI2WBControl::~CI2WBControl()
{
delete m_imgfile;
if(m_hdc)
{
ReleaseDC(m_hwnd,m_hdc);
// fclose(m_file);
}
}
VOID CI2WBControl::getControlRect(I2Rect& Value)
{
INT lw;
I2Rect r(MAXLONG,MAXLONG,0,0);
m_wb->get_LineWidth(&lw);
switch(m_type)
{
case dtPen:
rectFromPointList(Value);
InflateRect(&Value,lw/2+1,lw/2+1);
break;
case dtLine:
rectFromPointList(Value);
InflateRect(&Value,lw/2+1,lw/2+1);
break;
case dtHRect:
case dtRect:
Value=m_rect;
InflateRect(&Value,lw+2,lw+2);
break;
case dtHCirc:
case dtCirc:
Value=m_rect;
InflateRect(&Value,lw/2+1,lw/2+1);
break;
case dtHPoly:
rectFromPoly(Value);
InflateRect(&Value,lw/2+1,lw/2+1);
break;
case dtPoly:
rectFromPoly(Value);
InflateRect(&Value,lw/2+1,lw/2+1);
break;
case dtText:
{
RECT rect={MAXLONG,MAXLONG,0,0};
HDC hdc=CreateCompatibleDC(NULL);
HFONT hfont=m_wb->createWBFont(&cinfo.m_font);
HFONT holdfont=(HFONT)SelectObject(hdc,hfont);
DrawText(hdc,m_text,-1,&rect,DT_CALCRECT|DT_EDITCONTROL|DT_NOPREFIX|DT_EXPANDTABS);
SelectObject(hdc,holdfont);
DeleteObject(hfont);
DeleteDC(hdc);
SetRect(&Value,m_pos.x,m_pos.y,m_pos.x+rect.right-rect.left,m_pos.y+rect.bottom-rect.top);
}
break;
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
Value=m_rect;
InflateRect(&Value,2,2);
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
}
}
VOID CI2WBControl::rectFromPointList(I2Rect& rect)
{
I2Rect r(MAXLONG,MAXLONG,0,0);
INT i;
for(i=0;ir.right)r.right=x;
if(y>r.bottom)r.bottom=y;
}
rect=r;
}
VOID CI2WBControl::rectFromPoly(I2Rect& rect)
{
I2Rect r(MAXLONG,MAXLONG,0,0);
INT i;
for(i=0;ir.right)r.right=x;
if(y>r.bottom)r.bottom=y;
}
rect=r;
}
VOID CI2WBControl::paintControl(HDC hdc)
{
switch(m_type)
{
case dtPen:
paintPen(hdc);
break;
case dtLine:
paintLine(hdc);
break;
case dtHRect:
paintHRect(hdc);
break;
case dtRect:
paintRect(hdc);
break;
case dtHCirc:
paintHCirc(hdc);
break;
case dtCirc:
paintCirc(hdc);
break;
case dtHPoly:
paintHPoly(hdc);
break;
case dtPoly:
paintPoly(hdc);
break;
case dtText:
paintText(hdc);
break;
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
paintImage(hdc);
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
}
void CI2WBControl::OnLButtonDown(DWORD fwKeys,SHORT x,SHORT y,HWND hwnd,INT* fend)
{
POINT p={x,y};
beginTrack(&tracktype);
switch(tracktype)
{
case TRACKTYPE_POINT:
{
HDC hdc=GetDC(hwnd);
trackPoint(hdc,p);
ReleaseDC(hwnd,hdc);
}
break;
case TRACKTYPE_RECT:
m_pttrackstart.x=x;
m_pttrackstart.y=y;
SetCapture(hwnd);
break;
case TRACKTYPE_CLICK:
POINT p={x,y};
HDC hdc=GetDC(hwnd);
trackClick(hdc,p,TRUE);
ReleaseDC(hwnd,hdc);
break;
}
}
void CI2WBControl::OnMouseMove(DWORD fwKeys,SHORT x,SHORT y,HWND hwnd,INT* fend)
{
POINT p={x,y};
HDC hdc=GetDC(hwnd);
switch(tracktype)
{
case TRACKTYPE_POINT:
trackPoint(hdc,p);
break;
case TRACKTYPE_RECT:
{
I2Rect rect(
m_pttrackstart.xm_dlgexist=1;
CPropertyDlg* propertydlg;
_g_i2hresinst=GetModuleHandle("iaspwb.dll");
propertydlg=new CPropertyDlg(this);
m_wb->m_propdlg=propertydlg;
propertydlg->showModal(IDD_PROPERTY,hwnd);
if(propertydlg->m_pressok==1)
{
m_wb->m_dlgexist=0;
m_wb->m_propdlg=NULL;
delete propertydlg;
return 0;
}
delete propertydlg;
return -1;
}
void CI2WBControl::writeToStream(I2MemoryFileStream *stm,BOOL fdata)
{
// d::s("writeToStream");
WB32CONTROLDATA wcd;
wcd.cid=m_cid;
wcd.csid=m_csid;
wcd.len=0;
lstrcpy(wcd.idname,m_name);
//d::s("wcd.idname %s",wcd.idname);
lstrcpy(wcd.idgrpname,m_grpname);
getControlRect(wcd.rect);
get_GrpRect(&wcd.grprect);
if(fdata)
{
switch(m_type)
{
case dtPen:
case dtLine:
wcd.len=m_ptlist.get_Count()*sizeof(POINT)+sizeof(WB32CONTROLATTRIB);
break;
case dtHRect:
case dtRect:
case dtHCirc:
case dtCirc:
wcd.len=sizeof(WB32CONTROLATTRIB);
wcd.rect=m_rect;
break;
case dtHPoly:
case dtPoly:
wcd.len=m_poly.get_Count()*sizeof(POINT)+sizeof(WB32CONTROLATTRIB);
break;
case dtText:
if(m_text)
wcd.len=strlen(m_text)+sizeof(POINT)+1+sizeof(WB32CONTROLATTRIB);
break;
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
wcd.len=m_imgfile->get_Length()+sizeof(POINT)+sizeof(WB32CONTROLATTRIB);
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
}
stm->writeFile((CHAR*)&wcd,sizeof(WB32CONTROLDATA));
if(fdata)
{
stm->writeFile((CHAR*)&cinfo,sizeof(WB32CONTROLATTRIB));
switch(m_type)
{
case dtPen:
case dtLine:
stm->writeFile((CHAR*)m_ptlist.get_Items(),sizeof(POINT)*m_ptlist.get_Count());
break;
case dtHRect:
case dtRect:
case dtHCirc:
case dtCirc:
break;
case dtHPoly:
case dtPoly:
stm->writeFile((CHAR*)m_poly.get_Items(),sizeof(POINT)*m_poly.get_Count());
break;
case dtText:
if(m_text)
{
stm->writeFile((CHAR*)&m_pos,sizeof(POINT));
stm->writeFile(m_text,lstrlen(m_text)+1);
}
break;
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
stm->writeFile((CHAR*)&m_pos,sizeof(POINT));
stm->writeFile((CHAR*)m_imgfile->get_Pointer(),m_imgfile->get_Length());
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}//end switch
}//end if(fdata)
}
VOID CI2WBControl::readFromStream(I2MemoryFileStream *stm,INT len,const I2Rect& r)
{
VOID *p;
int count=0;
if(len)
{
stm->readFile((CHAR*)&cinfo,sizeof(WB32CONTROLATTRIB));
p=GlobalAlloc(GPTR,len-sizeof(WB32CONTROLATTRIB));
stm->readFile((CHAR*)p,len-sizeof(WB32CONTROLATTRIB));
count=(len-sizeof(WB32CONTROLATTRIB))/sizeof(POINT);
}
switch(m_type)
{
case dtPen:
m_ptlist.setItems((CHAR*)p,count,count);
break;
case dtLine:
if(len)
m_ptlist.setItems((CHAR*)p,count,count);
else
OnChangeData((RECT)r);
break;
case dtHRect:
m_rect=r;
break;
case dtRect:
m_rect=r;
break;
case dtHCirc:
m_rect=r;
break;
case dtCirc:
m_rect=r;
break;
case dtHPoly:
m_poly.setItems((CHAR*)p,count,count);
break;
case dtPoly:
m_poly.setItems((CHAR*)p,count,count);
break;
case dtText:
{
if(len)
{
m_pos=*(POINT*)((CHAR*)p);
m_text=SysAllocAnsiString((CHAR*)p+sizeof(POINT));
}
//len=strlen(m_text)+sizeof(POINT)+1+sizeof(WB32CONTROLATTRIB);
//int lenm=sizeof(WB32CONTROLATTRIB);
//*(m_text+len-sizeof(WB32CONTROLATTRIB)-1)='\0';//tmp
}
break;
case dtImage:
{
m_pos=*(POINT*)((CHAR*)p);
m_imgfile->set_Length(0);
m_imgfile->seekFile(0,I2SEEK_SET);
m_imgfile->writeFile((CHAR*)p+sizeof(POINT),len-sizeof(WB32CONTROLATTRIB)-sizeof(POINT));
m_imgfile->seekFile(0,I2SEEK_SET);
m_img.loadStreamBitmap(*m_imgfile);
SIZE size=m_img.get_Size();
SetRect(&m_rect,m_pos.x,m_pos.y,m_pos.x+size.cx,m_pos.y+size.cy);
}
break;
case dtImageGif:
{
m_pos=*(POINT*)((CHAR*)p);
m_imgfile->set_Length(0);
m_imgfile->seekFile(0,I2SEEK_SET);
m_imgfile->writeFile((CHAR*)p+sizeof(POINT),len-sizeof(WB32CONTROLATTRIB)-sizeof(POINT));
m_imgfile->seekFile(0,I2SEEK_SET);
m_img.loadStreamGif(*m_imgfile);
SIZE size=m_img.get_Size();
SetRect(&m_rect,m_pos.x,m_pos.y,m_pos.x+size.cx,m_pos.y+size.cy);
}
break;
case dtImageJpeg:
{
char buf[256];
m_pos=*(POINT*)((CHAR*)p);
I2SDKFileStream *file;
GetSystemDirectory(buf,256);
*(strrchr(buf,'\\')+1)='\0';
lstrcat(buf,"\\temp\\tmp0001.jpg");
file=new I2SDKFileStream(buf,CREATE_ALWAYS);
file->seekFile(0,I2SEEK_SET);
file->writeFile((CHAR*)p+sizeof(POINT),len-sizeof(WB32CONTROLATTRIB)-sizeof(POINT));
delete file;
m_imgfile->set_Length(0);
m_imgfile->seekFile(0,I2SEEK_SET);
m_imgfile->writeFile((CHAR*)p+sizeof(POINT),len-sizeof(WB32CONTROLATTRIB)-sizeof(POINT));
m_hdc=GetDC(m_hwnd);
m_img.loadStreamJpeg(m_hdc,buf);
SIZE size=m_img.get_Size();
SetRect(&m_rect,m_pos.x,m_pos.y,m_pos.x+size.cx,m_pos.y+size.cy);
}
break;
case dtImageMeta:
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
if(len)
GlobalFree(p);
}
VOID CI2WBControl::beginTrack(INT* tracktype)
{
switch(m_type)
{
case dtPen:
*tracktype=TRACKTYPE_POINT;
break;
case dtLine:
*tracktype=TRACKTYPE_POINT;
break;
case dtHRect:
*tracktype=TRACKTYPE_RECT;
break;
case dtRect:
*tracktype=TRACKTYPE_RECT;
break;
case dtHCirc:
*tracktype=TRACKTYPE_RECT;
break;
case dtCirc:
*tracktype=TRACKTYPE_RECT;
break;
case dtHPoly:
*tracktype=TRACKTYPE_CLICK;
break;
case dtPoly:
*tracktype=TRACKTYPE_CLICK;
break;
case dtText:
break;
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
}
VOID CI2WBControl::trackPoint(HDC hdc,POINT p)
{
switch(m_type)
{
case dtPen:
if(m_ptlist.get_Count()>120)
break;
m_ptlist.append(p);
if(m_prev.x==-1)
m_prev=p;
else
{
HPEN holdpen,hpen;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
MoveToEx(hdc,m_prev.x,m_prev.y,NULL);
LineTo(hdc,p.x,p.y);
SelectObject(hdc,holdpen);
DeleteObject(hpen);
m_prev=p;
}
break;
case dtLine:
if(m_prev.x==-1)
{
m_prev=p;
m_ptlist.append(p);
}
else
{
if(m_ptlist.get_Count()==2)
m_ptlist.Delete(m_ptlist.get_Count()-1);
m_ptlist.append(p);
HPEN holdpen,hpen;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
SetROP2(hdc,R2_NOTXORPEN);
SHORT x,y;
x=(SHORT)(m_ptlist.get_Items()[0]).x;
y=(SHORT)(m_ptlist.get_Items()[0]).y;
MoveToEx(hdc,x,y,NULL);
LineTo(hdc,m_prev.x,m_prev.y);
MoveToEx(hdc,x,y,NULL);
LineTo(hdc,p.x,p.y);
SelectObject(hdc,holdpen);
DeleteObject(hpen);
m_prev=p;
}
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
}
VOID CI2WBControl::endTrackPoint(HDC hdc,POINT p)
{
switch(m_type)
{
case dtPen:
if(m_ptlist.get_Count()>120)
break;
m_ptlist.append(p);
if(m_prev.x!=-1)
{
HPEN holdpen,hpen;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
MoveToEx(hdc,m_prev.x,m_prev.y,NULL);
LineTo(hdc,p.x,p.y);
SelectObject(hdc,holdpen);
DeleteObject(hpen);
}
break;
case dtLine:
if(m_ptlist.get_Count()==2)
m_ptlist.Delete(m_ptlist.get_Count()-1);
m_ptlist.append(p);
if(m_prev.x!=-1)
{
HPEN holdpen,hpen;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
SHORT x,y;
x=(SHORT)(m_ptlist.get_Items()[0].x);
y=(SHORT)(m_ptlist.get_Items()[0].y);
MoveToEx(hdc,x,y,NULL);
LineTo(hdc,p.x,p.y);
SelectObject(hdc,holdpen);
DeleteObject(hpen);
}
break;
case dtHRect:
case dtRect:
case dtHCirc:
case dtCirc:
case dtHPoly:
case dtPoly:
case dtText:
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
}
VOID CI2WBControl::trackRect(HDC hdc,const I2Rect& r)
{
HPEN holdpen,hpen;
HBRUSH holdbrush,hbrush;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
SetROP2(hdc,R2_NOTXORPEN);
switch(m_type)
{
case dtPen:
case dtLine:
case dtHPoly:
case dtPoly:
case dtText:
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
break;
case dtHRect://paint hollow rectangle
// Rectangle(hdc,m_pttrackstart.x,m_pttrackstart.y,x,y);
MoveToEx(hdc,cinfo.m_rect.left,cinfo.m_rect.top,NULL);
LineTo(hdc,cinfo.m_rect.right,cinfo.m_rect.top);
LineTo(hdc,cinfo.m_rect.right,cinfo.m_rect.bottom);
LineTo(hdc,cinfo.m_rect.left,cinfo.m_rect.bottom);
LineTo(hdc,cinfo.m_rect.left,cinfo.m_rect.top);
cinfo.m_rect=r;
MoveToEx(hdc,cinfo.m_rect.left,cinfo.m_rect.top,NULL);
LineTo(hdc,cinfo.m_rect.right,cinfo.m_rect.top);
LineTo(hdc,cinfo.m_rect.right,cinfo.m_rect.bottom);
LineTo(hdc,cinfo.m_rect.left,cinfo.m_rect.bottom);
LineTo(hdc,cinfo.m_rect.left,cinfo.m_rect.top);
/* m_pttrackstart.x=x;
m_pttrackstart.y=y;
Rectangle(hdc,m_pttrackstart.x,m_pttrackstart.y,x,y);
*/
break;
case dtRect: //paint filled rectangle
hbrush=(HBRUSH)CreateSolidBrush(cinfo.m_bkcolor);
holdbrush=(HBRUSH)SelectObject(hdc,hbrush);
if(cinfo.m_rect.left==-1)
Rectangle(hdc,r.left,r.top,r.right,r.bottom);
else
{
Rectangle(hdc,cinfo.m_rect.left,cinfo.m_rect.top,cinfo.m_rect.right,cinfo.m_rect.bottom);
Rectangle(hdc,r.left,r.top,r.right,r.bottom);
}
cinfo.m_rect=r;
SelectObject(hdc,holdbrush);
DeleteObject(hbrush);
break;
case dtHCirc://paint hollow circle
if(cinfo.m_rect.left==-1)
Arc(hdc, r.left,r.top,r.right,r.bottom,r.left,
(r.bottom-r.top)/2,r.left,(r.bottom-r.top)/2);
else
{
Arc(hdc, r.left,r.top,r.right,r.bottom,r.left,
(r.bottom-r.top)/2,r.left,(r.bottom-r.top)/2);
Arc(hdc, cinfo.m_rect.left,cinfo.m_rect.top,cinfo.m_rect.right,cinfo.m_rect.bottom,cinfo.m_rect.left,
(cinfo.m_rect.bottom-cinfo.m_rect.top)/2,cinfo.m_rect.left,(cinfo.m_rect.bottom-cinfo.m_rect.top)/2);
}
cinfo.m_rect=r;
break;
case dtCirc://paint filled circle
hbrush=(HBRUSH)CreateSolidBrush(cinfo.m_bkcolor);
holdbrush=(HBRUSH)SelectObject(hdc,hbrush);
if(cinfo.m_rect.left==-1)
Chord(hdc, r.left,r.top,r.right,r.bottom,r.left,
(r.bottom-r.top)/2,r.left,(r.bottom-r.top)/2);
else
{
Chord(hdc, r.left,r.top,r.right,r.bottom,r.left,
(r.bottom-r.top)/2,r.left,(r.bottom-r.top)/2);
Chord(hdc, cinfo.m_rect.left,cinfo.m_rect.top,cinfo.m_rect.right,cinfo.m_rect.bottom,cinfo.m_rect.left,
(cinfo.m_rect.bottom-cinfo.m_rect.top)/2,cinfo.m_rect.left,(cinfo.m_rect.bottom-cinfo.m_rect.top)/2);
}
cinfo.m_rect=r;
SelectObject(hdc,holdbrush);
DeleteObject(hbrush);
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
SelectObject(hdc,holdpen);
DeleteObject(hpen);
}
VOID CI2WBControl::endTrackRect(HDC hdc,const I2Rect& r)
{
HPEN holdpen,hpen;
HBRUSH hbrush,m_oldbrush;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
switch(m_type)
{
case dtPen:
case dtLine:
case dtHPoly:
case dtPoly:
case dtText:
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
break;
case dtHRect:
if(cinfo.m_rect.left!=-1)
{
cinfo.m_rect=r;
MoveToEx(hdc,cinfo.m_rect.left,cinfo.m_rect.top,NULL);
LineTo(hdc,cinfo.m_rect.right,cinfo.m_rect.top);
LineTo(hdc,cinfo.m_rect.right,cinfo.m_rect.bottom);
LineTo(hdc,cinfo.m_rect.left,cinfo.m_rect.bottom);
LineTo(hdc,cinfo.m_rect.left,cinfo.m_rect.top);
}
break;
case dtRect:
if(cinfo.m_rect.left!=-1)
{
hbrush=CreateSolidBrush(cinfo.m_bkcolor);
m_oldbrush=(HBRUSH)SelectObject(hdc,hbrush);
Rectangle(hdc,cinfo.m_rect.left,cinfo.m_rect.top,cinfo.m_rect.right,cinfo.m_rect.bottom);
Rectangle(hdc,r.left,r.top,r.right,r.bottom);
SelectObject(hdc,m_oldbrush);
DeleteObject(hbrush);
}
break;
case dtHCirc:
if(cinfo.m_rect.left!=-1)
{
Arc(hdc, cinfo.m_rect.left,cinfo.m_rect.top,cinfo.m_rect.right,cinfo.m_rect.bottom,cinfo.m_rect.left,
(cinfo.m_rect.bottom-cinfo.m_rect.top)/2,cinfo.m_rect.left,(cinfo.m_rect.bottom-cinfo.m_rect.top)/2);
}
break;
case dtCirc:
hbrush=CreateSolidBrush(cinfo.m_bkcolor);
m_oldbrush=(HBRUSH)SelectObject(hdc,hbrush);
if(cinfo.m_rect.left!=-1)
Chord(hdc, cinfo.m_rect.left,cinfo.m_rect.top,cinfo.m_rect.right,cinfo.m_rect.bottom,cinfo.m_rect.left,
(cinfo.m_rect.bottom-cinfo.m_rect.top)/2,cinfo.m_rect.left,(cinfo.m_rect.bottom-cinfo.m_rect.top)/2);
SelectObject(hdc,m_oldbrush);
DeleteObject(hbrush);
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
SelectObject(hdc,holdpen);
DeleteObject(hpen);
}
VOID CI2WBControl::trackClick(HDC hdc,POINT p,BOOL fclick)
{
switch(m_type)
{
case dtHPoly:
case dtPoly:
m_poly.append(p);
if(m_prev.x==-1)
m_prev=p;
else
{
HPEN holdpen,hpen;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
MoveToEx(hdc,m_prev.x,m_prev.y,NULL);
LineTo(hdc,p.x,p.y);
SelectObject(hdc,holdpen);
DeleteObject(hpen);
m_prev=p;
}
break;
case dtPen:
case dtLine:
case dtHRect:
case dtRect:
case dtHCirc:
case dtCirc:
case dtText:
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
}
VOID CI2WBControl::endTrackClick(HDC hdc,POINT p)
{
if(m_prev.x!=-1)
{
SHORT i;
HPEN holdpen,hpen;
HBRUSH hbrush,oldbrush;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
hbrush=(HBRUSH)CreateSolidBrush(cinfo.m_bkcolor);
oldbrush=(HBRUSH)SelectObject(hdc,hbrush);
switch(m_type)
{
case dtHPoly:
SHORT x,y;
MoveToEx(hdc,m_prev.x,m_prev.y,NULL);
x=(SHORT)(m_poly.get_Items()[0].x);
y=(SHORT)(m_poly.get_Items()[0].y);
LineTo(hdc,x,y);
break;
case dtPoly:
POINT *point;
point=(POINT *)GlobalAlloc(GPTR,sizeof(POINT)*m_poly.get_Count());
for(i=0;ix=(SHORT)(m_poly.get_Items()[i].x);
(point+i)->y=(SHORT)(m_poly.get_Items()[i].y);
}
SetPolyFillMode(hdc,WINDING);
Polygon(hdc,(LPPOINT)point,m_poly.get_Count());
GlobalFree(point);
break;
case dtPen:
case dtLine:
case dtHRect:
case dtRect:
case dtHCirc:
case dtCirc:
case dtText:
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
SelectObject(hdc,holdpen);
SelectObject(hdc,oldbrush);
DeleteObject(hbrush);
DeleteObject(hpen);
}
}
VOID CI2WBControl::paintPen(HDC hdc)
{
if(m_ptlist.get_Count()<1)
return;
HPEN holdpen,hpen;
hpen=CreatePen(cinfo.m_linestyle,cinfo.m_linewidth,cinfo.m_color);
holdpen=(HPEN)SelectObject(hdc,hpen);
INT i;
SHORT x,y;
x=(SHORT)(m_ptlist.get_Items()[0].x);
y=(SHORT)(m_ptlist.get_Items()[0].y);
MoveToEx(hdc,x,y,NULL);
for(i=1;ix=(SHORT)(m_poly.get_Items()[i].x);
(point+i)->y=(SHORT)(m_poly.get_Items()[i].y);
}
SetPolyFillMode(hdc,WINDING);
Polygon(hdc,(LPPOINT)point,m_poly.get_Count());
GlobalFree(point);
SelectObject(hdc,holdpen);
SelectObject(hdc,hbrush);
DeleteObject(hbrush);
DeleteObject(hpen);
return;
}
VOID CI2WBControl::paintText(HDC hdc)
{
if(m_pos.x==-1)
return;
HFONT hfont=m_wb->createWBFont(&cinfo.m_font);
HFONT holdfont=(HFONT)SelectObject(hdc,hfont);
SetTextColor(hdc,cinfo.m_color);
int oldmode=SetBkMode(hdc,TRANSPARENT);
RECT r={m_pos.x,m_pos.y,0,0};
DrawText(hdc,m_text,-1,&r,DT_CALCRECT|DT_EDITCONTROL|DT_NOPREFIX|DT_EXPANDTABS);
DrawText(hdc,m_text,-1,&r,DT_EDITCONTROL|DT_NOPREFIX|DT_EXPANDTABS);
SetBkMode(hdc,oldmode);
SelectObject(hdc,holdfont);
DeleteObject(hfont);
}
VOID CI2WBControl::paintImage(HDC hdc)
{
if(m_pos.x==-1)
return;
m_pos.x=m_rect.left;
m_pos.y=m_rect.top;
switch(m_type)
{
case dtImageJpeg:
m_img.drawJpeg(m_hdc,m_pos.x,m_pos.y,m_rect.right-m_rect.left,m_rect.bottom-m_rect.top);
break;
case dtImage:
case dtImageGif:
case dtImageMeta:
m_img.draw(hdc,m_pos.x,m_pos.y,0,0,0,0);
break;
}
}
VOID CI2WBControl::moveTo(INT xoffset,INT yoffset)
{
if(m_state&CTRLSTATE_LOCKED)
return;
switch(m_type)
{
case dtPen:
case dtLine:
movePointList(xoffset,yoffset);
break;
case dtHRect:
case dtRect:
case dtHCirc:
case dtCirc:
moveRect(xoffset,yoffset);
break;
case dtHPoly:
case dtPoly:
movePoly(xoffset,yoffset);
break;
case dtText:
m_pos.x+=xoffset;
m_pos.y+=yoffset;
break;
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
moveRect(xoffset,yoffset);
break;
default:
throw new I2BaseException(I2E_NOTSUPPORT);
break;
}
}
VOID CI2WBControl::movePointList(INT xoffset,INT yoffset)
{
INT i;
POINT p;
POINT *ptr;
ptr=m_ptlist.get_Items();
for(i=0;iget_LineWidth(&cinfo.m_linewidth);
if(type == WBAT_LINESTYLE)
m_wb->get_LineStyle(&cinfo.m_linestyle);
if(type == WBAT_COLOR)
m_wb->get_Color(&cinfo.m_color);
if(type == WBAT_BKCOLOR)
m_wb->get_BKColor(&cinfo.m_bkcolor);
if(type == WBAT_FONT)
m_wb->get_Font(&cinfo.m_font,mask);
}
}
LPSTR CI2WBControl::SysAllocAnsiString(LPSTR sz)
{
if(!sz)
return NULL;
LPSTR rsz;
if((rsz=(LPSTR)CoTaskMemAlloc(lstrlen(sz)+1))!=NULL)
lstrcpy(rsz,sz);
return rsz;
}
VOID CI2WBControl::OnInplaceEditorNeedText(LPWB32FONT pfont,LPSTR* ptext)
{
if(!pfont||!ptext)
throw new I2BaseException(I2E_NOTSUPPORT);
CopyMemory(pfont,&cinfo.m_font,sizeof(WB32FONT));
*ptext=SysAllocAnsiString(m_text);
CoTaskMemFree(m_text);
m_text=NULL;
}
VOID CI2WBControl::OnInplaceEditorReturnText(POINT pos,LPSTR text)
{
if(!text)
throw new I2BaseException(I2E_NOTSUPPORT);
if(m_text)
CoTaskMemFree(m_text);
m_pos=pos;
m_text=SysAllocAnsiString(text);
}
VOID CI2WBControl::set_Font(WB32FONT* pfont,INT mask)
{
switch(mask)
{
case WB_FONT_NAME:
lstrcpy(cinfo.m_font.name,pfont->name);
break;
case WB_FONT_SIZE:
cinfo.m_font.size=pfont->size;
break;
case WB_FONT_BOLD:
if(pfont->style&WBFS_BOLD)
cinfo.m_font.style=pfont->style|WBFS_BOLD;
else
cinfo.m_font.style=pfont->style^WBFS_BOLD;
break;
case WB_FONT_ITAL:
if(pfont->style&WBFS_ITALIC)
cinfo.m_font.style=pfont->style|WBFS_ITALIC;
else
cinfo.m_font.style=pfont->style^WBFS_ITALIC;
break;
case WB_FONT_UNDE:
if(pfont->style&WBFS_UNDERLINE)
cinfo.m_font.style=pfont->style|WBFS_UNDERLINE;
else
cinfo.m_font.style=pfont->style^WBFS_UNDERLINE;
break;
case WB_FONT_ALL:
cinfo.m_font=*pfont;
break;
}
}
BOOL CI2WBControl::OnDragFile(LPSTR filename,POINT p,CHAR* ptr,HWND hwnd)
{
CHAR *pdata;
DWORD filelen,nBytesRead;
BOOL bResult;
HANDLE stream;
I2MemoryFileStream stm(1024);
VOID *pt=NULL;
INT len;
m_pos=p;
if(!lstrcmp(ptr,"bmp"))
{//draw bmp
try
{
I2SDKFileStream fstm(filename);
m_img.loadStreamBitmap(fstm);
SIZE size=m_img.get_Size();
SetRect(&m_rect,p.x,p.y,p.x+size.cx,p.y+size.cy);
fstm.seekFile(0,I2SEEK_SET);
len=fstm.get_Length();
pt=GlobalAlloc(GPTR,len);
fstm.readFile((CHAR*)pt,len);
m_imgfile->set_Length(0);
m_imgfile->writeFile((CHAR*)pt,len);
if(pt)
GlobalFree(pt);
}
catch(I2Exception *e)
{
d::s("OnDragFile");
e->report();
e->Delete();
return FALSE;
}
}
else if(!lstrcmp(ptr,"gif"))
{//draw gif
try
{
I2SDKFileStream fstm(filename);
m_img.loadStreamGif(fstm);
SIZE size=m_img.get_Size();
SetRect(&m_rect,p.x,p.y,p.x+size.cx,p.y+size.cy);
fstm.seekFile(0,I2SEEK_SET);
len=fstm.get_Length();
pt=GlobalAlloc(GPTR,len);
fstm.readFile((CHAR*)pt,len);
m_imgfile->set_Length(0);
m_imgfile->writeFile((CHAR*)pt,len);
GlobalFree(pt);
}
catch(I2Exception *e)
{
d::s("OnDragFile Gif");
e->report();
e->Delete();
return FALSE;
}
}
else if(!lstrcmp(ptr,"jpg"))
{//draw jpeg
/* m_hdc=GetDC(hwnd);
m_hwnd=hwnd;
if((m_file=fopen(filename,"rb"))==NULL)
throw new I2BaseException(I2E_CANNTOPENFILE);
m_img.readmyfile(m_file);
//m_img.loadStreamJpeg(m_hdc,&m_file);
SIZE size=m_img.get_Size();
SetRect(&m_rect,p.x,p.y,p.x+size.cx,p.y+size.cy);
*/
m_hdc=GetDC(hwnd);
m_hwnd=hwnd;
m_img.loadStreamJpeg(m_hdc,filename);
SIZE size=m_img.get_Size();
SetRect(&m_rect,p.x,p.y,p.x+size.cx,p.y+size.cy);
I2SDKFileStream fstm(filename);
len=fstm.get_Length();
pt=GlobalAlloc(GPTR,len);
fstm.readFile((CHAR*)pt,len);
m_imgfile->set_Length(0);
m_imgfile->writeFile((CHAR*)pt,len);
GlobalFree(pt);
//m_img.drawJpeg(m_hdc,p.x,p.y,p.x+size.cx,p.y+size.cy);
/* m_hdc=GetDC(hwnd);
m_hwnd=hwnd;
I2String str;
str=filename;
I2RTLFileStream fstm(str,"rb");
//m_img.loadStreamJpeg(m_hdc,&fstm);
SIZE size=m_img.get_Size();
SetRect(&m_rect,p.x,p.y,p.x+size.cx,p.y+size.cy);
m_img.drawJpeg(m_hdc,p.x,p.y,p.x+size.cx,p.y+size.cy);
*/
}
else if(!lstrcmp(ptr,"emf")||!lstrcmp(ptr,"wmf"))
{
try
{
I2SDKFileStream fstm(filename);
m_img.loadStreamMetaFile(fstm);
SIZE size=m_img.get_Size();
SetRect(&m_rect,p.x,p.y,p.x+size.cx,p.y+size.cy);
fstm.seekFile(0,I2SEEK_SET);
len=fstm.get_Length();
pt=GlobalAlloc(GPTR,len);
fstm.readFile((CHAR*)pt,len);
m_imgfile->set_Length(0);
m_imgfile->writeFile((CHAR*)pt,len);
GlobalFree(pt);
}
catch(I2Exception *e)
{
d::s("OndragFile jpg");
e->report();
e->Delete();
return FALSE;
}
}
else
{//drag file - .h .c .cpp .bat .txt
if( (stream = CreateFile(filename,GENERIC_READ,0,NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL)) == INVALID_HANDLE_VALUE )
throw new I2BaseException(I2E_CANNTOPENFILE);
filelen=GetFileSize(stream,NULL);
pdata=(CHAR *)GlobalAlloc(GPTR,filelen+1);
bResult = ReadFile(stream, pdata, filelen, &nBytesRead, NULL) ;
// Check for end of file.
if (bResult)
{
CloseHandle(stream);
}
m_text=SysAllocAnsiString((CHAR*)pdata);
GlobalFree(pdata);
//CloseHandle(stream);
}
return TRUE;
}
VOID CI2WBControl::OnChangeData(RECT& rect)
{
INT lw;
m_wb->get_LineWidth(&lw);
switch(m_type)
{
case dtPen:
break;
case dtLine:
{
INT x1,x2,y1,y2;
x1=m_ptlist.get_Items()[0].x;
x2=m_ptlist.get_Items()[1].x;
y1=m_ptlist.get_Items()[0].y;
y2=m_ptlist.get_Items()[1].y;
m_ptlist.clear();
InflateRect(&rect,-1-lw/2,-1-lw/2);
if((x2>=x1 && y2>=y1) || (x2<=x1 && y2<=y1))
{
I2Point p1(rect.left,rect.top);
I2Point p2(rect.right,rect.bottom);
m_ptlist.append(p1);
m_ptlist.append(p2);
}
else
{
I2Point p1(rect.left,rect.bottom);
I2Point p2(rect.right,rect.top);
m_ptlist.append(p1);
m_ptlist.append(p2);
}
break;
}
case dtHRect:
case dtRect:
InflateRect(&rect,-lw-2,-lw-2);
m_rect=rect;
break;
case dtHCirc:
case dtCirc:
InflateRect(&rect,-1-lw/2,-1-lw/2);
m_rect=rect;
break;
case dtHPoly:
case dtPoly:
case dtText:
case dtImage:
case dtImageGif:
case dtImageJpeg:
case dtImageMeta:
break;
}
}
CPropertyDlg::CPropertyDlg(CI2WBControl* pawc)
{
m_pawc=pawc;
m_pressok=0;
}
void CPropertyDlg::onInitliaze(const I2Dialog& dlg)
{
char buf[10],buf1[32];
INT color;
itoa(m_pawc->cinfo.m_linestyle,buf,10);
itemMessage(IDC_P_LINESTYLE,WM_SETTEXT,0, (LPARAM)buf);
itoa(m_pawc->cinfo.m_linewidth,buf,10);
itemMessage(IDC_P_LINEWIDTH,WM_SETTEXT,0, (LPARAM)buf);
color=GetRValue(m_pawc->cinfo.m_color);
itoa(color,buf,10);
lstrcpy(buf1,buf);
lstrcat(buf1," ");
color=GetGValue(m_pawc->cinfo.m_color);
itoa(color,buf,10);
lstrcat(buf1,buf);
lstrcat(buf1," ");
color=GetBValue(m_pawc->cinfo.m_color);
itoa(color,buf,10);
lstrcat(buf1,buf);
itemMessage(IDC_P_COLOR,WM_SETTEXT,0, (LPARAM)buf1);
color=GetRValue(m_pawc->cinfo.m_bkcolor);
itoa(color,buf,10);
lstrcpy(buf1,buf);
lstrcat(buf1," ");
color=GetGValue(m_pawc->cinfo.m_bkcolor);
itoa(color,buf,10);
lstrcat(buf1,buf);
lstrcat(buf1," ");
color=GetBValue(m_pawc->cinfo.m_bkcolor);
itoa(color,buf,10);
lstrcat(buf1,buf);
itemMessage(IDC_P_BCOLOR,WM_SETTEXT,0, (LPARAM)buf1);
itemMessage(IDC_P_FONT,WM_SETTEXT,0, (LPARAM)m_pawc->cinfo.m_font.name);
itoa(m_pawc->cinfo.m_font.size,buf,10);
itemMessage(IDC_P_FONTSIZE,WM_SETTEXT,0, (LPARAM)buf);
}
void CPropertyDlg::onCommand(const I2Dialog& dlg,WORD wID,WORD wNotifyCode)
{
char buf[16];
memset(buf,0,16);
if(wID==IDOK)
{
m_pressok=1;
destroy();
}
}