home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / tdoslyn3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  3.6 KB  |  136 lines

  1. //    Copyright (c) 1994, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        TDosLynx : public TApplication
  4. //    Include File:    TDosLynx.h
  5. //    Purpose:    Implement our application object.
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        01-05-93    created
  9. #define Uses_TDialog
  10. #define Uses_TInputLine
  11. #define Uses_TLabel
  12. #define Uses_TDeskTop
  13. #define Uses_THistory
  14. #define Uses_TButton
  15. #include"tdoslynx.h"
  16. #include"trace.h"
  17. #include"turlwind.h"
  18. #include<ctype.h>
  19.  
  20. void TDosLynx::OpenURL(const char *cp_URL)    {
  21. //    Purpose:    Open a URL
  22. //    Arguments:    cp_URL    The url to load.
  23. //    Return Value:   void
  24. //    Remarks/Portability/Dependencies/Restrictions:
  25. //    Revision History:
  26. //        12-13-93    created
  27. //        12-30-93        Disabled passing in URL name as argument
  28. //                Added dialog to ask for URL name
  29. //        01-05-94    Modified not to use a derived dialog since
  30. //                unable to make buttons draw correctly.
  31. //                Still didn't work.
  32. //                Increased button rectangle size to two lines,
  33. //                worked!
  34. //                Why the hell isn't that documented anywhere?
  35. //        04-07-94    Added ability to pass in a URL.
  36.  
  37. #ifndef RELEASE
  38.     trace("Opening URL");
  39. #endif // RELEASE
  40.  
  41.     if(cp_URL == NULL)    {
  42.         //    General use rectangle
  43.         TRect TR(0, 0, 74, 15);
  44.  
  45.         //    Create the URL dialog to get the URL name.
  46.         TDialog *TURLD = (TDialog *)validView(new TDialog(TR,
  47.             "Open URL"));
  48.  
  49.         //    Center the dialog
  50.         TURLD->options |= ofCentered;
  51.  
  52.         //    Make the input line.
  53.         TR = TRect(5, 4, 68, 5);
  54.         TInputLine *TIL_URLEntry = (TInputLine *)validView(new
  55.             TInputLine(TR, usi_TILURLSize - 1));
  56.         TURLD->insert(TIL_URLEntry);
  57.  
  58.         //    Make the input line's label.
  59.         TR = TRect(4, 3, 68, 4);
  60.         TURLD->insert(validView(new TLabel(TR, "~U~RL",
  61.             TIL_URLEntry)));
  62.  
  63.         //    Make the input line's history list.
  64.         TR = TRect(69, 4, 72, 5);
  65.         TURLD->insert(validView(new THistory(TR, TIL_URLEntry,
  66.             usi_OpenURLHist)));
  67.  
  68.         //    Make the OK, Cancel, and Help buttons.
  69.         TR = TRect(21, 11, 33, 13);
  70.         TURLD->insert(validView(new TButton(TR, "~O~K", cmOK,
  71.             bfDefault)));
  72.         TR = TRect(40, 11, 52, 13);
  73.         TURLD->insert(validView(new TButton(TR, "~C~ancel", cmCancel,
  74.             bfNormal)));
  75.  
  76.         //    Stay in the URL field
  77.         TURLD->selectNext(False);
  78.  
  79.         //    Draw the dialog
  80.         TURLD->drawView();
  81.  
  82.         //    Ensure creation, execution.
  83.         //    If user cancelled, code will do nothing.
  84.         if(TURLD != NULL && deskTop->execView(TURLD) != cmCancel)
  85.         {
  86.             //    Small temporary buffer to hold URL name.
  87.             auto char ca_buffer[usi_TILURLSize];
  88.  
  89.             //    Get information from the Input line.
  90.             TIL_URLEntry->getData(ca_buffer);
  91.  
  92.             //    Remove whitespace from the front of the line.
  93.             if(isspace(ca_buffer[0]))    {
  94.                 char *cp_temp = ca_buffer + 1;
  95.  
  96.                 while(isspace(*cp_temp))
  97.                     cp_temp++;
  98.  
  99.                 int i_traverse;
  100.                 for(i_traverse = 0; *cp_temp != '\0';
  101.                     i_traverse++)    {
  102.                     ca_buffer[i_traverse] = *cp_temp++;
  103.                 }
  104.  
  105.                 ca_buffer[i_traverse] = '\0';
  106.             }
  107.  
  108.             //    Only if we actually received a URL entry do we
  109.             //        to process it.
  110.             if(ca_buffer[0] != '\0')    {
  111.                 //    Create our new valid window.
  112.                 TView *TV_new = validView((TView *)new
  113.                     TURLWindow(ca_buffer));
  114.  
  115.                 //    If not created, don't insert.
  116.                 if(TV_new != NULL)
  117.                     deskTop->insert(TV_new);
  118.             }
  119.         }
  120.  
  121.         //    Release the dialog.
  122.         if(TURLD != NULL)    {
  123.             destroy(TURLD);
  124.         }
  125.     }
  126.     else    {
  127.         //    URL name passed in.  Load it.
  128.         //    Create our new valid window.
  129.         auto TView *TV_new2 = validView((TView *)new
  130.             TURLWindow(cp_URL));
  131.  
  132.         //    If not created, don't insert onto the desktop.
  133.         if(TV_new2 != NULL)
  134.             deskTop->insert(TV_new2);
  135.     }
  136. }