Bookmark fixes and cleanups:

- Fix Search field not working on Windows 7 (at least), hope I didn't break all the other platforms
- Memory management is tedious there, with lots of BookmarkEntry* / BookmarkRangeEntry* shared and dangling around
  we cannot reasonably know when to clean up safely. So go nuclear and std::shared_ptr those things.
This commit is contained in:
vsonnier 2017-02-28 18:58:54 +01:00
parent 469fc41805
commit b149da864a
4 changed files with 164 additions and 127 deletions

View File

@ -78,10 +78,10 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup) {
bool loadStatusOk = true; bool loadStatusOk = true;
// Clear any active data // Clear any active data
bmData.erase(bmData.begin(),bmData.end()); bmData.clear();
recents.erase(recents.begin(),recents.end()); clearRecents();
ranges.erase(ranges.begin(),ranges.end()); clearRanges();
bmDataSorted.erase(bmDataSorted.begin(),bmDataSorted.end()); bmDataSorted.clear();
// File exists but is not readable // File exists but is not readable
if (loadFile.FileExists() && !loadFile.IsFileReadable()) { if (loadFile.FileExists() && !loadFile.IsFileReadable()) {
@ -117,7 +117,7 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup) {
while (view_ranges->hasAnother("range")) { while (view_ranges->hasAnother("range")) {
DataNode *range = view_ranges->getNext("range"); DataNode *range = view_ranges->getNext("range");
BookmarkRangeEntry *re = new BookmarkRangeEntry; BookmarkRangeEntryPtr re(new BookmarkRangeEntry);
if (range->hasAnother("label")) range->getNext("label")->element()->get(re->label); if (range->hasAnother("label")) range->getNext("label")->element()->get(re->label);
if (range->hasAnother("freq")) range->getNext("freq")->element()->get(re->freq); if (range->hasAnother("freq")) range->getNext("freq")->element()->get(re->freq);
@ -143,7 +143,7 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup) {
setExpandState(groupName, (expandState == "true")); setExpandState(groupName, (expandState == "true"));
while (group->hasAnother("modem")) { while (group->hasAnother("modem")) {
DataNode *modem = group->getNext("modem"); DataNode *modem = group->getNext("modem");
BookmarkEntry *be = nodeToBookmark("modem", modem); BookmarkEntryPtr be = nodeToBookmark("modem", modem);
if (be) { if (be) {
addBookmark(groupName.c_str(), be); addBookmark(groupName.c_str(), be);
} else { } else {
@ -159,7 +159,7 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup) {
while (recent_modems->hasAnother("modem")) { while (recent_modems->hasAnother("modem")) {
DataNode *modem = recent_modems->getNext("modem"); DataNode *modem = recent_modems->getNext("modem");
BookmarkEntry *be = nodeToBookmark("modem", modem); BookmarkEntryPtr be = nodeToBookmark("modem", modem);
if (be) { if (be) {
addRecent(be); addRecent(be);
} else { } else {
@ -202,7 +202,7 @@ bool BookmarkMgr::hasBackup(std::string bookmarkFn) {
void BookmarkMgr::addBookmark(std::string group, DemodulatorInstance *demod) { void BookmarkMgr::addBookmark(std::string group, DemodulatorInstance *demod) {
std::lock_guard < std::mutex > lock(busy_lock); std::lock_guard < std::mutex > lock(busy_lock);
BookmarkEntry *be = demodToBookmarkEntry(demod); BookmarkEntryPtr be = demodToBookmarkEntry(demod);
wxGetApp().getDemodMgr().saveInstance(be->node, demod); wxGetApp().getDemodMgr().saveInstance(be->node, demod);
@ -210,7 +210,7 @@ void BookmarkMgr::addBookmark(std::string group, DemodulatorInstance *demod) {
bmDataSorted[group] = false; bmDataSorted[group] = false;
} }
void BookmarkMgr::addBookmark(std::string group, BookmarkEntry *be) { void BookmarkMgr::addBookmark(std::string group, BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lock(busy_lock); std::lock_guard < std::mutex > lock(busy_lock);
bmData[group].push_back(be); bmData[group].push_back(be);
@ -218,7 +218,7 @@ void BookmarkMgr::addBookmark(std::string group, BookmarkEntry *be) {
} }
void BookmarkMgr::removeBookmark(std::string group, BookmarkEntry *be) { void BookmarkMgr::removeBookmark(std::string group, BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lockData(busy_lock); std::lock_guard < std::mutex > lockData(busy_lock);
std::lock_guard < std::mutex > lockEnt(be->busy_lock); std::lock_guard < std::mutex > lockEnt(be->busy_lock);
@ -229,12 +229,12 @@ void BookmarkMgr::removeBookmark(std::string group, BookmarkEntry *be) {
BookmarkList::iterator i = std::find(bmData[group].begin(), bmData[group].end(), be); BookmarkList::iterator i = std::find(bmData[group].begin(), bmData[group].end(), be);
if (i != bmData[group].end()) { if (i != bmData[group].end()) {
delete *i;
bmData[group].erase(i); bmData[group].erase(i);
} }
} }
void BookmarkMgr::removeBookmark(BookmarkEntry *be) { void BookmarkMgr::removeBookmark(BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lockData(busy_lock); std::lock_guard < std::mutex > lockData(busy_lock);
std::lock_guard < std::mutex > lockEnt(be->busy_lock); std::lock_guard < std::mutex > lockEnt(be->busy_lock);
@ -246,7 +246,7 @@ void BookmarkMgr::removeBookmark(BookmarkEntry *be) {
} }
} }
void BookmarkMgr::moveBookmark(BookmarkEntry *be, std::string group) { void BookmarkMgr::moveBookmark(BookmarkEntryPtr be, std::string group) {
std::lock_guard < std::mutex > lockData(busy_lock); std::lock_guard < std::mutex > lockData(busy_lock);
std::lock_guard < std::mutex > lockEnt(be->busy_lock); std::lock_guard < std::mutex > lockEnt(be->busy_lock);
@ -280,9 +280,7 @@ void BookmarkMgr::removeGroup(std::string group) {
BookmarkMap::iterator i = bmData.find(group); BookmarkMap::iterator i = bmData.find(group);
if (i != bmData.end()) { if (i != bmData.end()) {
for (auto ii : bmData[group]) {
delete ii;
}
bmData.erase(group); bmData.erase(group);
} }
} }
@ -383,7 +381,7 @@ void BookmarkMgr::addRecent(DemodulatorInstance *demod) {
trimRecents(); trimRecents();
} }
void BookmarkMgr::addRecent(BookmarkEntry *be) { void BookmarkMgr::addRecent(BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lock(busy_lock); std::lock_guard < std::mutex > lock(busy_lock);
recents.push_back(be); recents.push_back(be);
@ -393,7 +391,7 @@ void BookmarkMgr::addRecent(BookmarkEntry *be) {
void BookmarkMgr::removeRecent(BookmarkEntry *be) { void BookmarkMgr::removeRecent(BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lock(busy_lock); std::lock_guard < std::mutex > lock(busy_lock);
BookmarkList::iterator bm_i = std::find(recents.begin(),recents.end(), be); BookmarkList::iterator bm_i = std::find(recents.begin(),recents.end(), be);
@ -413,19 +411,19 @@ BookmarkList BookmarkMgr::getRecents() {
void BookmarkMgr::clearRecents() { void BookmarkMgr::clearRecents() {
std::lock_guard < std::mutex > lock(busy_lock); std::lock_guard < std::mutex > lock(busy_lock);
recents.erase(recents.begin(),recents.end()); recents.clear();
} }
void BookmarkMgr::trimRecents() { void BookmarkMgr::trimRecents() {
if (recents.size() > BOOKMARK_RECENTS_MAX) { if (recents.size() > BOOKMARK_RECENTS_MAX) {
delete *(recents.begin());
recents.erase(recents.begin(), recents.begin()+1); recents.erase(recents.begin(), recents.begin()+1);
} }
} }
void BookmarkMgr::addRange(BookmarkRangeEntry *re) { void BookmarkMgr::addRange(BookmarkRangeEntryPtr re) {
std::lock_guard < std::mutex > lock(busy_lock); std::lock_guard < std::mutex > lock(busy_lock);
ranges.push_back(re); ranges.push_back(re);
@ -434,12 +432,13 @@ void BookmarkMgr::addRange(BookmarkRangeEntry *re) {
void BookmarkMgr::removeRange(BookmarkRangeEntry *re) { void BookmarkMgr::removeRange(BookmarkRangeEntryPtr re) {
std::lock_guard < std::mutex > lock(busy_lock); std::lock_guard < std::mutex > lock(busy_lock);
BookmarkRangeList::iterator re_i = std::find(ranges.begin(), ranges.end(), re); BookmarkRangeList::iterator re_i = std::find(ranges.begin(), ranges.end(), re);
if (re_i != ranges.end()) { if (re_i != ranges.end()) {
ranges.erase(re_i); ranges.erase(re_i);
} }
} }
@ -460,12 +459,13 @@ BookmarkRangeList BookmarkMgr::getRanges() {
void BookmarkMgr::clearRanges() { void BookmarkMgr::clearRanges() {
std::lock_guard < std::mutex > lock(busy_lock); std::lock_guard < std::mutex > lock(busy_lock);
ranges.erase(ranges.begin(),ranges.end()); ranges.clear();
} }
BookmarkEntry *BookmarkMgr::demodToBookmarkEntry(DemodulatorInstance *demod) { BookmarkEntryPtr BookmarkMgr::demodToBookmarkEntry(DemodulatorInstance *demod) {
BookmarkEntry *be = new BookmarkEntry;
BookmarkEntryPtr be(new BookmarkEntry);
be->bandwidth = demod->getBandwidth(); be->bandwidth = demod->getBandwidth();
be->type = demod->getDemodulatorType(); be->type = demod->getDemodulatorType();
@ -478,12 +478,13 @@ BookmarkEntry *BookmarkMgr::demodToBookmarkEntry(DemodulatorInstance *demod) {
return be; return be;
} }
BookmarkEntry *BookmarkMgr::nodeToBookmark(const char *name_in, DataNode *node) { BookmarkEntryPtr BookmarkMgr::nodeToBookmark(const char *name_in, DataNode *node) {
if (!node->hasAnother("frequency") || !node->hasAnother("type") || !node->hasAnother("bandwidth")) { if (!node->hasAnother("frequency") || !node->hasAnother("type") || !node->hasAnother("bandwidth")) {
return nullptr; return nullptr;
} }
BookmarkEntry *be = new BookmarkEntry(); BookmarkEntryPtr be(new BookmarkEntry());
node->getNext("frequency")->element()->get(be->frequency); node->getNext("frequency")->element()->get(be->frequency);
node->getNext("type")->element()->get(be->type); node->getNext("type")->element()->get(be->type);
node->getNext("bandwidth")->element()->get(be->bandwidth); node->getNext("bandwidth")->element()->get(be->bandwidth);
@ -500,7 +501,7 @@ BookmarkEntry *BookmarkMgr::nodeToBookmark(const char *name_in, DataNode *node)
} }
std::wstring BookmarkMgr::getBookmarkEntryDisplayName(BookmarkEntry *bmEnt) { std::wstring BookmarkMgr::getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt) {
std::wstring dispName = bmEnt->label; std::wstring dispName = bmEnt->label;
if (dispName == "") { if (dispName == "") {

View File

@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include <memory>
#include "DemodulatorInstance.h" #include "DemodulatorInstance.h"
@ -44,26 +45,28 @@ public:
long long endFreq; long long endFreq;
}; };
typedef std::shared_ptr<BookmarkEntry> BookmarkEntryPtr;
typedef std::shared_ptr<BookmarkRangeEntry> BookmarkRangeEntryPtr;
struct BookmarkEntryCompare : public std::binary_function<BookmarkEntry *,BookmarkEntry *,bool> struct BookmarkEntryCompare : public std::binary_function<BookmarkEntryPtr,BookmarkEntryPtr,bool>
{ {
bool operator()(const BookmarkEntry *a, BookmarkEntry *b) const bool operator()(const BookmarkEntryPtr a, BookmarkEntryPtr b) const
{ {
return a->frequency < b->frequency; return a->frequency < b->frequency;
} }
}; };
struct BookmarkRangeEntryCompare : public std::binary_function<BookmarkRangeEntry *,BookmarkRangeEntry *,bool> struct BookmarkRangeEntryCompare : public std::binary_function<BookmarkRangeEntryPtr ,BookmarkRangeEntryPtr ,bool>
{ {
bool operator()(const BookmarkRangeEntry *a, BookmarkRangeEntry *b) const bool operator()(const BookmarkRangeEntryPtr a, BookmarkRangeEntryPtr b) const
{ {
return a->freq < b->freq; return a->freq < b->freq;
} }
}; };
typedef std::vector<BookmarkEntry *> BookmarkList; typedef std::vector<BookmarkEntryPtr> BookmarkList;
typedef std::vector<BookmarkRangeEntry *> BookmarkRangeList; typedef std::vector<BookmarkRangeEntryPtr> BookmarkRangeList;
typedef std::map<std::string, BookmarkList > BookmarkMap; typedef std::map<std::string, BookmarkList > BookmarkMap;
typedef std::map<std::string, bool > BookmarkMapSorted; typedef std::map<std::string, bool > BookmarkMapSorted;
typedef std::vector<std::string> BookmarkNames; typedef std::vector<std::string> BookmarkNames;
@ -80,10 +83,10 @@ public:
bool hasBackup(std::string bookmarkFn); bool hasBackup(std::string bookmarkFn);
void addBookmark(std::string group, DemodulatorInstance *demod); void addBookmark(std::string group, DemodulatorInstance *demod);
void addBookmark(std::string group, BookmarkEntry *be); void addBookmark(std::string group, BookmarkEntryPtr be);
void removeBookmark(std::string group, BookmarkEntry *be); void removeBookmark(std::string group, BookmarkEntryPtr be);
void removeBookmark(BookmarkEntry *be); void removeBookmark(BookmarkEntryPtr be);
void moveBookmark(BookmarkEntry *be, std::string group); void moveBookmark(BookmarkEntryPtr be, std::string group);
void addGroup(std::string group); void addGroup(std::string group);
void removeGroup(std::string group); void removeGroup(std::string group);
@ -100,26 +103,26 @@ public:
void updateBookmarks(std::string group); void updateBookmarks(std::string group);
void addRecent(DemodulatorInstance *demod); void addRecent(DemodulatorInstance *demod);
void addRecent(BookmarkEntry *be); void addRecent(BookmarkEntryPtr be);
void removeRecent(BookmarkEntry *be); void removeRecent(BookmarkEntryPtr be);
BookmarkList getRecents(); BookmarkList getRecents();
void clearRecents(); void clearRecents();
void addRange(BookmarkRangeEntry *re); void addRange(BookmarkRangeEntryPtr re);
void removeRange(BookmarkRangeEntry *re); void removeRange(BookmarkRangeEntryPtr re);
BookmarkRangeList getRanges(); BookmarkRangeList getRanges();
void clearRanges(); void clearRanges();
static std::wstring getBookmarkEntryDisplayName(BookmarkEntry *bmEnt); static std::wstring getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt);
static std::wstring getActiveDisplayName(DemodulatorInstance *demod); static std::wstring getActiveDisplayName(DemodulatorInstance *demod);
protected: protected:
void trimRecents(); void trimRecents();
BookmarkEntry *demodToBookmarkEntry(DemodulatorInstance *demod); BookmarkEntryPtr demodToBookmarkEntry(DemodulatorInstance *demod);
BookmarkEntry *nodeToBookmark(const char *name_in, DataNode *node); BookmarkEntryPtr nodeToBookmark(const char *name_in, DataNode *node);
BookmarkMap bmData; BookmarkMap bmData;
BookmarkMapSorted bmDataSorted; BookmarkMapSorted bmDataSorted;

View File

@ -38,7 +38,7 @@ BookmarkViewVisualDragItem::BookmarkViewVisualDragItem(wxString labelValue) : wx
class ActionDialogRemoveBookmark : public ActionDialog { class ActionDialogRemoveBookmark : public ActionDialog {
public: public:
ActionDialogRemoveBookmark( BookmarkEntry *be ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Bookmark?")) { ActionDialogRemoveBookmark( BookmarkEntryPtr be ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Bookmark?")) {
subject = be; subject = be;
m_questionText->SetLabelText(wxT("Are you sure you want to remove the bookmark\n '" + BookmarkMgr::getBookmarkEntryDisplayName(subject) + "'?")); m_questionText->SetLabelText(wxT("Are you sure you want to remove the bookmark\n '" + BookmarkMgr::getBookmarkEntryDisplayName(subject) + "'?"));
} }
@ -49,7 +49,7 @@ public:
} }
private: private:
BookmarkEntry *subject; BookmarkEntryPtr subject;
}; };
class ActionDialogRemoveGroup : public ActionDialog { class ActionDialogRemoveGroup : public ActionDialog {
@ -71,7 +71,7 @@ private:
class ActionDialogRemoveRange : public ActionDialog { class ActionDialogRemoveRange : public ActionDialog {
public: public:
ActionDialogRemoveRange( BookmarkRangeEntry *rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Range?")) { ActionDialogRemoveRange( BookmarkRangeEntryPtr rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Range?")) {
subject = rangeEnt; subject = rangeEnt;
std::wstring name = rangeEnt->label; std::wstring name = rangeEnt->label;
@ -90,13 +90,13 @@ public:
} }
private: private:
BookmarkRangeEntry *subject; BookmarkRangeEntryPtr subject;
}; };
class ActionDialogUpdateRange : public ActionDialog { class ActionDialogUpdateRange : public ActionDialog {
public: public:
ActionDialogUpdateRange( BookmarkRangeEntry *rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Update Range?")) { ActionDialogUpdateRange( BookmarkRangeEntryPtr rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Update Range?")) {
subject = rangeEnt; subject = rangeEnt;
std::wstring name = rangeEnt->label; std::wstring name = rangeEnt->label;
@ -110,19 +110,17 @@ public:
} }
void doClickOK() { void doClickOK() {
BookmarkRangeEntry *ue = BookmarkView::makeActiveRangeEntry(); BookmarkRangeEntryPtr ue = BookmarkView::makeActiveRangeEntry();
subject->freq = ue->freq; subject->freq = ue->freq;
subject->startFreq = ue->startFreq; subject->startFreq = ue->startFreq;
subject->endFreq = ue->endFreq; subject->endFreq = ue->endFreq;
delete ue;
wxGetApp().getBookmarkMgr().updateActiveList(); wxGetApp().getBookmarkMgr().updateActiveList();
} }
private: private:
BookmarkRangeEntry *subject; BookmarkRangeEntryPtr subject;
}; };
@ -152,11 +150,12 @@ BookmarkView::BookmarkView( wxWindow* parent, wxWindowID id, const wxPoint& pos,
hideProps(); hideProps();
m_updateTimer.Start(500); m_updateTimer.Start(500);
mouseInView.store(false);
visualDragItem = nullptr; visualDragItem = nullptr;
nextEnt = nullptr; nextEnt = nullptr;
nextDemod = nullptr; nextDemod = nullptr;
mouseTracker.setTarget(this);
} }
@ -204,7 +203,6 @@ void BookmarkView::updateTheme() {
m_modulationVal->SetForegroundColour(textColor); m_modulationVal->SetForegroundColour(textColor);
m_modulationLabel->SetForegroundColour(textColor); m_modulationLabel->SetForegroundColour(textColor);
refreshLayout(); refreshLayout();
} }
@ -244,16 +242,15 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
BookmarkNames groupNames; BookmarkNames groupNames;
wxGetApp().getBookmarkMgr().getGroups(groupNames); wxGetApp().getBookmarkMgr().getGroups(groupNames);
if (doUpdateBookmarkGroup.size()) { // Nothing for the moment.. doUpdateBookmarkGroup.clear();
doUpdateBookmarkGroup.erase(doUpdateBookmarkGroup.begin(), doUpdateBookmarkGroup.end());
}
wxTreeItemId bmSelFound = nullptr; wxTreeItemId bmSelFound = nullptr;
std::map<std::string, bool> groupExpandState; std::map<std::string, bool> groupExpandState;
bool searchState = (searchKeywords.size() != 0); bool searchState = (searchKeywords.size() != 0);
groups.erase(groups.begin(),groups.end()); groups.clear();
m_treeView->DeleteChildren(bookmarkBranch); m_treeView->DeleteChildren(bookmarkBranch);
bool bmExpandState = expandState["bookmark"]; bool bmExpandState = expandState["bookmark"];
@ -321,8 +318,6 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
m_treeView->Expand(groupItem); m_treeView->Expand(groupItem);
} }
} }
return bmSelFound; return bmSelFound;
} }
@ -535,6 +530,7 @@ void BookmarkView::onTreeEndLabelEdit( wxTreeEvent& event ) {
void BookmarkView::onTreeActivate( wxTreeEvent& event ) { void BookmarkView::onTreeActivate( wxTreeEvent& event ) {
wxTreeItemId itm = event.GetItem(); wxTreeItemId itm = event.GetItem();
TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(itm)); TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(itm));
@ -643,7 +639,10 @@ bool BookmarkView::isMouseInView() {
if (m_labelText->HasFocus()) { if (m_labelText->HasFocus()) {
return true; return true;
} }
return mouseInView.load(); if (m_searchText->HasFocus()) {
return true;
}
return mouseTracker.mouseInView();
} }
@ -725,7 +724,7 @@ void BookmarkView::doBookmarkActive(std::string group, DemodulatorInstance *demo
} }
void BookmarkView::doBookmarkRecent(std::string group, BookmarkEntry *be) { void BookmarkView::doBookmarkRecent(std::string group, BookmarkEntryPtr be) {
wxGetApp().getBookmarkMgr().removeRecent(be); wxGetApp().getBookmarkMgr().removeRecent(be);
wxGetApp().getBookmarkMgr().addBookmark(group, be); wxGetApp().getBookmarkMgr().addBookmark(group, be);
nextEnt = be; nextEnt = be;
@ -734,7 +733,7 @@ void BookmarkView::doBookmarkRecent(std::string group, BookmarkEntry *be) {
} }
void BookmarkView::doMoveBookmark(BookmarkEntry *be, std::string group) { void BookmarkView::doMoveBookmark(BookmarkEntryPtr be, std::string group) {
wxGetApp().getBookmarkMgr().moveBookmark(be, group); wxGetApp().getBookmarkMgr().moveBookmark(be, group);
nextEnt = be; nextEnt = be;
wxGetApp().getBookmarkMgr().updateBookmarks(); wxGetApp().getBookmarkMgr().updateBookmarks();
@ -750,7 +749,7 @@ void BookmarkView::doRemoveActive(DemodulatorInstance *demod) {
} }
void BookmarkView::doRemoveRecent(BookmarkEntry *be) { void BookmarkView::doRemoveRecent(BookmarkEntryPtr be) {
wxGetApp().getBookmarkMgr().removeRecent(be); wxGetApp().getBookmarkMgr().removeRecent(be);
wxGetApp().getBookmarkMgr().updateActiveList(); wxGetApp().getBookmarkMgr().updateActiveList();
} }
@ -762,9 +761,9 @@ void BookmarkView::doClearRecents() {
void BookmarkView::updateBookmarkChoices() { void BookmarkView::updateBookmarkChoices() {
if (!bookmarkChoices.empty()) {
bookmarkChoices.erase(bookmarkChoices.begin(),bookmarkChoices.end()); bookmarkChoices.clear();
}
TreeViewItem *activeSel = itemToTVI(m_treeView->GetSelection()); TreeViewItem *activeSel = itemToTVI(m_treeView->GetSelection());
bookmarkChoices.push_back(((activeSel != nullptr && activeSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK))?BOOKMARK_VIEW_CHOICE_MOVE:BOOKMARK_VIEW_CHOICE_DEFAULT); bookmarkChoices.push_back(((activeSel != nullptr && activeSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK))?BOOKMARK_VIEW_CHOICE_MOVE:BOOKMARK_VIEW_CHOICE_DEFAULT);
@ -849,7 +848,7 @@ void BookmarkView::activeSelection(DemodulatorInstance *dsel) {
} }
void BookmarkView::activateBookmark(BookmarkEntry *bmEnt) { void BookmarkView::activateBookmark(BookmarkEntryPtr bmEnt) {
DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().loadInstance(bmEnt->node); DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().loadInstance(bmEnt->node);
nextDemod = newDemod; nextDemod = newDemod;
@ -875,13 +874,13 @@ void BookmarkView::activateBookmark(BookmarkEntry *bmEnt) {
} }
void BookmarkView::activateRange(BookmarkRangeEntry *rangeEnt) { void BookmarkView::activateRange(BookmarkRangeEntryPtr rangeEnt) {
wxGetApp().setFrequency(rangeEnt->freq); wxGetApp().setFrequency(rangeEnt->freq);
wxGetApp().getAppFrame()->setViewState(rangeEnt->startFreq + (rangeEnt->endFreq - rangeEnt->startFreq) / 2, rangeEnt->endFreq - rangeEnt->startFreq); wxGetApp().getAppFrame()->setViewState(rangeEnt->startFreq + (rangeEnt->endFreq - rangeEnt->startFreq) / 2, rangeEnt->endFreq - rangeEnt->startFreq);
} }
void BookmarkView::bookmarkSelection(BookmarkEntry *bmSel) { void BookmarkView::bookmarkSelection(BookmarkEntryPtr bmSel) {
m_frequencyVal->SetLabelText(frequencyToStr(bmSel->frequency)); m_frequencyVal->SetLabelText(frequencyToStr(bmSel->frequency));
m_bandwidthVal->SetLabelText(frequencyToStr(bmSel->bandwidth)); m_bandwidthVal->SetLabelText(frequencyToStr(bmSel->bandwidth));
@ -914,7 +913,7 @@ void BookmarkView::bookmarkSelection(BookmarkEntry *bmSel) {
} }
void BookmarkView::recentSelection(BookmarkEntry *bmSel) { void BookmarkView::recentSelection(BookmarkEntryPtr bmSel) {
m_frequencyVal->SetLabelText(frequencyToStr(bmSel->frequency)); m_frequencyVal->SetLabelText(frequencyToStr(bmSel->frequency));
m_bandwidthVal->SetLabelText(frequencyToStr(bmSel->bandwidth)); m_bandwidthVal->SetLabelText(frequencyToStr(bmSel->bandwidth));
@ -967,7 +966,7 @@ void BookmarkView::groupSelection(std::string groupName) {
} }
void BookmarkView::rangeSelection(BookmarkRangeEntry *re) { void BookmarkView::rangeSelection(BookmarkRangeEntryPtr re) {
clearButtons(); clearButtons();
@ -1126,6 +1125,7 @@ void BookmarkView::onLabelText( wxCommandEvent& /* event */ ) {
void BookmarkView::onDoubleClickFreq( wxMouseEvent& /* event */ ) { void BookmarkView::onDoubleClickFreq( wxMouseEvent& /* event */ ) {
TreeViewItem *curSel = itemToTVI(m_treeView->GetSelection()); TreeViewItem *curSel = itemToTVI(m_treeView->GetSelection());
if (curSel && curSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) { if (curSel && curSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
@ -1259,7 +1259,7 @@ void BookmarkView::onRenameGroup( wxCommandEvent& /* event */ ) {
void BookmarkView::onAddRange( wxCommandEvent& /* event */ ) { void BookmarkView::onAddRange( wxCommandEvent& /* event */ ) {
BookmarkRangeEntry *re = BookmarkView::makeActiveRangeEntry(); BookmarkRangeEntryPtr re = BookmarkView::makeActiveRangeEntry();
re->label = m_labelText->GetValue(); re->label = m_labelText->GetValue();
@ -1424,16 +1424,25 @@ void BookmarkView::onTreeItemGetTooltip( wxTreeEvent& event ) {
} }
void BookmarkView::onEnterWindow( wxMouseEvent& /* event */ ) { void BookmarkView::onEnterWindow( wxMouseEvent& event ) {
mouseInView.store(true); mouseTracker.OnMouseEnterWindow(event);
#ifdef _WIN32
if (wxGetApp().getAppFrame()->canFocus()) {
this->SetFocus();
}
#endif
} }
void BookmarkView::onLeaveWindow( wxMouseEvent& /* event */ ) { void BookmarkView::onLeaveWindow( wxMouseEvent& event ) {
mouseInView.store(false); mouseTracker.OnMouseLeftWindow(event);
} }
void BookmarkView::onMotion( wxMouseEvent& event ) { void BookmarkView::onMotion( wxMouseEvent& event ) {
mouseTracker.OnMouseMoved(event);
wxPoint pos = ClientToScreen(event.GetPosition()); wxPoint pos = ClientToScreen(event.GetPosition());
pos += wxPoint(30,-10); pos += wxPoint(30,-10);
@ -1455,11 +1464,26 @@ TreeViewItem *BookmarkView::itemToTVI(wxTreeItemId item) {
return tvi; return tvi;
} }
void BookmarkView::onSearchTextFocus( wxMouseEvent& /* event */ ) { void BookmarkView::onSearchTextFocus( wxMouseEvent& event ) {
if (!m_searchText->IsEmpty()) { mouseTracker.OnMouseMoved(event);
if (m_searchText->GetValue() == L"Search..") {
m_searchText->SetValue(L""); //apparently needed ???
} m_searchText->SetFocus();
if (m_searchText->GetValue() == L"Search..") {
//select the whole field, so that typing
//replaces the whole text by the new one right away.
m_searchText->SetSelection(-1, -1);
}
else if (!m_searchText->GetValue().Trim().empty()) {
//position at the end of the existing field, so we can append
//or truncate the existing field.
m_searchText->SetInsertionPointEnd();
}
else {
//empty field, restore displaying L"Search.."
m_searchText->SetValue(L"Search..");
m_searchText->SetSelection(-1, -1);
} }
} }
@ -1467,11 +1491,9 @@ void BookmarkView::onSearchTextFocus( wxMouseEvent& /* event */ ) {
void BookmarkView::onSearchText( wxCommandEvent& event ) { void BookmarkView::onSearchText( wxCommandEvent& event ) {
wstring searchText = m_searchText->GetValue().Trim().Lower().ToStdWstring(); wstring searchText = m_searchText->GetValue().Trim().Lower().ToStdWstring();
if (!searchKeywords.empty()) { searchKeywords.clear();
searchKeywords.erase(searchKeywords.begin(),searchKeywords.end());
}
if (searchText.length() != 0) { if (searchText.length() != 0) {
std::wstringstream searchTextLo(searchText); std::wstringstream searchTextLo(searchText);
wstring tmp; wstring tmp;
@ -1480,7 +1502,6 @@ void BookmarkView::onSearchText( wxCommandEvent& event ) {
searchKeywords.push_back(tmp); searchKeywords.push_back(tmp);
// std::wcout << L"Keyword: " << tmp << '\n'; // std::wcout << L"Keyword: " << tmp << '\n';
} }
} }
} }
@ -1501,30 +1522,42 @@ void BookmarkView::onClearSearch( wxCommandEvent& /* event */ ) {
m_clearSearchButton->Hide(); m_clearSearchButton->Hide();
m_searchText->SetValue(L"Search.."); m_searchText->SetValue(L"Search..");
m_treeView->SetFocus(); m_treeView->SetFocus();
if (!searchKeywords.empty()) {
searchKeywords.erase(searchKeywords.begin(),searchKeywords.end()); searchKeywords.clear();
}
wxGetApp().getBookmarkMgr().updateActiveList(); wxGetApp().getBookmarkMgr().updateActiveList();
wxGetApp().getBookmarkMgr().updateBookmarks(); wxGetApp().getBookmarkMgr().updateBookmarks();
refreshLayout(); refreshLayout();
} }
void BookmarkView::loadDefaultRanges() { void BookmarkView::loadDefaultRanges() {
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"160 Meters",1900000,1800000,2000000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"80 Meters",3750000,3500000,4000000)); BookmarkRangeEntryPtr band_160meters(new BookmarkRangeEntry(L"160 Meters", 1900000, 1800000, 2000000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"60 Meters",5368500,5332000,5405000)); BookmarkRangeEntryPtr band_80meters(new BookmarkRangeEntry(L"80 Meters", 3750000, 3500000, 4000000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"40 Meters",7150000,7000000,7300000)); BookmarkRangeEntryPtr band_60meters(new BookmarkRangeEntry(L"60 Meters", 5368500, 5332000, 5405000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"30 Meters",10125000,10100000,10150000)); BookmarkRangeEntryPtr band_40meters(new BookmarkRangeEntry(L"40 Meters", 7150000, 7000000, 7300000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"20 Meters",14175000,14000000,14350000)); BookmarkRangeEntryPtr band_30meters(new BookmarkRangeEntry(L"30 Meters", 10125000, 10100000, 10150000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"17 Meters",18068180,17044180,19092180)); BookmarkRangeEntryPtr band_20meters(new BookmarkRangeEntry(L"20 Meters", 14175000, 14000000, 14350000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"15 Meters",21225000,21000000,21450000)); BookmarkRangeEntryPtr band_17meters(new BookmarkRangeEntry(L"17 Meters", 18068180, 17044180, 19092180));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"12 Meters",24940000,24890000,24990000)); BookmarkRangeEntryPtr band_15meters(new BookmarkRangeEntry(L"15 Meters", 21225000, 21000000, 21450000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"10 Meters",28850000,28000000,29700000)); BookmarkRangeEntryPtr band_12meters(new BookmarkRangeEntry(L"12 Meters", 24940000, 24890000, 24990000));
BookmarkRangeEntryPtr band_10meters(new BookmarkRangeEntry(L"10 Meters", 28850000, 28000000, 29700000));
wxGetApp().getBookmarkMgr().addRange(band_160meters);
wxGetApp().getBookmarkMgr().addRange(band_80meters);
wxGetApp().getBookmarkMgr().addRange(band_60meters);
wxGetApp().getBookmarkMgr().addRange(band_40meters);
wxGetApp().getBookmarkMgr().addRange(band_30meters);
wxGetApp().getBookmarkMgr().addRange(band_20meters);
wxGetApp().getBookmarkMgr().addRange(band_17meters);
wxGetApp().getBookmarkMgr().addRange(band_15meters);
wxGetApp().getBookmarkMgr().addRange(band_12meters);
wxGetApp().getBookmarkMgr().addRange(band_10meters);
} }
BookmarkRangeEntry *BookmarkView::makeActiveRangeEntry() { BookmarkRangeEntryPtr BookmarkView::makeActiveRangeEntry() {
BookmarkRangeEntry *re = new BookmarkRangeEntry; BookmarkRangeEntryPtr re(new BookmarkRangeEntry);
re->freq = wxGetApp().getFrequency(); re->freq = wxGetApp().getFrequency();
re->startFreq = wxGetApp().getAppFrame()->getViewCenterFreq() - (wxGetApp().getAppFrame()->getViewBandwidth()/2); re->startFreq = wxGetApp().getAppFrame()->getViewCenterFreq() - (wxGetApp().getAppFrame()->getViewBandwidth()/2);
re->endFreq = wxGetApp().getAppFrame()->getViewCenterFreq() + (wxGetApp().getAppFrame()->getViewBandwidth()/2); re->endFreq = wxGetApp().getAppFrame()->getViewCenterFreq() + (wxGetApp().getAppFrame()->getViewBandwidth()/2);

View File

@ -8,7 +8,7 @@
#include "BookmarkPanel.h" #include "BookmarkPanel.h"
#include "BookmarkMgr.h" #include "BookmarkMgr.h"
#include "MouseTracker.h"
class TreeViewItem : public wxTreeItemData { class TreeViewItem : public wxTreeItemData {
public: public:
@ -27,8 +27,8 @@ public:
}; };
TreeViewItemType type; TreeViewItemType type;
BookmarkEntry *bookmarkEnt; BookmarkEntryPtr bookmarkEnt;
BookmarkRangeEntry *rangeEnt; BookmarkRangeEntryPtr rangeEnt;
DemodulatorInstance *demod; DemodulatorInstance *demod;
std::string groupName; std::string groupName;
}; };
@ -59,15 +59,15 @@ public:
void setExpandState(std::string branchName, bool state); void setExpandState(std::string branchName, bool state);
void loadDefaultRanges(); void loadDefaultRanges();
static BookmarkRangeEntry *makeActiveRangeEntry(); static BookmarkRangeEntryPtr makeActiveRangeEntry();
protected: protected:
void activeSelection(DemodulatorInstance *dsel); void activeSelection(DemodulatorInstance *dsel);
void bookmarkSelection(BookmarkEntry *bmSel); void bookmarkSelection(BookmarkEntryPtr bmSel);
void rangeSelection(BookmarkRangeEntry *re); void rangeSelection(BookmarkRangeEntryPtr re);
void activateBookmark(BookmarkEntry *bmEnt); void activateBookmark(BookmarkEntryPtr bmEnt);
void activateRange(BookmarkRangeEntry *rangeEnt); void activateRange(BookmarkRangeEntryPtr rangeEnt);
void recentSelection(BookmarkEntry *bmSel); void recentSelection(BookmarkEntryPtr bmSel);
void groupSelection(std::string groupName); void groupSelection(std::string groupName);
void bookmarkBranchSelection(); void bookmarkBranchSelection();
void recentBranchSelection(); void recentBranchSelection();
@ -111,10 +111,10 @@ protected:
wxButton *addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler); wxButton *addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler);
void doBookmarkActive(std::string group, DemodulatorInstance *demod); void doBookmarkActive(std::string group, DemodulatorInstance *demod);
void doBookmarkRecent(std::string group, BookmarkEntry *be); void doBookmarkRecent(std::string group, BookmarkEntryPtr be);
void doMoveBookmark(BookmarkEntry *be, std::string group); void doMoveBookmark(BookmarkEntryPtr be, std::string group);
void doRemoveActive(DemodulatorInstance *demod); void doRemoveActive(DemodulatorInstance *demod);
void doRemoveRecent(BookmarkEntry *be); void doRemoveRecent(BookmarkEntryPtr be);
void doClearRecents(); void doClearRecents();
void updateBookmarkChoices(); void updateBookmarkChoices();
@ -142,7 +142,7 @@ protected:
TreeViewItem *itemToTVI(wxTreeItemId item); TreeViewItem *itemToTVI(wxTreeItemId item);
std::atomic_bool mouseInView; MouseTracker mouseTracker;
wxTreeItemId rootBranch, activeBranch, bookmarkBranch, recentBranch, rangeBranch; wxTreeItemId rootBranch, activeBranch, bookmarkBranch, recentBranch, rangeBranch;
@ -166,8 +166,8 @@ protected:
std::atomic_bool doUpdateActive; std::atomic_bool doUpdateActive;
// Focus // Focus
BookmarkEntry *nextEnt; BookmarkEntryPtr nextEnt;
BookmarkRangeEntry *nextRange; BookmarkRangeEntryPtr nextRange;
DemodulatorInstance *nextDemod; DemodulatorInstance *nextDemod;
// Search // Search