diff --git a/src/browser.cpp b/src/browser.cpp index 0624d98f..2c6b2873 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -65,8 +65,8 @@ void Browser::SwitchTo() { CLEAR_FIND_HISTORY; w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList(); - wCurrent = w; - wCurrent->Hide(); + myScreen = this; + w->Hide(); current_screen = csBrowser; // redraw_screen = 1; redraw_header = 1; diff --git a/src/clock.cpp b/src/clock.cpp index cd368af6..97f009fc 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -80,7 +80,7 @@ void Clock::SwitchTo() ) { CLEAR_FIND_HISTORY; - wCurrent = w; + myScreen = this; myPlaylist->Main()->Hide(); current_screen = csClock; redraw_header = 1; @@ -97,7 +97,7 @@ std::string Clock::Title() void Clock::Update() { if (Width > size_t(COLS) || Height > main_height) - return; + myPlaylist->SwitchTo(); time_t rawtime; time(&rawtime); diff --git a/src/global.h b/src/global.h index 53921685..3d18039d 100644 --- a/src/global.h +++ b/src/global.h @@ -24,6 +24,7 @@ #include "settings.h" #include "ncmpcpp.h" #include "mpdpp.h" +#include "screen.h" /// FIXME: this is absolutely shitty, I need to get rid of this. @@ -32,8 +33,8 @@ namespace Global extern ncmpcpp_config Config; extern ncmpcpp_keys Key; - extern Window *wCurrent; - extern Window *wPrev; + extern BasicScreen *myScreen; + extern BasicScreen *myOldScreen; // extern Menu *myPlaylist->Main(); // extern Menu *myBrowser->Main(); diff --git a/src/help.cpp b/src/help.cpp index 4624ee90..881e74e5 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -49,8 +49,8 @@ void Help::SwitchTo() # endif // HAVE_TAGLIB_H ) { - wCurrent = w; - wCurrent->Hide(); + myScreen = this; + w->Hide(); current_screen = csHelp; redraw_header = 1; } diff --git a/src/info.cpp b/src/info.cpp index 13548cae..14fd7db4 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -81,11 +81,11 @@ void Info::Update() void Info::GetSong() { - if (wCurrent == w) + if (myScreen == this) { - wCurrent->Hide(); + w->Hide(); current_screen = prev_screen; - wCurrent = wPrev; + myScreen = myOldScreen; // redraw_screen = 1; redraw_header = 1; if (current_screen == csLibrary) @@ -104,18 +104,18 @@ void Info::GetSong() # endif // HAVE_TAGLIB_H } else if ( - (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) - || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == MPD::itSong) - || (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first) - || (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty()) - || (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) + (myScreen == myPlaylist && !myPlaylist->Main()->Empty()) + || (myScreen == myBrowser && myBrowser->Main()->Current().type == MPD::itSong) + || (myScreen == mySearcher && !mySearcher->Main()->Current().first) + || (myScreen->Cmp() == myLibrary->Songs && !myLibrary->Songs->Empty()) + || (myScreen->Cmp() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) # ifdef HAVE_TAGLIB_H - || (wCurrent == myTagEditor->Tags && !myTagEditor->Tags->Empty()) + || (myScreen->Cmp() == myTagEditor->Tags && !myTagEditor->Tags->Empty()) # endif // HAVE_TAGLIB_H ) { MPD::Song *s = 0; - size_t id = ((Menu *)wCurrent)->Choice(); + size_t id = reinterpret_cast *>(((Screen *)myScreen)->Main())->Choice(); switch (current_screen) { case csPlaylist: @@ -141,8 +141,8 @@ void Info::GetSong() default: break; } - wPrev = wCurrent; - wCurrent = w; + myOldScreen = myScreen; + myScreen = this; prev_screen = current_screen; current_screen = csInfo; redraw_header = 1; @@ -158,11 +158,11 @@ void Info::GetSong() void Info::GetArtist() { - if (wCurrent == w) + if (myScreen == this) { - wCurrent->Hide(); + w->Hide(); current_screen = prev_screen; - wCurrent = wPrev; + myScreen = myOldScreen; // redraw_screen = 1; redraw_header = 1; if (current_screen == csLibrary) @@ -181,14 +181,14 @@ void Info::GetArtist() # endif // HAVE_TAGLIB_H } else if ( - (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) - || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == MPD::itSong) - || (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first) - || (wCurrent == myLibrary->Artists && !myLibrary->Artists->Empty()) - || (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty()) - || (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) + (myScreen == myPlaylist && !myPlaylist->Main()->Empty()) + || (myScreen == myBrowser && myBrowser->Main()->Current().type == MPD::itSong) + || (myScreen == mySearcher && !mySearcher->Main()->Current().first) + || (myScreen->Cmp() == myLibrary->Artists && !myLibrary->Artists->Empty()) + || (myScreen->Cmp() == myLibrary->Songs && !myLibrary->Songs->Empty()) + || (myScreen->Cmp() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) # ifdef HAVE_TAGLIB_H - || (wCurrent == myTagEditor->Tags && !myTagEditor->Tags->Empty()) + || (myScreen->Cmp() == myTagEditor->Tags && !myTagEditor->Tags->Empty()) # endif // HAVE_TAGLIB_H ) { @@ -201,7 +201,7 @@ void Info::GetArtist() Update(); string *artist = new string(); - int id = ((Menu *)wCurrent)->Choice(); + size_t id = reinterpret_cast *>(((Screen *)myScreen)->Main())->Choice(); switch (current_screen) { case csPlaylist: @@ -219,18 +219,18 @@ void Info::GetArtist() case csPlaylistEditor: *artist = myPlaylistEditor->Content->at(id).GetArtist(); break; -# ifdef HAVE_TAGLIB_H +# ifdef HAVE_TAGLIB_H case csTagEditor: *artist = myTagEditor->Tags->at(id).GetArtist(); break; -# endif // HAVE_TAGLIB_H +# endif // HAVE_TAGLIB_H default: break; } if (!artist->empty()) { - wPrev = wCurrent; - wCurrent = w; + myOldScreen = myScreen; + myScreen = this; prev_screen = current_screen; current_screen = csInfo; redraw_header = 1; diff --git a/src/lyrics.cpp b/src/lyrics.cpp index cb6f173e..040091c4 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -84,11 +84,11 @@ void Lyrics::Update() void Lyrics::SwitchTo() { - if (wCurrent == w && !Reload) + if (myScreen == this && !Reload) { - wCurrent->Hide(); + w->Hide(); current_screen = prev_screen; - wCurrent = wPrev; + myScreen = myOldScreen; // redraw_screen = 1; redraw_header = 1; if (current_screen == csLibrary) @@ -108,13 +108,13 @@ void Lyrics::SwitchTo() } else if ( Reload - || (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) - || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == MPD::itSong) - || (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first) - || (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty()) - || (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) + || (myScreen == myPlaylist && !myPlaylist->Main()->Empty()) + || (myScreen == myBrowser && myBrowser->Main()->Current().type == MPD::itSong) + || (myScreen == mySearcher && !mySearcher->Main()->Current().first) + || (myScreen->Cmp() == myLibrary->Songs && !myLibrary->Songs->Empty()) + || (myScreen->Cmp() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) # ifdef HAVE_TAGLIB_H - || (wCurrent == myTagEditor->Tags && !myTagEditor->Tags->Empty()) + || (myScreen->Cmp() == myTagEditor->Tags && !myTagEditor->Tags->Empty()) # endif // HAVE_TAGLIB_H ) { @@ -137,12 +137,12 @@ void Lyrics::SwitchTo() if (Reload) { current_screen = csPlaylist; - wCurrent = myPlaylist->Main(); + myScreen = myPlaylist; Reload = 0; id = myPlaylist->NowPlaying; } else - id = ((Menu *)wCurrent)->Choice(); + id = reinterpret_cast *>(((Screen *)myScreen)->Main())->Choice(); switch (current_screen) { @@ -173,9 +173,9 @@ void Lyrics::SwitchTo() { itsScrollBegin = 0; itsSong = *s; - wPrev = wCurrent; + myOldScreen = myScreen; prev_screen = current_screen; - wCurrent = w; + myScreen = this; current_screen = csLyrics; redraw_header = 1; w->Clear(); diff --git a/src/media_library.cpp b/src/media_library.cpp index 98e95df6..f7794530 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -111,13 +111,13 @@ void MediaLibrary::SwitchTo() { CLEAR_FIND_HISTORY; - myPlaylist->Main()->Hide(); // hack, should be wCurrent, but it doesn't always have 100% width + myPlaylist->Main()->Hide(); // hack, should be myScreen, but it doesn't always have 100% width // redraw_screen = 1; redraw_header = 1; MediaLibrary::Refresh(); - wCurrent = w; + myScreen = this; current_screen = csLibrary; UpdateSongList(Songs); @@ -202,11 +202,11 @@ void MediaLibrary::Update() Albums->Refresh(); } - if (!Artists->Empty() && wCurrent == Albums && Albums->Empty()) + if (!Artists->Empty() && myScreen->Cmp() == Albums && Albums->Empty()) { Albums->HighlightColor(Config.main_highlight_color); Artists->HighlightColor(Config.active_column_color); - wCurrent = w = Artists; + w = Artists; } if (!Artists->Empty() && Songs->Empty()) @@ -257,7 +257,7 @@ void MediaLibrary::NextColumn() return; Artists->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = Albums; + w = Albums; Albums->HighlightColor(Config.active_column_color); if (!Albums->Empty()) return; @@ -266,7 +266,7 @@ void MediaLibrary::NextColumn() { Albums->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = Songs; + w = Songs; Songs->HighlightColor(Config.active_column_color); } } @@ -278,7 +278,7 @@ void MediaLibrary::PrevColumn() { Songs->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = Albums; + w = Albums; Albums->HighlightColor(Config.active_column_color); if (!Albums->Empty()) return; @@ -287,7 +287,7 @@ void MediaLibrary::PrevColumn() { Albums->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = Artists; + w = Artists; Artists->HighlightColor(Config.active_column_color); } } @@ -296,7 +296,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play) { SongList list; - if (!Artists->Empty() && wCurrent == Artists) + if (!Artists->Empty() && w == Artists) { Mpd->StartSearch(1); Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->Current())); @@ -318,7 +318,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play) ShowMessage("%s", message_part_of_songs_added); } } - else if (wCurrent == Albums) + else if (w == Albums) { for (size_t i = 0; i < Songs->Size(); i++) Mpd->QueueAddSong(Songs->at(i)); @@ -335,7 +335,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play) ShowMessage("%s", message_part_of_songs_added); } } - else if (wCurrent == Songs) + else if (w == Songs) { if (!Songs->Empty()) { @@ -387,13 +387,13 @@ void MediaLibrary::AddToPlaylist(bool add_n_play) FreeSongList(list); if (!add_n_play) { - wCurrent->Scroll(wDown); - if (wCurrent == Artists) + w->Scroll(wDown); + if (w == Artists) { Albums->Clear(0); Songs->Clear(0); } - else if (wCurrent == Albums) + else if (w == Albums) Songs->Clear(0); } } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index d19baee9..08edc36a 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -63,8 +63,8 @@ using std::vector; ncmpcpp_config Global::Config; ncmpcpp_keys Global::Key; -Window *Global::wCurrent; -Window *Global::wPrev; +BasicScreen *Global::myScreen; +BasicScreen *Global::myOldScreen; Window *Global::wHeader; Window *Global::wFooter; @@ -178,7 +178,7 @@ int main(int argc, char *argv[]) wFooter->SetGetStringHelper(TraceMpdStatus); wFooter->Display(); - wCurrent = myPlaylist->Main(); + myScreen = myPlaylist; current_screen = csPlaylist; timer = time(NULL); @@ -201,6 +201,9 @@ int main(int argc, char *argv[]) gettimeofday(&now, 0); + // this type of casting is absolutely hillarious lol + Screen *&myWindow = *(Screen **)(void *)&myScreen; + while (!main_exit) { if (!Mpd->Connected()) @@ -337,10 +340,10 @@ int main(int argc, char *argv[]) myInfo->Update(); } - wCurrent->Display(); + myWindow->Main()->Display(); // redraw_screen = 0; - wCurrent->ReadKey(input); + myWindow->Main()->ReadKey(input); if (input == ERR) continue; @@ -362,26 +365,26 @@ int main(int argc, char *argv[]) { if (Keypressed(input, Key.Up) || Keypressed(input, Key.Down) || Keypressed(input, Key.PageUp) || Keypressed(input, Key.PageDown) || Keypressed(input, Key.Home) || Keypressed(input, Key.End) || Keypressed(input, Key.FindForward) || Keypressed(input, Key.FindBackward) || Keypressed(input, Key.NextFoundPosition) || Keypressed(input, Key.PrevFoundPosition)) { - if (wCurrent == myLibrary->Artists) + if (myScreen->Cmp() == myLibrary->Artists) { myLibrary->Albums->Clear(0); myLibrary->Songs->Clear(0); } - else if (wCurrent == myLibrary->Albums) + else if (myScreen->Cmp() == myLibrary->Albums) { myLibrary->Songs->Clear(0); } - else if (wCurrent == myPlaylistEditor->List) + else if (myScreen->Cmp() == myPlaylistEditor->List) { myPlaylistEditor->Content->Clear(0); } # ifdef HAVE_TAGLIB_H - else if (wCurrent == myTagEditor->LeftColumn) + else if (myScreen->Cmp() == myTagEditor->LeftColumn) { myTagEditor->Tags->Clear(0); myTagEditor->TagTypes->Refresh(); } -// else if (wCurrent == myTagEditor->TagTypes) +// else if (myScreen == myTagEditor->TagTypes) // redraw_screen = 1; # endif // HAVE_TAGLIB_H } @@ -400,25 +403,25 @@ int main(int argc, char *argv[]) ) { if (!Config.fancy_scrolling - && (wCurrent == myLibrary->Artists - || wCurrent == myPlaylistEditor->List + && (myScreen->Cmp() == myLibrary->Artists + || myScreen->Cmp() == myPlaylistEditor->List # ifdef HAVE_TAGLIB_H - || wCurrent == myTagEditor->LeftColumn + || myScreen->Cmp() == myTagEditor->LeftColumn # endif // HAVE_TAGLIB_H ) ) { - wCurrent->SetTimeout(50); + myWindow->Main()->SetTimeout(50); while (Keypressed(input, Key.Up)) { - wCurrent->Scroll(wUp); - wCurrent->Refresh(); - wCurrent->ReadKey(input); + myWindow->Main()->Scroll(wUp); + myWindow->Main()->Refresh(); + myWindow->Main()->ReadKey(input); } - wCurrent->SetTimeout(ncmpcpp_window_timeout); + myWindow->Main()->SetTimeout(ncmpcpp_window_timeout); } else - wCurrent->Scroll(wUp); + myWindow->Main()->Scroll(wUp); } else if ( Keypressed(input, Key.Down) @@ -428,25 +431,25 @@ int main(int argc, char *argv[]) ) { if (!Config.fancy_scrolling - && (wCurrent == myLibrary->Artists - || wCurrent == myPlaylistEditor->List + && (myScreen->Cmp() == myLibrary->Artists + || myScreen->Cmp() == myPlaylistEditor->List # ifdef HAVE_TAGLIB_H - || wCurrent == myTagEditor->LeftColumn + || myScreen->Cmp() == myTagEditor->LeftColumn # endif // HAVE_TAGLIB_H ) ) { - wCurrent->SetTimeout(50); + myWindow->Main()->SetTimeout(50); while (Keypressed(input, Key.Down)) { - wCurrent->Scroll(wDown); - wCurrent->Refresh(); - wCurrent->ReadKey(input); + myWindow->Main()->Scroll(wDown); + myWindow->Main()->Refresh(); + myWindow->Main()->ReadKey(input); } - wCurrent->SetTimeout(ncmpcpp_window_timeout); + myWindow->Main()->SetTimeout(ncmpcpp_window_timeout); } else - wCurrent->Scroll(wDown); + myWindow->Main()->Scroll(wDown); } else if ( Keypressed(input, Key.PageUp) @@ -455,7 +458,7 @@ int main(int argc, char *argv[]) # endif // ENABLE_CLOCK ) { - wCurrent->Scroll(wPageUp); + myWindow->Main()->Scroll(wPageUp); } else if ( Keypressed(input, Key.PageDown) @@ -464,15 +467,15 @@ int main(int argc, char *argv[]) # endif // ENABLE_CLOCK ) { - wCurrent->Scroll(wPageDown); + myWindow->Main()->Scroll(wPageDown); } else if (Keypressed(input, Key.Home)) { - wCurrent->Scroll(wHome); + myWindow->Main()->Scroll(wHome); } else if (Keypressed(input, Key.End)) { - wCurrent->Scroll(wEnd); + myWindow->Main()->Scroll(wEnd); } else if (input == KEY_RESIZE) { @@ -545,7 +548,7 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.GoToParentDir)) { - if (wCurrent == myBrowser->Main() && myBrowser->CurrentDir() != "/") + if (myScreen == myBrowser && myBrowser->CurrentDir() != "/") { myBrowser->Main()->Reset(); myBrowser->EnterPressed(); @@ -601,26 +604,26 @@ int main(int argc, char *argv[]) else if (Keypressed(input, Key.Space)) { if (Config.space_selects - || wCurrent == myPlaylist->Main() + || myScreen == myPlaylist # ifdef HAVE_TAGLIB_H - || wCurrent == myTagEditor->Tags + || myScreen->Cmp() == myTagEditor->Tags # endif // HAVE_TAGLIB_H ) { - if (wCurrent == myPlaylist->Main() + if (myScreen == myPlaylist # ifdef HAVE_TAGLIB_H - || wCurrent == myTagEditor->Tags + || myScreen->Cmp() == myTagEditor->Tags # endif // HAVE_TAGLIB_H - || (wCurrent == myBrowser->Main() && ((Menu *)wCurrent)->Choice() >= (myBrowser->CurrentDir() != "/" ? 1 : 0)) || (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first) - || wCurrent == myLibrary->Songs - || wCurrent == myPlaylistEditor->Content) + || (myScreen == myBrowser && ((Menu *)myWindow->Main())->Choice() >= (myBrowser->CurrentDir() != "/" ? 1 : 0)) || (myScreen == mySearcher && !mySearcher->Main()->Current().first) + || myScreen->Cmp() == myLibrary->Songs + || myScreen->Cmp() == myPlaylistEditor->Content) { - List *mList = (Menu *)wCurrent; + List *mList = (Menu *)myWindow->Main(); if (mList->Empty()) continue; size_t i = mList->Choice(); mList->Select(i, !mList->isSelected(i)); - wCurrent->Scroll(wDown); + myWindow->Main()->Scroll(wDown); } } else @@ -730,10 +733,10 @@ int main(int argc, char *argv[]) } Mpd->CommitQueue(); } - else if (current_screen == csBrowser || wCurrent == myPlaylistEditor->List) + else if (current_screen == csBrowser || myScreen->Cmp() == myPlaylistEditor->List) { LockStatusbar(); - string name = wCurrent == myBrowser->Main() ? myBrowser->Main()->Current().name : myPlaylistEditor->List->Current(); + string name = myScreen == myBrowser ? myBrowser->Main()->Current().name : myPlaylistEditor->List->Current(); if (current_screen != csBrowser || myBrowser->Main()->Current().type == itPlaylist) { Statusbar() << "Delete playlist " << name << " ? [y/n] "; @@ -759,7 +762,7 @@ int main(int argc, char *argv[]) } UnlockStatusbar(); } - else if (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) + else if (myScreen->Cmp() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) { if (myPlaylistEditor->Content->hasSelected()) { @@ -915,7 +918,7 @@ int main(int argc, char *argv[]) } myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout); } - else if (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) + else if (myScreen->Cmp() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) { myPlaylistEditor->Content->SetTimeout(50); if (myPlaylistEditor->Content->hasSelected()) @@ -1019,7 +1022,7 @@ int main(int argc, char *argv[]) myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout); } - else if (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) + else if (myScreen->Cmp() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) { myPlaylistEditor->Content->SetTimeout(50); if (myPlaylistEditor->Content->hasSelected()) @@ -1151,7 +1154,7 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.ToggleDisplayMode)) { - if (wCurrent == myPlaylist->Main()) + if (myScreen == myPlaylist) { Config.columns_in_playlist = !Config.columns_in_playlist; ShowMessage("Playlist display mode: %s", Config.columns_in_playlist ? "Columns" : "Classic"); @@ -1159,13 +1162,13 @@ int main(int argc, char *argv[]) myPlaylist->Main()->SetItemDisplayerUserData(Config.columns_in_playlist ? &Config.song_columns_list_format : &Config.song_list_format); myPlaylist->Main()->SetTitle(Config.columns_in_playlist ? Display::Columns(Config.song_columns_list_format) : ""); } - else if (wCurrent == myBrowser->Main()) + else if (myScreen == myBrowser) { Config.columns_in_browser = !Config.columns_in_browser; ShowMessage("Browser display mode: %s", Config.columns_in_browser ? "Columns" : "Classic"); myBrowser->Main()->SetTitle(Config.columns_in_browser ? Display::Columns(Config.song_columns_list_format) : ""); } - else if (wCurrent == mySearcher->Main()) + else if (myScreen == mySearcher) { Config.columns_in_search_engine = !Config.columns_in_search_engine; ShowMessage("Search engine display mode: %s", Config.columns_in_search_engine ? "Columns" : "Classic"); @@ -1246,7 +1249,7 @@ int main(int argc, char *argv[]) { CHECK_MPD_MUSIC_DIR; # ifdef HAVE_TAGLIB_H - if (wCurrent == myLibrary->Artists) + if (myScreen->Cmp() == myLibrary->Artists) { LockStatusbar(); Statusbar() << fmtBold << IntoStr(Config.media_lib_primary_tag) << fmtBoldEnd << ": "; @@ -1284,7 +1287,7 @@ int main(int argc, char *argv[]) FreeSongList(list); } } - else if (wCurrent == myLibrary->Albums) + else if (myScreen->Cmp() == myLibrary->Albums) { LockStatusbar(); Statusbar() << fmtBold << "Album: " << fmtBoldEnd; @@ -1322,16 +1325,16 @@ int main(int argc, char *argv[]) } } else if ( - (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) - || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itSong) - || (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first) - || (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty()) - || (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) - || (wCurrent == myTagEditor->Tags && !myTagEditor->Tags->Empty())) + (myScreen == myPlaylist && !myPlaylist->Main()->Empty()) + || (myScreen == myBrowser && myBrowser->Main()->Current().type == itSong) + || (myScreen == mySearcher && !mySearcher->Main()->Current().first) + || (myScreen->Cmp() == myLibrary->Songs && !myLibrary->Songs->Empty()) + || (myScreen->Cmp() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) + || (myScreen->Cmp() == myTagEditor->Tags && !myTagEditor->Tags->Empty())) { myTinyTagEditor->SwitchTo(); } - else if (wCurrent == myTagEditor->Dirs) + else if (myScreen->Cmp() == myTagEditor->Dirs) { string old_dir = myTagEditor->Dirs->Current().first; LockStatusbar(); @@ -1354,7 +1357,7 @@ int main(int argc, char *argv[]) } else # endif // HAVE_TAGLIB_H - if (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itDirectory) + if (myScreen == myBrowser && myBrowser->Main()->Current().type == itDirectory) { string old_dir = myBrowser->Main()->Current().name; LockStatusbar(); @@ -1383,9 +1386,9 @@ int main(int argc, char *argv[]) ShowMessage("Cannot rename '%s' to '%s'!", old_dir.c_str(), new_dir.c_str()); } } - else if (wCurrent == myPlaylistEditor->List || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itPlaylist)) + else if (myScreen->Cmp() == myPlaylistEditor->List || (myScreen == myBrowser && myBrowser->Main()->Current().type == itPlaylist)) { - string old_name = wCurrent == myPlaylistEditor->List ? myPlaylistEditor->List->Current() : myBrowser->Main()->Current().name; + string old_name = myScreen->Cmp() == myPlaylistEditor->List ? myPlaylistEditor->List->Current() : myBrowser->Main()->Current().name; LockStatusbar(); Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd; string new_name = wFooter->GetString(old_name); @@ -1402,16 +1405,16 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.GoToContainingDir)) { - if ((wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) - || (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first) - || (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty()) - || (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) + if ((myScreen == myPlaylist && !myPlaylist->Main()->Empty()) + || (myScreen == mySearcher && !mySearcher->Main()->Current().first) + || (myScreen->Cmp() == myLibrary->Songs && !myLibrary->Songs->Empty()) + || (myScreen->Cmp() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty()) # ifdef HAVE_TAGLIB_H - || (wCurrent == myTagEditor->Tags && !myTagEditor->Tags->Empty()) + || (myScreen->Cmp() == myTagEditor->Tags && !myTagEditor->Tags->Empty()) # endif // HAVE_TAGLIB_H ) { - size_t id = ((Menu *)wCurrent)->Choice(); + size_t id = ((Menu *)myScreen)->Choice(); Song *s = 0; switch (current_screen) { @@ -1457,7 +1460,7 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.StartSearching)) { - if (wCurrent == mySearcher->Main()) + if (myScreen == mySearcher) { mySearcher->Main()->Highlight(SearchEngine::SearchButton); mySearcher->Main()->Highlighting(0); @@ -1485,24 +1488,24 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.ReverseSelection)) { - if (wCurrent == myPlaylist->Main() - || wCurrent == myBrowser->Main() - || (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first) - || wCurrent == myLibrary->Songs - || wCurrent == myPlaylistEditor->Content + if (myScreen == myPlaylist + || myScreen == myBrowser + || (myScreen == mySearcher && !mySearcher->Main()->Current().first) + || myScreen->Cmp() == myLibrary->Songs + || myScreen->Cmp() == myPlaylistEditor->Content # ifdef HAVE_TAGLIB_H - || wCurrent == myTagEditor->Tags + || myScreen->Cmp() == myTagEditor->Tags # endif // HAVE_TAGLIB_H ) { - List *mList = reinterpret_cast *>(wCurrent); + List *mList = reinterpret_cast *>(myWindow->Main()); for (size_t i = 0; i < mList->Size(); i++) mList->Select(i, !mList->isSelected(i) && !mList->isStatic(i)); // hackish shit begins - if (wCurrent == myBrowser->Main() && myBrowser->CurrentDir() != "/") + if (myScreen == myBrowser && myBrowser->CurrentDir() != "/") mList->Select(0, 0); // [..] cannot be selected, uhm. - if (wCurrent == mySearcher->Main()) + if (myScreen == mySearcher) mList->Select(SearchEngine::ResetButton, 0); // 'Reset' cannot be selected, omgplz. // hacking shit ends. ShowMessage("Selection reversed!"); @@ -1510,17 +1513,17 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.DeselectAll)) { - if (wCurrent == myPlaylist->Main() - || wCurrent == myBrowser->Main() - || wCurrent == mySearcher->Main() - || wCurrent == myLibrary->Songs - || wCurrent == myPlaylistEditor->Content + if (myScreen == myPlaylist + || myScreen == myBrowser + || myScreen == mySearcher + || myScreen->Cmp() == myLibrary->Songs + || myScreen->Cmp() == myPlaylistEditor->Content # ifdef HAVE_TAGLIB_H - || wCurrent == myTagEditor->Tags + || myScreen->Cmp() == myTagEditor->Tags # endif // HAVE_TAGLIB_H ) { - List *mList = reinterpret_cast *>(wCurrent); + List *mList = reinterpret_cast *>(myWindow->Main()); if (mList->hasSelected()) { for (size_t i = 0; i < mList->Size(); i++) @@ -1531,14 +1534,14 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.AddSelected)) { - if (wCurrent != myPlaylist->Main() - && wCurrent != myBrowser->Main() - && wCurrent != mySearcher->Main() - && wCurrent != myLibrary->Songs - && wCurrent != myPlaylistEditor->Content) + if (myScreen != myPlaylist + && myScreen != myBrowser + && myScreen != mySearcher + && myScreen->Cmp() != myLibrary->Songs + && myScreen->Cmp() != myPlaylistEditor->Content) continue; - List *mList = reinterpret_cast *>(wCurrent); + List *mList = reinterpret_cast *>(myWindow->Main()); if (!mList->hasSelected()) { ShowMessage("No selected items!"); @@ -1668,7 +1671,7 @@ int main(int argc, char *argv[]) myPlaylistEditor->Refresh(); } else - wCurrent->Refresh(); + myScreen->Refresh(); if (id == 0) { @@ -1765,7 +1768,7 @@ int main(int argc, char *argv[]) || current_screen == csSearcher # ifdef HAVE_TAGLIB_H || current_screen == csTinyTagEditor - || wCurrent == myTagEditor->TagTypes + || myScreen->Cmp() == myTagEditor->TagTypes # endif // HAVE_TAGLIB_H ) && (current_screen != csSearcher @@ -1786,8 +1789,8 @@ int main(int argc, char *argv[]) CLEAR_FIND_HISTORY; ShowMessage("Searching..."); - List *mList = reinterpret_cast *>(wCurrent); - for (size_t i = (wCurrent == mySearcher->Main() ? SearchEngine::StaticOptions : 0); i < mList->Size(); i++) + List *mList = reinterpret_cast *>(myWindow->Main()); + for (size_t i = (myScreen == mySearcher ? SearchEngine::StaticOptions : 0); i < mList->Size(); i++) { string name; switch (current_screen) @@ -1814,22 +1817,22 @@ int main(int argc, char *argv[]) name = mySearcher->Main()->at(i).second->toString(Config.song_list_format); break; case csLibrary: - if (wCurrent == myLibrary->Artists) + if (myScreen->Cmp() == myLibrary->Artists) name = myLibrary->Artists->at(i); - else if (wCurrent == myLibrary->Albums) + else if (myScreen->Cmp() == myLibrary->Albums) name = myLibrary->Albums->at(i).first; else name = myLibrary->Songs->at(i).toString(Config.song_library_format); break; case csPlaylistEditor: - if (wCurrent == myPlaylistEditor->List) + if (myScreen->Cmp() == myPlaylistEditor->List) name = myPlaylistEditor->List->at(i); else name = myPlaylistEditor->Content->at(i).toString(Config.song_list_format); break; # ifdef HAVE_TAGLIB_H case csTagEditor: - if (wCurrent == myTagEditor->LeftColumn) + if (myScreen->Cmp() == myTagEditor->LeftColumn) name = myTagEditor->LeftColumn->at(i).first; else { @@ -1908,7 +1911,7 @@ int main(int argc, char *argv[]) else { mList->Highlight(vFoundPositions[found_pos < 0 ? 0 : found_pos]); - if (wCurrent == myPlaylist->Main()) + if (myScreen == myPlaylist) { timer = time(NULL); myPlaylist->Main()->Highlighting(1); @@ -1919,7 +1922,7 @@ int main(int argc, char *argv[]) { if (!vFoundPositions.empty()) { - List *mList = reinterpret_cast *>(wCurrent); + List *mList = reinterpret_cast *>(myWindow->Main()); try { mList->Highlight(vFoundPositions.at(Keypressed(input, Key.NextFoundPosition) ? ++found_pos : --found_pos)); @@ -1962,11 +1965,11 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.SwitchTagTypeList)) { - if (wCurrent == myBrowser->Main()) + if (myScreen == myBrowser) { myBrowser->ChangeBrowseMode(); } - else if (wCurrent == myLibrary->Artists) + else if (myScreen->Cmp() == myLibrary->Artists) { LockStatusbar(); Statusbar() << "Tag type ? [" << fmtBold << 'a' << fmtBoldEnd << "rtist/" << fmtBold << 'y' << fmtBoldEnd << "ear/" << fmtBold << 'g' << fmtBoldEnd << "enre/" << fmtBold << 'c' << fmtBoldEnd << "omposer/" << fmtBold << 'p' << fmtBoldEnd << "erformer] "; diff --git a/src/playlist.cpp b/src/playlist.cpp index 6328749f..31ce8bcb 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -51,8 +51,8 @@ void Playlist::SwitchTo() ) { CLEAR_FIND_HISTORY; - wCurrent = w; - wCurrent->Hide(); + myScreen = this; + w->Hide(); current_screen = csPlaylist; // redraw_screen = 1; redraw_header = 1; @@ -148,4 +148,4 @@ const MPD::Song &Playlist::NowPlayingSong() { static MPD::Song null; return isPlaying() ? w->at(NowPlaying) : null; -} \ No newline at end of file +} diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index b6b5e052..f81b5fba 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -99,13 +99,13 @@ void PlaylistEditor::SwitchTo() { CLEAR_FIND_HISTORY; - myPlaylist->Main()->Hide(); // hack, should be wCurrent, but it doesn't always have 100% width + myPlaylist->Main()->Hide(); // hack, should be myScreen, but it doesn't always have 100% width // redraw_screen = 1; redraw_header = 1; - PlaylistEditor::Refresh(); + Refresh(); - wCurrent = w; + myScreen = this; current_screen = csPlaylistEditor; UpdateSongList(Content); @@ -157,11 +157,11 @@ void PlaylistEditor::Update() Content->Display(); } - if (wCurrent == Content && Content->Empty()) + if (w == Content && Content->Empty()) { Content->HighlightColor(Config.main_highlight_color); List->HighlightColor(Config.active_column_color); - wCurrent = w = List; + w = List; } if (Content->Empty()) @@ -178,7 +178,7 @@ void PlaylistEditor::NextColumn() CLEAR_FIND_HISTORY; List->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = Content; + w = Content; Content->HighlightColor(Config.active_column_color); } } @@ -190,7 +190,7 @@ void PlaylistEditor::PrevColumn() CLEAR_FIND_HISTORY; Content->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = List; + w = List; List->HighlightColor(Config.active_column_color); } } @@ -199,7 +199,7 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play) { SongList list; - if (wCurrent == List && !List->Empty()) + if (w == List && !List->Empty()) { Mpd->GetPlaylistContent(locale_to_utf_cpy(List->Current()), list); for (SongList::const_iterator it = list.begin(); it != list.end(); it++) @@ -217,7 +217,7 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play) ShowMessage("%s", message_part_of_songs_added); } } - else if (wCurrent == Content) + else if (w == Content) { if (!Content->Empty()) { @@ -254,7 +254,7 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play) } else { - Song &s = Content->at(Content->Choice()); + const Song &s = Content->Current(); int id = Mpd->AddSong(s); if (id >= 0) { @@ -268,6 +268,6 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play) } FreeSongList(list); if (!add_n_play) - wCurrent->Scroll(wDown); + w->Scroll(wDown); } diff --git a/src/screen.h b/src/screen.h index a757385f..03abbeb6 100644 --- a/src/screen.h +++ b/src/screen.h @@ -29,6 +29,8 @@ class BasicScreen BasicScreen() { } virtual ~BasicScreen() { } + virtual void *&Cmp() = 0; + virtual void Init() = 0; virtual void SwitchTo() = 0; virtual void Resize() = 0; @@ -48,7 +50,9 @@ template class Screen : public BasicScreen Screen() : w(0) { } virtual ~Screen() { } - WindowType *Main(); + virtual void *&Cmp(); + + WindowType *&Main(); virtual void Refresh(); @@ -56,7 +60,13 @@ template class Screen : public BasicScreen WindowType *w; }; -template WindowType *Screen::Main() +template void *&Screen::Cmp() +{ + return *(void **)(void *)&w; +} + + +template WindowType *&Screen::Main() { return w; } diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 79e0e8a4..109dab3d 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -68,14 +68,14 @@ void SearchEngine::SwitchTo() CLEAR_FIND_HISTORY; if (w->Empty()) Prepare(); - wCurrent = w; - wCurrent->Hide(); + myScreen = this; + w->Hide(); current_screen = csSearcher; // redraw_screen = 1; redraw_header = 1; if (!w->Back().first) { - wCurrent->WriteXY(0, 0, 0, "Updating list..."); + w->WriteXY(0, 0, 0, "Updating list..."); UpdateFoundList(); } } diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index d6b282bc..9e4aff3b 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -60,7 +60,7 @@ void TinyTagEditor::Resize() void TinyTagEditor::SwitchTo() { - List *mList = reinterpret_cast *>(wCurrent); + List *mList = reinterpret_cast *>(((Screen *)myScreen)->Main()); size_t id = mList->Choice(); switch (current_screen) { @@ -91,8 +91,8 @@ void TinyTagEditor::SwitchTo() } else if (GetTags()) { - wPrev = wCurrent; - wCurrent = w; + myOldScreen = myScreen; + myScreen = this; prev_screen = current_screen; current_screen = csTinyTagEditor; redraw_header = 1; @@ -221,9 +221,9 @@ void TinyTagEditor::EnterPressed() } else { - if (wPrev == myPlaylist->Main()) + if (myOldScreen == myPlaylist) myPlaylist->Main()->Current() = s; - else if (wPrev == myBrowser->Main()) + else if (myOldScreen == myBrowser) *myBrowser->Main()->Current().song = s; } } @@ -232,8 +232,8 @@ void TinyTagEditor::EnterPressed() } case 15: { - wCurrent->Clear(); - wCurrent = wPrev; + w->Clear(); + myScreen = myOldScreen; current_screen = prev_screen; redraw_header = 1; if (current_screen == csLibrary) @@ -392,7 +392,7 @@ void TagEditor::SwitchTo() { CLEAR_FIND_HISTORY; - myPlaylist->Main()->Hide(); // hack, should be wCurrent, but it doesn't always have 100% width + myPlaylist->Main()->Hide(); // hack, should be myScreen, but it doesn't always have 100% width // redraw_screen = 1; redraw_header = 1; @@ -422,7 +422,7 @@ void TagEditor::SwitchTo() TagTypes->AddOption("lower all letters"); } - wCurrent = w; + myScreen = this; current_screen = csTagEditor; } } @@ -527,7 +527,7 @@ void TagEditor::Update() Tags->Refresh(); } - if (/*redraw_screen && */wCurrent == TagTypes && TagTypes->Choice() < 13) + if (/*redraw_screen && */w == TagTypes && TagTypes->Choice() < 13) { Tags->Refresh(); // redraw_screen = 0; @@ -538,7 +538,7 @@ void TagEditor::Update() void TagEditor::EnterPressed() { - if (wCurrent == Dirs) + if (w == Dirs) { TagList test; Mpd->GetDirectories(LeftColumn->Current().second, test); @@ -595,7 +595,7 @@ void TagEditor::EnterPressed() case 4: get = &Song::GetTrack; set = &Song::SetTrack; - if (wCurrent == TagTypes) + if (w == TagTypes) { LockStatusbar(); Statusbar() << "Number tracks? [y/n] "; @@ -642,14 +642,14 @@ void TagEditor::EnterPressed() break; case 10: { - if (wCurrent == TagTypes) + if (w == TagTypes) { current_screen = csOther; DealWithFilenames(list); current_screen = csTagEditor; TagEditor::Refresh(); } - else if (wCurrent == Tags) + else if (w == Tags) { Song &s = Tags->Current(); string old_name = s.GetNewName().empty() ? s.GetName() : s.GetNewName(); @@ -691,8 +691,8 @@ void TagEditor::EnterPressed() ShowMessage("Tags updated!"); TagTypes->HighlightColor(Config.main_highlight_color); TagTypes->Reset(); - wCurrent->Refresh(); - wCurrent = LeftColumn; + w->Refresh(); + w = LeftColumn; LeftColumn->HighlightColor(Config.active_column_color); Mpd->UpdateDirectory(FindSharedDir(Tags)); } @@ -720,7 +720,7 @@ void TagEditor::EnterPressed() break; } - if (wCurrent == TagTypes && id != 0 && id != 4 && set != NULL) + if (w == TagTypes && id != 0 && id != 4 && set != NULL) { LockStatusbar(); Statusbar() << fmtBold << TagTypes->Current() << fmtBoldEnd << ": "; @@ -729,7 +729,7 @@ void TagEditor::EnterPressed() for (SongList::iterator it = list.begin(); it != list.end(); it++) (**it.*set)(new_tag); } - else if (wCurrent == Tags && set != NULL) + else if (w == Tags && set != NULL) { LockStatusbar(); Statusbar() << fmtBold << TagTypes->Current() << fmtBoldEnd << ": "; @@ -743,11 +743,11 @@ void TagEditor::EnterPressed() void TagEditor::SpacePressed() { - if (wCurrent != LeftColumn) + if (w != LeftColumn) return; Config.albums_in_tag_editor = !Config.albums_in_tag_editor; - wCurrent = w = LeftColumn = Config.albums_in_tag_editor ? Albums : Dirs; + w = LeftColumn = Config.albums_in_tag_editor ? Albums : Dirs; ShowMessage("Switched to %s view", Config.albums_in_tag_editor ? "albums" : "directories"); LeftColumn->Display(); Tags->Clear(0); @@ -756,18 +756,18 @@ void TagEditor::SpacePressed() void TagEditor::NextColumn() { CLEAR_FIND_HISTORY; - if (wCurrent == LeftColumn) + if (w == LeftColumn) { LeftColumn->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = TagTypes; + w = TagTypes; TagTypes->HighlightColor(Config.active_column_color); } - else if (wCurrent == TagTypes && TagTypes->Choice() < 12 && !Tags->Empty()) + else if (w == TagTypes && TagTypes->Choice() < 12 && !Tags->Empty()) { TagTypes->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = myTagEditor->Tags; + w = myTagEditor->Tags; Tags->HighlightColor(Config.active_column_color); } } @@ -775,18 +775,18 @@ void TagEditor::NextColumn() void TagEditor::PrevColumn() { CLEAR_FIND_HISTORY; - if (wCurrent == Tags) + if (w == Tags) { Tags->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = TagTypes; + w = TagTypes; TagTypes->HighlightColor(Config.active_column_color); } - else if (wCurrent == TagTypes) + else if (w == TagTypes) { TagTypes->HighlightColor(Config.main_highlight_color); w->Refresh(); - wCurrent = w = LeftColumn; + w = LeftColumn; LeftColumn->HighlightColor(Config.active_column_color); } } @@ -884,7 +884,7 @@ bool TagEditor::WriteTags(Song &s) locale_to_utf(new_name); if (rename(path_to_file.c_str(), new_name.c_str()) == 0 && !file_is_from_db) { - if (wPrev == myPlaylist->Main()) + if (myOldScreen == myPlaylist) { // if we rename local file, it won't get updated // so just remove it from playlist and add again