fixes and upgrades to guicast
authorGood Guy <good1.2guy@gmail.com>
Sat, 27 Feb 2016 00:00:17 +0000 (17:00 -0700)
committerGood Guy <good1.2guy@gmail.com>
Sat, 27 Feb 2016 00:00:17 +0000 (17:00 -0700)
cinelerra-5.0/guicast/bcfilebox.C
cinelerra-5.0/guicast/bcfilebox.h
cinelerra-5.0/guicast/bchash.C
cinelerra-5.0/guicast/bcmenu.C
cinelerra-5.0/guicast/bcpopupmenu.C
cinelerra-5.0/guicast/bcresources.C
cinelerra-5.0/guicast/bcresources.h
cinelerra-5.0/guicast/bctextbox.C
cinelerra-5.0/guicast/bcwindowbase.C
cinelerra-5.0/guicast/bcwindowdraw.C
cinelerra-5.0/guicast/units.C

index bf9c4e4ab61cef57b5b0d6a72585bd6f6dd200e7..005f9e2790ec4910cf012f96ce7e799a9dbd35f4 100644 (file)
@@ -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);
index f201a7224ce9f3115cdd30faade2a3d41bae9fff..509fa0d850a95476f18228fb2bd4847b8a982ed8 100644 (file)
@@ -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;
index 180c70de7897c8c9074845fd5ec96f4886270eac..a334658a8cdd03ee1258d87e1fd33c6e5830a5a8 100644 (file)
@@ -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);
 }
 
index 7cfc69fa374cfef1da69c651d8561fae079d7711..4745a445c49c3287a62c8da455c7319c693277e3 100644 (file)
@@ -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();
index e65b40d6552b11d7ecfb5ee0f507376c9148ba7e..5adeed4c37b21b7c60548e14eae5dcb22ca70ef3 100644 (file)
@@ -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();
        }
 
index d95a35b1496ed04ecffde988e134644e24702743..58d3c5879cfc0b08a29f4038254cacdb69e43b68 100644 (file)
@@ -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;
index f2b282050ae545bf089ef2f9e36fa73dca05f0d1..91199a490bb12a568a7a09142395abd5281f5f99 100644 (file)
@@ -347,7 +347,9 @@ public:
        static const char *wide_encoding;
        static ArrayList<BC_FontEntry*> *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);
index cab6866429f0375cb40b9a6146bbb5b9e9396b4c..12f32b85a02453717ab8f5a17676ea98c0eec8aa 100644 (file)
@@ -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;
 }
index 87403ec8f770159eebf06bd024b3f848a41ed1c8..2d43b62bfd6544ddb40cce46f6a2d9c8e4899629 100644 (file)
@@ -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);
        }
index 0b1f488ce29bfccdc46efd08b516750fbef794e5..635679ea43a7670e607bd0fddedbd069ea0408c9 100644 (file)
@@ -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; }
        }
 }
 
index dccdb6829362edd7eb69395a5ca740179e3c2f17..c1b486211205c00c952a2ac73005fb791b42ca2a 100644 (file)
@@ -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]);
        }