2
* Copyright 2007 Simone Della Longa <simonedll@yahoo.it>
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.
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.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
#include "launcher_dialog.h"
25
IMPLEMENT_CLASS(LauncherDialog, wxDialog)
28
BEGIN_EVENT_TABLE(LauncherDialog, wxDialog)
29
EVT_BUTTON(ID_bmp_button, LauncherDialog::OnBrowseEvent)
32
wxString LauncherDialog::lastPath = wxString();
34
void LauncherDialog::SetIcon(const wxBitmap& value)
37
if (value.GetWidth() != 50 || value.GetHeight() != 50)
39
v = value.ConvertToImage().Scale(50,50);
44
bmp_button->SetBitmapLabel(v);
47
bool LauncherDialog::saveChanges()
49
if (!bmp_path.IsEmpty() && bmp_path != launcher->img_link)
51
launcher -> img_link = bmp_path;
52
if (!launcher ->loadImage(bmp_path))
54
wxMessageBox (_T ("Error! Could not load Image"),
55
_T ("SimDock"), wxOK | wxICON_INFORMATION, NULL);
61
if (!launcher -> img.IsOk())
63
wxMessageBox (_T ("Error! Could not load Background Image!"),
64
_T ("SimDock"), wxOK | wxICON_INFORMATION, NULL);
68
launcher->name = name_text->GetValue();
69
launcher->descr = description_text->GetValue();
70
launcher->link = command_text->GetValue();
77
LauncherDialog::LauncherDialog(wxWindow* parent, simImage* launcher): wxDialog(parent, -1, _T("Add/Edit Launcher"))
79
if (!parent || !launcher)
81
printf ("LauncherDialog::LauncherDialog - NULL argument!\n");
84
this->launcher = launcher;
85
bmp_path = launcher->img_link;
87
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
89
wxStaticBoxSizer* LauncherBox = new wxStaticBoxSizer(wxVERTICAL, this, _T("Launcher"));
91
wxBoxSizer* Horizontal0 = new wxBoxSizer( wxHORIZONTAL );
93
bmp_button = new wxBitmapButton(this,ID_bmp_button,NULL,wxDefaultPosition,wxSize(60,60));
94
SetIcon(wxBitmap(launcher->img));
95
Horizontal0->Add(bmp_button,0,5);
96
LauncherBox->Add(Horizontal0, 0, wxGROW|wxALL, 5);
99
wxBoxSizer* Horizontal1 = new wxBoxSizer( wxHORIZONTAL );
100
name_text = new wxTextCtrl(this,-1,launcher->name);
101
Horizontal1->Add(new wxStaticText(this,-1,_T("Name")),wxGROW|wxALL,5);
102
Horizontal1->Add(name_text,wxGROW|wxALL,5);
103
LauncherBox->Add(Horizontal1, 0, wxGROW|wxALL, 5);
106
wxBoxSizer* Horizontal2 = new wxBoxSizer( wxHORIZONTAL );
107
command_text = new wxTextCtrl(this,-1,launcher->link,wxDefaultPosition,wxSize(150,wxDefaultSize.GetHeight()));
108
Horizontal2->Add(new wxStaticText(this,-1,_T("Command")),wxGROW|wxALL,5);
109
Horizontal2->Add(command_text,wxGROW|wxALL,5);
110
LauncherBox->Add(Horizontal2, 0, wxGROW|wxALL, 5);
113
wxBoxSizer* Horizontal3 = new wxBoxSizer( wxHORIZONTAL );
114
description_text = new wxTextCtrl(this,-1,launcher->descr,wxDefaultPosition,wxSize(150,wxDefaultSize.GetHeight()));
115
Horizontal3->Add(new wxStaticText(this,-1,_T("Description")),wxGROW|wxALL,5);
116
Horizontal3->Add(description_text,wxGROW|wxALL,5);
117
LauncherBox->Add(Horizontal3, 0, wxGROW|wxALL, 5);
119
wxSizer * sz = CreateButtonSizer(wxOK|wxCANCEL);
120
LauncherBox->Add(sz, 0, wxGROW|wxALL, 5);
122
topSizer->Add(LauncherBox, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
126
description_text->Enable(false);
127
command_text->Enable(false);
128
name_text->Enable(false);
129
bmp_button->Enable(false);
132
this->SetSizer(topSizer);
137
void LauncherDialog::OnBrowseEvent(wxCommandEvent& event)
139
wxString startingPath;
140
if (!bmp_path.IsEmpty())
141
startingPath = bmp_path;
143
startingPath = lastPath;
145
wxFileName fn(startingPath);
147
wxString filename = wxFileSelector(_T("Choose a file to open"),fn.GetPath() /*wxPathOnly(startingPath)*/, _T(""), _T("png"), wxImage::GetImageExtWildcard(), wxOPEN | wxFILE_MUST_EXIST);
149
if ( !filename.empty() )
152
SetIcon(wxBitmap(filename));
159
LauncherDialog::~LauncherDialog()