From: Good Guy Date: Sat, 27 Feb 2016 00:00:17 +0000 (-0700) Subject: fixes and upgrades to guicast X-Git-Url: https://git.cinelerra-gg.org/git/?a=commitdiff_plain;h=3c8ddbb0c9c24084b516e15cdf3e7271e81ae13c;p=goodguy%2Fhistory.git fixes and upgrades to guicast --- diff --git a/cinelerra-5.0/guicast/bcfilebox.C b/cinelerra-5.0/guicast/bcfilebox.C index bf9c4e4a..005f9e27 100644 --- a/cinelerra-5.0/guicast/bcfilebox.C +++ b/cinelerra-5.0/guicast/bcfilebox.C @@ -210,24 +210,23 @@ BC_FileBoxDirectoryText::BC_FileBoxDirectoryText(int x, int y, BC_FileBox *fileb int BC_FileBoxDirectoryText::handle_event() { - const char *path; - path = get_text(); - // is a directory, change directories - if(filebox->fs->is_dir(path)) - { - const char *cp = path; - char dir_path[BCTEXTLEN], *dp = dir_path; - while( *cp ) *dp++ = *cp++; - while( dp >= dir_path && *--dp == '/' ); - *++dp = '/'; *++dp = 0; - if( strcmp(filebox->fs->get_current_dir(), dir_path) ) { - filebox->fs->change_dir(dir_path); - filebox->refresh(1); - } - update(dir_path); - return 1; + const char *path = get_text(); + if( !filebox->fs->is_dir(path) ) return 0; + const char *cp = path; + while( *cp ) ++cp; + if( cp > path && *--cp != '/' ) return 0; + char *file_path = FileSystem::basepath(path); + char *dir_path = FileSystem::basepath(filebox->fs->get_current_dir()); + int ret = !strcmp(file_path, dir_path) ? 0 : 1; + if( ret ) { + strcpy(filebox->directory, file_path); + filebox->update_history(); + filebox->fs->change_dir(file_path); + filebox->refresh(1); } - return 0; + delete [] dir_path; + delete [] file_path; + return ret; } @@ -473,7 +472,7 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path, : BC_Window(title, x, y, BC_WindowBase::get_resources()->filebox_w, BC_WindowBase::get_resources()->filebox_h, - 10, 10, 1, 0, 1) + 400, 300, 1, 0, 1) { fs = new FileSystem; // if(want_directory) @@ -547,6 +546,8 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path, strcpy(directory, fs->get_current_dir()); filename[0] = 0; } + else + fs->set_current_dir(this->directory); if(h_padding == -1) @@ -801,18 +802,10 @@ int BC_FileBox::handle_event() int BC_FileBox::extract_extension(char *out, const char *in) { - int i; - - for(i = strlen(in)-1; i > 0 && in[i] != '.'; i--) - { - ; - } - if(in[i] == '.') { - i++; - strcpy(out, &in[i]); - } - else - out[0] = '\0'; + *out = 0; + int i = strlen(in); + while( --i>=0 && in[i]!='.' ); + if( i >= 0 ) strcpy(out, &in[++i]); return 0; } @@ -845,7 +838,7 @@ int BC_FileBox::create_tables() // { if(!is_dir) { - sprintf(string, _LD, file_item->size); + sprintf(string, "%jd", file_item->size); new_item = new BC_ListBoxItem(string, get_resources()->file_color); } else @@ -880,13 +873,11 @@ int BC_FileBox::create_tables() // Extension entry // if(!want_directory) // { - if(!is_dir) - { + if(!is_dir) { extract_extension(string, file_item->name); new_item = new BC_ListBoxItem(string, get_resources()->file_color); } - else - { + else { new_item = new BC_ListBoxItem("", get_resources()->directory_color); } list_column[column_of_type(FILEBOX_EXTENSION)].append(new_item); diff --git a/cinelerra-5.0/guicast/bcfilebox.h b/cinelerra-5.0/guicast/bcfilebox.h index f201a722..509fa0d8 100644 --- a/cinelerra-5.0/guicast/bcfilebox.h +++ b/cinelerra-5.0/guicast/bcfilebox.h @@ -221,6 +221,7 @@ public: virtual ~BC_FileBox(); friend class BC_FileBoxCancel; + friend class BC_FileBoxDirectoryText; friend class BC_FileBoxListBox; friend class BC_FileBoxTextBox; friend class BC_FileBoxText; diff --git a/cinelerra-5.0/guicast/bchash.C b/cinelerra-5.0/guicast/bchash.C index 180c70de..a334658a 100644 --- a/cinelerra-5.0/guicast/bchash.C +++ b/cinelerra-5.0/guicast/bchash.C @@ -210,7 +210,7 @@ int64_t BC_Hash::get(const char *name, int64_t default_) { if(!strcmp(names[i], name)) { - sscanf(values[i], _LD, &result); + sscanf(values[i], "%jd", &result); return result; } } @@ -278,7 +278,7 @@ int BC_Hash::update(const char *name, int32_t value) // update a value if it exi int BC_Hash::update(const char *name, int64_t value) // update a value if it exists { char string[BCSTRLEN]; - sprintf(string, _LD, value); + sprintf(string, "%jd", value); return update(name, string); } diff --git a/cinelerra-5.0/guicast/bcmenu.C b/cinelerra-5.0/guicast/bcmenu.C index 7cfc69fa..4745a445 100644 --- a/cinelerra-5.0/guicast/bcmenu.C +++ b/cinelerra-5.0/guicast/bcmenu.C @@ -197,6 +197,8 @@ int BC_Menu::dispatch_cursor_leave() { if(active) { + if( !menu_popup->cursor_inside() ) + deactivate_menu(); menu_popup->dispatch_cursor_leave(); } unhighlight(); diff --git a/cinelerra-5.0/guicast/bcpopupmenu.C b/cinelerra-5.0/guicast/bcpopupmenu.C index e65b40d6..5adeed4c 100644 --- a/cinelerra-5.0/guicast/bcpopupmenu.C +++ b/cinelerra-5.0/guicast/bcpopupmenu.C @@ -509,6 +509,8 @@ int BC_PopupMenu::cursor_leave_event() // dispatch to popup if(popup_down) { + if( !menu_popup->cursor_inside() ) + deactivate_menu(); menu_popup->dispatch_cursor_leave(); } diff --git a/cinelerra-5.0/guicast/bcresources.C b/cinelerra-5.0/guicast/bcresources.C index d95a35b1..58d3c587 100644 --- a/cinelerra-5.0/guicast/bcresources.C +++ b/cinelerra-5.0/guicast/bcresources.C @@ -1401,13 +1401,20 @@ int BC_Resources::init_fontconfig(const char *search_path) return 0; } -BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, int mask) +#define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \ + !((fst) & ~(style) & (msk)) + +BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, + int mask, int preferred) { - BC_FontEntry *entry, *style_match, *displayname_match; + BC_FontEntry *entry, *style_match, *preferred_match; if(!fontlist) return 0; + style_match = 0; + preferred_match = 0; + if(displayname) { for(int i = 0; i < fontlist->total; i++) @@ -1415,34 +1422,49 @@ BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, i entry = fontlist->values[i]; if(strcmp(entry->displayname, displayname) == 0 && - (entry->style & mask) == style) - return entry; + STYLE_MATCH(entry->style, style, mask)) + { + if(!style_match) + style_match = entry; + if(!preferred_match && (entry->style & preferred)) + preferred_match = entry; + } } + if(preferred_match) + return preferred_match; + + if(style_match) + return style_match; } + // No exact match - assume normal width font style |= FL_WIDTH_NORMAL; mask |= FL_WIDTH_MASK; - style_match = 0; displayname_match = 0; + style_match = 0; + preferred_match = 0; + for(int i = 0; i < fontlist->total; i++) { entry = fontlist->values[i]; - if(!strncasecmp(displayname, entry->family, - strlen(entry->family))) - { - if((entry->style & mask) == style) - return entry; - if(!displayname_match) - displayname_match = entry; - } - - if((entry->style & mask) == style) + if(STYLE_MATCH(entry->style, style, mask)) { if(!style_match) style_match = entry; + + if(!preferred_match && (entry->style & preferred)) + preferred_match = entry; + + if(!strncasecmp(displayname, entry->family, + strlen(entry->family))) + return entry; } } - return displayname_match ? displayname_match : style_match; + + if(preferred_match) + return preferred_match; + + return style_match; } size_t BC_Resources::encode(const char *from_enc, const char *to_enc, @@ -1493,6 +1515,14 @@ size_t BC_Resources::encode(const char *from_enc, const char *to_enc, return inbytes; } +void BC_Resources::encode_to_utf8(char *buffer, int buflen) +{ + if(BC_Resources::locale_utf8) return; + char lbuf[buflen]; + encode(encoding, 0, buffer, buflen, lbuf, buflen); + strcpy(buffer, lbuf); +} + int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface) { FcPattern *font, *ofont; diff --git a/cinelerra-5.0/guicast/bcresources.h b/cinelerra-5.0/guicast/bcresources.h index f2b28205..91199a49 100644 --- a/cinelerra-5.0/guicast/bcresources.h +++ b/cinelerra-5.0/guicast/bcresources.h @@ -347,7 +347,9 @@ public: static const char *wide_encoding; static ArrayList *fontlist; static int init_fontconfig(const char *search_path); - static BC_FontEntry *find_fontentry(const char *displayname, int style, int mask); + static BC_FontEntry *find_fontentry(const char *displayname, int style, + int mask, int preferred_style = 0); + static void encode_to_utf8(char *buffer, int buflen); static FcPattern* find_similar_font(FT_ULong char_code, FcPattern *oldfont); static size_t encode(const char *from_enc, const char *to_enc, char *input, int input_length, char *output, int output_length); diff --git a/cinelerra-5.0/guicast/bctextbox.C b/cinelerra-5.0/guicast/bctextbox.C index cab68664..12f32b85 100644 --- a/cinelerra-5.0/guicast/bctextbox.C +++ b/cinelerra-5.0/guicast/bctextbox.C @@ -101,7 +101,7 @@ BC_TextBox::BC_TextBox(int x, int y, int w, int rows, is_utf8 = 1; skip_cursor = 0; reset_parameters(rows, has_border, font, BCSTRLEN); - snprintf(this->text, this->tsize, _LD, text); + snprintf(this->text, this->tsize, "%jd", text); dirty = 1; wtext_update(); } @@ -514,7 +514,7 @@ int BC_TextBox::update(const wchar_t *wtext) int BC_TextBox::update(int64_t value) { char string[BCTEXTLEN]; - sprintf(string, _LD, value); + sprintf(string, "%jd", value); update(string); return 0; } diff --git a/cinelerra-5.0/guicast/bcwindowbase.C b/cinelerra-5.0/guicast/bcwindowbase.C index 87403ec8..2d43b62b 100644 --- a/cinelerra-5.0/guicast/bcwindowbase.C +++ b/cinelerra-5.0/guicast/bcwindowbase.C @@ -160,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(); @@ -2282,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); } diff --git a/cinelerra-5.0/guicast/bcwindowdraw.C b/cinelerra-5.0/guicast/bcwindowdraw.C index 0b1f488c..635679ea 100644 --- a/cinelerra-5.0/guicast/bcwindowdraw.C +++ b/cinelerra-5.0/guicast/bcwindowdraw.C @@ -142,30 +142,29 @@ void BC_WindowBase::draw_text(int x, int y, const char *text, int length, break; default: { - if(top_level->get_xft_struct(top_level->current_font)) { - draw_xft_text(x, y, text, length, pixmap); - return; - } + if(top_level->get_xft_struct(top_level->current_font)) { + draw_xft_text(x, y, text, length, pixmap); + return; + } - for(int i = 0, j = 0; i <= length; i++) { - if(text[i] == '\n' || text[i] == 0) { - if(get_resources()->use_fontset && top_level->get_curr_fontset()) { - XmbDrawString(top_level->display, - pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, - top_level->get_curr_fontset(), - top_level->gc, x, y, &text[j], i-j); - } - else { - XDrawString(top_level->display, - pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, - top_level->gc, x, y, &text[j], i-j); - } - j = i; - y += get_text_height(font); + for(int i = 0, j = 0; i <= length; i++) { + if(text[i] == '\n' || text[i] == 0) { + if(get_resources()->use_fontset && top_level->get_curr_fontset()) { + XmbDrawString(top_level->display, + pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, + top_level->get_curr_fontset(), + top_level->gc, x, y, &text[j], i-j); } + else { + XDrawString(top_level->display, + pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, + top_level->gc, x, y, &text[j], i-j); + } + j = i + 1; + y += get_text_height(font); } } - break; + break; } } } diff --git a/cinelerra-5.0/guicast/units.C b/cinelerra-5.0/guicast/units.C index dccdb682..c1b48621 100644 --- a/cinelerra-5.0/guicast/units.C +++ b/cinelerra-5.0/guicast/units.C @@ -213,22 +213,22 @@ char* Units::totext(char *text, double seconds, int time_format, break; } case TIME_SAMPLES: { - sprintf(text, _LDv(09), to_int64(seconds * sample_rate)); + sprintf(text, "%09jd", to_int64(seconds * sample_rate)); break; } case TIME_SAMPLES_HEX: { - sprintf(text, _LXv(08), to_int64(seconds * sample_rate)); + sprintf(text, "%08jx", to_int64(seconds * sample_rate)); break; } case TIME_FRAMES: { frame = to_int64(seconds * frame_rate); - sprintf(text, _LDv(06), frame); + sprintf(text, "%06jd", frame); break; } case TIME_FEET_FRAMES: { frame = to_int64(seconds * frame_rate); feet = (int64_t)(frame / frames_per_foot); - sprintf(text, _LDv(05) "-" _LDv(02), feet, + sprintf(text, "%05jd-%02jd", feet, (int64_t)(frame - feet * frames_per_foot)); break; } @@ -325,7 +325,7 @@ int64_t Units::fromtext(const char *text, int samplerate, int time_format, return get_int64(text); } case TIME_SAMPLES_HEX: { - sscanf(text, _LX, &total_samples); + sscanf(text, "%jx", &total_samples); return total_samples; } case TIME_FRAMES: { @@ -520,12 +520,12 @@ char* Units::size_totext(int64_t bytes, char *text) if( i > 0 ) { bytes >>= 10*(i-1); int frac = bytes % 1000; - sprintf(string, _LD, bytes/1000); + sprintf(string, "%jd", bytes/1000); if( bytes > 1000 ) punctuate(string); sprintf(text, "%s.%03d %s", string, frac, sz[i]); } else { - sprintf(string, _LD, bytes); + sprintf(string, "%jd", bytes); if( bytes > 1000 ) punctuate(string); sprintf(text, "%s %s", string, sz[i]); }