home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_Menu_Button.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.4 KB  |  83 lines

  1. //
  2. // "$Id: Fl_Menu_Button.cxx,v 1.4 1999/01/07 19:17:23 mike Exp $"
  3. //
  4. // Menu button widget for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/Fl_Menu_Button.H>
  28. #include <FL/fl_draw.H>
  29.  
  30. void Fl_Menu_Button::draw() {
  31.   if (!box() || type()) return;
  32.   draw_box(box(), color());
  33.   draw_label();
  34.   if (box() == FL_FLAT_BOX) return; // for XForms compatability
  35.   int H = (labelsize()-3)&-2;
  36.   int X = x()+w()-H*2;
  37.   int Y = y()+(h()-H)/2;
  38.   fl_color(FL_DARK3); fl_line(X+H/2, Y+H, X, Y, X+H, Y);
  39.   fl_color(FL_LIGHT3); fl_line(X+H, Y, X+H/2, Y+H);
  40. }
  41.  
  42. const Fl_Menu_Item* Fl_Menu_Button::popup() {
  43.   const Fl_Menu_Item* m;
  44.   if (!box() || type()) {
  45.     m = menu()->popup(Fl::event_x(), Fl::event_y(), label(), mvalue(), this);
  46.   } else {
  47.     m = menu()->pulldown(x(), y(), w(), h(), 0, this);
  48.   }
  49.   picked(m);
  50.   return m;
  51. }
  52.  
  53. int Fl_Menu_Button::handle(int e) {
  54.   if (!menu() || !menu()->text) return 0;
  55.   switch (e) {
  56.   case FL_ENTER:
  57.   case FL_LEAVE:
  58.     return (box() && !type()) ? 1 : 0;
  59.   case FL_PUSH:
  60.     if (!box()) {
  61.       if (Fl::event_button() != 3) return 0;
  62.     } else if (type()) {
  63.       if (!(type() & (1 << (Fl::event_button()-1)))) return 0;
  64.     }
  65.     popup();
  66.     return 1;
  67.   case FL_SHORTCUT:
  68.     if (Fl_Widget::test_shortcut()) {popup(); return 1;}
  69.     return test_shortcut() != 0;
  70.   default:
  71.     return 0;
  72.   }
  73. }
  74.  
  75. Fl_Menu_Button::Fl_Menu_Button(int X,int Y,int W,int H,const char *l)
  76. : Fl_Menu_(X,Y,W,H,l) {
  77.   down_box(FL_NO_BOX);
  78. }
  79.  
  80. //
  81. // End of "$Id: Fl_Menu_Button.cxx,v 1.4 1999/01/07 19:17:23 mike Exp $".
  82. //
  83.