home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / edispm11.zip / EDisPM / SRC / Client / EDISPM.CPP < prev    next >
Text File  |  1996-05-14  |  7KB  |  276 lines

  1. /* EDisPM.cpp: EDMainWin:       EDisPM.EXE V 1.1 */
  2. /* Editorclient - Hauptprogrammrahmenfenster     */
  3. /*                                               */
  4. /* (C) 1995 M.Schwarz, FoPra TU-Muenchen SS1995  */
  5. /* (C) 1996 M.Schwarz, SOMObjects-Programmierung */
  6. /*                     OS/2 Inside 7/96          */
  7. /*                                               */
  8. /* latest changes: 11.5.1996                     */
  9. /*-----------------------------------------------*/
  10.  
  11. /* IUICL Headers */
  12. #include <iapp.hpp>
  13. #include <imsgbox.hpp>
  14. #include <ititle.hpp>
  15.  
  16. /* OS/2-API Headers */
  17. #define INCL_WIN
  18. #include <os2.h>
  19.  
  20.  
  21. /* Application Headers */
  22. #include "EDISPM.H"
  23.  
  24. #include "EDISPM.HPP"
  25. #include "EDDLG.HPP"
  26. #include "EDADM.HPP"
  27.  
  28.  
  29. /* Implementierung der Klasse EDMainWin */
  30.  
  31. EDMainWin::EDMainWin (char *fname, char *uname) :
  32.    IFrameWindow ("EDisPM"),
  33.    Menu (IResourceId (EDMAINMENU), this),
  34.    Info(this),
  35.    EDClient(this, *uname),
  36.    textNameStr(fname),
  37.    userNameStr(uname)
  38.  
  39. {
  40.   // Infozeile für EDClientStub zugänglich machen
  41.    infoA = &Info;
  42.  
  43.    IString titel("EDisPM");
  44.    EmptyClient = new IStaticText(0, this, this);
  45.  
  46.   /* Hauptfenster aufbauen und anzeigen */
  47.    setClient(EmptyClient);
  48.    setIcon(IDIC_EDISPM);
  49.    ICommandHandler::handleEventsFor(this);
  50.    show();
  51.    setFocus();
  52.  
  53.   /* Wenn Username nicht gesetzt, mit Dialog einlesen */
  54.    if (userNameStr == "") {
  55.       commandTextUsername(&userNameStr);
  56.    }
  57.    ITitle(this, titel+" ("+userNameStr+")");
  58.  
  59.    if (isClientStubReady()) {
  60.       IEvent closeEvent(this, WM_CLOSE, 0, 0);
  61.       dispatch (closeEvent);
  62.    } /* endif */
  63.  
  64.   /* Wenn Doc-kürzel angegeben: EDClient starten */
  65.    if (textNameStr != "NO")
  66.       commandTextLogon(&textNameStr);
  67. }
  68.  
  69.  
  70.  
  71. Boolean EDMainWin::command (ICommandEvent &e)
  72. {
  73.    short rc;
  74.    switch (e.commandId()) {
  75.    case IDMM_OPEN:
  76.       textNameStr = "NO";
  77.       commandTextLogon(&textNameStr);
  78.       break;
  79.    case IDMM_CLOSE:
  80.       commandTextLogoff(&textNameStr);
  81.       break;
  82.    case IDMM_SAVE:
  83.       saveEditWinText();
  84.       break;
  85.    case IDMM_TEXT_USERNAME:
  86.       commandTextUsername(&userNameStr);
  87.       break;
  88.    case IDMM_ABOUT:
  89.       displayAboutBox((HWND) e.handle());
  90.       break;
  91.    case IDMM_HORZ:
  92.       setWindowView(IDMM_HORZ);
  93.      break;
  94.    case IDMM_VERT:
  95.       setWindowView(IDMM_VERT);
  96.       break;
  97.    case IDMM_UPDATE:
  98.       updateTextWin();
  99.       break;
  100.    case IDMM_EXIT:
  101.       {
  102.          commandTextLogoff(&textNameStr);
  103.          IEvent closeEvent(this, WM_CLOSE, 0, 0);
  104.          dispatch (closeEvent);
  105.       }
  106.       return true;
  107.    }
  108.    return false;
  109. }
  110.  
  111.  
  112. Boolean EDMainWin::systemCommand (ICommandEvent &e)
  113. {
  114.    Boolean result = false;
  115.  
  116.    if (e.commandId() == SC_CLOSE) {
  117.       commandTextLogoff(&textNameStr);
  118.    } /* endif */
  119.  
  120.    return result;
  121. }
  122.  
  123. Boolean EDMainWin::commandTextLogon(IString *textNameStr) {
  124.  
  125.  
  126.    EDDocAdmin DocVerw(this);
  127.    IString    strDocID("");
  128.    IString    strDocPfad("");
  129.    IString    strDocServer("");
  130.    short      rc;
  131.  
  132.   // if text currently active then output error message
  133.    if (isEditWindowActive()) {
  134.       errorMsgBox("Text-Logon", "Vor dem Einloggen muß der derzeitig bearbeitete Text geschlossen werden.");
  135.       return false;
  136.    }
  137.  
  138.    if (DocVerw.openProfile()) {
  139.      // choose or retrieve textName?
  140.       if (*textNameStr == "NO") {
  141.         // choose text with dialog
  142.          if (!DocVerw.chooseDoc(&strDocID, &strDocPfad, &strDocServer)) {
  143.             *textNameStr = "NO";
  144.             return false;
  145.          }
  146.       } else {
  147.         // retrieve text with textNameStr
  148.          strDocID = *textNameStr;
  149.          if (!DocVerw.getDocFromID(&strDocID, &strDocPfad, &strDocServer)) {
  150.             *textNameStr =  "NO";
  151.             return false;
  152.          }
  153.       }
  154.       *textNameStr = strDocID;
  155.  
  156.      // build DSOM-connection to text server
  157.       rc = logonEDSObj(&strDocID, &strDocPfad, &strDocServer, userNameStr);
  158.       if (rc == 1) {
  159.        // enter new text server in profile
  160.          DocVerw.setServer(&strDocID, &strDocServer);
  161.       } else if (rc < 0) {
  162.          *textNameStr = "NO";
  163.          return false;
  164.       } /* endif */
  165.  
  166.      // open edit cient window
  167.       openEditWindow(&Menu);
  168.  
  169.    } else {
  170.       *textNameStr = "NO";
  171.       edClientStatus = 0;
  172.       return false;
  173.    } /* endif */
  174.  
  175.   ITitle(this, "EDisPM ("+getLogonUserNameStr()+") - "+*textNameStr);
  176.  
  177.   return true;
  178. }
  179.  
  180. Boolean EDMainWin::commandTextLogoff(IString* textNameStr) {
  181.  
  182.    if (!isEditWindowActive())
  183.       return true;
  184.  
  185.   // close edit client window
  186.    closeEditWindow(EmptyClient, &Menu);
  187.  
  188.    // stop DSOM connection to text server
  189.    logoffEDSObj();
  190.  
  191.    *textNameStr = "NO";
  192.  
  193.    ITitle(this, "EDisPM ("+userNameStr+")");
  194.  
  195.    return true;
  196. }
  197.  
  198.  
  199.  
  200.  
  201. Boolean EDMainWin::commandTextUsername(IString *uNS) {
  202.    IString uNameStr(*uNS);
  203.  
  204.    UserNameDlg UNameDlg(this, &uNameStr);
  205.    if (uNameStr == "")
  206.       uNameStr = "anonymous";
  207.  
  208.    if (*uNS == uNameStr)
  209.       return false;  // No changes
  210.  
  211.   // Update of current text∩s username ?
  212.    if (isEditWindowActive()) {
  213.       IMessageBox imb(IWindow::objectWindow());
  214.       imb.setTitle("Question: User - Change");
  215.       short rc = imb.show("Soll der Benutzername für den derzeitig bearbeiteten Text geändert werden?", IMessageBox::yesNoCancelButton);
  216.       if (rc == IMessageBox::cancel) {
  217.          return false;
  218.       } else if (rc == IMessageBox::yes) {
  219.          saveEditWinText();                // unlock lines
  220.          changeLogonUserNameStr(uNameStr); // leave/joinsession
  221.          updateTextWin();                  // update view
  222.       }
  223.    }
  224.  
  225.    *uNS = uNameStr;
  226.  
  227.    if (isEditWindowActive())
  228.       ITitle(this, "EDisPM ("+*uNS+") - "+textNameStr);
  229.    else
  230.       ITitle(this, "EDisPM ("+*uNS+")");
  231.  
  232.    return true;
  233. }
  234.  
  235.  
  236. Boolean EDMainWin::displayAboutBox(HWND hwnd) {
  237.  
  238.   /* display my AboutBox dialog */
  239.    WinDlgBox(HWND_DESKTOP,
  240.              hwnd,
  241.              AboutBoxDlgProc,
  242.              0,
  243.              IDD_ABOUTBOX,
  244.              (PVOID)NULL);
  245.    return 0;
  246. }
  247.  
  248.  
  249.  
  250. /*****************/
  251. /* Hauptprogramm */
  252. /*****************/
  253.  
  254. main(int argc, char *argv[], char *envp[])
  255. {
  256.    IString argTextNameStr("NO");
  257.    IString argUserNameStr("");
  258.  
  259.   /* Variablen initialisieren */
  260.    if (argc >= 2) {
  261.      /* Username übergeben */
  262.       argUserNameStr = argv[1];
  263.    } /* endif */
  264.    if (argc == 3) {
  265.      /* Dateikürzel übergeben */
  266.       argTextNameStr = argv[2];
  267.    } /* endif */
  268.  
  269.   /* Programmfenster aufbauen */
  270.    EDMainWin mainWindow(argTextNameStr, argUserNameStr);
  271.  
  272.   /* Progammschleife */
  273.    IApplication::current().run();
  274.  
  275. }
  276.