OpenCPN Partial API docs
LinkPropDlg.cpp
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: Hyperlink properties
5  * Author: David Register
6  *
7  ***************************************************************************
8  * Copyright (C) 2010 by David S. Register *
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24  **************************************************************************/
25 
26 #include "LinkPropDlg.h"
27 #include "navutil.h"
28 #include "gui_lib.h"
29 
30 LinkPropDlgDef::LinkPropDlgDef(wxWindow* parent, wxWindowID id,
31  const wxString& title, const wxPoint& pos,
32  const wxSize& size, long style) {
33  long wstyle = style; // wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
34 
35  wxDialog::Create(parent, id, title, pos, size, wstyle);
36 
37  wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
38  SetFont(*qFont);
39 
40  this->SetSizeHints(wxDefaultSize, wxDefaultSize);
41 
42  wxBoxSizer* bSizerMain;
43  bSizerMain = new wxBoxSizer(wxVERTICAL);
44 
45  wxStaticBoxSizer* sbSizerLnkProp;
46  sbSizerLnkProp = new wxStaticBoxSizer(
47  new wxStaticBox(this, wxID_ANY, _("Link")), wxVERTICAL);
48 
49  m_staticTextLinkDesc = new wxStaticText(this, wxID_ANY, _("Link description"),
50  wxDefaultPosition, wxDefaultSize, 0);
51  m_staticTextLinkDesc->Wrap(-1);
52  sbSizerLnkProp->Add(m_staticTextLinkDesc, 0, wxALL, 5);
53 
54  m_textCtrlLinkDescription = new wxTextCtrl(
55  this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
56  sbSizerLnkProp->Add(m_textCtrlLinkDescription, 0, wxALL | wxEXPAND, 5);
57 
58  m_staticTextLinkUrl = new wxStaticText(this, wxID_ANY, _("URL"),
59  wxDefaultPosition, wxDefaultSize, 0);
60  m_staticTextLinkUrl->Wrap(-1);
61  sbSizerLnkProp->Add(m_staticTextLinkUrl, 0, wxALL, 5);
62 
63  m_textCtrlLinkUrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
64  wxDefaultPosition, wxDefaultSize, 0);
65  sbSizerLnkProp->Add(m_textCtrlLinkUrl, 0, wxALL | wxEXPAND, 5);
66 
67  m_buttonBrowseLocal = new wxButton(this, wxID_ANY, _("Local file..."),
68  wxDefaultPosition, wxDefaultSize, 0);
69  sbSizerLnkProp->Add(m_buttonBrowseLocal, 0, wxALL, 5);
70 
71  bSizerMain->Add(sbSizerLnkProp, 1, wxALL | wxEXPAND, 5);
72 
73  m_sdbSizerButtons = new wxStdDialogButtonSizer();
74  m_sdbSizerButtonsOK = new wxButton(this, wxID_OK);
75  m_sdbSizerButtons->AddButton(m_sdbSizerButtonsOK);
76  m_sdbSizerButtonsCancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
77  m_sdbSizerButtons->AddButton(m_sdbSizerButtonsCancel);
78  m_sdbSizerButtons->Realize();
79 
80  bSizerMain->Add(m_sdbSizerButtons, 0, wxALL | wxEXPAND, 5);
81 
82  this->SetSizer(bSizerMain);
83  this->Layout();
84  Fit();
85 
86  this->Centre(wxBOTH);
87 
88  // Connect Events
89  m_buttonBrowseLocal->Connect(
90  wxEVT_COMMAND_BUTTON_CLICKED,
91  wxCommandEventHandler(LinkPropDlgDef::OnLocalFileClick), NULL, this);
92  m_sdbSizerButtonsCancel->Connect(
93  wxEVT_COMMAND_BUTTON_CLICKED,
94  wxCommandEventHandler(LinkPropDlgDef::OnCancelClick), NULL, this);
95  m_sdbSizerButtonsOK->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
96  wxCommandEventHandler(LinkPropDlgDef::OnOkClick),
97  NULL, this);
98 }
99 
100 LinkPropDlgDef::~LinkPropDlgDef() {
101  // Disconnect Events
102  m_buttonBrowseLocal->Disconnect(
103  wxEVT_COMMAND_BUTTON_CLICKED,
104  wxCommandEventHandler(LinkPropDlgDef::OnLocalFileClick), NULL, this);
105  m_sdbSizerButtonsCancel->Disconnect(
106  wxEVT_COMMAND_BUTTON_CLICKED,
107  wxCommandEventHandler(LinkPropDlgDef::OnCancelClick), NULL, this);
108  m_sdbSizerButtonsOK->Disconnect(
109  wxEVT_COMMAND_BUTTON_CLICKED,
110  wxCommandEventHandler(LinkPropDlgDef::OnOkClick), NULL, this);
111 }
112 
113 LinkPropImpl::LinkPropImpl(wxWindow* parent, wxWindowID id,
114  const wxString& title, const wxPoint& pos,
115  const wxSize& size, long style)
116  : LinkPropDlgDef(parent, id, title, pos, size, style) {
117  m_parent = parent;
118  DimeControl(this);
119 }
120 
121 void LinkPropImpl::OnLocalFileClick(wxCommandEvent& event) {
122  wxString filename = wxFileSelector(_("Choose a file"));
123  if (!filename.empty()) {
124  wxString url = wxFileSystem::FileNameToURL(filename);
125  url.Replace(_T("%3A"), _T(":")); // The replace hack is a way to make it
126  // work on Windows... I hate it.
127  m_textCtrlLinkUrl->SetValue(url);
128  }
129 }
130 
131 void LinkPropImpl::OnOkClick(wxCommandEvent& event) {
132  if (m_textCtrlLinkUrl->GetValue() == wxEmptyString)
133  OCPNMessageBox(NULL, _("Link not complete, can't be saved."),
134  _("OpenCPN Info"), wxICON_HAND);
135 
136  else
137  event.Skip();
138 }
Class LinkPropDlgDef.
Definition: LinkPropDlg.h:59
General purpose GUI support.