Created
February 13, 2012 01:44
-
-
Save openglx/1812531 to your computer and use it in GitHub Desktop.
MyImageMenuItem extending WMenu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*****************************************************************************/ | |
/* my implementation of WMenu using thumbnail images as link */ | |
class MyImageMenuItem : public Wt::WMenuItem | |
{ | |
public: | |
MyImageMenuItem(Wt::WImage* img, Wt::WWidget *contents, | |
Wt::WMenuItem::LoadPolicy policy = Wt::WMenuItem::LazyLoading); | |
protected: | |
void updateItemWidget(Wt::WWidget *itemWidget); | |
Wt::WWidget *createItemWidget(); | |
private: | |
Wt::WImage* img_; | |
}; | |
MyImageMenuItem::MyImageMenuItem(Wt::WImage* img, Wt::WWidget *contents, | |
Wt::WMenuItem::LoadPolicy policy) | |
: Wt::WMenuItem("", contents, policy), | |
img_(0) | |
{ | |
img_ = img; | |
} | |
Wt::WWidget *MyImageMenuItem::createItemWidget() | |
{ | |
Wt::WContainerWidget *contents = new Wt::WContainerWidget(); | |
Wt::WAnchor *anchor = new Wt::WAnchor(); | |
contents->addWidget(anchor); | |
anchor->setImage(img_); | |
img_->setAlternateText(text()); | |
return contents; | |
} | |
void MyImageMenuItem::updateItemWidget(Wt::WWidget *itemWidget) | |
{ | |
Wt::WContainerWidget *contents = dynamic_cast<Wt::WContainerWidget *>(itemWidget); | |
Wt::WWidget *anchor = contents->widget(0); | |
Wt::WMenuItem::updateItemWidget(anchor); | |
} | |
/*****************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment