Changeset 890 for trunk/dll/newview.c


Ignore:
Timestamp:
Dec 28, 2007, 7:44:08 PM (18 years ago)
Author:
Gregg Young
Message:

Added mailrun to allow "mailto" by clicking on an email address in new view

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/newview.c

    r888 r890  
    2727  10 Oct 07 SHL Correct ReLineThread typo
    2828  17 Dec 07 GKY Make WPURLDEFAULTSETTINGS the fall back for ftp/httprun
     29  28 Dec 07 GKY Add mailrun to allow mailto by clicking on an email address in the viewer
    2930
    3031***********************************************************************/
     
    6061#define FIXED_FONT_LCID 5
    6162
    62 #define COLORS_MAX                   12
     63#define COLORS_MAX                   14
    6364
    6465#define COLORS_CURSOREDNORMALBACK    0
     
    7475#define COLORS_FTPBACK               10
    7576#define COLORS_FTPFORE               11
     77#define COLORS_MAILBACK              12
     78#define COLORS_MAILFORE              13
    7679
    7780static LONG Colors[COLORS_MAX] = { COLR_WHITE, COLR_DARKGRAY,
     
    8083  COLR_WHITE, COLR_YELLOW,
    8184  COLR_PALEGRAY, COLR_DARKBLUE,
    82   COLR_PALEGRAY, COLR_DARKGREEN
     85  COLR_PALEGRAY, COLR_DARKGREEN,
     86  COLR_PALEGRAY, COLR_DARKRED
    8387};
    8488
     
    100104    maxx, horzscroll;
    101105  BOOL hex, mousecaptured, sensitive, dummy, literalsearch, clientfocused,
    102     alsoselect, wrapon, relining, httpin, ftpin, ignorehttp, ignoreftp,
    103     needrefreshing;
     106    alsoselect, wrapon, relining, httpin, ftpin, mailin, ignorehttp, ignoreftp,
     107    ignoremail, needrefreshing;
    104108  HMTX ScanSem;
    105109  HWND hvscroll, hwndMenu, hwndStatus1, hwndStatus2, hwndStatus3, hwndRestore,
     
    129133static BOOL IgnoreFTP = FALSE;
    130134static BOOL IgnoreHTTP = FALSE;
     135static BOOL IgnoreMail = FALSE;
    131136static FATTRS Fattrs;
     137
     138// mailstr checks for a designated character in a string then cuts the string
     139//to the first word that contains the character
     140
     141CHAR *mailstr(CHAR *t, CHAR *s, LONG lens)
     142{
     143  CHAR *pp;
     144  CHAR *test = t;
     145
     146  if (!strnstr(test, s, lens))
     147    return NULL;
     148  bstripcr(t);
     149  if (!strstr(t, " "))
     150    return t;
     151  while (strchr(t, ' ') < strchr(t, (CHAR) s)){
     152    pp = t;
     153    while (*pp && *pp != ' '){
     154      *pp = ' ';
     155      pp++;
     156    }
     157      lstrip(t);
     158  }
     159  pp = t;
     160  while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' &&
     161         *pp != '\"')
     162    pp++;
     163  *pp = 0;
     164  printf("%s", t); fflush(stdout);
     165  strip_lead_char(t, "<");
     166  strip_trail_char(t, ">");
     167  return t;
     168}
    132169
    133170MRESULT EXPENTRY UrlDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     
    175212                            MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
    176213          p++;
    177         }
     214        }
    178215      }
    179216      while (p && *p && p < e);
     217      p = urld->line;
     218      if (mailstr(p, "@", e - p)) {
     219        strcpy(urld->url, p);
     220        WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
     221                          MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
     222      }
    180223      *urld->url = 0;
    181224      count = (SHORT) WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_QUERYITEMCOUNT,
     
    241284                  break;
    242285                }
    243               }
     286              }
     287              else if (!strncmp(urld->url, "@", 1)) {
     288                memmove(urld->url, urld->url + 6, strlen(urld->url) + 1);
     289                if (*urld->url) {
     290                  WinDismissDlg(hwnd, 3);
     291                  break;
     292                }
     293              }
    244294            }
    245295          }
     
    709759            GpiSetColor(hps, standardcolors[ad->colors[COLORS_HTTPFORE]]);
    710760            GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_HTTPBACK]]);
     761          }
     762
     763          if (ad->mailin && whichline != ad->cursored - 1
     764              && (!ad->markedlines
     765                  || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
     766              && strnstr(ad->lines[whichline], "@",e - ad->lines[whichline])) {
     767            GpiSetColor(hps, standardcolors[ad->colors[COLORS_MAILFORE]]);
     768            GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_MAILBACK]]);
    711769          }
    712770          rcl2 = *Rectl;
     
    762820              && (!ad->markedlines
    763821                  || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
    764               && strnstr(ad->lines[whichline], "http://",
    765                          e - ad->lines[whichline])) {
     822              && strnstr(ad->lines[whichline], "http://",e - ad->lines[whichline])) {
    766823            GpiSetColor(hps, standardcolors[ad->colors[COLORS_HTTPFORE]]);
    767824            GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_HTTPBACK]]);
     825          }
     826
     827          if (ad->mailin && whichline != ad->cursored - 1
     828              && (!ad->markedlines
     829                  || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
     830              &&  strnstr(ad->lines[whichline], "@",e - ad->lines[whichline])) {
     831            GpiSetColor(hps, standardcolors[ad->colors[COLORS_MAILFORE]]);
     832            GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_MAILBACK]]);
    768833          }
    769834          rcl2 = *Rectl;
     
    12281293                ad->selected = 0;
    12291294              }
    1230               if (*ftprun && !ad->ignoreftp && strstr(ad->text, "ftp://"))
     1295              if ((*ftprun || fFtpRunWPSDefault) && !ad->ignoreftp &&
     1296                  strstr(ad->text, "ftp://"))
    12311297                ad->ftpin = TRUE;
    1232               if (*httprun && !ad->ignorehttp && strstr(ad->text, "http://"))
    1233                 ad->httpin = TRUE;
     1298              if ((*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
     1299                  strstr(ad->text, "http://"))
     1300                ad->httpin = TRUE;
     1301              if (*mailrun && !ad->ignoremail && strstr(ad->text, "@"))
     1302                ad->mailin = TRUE;
    12341303            }
    12351304          }
     
    12861355            ad->lines = NULL;
    12871356            ad->markedlines = NULL;
    1288             ad->ftpin = ad->httpin = FALSE;
     1357            ad->ftpin = ad->httpin = ad->mailin = FALSE;
    12891358            ad->selected = ad->numlines = ad->textsize = ad->numalloc = 0;
    12901359            WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
     
    22012270      RECTL Rectl;
    22022271      POINTS pts;
     2272      //CHAR *mailstring;
    22032273
    22042274      WinQueryWindowRect(hwnd, &Rectl);
     
    22492319
    22502320        SHORT numsels, sSelect = 0, numinserted;
    2251         ULONG linenum;
     2321        ULONG linenum, size;
    22522322
    22532323        if (!ad->hex && ad->lines) {
     
    22662336          width = e - p;
    22672337          if (!width)
    2268             goto NoAdd;
    2269 
    2270           if ((ad->httpin && *httprun &&
     2338            goto NoAdd;
     2339
     2340          if ((ad->httpin && (*httprun || fHttpRunWPSDefault) &&
    22712341               strnstr(ad->lines[whichline], "http://", width)) ||
    2272               (ad->ftpin && *ftprun &&
    2273                strnstr(ad->lines[whichline], "ftp://", width))) {
     2342              (ad->ftpin && (*ftprun || fFtpRunWPSDefault) &&
     2343               strnstr(ad->lines[whichline], "ftp://", width)) ||
     2344              (ad->mailin && *mailrun && mailstr(ad->lines[whichline], "@", width))) {
    22742345
    22752346            USHORT ret;
     
    22852356              switch (ret) {
    22862357              case 0:
    2287                 free(urld);
     2358                free(urld);
    22882359                goto NoAdd;
    22892360              case 1:
    2290                        if (*urld->url)
    2291                          runemf2(SEPARATE | WINDOWED,
    2292                                  hwnd, pszSrcFile, __LINE__,
    2293                                  httprund, NULL, "%s %s", httprun, urld->url);
     2361                if (*urld->url) {
     2362                  if (fHttpRunWPSDefault) {
     2363                    CHAR WPSDefaultHttpRun[CCHMAXPATH], WPSDefaultHttpRunDir[CCHMAXPATH];
     2364
     2365                    size = sizeof(WPSDefaultHttpRun);
     2366                    PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
     2367                                        "DefaultBrowserExe", WPSDefaultHttpRun, &size);
     2368                    size = sizeof(WPSDefaultHttpRunDir);
     2369                    PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
     2370                                        "DefaultWorkingDir", WPSDefaultHttpRunDir, &size);
     2371                    runemf2(SEPARATE | WINDOWED,
     2372                            hwnd, pszSrcFile, __LINE__,
     2373                            WPSDefaultHttpRunDir,
     2374                            fLibPathStrictHttpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
     2375                            "%s %s", WPSDefaultHttpRun, urld->url);
     2376                  }
     2377                  else
     2378                    runemf2(SEPARATE | WINDOWED,
     2379                            hwnd, pszSrcFile, __LINE__,
     2380                            httprundir, NULL, "%s %s", httprun, urld->url);
     2381                }
    22942382                free(urld);
    22952383                goto NoAdd;
    22962384              case 2:
    2297                 if (*urld->url)
    2298                   runemf2(SEPARATE | WINDOWED,
     2385                if (*urld->url){
     2386                  if (fFtpRunWPSDefault) {
     2387                    CHAR WPSDefaultFtpRun[CCHMAXPATH], WPSDefaultFtpRunDir[CCHMAXPATH];
     2388
     2389                    size = sizeof(WPSDefaultFtpRun);
     2390                    PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
     2391                                        "DefaultBrowserExe", WPSDefaultFtpRun, &size);
     2392                    size = sizeof(WPSDefaultFtpRunDir);
     2393                    PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
     2394                                        "DefaultWorkingDir", WPSDefaultFtpRunDir, &size);
     2395                    runemf2(SEPARATE | WINDOWED,
     2396                            hwnd, pszSrcFile, __LINE__,
     2397                            WPSDefaultFtpRunDir,
     2398                            fLibPathStrictFtpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
     2399                            "%s %s", WPSDefaultFtpRun, urld->url);
     2400                  }
     2401                  else
     2402                    runemf2(SEPARATE | WINDOWED,
     2403                            hwnd, pszSrcFile, __LINE__,
     2404                            ftprundir, NULL, "%s %s", ftprun, urld->url);
     2405                }
     2406              case 3:
     2407                if (*urld->url){
     2408                  runemf2(SEPARATE | WINDOWED,
    22992409                          hwnd, pszSrcFile, __LINE__,
    2300                           ftprund, NULL, "%s %s", ftprun, urld->url);
    2301                 free(urld);
    2302                 goto NoAdd;
     2410                          mailrundir, NULL, "%s %s", mailrun, urld->url);
     2411                }
     2412                free(urld);
     2413                goto NoAdd;
    23032414              default:
    23042415                break;
    23052416              }
    2306               free(urld);
     2417              free(urld);
    23072418            }
    23082419          }
     
    25772688                                      IDM_PREVBLANKLINE), !ad->hex);
    25782689      if (ad->numlines)
    2579       //{      // 27 Aug 07 GKY This creates a duplicate error for a zero byte file
    2580       //  if (!ad->text)
    2581       //    Runtime_Error(pszSrcFile, __LINE__, "no data");
    2582       //  PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
    2583       // }
    2584       // else
    25852690      {
    25862691        if (mp1 && (ULONG) mp1 < ad->numlines + 1) {
     
    29413046      WinCheckMenuItem((HWND) mp2, IDM_IGNOREFTP, ad->ignoreftp);
    29423047      WinCheckMenuItem((HWND) mp2, IDM_IGNOREHTTP, ad->ignorehttp);
     3048      WinCheckMenuItem((HWND) mp2, IDM_IGNOREMAIL, ad->ignoremail);
    29433049      break;
    29443050
     
    31323238      ad->ignoreftp = (ad->ignoreftp) ? FALSE : TRUE;
    31333239      ad->ftpin = FALSE;
    3134       if (ad->text && *ftprun && !ad->ignoreftp && strstr(ad->text, "ftp://"))
     3240      if (ad->text && (*ftprun || fFtpRunWPSDefault) &&
     3241          !ad->ignoreftp && strstr(ad->text, "ftp://"))
    31353242        ad->ftpin = TRUE;
    31363243      IgnoreFTP = ad->ignoreftp;
     
    31433250      ad->ignorehttp = (ad->ignorehttp) ? FALSE : TRUE;
    31443251      ad->httpin = FALSE;
    3145       if (ad->text && *httprun && !ad->ignorehttp &&
     3252      if (ad->text && (*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
    31463253          strstr(ad->text, "http://"))
    31473254        ad->httpin = TRUE;
     
    31493256      PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
    31503257                          &ad->ignorehttp, sizeof(BOOL));
     3258      WinInvalidateRect(hwnd, NULL, FALSE);
     3259      break;
     3260
     3261     case IDM_IGNOREMAIL:
     3262      ad->ignoremail = (ad->ignoremail) ? FALSE : TRUE;
     3263      ad->mailin = FALSE;
     3264      if (ad->text && *mailrun && !ad->ignoremail &&
     3265          strstr(ad->text, "@"))
     3266        ad->mailin = TRUE;
     3267      IgnoreMail = ad->ignoremail;
     3268      PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreMail",
     3269                          &ad->ignoremail, sizeof(BOOL));
    31513270      WinInvalidateRect(hwnd, NULL, FALSE);
    31523271      break;
     
    38914010        size = sizeof(BOOL);
    38924011        PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
    3893                             (PVOID) & IgnoreHTTP, &size);
     4012                            (PVOID) & IgnoreHTTP, &size);
     4013        size = sizeof(BOOL);
     4014        PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreMail",
     4015                            (PVOID) & IgnoreMail, &size);
    38944016        memset(&Fattrs, 0, sizeof(FATTRS));
    38954017        size = sizeof(FATTRS);
     
    39214043      ad->ignorehttp = IgnoreHTTP;
    39224044      ad->ignoreftp = IgnoreFTP;
     4045      ad->ignoremail = IgnoreMail;
    39234046      memcpy(ad->colors, Colors, sizeof(LONG) * COLORS_MAX);
    39244047      WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
Note: See TracChangeset for help on using the changeset viewer.