Back to index

lightning-sunbird  0.9+nobinonly
nsGdkUtils.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Stuart Parmenter <pavlov@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsGdkUtils.h"
00040 #include <gdk/gdkprivate.h>
00041 #include <gdk/gdkx.h>
00042 
00043 void
00044 my_gdk_draw_text(GdkDrawable *drawable,
00045                  GdkFont     *font,
00046                  GdkGC       *gc,
00047                  gint         x,
00048                  gint         y,
00049                  const gchar *text,
00050                  gint         text_length)
00051 {
00052 #ifdef MOZ_WIDGET_GTK
00053   GdkWindowPrivate *drawable_private;
00054   GdkFontPrivate *font_private;
00055   GdkGCPrivate *gc_private;
00056 #endif /* MOZ_WIDGET_GTK */
00057 
00058   g_return_if_fail (drawable != NULL);
00059   g_return_if_fail (font != NULL);
00060   g_return_if_fail (gc != NULL);
00061   g_return_if_fail (text != NULL);
00062 
00063 #ifdef MOZ_WIDGET_GTK
00064   drawable_private = (GdkWindowPrivate*) drawable;
00065   if (drawable_private->destroyed)
00066     return;
00067 
00068   gc_private = (GdkGCPrivate*) gc;
00069   font_private = (GdkFontPrivate*) font;
00070 #endif /* MOZ_WIDGET_GTK */
00071 #ifdef MOZ_WIDGET_GTK2
00072   if (GDK_IS_WINDOW(drawable) && GDK_WINDOW_OBJECT(drawable)->destroyed)
00073     return;
00074 #endif /* MOZ_WIDGET_GTK2 */
00075 
00076   if (font->type == GDK_FONT_FONT)
00077   {
00078 #ifdef MOZ_WIDGET_GTK
00079     XFontStruct *xfont = (XFontStruct *) font_private->xfont;
00080 #endif /* MOZ_WIDGET_GTK */
00081 #ifdef MOZ_WIDGET_GTK2
00082     XFontStruct *xfont = (XFontStruct *) GDK_FONT_XFONT(font);
00083 #endif /* MOZ_WIDGET_GTK2 */
00084 
00085     // gdk does this... we don't need it..
00086     //    XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid);
00087 
00088     // We clamp the sizes down to 32768 which is the maximum width of
00089     // a window.  Even if a font was 1 pixel high and started at the
00090     // left, the maximum size of a draw request could only be 32k.
00091 
00092     if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
00093     {
00094 #ifdef MOZ_WIDGET_GTK
00095       XDrawString (drawable_private->xdisplay, drawable_private->xwindow,
00096                    gc_private->xgc, x, y, text, MIN(text_length, 32768));
00097 #endif /* MOZ_WIDGET_GTK */
00098 #ifdef MOZ_WIDGET_GTK2
00099       XDrawString (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable),
00100                    GDK_GC_XGC(gc), x, y, text, MIN(text_length, 32768));
00101 #endif /* MOZ_WIDGET_GTK2 */
00102     }
00103     else
00104     {
00105 #ifdef MOZ_WIDGET_GTK
00106       XDrawString16 (drawable_private->xdisplay, drawable_private->xwindow,
00107                      gc_private->xgc, x, y, (XChar2b *) text, 
00108                      MIN((text_length / 2), 32768));
00109 #endif /* MOZ_WIDGET_GTK */
00110 #ifdef MOZ_WIDGET_GTK2
00111       XDrawString16 (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable),
00112                      GDK_GC_XGC(gc), x, y, (XChar2b *) text, 
00113                      MIN((text_length / 2), 32768));
00114 #endif /* MOZ_WIDGET_GTK2 */
00115     }
00116   }
00117   else if (font->type == GDK_FONT_FONTSET)
00118   {
00119 #ifdef MOZ_WIDGET_GTK
00120     XFontSet fontset = (XFontSet) font_private->xfont;
00121     XmbDrawString (drawable_private->xdisplay, drawable_private->xwindow,
00122                    fontset, gc_private->xgc, x, y, text, text_length);
00123 #endif /* MOZ_WIDGET_GTK */
00124 #ifdef MOZ_WIDGET_GTK2
00125     XFontSet fontset = (XFontSet) GDK_FONT_XFONT(font);
00126     XmbDrawString (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable),
00127                    fontset, GDK_GC_XGC(gc), x, y, text, text_length);
00128 #endif /* MOZ_WIDGET_GTK2 */
00129   }
00130   else
00131     g_error("undefined font type\n");
00132 }