home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / ScriptExplorer / CLGCommander.cp < prev    next >
Encoding:
Text File  |  1997-07-24  |  7.0 KB  |  322 lines  |  [TEXT/CWIE]

  1. // CLGCommander.cp
  2. //
  3. //        ScriptExplorer Commander-in-Chief
  4. //
  5. //    May be distributed freely
  6. //    Brian Hamlin, NoEsis software contruction    nsc@screenlight.com
  7. //****************************************************************************
  8.  
  9. // system headers
  10. #ifndef __ICONS__
  11. #    include <Icons.h>
  12. #endif
  13. #ifndef __RESOURCES__
  14. #    include <Resources.h>
  15. #endif
  16.  
  17. #include <Files.h>
  18. #include <Folders.h>
  19. #include <Script.h>
  20. #include <TextUtils.h>
  21.  
  22. //#include <ansi_parms.h>
  23. //#define __dest_os __mac_os
  24. //include <string.h>
  25.  
  26. // PowerPlant headers
  27. #include <UDesktop.h>
  28. #include <LWindow.h>
  29.  
  30. // project headers
  31. #include "LG_Constants.h"
  32. #include "CLGCommander.h"
  33. #include "CLG_CharsGrid.h"
  34. #include "CLG_CharInfo.h"
  35.  
  36.  
  37.  
  38. //***********************
  39. //    CLGCommander
  40. //****************************************************************************
  41.  
  42. CLGCommander::CLGCommander(LCommander *inSuperCommander)
  43.     : LCommander(inSuperCommander)
  44. {
  45.     mWindow        = NULL;
  46.     
  47.     return;
  48. }
  49.  
  50.  
  51. //***********************
  52. //    ~CLGCommander
  53. //****************************************************************************
  54. CLGCommander::~CLGCommander(void)
  55. {
  56.     delete mWindow;
  57. }
  58.  
  59.  
  60. //***********************
  61. //    ~CLGCommander
  62. //
  63. //    Create a new PPD Window using an FSSpec as a reference.
  64. //****************************************************************************
  65. OSErr    CLGCommander::CreateWindow()
  66. {
  67.     
  68.     // preliminaries
  69.  
  70.     // create window
  71.     mWindow = LWindow::CreateWindow( 1, this);    
  72.     mWindow->Show();
  73.     mWindow->SetSuperCommander( this);
  74.     //GetIndString(theWindowTitle, STRS_WindowNames, 1);
  75.     //NumToString(mNextQuery++, theWindowNumber);
  76.     //LString::AppendPStr(theWindowTitle, theWindowNumber);
  77.     //mWindow->SetDescriptor(theWindowTitle);
  78.     
  79.  
  80.     // Text
  81.     mCharsGrid       = (CLG_CharsGrid *) mWindow->FindPaneByID( PID_CharsGrid);
  82.     mCharInfo         = (CLG_CharInfo *)  mWindow->FindPaneByID( PID_PnCharInfo);
  83.     
  84.     mMenuDrawAction        = (LStdPopupMenu*) mWindow->FindPaneByID( PID_MenuDrawAct);
  85.     mMenuScriptAction    = (LStdPopupMenu*) mWindow->FindPaneByID( PID_MenuScriptAct);
  86.     
  87.     mMenuDrawAction->Hide();
  88.  
  89.     mBtnUp            = (LButton*)mWindow->FindPaneByID( PID_IBtnPgUp);
  90.     mBtnDown        = (LButton*)mWindow->FindPaneByID( PID_IBtnPgDown);
  91.  
  92.     AllowPaging( false);
  93.     
  94.     UReanimator::LinkListenerToControls( this, mWindow, 1);
  95.     mWindow->Show();
  96.     
  97.     this->StartIdling();
  98.     
  99.     return noErr;
  100. }
  101.  
  102.  
  103. //***********************
  104. //    ListenToMessage
  105. //
  106. //        Respond to messages from Broadcasters
  107. //****************************************************************************
  108. void
  109. CLGCommander::ListenToMessage(
  110.     MessageT    inMessage,
  111.     void        *ioParam)
  112. {
  113.     switch ( inMessage) {
  114.  
  115.         default:
  116.             // CONVENTION - Just pass the msg to the Cmd Heirarchy
  117.             ObeyCommand( inMessage, ioParam);
  118.             break;
  119.     };
  120.  
  121.     return;
  122. }
  123.  
  124.  
  125. //***********************
  126. //    ObeyCommand
  127. //
  128. //        Respond to messages from Broadcasters
  129. //****************************************************************************
  130. Boolean    CLGCommander::ObeyCommand(CommandT inCommand, void *ioParam)
  131. {
  132.     Boolean            cmdHandled = true;
  133.  
  134.     switch (inCommand)
  135.     {
  136.     
  137.     case cmd_MenuScriptAct:
  138.         DoScriptActMenu();        
  139.         break;
  140.  
  141.     case cmd_SomeBtn:
  142.         ObeyCommand( cmd_About, 0);        
  143.         break;
  144.  
  145.     case cmd_PageUp:
  146.         mCharsGrid->DoPageUp();
  147.         mCharInfo->SetBaseCharDisp( mCharsGrid->mBaseChar);
  148.         break;    
  149.  
  150.     case cmd_PageDown:
  151.         mCharsGrid->DoPageDown();    
  152.         mCharInfo->SetBaseCharDisp( mCharsGrid->mBaseChar);
  153.         break;    
  154.  
  155.     default:
  156.         cmdHandled = LCommander::ObeyCommand(inCommand, ioParam);
  157.         break;
  158.     }
  159.  
  160.     return cmdHandled;
  161. }
  162.  
  163.  
  164.  
  165. //***********************
  166. //    SpendTime
  167. //****************************************************************************
  168. void
  169. CLGCommander::SpendTime(
  170.     const EventRecord&    inMacEvent)
  171. {
  172.     long            scripNum;
  173.     Boolean         isDblByteScript;
  174.  
  175.     // Check Current Script System
  176.     scripNum = GetScriptManagerVariable( smKeyScript);
  177.     
  178.     if ( mCurScriptNum != scripNum ) {
  179.         // FontToScript( mCharsGrid->mFontNum) != scripNum
  180.         mCharsGrid->mFontNum = GetScriptVariable( scripNum, smScriptAppFond);
  181.         mCharsGrid->mFontSiz = 0x00FF & GetScriptManagerVariable( smScriptMonoFondSize);
  182.         
  183.         isDblByteScript = (    scripNum == smJapanese 
  184.                         ||    scripNum == smTradChinese 
  185.                         ||    scripNum == smSimpChinese 
  186.                         ||    scripNum == smKorean );
  187.         
  188.         AllowPaging( isDblByteScript);
  189.         
  190.         if ( !isDblByteScript) {
  191.             mCharsGrid->mBaseChar = 0;
  192.             mCharInfo->SetBaseCharDisp( 0);
  193.         }
  194.         
  195.         // Keep a copy of the curScriptNum both here (for easy access)
  196.         //  and in the CharGrid, so it can handle the paging/drawing correctly
  197.         //  This is the only place scriptNum is changed, so synch is no problem
  198.  
  199.         mCurScriptNum = scripNum;
  200.         mCharsGrid->mCurScriptNum = scripNum;
  201.         mCharsGrid->Refresh();
  202.     }
  203.     
  204.     // Onward - update the Char info based on the Mouse Position
  205.     // Check for mousePos in Grid Area
  206.     Rect    tR = {0,0,20,20};
  207.     Point    tGridLoc;
  208.     Point    portMouse = inMacEvent.where;
  209.     SPoint32 gridLoc;
  210.     
  211.     mWindow->GlobalToPortPoint(portMouse);
  212.     if ( mWindow->FindSubPaneHitBy( portMouse.h, portMouse.v) == mCharsGrid) {
  213.         // find the char the cursor is over
  214.         
  215.         mCharsGrid->GetFrameLocation( gridLoc);
  216.         portMouse.h -= gridLoc.h + kcgHOffset;
  217.         tGridLoc.h = portMouse.h/kcgHSpacing;
  218.         
  219.         portMouse.v -= gridLoc.v + kcgVOffset;
  220.         tGridLoc.v = portMouse.v/kcgVSpacing;
  221.         
  222.         if ( tGridLoc.v < 16 && tGridLoc.h < 16)  {
  223.             if ( mLastCGChar.v != tGridLoc.v ||  mLastCGChar.h != tGridLoc.h)  {
  224.                 mLastCGChar = tGridLoc;
  225.                 mCharInfo->SetCharNum( 
  226.                     ((mCharsGrid->mBaseChar)*256) + 16*tGridLoc.v + tGridLoc.h);
  227.             }
  228.         }
  229.  
  230.     }
  231.  
  232.     return;
  233. }
  234.  
  235.  
  236. //***********************
  237. //    AllowPaging
  238. //****************************************************************************
  239. void
  240. CLGCommander::AllowPaging( Boolean inFlag) 
  241. {
  242.     if ( !inFlag) {
  243.         mBtnUp->SetGraphics( 1018, 1018);
  244.         mBtnDown->SetGraphics( 1019, 1019);
  245.  
  246.         mBtnUp->Disable();
  247.         mBtnDown->Disable();
  248.         
  249.     } else {
  250.         mBtnUp->SetGraphics( PID_IBtnPgUp, PID_IBtnPgUp+1);
  251.         mBtnDown->SetGraphics( PID_IBtnPgDown, PID_IBtnPgDown+1);
  252.         
  253.         mBtnUp->Enable();
  254.         mBtnDown->Enable();
  255.     }
  256.  
  257.     mBtnUp->Refresh();
  258.     mBtnDown->Refresh();
  259.  
  260.     return;
  261. }
  262.  
  263.  
  264. //***********************
  265. //    DoScriptActMenu
  266. //****************************************************************************
  267. void
  268. CLGCommander::DoScriptActMenu()
  269. {    
  270.     mCharsGrid->mScriptAction = mMenuScriptAction->GetValue();
  271.     mCharsGrid->DoChangeChars();
  272.     return;
  273. }
  274.  
  275.  
  276. //***********************
  277. //    FindCommandStatus
  278. //****************************************************************************
  279. void    CLGCommander::FindCommandStatus(
  280.     CommandT    inCommand,
  281.     Boolean        &outEnabled,
  282.     Boolean        &outUsesMark,
  283.     Char16        &outMark,
  284.     Str255        outName)
  285. {
  286.     outUsesMark = false;
  287.  
  288.     switch (inCommand)
  289.     {
  290.     case cmd_New:
  291.         outEnabled = false;
  292.         break;
  293.         
  294.     case cmd_Close:
  295.         outEnabled = false;
  296.         //if (mWindow != NULL)
  297.         //    outEnabled = true;
  298.         break;
  299.  
  300.  
  301.     default:
  302.         LCommander::FindCommandStatus(inCommand, outEnabled,
  303.                                       outUsesMark, outMark, outName);
  304.         break;
  305.     }
  306. }
  307.  
  308.  
  309. //***********************
  310. //    AllowSubRemoval
  311. //****************************************************************************
  312. Boolean    CLGCommander::AllowSubRemoval(LCommander *inSub)
  313. {
  314.     return (true);
  315. }
  316.  
  317.  
  318. //***************************************************************************************
  319. //                                                            E N D   O F   L I S T I N G
  320.  
  321.  
  322.