home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / WIREVIEW.LZH / WIRVWAPP.CPP < prev    next >
C/C++ Source or Header  |  1996-07-10  |  7KB  |  282 lines

  1. /*  Project wireview
  2.     DoGA
  3.     Copyright (c) 1995. Project Team DoGA. All Rights Reserved.
  4.  
  5.     サブシステム:    wireview.exe Application
  6.     ファイル:        wirvwapp.cpp
  7.     作成者:          Masamichi Takatsu
  8.  
  9.  
  10.     概要
  11.     ====
  12.     wireviewApp (TApplication) のインプリメンテーション用のソースファイル
  13. */
  14.  
  15.  
  16. #include <owl\owlpch.h>
  17. #pragma hdrstop
  18.  
  19.  
  20. #include "wirvwapp.h"
  21. #include "wrvwabtd.h"                        // 「プログラムについて」ダイアログボックスの定義
  22. #include "winframe.h"
  23. #include "suflib.h"
  24. #include "files.h"
  25. #include "anim.h"
  26.  
  27.  
  28. //{{wireviewApp Implementation}}
  29.  
  30.  
  31. //
  32. // アプリケーションが処理するすべてのメッセージ/コマンドに対する応答テーブルを作成する
  33. //
  34. DEFINE_RESPONSE_TABLE1(wireviewApp, TApplication)
  35. //{{wireviewAppRSP_TBL_BEGIN}}
  36.     EV_COMMAND(CM_FILENEW, CmFileNew),
  37.     EV_COMMAND(CM_FILEOPEN, CmFileOpen),
  38.     EV_COMMAND(CM_FILECLOSE, CmFileClose),
  39.     EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
  40. //{{wireviewAppRSP_TBL_END}}
  41. END_RESPONSE_TABLE;
  42.  
  43.  
  44.  
  45.  
  46. //////////////////////////////////////////////////////////
  47. // wireviewApp
  48. // =====
  49. //
  50. wireviewApp::wireviewApp () : TApplication("WireView")
  51. {
  52.  
  53.     // 「開く」と「名前を付けて保存」ダイアログボックスに共通の,ファイルフラグとフィルタ。ファイル名と
  54.     // ディレクトリは,メンバー関数 CmFileOpen と CmFileSaveAs で計算される
  55.     FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  56.     FileData.SetFilter("すべてのファイル (*.*)|*.*|");
  57.  
  58.     // INSERT>> コンストラクタ用のコードはここに
  59.  
  60. }
  61.  
  62.  
  63. wireviewApp::~wireviewApp ()
  64. {
  65.     // INSERT>> デストラクタ用のコードはここに
  66.  
  67. }
  68.  
  69.  
  70. //////////////////////////////////////////////////////////
  71. // wireviewApp
  72. // =====
  73. // アプリケーションの初期化
  74. //
  75. void wireviewApp::InitMainWindow ()
  76. {
  77.     TWinFrame *client = new TWinFrame(0);
  78.  
  79.     SDIDecFrame *frame = new SDIDecFrame(0, GetName(), client, FALSE);
  80. //    TFrameWindow *frame = new TFrameWindow(0, GetName(), client, TRUE);
  81. //    TFrameWindow *frame = new TFrameWindow(0, GetName(), client, FALSE);
  82.  
  83.     nCmdShow = nCmdShow != SW_SHOWMINIMIZED ? SW_SHOWNORMAL : nCmdShow;
  84.  
  85.     int screenX = GetSystemMetrics(SM_CXSCREEN);
  86.     int screenY = GetSystemMetrics(SM_CYSCREEN);
  87.  
  88.     if (wireview_x < 0 || wireview_y < 0 || wireview_w < 0 || wireview_h < 0) {
  89.         frame->Attr.W = 320;
  90.         frame->Attr.H = 240;
  91.         wireview_x = wireview_y = 0;
  92.         wireview_w = frame->Attr.W;
  93.         wireview_h = frame->Attr.H;
  94.     } else {
  95.         if (wireview_w > screenX) wireview_w = screenX;
  96.         if (wireview_h > screenY) wireview_h = screenY;
  97.         if (wireview_x + wireview_w > screenX) wireview_x = screenX - wireview_w;
  98.         if (wireview_y + wireview_h > screenY) wireview_y = screenY - wireview_h;
  99.         frame->Attr.X = wireview_x;
  100.         frame->Attr.Y = wireview_y;
  101.         frame->Attr.W = wireview_w;
  102.         frame->Attr.H = wireview_h;
  103.      }
  104.     //
  105.     // このアプリケーションに,アイコンを設定する
  106.     //
  107.     frame->SetIcon(this, IDI_SDIAPPLICATION);
  108.  
  109.     //
  110.     // ウィンドウに対応したメニューと,テーブルに対応したアクセラレータのテーブル
  111.     //
  112. //    frame->AssignMenu(SDI_MENU);
  113.  
  114.     //
  115.     // アクセラレータテーブルへの関連付け
  116.     //
  117. //    frame->Attr.AccelTable = SDI_MENU;
  118.  
  119.  
  120.     SetMainWindow(frame);
  121.  
  122. }
  123.  
  124.  
  125. //////////////////////////////////////////////////////////
  126. // wireviewApp
  127. // ===========
  128. // 「ファイル」メニューの「新規作成」コマンド
  129. void wireviewApp::CmFileNew ()
  130. {
  131. //    TEditFile *client = TYPESAFE_DOWNCAST(GetMainWindow()->GetClientWindow(), TEditFile);     // フレーム用のクライアントウィンドウ
  132. //    client->NewFile();
  133.     TWinFrame *client = TYPESAFE_DOWNCAST(GetMainWindow()->GetClientWindow(), TWinFrame);
  134.     client->anim->NewFile();
  135. }
  136.  
  137.  
  138. //////////////////////////////////////////////////////////
  139. // wireviewApp
  140. // ===========
  141. // 「ファイル」メニューの「開く」コマンド
  142. void wireviewApp::CmFileOpen ()
  143. {
  144.     //
  145.     // 標準の「開く」ダイアログボックスを表示し,ファイル名を選ぶ
  146.     //
  147. //    *FileData.FileName = 0;
  148.  
  149. //    TEditFile *client = TYPESAFE_DOWNCAST(GetMainWindow()->GetClientWindow(), TEditFile);     // フレーム用のクライアントウィンドウ
  150. //    if (client->CanClose())
  151. //        if (TFileOpenDialog(GetMainWindow(), FileData).Execute() == IDOK)
  152. //            OpenFile();
  153.     TWinFrame *client = TYPESAFE_DOWNCAST(GetMainWindow()->GetClientWindow(), TWinFrame);
  154.     char name[128];
  155.     if (client->anim->GetMotionName(name)) {
  156.         client->anim->ReadFile(name);
  157.     }
  158. }
  159.  
  160.  
  161. void wireviewApp::OpenFile (const char *fileName)
  162. {
  163.     if (fileName)
  164.         lstrcpy(FileData.FileName, fileName);
  165.  
  166.     TEditFile *client = TYPESAFE_DOWNCAST(GetMainWindow()->GetClientWindow(), TEditFile);     // フレーム用のクライアントウィンドウ
  167.     client->ReplaceWith(FileData.FileName);
  168. }
  169.  
  170.  
  171. //////////////////////////////////////////////////////////
  172. // wireviewApp
  173. // =====
  174. // 「ファイル」メニューの「閉じる」コマンド
  175. void wireviewApp::CmFileClose ()
  176. {
  177.     CmFileNew();
  178. }
  179.  
  180.  
  181. //
  182. // このアプリケーションで処理するすべてのメッセージ/コマンドの
  183. // 応答テーブルを作成する
  184. //
  185. DEFINE_RESPONSE_TABLE1(SDIDecFrame, TDecoratedFrame)
  186. //{{SDIDecFrameRSP_TBL_BEGIN}}
  187.     EV_WM_SIZE,
  188.     EV_WM_MOVE,
  189.     EV_WM_WINDOWPOSCHANGING,
  190. //{{SDIDecFrameRSP_TBL_END}}
  191. END_RESPONSE_TABLE;
  192.  
  193.  
  194. //{{SDIDecFrame Implementation}}
  195.  
  196.  
  197. SDIDecFrame::SDIDecFrame (TWindow *parent, const char far *title, TWindow *clientWnd, BOOL trackMenuSelection, TModule *module)
  198.     : TDecoratedFrame(parent, title, clientWnd, trackMenuSelection, module)
  199. {
  200.     // INSERT>> コンストラクタ用のコードはここに
  201.  
  202. }
  203.  
  204.  
  205. SDIDecFrame::~SDIDecFrame ()
  206. {
  207.     // INSERT>> デストラクタ用のコードはここに
  208.     FileWriteWireview();
  209. }
  210.  
  211. void SDIDecFrame::EvSize (UINT sizeType, TSize& size)
  212. {
  213.     // INSERT>> 追加コードはここに
  214.     TDecoratedFrame::EvSize(sizeType, size);
  215.     if (sizeType == SIZE_MAXIMIZED || sizeType == SIZE_RESTORED) {
  216.         int edgew = GetSystemMetrics(SM_CXBORDER) * 2;
  217.         int edgeh = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYBORDER);
  218.         wireview_w = size.cx + edgew;
  219.         wireview_h = size.cy + edgeh;
  220.     }
  221. }
  222.  
  223. void SDIDecFrame::EvMove (TPoint& clientOrigin)
  224. {
  225.     TDecoratedFrame::EvMove(clientOrigin);
  226.  
  227.     // INSERT>> 追加コードはここに
  228.     int edgew = GetSystemMetrics(SM_CXBORDER);
  229.     int edgeh = GetSystemMetrics(SM_CYCAPTION);
  230.     wireview_x = clientOrigin.x - edgew;
  231.     wireview_y = clientOrigin.y - edgeh;
  232. }
  233.  
  234.  
  235. void SDIDecFrame::EvWindowPosChanging (WINDOWPOS far& windowPos)
  236. {
  237.     TDecoratedFrame::EvWindowPosChanging(windowPos);
  238.  
  239.     // INSERT>> 追加コードはここに
  240. #define BUTTONSIZE 24
  241.     int edgew = GetSystemMetrics(SM_CXBORDER) * 2;
  242.     int edgeh = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYBORDER);
  243.     if (windowPos.cy - edgeh - BUTTONSIZE > (windowPos.cx - edgew) * 3 / 4) {
  244.         windowPos.cy = (windowPos.cx - edgew) * 3 / 4 + edgeh + BUTTONSIZE;
  245.     } else {
  246.         windowPos.cx = (windowPos.cy - edgeh - BUTTONSIZE) * 4 / 3 + edgew;
  247.     }
  248. //    wireview_w = windowPos.cx + edgew;
  249. //    wireview_h = windowPos.cy + edgeh;
  250.  
  251. }
  252.  
  253.  
  254. //////////////////////////////////////////////////////////
  255. // wireviewApp
  256. // ===========
  257. // 「ヘルプ」メニューの「wireview.exe について」コマンド
  258. void wireviewApp::CmHelpAbout ()
  259. {
  260.     //
  261.     // モーダルダイアログを表示する
  262.     //
  263.     wireviewAboutDlg(MainWindow).Execute();
  264. }
  265.  
  266.  
  267. int OwlMain (int , char* [])
  268. {
  269.     wireviewApp     App;
  270.     int             result;
  271.  
  272.     FileInit();
  273.     Object::UsePoly();
  274.  
  275.     result = App.Run();
  276.  
  277.     return result;
  278. }
  279.  
  280.  
  281.  
  282.