This one was really tough to track, understand: In fact, the problem was comming from the misplacement of the menu window, which itself came from invalid measurement, which itself came from invalid fl_witdh() measurement, but only when fl_gc is not valid because fl_width() relies on Win32 on the call of GetTextExtentPoint32W which can't succeed if the HDC(here fl_gc) is not valid ! Now the fix: A best-effort algorithm has been furthered to supply a valid fltk hdc if we can have one or a screen hdc if no fltk window is found by fl::first_window(). Note that when fl_gc is NULL inside fl_width() call, it can happen that Fl_Window::current() is not null but invalid (already deleted). Finally, in the case of the buggy menu window observed here, this fl_gc was set to NULL just after an Fl_Menu_Window deletion and re-creation in Fl_Menu_Item::pulldown(). Also added a comment to describe the new fl_width() behavior. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6540 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
87 lines
2.2 KiB
C++
87 lines
2.2 KiB
C++
//
|
|
// "$Id$"
|
|
//
|
|
// Font selection code for the Fast Light Tool Kit (FLTK).
|
|
//
|
|
// Copyright 1998-2008 by Bill Spitzak and others.
|
|
//
|
|
// This library is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU Library General Public
|
|
// License as published by the Free Software Foundation; either
|
|
// version 2 of the License, or (at your option) any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// Library General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Library General Public
|
|
// License along with this library; if not, write to the Free Software
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
// USA.
|
|
//
|
|
// Please report all bugs and problems on the following page:
|
|
//
|
|
// http://www.fltk.org/str.php
|
|
//
|
|
|
|
#ifdef WIN32
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
# define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
/* We require Windows 2000 features such as GetGlyphIndices */
|
|
# if !defined(WINVER) || (WINVER < 0x0500)
|
|
# define WINVER 0x0500
|
|
# endif
|
|
# if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
|
|
# define _WIN32_WINNT 0x0500
|
|
# endif
|
|
#endif
|
|
|
|
// Select fonts from the FLTK font table.
|
|
#include "flstring.h"
|
|
#include <FL/Fl.H>
|
|
#include <FL/fl_draw.H>
|
|
#include <FL/x.H>
|
|
#include "Fl_Font.H"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifdef WIN32
|
|
# include "fl_font_win32.cxx"
|
|
#elif defined(__APPLE__)
|
|
# include "fl_font_mac.cxx"
|
|
#elif USE_XFT
|
|
# include "fl_font_xft.cxx"
|
|
#else
|
|
# include "fl_font_x.cxx"
|
|
#endif // WIN32
|
|
|
|
|
|
double fl_width(const char* c) {
|
|
if (c) return fl_width(c, strlen(c));
|
|
else return 0.0f;
|
|
}
|
|
|
|
void fl_draw(const char* str, int x, int y) {
|
|
fl_draw(str, strlen(str), x, y);
|
|
}
|
|
|
|
void fl_text_extents(const char *c, int &dx, int &dy, int &w, int &h) {
|
|
if (c) return fl_text_extents(c, strlen(c), dx, dy, w, h);
|
|
// else
|
|
w = 0; h = 0;
|
|
dx = 0; dy = 0;
|
|
} // fl_text_extents
|
|
|
|
|
|
#if !USE_XFT && !__APPLE__
|
|
void fl_draw(const char* str, int l, float x, float y) {
|
|
fl_draw(str, l, (int)x, (int)y);
|
|
}
|
|
#endif
|
|
//
|
|
// End of "$Id$".
|
|
//
|