Back to index

lightning-sunbird  0.9+nobinonly
xlibxtbin.cpp
Go to the documentation of this file.
00001 /* widget -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  * vim:ts=2:et:sw=2 */
00003 
00004 /* ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code.
00018  *
00019  * The Initial Developer of the Original Code is Peter Hartshorn.
00020  * Portions created by the Initial Developer are Copyright (C) 2000
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Based on GtkXtBin by Rusty Lynch - 02/27/2000
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "xlibxtbin.h"
00041 #include "xlibrgb.h"
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include <X11/X.h>
00047 #include <X11/Xlib.h>
00048 #include <X11/Xutil.h>
00049 #include <X11/Shell.h>
00050 #include <X11/Intrinsic.h>
00051 #include <X11/StringDefs.h>
00052 
00053 xtbin::xtbin() {
00054   initialized = False;
00055   xtwindow    = None;
00056 }
00057 
00058 xtbin::~xtbin() {
00059 }
00060 
00061 void xtbin::xtbin_init() {
00062   mXlibRgbHandle = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE);
00063   xtdisplay = xxlib_rgb_get_display(mXlibRgbHandle);
00064   if (!xtdisplay)
00065     abort();
00066   app_context = XtDisplayToApplicationContext(xtdisplay);
00067   initialized = True;
00068 }
00069 
00070 void xtbin::xtbin_realize() {
00071   Arg args[2];
00072   int n;
00073   Widget top_widget;
00074   Widget embedded;
00075   XSetWindowAttributes attr;
00076   unsigned long mask;
00077 
00078   attr.bit_gravity = NorthWestGravity;
00079   attr.event_mask = 
00080     ButtonMotionMask |
00081     ButtonPressMask |
00082     ButtonReleaseMask |
00083     EnterWindowMask |
00084     ExposureMask |
00085     KeyPressMask |
00086     KeyReleaseMask |
00087     LeaveWindowMask |
00088     PointerMotionMask |
00089     StructureNotifyMask |
00090     VisibilityChangeMask |
00091     FocusChangeMask;
00092 
00093   attr.colormap         = xxlib_rgb_get_cmap(mXlibRgbHandle);
00094   attr.background_pixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, 0xFFC0C0C0);
00095   attr.border_pixel     = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, 0xFF646464);
00096 
00097 #ifdef DEBUG  
00098   printf("attr.background_pixel = %lx, attr.border_pixel = %lx, parent_window = %x\n", 
00099          (long)attr.background_pixel,
00100          (long)attr.border_pixel, (int)parent_window);
00101 #endif /* DEBUG */
00102   
00103   mask = CWBitGravity | CWEventMask | CWBorderPixel | CWBackPixel;
00104 
00105   if (attr.colormap)
00106     mask |= CWColormap;
00107 
00108   window = XCreateWindow(xtdisplay, parent_window,
00109                          x, y, width, height, 0, 
00110                          xxlib_rgb_get_depth(mXlibRgbHandle),
00111                          InputOutput, xxlib_rgb_get_visual(mXlibRgbHandle),
00112                          mask, &attr);
00113   XSetWindowBackgroundPixmap(xtdisplay, window, None);
00114   XSelectInput(xtdisplay, window, ExposureMask);
00115 
00116   XMapWindow(xtdisplay, window);
00117   XFlush(xtdisplay);
00118 
00119   top_widget = XtAppCreateShell("drawingArea", "Wrapper",
00120                                 applicationShellWidgetClass, xtdisplay,
00121                                 NULL, 0);
00122 
00123   xtwidget = top_widget;
00124 
00125   n = 0;
00126   XtSetArg(args[n], XtNheight, height); n++;
00127   XtSetArg(args[n], XtNwidth,  width);  n++;
00128   XtSetValues(top_widget, args, n);
00129 
00130   embedded = XtVaCreateWidget("form", compositeWidgetClass, top_widget, NULL);
00131 
00132   n = 0;
00133   XtSetArg(args[n], XtNheight, height); n++;
00134   XtSetArg(args[n], XtNwidth,  width);  n++;
00135   XtSetValues(embedded, args, n);
00136 
00137   oldwindow = top_widget->core.window;
00138   top_widget->core.window = window;
00139 
00140   XtRegisterDrawable(xtdisplay, window, top_widget);
00141 
00142   XtRealizeWidget(embedded);
00143   XtRealizeWidget(top_widget);
00144   XtManageChild(embedded);
00145 
00146   /* Now fill out the xtbin info */
00147   xtwindow = XtWindow(embedded);
00148 
00149   /* Suppress background refresh flashing */
00150   XSetWindowBackgroundPixmap(xtdisplay, XtWindow(top_widget), None);
00151   XSetWindowBackgroundPixmap(xtdisplay, XtWindow(embedded),   None);
00152 
00153   /* Listen to all Xt events */
00154   XSelectInput(xtdisplay, XtWindow(top_widget), 0x0fffff);
00155   XSelectInput(xtdisplay, XtWindow(embedded),   0x0fffff);
00156 
00157   sync();
00158 }
00159 
00160 void xtbin::xtbin_new(Window aParent) {
00161   parent_window = aParent;
00162 }
00163 
00164 void xtbin::sync() {
00165   /* is this really all ? */
00166   XSync(xtdisplay, False);
00167 }
00168 
00169 void xtbin::xtbin_destroy() {
00170   sync();
00171   XtUnregisterDrawable(xtdisplay, xtwindow);
00172   sync();
00173   xtwidget->core.window = oldwindow;
00174   XtUnrealizeWidget(xtwidget);
00175   initialized = False;
00176 }
00177 
00178 void xtbin::xtbin_resize(int aX, int aY, int aWidth, int aHeight) {
00179   x = aX;
00180   y = aY;
00181   width = aWidth;
00182   height = aHeight;
00183 }
00184 
00185 int xtbin::xtbin_initialized() {
00186   return initialized;
00187 }
00188