void Book::onKeyPressed(Widget& widgeth, input::Key key, bool pressed) { if (!pressed) return; auto p = std::find(pages.begin(), pages.end(), activePage); if (p == pages.end()) return; switch (key) { case input::KEY_TAB: case input::KEY_RIGHT: { if (++p == pages.end()) setActivePage(pages.front(), true); else setActivePage(*p, true); break; } case input::KEY_LEFT: { if (p == pages.begin()) setActivePage(pages.back(), true); else setActivePage(*(--p), true); break; } default: break; } }
void Book::removedChild(Widget& child) { if (Page* page = dynamic_cast<Page*>(&child)) { if (page == activePage) { if (pages.empty()) setActivePage(NULL, false); else setActivePage(pages.front(), false); } pages.erase(std::find(pages.begin(), pages.end(), page)); } }
bool HsScene::setActivePageIndex(int index) { if (index < 0 || mPages.count() <= index) { return false; } return setActivePage(mPages[index]); }
void KPrView::startPresentationFromBeginning() { KPrDocument * doc = dynamic_cast<KPrDocument *>( kopaDocument() ); QList<KoPAPageBase*> slideshow = doc->slideShow(); if ( !slideshow.isEmpty() ) { setActivePage( slideshow.first() ); } startPresentation(); }
// --------------------------------------------------------------------------- // Name: afGlobalSettingsDialog::showDialog // Description: Show the dialog // Author: Uri Shomroni // Date: 19/4/2012 // --------------------------------------------------------------------------- void afGlobalSettingsDialog::showDialog(const gtString& extensionActivePageName) { initDialogGlobalSettings(); // Select the General page: m_pMainTabWidget->setCurrentIndex(0); setActivePage(extensionActivePageName); afApplicationCommands::instance()->showModal(this); }
void TabControl::setActivePage_ID(int32 id) { for (size_t x=0; x<m_vTabInfo.size(); x++) { if (m_vTabInfo[x] && m_vTabInfo[x]->GetId() == id) { setActivePage((uint32)x); break; } } }
void Book::onButtonClicked(Widget& widget, const vec2& point, input::Button button, bool clicked) { const float position = transformToLocal(point).x; const float width = getWidth() / pages.size(); const uint index = (uint) (position / width); if (pages[index] != activePage) setActivePage(pages[index], true); }
void DesuraControl::setActivePage_ID(int32 id) { if (id == 0) return; for (size_t x=0; x<m_vTabInfo.size(); x++) { if (m_vTabInfo[x] && m_vTabInfo[x]->id == id) { setActivePage((PAGE)x); break; } } }
/** * Creates a new stack page that holds the given widget. * @param widget The widget to add */ void StackWidget::addWidget(QWidget* widget) { // Create a new page. StackPage* page = new StackPage(widget, this); pageList_.append(page); connect(page, SIGNAL(activated(StackPage*)), this, SLOT(setActivePage(StackPage*))); connect(page, SIGNAL(removed(StackPage*)), this, SLOT(removePage(StackPage*))); // Show the page and make it the active one. layout_->addWidget(page); page->show(); setActivePage(page); }
void Book::addedChild(Widget& child) { if (Page* page = dynamic_cast<Page*>(&child)) { const float em = getLayer().getDrawer().getCurrentEM(); const vec2& size = getSize(); page->setArea(Rect(0.f, 0.f, size.x, size.y - em * 2.f)); if (activePage) page->hide(); else setActivePage(page, false); pages.push_back(page); } }
void doTest(void) { int p, x, y, pages; /* This is the way to calculate the number of pages available. */ pages = 65536L/(widthBytes*height); for (p = 0; p < pages; ++p) { setActivePage(p); /* On each page draw a single colored border, and dump the palette onto a small square about the middle of the page. */ for (x = 0; x <= width; ++x) { putPixel_X(x, 0, p+1); putPixel_X(x, height-1, p+1); } for (y = 0; y <= height; ++y) { putPixel_X(0, y, p+1); putPixel_X(width-1, y, p+1); } for (x = 0; x < 16; ++x) for (y = 0; y < 16; ++y) putPixel_X(x+(p+3)*16, y+(p+3)*16, x + y*16); } /* Each pages will now contain a different image. Let the user cycle through all the pages by pressing a key. */ for (p = 0; p < pages; ++p) { setVisiblePage(p); getch(); } }
void Book::setActivePage(Page* newPage) { setActivePage(newPage, false); }
/********************************************************************* * @fn compactPage * * @brief Compacts the page specified. * * @param srcPg - Valid NV page to compact from. * The page must have changed its state (header) to xfer state * prior to this function call. This function will not * modify the state of its header to xfer state before starting * to compact. * * @return none. */ static void compactPage( uint8 srcPg ) { uint16 srcOff, dstOff; uint8 dstPg; osalSnvId_t lastId = (osalSnvId_t) 0xFFFF; dstPg = (srcPg == OSAL_NV_PAGE_BEG)? OSAL_NV_PAGE_END : OSAL_NV_PAGE_BEG; dstOff = OSAL_NV_PAGE_HDR_SIZE; // Read from the latest value srcOff = pgOff - sizeof(osalNvItemHdr_t); while (srcOff >= OSAL_NV_PAGE_HDR_SIZE) { osalNvItemHdr_t hdr; if (failF) { // Failure during transfer item will make next findItem error prone. return; } HalFlashRead(srcPg, srcOff, (uint8 *) &hdr, OSAL_NV_WORD_SIZE); if (hdr.id == 0xFFFF) { // Invalid entry. Skip this one. if (hdr.len & OSAL_NV_INVALID_LEN_MARK) { srcOff -= OSAL_NV_WORD_SIZE; } else { if (hdr.len + OSAL_NV_WORD_SIZE <= srcOff) { srcOff -= hdr.len + OSAL_NV_WORD_SIZE; } else { // invalid length. Source page must be a corrupt page. // This is possible only if the NV initialization failed upon erasing // what is selected as active page. // This is supposed to be a very rare case, as power should be // shutdown exactly during erase and then the page header is // still retained as either the Xfer or the Active state. // For production code, it might be useful to attempt to erase the page // so that at next power cycle at least the device is runnable // (with all entries removed). // However, it might be still better not to attempt erasing the page // just to see if this very rare case actually happened. //erasePage(srcPg); HAL_ASSERT_FORCED(); return; } } continue; } // Consider only valid item if (!(hdr.id & OSAL_NV_INVALID_ID_MARK) && hdr.id != lastId) { // lastId is used to speed up compacting in case the same item ID // items were neighboring each other contiguously. lastId = (osalSnvId_t) hdr.id; // Check if the latest value of the item was already written if (findItem(dstPg, dstOff, lastId) == 0) { // This item was not copied over yet. // This must be the latest value. // Write the latest value to the destination page xferItem(dstPg, dstOff, hdr.len, srcOff - hdr.len); dstOff += hdr.len + OSAL_NV_WORD_SIZE; } } srcOff -= hdr.len + OSAL_NV_WORD_SIZE; } // All items copied. // Activate the new page setActivePage(dstPg); if (!failF) { pgOff = dstOff; // update active page offset } // Erase the currently active page erasePage(srcPg); }
/********************************************************************* * @fn initNV * * @brief Initialize the NV flash pages. * * @param none * * @return TRUE if initialization succeeds. FALSE, otherwise. */ static uint8 initNV( void ) { uint32 pgHdr; uint8 xferPg = OSAL_NV_PAGE_NULL; uint8 pg; failF = FALSE; activePg = OSAL_NV_PAGE_NULL; // Pick active page and clean up erased page if necessary for ( pg = OSAL_NV_PAGE_BEG; pg <= OSAL_NV_PAGE_END; pg++ ) { HalFlashRead(pg, OSAL_NV_PAGE_HDR_OFFSET, (uint8 *)(&pgHdr), OSAL_NV_PAGE_HDR_SIZE); if ( pgHdr == OSAL_NV_ACTIVE_PAGE_STATE) { if (activePg != OSAL_NV_PAGE_NULL) { // Both pages are active only when power failed during flash erase and // with very low probability. // As it is hard (code size intensive) to figure out which page is the real active page, // and theoretically impossible as well in lowest probability, erase both pages // in this case cleanErasedPage(activePg); cleanErasedPage(pg); activePg = OSAL_NV_PAGE_NULL; } else { activePg = pg; } } else if ( pgHdr == OSAL_NV_XFER_PAGE_STATE) { xferPg = pg; } else { // Erase this page if it is not erased. // This is to ensure that any page that were in the middle of // compacting gets erased. cleanErasedPage(pg); } } if (activePg == OSAL_NV_PAGE_NULL) { if (xferPg == OSAL_NV_PAGE_NULL) { // Both pages are erased. This must be initial state. // Pick one page as active page. setActivePage(OSAL_NV_PAGE_BEG); pgOff = OSAL_NV_PAGE_HDR_SIZE; // If setting active page from a completely erased page failed, // it is not recommended to operate any further. // Other cases, even if non-active page is corrupt, NV module can still read // the active page content and hence this function could return TRUE. return (!failF); } else { // Compacting a page hasn't completed in previous power cycle. // Complete the compacting. activePg = xferPg; findOffset(); compactPage(xferPg); } } else { if (xferPg != OSAL_NV_PAGE_NULL) { // Compacting has completed except for the final step of erasing // the xferPage. erasePage(xferPg); } // find the active page offset to write a new variable location item findOffset(); } return TRUE; }