| 1 |
#include "BitmapSelectorDlg.h" |
| 2 |
#include "wxc_project_metadata.h" |
| 3 |
#include "wxc_settings.h" |
| 4 |
#include "wxgui_helpers.h" |
| 5 |
#include <windowattrmanager.h> |
| 6 |
#include <wx/filedlg.h> |
| 7 |
#include <wx/filename.h> |
| 8 |
|
| 9 |
BitmapSelectorDlg::BitmapSelectorDlg(wxWindow* parent, const wxString& selection) |
| 10 |
: BitmapSelectorDlgBase(parent) |
| 11 |
{ |
| 12 |
wxArrayString arr; |
| 13 |
arr.Add(wxT("wxART_ERROR")); |
| 14 |
arr.Add(wxT("wxART_QUESTION")); |
| 15 |
arr.Add(wxT("wxART_WARNING")); |
| 16 |
arr.Add(wxT("wxART_INFORMATION")); |
| 17 |
arr.Add(wxT("wxART_ADD_BOOKMARK")); |
| 18 |
arr.Add(wxT("wxART_DEL_BOOKMARK")); |
| 19 |
arr.Add(wxT("wxART_HELP_SIDE_PANEL")); |
| 20 |
arr.Add(wxT("wxART_HELP_SETTINGS")); |
| 21 |
arr.Add(wxT("wxART_HELP_BOOK")); |
| 22 |
arr.Add(wxT("wxART_HELP_FOLDER")); |
| 23 |
arr.Add(wxT("wxART_HELP_PAGE")); |
| 24 |
arr.Add(wxT("wxART_GO_BACK")); |
| 25 |
arr.Add(wxT("wxART_GO_FORWARD")); |
| 26 |
arr.Add(wxT("wxART_GO_UP")); |
| 27 |
arr.Add(wxT("wxART_GO_DOWN")); |
| 28 |
arr.Add(wxT("wxART_GO_TO_PARENT")); |
| 29 |
arr.Add(wxT("wxART_GO_HOME")); |
| 30 |
arr.Add(wxT("wxART_GOTO_FIRST")); |
| 31 |
arr.Add(wxT("wxART_GOTO_LAST")); |
| 32 |
arr.Add(wxT("wxART_PRINT")); |
| 33 |
arr.Add(wxT("wxART_HELP")); |
| 34 |
arr.Add(wxT("wxART_TIP")); |
| 35 |
arr.Add(wxT("wxART_REPORT_VIEW")); |
| 36 |
arr.Add(wxT("wxART_LIST_VIEW")); |
| 37 |
arr.Add(wxT("wxART_NEW_DIR")); |
| 38 |
arr.Add(wxT("wxART_FOLDER")); |
| 39 |
arr.Add(wxT("wxART_FOLDER_OPEN")); |
| 40 |
arr.Add(wxT("wxART_GO_DIR_UP")); |
| 41 |
arr.Add(wxT("wxART_EXECUTABLE_FILE")); |
| 42 |
arr.Add(wxT("wxART_NORMAL_FILE")); |
| 43 |
arr.Add(wxT("wxART_TICK_MARK")); |
| 44 |
arr.Add(wxT("wxART_CROSS_MARK")); |
| 45 |
arr.Add(wxT("wxART_MISSING_IMAGE")); |
| 46 |
arr.Add(wxT("wxART_NEW")); |
| 47 |
arr.Add(wxT("wxART_FILE_OPEN")); |
| 48 |
arr.Add(wxT("wxART_FILE_SAVE")); |
| 49 |
arr.Add(wxT("wxART_FILE_SAVE_AS")); |
| 50 |
arr.Add(wxT("wxART_DELETE")); |
| 51 |
arr.Add(wxT("wxART_COPY")); |
| 52 |
arr.Add(wxT("wxART_CUT")); |
| 53 |
arr.Add(wxT("wxART_PASTE")); |
| 54 |
arr.Add(wxT("wxART_UNDO")); |
| 55 |
arr.Add(wxT("wxART_REDO")); |
| 56 |
arr.Add(wxT("wxART_PLUS")); |
| 57 |
arr.Add(wxT("wxART_MINUS")); |
| 58 |
arr.Add(wxT("wxART_CLOSE")); |
| 59 |
arr.Add(wxT("wxART_QUIT")); |
| 60 |
arr.Add(wxT("wxART_FIND")); |
| 61 |
arr.Add(wxT("wxART_FIND_AND_REPLACE")); |
| 62 |
arr.Add(wxT("wxART_HARDDISK")); |
| 63 |
arr.Add(wxT("wxART_FLOPPY")); |
| 64 |
arr.Add(wxT("wxART_CDROM")); |
| 65 |
arr.Add(wxT("wxART_REMOVABLE")); |
| 66 |
arr.Sort(); |
| 67 |
|
| 68 |
m_choiceArtID->Append(arr); |
| 69 |
m_choiceArtID->SetSelection(0); |
| 70 |
m_checkBoxConvertToRelativePath->SetValue(!wxcSettings::Get().HasFlag(wxcSettings::DONT_USE_RELATIVE_BITMAPS)); |
| 71 |
|
| 72 |
wxString artID, clientID, sizeHint; |
| 73 |
if(wxCrafter::IsArtProviderBitmap(selection, artID, clientID, sizeHint)) { |
| 74 |
|
| 75 |
int where = m_choiceArtClientID->FindString(clientID); |
| 76 |
if(where != wxNOT_FOUND) { m_choiceArtClientID->SetSelection(where); } |
| 77 |
|
| 78 |
where = m_choiceArtID->FindString(artID); |
| 79 |
if(where != wxNOT_FOUND) { m_choiceArtID->SetSelection(where); } |
| 80 |
|
| 81 |
where = m_choiceSize->FindString(sizeHint); |
| 82 |
if(where != wxNOT_FOUND) { m_choiceSize->SetSelection(where); } |
| 83 |
|
| 84 |
m_checkBoxSelectFile->SetValue(false); |
| 85 |
m_checkBoxArtProvider->SetValue(true); |
| 86 |
|
| 87 |
} else { |
| 88 |
// File path |
| 89 |
m_checkBoxSelectFile->SetValue(true); |
| 90 |
m_checkBoxArtProvider->SetValue(false); |
| 91 |
|
| 92 |
wxFileName fn(selection); |
| 93 |
if(!fn.IsRelative() && m_checkBoxConvertToRelativePath->IsChecked()) { |
| 94 |
fn.MakeRelativeTo(wxcProjectMetadata::Get().GetProjectPath()); |
| 95 |
} |
| 96 |
m_textCtrlFile->ChangeValue(wxCrafter::ToUnixPath(fn.GetFullPath())); |
| 97 |
} |
| 98 |
SetName("BitmapSelectorDlg"); |
| 99 |
WindowAttrManager::Load(this); |
| 100 |
} |
| 101 |
|
| 102 |
BitmapSelectorDlg::~BitmapSelectorDlg() |
| 103 |
{ |
| 104 |
wxcSettings::Get().EnableFlag(wxcSettings::DONT_USE_RELATIVE_BITMAPS, |
| 105 |
!m_checkBoxConvertToRelativePath->IsChecked()); |
| 106 |
} |
| 107 |
|
| 108 |
void BitmapSelectorDlg::OnBrowseFile(wxCommandEvent& event) |
| 109 |
{ |
| 110 |
wxString initialFileValue = m_textCtrlFile->GetValue(); |
| 111 |
wxFileName fnBitmap(initialFileValue); |
| 112 |
if(fnBitmap.IsRelative()) { fnBitmap.MakeAbsolute(wxcProjectMetadata::Get().GetProjectPath()); } |
| 113 |
initialFileValue = fnBitmap.GetFullPath(); |
| 114 |
|
| 115 |
wxString wildcard = wxT("PNG files (*.png)|*.png|BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif|All files (*)|*"); |
| 116 |
wxString newPath = ::wxFileSelector(_("Select bitmap"), fnBitmap.GetPath(), fnBitmap.GetFullName(), wxEmptyString, |
| 117 |
wildcard, wxFD_OPEN); |
| 118 |
|
| 119 |
if(newPath.IsEmpty() == false) { |
| 120 |
wxFileName newFilePath(newPath); |
| 121 |
if(m_checkBoxConvertToRelativePath->IsChecked()) { |
| 122 |
newFilePath.MakeRelativeTo(wxcProjectMetadata::Get().GetProjectPath()); |
| 123 |
} |
| 124 |
m_textCtrlFile->ChangeValue(wxCrafter::ToUnixPath(newFilePath.GetFullPath())); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
void BitmapSelectorDlg::OnSelectBitmapUI(wxUpdateUIEvent& event) { event.Enable(m_checkBoxSelectFile->IsChecked()); } |
| 129 |
|
| 130 |
void BitmapSelectorDlg::OnUserArtPorviderUI(wxUpdateUIEvent& event) |
| 131 |
{ |
| 132 |
event.Enable(m_checkBoxArtProvider->IsChecked()); |
| 133 |
} |
| 134 |
|
| 135 |
wxString BitmapSelectorDlg::GetBitmapFile() const |
| 136 |
{ |
| 137 |
if(m_checkBoxArtProvider->IsChecked()) { |
| 138 |
wxString str; |
| 139 |
wxString size = m_choiceSize->GetStringSelection(); |
| 140 |
str << m_choiceArtID->GetStringSelection() << "," << m_choiceArtClientID->GetStringSelection() << "," << size; |
| 141 |
return str; |
| 142 |
|
| 143 |
} else { |
| 144 |
return m_textCtrlFile->GetValue(); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
void BitmapSelectorDlg::OnUseFilePicker(wxCommandEvent& event) { m_checkBoxArtProvider->SetValue(false); } |
| 149 |
|
| 150 |
void BitmapSelectorDlg::OnUserArtProvider(wxCommandEvent& event) { m_checkBoxSelectFile->SetValue(false); } |
| 151 |
void BitmapSelectorDlg::OnUseRelativePaths(wxCommandEvent& event) |
| 152 |
{ |
| 153 |
wxFileName newFilePath(m_textCtrlFile->GetValue()); |
| 154 |
if(event.IsChecked()) { |
| 155 |
newFilePath.MakeRelativeTo(wxcProjectMetadata::Get().GetProjectPath()); |
| 156 |
} else { |
| 157 |
newFilePath.MakeAbsolute(wxcProjectMetadata::Get().GetProjectPath()); |
| 158 |
} |
| 159 |
m_textCtrlFile->ChangeValue(wxCrafter::ToUnixPath(newFilePath.GetFullPath())); |
| 160 |
} |