prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / guicast / bcwindowbase.C
index 59963d6d4b5dd31ea511a6a287fa9b31ab4d4044..2d43b62bfd6544ddb40cce46f6a2d9c8e4899629 100644 (file)
@@ -136,19 +136,9 @@ BC_WindowBase::~BC_WindowBase()
        delete pixmap;
 
 #ifdef HAVE_GL
-       if( get_resources()->get_synchronous() && top_level->options & GLX_WINDOW ) {
-               if( !glx_win ) {
-// NVIDIA library threading problem, XCloseDisplay SEGVs without this
-                       sync_lock("BC_WindowBase::~BC_WindowBase:XDestroyWindow");
-                       lock_window("BC_WindowBase::~BC_WindowBase:XDestroyWindow");
-                       glXMakeContextCurrent(top_level->display, 0, 0, 0);
-                       XDestroyWindow(top_level->display, win);
-                       unlock_window();
-                       sync_unlock();
-               }
-               else
-                       get_resources()->get_synchronous()->delete_window(this);
-       }
+       if( get_resources()->get_synchronous() &&
+               (top_level->options & GLX_WINDOW) && glx_win != 0 )
+               get_resources()->get_synchronous()->delete_window(this);
        else
 #endif
                XDestroyWindow(top_level->display, win);
@@ -170,22 +160,31 @@ BC_WindowBase::~BC_WindowBase()
        if(window_type == MAIN_WINDOW)
        {
                XFreeGC(display, gc);
-               XFreeFont(display, smallfont);
-               XFreeFont(display, mediumfont);
-               XFreeFont(display, largefont);
-               XFreeFont(display, bigfont);
+               static XFontStruct *BC_WindowBase::*xfont[] = {
+                        &BC_WindowBase::smallfont,
+                        &BC_WindowBase::mediumfont,
+                        &BC_WindowBase::largefont,
+                        &BC_WindowBase::bigfont,
+               };
+               for( int i=sizeof(xfont)/sizeof(xfont[0]); --i>=0; )
+                       XFreeFont(display, this->*xfont[i]);
 
 // bug in X causes XRenderExtensionInfo to be damaged if this is done here
 //  left to be done in XCloseDisplay by Xlib.
 #if defined(HAVE_XFT) && 0
-               if(bigfont_xft)
-                       XftFontClose (display, (XftFont*)bigfont_xft);
-               if(largefont_xft)
-                       XftFontClose (display, (XftFont*)largefont_xft);
-               if(mediumfont_xft)
-                       XftFontClose (display, (XftFont*)mediumfont_xft);
-               if(smallfont_xft)
-                       XftFontClose (display, (XftFont*)smallfont_xft);
+               static void *BC_WindowBase::*xft_font[] = {
+                        &BC_WindowBase::smallfont_xft,
+                        &BC_WindowBase::mediumfont_xft,
+                        &BC_WindowBase::largefont_xft,
+                        &BC_WindowBase::bigfont_xft,
+                        &BC_WindowBase::bold_smallfont_xft,
+                        &BC_WindowBase::bold_mediumfont_xft,
+                        &BC_WindowBase::bold_largefont_xft,
+               };
+               for( int i=sizeof(xft_font)/sizeof(xft_font[0]); --i>=0; ) {
+                       XftFont *xft = (XftFont *)(this->*xft_font[i]);
+                       if( xft ) XftFontClose (display, xft);
+               }
 #endif
                finit_im();
 
@@ -461,8 +460,8 @@ int BC_WindowBase::create_window(BC_WindowBase *parent_window,
                init_colors();
 // get the resources
                if(resources.use_shm < 0) resources.initialize_display(this);
-               x_correction = get_resources()->get_left_border();
-               y_correction = get_resources()->get_top_border();
+               x_correction = BC_DisplayInfo::get_left_border();
+               y_correction = BC_DisplayInfo::get_top_border();
 
 // clamp window placement
                if(this->x + this->w + x_correction > root_w)
@@ -863,20 +862,25 @@ int BC_WindowBase::keysym_lookup(XEvent *event)
                keys_return[0] = keysym;
                return 0;
        }
+       wkey_string_length = 0;
 
-       wkey_string_length = XwcLookupString(input_context,
-               (XKeyEvent*)event, wkey_string, 4, &keysym, 0);
+       if( input_context ) {
+               wkey_string_length = XwcLookupString(input_context,
+                       (XKeyEvent*)event, wkey_string, 4, &keysym, 0);
 //printf("keysym_lookup 1 %d %d %lx %x %x %x %x\n", wkey_string_length, keysym,
 //  wkey_string[0], wkey_string[1], wkey_string[2], wkey_string[3]);
 
-       Status stat;
-       int ret = Xutf8LookupString(input_context, (XKeyEvent*)event,
-                       keys_return, KEYPRESSLEN, &keysym, &stat);
+               Status stat;
+               int ret = Xutf8LookupString(input_context, (XKeyEvent*)event,
+                               keys_return, KEYPRESSLEN, &keysym, &stat);
 //printf("keysym_lookup 2 %d %d %lx %x %x\n", ret, stat, keysym, keys_return[0], keys_return[1]);
-       if( stat == XLookupBoth ) return ret;
-       if( stat == XLookupKeySym ) return 0;
-
-       return XLookupString((XKeyEvent*)event, keys_return, KEYPRESSLEN, &keysym, 0);
+               if( stat == XLookupBoth ) return ret;
+               if( stat == XLookupKeySym ) return 0;
+       }
+       int ret = XLookupString((XKeyEvent*)event, keys_return, KEYPRESSLEN, &keysym, 0);
+       wkey_string_length = ret;
+       for( int i=0; i<ret; ++i ) wkey_string[i] = keys_return[i];
+       return ret;
 }
 
 pthread_t locking_task = -1;
@@ -2257,6 +2261,7 @@ int BC_WindowBase::init_fonts()
 void BC_WindowBase::init_xft()
 {
 #ifdef HAVE_XFT
+       if( !get_resources()->use_xft ) return;
        if(!(smallfont_xft =
                (resources.small_font_xft[0] == '-' ?
                        XftFontOpenXlfd(display, screen, resources.small_font_xft) :
@@ -2274,7 +2279,7 @@ void BC_WindowBase::init_xft()
        if(!(largefont_xft =
                (resources.large_font_xft[0] == '-' ?
                        XftFontOpenXlfd(display, screen, resources.large_font_xft) :
-                       XftFontOpenXlfd(display, screen, resources.large_font_xft))) )
+                       XftFontOpenName(display, screen, resources.large_font_xft))) )
                if(!(largefont_xft =
                        XftFontOpenXlfd(display, screen, resources.large_font_xft2)))
                        largefont_xft = XftFontOpenXlfd(display, screen, "fixed");
@@ -2286,13 +2291,34 @@ void BC_WindowBase::init_xft()
                        XftFontOpenXlfd(display, screen, resources.big_font_xft2)))
                        bigfont_xft = XftFontOpenXlfd(display, screen, "fixed");
 
+       if(!(bold_smallfont_xft =
+               (resources.small_b_font_xft[0] == '-' ?
+                       XftFontOpenXlfd(display, screen, resources.small_b_font_xft) :
+                       XftFontOpenName(display, screen, resources.small_b_font_xft))) )
+               bold_smallfont_xft = XftFontOpenXlfd(display, screen, "fixed");
+       if(!(bold_mediumfont_xft =
+               (resources.medium_b_font_xft[0] == '-' ?
+                       XftFontOpenXlfd(display, screen, resources.medium_b_font_xft) :
+                       XftFontOpenName(display, screen, resources.medium_b_font_xft))) )
+               bold_mediumfont_xft = XftFontOpenXlfd(display, screen, "fixed");
+       if(!(bold_largefont_xft =
+               (resources.large_b_font_xft[0] == '-' ?
+                       XftFontOpenXlfd(display, screen, resources.large_b_font_xft) :
+                       XftFontOpenName(display, screen, resources.large_b_font_xft))) )
+               bold_largefont_xft = XftFontOpenXlfd(display, screen, "fixed");
+
 // Extension failed to locate fonts
-       if( !smallfont_xft || !mediumfont_xft || !largefont_xft || !bigfont_xft) {
-               printf("BC_WindowBase::init_fonts: no xft fonts found %s=%p %s=%p %s=%p %s=%p\n",
+       if( !smallfont_xft || !mediumfont_xft || !largefont_xft || !bigfont_xft ||
+           !bold_largefont_xft || !bold_mediumfont_xft || !bold_largefont_xft ) {
+               printf("BC_WindowBase::init_fonts: no xft fonts found:"
+                       " %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n",
                        resources.small_font_xft, smallfont_xft,
                        resources.medium_font_xft, mediumfont_xft,
                        resources.large_font_xft, largefont_xft,
-                       resources.big_font_xft, bigfont_xft);
+                       resources.big_font_xft, bigfont_xft,
+                       resources.small_b_font_xft, bold_smallfont_xft,
+                       resources.medium_b_font_xft, bold_mediumfont_xft,
+                       resources.large_b_font_xft, bold_largefont_xft);
                get_resources()->use_xft = 0;
                exit(1);
        }
@@ -2791,16 +2817,22 @@ int BC_WindowBase::get_single_text_width(int font, const char *text, int length)
 
 int BC_WindowBase::get_single_text_width(int font, const wchar_t *text, int length)
 {
-//#ifdef HAVE_XFT
-       XGlyphInfo extents;
+#ifdef HAVE_XFT
+       if(get_resources()->use_xft && get_xft_struct(font)) {
+               XGlyphInfo extents;
 
-       XftTextExtents32(top_level->display,
-               get_xft_struct(font),
-               (const FcChar32*)text,
-               length,
-               &extents);
-       return extents.xOff;
-//#endif
+               XftTextExtents32(top_level->display, get_xft_struct(font),
+                       (const FcChar32*)text, length, &extents);
+               return extents.xOff;
+       }
+#endif
+       if(!get_font_struct(font)) return 0;
+       XChar2b xtext[length], *xp = xtext;
+       for( int i=0; i<length; ++i,++xp ) {
+               xp->byte1 = (unsigned char) (text[i] >> 8);
+               xp->byte2 = (unsigned char) (text[i] & 0xff);
+       }
+       return XTextWidth16(get_font_struct(font), xtext, length);
 }
 
 int BC_WindowBase::get_text_width(int font, const char *text, int length)
@@ -4199,6 +4231,15 @@ void BC_WindowBase::translate_coordinates(Window src_w,
        }
 }
 
+void BC_WindowBase::get_root_coordinates(int x, int y, int *abs_x, int *abs_y)
+{
+       translate_coordinates(win, top_level->rootwin, x, y, abs_x, abs_y);
+}
+
+void BC_WindowBase::get_win_coordinates(int abs_x, int abs_y, int *x, int *y)
+{
+       translate_coordinates(top_level->rootwin, win, abs_x, abs_y, x, y);
+}