Merged upstream clangen/PDCurses changes that allow for specifying a

preferred font, and default menu bar visibility.
This commit is contained in:
casey langen 2018-02-18 13:51:03 -08:00
parent c2fa156dc9
commit a840728083
3 changed files with 64 additions and 2 deletions

View File

@ -1770,6 +1770,9 @@ void PDC_set_resize_limits( const int new_min_lines,
int PDC_set_function_key( const unsigned function, int PDC_set_function_key( const unsigned function,
const int new_key); const int new_key);
int PDC_set_preferred_fontface( const wchar_t* fontface);
void PDC_set_default_menu_visibility(int visible);
WINDOW *Xinitscr(int, char **); WINDOW *Xinitscr(int, char **);
#ifdef XCURSES #ifdef XCURSES
void XCursesExit(void); void XCursesExit(void);

View File

@ -222,13 +222,59 @@ static LONG scale_font_for_current_dpi( LONG size)
} }
int PDC_font_size = -1; int PDC_font_size = -1;
TCHAR PDC_font_name[80]; TCHAR PDC_font_name[128];
TCHAR PDC_preferred_fontface[128]; /* can be set by application */
static TCHAR* PDC_default_font_name = _T("Courier New");
/* The calling application can override the default fontface with
their preferred one. If that font fails to load, we will fallback
to the global default (currently "Courier New") */
int PDC_set_preferred_fontface( const TCHAR* fontface)
{
int len = fontface == 0 ? 0 : wcslen( fontface);
if ( len < sizeof( PDC_preferred_fontface))
{
wcsncpy( PDC_preferred_fontface, fontface, len);
return 1;
}
return 0;
}
static int CALLBACK EnumFontCallback(
ENUMLOGFONT* lplf, NEWTEXTMETRIC* lpntm, DWORD type, LPVOID user)
{
/* we specified a filter in PDC_fontface_exists, so if we get here
at all, that means the font exists. */
*((int*)user) = 1;
return 1;
}
static int PDC_fontface_exists( const TCHAR* fontface)
{
extern HWND PDC_hWnd;
int result = 0;
LOGFONT lf = { 0 };
HDC hdc;
hdc = GetDC( PDC_hWnd);
wcscpy( lf.lfFaceName, fontface);
EnumFontFamiliesEx( hdc, &lf, EnumFontCallback, (LPARAM) &result, 0);
ReleaseDC( PDC_hWnd, hdc);
return result != 0;
}
static LOGFONT PDC_get_logical_font( const int font_idx) static LOGFONT PDC_get_logical_font( const int font_idx)
{ {
if ( PDC_font_size < 0) if ( PDC_font_size < 0)
{ {
PDC_font_size = scale_font_for_current_dpi(12); /* default 12 points */ PDC_font_size = scale_font_for_current_dpi( 15); /* default 15 points */
}
/* see if the user has overridden the default fontface. */
if ( wcslen( PDC_font_name) == 0 && PDC_fontface_exists(PDC_preferred_fontface))
{
wcsncpy( PDC_font_name, PDC_preferred_fontface, sizeof(PDC_font_name));
} }
LOGFONT lf; LOGFONT lf;

View File

@ -2277,6 +2277,19 @@ int PDC_set_function_key( const unsigned function, const int new_key)
return( old_key); return( old_key);
} }
/* Used to define whether or not the Font/Paste menu is visible by default.
If this method is not call, it will be true. Must be called before the main
window has been created. */
void PDC_set_default_menu_visibility( int visible)
{
extern HWND PDC_hWnd;
if ( !PDC_hWnd)
{
menu_shown = (visible) ? 1 : 0;
}
}
/* https://msdn.microsoft.com/en-us/library/windows/desktop/dd162826(v=vs.85).aspx /* https://msdn.microsoft.com/en-us/library/windows/desktop/dd162826(v=vs.85).aspx
The code at the above link provides general methods for positioning a window The code at the above link provides general methods for positioning a window
on a multiple-display setup. The only instance we're using is the on a multiple-display setup. The only instance we're using is the