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