SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FXLinkLabel.cpp
Go to the documentation of this file.
1 /* =========================================================================
2  * included modules
3  * ======================================================================= */
4 #ifdef _MSC_VER
5 #include <windows_config.h>
6 #else
7 #include <config.h>
8 #endif
9 
10 #ifdef WIN32
11 #include <windows.h>
12 #endif
13 
14 #include "FXLinkLabel.h"
15 
16 #ifdef CHECK_MEMORY_LEAKS
17 #include <foreign/nvwa/debug_new.h>
18 #endif // CHECK_MEMORY_LEAKS
19 
20 
21 FXint fxexecute(FXString link) {
22 #ifdef WIN32
23  FXString quoted = FXPath::enquote(link);
24  return (size_t)ShellExecute(NULL, "open", quoted.text(), NULL, NULL, SW_SHOW) > 32;
25 #else
26  FXString ext = FXPath::extension(link);
27  FXString list;
28  if (comparecase(link.section(':', 0), "http") == 0 ||
29  comparecase(link.section(':', 0), "ftp") == 0 ||
30  comparecase(ext, "htm") == 0 || comparecase(ext, "html") == 0 ||
31  comparecase(ext, "php") == 0 || comparecase(ext, "asp") == 0) {
32  list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx";
33  } else if (comparecase(ext, "pdf") == 0) {
34  list = "acroread\tkghostview\tgpdf\txpdf";
35  }
36 
37  if (list.length()) {
38  FXString software;
39  FXint index = 0;
40  FXString path = FXSystem::getExecPath();
41 
42  software = list.section("\t", index);
43  while (!software.empty()) {
44  software = FXPath::search(path, software);
45  if (software.length())
46  return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ",
47  software.text(), link.text()).text()) > 0 ? 0 : 1;
48  index++;
49  software = list.section("\t", index);
50  }
51  } else if (FXStat::isExecutable(link)) {
52  return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0 : 1;
53  }
54  return 0;
55 #endif
56 }
57 
58 
59 
60 FXDEFMAP(FXLinkLabel) FXLinkLabelMap[] = {
61  FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, FXLinkLabel::onLeftBtnPress),
62  FXMAPFUNC(SEL_TIMEOUT, FXLinkLabel::ID_TIMER, FXLinkLabel::onTimer),
63 };
64 FXIMPLEMENT(FXLinkLabel, FXLabel, FXLinkLabelMap, ARRAYNUMBER(FXLinkLabelMap))
65 
66 
67 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) {
68  setDefaultCursor(getApp()->getDefaultCursor(DEF_HAND_CURSOR));
69  setTextColor(FXRGB(0, 0, 255));
70 }
71 
73  getApp()->removeTimeout(this, ID_TIMER);
74 }
75 
76 long FXLinkLabel::onLeftBtnPress(FXObject*, FXSelector, void*) {
77  FXString link = getTipText();
78  if (link.length()) {
79  getApp()->beginWaitCursor();
80  if (fxexecute(link)) {
81  getApp()->addTimeout(this, ID_TIMER, 2000); // 2 seconds of way cursor
82  } else {
83  getApp()->endWaitCursor();
84  getApp()->beep();
85  }
86  }
87  return 1;
88 }
89 
90 long FXLinkLabel::onTimer(FXObject*, FXSelector, void*) {
91  getApp()->endWaitCursor();
92  return 1;
93 }