home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / PASM.LZH / PARTSDLG.CPP < prev    next >
C/C++ Source or Header  |  1996-07-03  |  8KB  |  329 lines

  1. /*  Project partsasm
  2.     Project Team DoGA
  3.     Copyright (c) 1995. All Rights Reserved.
  4.  
  5.     サブシステム:    partsasm.apx Application
  6.     ファイル:        partsdlg.cpp
  7.     作成者:          Taka2
  8.  
  9.  
  10.     概要
  11.     ====
  12.     PartsDialog (TDialog) のインプリメンテーション用のソースファイル
  13. */
  14.  
  15. #include <owl\owlpch.h>
  16. #pragma hdrstop
  17.  
  18. #include <stdio.h>
  19. #include "partsdlg.h"
  20. //#include "pasmapp.rh"
  21. #include "profile.h"
  22. #include "files.h"
  23. #include "log.h"
  24.  
  25. static const int PixelWidth=512, PixelHeight=384;
  26. static const TColor& cSelect = TColor::LtRed;
  27. static const TSize  CatalogSize(PixelWidth, PixelHeight);
  28. //static const TPoint CatalogPosition(120, 10);
  29. #define CatalogPosition TPoint(textwidth*15,textwidth)
  30.  
  31.  
  32. //
  33. // このアプリケーションで処理するすべてのメッセージ/コマンドの
  34. // 応答テーブルを作成する
  35. //
  36. DEFINE_RESPONSE_TABLE1(PartsDialog, TDialog)
  37. //{{PartsDialogRSP_TBL_BEGIN}}
  38.     EV_WM_LBUTTONDOWN,
  39.     EV_WM_PAINT,
  40.     EV_LBN_SELCHANGE(IDC_PARTS_LISTBOX, LBNSelchange),
  41.     EV_WM_PALETTECHANGED,
  42.     EV_WM_QUERYNEWPALETTE,
  43.     EV_WM_LBUTTONDBLCLK,
  44. //{{PartsDialogRSP_TBL_END}}
  45. END_RESPONSE_TABLE;
  46.  
  47.  
  48. //{{PartsDialog Implementation}}
  49.  
  50.  
  51. PartsDialog::PartsDialog (TWindow* parent, int lastmenu, int lastparts):
  52.     TDialog(parent, IDD_PARTS, NULL)
  53. {
  54.     // INSERT>> コンストラクタ用のコードはここに
  55.  
  56. //    SetBkgndColor(TColor::LtGray);
  57.  
  58.     pListBox = new TListBox(this, IDC_PARTS_LISTBOX);
  59.     pStatic = new TStatic(this, IDC_PARTS_NAME);
  60. //    pStatic->SetBkgndColor(TColor::LtGray);
  61.  
  62.     nowmenu = -1;
  63.     nowparts = -1;
  64.     CatalogDib = NULL;
  65.     CatalogPalette = NULL;
  66. //    partsname = NULL;
  67. //    partscount = 0;
  68. //    ProfileRead();
  69.     OpenCatalog(lastmenu);
  70.     SelectParts(lastparts);
  71. }
  72.  
  73.  
  74. PartsDialog::~PartsDialog ()
  75. {
  76.     Destroy();
  77.  
  78.     // INSERT>> デストラクタ用のコードはここに
  79.     delete CatalogPalette;
  80.     delete CatalogDib;
  81. //    delete [] partsname;
  82. }
  83.  
  84. void PartsDialog::SelectParts(int no)
  85. {
  86.     if (no == -1) {
  87.         nowparts = -1;
  88.         filename[0] = '\0';
  89.         pStatic->SetText(filename);
  90.     } else if (nowparts != no) {
  91.         nowparts = no;
  92.         wsprintf(filename, "%s%02d", partsname[nowmenu].partsfile.c_str(), no+1);
  93.         pStatic->SetText(filename);
  94.         strcat(filename, ".SUF");
  95.     }
  96. }
  97.  
  98. static void GetXY(int *ux, int *uy, int tw)
  99. {
  100.     if (tw < 8) {
  101.         *ux = tw * 16;
  102.         *uy = tw * 12;
  103.     } else {
  104.         *ux = PixelWidth/4;
  105.         *uy = PixelHeight/4;
  106.     }
  107. }
  108.  
  109. void PartsDialog::drawSelBox(TDC& dc, int no)
  110. {
  111.     if (no < 0 || no >= 16) {
  112.         return;
  113.     }
  114. //    const int ux=textwidth*16, uy=textwidth*12;
  115.     int ux, uy;
  116.     GetXY(&ux, &uy, textwidth);
  117.     int x = no % 4;
  118.     int y = no / 4;
  119.     dc.MoveTo(CatalogPosition + TPoint( x   *ux,    y   *uy));
  120.     dc.LineTo(CatalogPosition + TPoint((x+1)*ux,    y   *uy));
  121.     dc.LineTo(CatalogPosition + TPoint((x+1)*ux,   (y+1)*uy));
  122.     dc.LineTo(CatalogPosition + TPoint( x   *ux,   (y+1)*uy));
  123.     dc.LineTo(CatalogPosition + TPoint( x   *ux,    y   *uy));
  124.     dc.MoveTo(CatalogPosition + TPoint( x   *ux+1,  y   *uy+1));
  125.     dc.LineTo(CatalogPosition + TPoint((x+1)*ux-1,  y   *uy+1));
  126.     dc.LineTo(CatalogPosition + TPoint((x+1)*ux-1, (y+1)*uy-1));
  127.     dc.LineTo(CatalogPosition + TPoint( x   *ux+1, (y+1)*uy-1));
  128.     dc.LineTo(CatalogPosition + TPoint( x   *ux+1,  y   *uy+1));
  129.  
  130. }
  131.  
  132. void PartsDialog::EvLButtonDown (UINT modKeys, TPoint& point)
  133. {
  134.     TDialog::EvLButtonDown(modKeys, point);
  135.  
  136.     // INSERT>> 追加コードはここに
  137.  
  138. //    const ux=textwidth*16, uy=textwidth*12;
  139.     int ux, uy;
  140.     GetXY(&ux, &uy, textwidth);
  141.  
  142.     TPoint p;
  143.     p = point - CatalogPosition;
  144.     if (nowmenu >= 0 && 0 <= p.x && p.x < ux*4 && 0 <= p.y && p.y < uy*4) {
  145.         int x, y, n;
  146.         x = p.x / ux;
  147.         y = p.y / uy;
  148.         n = y * 4 + x;
  149.         if (n != nowparts) {
  150.             TClientDC dc(*this);
  151.             dc.SelectStockObject(WHITE_PEN);
  152. //            dc.SelectObject(TPen(TColor::LtGray));
  153.             drawSelBox(dc, nowparts);
  154.             dc.SelectObject(TPen(cSelect));
  155.             drawSelBox(dc, n);
  156.             SelectParts(n);
  157.         }
  158.     }
  159. }
  160.  
  161. void PartsDialog::EvPaint ()
  162. {
  163.     TDialog::EvPaint();
  164.  
  165. //    int ux=textwidth*16, uy=textwidth*12;
  166.     int ux, uy;
  167.     GetXY(&ux, &uy, textwidth);
  168.  
  169.     // INSERT>> 追加コードはここに
  170.     TClientDC dc(*this);
  171.  
  172.     if (CatalogPalette) {
  173.       dc.SelectObject(*CatalogPalette, FALSE);
  174.       dc.RealizePalette();
  175.     }
  176.  
  177.     TRect clientRect(CatalogPosition, TSize(ux*4,uy*4));
  178.     if (CatalogDib) {
  179.         if (textwidth < 8) {
  180.             TRect srcRect(TPoint(0,0), CatalogSize);
  181.             dc.StretchDIBits(clientRect, srcRect, *CatalogDib);
  182.         } else {
  183.             dc.SetDIBitsToDevice(clientRect, TPoint(0,0), *CatalogDib);
  184.         }
  185.     } else {
  186.         dc.PatBlt(clientRect, PATCOPY);
  187.     }
  188. //    dc.SelectObject(TPen(TColor::LtGray));
  189.     dc.SelectStockObject(WHITE_PEN);
  190.     for (int i = 0; i < 5; ++i) {
  191.         dc.MoveTo(CatalogPosition + TPoint(   0, i*uy-1)); dc.LineTo(CatalogPosition + TPoint(4*ux, i*uy-1));
  192.         dc.MoveTo(CatalogPosition + TPoint(   0, i*uy));   dc.LineTo(CatalogPosition + TPoint(4*ux, i*uy  ));
  193.         dc.MoveTo(CatalogPosition + TPoint(   0, i*uy+1)); dc.LineTo(CatalogPosition + TPoint(4*ux, i*uy+1));
  194.         dc.MoveTo(CatalogPosition + TPoint(i*ux-1,    0)); dc.LineTo(CatalogPosition + TPoint(i*ux-1, 4*uy));
  195.         dc.MoveTo(CatalogPosition + TPoint(i*ux  ,    0)); dc.LineTo(CatalogPosition + TPoint(i*ux  , 4*uy));
  196.         dc.MoveTo(CatalogPosition + TPoint(i*ux+1,    0)); dc.LineTo(CatalogPosition + TPoint(i*ux+1, 4*uy));
  197.     }
  198.     if (nowparts >= 0) {
  199.         dc.SelectObject(TPen(cSelect));
  200.         drawSelBox(dc, nowparts);
  201.     }
  202. }
  203.  
  204.  
  205. void PartsDialog::LBNSelchange ()
  206. {
  207.     // INSERT>> 追加コードはここに
  208.     int no;
  209.     if ((no = int(pListBox->GetItemData(pListBox->GetSelIndex()))) != nowmenu) {
  210.         OpenCatalog(no);
  211.         EvPaint();
  212.     }
  213. }
  214.  
  215. void PartsDialog::SetupWindow ()
  216. {
  217.     TDialog::SetupWindow();
  218.  
  219.     // INSERT>> 追加のコードはここに
  220.     for (int i = 0; i < partscount; ++i) {
  221.         int no = pListBox->AddString(partsname[i].title.c_str());
  222.         pListBox->SetItemData(no, i);
  223.     }
  224.     pListBox->SetSelIndex(nowmenu);
  225.  
  226.     int n = nowparts;
  227.     nowparts = -1;
  228.     SelectParts(n);
  229.     TEXTMETRIC metric;
  230.     TClientDC(*this).GetTextMetrics(metric);
  231.     textwidth = metric.tmAveCharWidth;
  232.  
  233. }
  234.  
  235. void PartsDialog::UpdatePalette(BOOL alwaysRepaint)
  236. {
  237.   if (CatalogPalette) {
  238.     TClientDC clientDC(*this);
  239.     #if !defined(__WIN32__)
  240.       CatalogPalette->UnrealizeObject();
  241.     #endif
  242.     clientDC.SelectObject(*CatalogPalette, FALSE);
  243.     if (clientDC.RealizePalette() > 0)
  244.       if (alwaysRepaint)
  245.         Invalidate(FALSE);
  246.       else
  247.         clientDC.UpdateColors();
  248.   }
  249. }
  250.  
  251.  
  252. void PartsDialog::OpenCatalog(int no)
  253. {
  254.     if (no < 0 || no >= partscount) {
  255.         return;
  256.     }
  257.     TDib* dib = 0;
  258.     try {
  259.         dib = new TDib(partsname[no].catalogfile.c_str());
  260.     }
  261.     catch (TGdiBase::TXGdi) {
  262.         char str[120];
  263.         sprintf(str, "ビットマップファイル(%s)を開けません", partsname[no].catalogfile.c_str());
  264.         MessageBox(str, GetApplication()->GetName(), MB_OK);
  265.         return;
  266.     }
  267.     nowmenu = no;
  268.     SelectParts(-1);
  269.     delete CatalogDib;
  270.     delete CatalogPalette;
  271.     CatalogDib = dib;
  272.     CatalogPalette = new TPalette(*dib);
  273.  
  274.     UpdatePalette(TRUE);
  275. }
  276.  
  277.  
  278.  
  279. void PartsDialog::EvPaletteChanged (HWND hWndPalChg)
  280. {
  281.     TDialog::EvPaletteChanged(hWndPalChg);
  282.  
  283.     // INSERT>> 追加コードはここに
  284.  
  285.   if (hWndPalChg != HWindow)
  286.     UpdatePalette(TRUE);    // 再描画する代わりに,UpdateColors() に FALSE を渡す
  287.  
  288. }
  289.  
  290.  
  291. BOOL PartsDialog::EvQueryNewPalette ()
  292. {
  293.     BOOL result;
  294.  
  295.     result = TDialog::EvQueryNewPalette();
  296.  
  297.     // INSERT>> 追加コードはここに
  298.  
  299.     UpdatePalette(TRUE);
  300.  
  301.     return result;
  302. }
  303.  
  304.  
  305.  
  306. void PartsDialog::EvLButtonDblClk (UINT modKeys, TPoint& point)
  307. {
  308.     TDialog::EvLButtonDblClk(modKeys, point);
  309.  
  310.     // INSERT>> 追加コードはここに
  311.  
  312. //    const int ux=textwidth*16, uy=textwidth*12;
  313.     int ux, uy;
  314.     GetXY(&ux, &uy, textwidth);
  315.  
  316.     TPoint p;
  317.     p = point - CatalogPosition;
  318.     if (nowmenu >= 0 && 0 <= p.x && p.x < ux*4 && 0 <= p.y && p.y < uy*4) {
  319.         int x, y, n;
  320.         x = p.x / ux;
  321.         y = p.y / uy;
  322.         n = y * 4 + x;
  323.  
  324.         SelectParts(n);
  325.         CloseWindow(IDOK);
  326.     }
  327. }
  328.  
  329.