home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / Epoc / Palmtime / files / FrotzCE2_src.ZIP / FrotzCE / MainFrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-16  |  8.2 KB  |  320 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "FrotzCE.h"
  6.  
  7. #include "FrotzCEDoc.h"
  8. #include "FrotzCEView.h"
  9.  
  10. extern "C"
  11. {
  12. #include "Frotz/Frotz.h"
  13. }
  14.  
  15. #include "MainFrm.h"
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. // Array tbSTDButton contains relevant buttons of bitmap IDB_STD_SMALL_COLOR
  24.  
  25. static TBBUTTON g_tbSTDButton[] = {
  26.     {0, 0,                TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0,  0},  
  27.     {0, ID_RESTORE,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  28.     {1, ID_SAVE,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  29.     {2, ID_UNDO,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  30.     {0, 0,                TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0, -1},
  31.     {3, ID_NORTH,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  32.     {4, ID_SOUTH,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  33.     {5, ID_EAST,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  34.     {6, ID_WEST,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  35.     {7, ID_UP,            TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  36.     {8, ID_DOWN,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  37.     {0, 0,                TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0, -1},
  38.     {9, ID_LOOK,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  39.     {10, ID_TAKE,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  40.     {11, ID_DROP,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  41.     {12, ID_GO,            TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  42.     {13, ID_OPEN,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  43.     {0, 0,                TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0, -1},
  44.     {14, ID_INVENTORY,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
  45.     {0, 0,                TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0,  0}
  46. };
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CMainFrame
  50.  
  51. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  52.  
  53. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  54.     //{{AFX_MSG_MAP(CMainFrame)
  55.     ON_WM_CREATE()
  56.     ON_MESSAGE(WM_UPDATE_MENU, OnUpdateMenu)
  57.     ON_COMMAND(ID_SMALLFONT, OnSmallfont)
  58.     ON_COMMAND(ID_BOLDFONT, OnBoldfont)
  59.     ON_UPDATE_COMMAND_UI(ID_BOLDFONT, OnUpdateBoldfont)
  60.     ON_UPDATE_COMMAND_UI(ID_SMALLFONT, OnUpdateSmallfont)
  61.     ON_COMMAND(ID_COLOURS, OnColours)
  62.     ON_UPDATE_COMMAND_UI(ID_COLOURS, OnUpdateColours)
  63.     ON_COMMAND(ID_STYLES, OnStyles)
  64.     ON_UPDATE_COMMAND_UI(ID_STYLES, OnUpdateStyles)
  65.     ON_COMMAND(ID_EXPANDABBREV, OnExpandabbrev)
  66.     ON_UPDATE_COMMAND_UI(ID_EXPANDABBREV, OnUpdateExpandabbrev)
  67.     ON_COMMAND(ID_IGNOREERRORS, OnIgnoreerrors)
  68.     ON_UPDATE_COMMAND_UI(ID_IGNOREERRORS, OnUpdateIgnoreerrors)
  69.     ON_COMMAND(ID_TANDY, OnTandy)
  70.     ON_UPDATE_COMMAND_UI(ID_TANDY, OnUpdateTandy)
  71.     ON_COMMAND(ID_SHOWCOMMANDBAR, OnShowcommandbar)
  72.     ON_WM_SIZE()
  73.     ON_COMMAND(ID_TERMINALFONT, OnTerminalfont)
  74.     ON_UPDATE_COMMAND_UI(ID_TERMINALFONT, OnUpdateTerminalfont)
  75.     ON_UPDATE_COMMAND_UI(ID_SHOWCOMMANDBAR, OnUpdateShowcommandbar)
  76.     //}}AFX_MSG_MAP
  77.     // Global help commands
  78.     ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
  79. END_MESSAGE_MAP()
  80.  
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CMainFrame construction/destruction
  83.  
  84. CMainFrame::CMainFrame()
  85. {
  86.     m_bShowCommandBar = TRUE;
  87. }
  88.  
  89. CMainFrame::~CMainFrame()
  90. {
  91. }
  92.  
  93. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  94. {
  95.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  96.         return -1;
  97.     
  98.     // Add Exit and Help buttons
  99.     if (!AddAdornments( 0 /*CMDBAR_HELP*/ ))
  100.     {
  101.         TRACE0("Failed to add exit and help buttons\n");
  102.         return -1; 
  103.     }
  104.  
  105.     // Save command bar height
  106.     m_nCmdBarHeight = CommandBar_Height( m_hCommandBar );
  107.  
  108.     return 0;
  109. }
  110.  
  111. void CMainFrame::OnUpdateMenu()
  112. {
  113.     // Clear the command bar
  114.     m_hCommandBar = m_poCommandBar->Reset();
  115.     m_hCommandBarMenu = NULL;
  116.  
  117.     // Z-machine running?
  118.     if (FROTZCEAPP->m_bZmachineRunning == FALSE)
  119.     {
  120.         // Add the menu first
  121.         m_hCommandBarMenu = InsertMenu(IDR_MAINFRAME);
  122.  
  123.         // Show command bar
  124.         CommandBar_Show( m_hCommandBar, TRUE );
  125.  
  126.         // Save command bar height
  127.         m_nCmdBarHeight = CommandBar_Height( m_hCommandBar );
  128.     }
  129.     else
  130.     {
  131.         // Add the menu first
  132.         m_hCommandBarMenu = InsertMenu(IDR_GAMEMENU);
  133.  
  134.         // Add button bar
  135.         if (!InsertButtons( g_tbSTDButton, 
  136.                            sizeof(g_tbSTDButton)/sizeof(TBBUTTON), // NButtons
  137.                            IDR_MAINFRAME,                           // toolbar bitmap
  138.                            15 ))                                    // NImages
  139.         {
  140.             TRACE0("Failed to add command bar buttons\n");
  141.             return;
  142.         }
  143.  
  144.         // Show or hide command bar
  145.         CommandBar_Show( m_hCommandBar, m_bShowCommandBar );
  146.  
  147.         // Save command bar height
  148.         m_nCmdBarHeight = CommandBar_Height( m_hCommandBar );
  149.     }
  150.  
  151.     // Add Exit and Help buttons
  152.     if (!AddAdornments( 0 /*CMDBAR_HELP*/ ))
  153.     {
  154.         TRACE0("Failed to add exit and help buttons\n");
  155.         return; 
  156.     }
  157. }
  158.  
  159. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  160. {
  161.     return CFrameWnd::PreCreateWindow(cs);
  162. }
  163.  
  164. /////////////////////////////////////////////////////////////////////////////
  165. // CMainFrame diagnostics
  166.  
  167. #ifdef _DEBUG
  168. void CMainFrame::AssertValid() const
  169. {
  170.     CFrameWnd::AssertValid();
  171. }
  172.  
  173. void CMainFrame::Dump(CDumpContext& dc) const
  174. {
  175.     CFrameWnd::Dump(dc);
  176. }
  177.  
  178. #endif //_DEBUG
  179.  
  180. void CMainFrame::OnSmallfont() 
  181. {
  182.     if (FROTZCEAPP->m_nFontHeight == 0) 
  183.     {
  184.         FROTZCEAPP->m_nFontHeight = SMALL_FONT_HEIGHT;
  185.         FROTZCEAPP->m_nFontWidth = SMALL_FONT_WIDTH;
  186.     }
  187.     else 
  188.     {
  189.         FROTZCEAPP->m_nFontHeight = 0;
  190.         FROTZCEAPP->m_nFontWidth = 0;
  191.     }
  192. }
  193.  
  194. void CMainFrame::OnTerminalfont() 
  195. {
  196.     if (FROTZCEAPP->m_nFontWidth != TERMINAL_FONT_WIDTH) 
  197.     {
  198.         FROTZCEAPP->m_nFontHeight = TERMINAL_FONT_HEIGHT;
  199.         FROTZCEAPP->m_nFontWidth = TERMINAL_FONT_WIDTH;
  200.     }
  201.     else 
  202.     {
  203.         FROTZCEAPP->m_nFontHeight = 0;
  204.         FROTZCEAPP->m_nFontWidth = 0;
  205.     }
  206. }
  207.  
  208. void CMainFrame::OnBoldfont() 
  209.     if (FROTZCEAPP->m_nDefaultStyle == NORMAL_STYLE) 
  210.         FROTZCEAPP->m_nDefaultStyle = BOLDFACE_STYLE;
  211.     else FROTZCEAPP->m_nDefaultStyle = NORMAL_STYLE;
  212. }
  213.  
  214. void CMainFrame::OnUpdateBoldfont(CCmdUI* pCmdUI) 
  215. {
  216.     pCmdUI->SetCheck( (FROTZCEAPP->m_nDefaultStyle != NORMAL_STYLE) );
  217. }
  218.  
  219. void CMainFrame::OnUpdateSmallfont(CCmdUI* pCmdUI) 
  220. {
  221.     pCmdUI->SetCheck( (FROTZCEAPP->m_nFontWidth != 0) );
  222. }
  223.  
  224. void CMainFrame::OnUpdateTerminalfont(CCmdUI* pCmdUI) 
  225. {
  226.     pCmdUI->SetCheck( (FROTZCEAPP->m_nFontWidth == TERMINAL_FONT_WIDTH) );
  227. }
  228.  
  229. void CMainFrame::OnColours() 
  230. {
  231.     if (FROTZCEAPP->m_bUseColours) FROTZCEAPP->m_bUseColours = FALSE;
  232.     else FROTZCEAPP->m_bUseColours = TRUE;
  233. }
  234.  
  235. void CMainFrame::OnUpdateColours(CCmdUI* pCmdUI) 
  236. {
  237.     pCmdUI->SetCheck( FROTZCEAPP->m_bUseColours );
  238. }
  239.  
  240. void CMainFrame::OnStyles() 
  241. {
  242.     if (FROTZCEAPP->m_bUseStyles) FROTZCEAPP->m_bUseStyles = FALSE;
  243.     else 
  244.     {
  245.         AfxMessageBox( TEXT( "Setting this option may result in irregular spacing" ) );
  246.         FROTZCEAPP->m_bUseStyles = TRUE;
  247.     }
  248. }
  249.  
  250. void CMainFrame::OnUpdateStyles(CCmdUI* pCmdUI) 
  251. {
  252.     pCmdUI->SetCheck( FROTZCEAPP->m_bUseStyles );
  253. }
  254.  
  255. void CMainFrame::OnExpandabbrev() 
  256. {
  257.     if (option_expand_abbreviations) option_expand_abbreviations = 0;
  258.     else option_expand_abbreviations = 1;
  259. }
  260.  
  261. void CMainFrame::OnUpdateExpandabbrev(CCmdUI* pCmdUI) 
  262. {
  263.     pCmdUI->SetCheck( (option_expand_abbreviations == 1) );
  264. }
  265.  
  266. void CMainFrame::OnIgnoreerrors() 
  267. {
  268.     if (option_ignore_errors) option_ignore_errors = 0;
  269.     else option_ignore_errors = 1;
  270. }
  271.  
  272. void CMainFrame::OnUpdateIgnoreerrors(CCmdUI* pCmdUI) 
  273. {
  274.     pCmdUI->SetCheck( (option_ignore_errors == 1) );
  275. }
  276.  
  277. void CMainFrame::OnTandy() 
  278. {
  279.     if (FROTZCEAPP->m_bTandy) FROTZCEAPP->m_bTandy = FALSE;
  280.     else FROTZCEAPP->m_bTandy = TRUE;
  281. }
  282.  
  283. void CMainFrame::OnUpdateTandy(CCmdUI* pCmdUI) 
  284. {
  285.     pCmdUI->SetCheck( FROTZCEAPP->m_bTandy );
  286. }
  287.  
  288. void CMainFrame::OnShowcommandbar() 
  289. {
  290.     if (m_bShowCommandBar) m_bShowCommandBar = FALSE;
  291.     else m_bShowCommandBar = TRUE;
  292. }
  293.  
  294. void CMainFrame::OnUpdateShowcommandbar(CCmdUI* pCmdUI) 
  295. {
  296.     pCmdUI->SetCheck( m_bShowCommandBar );
  297. }
  298.  
  299. void CMainFrame::OnSize(UINT nType, int cx, int cy) 
  300. {
  301.     CFrameWnd::OnSize(nType, cx, cy);
  302.     
  303.     // Z Machine running?
  304.     if (FROTZCEAPP->m_bZmachineRunning
  305.         && (nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED))
  306.     {
  307.     CRect cRect;
  308.     
  309.         // Get frame window rectangle
  310.         GetClientRect( cRect );
  311.  
  312.         // Subtract size of command bar if it's showing
  313.         if (m_bShowCommandBar) cRect.top += m_nCmdBarHeight;
  314.  
  315.         // Resize the view to cover the entire frame window client area
  316.         GetActiveView()->MoveWindow( cRect, FALSE );
  317.     }
  318. }
  319.