Rect_cpp.cpp

C:\home\SVGCats_src\src\Rect_cpp.cpp

[大目次 | 目次 | 関数]

大目次

目次

関数一覧


   1|/***********************************************************************
   2|  1. <<< 矩形 (Rect) >>> 
   3|************************************************************************/
   4|
   5|#include "mixer_precomp.h"  /* Auto precompiled header, Look at mixer-... folder */
   6|// #pragma hdrstop
   7|
   8|#if defined(USES_MXP_AUTOINC)
   9| #include "rect.ah"  /* Auto include header, Look at mixer-... folder */
  10|#endif
  11| 
  12|/*-------------------------------------------------------------------------*/
  13|/* 2. <<<< ◆ (Rect_Ex) 矩形・詳細(ディスプレイ表示用) >>>>  */ 
  14|/*-------------------------------------------------------------------------*/
  15| 
  16|Rect_Ex::Rect_Ex() 
  17|{
  18|  StdPlus_onMalloc( this );
  19|  m_bInUndoBuf = false;
  20|  m_bHold = false;
  21|  m_bSelected = false;
  22|  m_URL = "";
  23|  m_Target = "_blank";
  24|  m_IdLabel = "";
  25|  m_RotateDegree = 0;
  26|  m_ImgPath = "";
  27|  m_ImgWorkPath = "";
  28|  WinX_DDBmp_init( &m_ddb, "" );
  29|  m_bEmbedImg = true;
  30|  m_bNeedReadImgProp = true;
  31|  m_ImgWidth = 100;
  32|  m_ImgHeight = 100;
  33|  m_NTrans = 100;
  34|}
  35|
  36|Rect_Ex::~Rect_Ex()
  37|{
  38|  StdPlus_onFree( this );
  39|
  40|  if ( ! m_bInUndoBuf ) {
  41|    //remove( m_ImgWorkPath );
  42|      // カット&ペーストやアンドゥのため、CSVGCatApp::Finish_imp で削除
  43|    WinX_DDBmp_finish( &m_ddb );
  44|  }
  45|}
  46| 
  47|#ifdef  RECT_USES_WINDOWS_DC 
  48|
  49|
  50| 
  51|/***********************************************************************
  52|  2-1. <<< [Rect_Ex::print] CadPrim::print の実装部 >>> 
  53|************************************************************************/
  54|void  Rect_Ex::print( const char* title )
  55|{
  56|#ifndef  ERRORS_CUT_DEBUG_TOOL
  57|  Errors_printf( "%sRect[%d:%p], hold=%d, selected=%d", title, m_id, this, m_bHold, m_bSelected );
  58|  Rect_print( &m_Rect, title );
  59|#endif
  60|}
  61|
  62|
  63|/***********************************************************************
  64|  2-2. <<< [Rect_Ex::GetID] CadPrim::GetID の実装部 >>>
  65|************************************************************************/
  66|int  Rect_Ex::GetID()
  67|{
  68|  return  m_id;
  69|}
  70|
  71|
  72|/***********************************************************************
  73|  2-3. <<< [Rect_Ex::SetID] CadPrim::SetID の実装部 >>>
  74|************************************************************************/
  75|void  Rect_Ex::SetID( int id )
  76|{
  77|  m_id = id;
  78|}
  79|
  80|
  81|/***********************************************************************
  82|  2-4. <<< [Rect_Ex::GetTypeID] CadPrim::GetTypeID の実装部 >>>
  83|************************************************************************/
  84|int  Rect_Ex::GetTypeID()
  85|{
  86|  return  Rect_Ex_TypeID;
  87|}
  88|
  89|
  90|/***********************************************************************
  91|  2-5. <<< [Rect_Ex::GetTypeNameJp] CadPrim::GetTypeNameJp の実装部 >>>
  92|************************************************************************/
  93|char*  Rect_Ex::GetTypeNameJp()
  94|{
  95|  return  "図形";
  96|}
  97|
  98|
  99|/***********************************************************************
 100|  2-6. <<< [Rect_Ex::GetTypeNameEn] CadPrim::GetTypeNameEn の実装部 >>>
 101|************************************************************************/
 102|char*  Rect_Ex::GetTypeNameEn()
 103|{
 104|  return  "Figure";
 105|}
 106|
 107|
 108|/***********************************************************************
 109|  2-7. <<< [Rect_Ex::SetBInUndoBuf] CadPrim::SetBInUndoBuf の実装部 >>>
 110|************************************************************************/
 111|void  Rect_Ex::SetBInUndoBuf( bool b )
 112|{
 113|  m_bInUndoBuf = b;
 114|}
 115|
 116|
 117|/***********************************************************************
 118|  2-8. <<< [Rect_Ex::GetLinkURL] CadPrim::GetLinkURL の実装部 >>>
 119|************************************************************************/
 120|char*  Rect_Ex::GetLinkURL()
 121|{
 122|  return  (char*)(const char*)m_URL;
 123|}
 124|
 125|
 126|/***********************************************************************
 127|  2-9. <<< [Rect_Ex::GetIdLabel] CadPrim::GetIdLabel の実装部 >>>
 128|************************************************************************/
 129|char*  Rect_Ex::GetIdLabel()
 130|{
 131|  return  (char*)(const char*)m_IdLabel;
 132|}
 133|
 134|
 135| 
 136|/***********************************************************************
 137|  2-10. <<< [Rect_Ex::OutSVG] SVGファイルに属性値を出力する >>> 
 138|【引数】
 139|  ・FILE*   f;    出力先のテキスト・ファイル
 140|************************************************************************/
 141|void  Rect_Ex::OutSVG( CadPrim_SaveParam* p )
 142|{
 143|  char* urlFName = ( m_URL == "" ? strchr( m_URL, '\0' ) : StrX_refFName(m_URL) );
 144|  bool  bScript = ( strnicmp( urlFName, "script:", 7 ) == 0 );
 145|  char* script = urlFName + 7;
 146|  char  id_inPrim[256];
 147|
 148|
 149|  /* <g> タグをファイルに出力する */
 150|  id_inPrim[0] = '\0';
 151|  if ( bScript || urlFName[0] == '#' ) {
 152|    fputs( "\t<g", p->f );
 153|    if ( m_IdLabel != "" )  fprintf( p->f, " id=\"%s\"", m_IdLabel );
 154|    if ( urlFName[0] == '#' )  fprintf( p->f, " href=\"%s\"", urlFName );
 155|    if ( bScript )  fprintf( p->f, " onclick=\"%s\"", script );
 156|    if ( p->iTargetPage >= 1 )  fprintf( p->f, " onclick=\"chgPage( evt, %d )\"", p->iTargetPage );
 157|    fputs( ">\n", p->f );
 158|  }
 159|  else {
 160|    if ( m_IdLabel != "" )  sprintf( id_inPrim, " id=\"%s\"", m_IdLabel );
 161|  }
 162|
 163|
 164|  /* <a> タグをファイルに出力する */
 165|  if ( m_URL != "" ) {
 166|    if ( ! bScript && urlFName[0] != '#' ) {
 167|      char  stepPath[_MAX_PATH];
 168|
 169|      StrX_cpyStepPath2( stepPath, m_URL, sizeof(stepPath), p->path );
 170|      if ( p->bLower )  StrX_cpyLower( stepPath, stepPath );
 171|      fprintf( p->f, "\t<a xlink:href=\"%s\"", stepPath );
 172|      if ( m_Target != "" )
 173|        fprintf( p->f, " target=\"%s\"", m_Target );
 174|      fputs( ">\n", p->f );
 175|    }
 176|    else {
 177|      fputs( "<a>\n", p->f );
 178|    }
 179|  }
 180|
 181|
 182|  /* 図形タグをファイルに出力する */
 183|  switch ( m_ShapeType ) {
 184|   case  Rect_RectShape:
 185|    fprintf( p->f, "\t<rect%s x=\"%d.5\" y=\"%d.5\" width=\"%d\" height=\"%d\"\n",
 186|      id_inPrim, m_Rect.x, m_Rect.y, m_Rect.w, m_Rect.h );
 187|    break;
 188|
 189|   case  Rect_RoundRectShape:
 190|    fprintf( p->f, "\t<rect%s x=\"%d.5\" y=\"%d.5\" width=\"%d\" height=\"%d\""
 191|      " rx=\"10\" ry=\"10\"\n",
 192|      id_inPrim, m_Rect.x, m_Rect.y, m_Rect.w, m_Rect.h );
 193|    break;
 194|
 195|   case  Rect_CircleShape:
 196|    if ( m_Rect.w == m_Rect.h ) {
 197|      fprintf( p->f, "\t<circle%s cx=\"%d.5\" cy=\"%d.5\" r=\"%d\"\n",
 198|        id_inPrim, m_Rect.x + m_Rect.w / 2,  m_Rect.y + m_Rect.h / 2, m_Rect.w / 2 );
 199|    }
 200|    else {
 201|      fprintf( p->f, "\t<ellipse%s cx=\"%d.5\" cy=\"%d.5\" rx=\"%d\" ry=\"%d\"\n",
 202|        id_inPrim, m_Rect.x + m_Rect.w / 2,  m_Rect.y + m_Rect.h / 2,
 203|        m_Rect.w / 2,  m_Rect.h / 2 );
 204|    }
 205|    break;
 206|
 207|   case  Rect_DiamondShape: {
 208|    int  w = ( m_Rect.w % 2 == 0 ? m_Rect.w : m_Rect.w + 1 );
 209|    int  h = ( m_Rect.h % 2 == 0 ? m_Rect.h : m_Rect.h + 1 );
 210|
 211|    fprintf( p->f, "\t<polygon%s points=\"%d.5,%d.5 %d.5,%d.5 %d.5,%d.5 %d.5,%d.5\"\n",
 212|        id_inPrim,
 213|        m_Rect.x + w / 2,  m_Rect.y,
 214|        m_Rect.x + w,      m_Rect.y + h / 2,
 215|        m_Rect.x + w / 2,  m_Rect.y + h,
 216|        m_Rect.x,          m_Rect.y + h / 2 );
 217|    break;
 218|   }
 219|   case  Rect_ImageShape: {
 220|    char  imgPath[_MAX_PATH];
 221|
 222|    StrX_cpyStepPath2( imgPath, m_ImgPath, sizeof(imgPath), p->path );
 223|    if ( p->bLower )  StrX_cpyLower( imgPath, imgPath );
 224|    fprintf( p->f, "\t<image%s x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"",
 225|      id_inPrim, m_Rect.x, m_Rect.y, m_Rect.w, m_Rect.h );
 226|    if ( m_bEmbedImg && ( FileX_isExist( m_ImgPath ) || FileX_isExist( m_ImgWorkPath ) ) ) {
 227|      fprintf( p->f, " src=\"%s\" xlink:href=\"data:;base64,\n", imgPath );
 228|      if ( FileX_isExist( m_ImgPath ) )
 229|        FileX_putBase64( p->f, m_ImgPath, "\r\n" );
 230|      else
 231|        FileX_putBase64( p->f, m_ImgWorkPath, "\r\n" );
 232|      fputc( '\"', p->f );
 233|    }
 234|    else {
 235|      fprintf( p->f, " xlink:href=\"%s\"", imgPath );
 236|    }
 237|    break;
 238|   }
 239|  }
 240|
 241|  if ( m_ShapeType != Rect_ImageShape ) {
 242|    char  trans[20];
 243|
 244|    sprintf( trans, ";fill-opacity:0.%02d", m_NTrans );
 245|
 246|    fprintf( p->f, "\t\tstyle=\"fill:rgb(%d,%d,%d);stroke:rgb(%d,%d,%d);"
 247|      "stroke-width:%d%s\"",
 248|      Color_WinRGB_getR( m_FillColor ), Color_WinRGB_getG( m_FillColor ),
 249|      Color_WinRGB_getB( m_FillColor ),
 250|      Color_WinRGB_getR( m_BorderColor ), Color_WinRGB_getG( m_BorderColor ),
 251|      Color_WinRGB_getB( m_BorderColor ),
 252|      m_BorderWidth,
 253|      m_NTrans == 100 ? "" : trans );
 254|  }
 255|
 256|  if ( m_RotateDegree != 0 ) {
 257|    fprintf( p->f, " transform=\"rotate(%d,%d,%d)\"",
 258|      m_RotateDegree, m_Rect.x + m_Rect.w / 2, m_Rect.y + m_Rect.h / 2 );
 259|  }
 260|  fputs( "/>\n", p->f );
 261|
 262|
 263|  /* </a> タグをファイルに出力する */
 264|  if ( m_URL != "" )
 265|    fputs( "\t</a>\n", p->f );
 266|
 267|  /* </g> タグをファイルに出力する */
 268|  if ( bScript || urlFName[0] == '#' )
 269|    fprintf( p->f, "\t</g>\n" );
 270|}
 271|
 272| 
 273|/***********************************************************************
 274|  2-11. <<< [Rect_Ex::Draw] 矩形を描画する >>> 
 275|【引数】
 276|  ・CDC*    dc;    デバイスコンテキスト
 277|************************************************************************/
 278|void  Rect_Ex::Draw( CDC* dc, CadPrim_DrawParam* p )
 279|{
 280|  int   zoom = p->zoom;
 281|  int   x1 = m_Rect.x * zoom / 100;
 282|  int   y1 = m_Rect.y * zoom / 100;
 283|  int   x2 = (m_Rect.x + m_Rect.w) * zoom / 100;
 284|  int   y2 = (m_Rect.y + m_Rect.h) * zoom / 100;
 285|
 286|  CPen     pen( PS_SOLID, m_BorderWidth * zoom / 100,
 287|    p->bWhiteToBGColor && m_BorderColor == 0x000000 ?
 288|    GetSysColor( COLOR_WINDOWTEXT ) : m_BorderColor );
 289|  CPen     nullPen( PS_NULL, (int)0, (int)0 );
 290|  CBrush   brush( p->bWhiteToBGColor && m_FillColor == 0xFFFFFF ?
 291|    GetSysColor( COLOR_WINDOW ) : m_FillColor );
 292|  CBrush   grayBrush( RGB(0x40,0x40,0x80) );
 293|  CBrush   redBrush( RGB(0xFF,0,0) );
 294|  CBrush   nullBrush;
 295|  CBrush   transBrush( HS_VERTICAL, p->bWhiteToBGColor && m_FillColor == 0xFFFFFF ?
 296|    GetSysColor( COLOR_WINDOW ) : m_FillColor );
 297|  CPen*    oldPen;
 298|  CBrush*  oldBrush;
 299|
 300|  ASSERT( ! m_bInUndoBuf );
 301|
 302|  nullBrush.CreateStockObject( NULL_BRUSH );
 303|
 304|  oldPen = dc->SelectObject( m_BorderWidth == 0 ? &nullPen : &pen );
 305|  if ( m_NTrans == 100 )
 306|    oldBrush = dc->SelectObject( &brush );
 307|  else if ( m_NTrans == 0 )
 308|    oldBrush = dc->SelectObject( &nullBrush );
 309|  else {
 310|    dc->SetBkMode( TRANSPARENT );
 311|    oldBrush = dc->SelectObject( &transBrush );
 312|  }
 313|
 314|  switch ( m_ShapeType ) {
 315|
 316|   case  Rect_RectShape:
 317|    if ( m_RotateDegree == 0 ) {
 318|      dc->Rectangle( x1 - p->x0,  y1 - p->y0,  x2 + 1 - p->x0,  y2 + 1 - p->y0 );
 319|    }
 320|    else {
 321|      POINT    pts[4];
 322|      TwoD_XY  xy;
 323|      TwoD_XY  center;
 324|      int  i;
 325|
 326|      pts[0].x = m_Rect.x;             pts[0].y = m_Rect.y;
 327|      pts[1].x = m_Rect.x + m_Rect.w;  pts[1].y = m_Rect.y;
 328|      pts[2].x = m_Rect.x + m_Rect.w;  pts[2].y = m_Rect.y + m_Rect.h;
 329|      pts[3].x = m_Rect.x;             pts[3].y = m_Rect.y + m_Rect.h;
 330|      TwoD_XY_init( &center, m_Rect.x + m_Rect.w / 2, m_Rect.y + m_Rect.h / 2 );
 331|      for ( i = 0; i < 4; i++ ) {
 332|        TwoD_XY_init( &xy, pts[i].x, pts[i].y );
 333|        TwoD_XY_rot( &xy, &center, m_RotateDegree * (2 * 3.141592) / 360 );
 334|        pts[i].x = (long)(xy.x + 0.5) * zoom / 100 - p->x0;  pts[i].y = (long)(xy.y + 0.5) * zoom / 100 - p->y0;
 335|      }
 336|      dc->Polygon( pts, 4 );
 337|    }
 338|    break;
 339|
 340|   case  Rect_RoundRectShape:
 341|    if ( m_RotateDegree == 0 ) {
 342|      dc->RoundRect( x1 - p->x0,  y1 - p->y0,  x2 + 1 - p->x0,  y2 + 1 - p->y0,
 343|        20 * zoom / 100,  20 * zoom / 100 );
 344|    }
 345|    else {
 346|      POINT    pts[8];
 347|      TwoD_XY  xy;
 348|      TwoD_XY  center;
 349|      int  i;
 350|
 351|      pts[0].x = m_Rect.x;                 pts[0].y = m_Rect.y + 6;
 352|      pts[1].x = m_Rect.x + 6;             pts[1].y = m_Rect.y;
 353|      pts[2].x = m_Rect.x + m_Rect.w - 6;  pts[2].y = m_Rect.y;
 354|      pts[3].x = m_Rect.x + m_Rect.w;      pts[3].y = m_Rect.y + 6;
 355|      pts[4].x = m_Rect.x + m_Rect.w;      pts[4].y = m_Rect.y + m_Rect.h - 6;
 356|      pts[5].x = m_Rect.x + m_Rect.w - 6;  pts[5].y = m_Rect.y + m_Rect.h;
 357|      pts[6].x = m_Rect.x + 6;             pts[6].y = m_Rect.y + m_Rect.h;
 358|      pts[7].x = m_Rect.x;                 pts[7].y = m_Rect.y + m_Rect.h - 6;
 359|      TwoD_XY_init( &center, m_Rect.x + m_Rect.w / 2, m_Rect.y + m_Rect.h / 2 );
 360|      for ( i = 0; i < 8; i++ ) {
 361|        TwoD_XY_init( &xy, pts[i].x, pts[i].y );
 362|        TwoD_XY_rot( &xy, &center, m_RotateDegree * (2 * 3.141592) / 360 );
 363|        pts[i].x = (long)xy.x * zoom / 100 - p->x0;  pts[i].y = (long)xy.y * zoom / 100 - p->y0;
 364|      }
 365|      dc->Polygon( pts, 8 );
 366|    }
 367|    break;
 368|
 369|   case  Rect_CircleShape:
 370|    dc->Ellipse( x1 - p->x0,  y1 - p->y0,  x2 + 1 - p->x0,  y2 + 1 - p->y0 );
 371|    break;
 372|
 373|   case  Rect_DiamondShape: {
 374|    POINT  pts[4];
 375|    TwoD_XY  xy;
 376|    TwoD_XY  center;
 377|    int  i;
 378|    int  w = ( m_Rect.w % 2 == 0 ? m_Rect.w : m_Rect.w + 1 );
 379|    int  h = ( m_Rect.h % 2 == 0 ? m_Rect.h : m_Rect.h + 1 );
 380|
 381|    pts[0].x = m_Rect.x + w / 2;  pts[0].y = m_Rect.y;
 382|    pts[1].x = m_Rect.x + w;      pts[1].y = m_Rect.y + h / 2;
 383|    pts[2].x = m_Rect.x + w / 2;  pts[2].y = m_Rect.y + h;
 384|    pts[3].x = m_Rect.x;                 pts[3].y = m_Rect.y + h / 2;
 385|    TwoD_XY_init( &center, m_Rect.x + (w + 1) / 2, m_Rect.y + (h + 1) / 2 );
 386|    for ( i = 0; i < 4; i++ ) {
 387|      TwoD_XY_init( &xy, pts[i].x, pts[i].y );
 388|      TwoD_XY_rot( &xy, &center, m_RotateDegree * (2 * 3.141592) / 360 );
 389|      pts[i].x = (long)xy.x * zoom / 100 - p->x0;  pts[i].y = (long)xy.y * zoom / 100 - p->y0;
 390|    }
 391|    dc->Polygon( pts, 4 );
 392|    break;
 393|   }
 394|
 395|   case  Rect_ImageShape:
 396|    #ifdef  USES_SUSIE
 397|      const char*  src_path;
 398|      HDC  hdc;
 399|
 400|      /* m_ImgWorkPath にコピーする */
 401|      if ( m_bEmbedImg ) {
 402|        if ( FileX_cmpTime( m_ImgPath, m_ImgWorkPath ) > 0 ) {
 403|          char  path[_MAX_PATH];
 404|
 405|          FileX_copy( m_ImgWorkPath, m_ImgPath );
 406|          strcpy( path, m_ImgWorkPath );
 407|          FileX_repairExt( path );
 408|          m_ImgWorkPath = path;
 409|        }
 410|        src_path = m_ImgWorkPath;
 411|      }
 412|      else
 413|        src_path = m_ImgPath;
 414|
 415|
 416|      /* DDB を作る */
 417|      if ( src_path[0] != '\0' ) {
 418|        if ( m_ddb.path[0] == '\0' )
 419|          { strcpy( m_ddb.path, m_ImgWorkPath );  StrX_chgExt( m_ddb.path, "ddb" ); }
 420|
 421|        if ( FileX_cmpTime( src_path, m_ddb.path ) > 0 ||
 422|             ( ( m_Rect.w * zoom / 100 != m_ddb.width || m_Rect.h * zoom / 100 != m_ddb.height ) &&
 423|             FileX_isExist( src_path ) ) ) {
 424|          Susies_attach( &Susies_globl, src_path );
 425|
 426|          if ( Susies_globl.selectingSPI != NULL ) {
 427|
 428|            m_ImgWidth = Susies_globl.selectingSPI->width;
 429|            m_ImgHeight = Susies_globl.selectingSPI->height;
 430|
 431|            if ( m_bNeedReadImgProp ) {
 432|
 433|              m_Rect.w = m_ImgWidth;
 434|              m_Rect.h = m_ImgHeight;
 435|
 436|              /* キャンバス内に縮める */
 437|              if ( m_Rect.x + m_Rect.w >= p->clip_right * 100 / p->zoom - 8 )
 438|                m_Rect.w = p->clip_right * 100 / p->zoom - m_Rect.x - 8;
 439|              if ( m_Rect.y + m_Rect.h >= p->clip_bottom * 100 / p->zoom - 8 )
 440|                m_Rect.h = p->clip_bottom * 100 / p->zoom - m_Rect.y - 8;
 441|              if ( m_Rect.w * m_ImgHeight > m_Rect.h * m_ImgWidth )
 442|                m_Rect.w = m_Rect.h * m_ImgWidth / m_ImgHeight;
 443|              else
 444|                m_Rect.h = m_Rect.w * m_ImgHeight / m_ImgWidth;
 445|
 446|              m_bNeedReadImgProp = false;
 447|            }
 448|
 449|            hdc = WinX_DDBmp_openForWrite( &m_ddb, dc->m_hDC,
 450|              m_Rect.w * zoom / 100,  m_Rect.h * zoom / 100 );
 451|            if ( m_Rect.w * zoom / 100 == m_ImgWidth && m_Rect.h * zoom / 100 == m_ImgHeight ) {
 452|              Susies_draw( &Susies_globl, hdc, 0, 0 );
 453|            }
 454|            else {
 455|              Susies_drawStretch( &Susies_globl, hdc,
 456|                0, 0, m_Rect.w * zoom / 100,  m_Rect.h * zoom / 100 );
 457|            }
 458|            WinX_DDBmp_closeForWrite( &m_ddb );
 459|          }
 460|          else
 461|            remove( m_ddb.path );
 462|        }
 463|      }
 464|
 465|      /* 画像を表示する */
 466|      if ( m_bEmbedImg ? FileX_isExist( m_ddb.path ) : FileX_isExist( m_ImgPath ) ) {
 467|        if ( p->bPrint ) {
 468|          Susies_attach( &Susies_globl, src_path );
 469|          if ( Susies_globl.selectingSPI != NULL ) {
 470|            Susies_drawStretch( &Susies_globl, dc->m_hDC,
 471|              x1 - p->x0, y1 - p->y0,
 472|              m_Rect.w * zoom / 100,  m_Rect.h * zoom / 100 );
 473|          }
 474|        }
 475|        else {
 476|          #if 1
 477|            if ( WinX_DDBmp_readDirect( &m_ddb, dc->m_hDC, x1 - p->x0, y1 - p->y0 ) == 0 ) {
 478| 
 479|              /* WinX_DDBmp_readDirect ができないとき */ 
 480|              Susies_attach( &Susies_globl, src_path );
 481|              if ( Susies_globl.selectingSPI != NULL ) {
 482|                Susies_drawStretch( &Susies_globl, dc->m_hDC,
 483|                  x1 - p->x0, y1 - p->y0,
 484|                  m_Rect.w * zoom / 100,  m_Rect.h * zoom / 100 );
 485|              }
 486|            }
 487|          #else
 488|            hdc = WinX_DDBmp_openForRead( &m_ddb, dc->m_hDC );
 489|            BitBlt( dc->m_hDC, x1 - p->x0, y1 - p->y0, m_ddb.width, m_ddb.height, hdc, 0, 0, SRCCOPY );
 490|            WinX_DDBmp_closeForRead( &m_ddb );
 491|          #endif
 492|        }
 493|      }
 494|      else {
 495|        dc->SelectObject( grayBrush );
 496|        dc->Rectangle( x1 - p->x0,  y1 - p->y0,  x2 + 1 - p->x0,  y2 + 1 - p->y0 );
 497|      }
 498|    #else
 499|        dc->SelectObject( redBrush );
 500|        dc->Rectangle( x1 - p->x0,  y1 - p->y0,  x2 + 1 - p->x0,  y2 + 1 - p->y0 );
 501|    #endif
 502|    break;
 503|  }
 504|
 505|  dc->SelectObject( oldBrush );
 506|  dc->SelectObject( oldPen );
 507|
 508|  if ( m_bHold && p->bDrawHandle )
 509|    DrawHandles( dc, p, ~GetSysColor( COLOR_HIGHLIGHT ) & 0xFFFFFF, false );
 510|}
 511|
 512|
 513| 
 514|/***********************************************************************
 515|  2-12. <<< [Rect_Ex::DrawHandles] 全ハンドルを描画する >>> 
 516|【引数】
 517|  ・CDC*    dc;      デバイスコンテキスト
 518|  ・int     color;   ハンドルの色
 519|************************************************************************/
 520|void  Rect_Ex::DrawHandles( CDC* dc, CadPrim_DrawParam* p, COLORREF color,
 521|  bool bDrawFrame )
 522|{
 523|  CPen     pen( PS_SOLID, 1, color ^ 0xFFFFFF );
 524|  CBrush   brush( color );
 525|  CPen*    oldPen;
 526|  CBrush*  oldBrush;
 527|  int  i, x, y;
 528|  TwoD_XY  xy, center;
 529|  double   angle = m_RotateDegree * (2 * 3.141592) / 360;
 530|  int  w = ( m_Rect.w % 2 == 0 ? m_Rect.w : m_Rect.w + 1 );
 531|  int  h = ( m_Rect.h % 2 == 0 ? m_Rect.h : m_Rect.h + 1 );
 532|  CPen     dashPen( PS_DOT, 1, color );
 533|  TwoD_XY  corner[Rect_nHandle];
 534|
 535|  oldPen = dc->SelectObject( &pen );
 536|  oldBrush = dc->SelectObject( &brush );
 537|
 538|  TwoD_XY_init( &center, m_Rect.x + (w + 1) / 2, m_Rect.y + (h + 1) / 2 );
 539|  for ( i = 1; i <= Rect_nHandle; i++ ) {
 540|    Rect_getCenterOfHandle( &m_Rect, i, &x, &y );
 541|    TwoD_XY_init( &xy, x, y );
 542|    TwoD_XY_rot( &xy, &center, angle );
 543|    x = (long)xy.x * p->zoom / 100 - p->x0;  y = (long)xy.y * p->zoom / 100 - p->y0;
 544|    dc->Rectangle( x - 3, y - 3, x + 3, y + 3 );
 545|    corner[i-1].x = x;  corner[i-1].y = y;
 546|  }
 547|
 548|  if ( bDrawFrame && m_RotateDegree != 0 &&
 549|       ( m_ShapeType == Rect_RoundRectShape || m_ShapeType == Rect_CircleShape ) ) {
 550|    dc->SelectObject( dashPen );
 551|    dc->MoveTo( (int)corner[0].x, (int)corner[0].y );
 552|    dc->LineTo( (int)corner[2].x, (int)corner[2].y );
 553|    dc->LineTo( (int)corner[7].x, (int)corner[7].y );
 554|    dc->LineTo( (int)corner[5].x, (int)corner[5].y );
 555|    dc->LineTo( (int)corner[0].x, (int)corner[0].y );
 556|  }
 557|
 558|  dc->SelectObject( oldBrush );
 559|  dc->SelectObject( oldPen );
 560|}
 561|
 562| 
 563|/***********************************************************************
 564|  2-13. <<< [Rect_Ex::copy] CadPrim::copy の実装部 >>> 
 565|************************************************************************/
 566|void  Rect_Ex::copy( CadPrim* a, ListX* prims )
 567|{
 568|  Rect_Ex*  r = (Rect_Ex*)a;
 569|
 570|  m_id = r->m_id;
 571|  m_IdLabel = r->m_IdLabel;
 572|  m_URL = r->m_URL;
 573|  m_Target = r->m_Target;
 574|  m_Rect = r->m_Rect;
 575|  m_RotateDegree = r->m_RotateDegree;
 576|  m_BorderWidth = r->m_BorderWidth;
 577|  m_BorderColor = r->m_BorderColor;
 578|  m_FillColor = r->m_FillColor;
 579|  m_NTrans = r->m_NTrans;
 580|  m_HatchType = r->m_HatchType;
 581|  m_ShapeType = r->m_ShapeType;
 582|  m_ImgPath = r->m_ImgPath;
 583|  m_ImgWorkPath = r->m_ImgWorkPath;
 584| // m_ddb = r->m_ddb;
 585|  m_bEmbedImg = r->m_bEmbedImg;
 586|  m_bNeedReadImgProp = r->m_bNeedReadImgProp;
 587|  m_ImgWidth = r->m_ImgWidth;
 588|  m_ImgHeight = r->m_ImgHeight;
 589|}
 590|
 591|/***********************************************************************
 592|  2-14. <<< [Rect_Ex::copyStyle] CadPrim::copyStyle の実装部 >>>
 593|************************************************************************/
 594|void  Rect_Ex::copyStyle( CadPrim* a, ListX* prims )
 595|{
 596|  Rect_Ex*  r = (Rect_Ex*)a;
 597|
 598|  m_BorderWidth = r->m_BorderWidth;
 599|  m_BorderColor = r->m_BorderColor;
 600|  m_FillColor = r->m_FillColor;
 601|  m_NTrans = r->m_NTrans;
 602|  m_HatchType = r->m_HatchType;
 603|}
 604|
 605|/***********************************************************************
 606|  2-15. <<< [Rect_Ex::isEqual] CadPrim::isEqual の実装部 >>>
 607|************************************************************************/
 608|bool  Rect_Ex::isEqual( CadPrim* a )
 609|{
 610|  Rect_Ex*  r = (Rect_Ex*)a;
 611|
 612|  return (
 613|    a->GetTypeID() == Rect_Ex_TypeID &&
 614|    m_id == r->m_id &&
 615|    m_IdLabel == r->m_IdLabel &&
 616|    m_URL == r->m_URL &&
 617|    m_Target == r->m_Target &&
 618|    m_Rect.x == r->m_Rect.x &&
 619|    m_Rect.y == r->m_Rect.y &&
 620|    m_Rect.w == r->m_Rect.w &&
 621|    m_Rect.h == r->m_Rect.h &&
 622|    m_RotateDegree == r->m_RotateDegree &&
 623|    m_BorderWidth == r->m_BorderWidth &&
 624|    m_BorderColor == r->m_BorderColor &&
 625|    m_FillColor == r->m_FillColor &&
 626|    m_NTrans == r->m_NTrans &&
 627|    m_HatchType == r->m_HatchType &&
 628|    m_ShapeType == r->m_ShapeType &&
 629|    m_ImgPath == r->m_ImgPath &&
 630|    m_ImgWorkPath == r->m_ImgWorkPath &&
 631|    m_ImgPath == r->m_ImgPath &&
 632|    m_bEmbedImg == r->m_bEmbedImg );
 633|}
 634|
 635|/***********************************************************************
 636|  2-16. <<< [Rect_Ex::GetNewCopy] CadPrim::GetNewCopy の実装部 >>>
 637|************************************************************************/
 638|CadPrim*  Rect_Ex::GetNewCopy( ListX* prims )
 639|{
 640|  Rect_Ex*  r = new Rect_Ex;
 641|
 642|  r->copy( this, prims );
 643|  return  r;
 644|}
 645|
 646|
 647|/***********************************************************************
 648|  2-17. <<< [Rect_Ex::GetSerializedSize] CadPrim::GetSerializedSize の実装部 >>>
 649|************************************************************************/
 650|int  Rect_Ex::GetSerializedSize()
 651|{
 652|  return  ( sizeof(*this) + m_IdLabel.GetLength() + 1 + m_ImgPath.GetLength() + 1 +
 653|     m_ImgWorkPath.GetLength() + 1 + m_URL.GetLength() + 1 +
 654|     m_Target.GetLength() + 1 + 3 ) & ~3;
 655|}
 656|
 657|
 658|/***********************************************************************
 659|  2-18. <<< [Rect_Ex::CopyToSerial] CadPrim::CopyToSerial の実装部 >>>
 660|************************************************************************/
 661|void  Rect_Ex::CopyToSerial( void* a )
 662|{
 663|  Rect_Ex*  r = (Rect_Ex*)a;
 664|  char*  s = (char*)a + sizeof(Rect_Ex);
 665|
 666|  r->m_id = m_id;
 667|//  r->m_IdLabel = m_IdLabel;
 668|//  r->m_URL = m_URL;
 669|//  r->m_Target = m_Target;
 670|  r->m_Rect = m_Rect;
 671|  r->m_RotateDegree = m_RotateDegree;
 672|  r->m_BorderWidth = m_BorderWidth;
 673|  r->m_BorderColor = m_BorderColor;
 674|  r->m_FillColor = m_FillColor;
 675|  r->m_NTrans = m_NTrans;
 676|  r->m_HatchType = m_HatchType;
 677|  r->m_ShapeType = m_ShapeType;
 678|//  r->m_ImgPath = m_ImgPath;
 679|//  r->m_ImgWorkPath = m_ImgWorkPath;
 680|  r->m_ddb = m_ddb;
 681|  r->m_bEmbedImg = m_bEmbedImg;
 682|  r->m_bNeedReadImgProp = m_bNeedReadImgProp;
 683|  r->m_ImgWidth = m_ImgWidth;
 684|  r->m_ImgHeight = m_ImgHeight;
 685|
 686|  strcpy( s, m_IdLabel );
 687|  s = strchr( s, '\0' ) + 1;
 688|  strcpy( s, m_URL );
 689|  s = strchr( s, '\0' ) + 1;
 690|  strcpy( s, m_Target );
 691|  s = strchr( s, '\0' ) + 1;
 692|  strcpy( s, m_ImgPath );
 693|  s = strchr( s, '\0' ) + 1;
 694|  strcpy( s, m_ImgWorkPath );
 695|}
 696|
 697|
 698|/***********************************************************************
 699|  2-19. <<< [Rect_Ex::CopyFromSerial] CadPrim::CopyFromSerial の実装部 >>>
 700|************************************************************************/
 701|void  Rect_Ex::CopyFromSerial( void* a )
 702|{
 703|  Rect_Ex*  r = (Rect_Ex*)a;
 704|  char*  s = (char*)a + sizeof(Rect_Ex);
 705|
 706|  m_id = r->m_id;
 707|//  m_IdLabel = r->m_IdLabel;
 708|//  m_URL = r->m_URL;
 709|//  m_Target = r->m_Target;
 710|  m_Rect = r->m_Rect;
 711|  m_RotateDegree = r->m_RotateDegree;
 712|  m_BorderWidth = r->m_BorderWidth;
 713|  m_BorderColor = r->m_BorderColor;
 714|  m_FillColor = r->m_FillColor;
 715|  m_NTrans = r->m_NTrans;
 716|  m_HatchType = r->m_HatchType;
 717|  m_ShapeType = r->m_ShapeType;
 718|//  m_ImgPath = r->m_ImgPath;
 719|//  m_ImgWorkPath = r->m_ImgWorkPath;
 720|  m_ddb = r->m_ddb;
 721|  m_bEmbedImg = r->m_bEmbedImg;
 722|  m_bNeedReadImgProp = r->m_bNeedReadImgProp;
 723|  m_ImgWidth = r->m_ImgWidth;
 724|  m_ImgHeight = r->m_ImgHeight;
 725|
 726|  m_IdLabel = s;
 727|  s = strchr( s, '\0' ) + 1;
 728|  m_URL = s;
 729|  s = strchr( s, '\0' ) + 1;
 730|  m_Target = s;
 731|  s = strchr( s, '\0' ) + 1;
 732|  m_ImgPath = s;
 733|  s = strchr( s, '\0' ) + 1;
 734|  m_ImgWorkPath = s;
 735|}
 736|
 737|
 738| 
 739|/***********************************************************************
 740|  2-20. <<< [Rect_Ex::GetHitHandleNum] Rect_getHitHandleNum の C++ ラップ >>> 
 741|************************************************************************/
 742|int  Rect_Ex::GetHitHandleNum( int x, int y, int zoom, int mode,
 743|  int* dx, int* dy, int* diff, int* arrow )
 744|{
 745|  TwoD_XY  xy, center;
 746|  int  r;
 747|
 748|  TwoD_XY_init( &xy, x, y );
 749|  TwoD_XY_init( &center, m_Rect.x + m_Rect.w / 2, m_Rect.y + m_Rect.h / 2 );
 750|  TwoD_XY_rot( &xy, &center, - m_RotateDegree * (2 * 3.141592) / 360 );
 751|
 752|  r = Rect_getHitHandleNum( &m_Rect, (int)xy.x, (int)xy.y, zoom, dx, dy, arrow );
 753|
 754|  /* 角度編集モードのときは、矩形、台形のみ回転できる */
 755|  if ( mode == CadPrim_RotateMode ) {
 756|    if ( r == -1 )
 757|      *arrow = CadPrim_NormalArrow;
 758|    else if ( r > 0 ) {
 759|      if ( m_ShapeType == Rect_RectShape || m_ShapeType == Text_Box_RoundRectShape ||
 760|           m_ShapeType == Rect_DiamondShape ) {
 761|        *arrow = CadPrim_MovableArrow;
 762|      }
 763|      else {
 764|        *arrow = CadPrim_NoArrow;
 765|      }
 766|    }
 767|  }
 768|
 769|  else {
 770|
 771|#if 0
 772|    /* 画像のときは、サイズ変更できないようにする */
 773|    if ( m_ShapeType == Rect_ImageShape && r > 0 && FileX_isExist( m_ImgPath ) ) {
 774|      *arrow = CadPrim_MovableArrow;
 775|      *dx = m_Rect.x - (int)xy.x;   *dy = m_Rect.y - (int)xy.y;
 776|      r = -1;
 777|    }
 778|#endif
 779|
 780|  }
 781|
 782|  return  r;
 783|}
 784|
 785|
 786|/***********************************************************************
 787|  2-21. <<< [Rect_Ex::Move] CadPrim::Move の実装部 >>>
 788|************************************************************************/
 789|void  Rect_Ex::Move( int dx, int dy )
 790|{
 791|  m_Rect.x += dx;  m_Rect.y += dy;
 792|}
 793|
 794|
 795|/***********************************************************************
 796|  2-22. <<< [Rect_Ex::MoveByHandle] Rect_moveByHandle の C++ ラップ >>>
 797|************************************************************************/
 798|void  Rect_Ex::MoveByHandle( int iHandle, int x, int y, bool bShift, bool bRotate )
 799|{
 800|  if ( bRotate ) {
 801|    int  cx = m_Rect.x + m_Rect.w / 2;
 802|    int  cy = m_Rect.y + m_Rect.h / 2;
 803|    int  hx, hy;
 804|    double  curAng, hdlAng;
 805|
 806|    switch ( iHandle ) {
 807|      case  1:  hx = m_Rect.x;             hy = m_Rect.y;  break;
 808|      case  2:  hx = cx;                   hy = m_Rect.y;  break;
 809|      case  3:  hx = m_Rect.x + m_Rect.w;  hy = m_Rect.y;  break;
 810|      case  4:  hx = m_Rect.x;             hy = cy;  break;
 811|      case  5:  hx = m_Rect.x + m_Rect.w;  hy = cy;  break;
 812|      case  6:  hx = m_Rect.x;             hy = m_Rect.y + m_Rect.h;  break;
 813|      case  7:  hx = cx;                   hy = m_Rect.y + m_Rect.h;  break;
 814|      case  8:  hx = m_Rect.x + m_Rect.w;  hy = m_Rect.y + m_Rect.h;  break;
 815|    }
 816|
 817|    curAng = atan2( y - cy, x - cx );
 818|    hdlAng = atan2( hy - cy, hx - cx );
 819|    m_RotateDegree = (int)( ( curAng - hdlAng ) * 360.0 / ( 2 * 3.141592 ) );
 820|    if ( ! bShift ) {
 821|      hx = m_RotateDegree % 90;
 822|      if ( hx < 0 )  hx += 90;
 823|      if ( hx < 8 )  m_RotateDegree -= hx;
 824|      else if ( hx > 82 )  m_RotateDegree += 90 - hx;
 825|    }
 826|  }
 827|  else {
 828|    TwoD_XY  xy, center;
 829|
 830|    TwoD_XY_init( &xy, x, y );
 831|    TwoD_XY_init( &center, m_Rect.x + m_Rect.w / 2, m_Rect.y + m_Rect.h / 2 );
 832|    TwoD_XY_rot( &xy, &center, - m_RotateDegree * (2 * 3.141592) / 360 );
 833|
 834|    if ( m_ShapeType == Rect_ImageShape ) {
 835|      Rect_moveByHandle( &m_Rect, iHandle, (int)xy.x, (int)xy.y, false );
 836|      if ( ! bShift && iHandle == 8 )
 837|        m_Rect.h = m_Rect.w * m_ImgHeight / m_ImgWidth;
 838|      if ( abs( m_Rect.w - m_ImgWidth ) <= 4 )  m_Rect.w = m_ImgWidth;
 839|      if ( abs( m_Rect.h - m_ImgHeight ) <= 4 )  m_Rect.h = m_ImgHeight;
 840|    }
 841|    else
 842|      Rect_moveByHandle( &m_Rect, iHandle, (int)xy.x, (int)xy.y, bShift );
 843|  }
 844|}
 845|
 846|
 847|/***********************************************************************
 848|  2-23. <<< [Rect_Ex::GetCenterOfHandle] CadPrim::GetCenterOfHandle >>>
 849|************************************************************************/
 850|void  Rect_Ex::GetCenterOfHandle( int iHandle, int* x, int* y )
 851|{
 852|  switch ( iHandle ) {
 853|    case 1:  *x = m_Rect.x;                 *y = m_Rect.y;  break;
 854|    case 2:  *x = m_Rect.x + m_Rect.w / 2;  *y = m_Rect.y;  break;
 855|    case 3:  *x = m_Rect.x + m_Rect.w;      *y = m_Rect.y;  break;
 856|    case 4:  *x = m_Rect.x;                 *y = m_Rect.y + m_Rect.h / 2;  break;
 857|    case 5:  *x = m_Rect.x + m_Rect.w;      *y = m_Rect.y + m_Rect.h / 2;  break;
 858|    case 6:  *x = m_Rect.x;                 *y = m_Rect.y + m_Rect.h;  break;
 859|    case 7:  *x = m_Rect.x + m_Rect.w / 2;  *y = m_Rect.y + m_Rect.h;  break;
 860|    case 8:  *x = m_Rect.x + m_Rect.w;      *y = m_Rect.y + m_Rect.h;  break;
 861|  }
 862|}
 863|
 864| 
 865|/***********************************************************************
 866|  2-24. <<< [Rect_Ex::SetHold] CadPrim::SetHold の実装部 >>> 
 867|************************************************************************/
 868|void  Rect_Ex::SetHold( bool b )
 869|{
 870|  m_bHold = b;
 871|}
 872|
 873|/***********************************************************************
 874|  2-25. <<< [Rect_Ex::GetHold] CadPrim::GetHold の実装部 >>>
 875|************************************************************************/
 876|bool  Rect_Ex::GetHold()
 877|{
 878|  return  m_bHold;
 879|}
 880|
 881|/***********************************************************************
 882|  2-26. <<< [Rect_Ex::IsHoldable] CadPrim::IsHoldable の実装部 >>>
 883|************************************************************************/
 884|bool  Rect_Ex::IsHoldable()
 885|{
 886|  return  true;
 887|}
 888|
 889|/***********************************************************************
 890|  2-27. <<< [Rect_Ex::SetSelected] CadPrim::SetSelected の実装部 >>>
 891|************************************************************************/
 892|void  Rect_Ex::SetSelected( bool b )
 893|{
 894|  m_bSelected = b;
 895|}
 896|
 897|/***********************************************************************
 898|  2-28. <<< [Rect_Ex::GetSelected] CadPrim::GetSelected の実装部 >>>
 899|************************************************************************/
 900|bool  Rect_Ex::GetSelected()
 901|{
 902|  return  m_bSelected;
 903|}
 904|
 905| 
 906|/***********************************************************************
 907|  2-29. <<< [Rect_Ex::IsMultiSelect] CadPrim::IsMultiSelect の実装部 >>> 
 908|************************************************************************/
 909|bool  Rect_Ex::IsMultiSelect( Rect* rect )
 910|{
 911|  Rect  com;
 912|
 913|  Rect_toAnd( &com, &m_Rect, rect );
 914|  return  ( com.w > 0 && com.h > 0 );
 915|}
 916|
 917|
 918|/***********************************************************************
 919|  2-30. <<< [Rect_Ex::GetForAlign] CadPrim::GetForAlign の実装部 >>>
 920|************************************************************************/
 921|int   Rect_Ex::GetForAlign( int iPos )
 922|{
 923|  switch ( iPos ) {
 924|    case  CadPrim_AlignLeft:    return  m_Rect.x;
 925|    case  CadPrim_AlignRight:   return  m_Rect.x + m_Rect.w;
 926|    case  CadPrim_AlignTop:     return  m_Rect.y;
 927|    case  CadPrim_AlignBottom:  return  m_Rect.y + m_Rect.h;
 928|    case  CadPrim_AlignVertical:    return  m_Rect.x + m_Rect.w / 2;
 929|    case  CadPrim_AlignHorizontal:  return  m_Rect.y + m_Rect.h / 2;
 930|    default:  error();  return  0;
 931|  }
 932|}
 933|
 934|/***********************************************************************
 935|  2-31. <<< [Rect_Ex::SetForAlign] CadPrim::SetForAlign の実装部 >>>
 936|************************************************************************/
 937|void  Rect_Ex::SetForAlign( int iPos, int value )
 938|{
 939|  switch ( iPos ) {
 940|    case  CadPrim_AlignLeft:    m_Rect.x = value;  break;
 941|    case  CadPrim_AlignRight:   m_Rect.x = value - m_Rect.w;  break;
 942|    case  CadPrim_AlignTop:     m_Rect.y = value;  break;
 943|    case  CadPrim_AlignBottom:  m_Rect.y = value - m_Rect.h;  break;
 944|    case  CadPrim_AlignVertical:    m_Rect.x = value - m_Rect.w / 2;  break;
 945|    case  CadPrim_AlignHorizontal:  m_Rect.y = value - m_Rect.h / 2;  break;
 946|    default:  error();
 947|  }
 948|}
 949|
 950|/***********************************************************************
 951|  2-32. <<< [Rect_Ex::GetForFitSize] CadPrim::GetForFitSize の実装部 >>>
 952|************************************************************************/
 953|int   Rect_Ex::GetForFitSize( int iAttr )
 954|{
 955|  if ( iAttr == CadPrim_Horizontal )  return  m_Rect.w;
 956|  else  return  m_Rect.h;
 957|}
 958|
 959|/***********************************************************************
 960|  2-33. <<< [Rect_Ex::SetForFitSize] CadPrim::SetForFitSize の実装部 >>>
 961|************************************************************************/
 962|void  Rect_Ex::SetForFitSize( int iAttr, int value )
 963|{
 964|  if ( iAttr == CadPrim_Horizontal )
 965|    m_Rect.w = value;
 966|  else
 967|    m_Rect.h = value;
 968|}
 969| 
 970|/***********************************************************************
 971|  2-34. <<< [Rect_Ex::OnCreated] CadPrim::OnCreated の実装部 >>> 
 972|************************************************************************/
 973|void  Rect_Ex::OnCreated()
 974|{
 975|  if ( m_Rect.w <= 2 && m_Rect.h <= 2 ) {
 976|    m_Rect.w = 32; m_Rect.h = 20;
 977|  }
 978|}
 979|
 980| 
 981|/***********************************************************************
 982|  2-35. <<< [Rect_Ex::GetNProp] プロパティの要素数を返す >>> 
 983|************************************************************************/
 984|int  Rect_Ex::GetNProp()
 985|{
 986|  int  plus = ( m_ShapeType == Rect_ImageShape ? 4 : 0 );
 987|
 988|  #ifdef  NDEBUG
 989|    return  16 + plus;
 990|  #else
 991|    return  17 + plus;
 992|  #endif
 993|}
 994|
 995|
 996|/***********************************************************************
 997|  2-36. <<< [Rect_Ex::GetProp] プロパティの名前と値を取得する >>>
 998|************************************************************************/
 999|int  Rect_Ex::GetProp( int iProp, bool bJapanese, char* name, int name_size,
1000|  char* value, int value_size, const char* path, void** option )
1001|{
1002|  int  r = CadPrim_ReadOnly;
1003|
1004|  static ListX  list;
1005|  static StrX_ListElem  strs[5];
1006|  static int            range[2];
1007|
1008|  if ( m_ShapeType != Rect_ImageShape && iProp >= 2 )  iProp += 2;
1009|  if ( m_ShapeType != Rect_ImageShape && iProp >= 13 )  iProp += 2;
1010|
1011|  switch ( iProp ) {
1012|    case 0:
1013|      if ( bJapanese ) {
1014|        strncpy( name, "形状", name_size );
1015|        sprintf( value, "%d", m_ShapeType - 1 );
1016|        ListX_init( &list );
1017|        ListX_addLast( &list, &strs[0] );  strs[0].p = "矩形、長方形";
1018|        ListX_addLast( &list, &strs[1] );  strs[1].p = "丸矩形";
1019|        ListX_addLast( &list, &strs[2] );  strs[2].p = "円、楕円";
1020|        ListX_addLast( &list, &strs[3] );  strs[3].p = "ひし形";
1021|        ListX_addLast( &list, &strs[4] );  strs[4].p = "画像";
1022|      }
1023|      else {
1024|        strncpy( name, "Figure", name_size );
1025|        sprintf( value, "%d", m_ShapeType - 1 );
1026|        ListX_init( &list );
1027|        ListX_addLast( &list, &strs[0] );  strs[0].p = "Rectangle";
1028|        ListX_addLast( &list, &strs[1] );  strs[1].p = "Round Rectangle";
1029|        ListX_addLast( &list, &strs[2] );  strs[2].p = "Circle, Ellipse";
1030|        ListX_addLast( &list, &strs[3] );  strs[3].p = "Diamond";
1031|        ListX_addLast( &list, &strs[4] );  strs[4].p = "Image";
1032|      }
1033|      *option = &list;
1034|      r = CadPrim_Select;
1035|      break;
1036|    case 1:
1037|      if ( bJapanese ) {
1038|        strncpy( name, "画像ファイルパス", name_size );
1039|        if ( path[0] == '\0' )  strcpy( value, m_ImgPath );
1040|        else  StrX_cpyStepPath2( value, m_ImgPath, value_size, path );
1041|        *option = (void*)"画像ファイル(*.jpg;*.gif;*.png)|*.jpg;*.gif;*.png|すべてのファイル (*.*)|*.*||";
1042|      }
1043|      else {
1044|        strncpy( name, "Image Path", name_size );
1045|        if ( path[0] == '\0' )  strcpy( value, m_ImgPath );
1046|        else  StrX_cpyStepPath2( value, m_ImgPath, value_size, path );
1047|        *option = (void*)"Image File(*.jpg;*.gif;*.png)|*.jpg;*.gif;*.png|All Files (*.*)|*.*||";
1048|      }
1049|      r = CadPrim_PathMust;
1050|      break;
1051|    case 2: {
1052|      int  size = FileX_getSize( m_bEmbedImg ? m_ImgWorkPath : m_ImgPath );
1053|      int  size10;
1054|
1055|      size10 = ( (size + 101) % 1024) / 102;
1056|      if ( size10 >= 10 )  size10 = 9;
1057|      size = ( size + 101 ) / 1024;
1058|
1059|      strncpy( name, "サイズ", name_size );
1060|      sprintf( value, "%d.%dKB", size, size10 );
1061|      break;
1062|    }
1063|    case 3:
1064|      strncpy( name, bJapanese ? "画像埋め込み" : "embed image", name_size );
1065|      sprintf( value, "%d", m_bEmbedImg );
1066|      r = CadPrim_Bool;
1067|      break;
1068|    case 4:
1069|      strncpy( name, "id", name_size );
1070|      strncpy( value, m_IdLabel, value_size );
1071|      *option = NULL;
1072|      r = CadPrim_Text;
1073|      break;
1074|    case 5:
1075|      strncpy( name, "URL/onclick", name_size );
1076|      #if 1
1077|        if ( path[0] == '\0' )  strcpy( value, m_URL );
1078|        else  StrX_cpyStepPath2( value, m_URL, value_size, path );
1079|        if ( bJapanese )
1080|          *option = (void*)"すべてのファイル (*.*)|*.*||";
1081|        else
1082|          *option = (void*)"All Files (*.*)|*.*||";
1083|        r = CadPrim_Path;
1084|      #else
1085|        strncpy( value, m_URL, value_size );
1086|        r = CadPrim_Text;
1087|      #endif
1088|      break;
1089|    case 6:
1090|      strncpy( name, "target", name_size );
1091|      strncpy( value, m_Target, value_size );
1092|      *option = NULL;
1093|      r = CadPrim_Text;
1094|      break;
1095|    case 7:
1096|      if ( bJapanese )
1097|        strncpy( name, "x (左)", name_size );
1098|      else
1099|        strncpy( name, "x (Left)", name_size );
1100|      sprintf( value, "%d", m_Rect.x );
1101|      range[0] = INT_MIN;  range[1] = INT_MAX;
1102|      *option = range;
1103|      r = CadPrim_Int;
1104|      break;
1105|    case 8:
1106|      if ( bJapanese )
1107|        strncpy( name, "y (上)", name_size );
1108|      else
1109|        strncpy( name, "y (Top)", name_size );
1110|      sprintf( value, "%d", m_Rect.y );
1111|      range[0] = INT_MIN;  range[1] = INT_MAX;
1112|      *option = range;
1113|      r = CadPrim_Int;
1114|      break;
1115|    case 9:
1116|      if ( bJapanese )
1117|        strncpy( name, "x (右)", name_size );
1118|      else
1119|        strncpy( name, "x (Right)", name_size );
1120|      sprintf( value, "%d", m_Rect.x + m_Rect.w );
1121|      range[0] = INT_MIN;  range[1] = INT_MAX;
1122|      *option = range;
1123|      r = CadPrim_Int;
1124|      break;
1125|    case 10:
1126|      if ( bJapanese )
1127|        strncpy( name, "y (下)", name_size );
1128|      else
1129|        strncpy( name, "y (Bottom)", name_size );
1130|      sprintf( value, "%d", m_Rect.y + m_Rect.h );
1131|      range[0] = INT_MIN;  range[1] = INT_MAX;
1132|      *option = range;
1133|      r = CadPrim_Int;
1134|      break;
1135|    case 11:
1136|      if ( bJapanese )
1137|        strncpy( name, "幅", name_size );
1138|      else
1139|        strncpy( name, "width", name_size );
1140|      sprintf( value, "%d", m_Rect.w );
1141|      range[0] = 1;  range[1] = INT_MAX;
1142|      *option = range;
1143|      r = CadPrim_Int;
1144|      break;
1145|    case 12:
1146|      if ( bJapanese )
1147|        strncpy( name, "高さ", name_size );
1148|      else
1149|        strncpy( name, "Height", name_size );
1150|      sprintf( value, "%d", m_Rect.h );
1151|      range[0] = 1;  range[1] = INT_MAX;
1152|      *option = range;
1153|      r = CadPrim_Int;
1154|      break;
1155|    case 13:
1156|      if ( bJapanese )
1157|        strncpy( name, "X拡大(%)", name_size );
1158|      else
1159|        strncpy( name, "x-zoom", name_size );
1160|      sprintf( value, "%d", m_Rect.w * 100 / m_ImgWidth );
1161|      range[0] = 1;  range[1] = INT_MAX;
1162|      *option = range;
1163|      r = CadPrim_Int;
1164|      break;
1165|    case 14:
1166|      if ( bJapanese )
1167|        strncpy( name, "Y拡大(%)", name_size );
1168|      else
1169|        strncpy( name, "y-zoom", name_size );
1170|      sprintf( value, "%d", m_Rect.h * 100 / m_ImgHeight );
1171|      range[0] = 1;  range[1] = INT_MAX;
1172|      *option = range;
1173|      r = CadPrim_Int;
1174|      break;
1175|    case 15:
1176|      if ( bJapanese )
1177|        strncpy( name, "角度", name_size );
1178|      else
1179|        strncpy( name, "Angle", name_size );
1180|      sprintf( value, "%d", m_RotateDegree );
1181|      range[0] = INT_MIN;  range[1] = INT_MAX;
1182|      *option = range;
1183|      r = CadPrim_Int;
1184|      break;
1185|    case 16:
1186|      if ( bJapanese )
1187|        strncpy( name, "塗りつぶし色", name_size );
1188|      else
1189|        strncpy( name, "Fill Color", name_size );
1190|      StrX_getColorStr( value, m_FillColor );
1191|      r = CadPrim_Color;
1192|      break;
1193|    case 17:
1194|      if ( bJapanese )
1195|        strncpy( name, "濃さ(非透過率%)", name_size );
1196|      else
1197|        strncpy( name, "Transparent %", name_size );
1198|      sprintf( value, "%d", m_NTrans );
1199|      range[0] = 0;  range[1] = 100;
1200|      *option = range;
1201|      r = CadPrim_Int;
1202|      break;
1203|    case 18:
1204|      if ( bJapanese )
1205|        strncpy( name, "境界色", name_size );
1206|      else
1207|        strncpy( name, "Border Color", name_size );
1208|      StrX_getColorStr( value, m_BorderColor );
1209|      r = CadPrim_Color;
1210|      break;
1211|    case 19:
1212|      if ( bJapanese )
1213|        strncpy( name, "境界幅", name_size );
1214|      else
1215|        strncpy( name, "Border Width", name_size );
1216|      sprintf( value, "%d", m_BorderWidth );
1217|      range[0] = 0;  range[1] = INT_MAX;
1218|      *option = range;
1219|      r = CadPrim_Int;
1220|      break;
1221|   #ifndef NDEBUG
1222|    case 20:
1223|      strncpy( name, "id", name_size );
1224|      sprintf( value, "%d", m_id );
1225|      break;
1226|   #endif
1227|  }
1228|
1229|  return  r;
1230|}
1231|
1232|/***********************************************************************
1233|  2-37. <<< [Rect_Ex::SetProp] プロパティの値を設定する >>>
1234|************************************************************************/
1235|void  Rect_Ex::SetProp( int iProp, const char* value, const char* path )
1236|{
1237|  char  absPath[_MAX_PATH];
1238|
1239|  if ( m_ShapeType != Rect_ImageShape && iProp >= 2 )  iProp += 2;
1240|  if ( m_ShapeType != Rect_ImageShape && iProp >= 13 )  iProp += 2;
1241|
1242|  switch ( iProp ) {
1243|    case 0:
1244|      m_ShapeType = atoi( value ) + 1;
1245|      if ( m_ShapeType < 1 || m_ShapeType > 5 )  m_ShapeType = 1;
1246|      // if ( m_ShapeType != Rect_ImageShape )  m_ImgPath = "";
1247|      break;
1248|    case 1:
1249|      if ( path[0] == '\0' )  strcpy( absPath, value );
1250|      else {
1251|        c_try {
1252|          StrX_cpyAbsPath2( absPath, value, sizeof(absPath), path );
1253|        }
1254|        c_catch ( Errors_Msg*, msg ) {
1255|          if ( msg->code == StrX_Err_NoMoreParentDir )
1256|            strcpy( absPath, value );
1257|          else
1258|            c_throw_again();
1259|        } c_end_catch;
1260|      }
1261|      m_ImgPath = absPath;
1262|      m_ShapeType = Rect_ImageShape;
1263|      m_bNeedReadImgProp = true;
1264|      break;
1265|    case 3:
1266|      m_bEmbedImg = ( *value != '0' );
1267|      break;
1268|    case 4:
1269|      m_IdLabel = value;
1270|      break;
1271|    case 5:
1272|      m_URL = value;
1273|      break;
1274|    case 6:
1275|      m_Target = value;
1276|      break;
1277|    case 7:
1278|      m_Rect.x = atoi( value );
1279|      break;
1280|    case 8:
1281|      m_Rect.y = atoi( value );
1282|      break;
1283|    case 9:
1284|      m_Rect.w = atoi( value ) - m_Rect.x;
1285|      if ( m_Rect.w <= 0 )  m_Rect.w = 1;
1286|      break;
1287|    case 10:
1288|      m_Rect.h = atoi( value ) - m_Rect.y;
1289|      if ( m_Rect.h <= 0 )  m_Rect.h = 1;
1290|      break;
1291|    case 11:
1292|      m_Rect.w = atoi( value );
1293|      break;
1294|    case 12:
1295|      m_Rect.h = atoi( value );
1296|      break;
1297|    case 13: {
1298|      float  mul = ((float)atoi( value ) + 0.5f) / (m_Rect.w * 100 / m_ImgWidth);
1299|      int  value2;
1300|
1301|      if ( atoi(value) == 100 )  m_Rect.w = m_ImgWidth;
1302|      else  m_Rect.w = (atoi( value ) * 10 + 5) * m_ImgWidth / 1000;
1303|
1304|      if ( MessageBox( NULL, "高さの倍率も同様に変えますか?", "確認", MB_YESNO ) == IDYES ) {
1305|        value2 = (int)( m_Rect.h * 100 / m_ImgHeight * mul );
1306|        if ( value2 == 100 )  m_Rect.h = m_ImgHeight;
1307|        else  m_Rect.h = (value2 * 10 + 5) * m_ImgHeight/ 1000;
1308|      }
1309|      break;
1310|    }
1311|    case 14: {
1312|      float  mul = ((float)atoi( value ) + 0.5f) / (m_Rect.h * 100 / m_ImgHeight);
1313|      int  value2;
1314|
1315|      if ( atoi(value) == 100 )  m_Rect.h = m_ImgHeight;
1316|      else  m_Rect.h = (atoi( value ) * 10 + 5) * m_ImgHeight/ 1000;
1317|
1318|      if ( MessageBox( NULL, "幅の倍率も同様に変えますか?", "確認", MB_YESNO ) == IDYES ) {
1319|        value2 = (int)( m_Rect.w * 100 / m_ImgWidth * mul );
1320|        if ( value2 == 100 )  m_Rect.w = m_ImgWidth;
1321|        else  m_Rect.w = (value2 * 10 + 5) * m_ImgWidth / 1000;
1322|      }
1323|      break;
1324|    }
1325|    case 15:
1326|      m_RotateDegree = atoi( value );
1327|      break;
1328|    case 16:
1329|      m_FillColor = StrX_getColorValue( value );
1330|      break;
1331|    case 17:
1332|      m_NTrans = atoi( value );
1333|      break;
1334|    case 18:
1335|      m_BorderColor = StrX_getColorValue( value );
1336|      break;
1337|    case 19:
1338|      m_BorderWidth = atoi( value );
1339|      break;
1340|  }
1341|}
1342| 
1343|/***********************************************************************
1344|  2-38. <<< [Rect_Ex::IsNeedUnicode] CadPrim::IsNeedUnicode の実装部 >>> 
1345|************************************************************************/
1346|bool  Rect_Ex::IsNeedUnicode()
1347|{
1348|  return  StrX_isExist2byte( m_ImgPath ) != 0;
1349|}
1350|
1351| 
1352|#endif 
1353|
1354| 
1355|