SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FXLinkLabel.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 //
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2006-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 /* =========================================================================
24  * included modules
25  * ======================================================================= */
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifdef WIN32
33 #define NOMINMAX
34 #include <windows.h>
35 #undef NOMINMAX
36 #endif
37 
38 #include "FXLinkLabel.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 FXint
46 FXLinkLabel::fxexecute(FXString link) {
47 #ifdef WIN32
48  FXString quoted = FXPath::enquote(link);
49  return (int)ShellExecute(NULL, "open", quoted.text(), NULL, NULL, SW_SHOW) > 32;
50 #else
51  FXString ext = FXPath::extension(link);
52  FXString list;
53  if (comparecase(link.section(':', 0), "http") == 0 ||
54  comparecase(link.section(':', 0), "ftp") == 0 ||
55  comparecase(ext, "htm") == 0 || comparecase(ext, "html") == 0 ||
56  comparecase(ext, "php") == 0 || comparecase(ext, "asp") == 0) {
57  list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx";
58  } else if (comparecase(ext, "pdf") == 0) {
59  list = "acroread\tkghostview\tgpdf\txpdf";
60  }
61 
62  if (list.length()) {
63  FXString software;
64  FXint index = 0;
65  FXString path = FXSystem::getExecPath();
66 
67  software = list.section("\t", index);
68  while (!software.empty()) {
69  software = FXPath::search(path, software);
70  if (software.length())
71  return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ",
72  software.text(), link.text()).text()) > 0 ? 0 : 1;
73  index++;
74  software = list.section("\t", index);
75  }
76  } else if (FXStat::isExecutable(link)) {
77  return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0 : 1;
78  }
79  return 0;
80 #endif
81 }
82 
83 
84 
85 FXDEFMAP(FXLinkLabel) FXLinkLabelMap[] = {
86  FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, FXLinkLabel::onLeftBtnPress),
87  FXMAPFUNC(SEL_TIMEOUT, FXLinkLabel::ID_TIMER, FXLinkLabel::onTimer),
88 };
89 FXIMPLEMENT(FXLinkLabel, FXLabel, FXLinkLabelMap, ARRAYNUMBER(FXLinkLabelMap))
90 
91 
92 FXLinkLabel::FXLinkLabel(FXComposite* p, const FXString& text, FXIcon* ic, FXuint opts, FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb) : FXLabel(p, text, ic, opts, x, y, w, h, pl, pr, pt, pb) {
93  setDefaultCursor(getApp()->getDefaultCursor(DEF_HAND_CURSOR));
94  setTextColor(FXRGB(0, 0, 255));
95 }
96 
98  getApp()->removeTimeout(this, ID_TIMER);
99 }
100 
101 long FXLinkLabel::onLeftBtnPress(FXObject*, FXSelector, void*) {
102  FXString link = getTipText();
103  if (link.length()) {
104  getApp()->beginWaitCursor();
105  if (fxexecute(link)) {
106  getApp()->addTimeout(this, ID_TIMER, 2000); // 2 seconds of way cursor
107  } else {
108  getApp()->endWaitCursor();
109  getApp()->beep();
110  }
111  }
112  return 1;
113 }
114 
115 long FXLinkLabel::onTimer(FXObject*, FXSelector, void*) {
116  getApp()->endWaitCursor();
117  return 1;
118 }