include/GUI/components/BrowserBar.hpp

Go to the documentation of this file.
00001 #ifndef hpp_CPP_BrowserBar_CPP_hpp
00002 #define hpp_CPP_BrowserBar_CPP_hpp
00003 
00004 // We need our declaration
00005 #include "../UZIBase.hpp"
00006 // We need icons
00007 #include "Resources/Icons.hpp"
00008 // We need URL change updater
00009 #include "../URLChangeUpdater.hpp"
00010 
00011 namespace juce
00012 {
00016     class BrowserBar : public Component, ComboBoxListener
00017     {
00018         // Members
00019     private:
00021         Toolbar* toolbar;
00023         URLChangeUpdate * urlUpdater;
00024 
00025         // Construction / Destruction
00026     public:
00028         BrowserBar (ApplicationCommandManager* commandManager, const String & homeURL) : urlUpdater(0)
00029         {
00030             // Create and add the toolbar...
00031             addAndMakeVisible (toolbar = new Toolbar());
00032 
00033             factory.setComboBoxListener(this);
00034             factory.setHomeURL(homeURL);
00035             // And use our item factory to add a set of default icons to it...
00036             toolbar->addDefaultItems (factory);
00037         }
00039         ~BrowserBar()    { deleteAllChildren(); }
00040 
00041         // Juce interface
00042     public:
00044         void resized()
00045         {
00046             toolbar->setBounds (0, 0, getWidth(), getHeight());
00047         }
00048 
00050         virtual void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
00051         {
00052             if (comboBoxThatHasChanged && urlUpdater)
00053                 urlUpdater->UpdateURL(comboBoxThatHasChanged->getText());
00054         }
00055 
00057         void setUpdater(URLChangeUpdate * _urlUpdater) { urlUpdater = _urlUpdater; }
00058 
00059 
00060         // Inner factory
00061     public:
00062         //==============================================================================
00063         class BrowserItemFactory : public ToolbarItemFactory
00064         {
00065             // Construction / Destruction
00066         public:
00068             BrowserItemFactory() : listener(0) {}
00070             ~BrowserItemFactory() {}
00071 
00072             // Enumerations
00073         public:
00076             enum BrowserItemIds
00077             {
00078                 Previous         = 1,   
00079                 Next             = 2,   
00080                 URLBar           = 3,   
00081                 Go               = 4,   
00082             };
00083 
00084             // ToolbarItemFactory interface
00085         public:
00087             void getAllToolbarItemIds (Array <int>& ids)
00088             {
00089                 // This returns the complete list of all item IDs that are allowed to
00090                 // go in our toolbar. Any items you might want to add must be listed here. The
00091                 // order in which they are listed will be used by the toolbar customisation panel.
00092                 ids.add (Previous);
00093                 ids.add (Next);
00094                 ids.add (URLBar);
00095                 ids.add (Go);
00096                 // If you're going to use separators, then they must also be added explicitly
00097                 // to the list.
00098                 ids.add (separatorBarId);
00099                 ids.add (spacerId);
00100                 ids.add (flexibleSpacerId);
00101             }
00102 
00104             void getDefaultItemSet (Array <int>& ids)
00105             {
00106                 // This returns an ordered list of the set of items that make up a
00107                 // toolbar's default set. Not all items need to be on this list, and
00108                 // items can appear multiple times (e.g. the separators used here).
00109                 ids.add (Previous);
00110                 ids.add (Next);
00111                 ids.add (separatorBarId);
00112                 ids.add (URLBar);
00113                 ids.add (spacerId);
00114                 ids.add (separatorBarId);
00115                 ids.add (Go);
00116             }
00117 
00119             ToolbarItemComponent* createItem (const int itemId)
00120             {
00121                 switch (itemId)
00122                 {
00123                 case Previous:
00124                     return createButton (itemId, JUCE_T("Previous"));
00125 
00126                 case Next:
00127                     return createButton (itemId, JUCE_T("Next"));
00128 
00129                 case URLBar:
00130                     return new URLBarComboBox  (itemId, listener, homeURL);
00131 
00132                 case Go:
00133                     return createButton (itemId, JUCE_T("Go"));
00134 
00135                 default:
00136                     break;
00137                 }
00138 
00139                 return 0;
00140             }
00141 
00142             void setComboBoxListener(ComboBoxListener * _listener) { listener = _listener; }
00143             void setHomeURL(const String & url) { homeURL = url; }
00144 
00145         private:
00146             OwnedArray <Drawable> icons;
00147 
00148             // This is a little utility to create a button with one of the SVG images in
00149             // our embedded ZIP file "icons.zip"
00150             ToolbarButton* createButton (const int itemId, const String& text)
00151             {
00152                 if (!icons.size())
00153                 {
00154                     icons.add(Drawable::createFromImageData(ScalableIcons::previous_svg, ScalableIcons::previous_svgSize));
00155                     icons.add(Drawable::createFromImageData(ScalableIcons::next_svg, ScalableIcons::next_svgSize));
00156                     icons.add(Drawable::createFromImageData(ScalableIcons::go_svg, ScalableIcons::go_svgSize));
00157                 }
00158                 switch (itemId)
00159                 {
00160                 case Previous:
00161                     {
00162                         Drawable * image = icons[0]->createCopy();
00163                         return new ToolbarButton(itemId, text, image, 0);
00164                     }
00165                 case Next:
00166                     {
00167                         Drawable * image = icons[1]->createCopy();
00168                         return new ToolbarButton(itemId, text, image, 0);
00169                     }
00170                 case Go:
00171                     {
00172                         Drawable * image = icons[2]->createCopy();
00173                         return new ToolbarButton(itemId, text, image, 0);
00174                     }
00175                 default:
00176                     return 0;
00177                 }
00178             }
00179 
00180             // Demonstrates how to put a custom component into a toolbar - this one contains
00181             // a ComboBox.
00182             class URLBarComboBox : public ToolbarItemComponent
00183             {
00184             public:
00185                 URLBarComboBox (const int toolbarItemId, ComboBoxListener * listener = 0, const String & homeURL = String::empty)
00186                     : ToolbarItemComponent (toolbarItemId, JUCE_T("Enter URL here"), false)
00187                 {
00188                     addAndMakeVisible (comboBox = new ComboBox (JUCE_T("Enter URL here")));
00189 
00190 
00191                     comboBox->setTextWhenNothingSelected(JUCE_T("Enter URL here"));
00192                     if (homeURL.isNotEmpty()) comboBox->setText(homeURL);
00193                     comboBox->setEditableText (true);
00194 
00195                     if (listener) comboBox->addListener(listener);
00196                 }
00197 
00198                 ~URLBarComboBox()
00199                 {
00200                     delete comboBox;
00201                 }
00202 
00203                 bool getToolbarItemSizes (int toolbarDepth,
00204                                           bool isToolbarVertical,
00205                                           int& preferredSize, int& minSize, int& maxSize)
00206                 {
00207                     if (isToolbarVertical)
00208                         return false;
00209 
00210                     preferredSize = 600;
00211                     minSize = 80;
00212                     maxSize = 600;
00213                     return true;
00214                 }
00215 
00216                 void paintButtonArea (Graphics&, int, int, bool, bool)
00217                 {
00218                 }
00219 
00220                 void contentAreaChanged (const Rectangle& contentArea)
00221                 {
00222                     comboBox->setSize (contentArea.getWidth() - 2,
00223                                        jmin (contentArea.getHeight() - 2, 22));
00224 
00225                     comboBox->setCentrePosition (contentArea.getCentreX(), contentArea.getCentreY());
00226                 }
00227 
00228             private:
00229                 ComboBox* comboBox;
00230             };
00231 
00232             ComboBoxListener * listener;
00233             String             homeURL;
00234         };
00235 
00236         BrowserItemFactory factory;
00237     };
00238 
00239 }
00240 
00241 #endif

(C) An X-Ryl669 project 2007

This document describes Unlimited Zooming Interface source code. UZI stands for Unlimited Zooming Interface, and source code license is