2006-05-31 19:57:54 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: src/generic/filepickerg.cpp
|
|
|
|
// Purpose: wxGenericFileDirButton class implementation
|
|
|
|
// Author: Francesco Montorsi
|
|
|
|
// Modified by:
|
|
|
|
// Created: 15/04/2006
|
|
|
|
// Copyright: (c) Francesco Montorsi
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
|
2006-06-03 15:20:23 -04:00
|
|
|
#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
|
2006-05-31 19:57:54 -04:00
|
|
|
|
2011-12-18 07:34:47 -05:00
|
|
|
#include "wx/filename.h"
|
2006-05-31 19:57:54 -04:00
|
|
|
#include "wx/filepicker.h"
|
|
|
|
|
2011-12-18 07:27:04 -05:00
|
|
|
#include "wx/scopedptr.h"
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_DYNAMIC_CLASS(wxGenericFileButton, wxButton);
|
|
|
|
wxIMPLEMENT_DYNAMIC_CLASS(wxGenericDirButton, wxButton);
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxGenericFileButton
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-06-29 18:07:34 -04:00
|
|
|
bool wxGenericFileDirButton::Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& label,
|
|
|
|
const wxString& path,
|
|
|
|
const wxString& message,
|
|
|
|
const wxString& wildcard,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
2010-03-08 14:37:08 -05:00
|
|
|
long style,
|
2009-06-29 18:07:34 -04:00
|
|
|
const wxValidator& validator,
|
|
|
|
const wxString& name)
|
2006-05-31 19:57:54 -04:00
|
|
|
{
|
2010-03-08 14:37:08 -05:00
|
|
|
m_pickerStyle = style;
|
|
|
|
|
2011-08-27 10:11:25 -04:00
|
|
|
// If the special wxPB_SMALL flag is used, ignore the provided label and
|
|
|
|
// use the shortest possible label and the smallest possible button fitting
|
|
|
|
// it.
|
|
|
|
long styleButton = 0;
|
|
|
|
wxString labelButton;
|
|
|
|
if ( m_pickerStyle & wxPB_SMALL )
|
|
|
|
{
|
|
|
|
labelButton = _("...");
|
|
|
|
styleButton = wxBU_EXACTFIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelButton = label;
|
|
|
|
}
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
// create this button
|
2011-08-27 10:11:25 -04:00
|
|
|
if ( !wxButton::Create(parent, id, labelButton,
|
|
|
|
pos, size, styleButton, validator, name) )
|
2006-05-31 19:57:54 -04:00
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and handle user clicks on it
|
2018-05-28 16:10:56 -04:00
|
|
|
Bind(wxEVT_BUTTON, &wxGenericFileDirButton::OnButtonClick, this, GetId());
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// create the dialog associated with this button
|
|
|
|
m_path = path;
|
2006-06-02 08:00:30 -04:00
|
|
|
m_message = message;
|
|
|
|
m_wildcard = wildcard;
|
|
|
|
|
|
|
|
return true;
|
2006-05-31 19:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxGenericFileDirButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
|
|
|
|
{
|
2011-12-18 07:27:04 -05:00
|
|
|
wxScopedPtr<wxDialog> p(CreateDialog());
|
2006-06-02 08:00:30 -04:00
|
|
|
if (p->ShowModal() == wxID_OK)
|
2006-05-31 19:57:54 -04:00
|
|
|
{
|
2006-06-02 08:00:30 -04:00
|
|
|
// save updated path in m_path
|
2011-12-18 07:27:04 -05:00
|
|
|
UpdatePathFromDialog(p.get());
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// fire an event
|
|
|
|
wxFileDirPickerEvent event(GetEventType(), this, GetId(), m_path);
|
|
|
|
GetEventHandler()->ProcessEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-18 07:34:47 -05:00
|
|
|
void wxGenericFileDirButton::SetInitialDirectory(const wxString& dir)
|
|
|
|
{
|
|
|
|
m_initialDir = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2012-09-09 09:34:49 -04:00
|
|
|
// wxGenericFileButton
|
2011-12-18 07:34:47 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
wxDialog *wxGenericFileButton::CreateDialog()
|
|
|
|
{
|
2012-09-09 09:34:49 -04:00
|
|
|
// Determine the initial directory for the dialog: it comes either from the
|
|
|
|
// default path, if it has it, or from the separately specified initial
|
|
|
|
// directory that can be set even if the path is e.g. empty.
|
|
|
|
wxFileName fn(m_path);
|
|
|
|
wxString initialDir = fn.GetPath();
|
|
|
|
if ( initialDir.empty() )
|
|
|
|
initialDir = m_initialDir;
|
|
|
|
|
|
|
|
return new wxFileDialog
|
|
|
|
(
|
|
|
|
GetDialogParent(),
|
|
|
|
m_message,
|
|
|
|
initialDir,
|
|
|
|
fn.GetFullName(),
|
|
|
|
m_wildcard,
|
|
|
|
GetDialogStyle()
|
|
|
|
);
|
2011-12-18 07:34:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxGenericDirButton
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
wxDialog *wxGenericDirButton::CreateDialog()
|
|
|
|
{
|
|
|
|
wxDirDialog* const dialog = new wxDirDialog
|
|
|
|
(
|
|
|
|
GetDialogParent(),
|
|
|
|
m_message,
|
|
|
|
m_path.empty() ? m_initialDir : m_path,
|
|
|
|
GetDialogStyle()
|
|
|
|
);
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
|