TrayApp.cpp

A small example Application.

00001 #include "fx.h"
00002 
00003 #include "FXTrayIcon.h"
00004 
00005 #include <memory>
00006 using namespace std;
00007 
00008 #include "tray_icon1.xpm"
00009 #include "tray_icon2.xpm"
00010 
00011 /*
00012  * Create a class derrived from FXObject to handle messages sent by
00013  * FXTrayIcon. You can use also derrive from FXTopWindow for example
00014  */
00015 class TrayApp : public FXObject
00016 {
00017     FXDECLARE(TrayApp)
00018 public:
00019     enum {
00020         ID_HELLO = FXApp::ID_LAST,
00021         ID_LAST
00022     };
00023 
00024     TrayApp(FXApp* app);
00025 
00026     long onHello(FXObject* sender, FXSelector sel, void*);
00027 private:
00028     TrayApp() {}
00029 
00030     auto_ptr<FXIcon> mIcon1;
00031     auto_ptr<FXIcon> mIcon2;
00032     auto_ptr<FXPopup> mPup;
00033     FXTrayIcon* mTray;
00034 
00035     FXApp* mApp;
00036 };
00037 
00038 FXDEFMAP(TrayApp) TrayAppMap[] = {
00039     FXMAPFUNC(SEL_COMMAND, TrayApp::ID_HELLO, TrayApp::onHello)
00040 };
00041 
00042 FXIMPLEMENT(TrayApp, FXObject, TrayAppMap, ARRAYNUMBER(TrayAppMap))
00043 
00044 TrayApp::TrayApp(FXApp* app) :
00045     mApp(app)
00046 {
00047     // Create the icon
00048     mIcon1 = auto_ptr<FXXPMIcon> (new FXXPMIcon(app, 
00049             const_cast<const FXchar**>(tray_icon1_xpm)) );
00050 
00051     mIcon2 = auto_ptr<FXXPMIcon> (new FXXPMIcon(app,
00052             const_cast<const FXchar**>(tray_icon2_xpm)) );
00053 
00054     // create the tray icon
00055     // it will open a popup menu on right click and send SEL_COMMAND
00056     // on left click
00057     mTray = new FXTrayIcon(app, "Tray Test", mIcon1.get(),
00058             0, this, TrayApp::ID_HELLO, TRAY_CMD_ON_LEFT|TRAY_MENU_ON_RIGHT);
00059 
00060     // create the popup menu
00061     mPup = auto_ptr<FXPopup> (new FXPopup(mTray));
00062     new FXMenuCommand(mPup.get(), "Hello", 0, this, TrayApp::ID_HELLO);
00063     new FXMenuSeparator(mPup.get() );
00064     new FXMenuCommand(mPup.get(), "E&xit", 0, mApp, FXApp::ID_QUIT);
00065     mTray->setMenu(mPup.get());
00066 }
00067 
00068 long TrayApp::onHello(FXObject* sender, FXSelector sel, void*)
00069 {
00070     static int clickCount = 0;
00071     clickCount++;
00072 
00073     // ensure the Icon is created
00074     mIcon2->create();
00075     mTray->setIcon(mIcon2.get() );
00076 
00077     FXMessageBox::information(mApp, MBOX_OK, "Tray Test", "Hello World!");
00078 
00079     mTray->setIcon(mIcon1.get() );
00080 
00081     // update the click count
00082     FXString text("Clicked: ");
00083     text += FXStringVal(clickCount) + " times";
00084     mTray->setText(text);
00085 
00086     return 1;
00087 }
00088 
00089 int main(int argc, char* argv[])
00090 {
00091     FXTrayApp app;
00092     app.init(argc, argv);
00093 
00094     TrayApp tray_app(&app);
00095 
00096     app.create();
00097 
00098     return app.run();
00099 }
00100 
00101 

Generated on Sat Oct 18 14:30:53 2008 for FoxTray by  doxygen 1.5.1