fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Menu_Button.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: Fl_Menu_Button.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Menu button widget for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 #include <FL/Fl.H>
00029 #include <FL/Fl_Menu_Button.H>
00030 #include <FL/fl_draw.H>
00031 
00032 
00033 static Fl_Menu_Button   *pressed_menu_button_ = 0;
00034 
00035 void Fl_Menu_Button::draw() {
00036   if (!box() || type()) return;
00037   draw_box(pressed_menu_button_ == this ? fl_down(box()) : box(), color());
00038   draw_label();
00039   if (Fl::focus() == this) draw_focus();
00040   // ** if (box() == FL_FLAT_BOX) return; // for XForms compatibility
00041   int H = (labelsize()-3)&-2;
00042   int X = x()+w()-H*2;
00043   int Y = y()+(h()-H)/2;
00044   fl_color(active_r() ? FL_DARK3 : fl_inactive(FL_DARK3));
00045   fl_line(X+H/2, Y+H, X, Y, X+H, Y);
00046   fl_color(active_r() ? FL_LIGHT3 : fl_inactive(FL_LIGHT3));
00047   fl_line(X+H, Y, X+H/2, Y+H);
00048 }
00049 
00057 const Fl_Menu_Item* Fl_Menu_Button::popup() {
00058   const Fl_Menu_Item* m;
00059   pressed_menu_button_ = this;
00060   redraw();
00061   Fl_Widget_Tracker mb(this);
00062   if (!box() || type()) {
00063     m = menu()->popup(Fl::event_x(), Fl::event_y(), label(), mvalue(), this);
00064   } else {
00065     m = menu()->pulldown(x(), y(), w(), h(), 0, this);
00066   }
00067   picked(m);
00068   pressed_menu_button_ = 0;
00069   if (mb.exists()) redraw();
00070   return m;
00071 }
00072 
00073 int Fl_Menu_Button::handle(int e) {
00074   if (!menu() || !menu()->text) return 0;
00075   switch (e) {
00076   case FL_ENTER: /* FALLTHROUGH */
00077   case FL_LEAVE:
00078     return (box() && !type()) ? 1 : 0;
00079   case FL_PUSH:
00080     if (!box()) {
00081       if (Fl::event_button() != 3) return 0;
00082     } else if (type()) {
00083       if (!(type() & (1 << (Fl::event_button()-1)))) return 0;
00084     }
00085     if (Fl::visible_focus()) Fl::focus(this);
00086     popup();
00087     return 1;
00088   case FL_KEYBOARD:
00089     if (!box()) return 0;
00090     if (Fl::event_key() == ' ' &&
00091         !(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
00092       popup();
00093       return 1;
00094     } else return 0;
00095   case FL_SHORTCUT:
00096     if (Fl_Widget::test_shortcut()) {popup(); return 1;}
00097     return test_shortcut() != 0;
00098   case FL_FOCUS: /* FALLTHROUGH */
00099   case FL_UNFOCUS:
00100     if (box() && Fl::visible_focus()) {
00101       redraw();
00102       return 1;
00103     }
00104   default:
00105     return 0;
00106   }
00107 }
00108 
00115 Fl_Menu_Button::Fl_Menu_Button(int X,int Y,int W,int H,const char *l)
00116 : Fl_Menu_(X,Y,W,H,l) {
00117   down_box(FL_NO_BOX);
00118 }
00119 
00120 //
00121 // End of "$Id: Fl_Menu_Button.cxx 7903 2010-11-28 21:06:39Z matt $".
00122 //