home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / Editor / Source / Editor.cpp next >
C/C++ Source or Header  |  1996-08-12  |  2KB  |  118 lines

  1. // OCL Sample
  2. // Editor.cpp
  3.  
  4. #ifdef __BCPLUSPLUS__
  5.   #define __MSC
  6. #endif
  7.  
  8.  
  9. #define __OCL_RESOLVE_TEMPLATES__
  10. #include "..\Source\Editor.hpp"
  11.  
  12.  
  13. void main(void)
  14. {
  15.  Editor editor;
  16.  
  17.  try
  18.    {
  19.     editor.createFrame("A simple editor");
  20.     editor.textfield = new OEditor(ID_TEXTFIELD, editor);
  21.     editor.textfield->createMLE();
  22.     editor.showFrame();
  23.    }
  24.  
  25.  catch(OPMException ex)
  26.    {
  27.     ex.viewError();
  28.     _exit(1);
  29.    }
  30.  
  31.  OApp::current().run();
  32.  
  33.  _exit(0);
  34. }
  35.  
  36.  
  37. Editor::Editor()
  38.   : OFrame(EDITOR_MAIN) 
  39.   {}
  40.  
  41.  
  42.  
  43. Editor::~Editor() 
  44. {
  45.  if (textfield) delete textfield; 
  46. }
  47.  
  48.  
  49.  
  50. PSZ Editor::isOfType() const
  51.  return("Editor");  
  52.  
  53.  
  54.  
  55. BOOL Editor::TasklistKill()
  56. {
  57.  OMsgs msg;
  58.  return(!msg.ask("Tasklist Kill", "Do you really want to quit?"));
  59. }
  60.  
  61.  
  62.  
  63. BOOL Editor::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  64. {
  65.  switch(msg)
  66.   {
  67.    case WM_SIZE:
  68.      WinSetWindowPos(textfield->hwnd, HWND_TOP, 0, 0, 
  69.                      SHORT1FROMMP(mp2),  SHORT2FROMMP(mp2), 
  70.                      SWP_MOVE | SWP_SIZE);
  71.      textfield->setFocus();
  72.      break; 
  73.  
  74.  
  75.    case WM_COMMAND:
  76.      switch(SHORT1FROMMP(mp1))
  77.       {
  78.        case EDITOR_QUIT:
  79.         WinSendMsg(hwnd, WM_CLOSE, NULL, NULL);
  80.         break;
  81.  
  82.        case EDITOR_LOAD:
  83.         textfield->loadFile();
  84.         setWindowText(textfield->openedFile);
  85.         break;
  86.  
  87.        case EDITOR_SAVE:
  88.         textfield->saveFileThr.run();
  89.         break;
  90.  
  91.        case EDITOR_SAVEAS:
  92.         textfield->saveFileAs(); 
  93.         setWindowText(textfield->openedFile);
  94.         break; 
  95.       }
  96.      break;
  97.  
  98.    case WM_CLOSE:
  99.      forceQuit();
  100.      break; 
  101.  
  102.    default:
  103.      return(OFrame::OCommand(msg, mp1, mp2));
  104.   }
  105.  return(TRUE);
  106. #ifdef __BCPLUSPLUS__
  107.   #pragma warn -par
  108. #endif
  109. }
  110. #ifdef __BCPLUSPLUS__
  111.   #pragma warn .par
  112. #endif
  113.  
  114.  
  115. // end of source
  116.