blob: 956f88bdcdc4e3cc7cdc7d1204c237e4f83673d8 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_Menu_Window.cxx 8198 2011-01-06 10:24:58Z manolo $"
3//
4// Menu window code 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// This is the window type used by Fl_Menu to make the pop-ups.
29// It draws in the overlay planes if possible.
30
31// Also here is the implementation of the mouse & keyboard grab,
32// which are used so that clicks outside the program's windows
33// can be used to dismiss the menus.
34
35#include <config.h>
36#include <FL/Fl.H>
37#include <FL/x.H>
38#include <FL/fl_draw.H>
39#include <FL/Fl_Menu_Window.H>
40
41// WIN32 note: HAVE_OVERLAY is false
42#if HAVE_OVERLAY
43extern XVisualInfo *fl_find_overlay_visual();
44extern XVisualInfo *fl_overlay_visual;
45extern Colormap fl_overlay_colormap;
46extern unsigned long fl_transparent_pixel;
47static GC gc; // the GC used by all X windows
48extern uchar fl_overlay; // changes how fl_color(x) works
49#endif
50
51#include <stdio.h>
52
53void Fl_Menu_Window::show() {
54#if HAVE_OVERLAY
55 if (!shown() && overlay() && fl_find_overlay_visual()) {
56 XInstallColormap(fl_display, fl_overlay_colormap);
57 fl_background_pixel = int(fl_transparent_pixel);
58 Fl_X::make_xid(this, fl_overlay_visual, fl_overlay_colormap);
59 fl_background_pixel = -1;
60 } else
61#endif
62 Fl_Single_Window::show();
63}
64
65void Fl_Menu_Window::flush() {
66#if HAVE_OVERLAY
67 if (!fl_overlay_visual || !overlay()) {Fl_Single_Window::flush(); return;}
68 Fl_X *myi = Fl_X::i(this);
69 fl_window = myi->xid;
70 if (!gc) {
71 gc = XCreateGC(fl_display, myi->xid, 0, 0);
72# if defined(FLTK_USE_CAIRO)
73 if(Fl::autolink_context()) Fl::cairo_make_current(gc); // capture gc changes automatically to update the cairo context adequately
74# endif
75 }
76 fl_gc = gc;
77 fl_overlay = 1;
78 fl_clip_region(myi->region); myi->region = 0; current_ = this;
79 draw();
80 fl_overlay = 0;
81#else
82 Fl_Single_Window::flush();
83#endif
84}
85
86/** Erases the window, does nothing if HAVE_OVERLAY is not defined config.h */
87void Fl_Menu_Window::erase() {
88#if HAVE_OVERLAY
89 if (!gc || !shown()) return;
90//XSetForeground(fl_display, gc, 0);
91//XFillRectangle(fl_display, fl_xid(this), gc, 0, 0, w(), h());
92 XClearWindow(fl_display, fl_xid(this));
93#endif
94}
95
96// Fix the colormap flashing on Maximum Impact Graphics by erasing the
97// menu before unmapping it:
98void Fl_Menu_Window::hide() {
99 erase();
100 Fl_Single_Window::hide();
101}
102
103/** Destroys the window and all of its children.*/
104Fl_Menu_Window::~Fl_Menu_Window() {
105 hide();
106}
107
108//
109// End of "$Id: Fl_Menu_Window.cxx 8198 2011-01-06 10:24:58Z manolo $".
110//