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;
}
: 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)
strcpy(directory, fs->get_current_dir());
filename[0] = 0;
}
+ else
+ fs->set_current_dir(this->directory);
if(h_padding == -1)
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;
}
// {
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
// 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);
virtual ~BC_FileBox();
friend class BC_FileBoxCancel;
+ friend class BC_FileBoxDirectoryText;
friend class BC_FileBoxListBox;
friend class BC_FileBoxTextBox;
friend class BC_FileBoxText;
{
if(!strcmp(names[i], name))
{
- sscanf(values[i], _LD, &result);
+ sscanf(values[i], "%jd", &result);
return result;
}
}
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);
}
{
if(active)
{
+ if( !menu_popup->cursor_inside() )
+ deactivate_menu();
menu_popup->dispatch_cursor_leave();
}
unhighlight();
// dispatch to popup
if(popup_down)
{
+ if( !menu_popup->cursor_inside() )
+ deactivate_menu();
menu_popup->dispatch_cursor_leave();
}
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++)
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,
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;
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);
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();
}
int BC_TextBox::update(int64_t value)
{
char string[BCTEXTLEN];
- sprintf(string, _LD, value);
+ sprintf(string, "%jd", value);
update(string);
return 0;
}
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();
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);
}
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; }
}
}
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; }
return get_int64(text); }
case TIME_SAMPLES_HEX: {
- sscanf(text, _LX, &total_samples);
+ sscanf(text, "%jx", &total_samples);
return total_samples; }
case TIME_FRAMES: {
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]);
}