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