TBSpaceAllocator::Space *TBSpaceAllocator::GetSmallestAvailableSpace(int needed_w) { assert(needed_w > 0); // Add free space covering all available space if empty. if (!m_free_space_list.HasLinks() && IsAllAvailable()) { if (Space *fs = new Space) { fs->x = 0; fs->width = m_available_space; m_free_space_list.AddLast(fs); } } // Check for the smallest space where we fit Space *best_fs = nullptr; for (Space *fs = m_free_space_list.GetFirst(); fs; fs = fs->GetNext()) { if (needed_w == fs->width) return fs; // It can't be better than a perfect match! if (needed_w < fs->width) if (!best_fs || fs->width < best_fs->width) best_fs = fs; } return best_fs; }
void SjMainFrame::CreateViewMenu(SjMenu* viewMenu, bool createMainMenu, bool appendGotoCurrMark) { bool enableQueue = m_player.m_queue.GetCount()!=0; if( appendGotoCurrMark ) { viewMenu->Append(IDO_GOTO_CURR_MARK); } viewMenu->Append(IDT_GOTO_CURR); viewMenu->Enable(IDT_GOTO_CURR, enableQueue); viewMenu->Append(IDT_WORKSPACE_GOTO_RANDOM); viewMenu->AppendSeparator(); viewMenu->Append(IDT_WORKSPACE_TOGGLE_VIEW); if( createMainMenu || IsOpAvailable(SJ_OP_ZOOM) ) { SjMenu* zoomMenu = new SjMenu(viewMenu->ShowShortcuts()); zoomMenu->Append(IDT_ZOOM_IN); zoomMenu->Append(IDT_ZOOM_OUT); zoomMenu->Append(IDT_ZOOM_NORMAL); zoomMenu->AppendSeparator(); zoomMenu->AppendCheckItem(IDO_SAMEZOOMINALLVIEWS, _("Same zoom in all views")); zoomMenu->Check(IDO_SAMEZOOMINALLVIEWS, (g_accelModule->m_flags&SJ_ACCEL_SAME_ZOOM_IN_ALL_VIEWS)!=0); viewMenu->Append(0, _("Zoom"), zoomMenu); } if( createMainMenu || IsAllAvailable() ) { wxString showCoverText; // default by SjAccelModule if( m_browser->GetView() == SJ_BROWSER_COVER_VIEW ) showCoverText = _("Show album name"); viewMenu->AppendCheckItem(IDT_WORKSPACE_SHOW_COVERS, showCoverText); viewMenu->Check(IDT_WORKSPACE_SHOW_COVERS, m_browser->AreCoversShown()); } viewMenu->Append(IDT_TOGGLE_TIME_MODE, m_showRemainingTime? _("Show elapsed time") : _("Show remaining time")); viewMenu->Enable(IDT_TOGGLE_TIME_MODE, enableQueue); if( createMainMenu || !IsKioskStarted() ) { viewMenu->AppendSeparator(); viewMenu->AppendCheckItem(IDT_ALWAYS_ON_TOP); viewMenu->Check(IDT_ALWAYS_ON_TOP, IsAlwaysOnTop()); } viewMenu->AppendSeparator(); // add vis. toggle if( g_visModule ) { viewMenu->AppendCheckItem(IDT_START_VIS, _("Video screen")); viewMenu->Check(IDT_START_VIS, g_visModule->IsVisStarted()); } }
bool TBSpaceAllocator::HasSpace(int needed_w) const { if (needed_w > m_available_space) return false; if (IsAllAvailable()) return true; for (Space *fs = m_free_space_list.GetFirst(); fs; fs = fs->GetNext()) { if (needed_w <= fs->width) return true; } return false; }
void SjMainFrame::OnSkinDisplayEvent(int targetId, SjSkinValue& value, long accelFlags) { if( targetId >= IDT_DISPLAY_LINE_FIRST && targetId <= IDT_DISPLAY_LINE_LAST ) { long displayLine = targetId-IDT_DISPLAY_LINE_FIRST; GotDisplayInputFromUser(); if( !m_display.m_msg1.IsEmpty() ) { ClearDisplayMsg(); return; } long queuePos = m_display.m_firstLineQueuePos + displayLine; if( queuePos >= 0 && queuePos < m_player.m_queue.GetCount() ) { if( value.value == SJ_SUBITEM_ICONRIGHT && IsOpAvailable(SJ_OP_UNQUEUE) ) { UnqueueByPos(queuePos); } else if( value.value == SJ_SUBITEM_ICONLEFT ) { if( m_player.m_queue.GetCurrPos() == queuePos ) { if( IsOpAvailable(SJ_OP_PLAYPAUSE) ) { PlayOrPause(accelFlags != 0); } } else if( m_player.m_queue.WasPlayed(queuePos) ) { if( IsOpAvailable(SJ_OP_EDIT_QUEUE) ) { m_player.m_queue.ResetPlayCount(queuePos); UpdateDisplay(); } } } else if( value.value == SJ_SUBITEM_TEXT_DCLICK && IsOpAvailable(SJ_OP_EDIT_QUEUE) ) { #ifdef DEBUG_DISPLAY SjPlaylistEntry& urlInfo = m_player.m_queue.GetInfo(queuePos); wxLogDebug("Line pos. %i: %s - %s", (int)queuePos, urlInfo.GetLeadArtistName().c_str(), urlInfo.GetTrackName().c_str()); #endif if( m_player.m_queue.GetCurrPos() == queuePos && IsPlaying() ) { ; // PlayOrPause(); // better do nothing } else { m_player.GotoAbsPos(queuePos, accelFlags!=0); if( !IsPlaying() ) { Play(); UpdateDisplay(); } } } else if( (value.value == SJ_SUBITEM_TEXT_MOUSEDOWN || value.value == SJ_SUBITEM_TEXT/*_MOUSEUP*/ ) && IsOpAvailable(SJ_OP_EDIT_QUEUE) ) { MarkDisplayTrack(targetId, value.value == SJ_SUBITEM_TEXT_MOUSEDOWN, value.vmin); } else if( value.value == SJ_SUBITEM_TEXT_MIDDLECLICK ) { if( g_accelModule->m_middleMouseAction ) { long queueId = m_player.m_queue.GetIdByPos(queuePos); if( queueId == 0 ) { return; } if( !m_display.m_selectedIds.Lookup(queueId) ) { // mark the item under the mouse if it is not marked m_display.m_selectedIds.Clear(); m_display.m_selectedIds.Insert(queueId, 1); m_display.m_selectedAnchorId = queueId; UpdateDisplay(); } m_display.m_selectedIdsTimestamp = SjTools::GetMsTicks(); m_display.m_selectedIdsLockMs = SJ_DISPLAY_SELECTION_LOCK_MS; m_contextMenuClickedUrls = m_player.m_queue.GetUrlsByIds(m_display.m_selectedIds); m_contextMenuClickedId = queueId; switch( g_accelModule->m_middleMouseAction ) { case SJ_ACCEL_MID_OPENS_TAG_EDITOR: if( IsAllAvailable() ) { g_tagEditorModule->OpenTagEditor(new SjDisplayEditDlg()); } break; } } } } else { // click on empty line; remove all marks m_display.m_selectedIds.Clear(); m_display.m_selectedAnchorId = 0; UpdateDisplay(); } } else switch( targetId ) { // curr / next tracks case IDT_CURR_TRACK: if( value.value == SJ_SUBITEM_TEXT_DCLICK && !IsStopped() && IsPaused() && IsOpAvailable(SJ_OP_PLAYPAUSE) ) { Play(); UpdateDisplay(); } break; case IDT_NEXT_TRACK: if( value.value == SJ_SUBITEM_TEXT_DCLICK && !IsStopped() && !GetShuffle() && HasNextIgnoreAP() && IsOpAvailable(SJ_OP_EDIT_QUEUE) ) { GotoNextRegardAP(accelFlags!=0); if( !IsPlaying() ) Play(); UpdateDisplay(); } break; // main volume case IDT_MAIN_VOL_UP: case IDT_MAIN_VOL_DOWN: if( IsOpAvailable(SJ_OP_MAIN_VOL) ) { SetRelMainVol(targetId==IDT_MAIN_VOL_UP? 8 : -8); SetSkinTargetValue(IDT_MAIN_VOL_MUTE, m_player.GetMainVolMute()? 1 : 0); // maybe later -- SetDisplayMsg(_("Volume")+wxString::Format(": %i%%", (m_player.GetMainVolume()*100)/255), SDM_STATE_CHANGE_MS); } break; case IDT_MAIN_VOL_SLIDER: if( IsOpAvailable(SJ_OP_MAIN_VOL) ) { SetAbsMainVol(value.value); SetSkinTargetValue(IDT_MAIN_VOL_MUTE, m_player.GetMainVolMute()? 1 : 0); // maybe later -- SetDisplayMsg(_("Volume")+wxString::Format(": %i%%", (m_player.GetMainVolume()*100)/255), SDM_STATE_CHANGE_MS); } break; case IDT_MAIN_VOL_MUTE: if( IsOpAvailable(SJ_OP_MAIN_VOL) ) { m_player.ToggleMainVolMute(); UpdateDisplay(); } break; // seek case IDT_SEEK: if( IsOpAvailable(SJ_OP_EDIT_QUEUE) ) { SjPlayer* recentPlayer = &g_mainFrame->m_player; recentPlayer->SeekAbs(value.value*SJ_SEEK_RESOLUTION); UpdateDisplay(); } break; case IDT_SEEK_BWD: case IDT_SEEK_FWD: if( IsOpAvailable(SJ_OP_EDIT_QUEUE) ) { SjPlayer* recentPlayer = &g_mainFrame->m_player; recentPlayer->SeekRel(targetId==IDT_SEEK_BWD? -5000 : 5000); UpdateDisplay(); } break; // misc. case IDO_DISPLAY_COVER_EXPLR: { SjPlayer* recentPlayer = &g_mainFrame->m_player; g_tools->ExploreUrl(m_columnMixer.GetTrackCoverUrl(recentPlayer->m_queue.GetUrlByPos(-1))); } break; case IDT_DISPLAY_COVER: case IDO_DISPLAY_COVER: // IDO_DISPLAY_COVER is only used for the menu item if( value.value == SJ_SUBITEM_TEXT_DCLICK || (value.value == SJ_SUBITEM_TEXT_MIDDLECLICK && g_accelModule->m_middleMouseAction==SJ_ACCEL_MID_OPENS_TAG_EDITOR) || targetId != IDT_DISPLAY_COVER ) { // open the cover editor for the display cover SjPlayer* recentPlayer = &g_mainFrame->m_player; wxString trackUrl = recentPlayer->m_queue.GetUrlByPos(-1); wxSqlt sql; sql.Query(wxT("SELECT albumid FROM tracks WHERE url='") + sql.QParam(trackUrl) + wxT("';")); unsigned long albumId = sql.Next()? sql.GetLong(0) : 0; wxString selArtUrl = m_columnMixer.GetTrackCoverUrl(recentPlayer->m_queue.GetUrlByPos(-1)); wxArrayLong artIds; wxArrayString artUrls; g_mainFrame->m_libraryModule->GetPossibleAlbumArts(albumId, artIds, &artUrls, true/*addAutoCover*/); g_artEditorModule->OnArtMenu(g_mainFrame, artUrls, selArtUrl, albumId, IDM_OPENARTEDITOR, NULL, true /*IsPlaylistCover*/ ); /* // simulate a double click on the cover row or explore the cover url long index, r; SjCol* col = m_columnMixer.GetMaskedCol(recentPlayer->m_queue.GetUrlByPos(recentPlayer->m_queue.GetCurrPos()), index); SjAlbumCoverRow* row; if( col ) { for( r = 0; r < col->m_rowCount; r++ ) { if( col->m_rows[r]->m_roughType == SJ_RRTYPE_COVER ) { row = (SjAlbumCoverRow*)col->m_rows[r]; row->IsPlaylistCover(true); // if set to true, "follow playlist" is always active row->OnMiddleClick(false); break; } } delete col; } */ } break; case IDT_DISPLAY_UP: GotDisplayInputFromUser(); if( m_display.m_scrollPos == -1 ) { m_display.m_scrollPos = GetQueuePos(); } if( m_display.m_scrollPos >= 1 ) { m_display.m_scrollPos--; UpdateDisplay(); } break; case IDT_DISPLAY_DOWN: GotDisplayInputFromUser(); if( m_display.m_scrollPos == -1 ) { m_display.m_scrollPos = GetQueuePos(); } m_display.m_scrollPos++; // corrected in UpdateDisplay() UpdateDisplay(); break; case IDT_DISPLAY_V_SCROLL: GotDisplayInputFromUser(); m_display.m_scrollPos = value.value; UpdateDisplay(); break; } }
void SjMainFrame::OnSkinTargetContextMenu(int targetId, long x, long y) { SjMenu mainMenu(0); int idtSettings = IDT_SETTINGS_JUKEBOX; bool appendGotoCurrMark = FALSE; bool prependOpen = TRUE; bool embedFastSearch = FALSE; long unmarkQueueId = 0; m_display.m_tagEditorJustOpened = FALSE; GotInputFromUser(); m_contextMenuClickedUrls.Clear(); m_contextMenuClickedId = 0; if( (targetId>=IDT_DISPLAY_LINE_FIRST && targetId<=IDT_DISPLAY_LINE_LAST) || targetId==IDT_CURR_TRACK || targetId==IDT_NEXT_TRACK ) { // queue menu items if( IsAllAvailable() && (targetId==IDT_CURR_TRACK || targetId==IDT_NEXT_TRACK) ) { if( targetId==IDT_CURR_TRACK || targetId==IDT_NEXT_TRACK ) { long queuePos = m_player.m_queue.GetCurrPos()+(targetId==IDT_NEXT_TRACK?1:0); if( !IsStopped() && queuePos >= 0 && queuePos < m_player.m_queue.GetCount() ) { if( targetId==IDT_CURR_TRACK || !GetShuffle() ) { m_contextMenuClickedUrls.Add(m_player.m_queue.GetUrlByPos(queuePos)); m_contextMenuClickedId = m_player.m_queue.GetIdByPos(queuePos); m_display.m_selectedIds.Clear(); m_display.m_selectedIds.Insert(m_contextMenuClickedId, 1); m_display.m_selectedIdsTimestamp = SjTools::GetMsTicks(); m_display.m_selectedIdsLockMs = 60*60*1000; // long enough, i think after one hour, the context menu should be closed unmarkQueueId = m_contextMenuClickedId; UpdateDisplay(); } } } else { long trackCount = m_player.m_queue.GetCount(); if( trackCount > 0 ) { // mark the line under the mouse if it is not marked long queuePos = m_display.m_firstLineQueuePos + (targetId-IDT_DISPLAY_LINE_FIRST); if( queuePos >= 0 && queuePos < m_player.m_queue.GetCount() ) { m_contextMenuClickedId = m_player.m_queue.GetIdByPos(queuePos); if( m_contextMenuClickedId != 0 ) { if( m_display.m_selectedIds.Lookup(m_contextMenuClickedId) == 0 ) { m_display.m_selectedIds.Clear(); m_display.m_selectedIds.Insert(m_contextMenuClickedId, 1); m_display.m_selectedIdsTimestamp = SjTools::GetMsTicks(); m_display.m_selectedIdsLockMs = 60*60*1000; // long enough, i think after one hour, the context menu should be closed unmarkQueueId = m_contextMenuClickedId; UpdateDisplay(); } } } m_contextMenuClickedUrls = m_player.m_queue.GetUrlsByIds(m_display.m_selectedIds); appendGotoCurrMark = TRUE; } } long markedCount = m_contextMenuClickedUrls.GetCount(); CreateUnqueueMenu(mainMenu); mainMenu.AppendSeparator(); mainMenu.Append(IDO_EDITQUEUE, _("Edit tracks/Get info")+wxString(wxT("..."))); mainMenu.Enable(IDO_EDITQUEUE, (markedCount>0)); m_libraryModule->CreateRatingMenu(mainMenu, IDO_RATINGQUEUE00, m_contextMenuClickedUrls); m_libraryModule->CreateArtistInfoMenu(mainMenu, IDO_ARTISTINFQUEUE00, m_contextMenuClickedUrls); mainMenu.Append(IDO_EXPLOREQUEUE, _("Show file")); mainMenu.Enable(IDO_EXPLOREQUEUE, (markedCount==1)); } } else { switch( targetId ) { case IDT_DISPLAY_COVER: if( m_player.m_queue.GetCount() ) { mainMenu.Append(IDO_DISPLAY_COVER, _("Cover editor")); if( IsAllAvailable() ) { mainMenu.Append(IDO_DISPLAY_COVER_EXPLR, _("Show file")); } } break; case IDT_OPEN_FILES: case IDT_APPEND_FILES: case IDT_SAVE_PLAYLIST: case IDT_UNQUEUE_ALL: case IDT_DISPLAY_UP: case IDT_DISPLAY_DOWN: case IDT_DISPLAY_V_SCROLL: CreateUnqueueMenu(mainMenu); break; case IDT_SEARCH: case IDT_SEARCH_BUTTON: case IDT_SEARCH_INFO: // "Search" menu prependOpen = FALSE; if( IsAllAvailable() ) { embedFastSearch = TRUE; } else { CreateSearchMenu(mainMenu); } break; } } CreateContextMenu_(mainMenu, prependOpen, idtSettings, appendGotoCurrMark, embedFastSearch); if( targetId == IDT_MAINMENU && !IsKioskStarted() ) { mainMenu.AppendSeparator(); mainMenu.Append(IDT_QUIT); } if( mainMenu.GetMenuItemCount() ) { PopupMenu(&mainMenu, x, y); } if( unmarkQueueId && !m_display.m_tagEditorJustOpened ) // if the tag editor is opened in between, the marked tracks in the display should stay { m_display.m_selectedIds.Remove(unmarkQueueId); UpdateDisplay(); } }
void SjMainFrame::CreateContextMenu_(SjMenu& mainMenu, bool prependOpen, int idmSettings, bool appendGotoCurrMark, bool embedFastSearch) { // prepend open/save items (reverse order!) /* -- as we have a normal menu bar since 15.1, the context menu can be more focused if( prependOpen && IsAllAvailable() ) { if( mainMenu.GetMenuItemCount() ) { mainMenu.InsertSeparator(0); } bool enableQueue = m_player.m_queue.GetCount()!=0; mainMenu.Insert(0, IDT_UNQUEUE_ALL); mainMenu.Enable(IDT_UNQUEUE_ALL, enableQueue); mainMenu.Insert(0, IDT_SAVE_PLAYLIST); mainMenu.Enable(IDT_SAVE_PLAYLIST, enableQueue); mainMenu.Insert(0, IDT_OPEN_FILES); } */ // search // -- as we have a normal menu bar since 15.1, the context menu can be more focused (search only added if embedFastSearch set, formally this was always the case) if( embedFastSearch && IsOpAvailable(SJ_OP_SEARCH) ) { // open adv. search dialog if( mainMenu.GetMenuItemCount() ) { mainMenu.AppendSeparator(); } if( IsAllAvailable() ) { mainMenu.Append(IDT_ADV_SEARCH); } // "fast search" if( embedFastSearch ) { CreateSearchMenu(mainMenu); } // end search mainMenu.Append(IDO_REALLYENDSEARCH, _("End search")); mainMenu.Enable(IDO_REALLYENDSEARCH, HasAnySearch()); } // settings / view / control /* -- as we have a normal menu bar since 15.1, the context menu can be more focused if( IsAllAvailable() ) { // seperator abottom (sth. will follow in any case, at least "Go to random album") if( mainMenu.GetMenuItemCount() ) { mainMenu.AppendSeparator(); } // settings mainMenu.Append(idmSettings); // view menu SjMenu* viewMenu = new SjMenu(mainMenu.ShowShortcuts()); CreateViewMenu(viewMenu, false, appendGotoCurrMark); mainMenu.Append(0, _("View"), viewMenu); // control menu SjMenu* playbackMenu = new SjMenu(mainMenu.ShowShortcuts()); CreatePlaybackMenu(playbackMenu, false); mainMenu.Append(0, _("Playback"), playbackMenu); } */ // help if( IsKioskStarted() ) { mainMenu.Append(IDO_ABOUT, wxString::Format(_("About %s"), SJ_PROGRAM_NAME)+wxString(wxT("..."))); } }