Wineconsole (again)

Eric Pouech eric.pouech at wanadoo.fr
Mon May 20 14:50:03 CDT 2002


this patch fixes a set of issues:
1/ large fonts could be picked up if no decent registry content was
found 
   (thanks to Sylvain Petreolle and Andi Mohr for the bug reports)
2/ better error messages in case of failure (even if I'm sure Andi will 
   not like them... feel free to be more verbose)
3/ removed some unneeded DC creation

it also starts to implement the ability not to close the console once
the console object has been destroyed in the server. this let you look
at the output of a program after it exited
as of today, it's a registry only setting, the UI part will be added 
later on

A+
-------------- next part --------------
Name:          wc_fntexit
ChangeLog:     allow ANSI charset in font enumeration
	added ability not to close the wineconsole on console object destruction
License:       X11
GenDate:       2002/05/20 19:17:10 UTC
ModifiedFiles: programs/wineconsole/dialog.c  programs/wineconsole/registry.c programs/wineconsole/user.c programs/wineconsole/winecon_private.h programs/wineconsole/wineconsole.c
AddedFiles:    
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/wineconsole/dialog.c,v
retrieving revision 1.8
diff -u -u -r1.8 dialog.c
--- programs/wineconsole/dialog.c	14 May 2002 21:45:13 -0000	1.8
+++ programs/wineconsole/dialog.c	20 May 2002 14:48:46 -0000
@@ -409,25 +409,23 @@
 			      DWORD FontType, LPARAM lParam)
 {
     struct dialog_info*	di = (struct dialog_info*)lParam;
-    HDC	hdc;
 
-    WCUSER_DumpLogFont("font", lf, FontType);
-    if (WCUSER_ValidateFont(di->data, lf) && (hdc = GetDC(di->hDlg)))
+    WCUSER_DumpLogFont("DlgFamily: ", lf, FontType);
+    if (WCUSER_ValidateFont(di->data, lf))
     {
         if (FontType & RASTER_FONTTYPE)
         {
             di->nFont = 0;
-            EnumFontFamilies(hdc, lf->lfFaceName, font_enum_size2, (LPARAM)di);
+            EnumFontFamilies(PRIVATE(di->data)->hMemDC, lf->lfFaceName, font_enum_size2, (LPARAM)di);
         }
         else
             di->nFont = 1;
         
         if (di->nFont)
 	{
-	    SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_FONT, LB_ADDSTRING, 
+ 	    SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_FONT, LB_ADDSTRING, 
                                0, (LPARAM)lf->lfFaceName);
         }
-	ReleaseDC(di->hDlg, hdc);
     }
 
     return 1;
@@ -552,24 +550,19 @@
  */
 static BOOL  fill_list_size(struct dialog_info* di, BOOL doInit)
 {
-    HDC 	hdc;
     int		idx;
     WCHAR	lfFaceName[LF_FACESIZE];
 
     idx = SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_FONT, LB_GETCURSEL, 0L, 0L);
     if (idx < 0) return FALSE;
     
-    hdc = GetDC(di->hDlg);
-    if (!hdc) return FALSE;
-
     SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_FONT, LB_GETTEXT, idx, (LPARAM)lfFaceName);
     SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_SIZE, LB_RESETCONTENT, 0L, 0L);
     if (di->font) HeapFree(GetProcessHeap(), 0, di->font);
     di->nFont = 0;
     di->font = NULL;
 
-    EnumFontFamilies(hdc, lfFaceName, font_enum_size, (LPARAM)di);
-    ReleaseDC(di->hDlg, hdc);
+    EnumFontFamilies(PRIVATE(di->data)->hMemDC, lfFaceName, font_enum_size, (LPARAM)di);
 
     if (doInit)
     {
@@ -601,14 +594,8 @@
  */
 static BOOL fill_list_font(struct dialog_info* di)
 {
-    HDC hdc;
-
-    hdc = GetDC(di->hDlg);
-    if (!hdc) return FALSE;
-
     SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_FONT, LB_RESETCONTENT, 0L, 0L);
-    EnumFontFamilies(hdc, NULL, font_enum, (LPARAM)di);
-    ReleaseDC(di->hDlg, hdc);
+    EnumFontFamilies(PRIVATE(di->data)->hMemDC, NULL, font_enum, (LPARAM)di);
     if (SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_FONT, LB_SELECTSTRING, 
 			   (WPARAM)-1, (LPARAM)di->config->face_name) == LB_ERR)
 	SendDlgItemMessage(di->hDlg, IDC_FNT_LIST_FONT, LB_SETCURSEL, 0L, 0L);
Index: programs/wineconsole/registry.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/wineconsole/registry.c,v
retrieving revision 1.5
diff -u -u -r1.5 registry.c
--- programs/wineconsole/registry.c	14 May 2002 21:45:13 -0000	1.5
+++ programs/wineconsole/registry.c	20 May 2002 14:30:29 -0000
@@ -30,6 +30,7 @@
 static const WCHAR wszConsole[]           = {'C','o','n','s','o','l','e',0};
 static const WCHAR wszCursorSize[]        = {'C','u','r','s','o','r','S','i','z','e',0};
 static const WCHAR wszCursorVisible[]     = {'C','u','r','s','o','r','V','i','s','i','b','l','e',0};
+static const WCHAR wszExitOnDie[]         = {'E','x','i','t','O','n','D','i','e',0};
 static const WCHAR wszFaceName[]          = {'F','a','c','e','N','a','m','e',0};
 static const WCHAR wszFontSize[]          = {'F','o','n','t','S','i','z','e',0};
 static const WCHAR wszFontWeight[]        = {'F','o','n','t','W','e','i','g','h','t',0};
@@ -64,6 +65,11 @@
         val = 1;
     cfg->cursor_visible = val;
 
+    count = sizeof(val);
+    if (!hConKey || RegQueryValueEx(hConKey, wszExitOnDie, 0, &type, (char*)&val, &count)) 
+        val = 1;
+    cfg->exit_on_die = val;
+
     count = sizeof(cfg->face_name); 
     if (!hConKey || RegQueryValueEx(hConKey, wszFaceName, 0, &type, (char*)&cfg->face_name, &count))
         cfg->face_name[0] = 0;
@@ -138,6 +144,9 @@
 
     val = cfg->cursor_visible;
     RegSetValueEx(hConKey, wszCursorVisible, 0, REG_DWORD, (char*)&val, sizeof(val));
+
+    val = cfg->exit_on_die;
+    RegSetValueEx(hConKey, wszExitOnDie, 0, REG_DWORD, (char*)&val, sizeof(val));
 
     RegSetValueEx(hConKey, wszFaceName, 0, REG_SZ, (char*)&cfg->face_name, sizeof(cfg->face_name));
 
Index: programs/wineconsole/user.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/wineconsole/user.c,v
retrieving revision 1.9
diff -u -u -r1.9 user.c
--- programs/wineconsole/user.c	14 May 2002 21:45:13 -0000	1.9
+++ programs/wineconsole/user.c	20 May 2002 17:11:54 -0000
@@ -64,7 +64,7 @@
 	for (i = 0; i < data->curcfg.sb_width; i++)
 	{
 	    attr = cell[i].Attributes;
-	    SetBkColor(PRIVATE(data)->hMemDC,WCUSER_ColorMap[(attr>>4)&0x0F]);
+	    SetBkColor(PRIVATE(data)->hMemDC, WCUSER_ColorMap[(attr>>4)&0x0F]);
 	    SetTextColor(PRIVATE(data)->hMemDC, WCUSER_ColorMap[attr&0x0F]);
 	    for (k = i; k < data->curcfg.sb_width && cell[k].Attributes == attr; k++)
 	    {
@@ -90,7 +90,8 @@
     HDC         hDC;
     HBITMAP	hnew, hold;
 
-    if (!data->curcfg.sb_width || !data->curcfg.sb_height || !(hDC = GetDC(PRIVATE(data)->hWnd))) 
+    if (!data->curcfg.sb_width || !data->curcfg.sb_height || 
+        !PRIVATE(data)->hFont || !(hDC = GetDC(PRIVATE(data)->hWnd)))
         return;
     hnew = CreateCompatibleBitmap(hDC, 
 				  data->curcfg.sb_width  * data->curcfg.cell_width, 
@@ -328,7 +329,7 @@
         ret = (tm->tmMaxCharWidth * data->curcfg.win_width < GetSystemMetrics(SM_CXSCREEN) &&
                tm->tmHeight * data->curcfg.win_height < GetSystemMetrics(SM_CYSCREEN));
     return ret && !tm->tmItalic && !tm->tmUnderlined && !tm->tmStruckOut &&
-        (tm->tmCharSet == DEFAULT_CHARSET /*|| tm->tmCharSet == ANSI_CHARSET*/);
+        (tm->tmCharSet == DEFAULT_CHARSET || tm->tmCharSet == ANSI_CHARSET);
 }
 
 /******************************************************************
@@ -355,19 +356,31 @@
     struct font_chooser*	fc = (struct font_chooser*)lParam;
 
     WCUSER_DumpTextMetric(tm, FontType);
-
-    if (WCUSER_ValidateFontMetric(fc->data, tm, FontType) && 
-        WCUSER_SetFont(fc->data, lf))
+    if (WCUSER_ValidateFontMetric(fc->data, tm, FontType))
     {
-        fc->done = 1;
-        /* since we've modified the current config with new font information, 
-         * set it as the new default.
-         * Force also its writing back to the registry so that we can get it
-         * the next time
+        LOGFONT mlf = *lf;
+
+        /* Use the default sizes for the font (this is needed, especially for
+         * TrueType fonts, so that we get a decent size, not the max size) 
          */
-        fc->data->defcfg = fc->data->curcfg;
-        WINECON_RegSave(&fc->data->defcfg);
-        return 0;
+        mlf.lfWidth  = fc->data->curcfg.cell_width;
+        mlf.lfHeight = fc->data->curcfg.cell_height;
+        if (WCUSER_SetFont(fc->data, &mlf))
+        {
+            WCUSER_DumpLogFont("InitChoosing: ", &mlf, FontType);
+            fc->done = 1;
+            /* since we've modified the current config with new font information, 
+             * set this information as the new default.
+             */
+            fc->data->defcfg.cell_width = fc->data->curcfg.cell_width;
+            fc->data->defcfg.cell_height = fc->data->curcfg.cell_height;
+            lstrcpyW(fc->data->defcfg.face_name, fc->data->curcfg.face_name);
+            /* Force also its writing back to the registry so that we can get it
+             * the next time.
+             */
+            WINECON_RegSave(&fc->data->defcfg);
+            return 0;
+        }
     }
     return 1;
 }
@@ -377,8 +390,7 @@
 {
     struct font_chooser*	fc = (struct font_chooser*)lParam;
 
-    WCUSER_DumpLogFont("init", lf, FontType);
-
+    WCUSER_DumpLogFont("InitFamily: ", lf, FontType);
     if (WCUSER_ValidateFont(fc->data, lf))
     {
 	EnumFontFamilies(PRIVATE(fc->data)->hMemDC, lf->lfFaceName, 
@@ -431,7 +443,8 @@
         {
             if (buf[j] != w)
             {
-                WINE_WARN("Non uniform cell width: [%d]=%d [%d]=%d\n", 
+                WINE_WARN("Non uniform cell width: [%d]=%d [%d]=%d\n"
+                          "This may be caused by old freetype libraries, >= 2.0.8 is recommended\n", 
                           i + j, buf[j], tm.tmFirstChar, w);
                 goto err;
             }
@@ -515,6 +528,7 @@
 {
     struct font_chooser fc;
 
+    WINE_TRACE_(wc_font)("=> %s\n", wine_dbgstr_wn(data->curcfg.face_name, -1));
     if (data->curcfg.face_name[0] != '\0' &&
         data->curcfg.cell_height != 0 &&
         data->curcfg.font_weight != 0)
@@ -525,7 +539,11 @@
                            data->curcfg.cell_height, data->curcfg.font_weight);
         if (PRIVATE(data)->hFont != 0) WINE_FIXME("Oh strange\n");
 
-        if (WCUSER_SetFont(data, &lf)) return TRUE;
+        if (WCUSER_SetFont(data, &lf)) 
+        {
+            WCUSER_DumpLogFont("InitReuses: ", &lf, 0);
+            return TRUE;
+        }
     }
 
     /* try to find an acceptable font */
@@ -533,6 +551,7 @@
     fc.data = data;
     fc.done = 0;
     EnumFontFamilies(PRIVATE(data)->hMemDC, NULL, get_first_font_enum, (LPARAM)&fc);
+    if (!fc.done) WINE_WARN("Couldn't find a decent font, aborting\n");
     return fc.done;
 }
 
@@ -1308,10 +1327,10 @@
 void WCUSER_DeleteBackend(struct inner_data* data)
 {
     if (!PRIVATE(data)) return;
+    if (PRIVATE(data)->hMemDC)		DeleteDC(PRIVATE(data)->hMemDC);
     if (PRIVATE(data)->hWnd)		DestroyWindow(PRIVATE(data)->hWnd);
     if (PRIVATE(data)->hFont)		DeleteObject(PRIVATE(data)->hFont);
     if (PRIVATE(data)->cursor_bitmap)	DeleteObject(PRIVATE(data)->cursor_bitmap);
-    if (PRIVATE(data)->hMemDC)		DeleteDC(PRIVATE(data)->hMemDC);
     if (PRIVATE(data)->hBitmap)		DeleteObject(PRIVATE(data)->hBitmap);
     HeapFree(GetProcessHeap(), 0, PRIVATE(data));
 }
@@ -1330,8 +1349,8 @@
 	switch (MsgWaitForMultipleObjects(1, &data->hSynchro, FALSE, INFINITE, QS_ALLINPUT))
 	{
 	case WAIT_OBJECT_0:
-	    if (!WINECON_GrabChanges(data))
-		PostQuitMessage(0);
+	    if (!WINECON_GrabChanges(data) && data->curcfg.exit_on_die)
+                PostQuitMessage(0);
 	    break;
 	case WAIT_OBJECT_0+1:
 	    switch (GetMessage(&msg, 0, 0, 0))
Index: programs/wineconsole/winecon_private.h
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/wineconsole/winecon_private.h,v
retrieving revision 1.5
diff -u -u -r1.5 winecon_private.h
--- programs/wineconsole/winecon_private.h	14 May 2002 21:45:13 -0000	1.5
+++ programs/wineconsole/winecon_private.h	20 May 2002 13:17:09 -0000
@@ -40,6 +40,7 @@
     unsigned	win_width;	/* size (in cells) of visible part of window (width & height) */
     unsigned	win_height;
     COORD	win_pos;	/* position (in cells) of visible part of screen buffer in window */
+    BOOL        exit_on_die;    /* whether the wineconsole should quit if server destroys the console */
 };
 
 struct inner_data {


More information about the wine-patches mailing list