blob: 8e114e39b61b083734ede6879abe3cad508f95f1 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_Menu_Bar.cxx 7903 2010-11-28 21:06:39Z matt $"
3//
4// Menu bar widget for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 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 on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28#include <FL/Fl.H>
29#include <FL/Fl_Menu_Bar.H>
30#include <FL/fl_draw.H>
31
32void Fl_Menu_Bar::draw() {
33 draw_box();
34 if (!menu() || !menu()->text) return;
35 const Fl_Menu_Item* m;
36 int X = x()+6;
37 for (m=menu()->first(); m->text; m = m->next()) {
38 int W = m->measure(0,this) + 16;
39 m->draw(X, y(), W, h(), this);
40 X += W;
41 if (m->flags & FL_MENU_DIVIDER) {
42 int y1 = y() + Fl::box_dy(box());
43 int y2 = y1 + h() - Fl::box_dh(box()) - 1;
44
45 // Draw a vertical divider between menus...
46 fl_color(FL_DARK3);
47 fl_yxline(X - 6, y1, y2);
48 fl_color(FL_LIGHT3);
49 fl_yxline(X - 5, y1, y2);
50 }
51 }
52}
53
54int Fl_Menu_Bar::handle(int event) {
55 const Fl_Menu_Item* v;
56 if (menu() && menu()->text) switch (event) {
57 case FL_ENTER:
58 case FL_LEAVE:
59 return 1;
60 case FL_PUSH:
61 v = 0;
62 J1:
63 v = menu()->pulldown(x(), y(), w(), h(), v, this, 0, 1);
64 picked(v);
65 return 1;
66 case FL_SHORTCUT:
67 if (visible_r()) {
68 v = menu()->find_shortcut(0, true);
69 if (v && v->submenu()) goto J1;
70 }
71 return test_shortcut() != 0;
72 }
73 return 0;
74}
75
76//
77// End of "$Id: Fl_Menu_Bar.cxx 7903 2010-11-28 21:06:39Z matt $".
78//