~ubuntu-branches/ubuntu/karmic/fltk1.1/karmic

« back to all changes in this revision

Viewing changes to src/Fl_Menu.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-05-22 13:57:06 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050522135706-mchag24yf42lu7bu
Tags: 1.1.6-5
* Revert previous change, which seems to have been ineffective for some
  reason, in favor of commenting out the problematic Makefile rule
  altogether.  (Closes: #310151.)
* debian/control: Go back to specifying the URL as part of the
  description rather than via a non-standard field that doesn't seem to
  have caught on.  (Closes: #310240.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
 
// "$Id: Fl_Menu.cxx,v 1.18.2.12.2.30 2004/04/11 04:38:57 easysw Exp $"
 
2
// "$Id: Fl_Menu.cxx,v 1.18.2.12.2.35 2004/11/23 01:48:25 matthiaswm Exp $"
3
3
//
4
4
// Menu code for the Fast Light Tool Kit (FLTK).
5
5
//
35
35
#include <FL/fl_draw.H>
36
36
#include <stdio.h>
37
37
 
 
38
#ifdef __APPLE__
 
39
#  include <Carbon/Carbon.H>
 
40
#endif
 
41
 
38
42
int Fl_Menu_Item::size() const {
39
43
  const Fl_Menu_Item* m = this;
40
44
  int nest = 0;
53
57
  if (n < 0) return 0; // this is so selected==-1 returns NULL
54
58
  const Fl_Menu_Item* m = this;
55
59
  int nest = 0;
 
60
  if (!m->visible()) n++;
56
61
  while (n>0) {
57
62
    if (!m->text) {
58
63
      if (!nest) return m;
233
238
                       int menubar, int menubar_title, int right_edge)
234
239
  : Fl_Menu_Window(X, Y, Wp, Hp, 0)
235
240
{
236
 
  if (!right_edge) right_edge = Fl::w();
 
241
  int scr_right = Fl::x() + Fl::w();
 
242
  int scr_x = Fl::x();
 
243
#ifdef __APPLE__
 
244
  GDHandle gd = 0L;
 
245
  for ( gd = GetDeviceList(); gd; gd = GetNextDevice(gd) ) {
 
246
    GDPtr gp = *gd;
 
247
    if (    X >= gp->gdRect.left && X <= gp->gdRect.right
 
248
         && Y >= gp->gdRect.top  && Y <= gp->gdRect.bottom)
 
249
      break;
 
250
  }
 
251
  if ( !gd ) gd = GetMainDevice();
 
252
  if ( gd ) {
 
253
    // since the menu pops over everything, we use the screen
 
254
    // bounds, right across the dock and menu bar
 
255
    GDPtr gp = *gd;
 
256
    scr_right = gp->gdRect.right;
 
257
    scr_x = gp->gdRect.left;
 
258
  }
 
259
#endif
 
260
 
 
261
  if (!right_edge) right_edge = scr_right;
237
262
 
238
263
  end();
239
264
  set_modal();
240
265
  clear_border();
241
266
  menu = m;
 
267
  if (m) m = m->first(); // find the first item that needs to be rendered
242
268
  drawn_selected = -1;
243
269
  if (button) {
244
270
    box(button->box());
288
314
  if (Wp > W) W = Wp;
289
315
  if (Wtitle > W) W = Wtitle;
290
316
 
291
 
  if (!Wp) {if (X < 0) X = 0; if (X > Fl::w()-W) X= right_edge-W;}
 
317
  if (!Wp) {if (X < scr_x) X = scr_x; if (X > scr_right-W) X= right_edge-W;}
292
318
  x(X); w(W);
293
319
  h((numitems ? itemheight*numitems-LEADING : 0)+2*BW+3);
294
320
  if (selected >= 0)
317
343
 
318
344
// scroll so item i is visible on screen
319
345
void menuwindow::autoscroll(int n) {
 
346
  int scr_y = Fl::y(), scr_h = Fl::h();
320
347
  int Y = y()+Fl::box_dx(box())+2+n*itemheight;
321
 
  if (Y <= Fl::y()) Y = Fl::y()-Y+10;
 
348
#ifdef __APPLE__
 
349
  GDHandle gd = 0L;
 
350
  for ( gd = GetDeviceList(); gd; gd = GetNextDevice(gd) ) {
 
351
    GDPtr gp = *gd;
 
352
    if (    x() >= gp->gdRect.left && x() <= gp->gdRect.right
 
353
         && Y >= gp->gdRect.top    && Y <= gp->gdRect.bottom)
 
354
      break;
 
355
  }
 
356
  if ( !gd ) gd = GetMainDevice();
 
357
  if ( gd ) {
 
358
    // since the menu pops over everything, we use the screen
 
359
    // bounds, right across the dock and menu bar
 
360
    GDPtr gp = *gd;
 
361
    scr_y = gp->gdRect.top; scr_h = gp->gdRect.bottom - gp->gdRect.top + 1;
 
362
  }
 
363
#endif
 
364
  if (Y <= scr_y) Y = scr_y-Y+10;
322
365
  else {
323
 
    Y = Y+itemheight-Fl::h()-Fl::y();
 
366
    Y = Y+itemheight-scr_h-scr_y;
324
367
    if (Y < 0) return;
325
368
    Y = -Y-10;
326
369
  }
376
419
 
377
420
void menuwindow::draw() {
378
421
  if (damage() != FL_DAMAGE_CHILD) {    // complete redraw
379
 
    fl_draw_box(box(), 0, 0, w(), h(), color());
 
422
    fl_draw_box(box(), 0, 0, w(), h(), button ? button->color() : color());
380
423
    if (menu) {
381
424
      const Fl_Menu_Item* m; int j;
382
 
      for (m=menu, j=0; m->text; j++, m = m->next()) drawentry(m, j, 0);
 
425
      for (m=menu->first(), j=0; m->text; j++, m = m->next()) drawentry(m, j, 0);
383
426
    }
384
427
  } else {
385
428
    if (damage() & FL_DAMAGE_CHILD && selected!=drawn_selected) { // change selection
403
446
  if (my < 0 || my >= h()) return -1;
404
447
  if (!itemheight) { // menubar
405
448
    int xx = 3; int n = 0;
406
 
    const Fl_Menu_Item* m = menu;
 
449
    const Fl_Menu_Item* m = menu ? menu->first() : 0;
407
450
    for (; ; m = m->next(), n++) {
408
451
      if (!m->text) return -1;
409
452
      xx += m->measure(0, button) + 16;
421
464
int menuwindow::titlex(int n) {
422
465
  const Fl_Menu_Item* m;
423
466
  int xx = 3;
424
 
  for (m=menu; n--; m = m->next()) xx += m->measure(0, button) + 16;
 
467
  for (m=menu->first(); n--; m = m->next()) xx += m->measure(0, button) + 16;
425
468
  return xx;
426
469
}
427
470
 
754
797
// Search only the top level menu for a shortcut.  Either &x in the
755
798
// label or the shortcut fields are used:
756
799
const Fl_Menu_Item* Fl_Menu_Item::find_shortcut(int* ip) const {
757
 
  const Fl_Menu_Item* m = this;
 
800
  const Fl_Menu_Item* m = first();
758
801
  if (m) for (int ii = 0; m->text; m = m->next(), ii++) {
759
802
    if (m->activevisible()) {
760
803
      if (Fl::test_shortcut(m->shortcut_)
770
813
// Recursive search of all submenus for anything with this key as a
771
814
// shortcut.  Only uses the shortcut field, ignores &x in the labels:
772
815
const Fl_Menu_Item* Fl_Menu_Item::test_shortcut() const {
773
 
  const Fl_Menu_Item* m = this;
 
816
  const Fl_Menu_Item* m = first();
774
817
  const Fl_Menu_Item* ret = 0;
775
818
  if (m) for (; m->text; m = m->next()) {
776
819
    if (m->activevisible()) {
789
832
}
790
833
 
791
834
//
792
 
// End of "$Id: Fl_Menu.cxx,v 1.18.2.12.2.30 2004/04/11 04:38:57 easysw Exp $".
 
835
// End of "$Id: Fl_Menu.cxx,v 1.18.2.12.2.35 2004/11/23 01:48:25 matthiaswm Exp $".
793
836
//