示例#1
0
void TabBarElement::mousedown(int mouseButton, int x, int y) {
    TabBarElement *tabBar = this;
    x = tabBar->getAbsoluteBounds() != NULL ? x - tabBar->getAbsoluteBounds()->x : x;
    y = tabBar->getAbsoluteBounds() != NULL ? y - tabBar->getAbsoluteBounds()->y : y;
    FontStyle *font = (FontStyle *)tabBar->getAttributeObj("font");
    int left = 0;
    for(std::vector<Tab *>::iterator it = tabBar->getTabs()->begin(); it != tabBar->getTabs()->end(); ++it) {
        Tab *tab = (Tab *)static_cast<Tab *>(*it);
        string *title = tab->getName();
        string *id = tab->getId();
        string *uri = tab->getUri();
        GraphicsContext *g = tabBar->createGraphics();
        rectangle strSize = g->measureString((char *)title->c_str(), font);
        int width = 20 + 100 + 20;
        if (x > left  && x < left + width) {
            tabBar->activeTab = tab;
            TabBarEventArgs *args = new TabBarEventArgs(tab);
            tabBar->notify(string("tabselected"), (SPType *)tabBar, (EventArgs *)args);
        cout << title->c_str();
            break;
        }

        left += width;
    }
    tabBar->invalidate();
}
示例#2
0
int tabbar_mousedown(SPType *sender, EventArgs *e) {
    TabBarElement *tabBar = (TabBarElement *)sender;
    MouseEventArgs *me = (MouseEventArgs *)e;
    int x = tabBar->getAbsoluteBounds() != NULL ? me->getX() - tabBar->getAbsoluteBounds()->y : me->getX();
    int y = tabBar->getAbsoluteBounds() != NULL ? me->getY() - tabBar->getAbsoluteBounds()->y : me->getY();
    int left = 0;
    ;
    for(std::vector<Tab *>::iterator it = tabBar->tabs->begin(); it != tabBar->tabs->end(); ++it) {
        Tab *tab = (Tab *)dynamic_cast<Tab *>(*it);
        string *title = tab->getName();
        string *id = tab->getId();
        string *uri = tab->getUri();
        FontStyle *font = (FontStyle *)tabBar->getAttributeObj("font");
        GraphicsContext *g = tabBar->createGraphics();
        rectangle strSize = g->measureString((char *)title->c_str(), font);
        int width = 20 + strSize.width + 20;
        if (x > left && x < left + width) {
            tabBar->activeTab = tab;
            TabBarEventArgs *args = new TabBarEventArgs(tab);
            tabBar->notify(string("tabselected"), (SPType *)tabBar, (EventArgs *)args);

        }

        left += width;
    }
    tabBar->invalidate();
}