OSDN Git Service

・ MBCS->Unicode対応
[seraphyscrtools/SeraphyScriptTools.git] / Layer.h
diff --git a/Layer.h b/Layer.h
index 7574acc..c571410 100644 (file)
--- a/Layer.h
+++ b/Layer.h
@@ -1,7 +1,6 @@
 // Layer.h : CLayer \82Ì\90é\8c¾
 
-#ifndef __LAYER_H_
-#define __LAYER_H_
+#pragma once
 
 #include "resource.h"       // \83\81\83C\83\93 \83V\83\93\83{\83\8b
 
@@ -27,30 +26,32 @@ public:
        {
                HWND hWnd = GetDesktopWindow();
                HDC hdc = GetDC(hWnd);
-               m_height_mm = GetDeviceCaps(hdc,VERTSIZE) * 10;
-               m_height_px = GetDeviceCaps(hdc,VERTRES);
-               m_width_mm  = GetDeviceCaps(hdc,HORZSIZE) * 10;
-               m_width_px = GetDeviceCaps(hdc,HORZRES);
-               ReleaseDC(hWnd,hdc);
+               m_height_mm = GetDeviceCaps(hdc, VERTSIZE) * 10;
+               m_height_px = GetDeviceCaps(hdc, VERTRES);
+               m_width_mm = GetDeviceCaps(hdc, HORZSIZE) * 10;
+               m_width_px = GetDeviceCaps(hdc, HORZRES);
+               ReleaseDC(hWnd, hdc);
        }
        virtual void Destroy() = 0;
        virtual void Draw(CDC hdc) = 0;
-       void DPtoLP(CDC& dc,POINT* pt,int cnt)
+       void DPtoLP(CDC& dc, POINT* pt, int cnt)
        {
                long offsetY = 0;
-               if(!dc.m_bPrinting){
-                       offsetY = MulDiv(dc.m_rct.bottom,m_height_mm,m_height_px);
+               if (!dc.m_bPrinting) {
+                       offsetY = MulDiv(dc.m_rct.bottom, m_height_mm, m_height_px);
                }
-               else{
+               else {
                        offsetY = dc.m_rct.bottom;
                }
                int i;
-               for(i=0;i<cnt;i++){
-                       pt[i].y = offsetY - MulDiv(pt[i].y,m_height_mm,m_height_px);
-                       pt[i].x = MulDiv(pt[i].x,m_width_mm ,m_width_px );
+               for (i = 0; i < cnt; i++) {
+                       pt[i].y = offsetY - MulDiv(pt[i].y, m_height_mm, m_height_px);
+                       pt[i].x = MulDiv(pt[i].x, m_width_mm, m_width_px);
                }
        }
 protected:
+       virtual ~drawdata() {}
+
        int m_bTextMappingMode;
        long m_height_mm;
        long m_height_px;
@@ -63,8 +64,10 @@ class textdata : public drawdata
 public:
        textdata(long x, long y, LPCTSTR text, BOOL mapmode)
        {
-               pBuf = new TCHAR[lstrlen(text)+1];
-               lstrcpy(pBuf,text);
+               if (text == NULL) {
+                       text = _TEXT("");
+               }
+               buf = text;
                m_x = x;
                m_y = y;
                m_bTextMappingMode = mapmode;
@@ -72,26 +75,25 @@ public:
 
        virtual void Destroy()
        {
-               delete pBuf;
                delete this;
        }
 
        virtual void Draw(CDC dc)
        {
-               POINT pt = {m_x,m_y};
-               if(m_bTextMappingMode){
-                       SetTextAlign(dc.m_hDC,TA_TOP);
-                       DPtoLP(dc,&pt,1);
+               POINT pt = {m_x, m_y};
+               if (m_bTextMappingMode) {
+                       SetTextAlign(dc.m_hDC, TA_TOP);
+                       DPtoLP(dc, &pt, 1);
                }
-               else{
-                       SetTextAlign(dc.m_hDC,TA_BASELINE);
+               else {
+                       SetTextAlign(dc.m_hDC, TA_BASELINE);
                }
-               TextOut(dc.m_hDC,pt.x,pt.y,pBuf,lstrlen(pBuf));
+               TextOut(dc.m_hDC, pt.x, pt.y, buf, buf.GetLength());
        }
 protected:
        long m_x;
        long m_y;
-       LPTSTR pBuf;
+       ATL::CString buf;
 };
 
 class textboxdata : public drawdata
@@ -99,42 +101,44 @@ class textboxdata : public drawdata
 public:
        textboxdata(long sx, long sy, long ex, long ey, LPCTSTR text, UINT fmt, BOOL mapmode)
        {
-               pBuf = new TCHAR[lstrlen(text)+1];
-               lstrcpy(pBuf,text);
-               m_box.left   = sx;
-               m_box.top    = sy;
-               m_box.right  = ex;
+               if (text == NULL) {
+                       text = _TEXT("");
+               }
+               buf = text;
+               m_box.left = sx;
+               m_box.top = sy;
+               m_box.right = ex;
                m_box.bottom = ey;
                m_fmt = fmt;
                m_bTextMappingMode = mapmode;
        }
        virtual void Destroy()
        {
-               delete pBuf;
                delete this;
        }
        virtual void Draw(CDC dc)
        {
                RECT box = m_box;
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,(LPPOINT)&box,2);
-                       SetTextAlign(dc.m_hDC,TA_TOP);
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, (LPPOINT)&box, 2);
+                       SetTextAlign(dc.m_hDC, TA_TOP);
                }
-               else{
-                       SetTextAlign(dc.m_hDC,TA_BASELINE);
+               else {
+                       SetTextAlign(dc.m_hDC, TA_BASELINE);
                }
-               DrawText(dc.m_hDC,pBuf,lstrlen(pBuf),&box,m_fmt);
+               DrawText(dc.m_hDC, buf, buf.GetLength(), &box, m_fmt);
        }
+
 protected:
        UINT m_fmt;
        RECT m_box;
-       LPTSTR pBuf;
+       ATL::CString buf;
 };
 
 class linedata : public drawdata
 {
 public:
-       linedata(long sx,long sy,long ex,long ey,BOOL mapmode)
+       linedata(long sx, long sy, long ex, long ey, BOOL mapmode)
        {
                m_sx = sx;
                m_sy = sy;
@@ -142,19 +146,22 @@ public:
                m_ey = ey;
                m_bTextMappingMode = mapmode;
        }
+
        virtual void Destroy()
        {
                delete this;
        }
+
        virtual void Draw(CDC dc)
        {
-               POINT pt[2] = {{m_sx,m_sy},{m_ex,m_ey}};
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,pt,2);
+               POINT pt[2] = {{m_sx, m_sy}, {m_ex, m_ey}};
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, pt, 2);
                }
-               MoveToEx(dc.m_hDC,pt[0].x,pt[0].y,NULL);
-               LineTo(dc.m_hDC,pt[1].x,pt[1].y);
+               MoveToEx(dc.m_hDC, pt[0].x, pt[0].y, NULL);
+               LineTo(dc.m_hDC, pt[1].x, pt[1].y);
        }
+
 protected:
        long m_sx;
        long m_sy;
@@ -165,24 +172,31 @@ protected:
 class circledata : public drawdata
 {
 public:
-       circledata(long sx,long sy,long radius,BOOL mapmode)
+       circledata(long sx, long sy, long radius, BOOL mapmode)
        {
                m_sx = sx;
                m_sy = sy;
                m_radius = radius;
                m_bTextMappingMode = mapmode;
        }
+
        virtual void Destroy()
        {
                delete this;
        }
+
        virtual void Draw(CDC dc)
        {
-               POINT pt[2]   = {{m_sx ,m_sy},{m_radius ,m_radius}};
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,pt,2);
+               POINT pt[2] = {{m_sx, m_sy}, {m_radius, m_radius}};
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, pt, 2);
                }
-               Arc(dc.m_hDC,(pt[0].x-pt[1].x),(pt[0].y-pt[1].x),(pt[0].x+pt[1].x),(pt[0].y+pt[1].x),0,0,0,0);
+               Arc(dc.m_hDC,
+                       (pt[0].x - pt[1].x),
+                       (pt[0].y - pt[1].x),
+                       (pt[0].x + pt[1].x),
+                       (pt[0].y + pt[1].x),
+                       0, 0, 0, 0);
        }
 protected:
        long m_sx;
@@ -193,25 +207,32 @@ protected:
 class fillcircledata : public drawdata
 {
 public:
-       fillcircledata(long sx,long sy,long radius,BOOL mapmode)
+       fillcircledata(long sx, long sy, long radius, BOOL mapmode)
        {
                m_sx = sx;
                m_sy = sy;
                m_radius = radius;
                m_bTextMappingMode = mapmode;
        }
+
        virtual void Destroy()
        {
                delete this;
        }
+
        virtual void Draw(CDC dc)
        {
                long mid = m_radius / 2;
-               POINT pt[2]   = {{m_sx ,m_sy},{m_radius ,m_radius}};
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,pt,2);
+               POINT pt[2] = {{m_sx, m_sy}, {m_radius, m_radius}};
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, pt, 2);
                }
-               Ellipse(dc.m_hDC,(pt[0].x-pt[1].x),(pt[0].y-pt[1].x),(pt[0].x+pt[1].x),(pt[0].y+pt[1].x));
+               Ellipse(dc.m_hDC,
+                       (pt[0].x - pt[1].x),
+                       (pt[0].y - pt[1].x),
+                       (pt[0].x + pt[1].x),
+                       (pt[0].y + pt[1].x)
+                       );
        }
 protected:
        long m_sx;
@@ -222,7 +243,7 @@ protected:
 class boxdata : public drawdata
 {
 public:
-       boxdata(long sx,long sy,long ex,long ey,BOOL mapmode)
+       boxdata(long sx, long sy, long ex, long ey, BOOL mapmode)
        {
                m_sx = sx;
                m_sy = sy;
@@ -230,22 +251,25 @@ public:
                m_ey = ey;
                m_bTextMappingMode = mapmode;
        }
+
        virtual void Destroy()
        {
                delete this;
        }
+
        virtual void Draw(CDC dc)
        {
-               POINT pt[2]   = {{m_sx ,m_sy},{m_ex,m_ey}};
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,pt,2);
+               POINT pt[2] = {{m_sx, m_sy}, {m_ex, m_ey}};
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, pt, 2);
                }
-               MoveToEx(dc.m_hDC,pt[0].x,pt[0].y,NULL);
-               LineTo  (dc.m_hDC,pt[1].x,pt[0].y);
-               LineTo  (dc.m_hDC,pt[1].x,pt[1].y);
-               LineTo  (dc.m_hDC,pt[0].x,pt[1].y);
-               LineTo  (dc.m_hDC,pt[0].x,pt[0].y);
+               MoveToEx(dc.m_hDC, pt[0].x, pt[0].y, NULL);
+               LineTo(dc.m_hDC, pt[1].x, pt[0].y);
+               LineTo(dc.m_hDC, pt[1].x, pt[1].y);
+               LineTo(dc.m_hDC, pt[0].x, pt[1].y);
+               LineTo(dc.m_hDC, pt[0].x, pt[0].y);
        }
+
 protected:
        long m_sx;
        long m_sy;
@@ -256,7 +280,7 @@ protected:
 class fillboxdata : public drawdata
 {
 public:
-       fillboxdata(long sx,long sy,long ex,long ey,BOOL mapmode)
+       fillboxdata(long sx, long sy, long ex, long ey, BOOL mapmode)
        {
                m_sx = sx;
                m_sy = sy;
@@ -264,18 +288,21 @@ public:
                m_ey = ey;
                m_bTextMappingMode = mapmode;
        }
+
        virtual void Destroy()
        {
                delete this;
        }
+
        virtual void Draw(CDC dc)
        {
-               POINT pt[2]   = {{m_sx ,m_sy},{m_ex,m_ey}};
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,pt,2);
+               POINT pt[2] = {{m_sx, m_sy}, {m_ex, m_ey}};
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, pt, 2);
                }
-               Rectangle(dc.m_hDC,pt[0].x,pt[0].y,pt[1].x,pt[1].y);
+               Rectangle(dc.m_hDC, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
        }
+
 protected:
        long m_sx;
        long m_sy;
@@ -286,28 +313,31 @@ protected:
 class fillrboxdata : public drawdata
 {
 public:
-       fillrboxdata(long sx,long sy,long ex,long ey,long w,long h,BOOL mapmode)
+       fillrboxdata(long sx, long sy, long ex, long ey, long w, long h, BOOL mapmode)
        {
                m_sx = sx;
                m_sy = sy;
                m_ex = ex;
                m_ey = ey;
-               m_w  = w;
-               m_h  = h;
+               m_w = w;
+               m_h = h;
                m_bTextMappingMode = mapmode;
        }
+
        virtual void Destroy()
        {
                delete this;
        }
+
        virtual void Draw(CDC dc)
        {
-               POINT pt[3]   = {{m_sx ,m_sy},{m_ex,m_ey},{m_w,m_h}};
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,pt,3);
+               POINT pt[3] = {{m_sx, m_sy}, {m_ex, m_ey}, {m_w, m_h}};
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, pt, 3);
                }
-               RoundRect(dc.m_hDC,pt[0].x,pt[0].y,pt[1].x,pt[1].y,pt[2].x,pt[2].y);
+               RoundRect(dc.m_hDC, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x, pt[2].y);
        }
+
 protected:
        long m_sx;
        long m_sy;
@@ -320,7 +350,7 @@ protected:
 class arcdata : public drawdata
 {
 public:
-       arcdata(long x1,long y1,long x2,long y2,long sx,long sy,long ex,long ey,BOOL mapmode)
+       arcdata(long x1, long y1, long x2, long y2, long sx, long sy, long ex, long ey, BOOL mapmode)
        {
                m_x1 = x1;
                m_y1 = y1;
@@ -338,11 +368,11 @@ public:
        }
        virtual void Draw(CDC dc)
        {
-               POINT pt[4]   = {{m_x1,m_y1},{m_x2,m_y2},{m_sx ,m_sy},{m_ex,m_ey}};
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,pt,4);
+               POINT pt[4] = {{m_x1, m_y1}, {m_x2, m_y2}, {m_sx, m_sy}, {m_ex, m_ey}};
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, pt, 4);
                }
-               Arc(dc.m_hDC,pt[0].x,pt[0].y,pt[1].x,pt[1].y,pt[2].x,pt[2].y,pt[3].x,pt[3].y);
+               Arc(dc.m_hDC, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x, pt[2].y, pt[3].x, pt[3].y);
        }
 protected:
        long m_x1;
@@ -358,7 +388,7 @@ protected:
 class fillarcdata : public drawdata
 {
 public:
-       fillarcdata(long x1,long y1,long x2,long y2,long sx,long sy,long ex,long ey,BOOL mapmode)
+       fillarcdata(long x1, long y1, long x2, long y2, long sx, long sy, long ex, long ey, BOOL mapmode)
        {
                m_x1 = x1;
                m_y1 = y1;
@@ -376,11 +406,11 @@ public:
        }
        virtual void Draw(CDC dc)
        {
-               POINT pt[4]   = {{m_x1,m_y1},{m_x2,m_y2},{m_sx ,m_sy},{m_ex,m_ey}};
-               if(m_bTextMappingMode){
-                       DPtoLP(dc,pt,4);
+               POINT pt[4] = {{m_x1, m_y1}, {m_x2, m_y2}, {m_sx, m_sy}, {m_ex, m_ey}};
+               if (m_bTextMappingMode) {
+                       DPtoLP(dc, pt, 4);
                }
-               Pie(dc.m_hDC,pt[0].x,pt[0].y,pt[1].x,pt[1].y,pt[2].x,pt[2].y,pt[3].x,pt[3].y);
+               Pie(dc.m_hDC, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x, pt[2].y, pt[3].x, pt[3].y);
        }
 protected:
        long m_x1;
@@ -396,7 +426,7 @@ protected:
 class polygondata : public drawdata
 {
 public:
-       polygondata(POINT* pPt,int cnt,BOOL mapmode)
+       polygondata(POINT* pPt, int cnt, BOOL mapmode)
        {
                m_cnt = cnt;
                m_pPt = pPt;
@@ -409,18 +439,18 @@ public:
        }
        virtual void Draw(CDC dc)
        {
-               if(m_bTextMappingMode){
+               if (m_bTextMappingMode) {
                        POINT* pt = new POINT[m_cnt];
                        int i;
-                       for(i=0;i<m_cnt;i++){
+                       for (i = 0; i < m_cnt; i++) {
                                pt[i] = m_pPt[i];
                        }
-                       DPtoLP (dc,pt,m_cnt);
-                       Polygon(dc.m_hDC,pt,m_cnt);
+                       DPtoLP(dc, pt, m_cnt);
+                       Polygon(dc.m_hDC, pt, m_cnt);
                        delete[]pt;
                }
-               else{
-                       Polygon(dc.m_hDC,m_pPt,m_cnt);
+               else {
+                       Polygon(dc.m_hDC, m_pPt, m_cnt);
                }
        }
 protected:
@@ -431,7 +461,7 @@ protected:
 class picturedata : public drawdata
 {
 public:
-       picturedata(IPicture* pPicture,long x,long y,long w,long h,BOOL mapmode)
+       picturedata(IPicture* pPicture, long x, long y, long w, long h, BOOL mapmode)
        {
                m_x = x;
                m_y = y;
@@ -439,20 +469,20 @@ public:
                m_w = w;
                m_pPicture = pPicture;
                m_bTextMappingMode = mapmode;
-               if(m_pPicture){
+               if (m_pPicture) {
                        m_pPicture->AddRef();
                }
        }
        virtual void Destroy()
        {
-               if(m_pPicture){
+               if (m_pPicture) {
                        m_pPicture->Release();
                        m_pPicture = NULL;
                }
        }
        virtual void Draw(CDC dc)
        {
-               if(!m_pPicture){
+               if (!m_pPicture) {
                        // \83r\83N\83`\83\83\81[\83C\83\93\83^\81[\83t\83F\83C\83X\82ª\82È\82¢\82È\82ç\89½\82à\82µ\82È\82¢
                        return;
                }
@@ -463,24 +493,26 @@ public:
                m_pPicture->get_Width(&w);
                m_pPicture->get_Height(&h);
 
-               if(m_bTextMappingMode){
-                       POINT pt[2] = {{m_x,m_y},{m_x+m_w,m_y+m_h}};
-                       DPtoLP(dc,pt,2);
-                       if(m_w < 0){ pt[1].x = w/10; } else { pt[1].x = labs(pt[1].x - pt[0].x); }
-                       if(m_h < 0){ pt[1].y = h/10; } else { pt[1].y = labs(pt[1].y - pt[0].y); }
+               if (m_bTextMappingMode) {
+                       POINT pt[2] = {{m_x, m_y}, {m_x + m_w, m_y + m_h}};
+                       DPtoLP(dc, pt, 2);
+                       if (m_w < 0) { pt[1].x = w / 10; }
+                       else { pt[1].x = labs(pt[1].x - pt[0].x); }
+                       if (m_h < 0) { pt[1].y = h / 10; }
+                       else { pt[1].y = labs(pt[1].y - pt[0].y); }
                        m_pPicture->Render(dc.m_hDC
-                               ,(pt[0].x)
-                               ,(pt[0].y-pt[1].y)
-                               ,(pt[1].x)
-                               ,(pt[1].y)
-                               ,0,0,w,h,NULL);
+                               , (pt[0].x)
+                               , (pt[0].y - pt[1].y)
+                               , (pt[1].x)
+                               , (pt[1].y)
+                               , 0, 0, w, h, NULL);
                }
-               else{
+               else {
                        long dw = w / 10;
                        long dh = h / 10;
-                       if(m_w > 0) dw = m_w;
-                       if(m_h > 0) dh = m_h;
-                       m_pPicture->Render(dc.m_hDC,m_x,m_y,dw,dh,0,0,w,h,NULL);
+                       if (m_w > 0) dw = m_w;
+                       if (m_h > 0) dh = m_h;
+                       m_pPicture->Render(dc.m_hDC, m_x, m_y, dw, dh, 0, 0, w, h, NULL);
                }
        }
 protected:
@@ -493,10 +525,10 @@ protected:
 
 /////////////////////////////////////////////////////////////////////////////
 // CLayer
-class ATL_NO_VTABLE CLayer : 
+class ATL_NO_VTABLE CLayer :
        public CComObjectRootEx<CComSingleThreadModel>,
-//     public CComCoClass<CLayer, &CLSID_Layer>,
-       public ISupportErrorInfo,
+       public CComCoClass<CLayer, &CLSID_Layer>,
+       public ISupportErrorInfoImpl<&IID_ILayer>,
        public IConnectionPointContainerImpl<CLayer>,
        public IDispatchImpl<ILayer, &IID_ILayer, &LIBID_SERAPHYSCRIPTTOOLSLib>
 {
@@ -518,26 +550,22 @@ public:
        }
        void FinalRelease();
 
-//DECLARE_REGISTRY_RESOURCEID(IDR_LAYER)
+       //DECLARE_REGISTRY_RESOURCEID(IDR_LAYER)
 
-DECLARE_PROTECT_FINAL_CONSTRUCT()
+       DECLARE_PROTECT_FINAL_CONSTRUCT()
 
-BEGIN_COM_MAP(CLayer)
-       COM_INTERFACE_ENTRY(ILayer)
-       COM_INTERFACE_ENTRY(IDispatch)
-       COM_INTERFACE_ENTRY(ISupportErrorInfo)
-       COM_INTERFACE_ENTRY(IConnectionPointContainer)
-END_COM_MAP()
-BEGIN_CONNECTION_POINT_MAP(CLayer)
-END_CONNECTION_POINT_MAP()
+       BEGIN_COM_MAP(CLayer)
+               COM_INTERFACE_ENTRY(ILayer)
+               COM_INTERFACE_ENTRY(IDispatch)
+               COM_INTERFACE_ENTRY(ISupportErrorInfo)
+               COM_INTERFACE_ENTRY(IConnectionPointContainer)
+       END_COM_MAP()
+       BEGIN_CONNECTION_POINT_MAP(CLayer)
+       END_CONNECTION_POINT_MAP()
 
-
-// ISupportsErrorInfo
-       STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
-
-// ILayer
+       // ILayer
 public:
-       long GetMappedValue(VARIANT var,long def = 0);
+       long GetMappedValue(VARIANT var, long def = 0);
        STDMETHOD(SetMappingMode)(/*[in]*/VARIANT mode);
        STDMETHOD(Picture)(/*[in]*/VARIANT punkVal,/*[in]*/VARIANT x,/*[in]*/VARIANT y,/*[in,optional]*/VARIANT w,/*[in,optional]*/VARIANT h);
        STDMETHOD(Clear)();
@@ -578,5 +606,3 @@ protected:
        int m_bTextMappingMode;
        int m_bFontTextMappingMode;
 };
-
-#endif //__LAYER_H_