<URL: http://bugs.freeciv.org/Ticket/Display.html?id=26924 >

> [emj - Fr 01. Dez 2006, 16:15:02]:
> 
> 1.  open a treaty dialog
> 2.  add nine or ten treaty clauses
> 3.  crash
> 
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread -1214245200 (LWP 28988)]
> del_widget_from_vertical_scroll_widget_list (pDlg=0x99426e0,
> pWidget=0x95a5af8)
>     at gui_stuff.c:2077
> 2077              pBuf->gfx = pBuf->prev->gfx;
> (gdb) bt
> #0  del_widget_from_vertical_scroll_widget_list (pDlg=0x99426e0,
>     pWidget=0x95a5af8) at gui_stuff.c:2077
> #1  0x0810317e in remove_clause_widget_from_list (
>     counterpart=<value optimized out>, giver=0, type=CLAUSE_ALLIANCE,
> value=0)
>     at diplodlg.c:1083
> #2  0x081037d0 in handle_diplomacy_create_clause (counterpart=3,
> giver=0,
>     type=CLAUSE_ADVANCE, value=13) at diplodlg.c:170
> #3  0x0806c3d7 in client_handle_packet
> (type=PACKET_DIPLOMACY_CREATE_CLAUSE,
>     packet=0x0) at packhand_gen.c:188
> #4  0x0804f889 in handle_packet_input (packet=0xf2, type=78) at
> civclient.c:400
> #5  0x08053ab1 in input_from_server (fd=13) at clinet.c:379
> #6  0x0810dd57 in gui_event_loop (pData=0x0, loop_action=0,
>     key_down_handler=0x810d370 <main_key_down_handler>,
>     key_up_handler=0x810cf40 <main_key_up_handler>,
>     mouse_button_down_handler=0x810d2b0
> <main_mouse_button_down_handler>,
>     mouse_button_up_handler=0x810d210 <main_mouse_button_up_handler>,
>     mouse_motion_handler=0x810cf60 <main_mouse_motion_handler>)
>     at gui_main.c:704
> #7  0x0810e0c7 in ui_main (argc=1, argv=0xbfa1aa14) at gui_main.c:971
> #8  0x080503c5 in main (argc=2, argv=0xbfa1aa14) at civclient.c:357
> 
> 

Here's a small patch for 2.1.0-beta2 and a bigger one for SVN trunk that
fixes some more problems I found while playing around with the treaty
dialog. Your savegame still loads fine in the development version and
there are also some other problems of the beta2 version fixed in it, so
perhaps a recent snapshot of the development version
(http://svn.gna.org/daily/freeciv-snapshot.tar.gz) might be more
interesting for you if you want to continue playing with the SDL client.

Index: client/gui-sdl/gotodlg.c
===================================================================
--- client/gui-sdl/gotodlg.c	(Revision 12411)
+++ client/gui-sdl/gotodlg.c	(Arbeitskopie)
@@ -175,12 +175,14 @@
     } city_list_iterate_end;
   }
 
-  if(n) {
-    pGotoDlg->pBeginActiveWidgetList = pBuf;
+  if (n > 0) {
     pGotoDlg->pBeginWidgetList = pBuf;
+    
+    pGotoDlg->pBeginActiveWidgetList = pGotoDlg->pBeginWidgetList;
     pGotoDlg->pEndActiveWidgetList = pLast->prev;
-    pGotoDlg->pActiveWidgetList = pLast->prev;
+    pGotoDlg->pActiveWidgetList = pGotoDlg->pEndActiveWidgetList;
     pGotoDlg->pScroll->count = n;
+    
     if (n > 17)
     {
       show_scrollbar(pGotoDlg->pScroll);
Index: client/gui-sdl/citydlg.c
===================================================================
--- client/gui-sdl/citydlg.c	(Revision 12411)
+++ client/gui-sdl/citydlg.c	(Arbeitskopie)
@@ -755,10 +755,10 @@
   
   pCityDlg->pPanel = fc_calloc(1, sizeof(struct ADVANCED_DLG));
   pCityDlg->pPanel->pEndWidgetList = pEnd;
-  pCityDlg->pPanel->pEndActiveWidgetList = pEnd;
-  pCityDlg->pPanel->pBeginWidgetList = pBuf;
-  pCityDlg->pPanel->pBeginActiveWidgetList = pBuf;
-  pCityDlg->pPanel->pActiveWidgetList = pEnd;
+  pCityDlg->pPanel->pBeginWidgetList = pBuf;  
+  pCityDlg->pPanel->pEndActiveWidgetList = pCityDlg->pPanel->pEndWidgetList;
+  pCityDlg->pPanel->pBeginActiveWidgetList = pCityDlg->pPanel->pBeginWidgetList;
+  pCityDlg->pPanel->pActiveWidgetList = pCityDlg->pPanel->pEndActiveWidgetList;
   
   setup_vertical_widgets_position(NUM_UNITS_SHOWN,
 	pWindow->size.x + adj_size(7),
@@ -906,7 +906,7 @@
       else
         BV_SET(new_options, CITYO_NEW_TAXMAN);
     
-      pWidget->gfx = get_tax_surface(O_GOLD);
+      pWidget->theme2 = get_tax_surface(O_GOLD);
       pWidget->ID = MAX_ID - 0x40;
       widget_redraw(pWidget);
       widget_flush(pWidget);
@@ -914,7 +914,7 @@
     case 0x40:
       BV_CLR(new_options, CITYO_NEW_EINSTEIN);
       BV_CLR(new_options, CITYO_NEW_TAXMAN);
-      pWidget->gfx = get_tax_surface(O_LUXURY);
+      pWidget->theme2 = get_tax_surface(O_LUXURY);
       pWidget->ID = MAX_ID - 0x60;
       widget_redraw(pWidget);
       widget_flush(pWidget);
@@ -924,7 +924,7 @@
         BV_CLR(new_options, CITYO_NEW_EINSTEIN);
       else
         BV_SET(new_options, CITYO_NEW_EINSTEIN);
-      pWidget->gfx = get_tax_surface(O_SCIENCE);
+      pWidget->theme2 = get_tax_surface(O_SCIENCE);
       pWidget->ID = MAX_ID - 0x20;
       widget_redraw(pWidget);
       widget_flush(pWidget);
@@ -3573,13 +3573,12 @@
 
   if (count) {
     pCityDlg->pImprv->pEndWidgetList = pLast->prev;
-    pCityDlg->pImprv->pEndActiveWidgetList = pLast->prev;
+    pCityDlg->pImprv->pEndActiveWidgetList = pCityDlg->pImprv->pEndWidgetList;
     pCityDlg->pImprv->pBeginWidgetList = pBuf;
-    pCityDlg->pImprv->pBeginActiveWidgetList = pBuf;
+    pCityDlg->pImprv->pBeginActiveWidgetList = pCityDlg->pImprv->pBeginWidgetList;
 
     if (count > 8) {
-      pCityDlg->pImprv->pActiveWidgetList =
-		    pCityDlg->pImprv->pEndActiveWidgetList;
+      pCityDlg->pImprv->pActiveWidgetList = pCityDlg->pImprv->pEndActiveWidgetList;
       
 /* FIXME: this can probably be removed */
 #if 0
Index: client/gui-sdl/optiondlg.c
===================================================================
--- client/gui-sdl/optiondlg.c	(Revision 12409)
+++ client/gui-sdl/optiondlg.c	(Arbeitskopie)
@@ -351,10 +351,10 @@
     
     pOption_Dlg->pADlg->pEndActiveWidgetList =
                     pOption_Dlg->pBeginMainOptionsWidgetList->prev->prev;
+
+    pOption_Dlg->pADlg->pBeginWidgetList = pBuf;    
+    pOption_Dlg->pADlg->pBeginActiveWidgetList = pOption_Dlg->pADlg->pBeginWidgetList;
     
-    pOption_Dlg->pADlg->pBeginActiveWidgetList = pBuf;
-    pOption_Dlg->pADlg->pBeginWidgetList = pBuf;
-    
 /* FIXME: this can probably be removed */
 #if 0
     pOption_Dlg->pADlg->pScroll = fc_calloc(1, sizeof(struct ScrollBar));
@@ -369,8 +369,7 @@
           area.x + area.w - 1, area.y + 1, area.h - adj_size(32), TRUE);
     
     if(count>13) {
-      pOption_Dlg->pADlg->pActiveWidgetList =
-                                  pOption_Dlg->pADlg->pEndActiveWidgetList;
+      pOption_Dlg->pADlg->pActiveWidgetList = pOption_Dlg->pADlg->pEndActiveWidgetList;
     } else {
       hide_scrollbar(pOption_Dlg->pADlg->pScroll);
       scrollbar_width = 0;
Index: client/gui-sdl/mapview.c
===================================================================
--- client/gui-sdl/mapview.c	(Revision 12411)
+++ client/gui-sdl/mapview.c	(Arbeitskopie)
@@ -811,7 +811,7 @@
 	    
 	pDlg->pBeginActiveWidgetList = pBuf;
 	pDlg->pEndActiveWidgetList = pEnd;
-	pDlg->pActiveWidgetList = pEnd;
+	pDlg->pActiveWidgetList = pDlg->pEndActiveWidgetList;
 	  	  	  
 	if (n > num_w * num_h) {
     
Index: client/gui-sdl/repodlgs.c
===================================================================
--- client/gui-sdl/repodlgs.c	(Revision 12411)
+++ client/gui-sdl/repodlgs.c	(Arbeitskopie)
@@ -569,9 +569,9 @@
   w = (tileset_full_tile_width(tileset) * 2 + name_w + adj_size(15)) +
 		(adj_size(4) * pText1->w + adj_size(46)) + (pText2->w + adj_size(16))
                                  + (pText5->w + adj_size(6)) + adj_size(2);
-  if(count) {
-    pUnitsDlg->pBeginActiveWidgetList = pBuf;
+  if (count > 0) {
     pUnitsDlg->pEndActiveWidgetList = pLast->prev;
+    pUnitsDlg->pBeginActiveWidgetList = pUnitsDlg->pBeginWidgetList;
     if(count > adj_size(80)) {
       pUnitsDlg->pActiveWidgetList = pUnitsDlg->pEndActiveWidgetList;
       if(pUnitsDlg->pScroll) {
@@ -2061,8 +2061,8 @@
     FREESURFACE(pBackground);
     
     pEconomyDlg->pEndActiveWidgetList = pLast->prev;
-    pEconomyDlg->pBeginActiveWidgetList = pBuf;
     pEconomyDlg->pBeginWidgetList = pBuf;
+    pEconomyDlg->pBeginActiveWidgetList = pEconomyDlg->pBeginWidgetList;
     
     if(entries_used > (TARGETS_ROW * TARGETS_COL)) {
       pEconomyDlg->pActiveWidgetList = pEconomyDlg->pEndActiveWidgetList;
@@ -2882,9 +2882,10 @@
   }
   
   FREESTRING16(pStr);
+  
   pChangeTechDlg->pBeginWidgetList = pBuf;
-  pChangeTechDlg->pBeginActiveWidgetList = pBuf;
-  pChangeTechDlg->pEndActiveWidgetList = pWindow->prev->prev;
+  pChangeTechDlg->pBeginActiveWidgetList = pChangeTechDlg->pBeginWidgetList;
+  pChangeTechDlg->pEndActiveWidgetList = pChangeTechDlg->pEndWidgetList->prev->prev;
   
   /* -------------------------------------------------------------- */
   
@@ -2892,7 +2893,7 @@
   if (count > col) {
     count = (count + (col - 1)) / col;
     if (count > max_row) {
-      pChangeTechDlg->pActiveWidgetList = pWindow->prev->prev;
+      pChangeTechDlg->pActiveWidgetList = pChangeTechDlg->pEndActiveWidgetList;
       count = max_row;
       i = create_vertical_scrollbar(pChangeTechDlg, col, count, TRUE, TRUE);  
     }
@@ -3067,9 +3068,10 @@
   }
   
   FREESTRING16(pStr);
+  
   pChangeTechDlg->pBeginWidgetList = pBuf;
-  pChangeTechDlg->pBeginActiveWidgetList = pBuf;
-  pChangeTechDlg->pEndActiveWidgetList = pWindow->prev->prev;
+  pChangeTechDlg->pBeginActiveWidgetList = pChangeTechDlg->pBeginWidgetList;
+  pChangeTechDlg->pEndActiveWidgetList = pChangeTechDlg->pEndWidgetList->prev->prev;
   
   /* -------------------------------------------------------------- */
   
@@ -3077,7 +3079,7 @@
   if (count > col) {
     count = (count + (col-1)) / col;
     if (count > max_row) {
-      pChangeTechDlg->pActiveWidgetList = pWindow->prev->prev;
+      pChangeTechDlg->pActiveWidgetList = pChangeTechDlg->pEndActiveWidgetList;
       count = max_row;
       i = create_vertical_scrollbar(pChangeTechDlg, col, count, TRUE, TRUE);  
     }
Index: client/gui-sdl/widget_label.c
===================================================================
--- client/gui-sdl/widget_label.c	(Revision 12407)
+++ client/gui-sdl/widget_label.c	(Arbeitskopie)
@@ -65,16 +65,6 @@
     return ret;
   }
   
-  /* if label transparen then clear background under widget
-   * or save this background */
-  if (get_wflags(pLabel) & WF_RESTORE_BACKGROUND) {
-    if (pLabel->gfx) {
-      widget_undraw(pLabel);
-    } else {
-      pLabel->gfx = crop_rect_from_surface(pLabel->dst->surface, &area);
-    }
-  }
-
   if(get_wtype(pLabel) == WT_T2_LABEL) {
     return redraw_themelabel2(pLabel);
   }
Index: client/gui-sdl/widget.h
===================================================================
--- client/gui-sdl/widget.h	(Revision 12407)
+++ client/gui-sdl/widget.h	(Arbeitskopie)
@@ -113,7 +113,8 @@
   struct gui_layer *dst;      /* destination buffer layer */
 
   SDL_Surface *theme;
-  SDL_Surface *gfx;		/* Icon, background or theme2 */
+  SDL_Surface *theme2;        /* Icon or theme2 */
+  SDL_Surface *gfx;           /* saved background */
   SDL_String16 *string16;
   
   /* data/information/transport pointers */
Index: client/gui-sdl/widget_icon.c
===================================================================
--- client/gui-sdl/widget_icon.c	(Revision 12411)
+++ client/gui-sdl/widget_icon.c	(Arbeitskopie)
@@ -51,10 +51,6 @@
     return -3;
   }
 
-  if (pIcon->gfx) {
-    widget_undraw(pIcon);
-  }
-
   src.x = (pIcon->theme->w / 4) * (Uint8) (get_wstate(pIcon));
   src.y = 0;
   src.w = (pIcon->theme->w / 4);
@@ -95,10 +91,6 @@
   
   state = get_wstate(pIcon);
     
-  if (pIcon->gfx) {
-    widget_undraw(pIcon);
-  }
-
   dest.x = pIcon->size.x;
   dest.y = pIcon->size.y;
   dest.w = pIcon->theme->w;
Index: client/gui-sdl/cma_fe.c
===================================================================
--- client/gui-sdl/cma_fe.c	(Revision 12411)
+++ client/gui-sdl/cma_fe.c	(Arbeitskopie)
@@ -495,9 +495,9 @@
     }
   }
   pCma->pAdv->pBeginWidgetList = pBuf;
-  pCma->pAdv->pBeginActiveWidgetList = pBuf;
+  pCma->pAdv->pBeginActiveWidgetList = pCma->pAdv->pBeginWidgetList;
   pCma->pAdv->pEndActiveWidgetList = pWindow->prev->prev;
-  pCma->pAdv->pActiveWidgetList = pWindow->prev->prev;
+  pCma->pAdv->pActiveWidgetList = pCma->pAdv->pEndActiveWidgetList;
   
   ww += pTheme->FR_Left->w + pTheme->FR_Right->w + adj_size(2);
   hh += pTheme->FR_Bottom->h + 1;
Index: client/gui-sdl/widget_button.c
===================================================================
--- client/gui-sdl/widget_button.c	(Revision 12407)
+++ client/gui-sdl/widget_button.c	(Arbeitskopie)
@@ -41,7 +41,7 @@
   Graphic for button is taken from pIButton->theme surface 
   and blit to new created image.
 
-  Graphic for Icon is taken from pIButton->gfx surface and blit to new
+  Graphic for Icon is taken from pIButton->theme2 surface and blit to new
   created image.
 
   function return (-1) if there are no Icon and Text.
@@ -51,7 +51,7 @@
 {
   SDL_Rect dest = { 0, 0, 0, 0 };
   SDL_String16 TMPString;
-  SDL_Surface *pButton = NULL, *pText = NULL, *pIcon = pIButton->gfx;
+  SDL_Surface *pButton = NULL, *pText = NULL, *pIcon = pIButton->theme2;
   Uint16 Ix, Iy, x;
   Uint16 y = 0; /* FIXME: possibly uninitialized */
   int ret;
@@ -220,7 +220,7 @@
   Graphic for button is taken from pTIButton->theme surface 
   and blit to new created image.
 
-  Graphic for Icon Theme is taken from pTIButton->gfx surface 
+  Graphic for Icon Theme is taken from pTIButton->theme2 surface 
   and blit to new created image.
 
   function return (-1) if there are no Icon and Text.  Else return 0.
@@ -235,16 +235,15 @@
     return iRet;
   }
   
-  pIcon = create_icon_from_theme(pTIButton->gfx,
-					      get_wstate(pTIButton));
-  SDL_Surface *pCopy_Of_Icon_Theme = pTIButton->gfx;
+  pIcon = create_icon_from_theme(pTIButton->theme2, get_wstate(pTIButton));
+  SDL_Surface *pCopy_Of_Icon_Theme = pTIButton->theme2;
 
-  pTIButton->gfx = pIcon;
+  pTIButton->theme2 = pIcon;
 
   iRet = redraw_ibutton(pTIButton);
 
-  FREESURFACE(pTIButton->gfx);
-  pTIButton->gfx = pCopy_Of_Icon_Theme;
+  FREESURFACE(pTIButton->theme2);
+  pTIButton->theme2 = pCopy_Of_Icon_Theme;
 
   return iRet;
 }
@@ -275,7 +274,7 @@
   pButton = widget_new();
 
   pButton->theme = pTheme->Button;
-  pButton->gfx = pIcon;
+  pButton->theme2 = pIcon;
   pButton->string16 = pStr;
   set_wflag(pButton, (WF_FREE_STRING | flags));
   set_wstate(pButton, FC_WS_DISABLED);
@@ -346,8 +345,8 @@
   SDL_Surface *pIcon = create_icon_from_theme(pIcon_theme, 1);
   struct widget *pButton = create_icon_button(pIcon, pDest, pString16, flags);
 
-  FREESURFACE(pButton->gfx);	/* pButton->gfx == pIcon */
-  pButton->gfx = pIcon_theme;
+  FREESURFACE(pButton->theme2);
+  pButton->theme2 = pIcon_theme;
   set_wtype(pButton, WT_TI_BUTTON);
 
   pButton->redraw = redraw_tibutton;
@@ -364,7 +363,7 @@
   Graphic for button is taken from pButton->theme surface and blit to new
   created image.
 
-  Graphic for Icon theme is taken from pButton->gfx surface and blit to
+  Graphic for Icon theme is taken from pButton->theme2 surface and blit to
   new created image.
 
   function return (-1) if there are no Icon and Text.
@@ -386,7 +385,7 @@
    Graphic for button is taken from pButton->theme surface 
    and blit to new created image.
 
-  Graphic for Icon is taken from pButton->gfx surface 
+  Graphic for Icon is taken from pButton->theme2 surface 
   and blit to new created image.
 
   function return (-1) if there are no Icon and Text.
Index: client/gui-sdl/cityrep.c
===================================================================
--- client/gui-sdl/cityrep.c	(Revision 12411)
+++ client/gui-sdl/cityrep.c	(Arbeitskopie)
@@ -566,8 +566,8 @@
 	pUnits_Icon->w + adj_size(6) + prod_w + adj_size(170);
   
   if(count) {
-    pCityRep->pBeginActiveWidgetList = pBuf;
     pCityRep->pEndActiveWidgetList = pLast->prev;
+    pCityRep->pBeginActiveWidgetList = pCityRep->pBeginWidgetList;
     if(count > 10 * COL) {
       pCityRep->pActiveWidgetList = pCityRep->pEndActiveWidgetList;
       if(pCityRep->pScroll) {
Index: client/gui-sdl/dialogs.c
===================================================================
--- client/gui-sdl/dialogs.c	(Revision 12411)
+++ client/gui-sdl/dialogs.c	(Arbeitskopie)
@@ -713,9 +713,9 @@
     
   }
   pUnit_Select_Dlg->pBeginWidgetList = pBuf;
-  pUnit_Select_Dlg->pBeginActiveWidgetList = pBuf;
+  pUnit_Select_Dlg->pBeginActiveWidgetList = pUnit_Select_Dlg->pBeginWidgetList;
   pUnit_Select_Dlg->pEndActiveWidgetList = pWindow->prev->prev;
-  pUnit_Select_Dlg->pActiveWidgetList = pWindow->prev->prev;
+  pUnit_Select_Dlg->pActiveWidgetList = pUnit_Select_Dlg->pEndActiveWidgetList;
   
   w += (pTheme->FR_Left->w + pTheme->FR_Right->w + adj_size(2));
   if (n > NUM_SEEN)
@@ -1453,9 +1453,9 @@
       }
       
       pAdvanced_Terrain_Dlg->pEndActiveWidgetList = pLast->prev;
-      pAdvanced_Terrain_Dlg->pActiveWidgetList = pLast->prev;
+      pAdvanced_Terrain_Dlg->pActiveWidgetList = pAdvanced_Terrain_Dlg->pEndActiveWidgetList;
       pAdvanced_Terrain_Dlg->pBeginWidgetList = pBuf;
-      pAdvanced_Terrain_Dlg->pBeginActiveWidgetList = pBuf;
+      pAdvanced_Terrain_Dlg->pBeginActiveWidgetList = pAdvanced_Terrain_Dlg->pBeginWidgetList;
             
       if(n > ADV_NUM_SEEN)
       {
@@ -2754,8 +2754,8 @@
   FREESURFACE(pMain_Bg);
     
   pNationDlg->pEndActiveWidgetList = pWindow->prev;
-  pNationDlg->pBeginActiveWidgetList = pWidget;
   pNationDlg->pBeginWidgetList = pWidget;
+  pNationDlg->pBeginActiveWidgetList = pNationDlg->pBeginWidgetList;
     
   if(get_playable_nation_count() > TARGETS_ROW * TARGETS_COL) {
       pNationDlg->pActiveWidgetList = pNationDlg->pEndActiveWidgetList;
Index: client/gui-sdl/diplomat_dialog.c
===================================================================
--- client/gui-sdl/diplomat_dialog.c	(Revision 12407)
+++ client/gui-sdl/diplomat_dialog.c	(Arbeitskopie)
@@ -340,8 +340,8 @@
   /* --------------------------------------------------------- */
   FREESTRING16(pStr);
   pDiplomat_Dlg->pdialog->pBeginWidgetList = pBuf;
-  pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pBuf;
-  pDiplomat_Dlg->pdialog->pEndActiveWidgetList = pWindow->prev->prev;
+  pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pDiplomat_Dlg->pdialog->pBeginWidgetList;
+  pDiplomat_Dlg->pdialog->pEndActiveWidgetList = pDiplomat_Dlg->pdialog->pEndWidgetList->prev->prev;
   
   /* -------------------------------------------------------------- */
   
@@ -349,7 +349,7 @@
   if (count > col) {
     count = (count + (col - 1)) / col;
     if (count > max_row) {
-      pDiplomat_Dlg->pdialog->pActiveWidgetList = pWindow->prev->prev;
+      pDiplomat_Dlg->pdialog->pActiveWidgetList = pDiplomat_Dlg->pdialog->pEndActiveWidgetList;
       count = max_row;
       i = create_vertical_scrollbar(pDiplomat_Dlg->pdialog, col, count, TRUE, TRUE);  
     }
@@ -897,9 +897,10 @@
       /* ----------- */
     }  
   } built_impr_iterate_end;
+
   pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pBuf;
   
-  if(n) {
+  if (n > 0) {
     /* separator */
     pBuf = create_iconlabel(NULL, pWindow->dst, NULL, WF_FREE_THEME);
     
@@ -920,9 +921,8 @@
   /* ----------- */
   
   pLast = pBuf;
-  pDiplomat_Dlg->pdialog->pBeginWidgetList = pBuf;
-  pDiplomat_Dlg->pdialog->pActiveWidgetList =
-			      pDiplomat_Dlg->pdialog->pEndActiveWidgetList;
+  pDiplomat_Dlg->pdialog->pBeginWidgetList = pLast;
+  pDiplomat_Dlg->pdialog->pActiveWidgetList = pDiplomat_Dlg->pdialog->pEndActiveWidgetList;
   
   /* ---------- */
   if (n > 10)
Index: client/gui-sdl/widget_core.c
===================================================================
--- client/gui-sdl/widget_core.c	(Revision 12407)
+++ client/gui-sdl/widget_core.c	(Arbeitskopie)
@@ -150,6 +150,10 @@
     return -1;
   }
   
+  if (pwidget->gfx) {
+    widget_undraw(pwidget);
+  }
+  
   if (!pwidget->gfx && (get_wflags(pwidget) & WF_RESTORE_BACKGROUND)) {
     refresh_widget_background(pwidget);
   }
Index: client/gui-sdl/diplodlg.c
===================================================================
--- client/gui-sdl/diplodlg.c	(Revision 12411)
+++ client/gui-sdl/diplodlg.c	(Arbeitskopie)
@@ -711,15 +711,15 @@
   } /* Cities */
   
   pDlg->pBeginWidgetList = pBuf;
-  pDlg->pBeginActiveWidgetList = pBuf;
-  pDlg->pEndActiveWidgetList = pWindow->prev;
+  pDlg->pBeginActiveWidgetList = pDlg->pBeginWidgetList;
+  pDlg->pEndActiveWidgetList = pDlg->pEndWidgetList->prev;
   pDlg->pScroll = NULL;
   
   hh = (Main.screen->h - adj_size(100) - WINDOW_TITLE_HEIGHT - adj_size(4) - pTheme->FR_Bottom->h);
   ww = hh < (count * height);
   
   if(ww) {
-    pDlg->pActiveWidgetList = pWindow->prev;
+    pDlg->pActiveWidgetList = pDlg->pEndActiveWidgetList;
     count = hh / height;
     scroll_w = create_vertical_scrollbar(pDlg, 1, count, TRUE, TRUE);
     pBuf = pWindow;
@@ -1012,7 +1012,7 @@
   SDL_String16 *pStr;
   struct widget *pBuf, *pWindow = pdialog->pdialog->pEndWidgetList;
   char cBuf[64];
-  bool redraw_all, scroll = pdialog->pdialog->pActiveWidgetList == NULL;
+  bool redraw_all, scroll = (pdialog->pdialog->pActiveWidgetList != NULL);
   int len = pdialog->pdialog->pScroll->pUp_Left_Button->size.w;
   
   clause_list_iterate(pdialog->treaty.clauses, pclause) {
@@ -1035,7 +1035,7 @@
     pBuf->action = remove_clause_callback;
     set_wstate(pBuf, FC_WS_NORMAL);
     
-    pBuf->size.w = pWindow->size.w - adj_size(24) - (scroll ? 0 : len);
+    pBuf->size.w = pWindow->size.w - adj_size(24) - (scroll ? len : 0);
     
     redraw_all = add_widget_to_vertical_scroll_widget_list(pdialog->pdialog,
                   pBuf, pdialog->pdialog->pBeginWidgetList,
@@ -1043,14 +1043,16 @@
                   pWindow->size.x + adj_size(12),
                   pdialog->pdialog->pScroll->pUp_Left_Button->size.y + adj_size(2));
 
-    /* find if there was scrollbar shown */
-    if(scroll && pdialog->pdialog->pActiveWidgetList != NULL) {
+    if(!scroll && (pdialog->pdialog->pActiveWidgetList != NULL)) {
+      /* -> the scrollbar has been activated */
       pBuf = pdialog->pdialog->pEndActiveWidgetList->next;
       do {
         pBuf = pBuf->prev;
         pBuf->size.w -= len;
+        /* we need to save a new background because the width has changed */
         FREESURFACE(pBuf->gfx);
       } while(pBuf != pdialog->pdialog->pBeginActiveWidgetList);
+      scroll = TRUE;
     }
 
     /* redraw */
@@ -1081,31 +1083,36 @@
   
   /* find widget with clause */
   pBuf = pdialog->pdialog->pEndActiveWidgetList->next;
+  
   do {
     pBuf = pBuf->prev;
-  } while(!(pBuf->data.cont->id0 == giver &&
-            ((pBuf->data.cont->value >> 16) & 0xFFFF) == (int)type &&
-            (pBuf->data.cont->value & 0xFFFF) == value) &&
-  		pBuf != pdialog->pdialog->pBeginActiveWidgetList);
+  } while(!((pBuf->data.cont->id0 == giver) &&
+            (((pBuf->data.cont->value >> 16) & 0xFFFF) == (int)type) &&
+            ((pBuf->data.cont->value & 0xFFFF) == value)) &&
+          (pBuf != pdialog->pdialog->pBeginActiveWidgetList));
   
   if(!(pBuf->data.cont->id0 == giver &&
             ((pBuf->data.cont->value >> 16) & 0xFFFF) == (int)type &&
             (pBuf->data.cont->value & 0xFFFF) == value)) {
      return;
   }
-    
-  scroll = pdialog->pdialog->pActiveWidgetList != NULL;
+  
+  scroll = (pdialog->pdialog->pActiveWidgetList != NULL);
   del_widget_from_vertical_scroll_widget_list(pdialog->pdialog, pBuf);
 
-  /* find if there was scrollbar hide */
-  if(scroll && pdialog->pdialog->pActiveWidgetList == NULL) {
+  if(scroll && (pdialog->pdialog->pActiveWidgetList == NULL)) {
+    /* -> the scrollbar has been deactivated */
+    
     int len = pdialog->pdialog->pScroll->pUp_Left_Button->size.w;
     pBuf = pdialog->pdialog->pEndActiveWidgetList->next;
     do {
       pBuf = pBuf->prev;
+      widget_undraw(pBuf);
       pBuf->size.w += len;
+      /* we need to save a new background because the width has changed */
       FREESURFACE(pBuf->gfx);
     } while(pBuf != pdialog->pdialog->pBeginActiveWidgetList);
+    scroll = FALSE;
   }
     
   /* update state icons */
Index: client/gui-sdl/inteldlg.c
===================================================================
--- client/gui-sdl/inteldlg.c	(Revision 12411)
+++ client/gui-sdl/inteldlg.c	(Arbeitskopie)
@@ -333,11 +333,11 @@
     
     pdialog->pdialog->pBeginWidgetList = pBuf;
     
-    if(n) {
-      pdialog->pdialog->pBeginActiveWidgetList = pBuf;
+    if (n > 0) {
       pdialog->pdialog->pEndActiveWidgetList = pLast->prev;
+      pdialog->pdialog->pBeginActiveWidgetList = pdialog->pdialog->pBeginWidgetList;
       if(n > 2 * col) {
-        pdialog->pdialog->pActiveWidgetList = pLast->prev;
+        pdialog->pdialog->pActiveWidgetList = pdialog->pdialog->pEndActiveWidgetList;
         count = create_vertical_scrollbar(pdialog->pdialog, col, 2, TRUE, TRUE);
         h += (2 * pBuf->size.h + adj_size(10));
       } else {
Index: client/gui-sdl/finddlg.c
===================================================================
--- client/gui-sdl/finddlg.c	(Revision 12411)
+++ client/gui-sdl/finddlg.c	(Arbeitskopie)
@@ -198,7 +198,7 @@
     } city_list_iterate_end;
   }
   pFind_City_Dlg->pBeginWidgetList = pBuf;
-  pFind_City_Dlg->pBeginActiveWidgetList = pBuf;
+  pFind_City_Dlg->pBeginActiveWidgetList = pFind_City_Dlg->pBeginWidgetList;
   pFind_City_Dlg->pEndActiveWidgetList = pWindow->prev->prev;
   pFind_City_Dlg->pActiveWidgetList = pFind_City_Dlg->pEndActiveWidgetList;
   
Index: client/gui-sdl/helpdlg.c
===================================================================
--- client/gui-sdl/helpdlg.c	(Revision 12411)
+++ client/gui-sdl/helpdlg.c	(Arbeitskopie)
@@ -266,12 +266,12 @@
     
     FREESURFACE(pTmp);
     
-    pHelpDlg->pBeginActiveWidgetList = pBuf;
     pHelpDlg->pEndActiveWidgetList = pDock->prev;
     pHelpDlg->pBeginWidgetList = pBuf;/* IMPORTANT */
+    pHelpDlg->pBeginActiveWidgetList = pHelpDlg->pBeginWidgetList;
     
     if (h > 10) {
-      pHelpDlg->pActiveWidgetList = pDock->prev;
+      pHelpDlg->pActiveWidgetList = pHelpDlg->pEndActiveWidgetList;
       width = create_vertical_scrollbar(pHelpDlg, 1, 10, TRUE, TRUE);
     }
         
@@ -637,13 +637,13 @@
     } unit_type_iterate_end;
     
     FREESURFACE(pTmp);
-    
-    pHelpDlg->pBeginActiveWidgetList = pBuf;
+
     pHelpDlg->pEndActiveWidgetList = pDock->prev;
     pHelpDlg->pBeginWidgetList = pBuf;/* IMPORTANT */
+    pHelpDlg->pBeginActiveWidgetList = pHelpDlg->pBeginWidgetList;
     
     if (h > 10) {
-      pHelpDlg->pActiveWidgetList = pDock->prev;
+      pHelpDlg->pActiveWidgetList = pHelpDlg->pEndActiveWidgetList;
       width = create_vertical_scrollbar(pHelpDlg, 1, 10, TRUE, TRUE);
     }
         
@@ -903,7 +903,7 @@
     if (!pStore->show_tree)
     {
       pStore->show_full_tree = FALSE;
-      pStore->pDock->gfx = pTheme->UP_Icon;
+      pStore->pDock->theme2 = pTheme->UP_Icon;
     }
     popup_tech_info(MAX_ID - pStore->pDock->prev->ID);
   }
@@ -1535,9 +1535,9 @@
     struct TECHS_BUTTONS *pStore = (struct TECHS_BUTTONS *)pHelpDlg->pEndWidgetList->data.ptr;
     if (pStore->show_full_tree)
     {
-      pWidget->gfx = pTheme->UP_Icon;
+      pWidget->theme2 = pTheme->UP_Icon;
     } else {
-      pWidget->gfx = pTheme->DOWN_Icon;
+      pWidget->theme2 = pTheme->DOWN_Icon;
     }
     pStore->show_full_tree = !pStore->show_full_tree;
     popup_tech_info(MAX_ID - pStore->pDock->prev->ID);
@@ -1888,13 +1888,13 @@
     }
     
     FREESTRING16(pStr);  
-    
-    pHelpDlg->pBeginActiveWidgetList = pBuf;
+
     pHelpDlg->pEndActiveWidgetList = pDock->prev;
     pHelpDlg->pBeginWidgetList = pBuf;/* IMPORTANT */
+    pHelpDlg->pBeginActiveWidgetList = pHelpDlg->pBeginWidgetList;
     
     if (h > 10) {
-      pHelpDlg->pActiveWidgetList = pDock->prev;
+      pHelpDlg->pActiveWidgetList = pHelpDlg->pEndActiveWidgetList;
       width = create_vertical_scrollbar(pHelpDlg, 1, 10, TRUE, TRUE);
     }
         
Index: client/gui-sdl/plrdlg.c
===================================================================
--- client/gui-sdl/plrdlg.c	(Revision 12411)
+++ client/gui-sdl/plrdlg.c	(Arbeitskopie)
@@ -742,7 +742,7 @@
     }
   }
   pShort_Players_Dlg->pBeginWidgetList = pBuf;
-  pShort_Players_Dlg->pBeginActiveWidgetList = pBuf;
+  pShort_Players_Dlg->pBeginActiveWidgetList = pShort_Players_Dlg->pBeginWidgetList;
   pShort_Players_Dlg->pEndActiveWidgetList = pWindow->prev->prev;
   pShort_Players_Dlg->pActiveWidgetList = pShort_Players_Dlg->pEndActiveWidgetList;
   
Index: client/gui-sdl/chatline.c
===================================================================
--- client/gui-sdl/chatline.c	(Revision 12407)
+++ client/gui-sdl/chatline.c	(Arbeitskopie)
@@ -482,8 +482,8 @@
       
   pConnDlg->pChat_Dlg->pBeginWidgetList = pLabel;
   pConnDlg->pChat_Dlg->pEndWidgetList = pLabel;
-  pConnDlg->pChat_Dlg->pBeginActiveWidgetList = pLabel;
-  pConnDlg->pChat_Dlg->pEndActiveWidgetList = pLabel;
+  pConnDlg->pChat_Dlg->pBeginActiveWidgetList = pConnDlg->pChat_Dlg->pBeginWidgetList;
+  pConnDlg->pChat_Dlg->pEndActiveWidgetList = pConnDlg->pChat_Dlg->pEndWidgetList;
 
 /* FIXME: this can probably be removed */
 #if 0
Index: client/gui-sdl/widget_edit.c
===================================================================
--- client/gui-sdl/widget_edit.c	(Revision 12407)
+++ client/gui-sdl/widget_edit.c	(Arbeitskopie)
@@ -59,18 +59,19 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static void redraw_edit_chain(struct EDIT *pEdt)
+static int redraw_edit_chain(struct EDIT *pEdt)
 {
   struct UniChar *pInputChain_TMP;
   SDL_Rect Dest, Dest_Copy = {0, 0, 0, 0};
   int iStart_Mod_X;
+  int ret;
 
   Dest_Copy.x = pEdt->pWidget->size.x;
   Dest_Copy.y = pEdt->pWidget->size.y;
 
-  /* blit backgroud ( if any ) */
-  if (get_wflags(pEdt->pWidget) & WF_RESTORE_BACKGROUND) {
-    widget_undraw(pEdt->pWidget);
+  ret = (*baseclass_redraw)(pEdt->pWidget);
+  if (ret != 0) {
+    return ret;
   }
 
   /* blit theme */
@@ -118,6 +119,7 @@
 
   widget_flush(pEdt->pWidget);
   
+  return 0;
 }
 
 /**************************************************************************
@@ -135,14 +137,21 @@
 **************************************************************************/
 static int redraw_edit(struct widget *pEdit_Widget)
 {
+  int ret;
+  
   if (get_wstate(pEdit_Widget) == FC_WS_PRESSED) {
-    redraw_edit_chain((struct EDIT *)pEdit_Widget->data.ptr);
+    return redraw_edit_chain((struct EDIT *)pEdit_Widget->data.ptr);
   } else {
     int iRet = 0;
     SDL_Rect rDest = {pEdit_Widget->size.x, pEdit_Widget->size.y, 0, 0};
     SDL_Surface *pEdit = NULL;
     SDL_Surface *pText;
-  
+
+    ret = (*baseclass_redraw)(pEdit_Widget);
+    if (ret != 0) {
+      return ret;
+    }
+    
     if (pEdit_Widget->string16->text &&
     	get_wflags(pEdit_Widget) & WF_PASSWD_EDIT) {
       Uint16 *backup = pEdit_Widget->string16->text;
@@ -167,11 +176,6 @@
       return -1;
     }
     
-    if (get_wflags(pEdit_Widget) & WF_RESTORE_BACKGROUND) {
-      /* blit background */
-      widget_undraw(pEdit_Widget);
-    }
-
     /* blit theme */
     alphablit(pEdit, NULL, pEdit_Widget->dst->surface, &rDest);
 
@@ -326,7 +330,7 @@
   struct widget *pEdit = widget_new();
 
   pEdit->theme = pTheme->Edit;
-  pEdit->gfx = pBackground;
+  pEdit->theme2 = pBackground; /* FIXME: make somewhere use of it */
   pEdit->string16 = pString16;
   set_wflag(pEdit, (WF_FREE_STRING | WF_FREE_GFX | flags));
   set_wstate(pEdit, FC_WS_DISABLED);
Index: client/gui-sdl/wldlg.c
===================================================================
--- client/gui-sdl/wldlg.c	(Revision 12411)
+++ client/gui-sdl/wldlg.c	(Arbeitskopie)
@@ -1206,8 +1206,8 @@
     
     pEditor->pWork->pEndWidgetList = pBuf;
     pEditor->pWork->pBeginWidgetList = pBuf;
-    pEditor->pWork->pEndActiveWidgetList = pBuf;
-    pEditor->pWork->pBeginActiveWidgetList = pBuf;
+    pEditor->pWork->pEndActiveWidgetList = pEditor->pWork->pEndWidgetList;
+    pEditor->pWork->pBeginActiveWidgetList = pEditor->pWork->pBeginWidgetList;
     pEditor->pWork->pScroll->count++;
   }
   
@@ -1250,10 +1250,10 @@
   if(count) {
     if(!pCity) {
       pEditor->pWork->pEndWidgetList = pLast->prev;
-      pEditor->pWork->pEndActiveWidgetList = pLast->prev;
+      pEditor->pWork->pEndActiveWidgetList = pEditor->pWork->pEndWidgetList;
     }
     pEditor->pWork->pBeginWidgetList = pBuf;
-    pEditor->pWork->pBeginActiveWidgetList = pBuf;
+    pEditor->pWork->pBeginActiveWidgetList = pEditor->pWork->pBeginWidgetList;
   } else {
     if(!pCity) {
       pEditor->pWork->pEndWidgetList = pLast;
@@ -1263,7 +1263,7 @@
   
 /* FIXME */
 #if 0  
-  pEditor->pWork->pActiveWidgetList = pLast;
+  pEditor->pWork->pActiveWidgetList = pEditor->pWork->pEndActiveWidgetList;
   create_vertical_scrollbar(pEditor->pWork, 1,
                            pEditor->pWork->pScroll->active, FALSE, TRUE);
   pEditor->pWork->pScroll->pUp_Left_Button->size.w = adj_size(122);
@@ -1310,12 +1310,12 @@
     if(count) {
       pEditor->pGlobal = fc_calloc(1, sizeof(struct ADVANCED_DLG));
       pEditor->pGlobal->pEndWidgetList = pLast->prev;
-      pEditor->pGlobal->pEndActiveWidgetList = pLast->prev;
+      pEditor->pGlobal->pEndActiveWidgetList = pEditor->pGlobal->pEndWidgetList;
       pEditor->pGlobal->pBeginWidgetList = pBuf;
-      pEditor->pGlobal->pBeginActiveWidgetList = pBuf;
+      pEditor->pGlobal->pBeginActiveWidgetList = pEditor->pGlobal->pBeginWidgetList;
     
       if(count > 6) {
-        pEditor->pGlobal->pActiveWidgetList = pLast->prev;
+        pEditor->pGlobal->pActiveWidgetList = pEditor->pGlobal->pEndActiveWidgetList;
 
 /* FIXME: this can probably be removed */
 #if 0
@@ -1587,9 +1587,9 @@
   
   pEditor->pTargets->pEndWidgetList = pLast->prev;
   pEditor->pTargets->pBeginWidgetList = pBuf;
-  pEditor->pTargets->pEndActiveWidgetList = pLast->prev;
-  pEditor->pTargets->pBeginActiveWidgetList = pBuf;
-  pEditor->pTargets->pActiveWidgetList = pLast->prev;
+  pEditor->pTargets->pEndActiveWidgetList = pEditor->pTargets->pEndWidgetList;
+  pEditor->pTargets->pBeginActiveWidgetList = pEditor->pTargets->pBeginWidgetList;
+  pEditor->pTargets->pActiveWidgetList = pEditor->pTargets->pEndActiveWidgetList;
     
   /* --------------- */
   if(count > (TARGETS_ROW * TARGETS_COL - 1)) {
Index: client/gui-sdl/connectdlg.c
===================================================================
--- client/gui-sdl/connectdlg.c	(Revision 12407)
+++ client/gui-sdl/connectdlg.c	(Arbeitskopie)
@@ -342,9 +342,9 @@
   }
   
   pMeta_Severs->pBeginWidgetList = pNewWidget;
-  pMeta_Severs->pBeginActiveWidgetList = pNewWidget;
-  pMeta_Severs->pEndActiveWidgetList = pWindow->prev->prev;
-  pMeta_Severs->pActiveWidgetList = pWindow->prev->prev;
+  pMeta_Severs->pBeginActiveWidgetList = pMeta_Severs->pBeginWidgetList;
+  pMeta_Severs->pEndActiveWidgetList = pMeta_Severs->pEndWidgetList->prev->prev;
+  pMeta_Severs->pActiveWidgetList = pMeta_Severs->pEndActiveWidgetList;
     
   if (count > 10) {
     meta_h = 10 * h;
Index: client/gui-sdl/widget_scrollbar.c
===================================================================
--- client/gui-sdl/widget_scrollbar.c	(Revision 12411)
+++ client/gui-sdl/widget_scrollbar.c	(Arbeitskopie)
@@ -442,10 +442,10 @@
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
     struct ADVANCED_DLG *pDlg = pWidget->private_data.adv_dlg;
     struct widget *pBegin = down_scroll_widget_list(
-                          pDlg->pScroll,
-                          pDlg->pActiveWidgetList,
-                          pDlg->pBeginActiveWidgetList,
-                          pDlg->pEndActiveWidgetList);
+                              pDlg->pScroll,
+                              pDlg->pActiveWidgetList,
+                              pDlg->pBeginActiveWidgetList,
+                              pDlg->pEndActiveWidgetList);
   
     if (pBegin) {
       pDlg->pActiveWidgetList = pBegin;
@@ -468,10 +468,10 @@
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
     struct ADVANCED_DLG *pDlg = pScrollBar->private_data.adv_dlg;
     struct widget *pBegin = vertic_scroll_widget_list(
-                          pDlg->pScroll,
-                          pDlg->pActiveWidgetList,
-                          pDlg->pBeginActiveWidgetList,
-                          pDlg->pEndActiveWidgetList);
+                              pDlg->pScroll,
+                              pDlg->pActiveWidgetList,
+                              pDlg->pBeginActiveWidgetList,
+                              pDlg->pEndActiveWidgetList);
   
     if (pBegin) {
       pDlg->pActiveWidgetList = pBegin;
@@ -490,8 +490,8 @@
   ...
 **************************************************************************/
 Uint32 create_vertical_scrollbar(struct ADVANCED_DLG *pDlg,
-		  Uint8 step, Uint8 active,
-		  bool create_scrollbar, bool create_buttons)
+                                 Uint8 step, Uint8 active,
+                                 bool create_scrollbar, bool create_buttons)
 {
   Uint16 count = 0;
   struct widget *pBuf = NULL, *pWindow = NULL;
@@ -500,11 +500,11 @@
   
   pWindow = pDlg->pEndWidgetList;
   
-  if(!pDlg->pScroll) {
+  if (!pDlg->pScroll) {
     pDlg->pScroll = fc_calloc(1, sizeof(struct ScrollBar));
         
     pBuf = pDlg->pEndActiveWidgetList;
-    while(pBuf && pBuf != pDlg->pBeginActiveWidgetList->prev) {
+    while (pBuf && (pBuf != pDlg->pBeginActiveWidgetList->prev)) {
       pBuf = pBuf->prev;
       count++;
     }
@@ -517,7 +517,7 @@
   
   if(create_buttons) {
     /* create up button */
-    pBuf = create_themeicon_button(pTheme->UP_Icon, pWindow->dst, NULL, 0);
+    pBuf = create_themeicon_button(pTheme->UP_Icon, pWindow->dst, NULL, WF_RESTORE_BACKGROUND);
     
     pBuf->ID = ID_BUTTON;
     pBuf->private_data.adv_dlg = pDlg;
@@ -531,7 +531,7 @@
     count = pBuf->size.w;
     
     /* create down button */
-    pBuf = create_themeicon_button(pTheme->DOWN_Icon, pWindow->dst, NULL, 0);
+    pBuf = create_themeicon_button(pTheme->DOWN_Icon, pWindow->dst, NULL, WF_RESTORE_BACKGROUND);
     
     pBuf->ID = ID_BUTTON;
     pBuf->private_data.adv_dlg = pDlg;
@@ -921,7 +921,9 @@
 
     if (pUp->pVscroll->pScrollBar) {
       /* redraw scroolbar */
-      refresh_widget_background(pUp->pVscroll->pScrollBar);
+      if (get_wflags(pUp->pVscroll->pScrollBar) & WF_RESTORE_BACKGROUND) {
+        refresh_widget_background(pUp->pVscroll->pScrollBar);
+      }
       redraw_vert(pUp->pVscroll->pScrollBar);
       widget_mark_dirty(pUp->pVscroll->pScrollBar);
     }
@@ -1011,7 +1013,9 @@
     }
 
     /* redraw slider */
-    refresh_widget_background(pMotion->pVscroll->pScrollBar);
+    if (get_wflags(pMotion->pVscroll->pScrollBar) & WF_RESTORE_BACKGROUND) {
+      refresh_widget_background(pMotion->pVscroll->pScrollBar);
+    }
     redraw_vert(pMotion->pVscroll->pScrollBar);
     widget_mark_dirty(pMotion->pVscroll->pScrollBar);
 
@@ -1125,9 +1129,10 @@
   It isn't full secure to multi widget list.
 **************************************************************************/
 bool add_widget_to_vertical_scroll_widget_list(struct ADVANCED_DLG *pDlg,
-				      struct widget *pNew_Widget,
-				      struct widget *pAdd_Dock, bool dir,
-					Sint16 start_x, Sint16 start_y)
+                                               struct widget *pNew_Widget,
+                                               struct widget *pAdd_Dock,
+                                               bool dir,
+                                               Sint16 start_x, Sint16 start_y)
 {
   struct widget *pBuf = NULL;
   struct widget *pEnd = NULL, *pOld_End = NULL;
@@ -1138,14 +1143,18 @@
   assert(pDlg != NULL);
   assert(pDlg->pScroll != NULL);
   
-  if(!pAdd_Dock) {
-    pAdd_Dock = pDlg->pBeginWidgetList;
+  if (!pAdd_Dock) {
+    pAdd_Dock = pDlg->pBeginWidgetList; /* last item */
   }
   
   pDlg->pScroll->count++;
   
-  if(pDlg->pScroll->count > pDlg->pScroll->active * pDlg->pScroll->step) {
-    if(pDlg->pActiveWidgetList) {
+  if (pDlg->pScroll->count > (pDlg->pScroll->active * pDlg->pScroll->step)) {
+    /* -> scrollbar needed */
+    
+    if (pDlg->pActiveWidgetList) {
+      /* -> scrollbar is already visible */
+      
       int i = 0;
       /* find last active widget */
       pOld_End = pAdd_Dock;
@@ -1153,24 +1162,27 @@
         pOld_End = pOld_End->next;
 	i++;
 	if (pOld_End == pDlg->pEndActiveWidgetList) {
+          /* implies (pOld_End == pDlg->pActiveWidgetList)? */
 	  seen = FALSE;
 	  break;
 	}
       }
+      
       if (seen) {
-        count = pDlg->pScroll->active * pDlg->pScroll->step - 1;
+        count = (pDlg->pScroll->active * pDlg->pScroll->step) - 1;
         if (i > count) {
 	  seen = FALSE;
         } else {
-          while(count) {
+          while (count > 0) {
 	    pOld_End = pOld_End->prev;
 	    count--;
           }
-          if(pOld_End == pAdd_Dock) {
+          if (pOld_End == pAdd_Dock) {
 	    last = TRUE;
           }
 	}
       }
+      
     } else {
       last = TRUE;
       pDlg->pActiveWidgetList = pDlg->pEndActiveWidgetList;
@@ -1179,8 +1191,9 @@
   }
 
   count = 0;
+  
   /* add Pointer to list */
-  if(dir) {
+  if (dir) {
     /* upper add */
     UpperAdd(pNew_Widget, pAdd_Dock);
     
@@ -1296,7 +1309,9 @@
     if(last) {
       pDlg->pScroll->pScrollBar->size.y = get_position(pDlg);
     }
-    refresh_widget_background(pDlg->pScroll->pScrollBar);
+    if (get_wflags(pDlg->pScroll->pScrollBar) & WF_RESTORE_BACKGROUND) {
+      refresh_widget_background(pDlg->pScroll->pScrollBar);
+    }
     if (!seen) {
       redraw_vert(pDlg->pScroll->pScrollBar);
     }
@@ -1319,25 +1334,30 @@
   assert(pDlg != NULL);
 
   /* if begin == end -> size = 1 */
-  if (pDlg->pBeginActiveWidgetList ==
-      pDlg->pEndActiveWidgetList) {
+  if (pDlg->pBeginActiveWidgetList == pDlg->pEndActiveWidgetList) {
+    
     if(pDlg->pScroll) {
       pDlg->pScroll->count = 0;
+
       if(!pDlg->pScroll->pUp_Left_Button && 
-	!pDlg->pScroll->pScrollBar &&
-        !pDlg->pScroll->pDown_Right_Button) {
+	 !pDlg->pScroll->pScrollBar &&
+         !pDlg->pScroll->pDown_Right_Button) {
         pDlg->pBeginWidgetList = NULL;
         pDlg->pEndWidgetList = NULL;
       }
+      
       if(pDlg->pBeginActiveWidgetList == pDlg->pBeginWidgetList) {
 	pDlg->pBeginWidgetList = pDlg->pBeginWidgetList->next;
       }
+      
       if(pDlg->pEndActiveWidgetList == pDlg->pEndWidgetList) {
 	pDlg->pEndWidgetList = pDlg->pEndWidgetList->prev;
       }
+      
       pDlg->pBeginActiveWidgetList = NULL;
       pDlg->pActiveWidgetList = NULL;
       pDlg->pEndActiveWidgetList = NULL;
+      
     } else {
       pDlg->pBeginWidgetList = NULL;
       pDlg->pEndWidgetList = NULL;
@@ -1353,6 +1373,7 @@
     /* scrollbar exist and active, start mod. from last seen label */
     
     struct widget *pLast;
+    bool widget_found = FALSE;
       
     /* this is always true becouse no-scrolbar case (active*step < count)
        will be suported in other part of code (see "else" part) */
@@ -1360,11 +1381,10 @@
         
     /* find last */
     pBuf = pDlg->pActiveWidgetList;
-    while (count) {
+    while (count > 0) {
       pBuf = pBuf->prev;
       count--;
     }
-
     if(!pBuf) {
       pLast = pDlg->pBeginActiveWidgetList;
     } else {
@@ -1372,17 +1392,33 @@
     }
     
     if(pLast == pDlg->pBeginActiveWidgetList) {
+      
       if(pDlg->pScroll->step == 1) {
-        pBuf = pDlg->pActiveWidgetList->next;
-        pDlg->pActiveWidgetList = pBuf;
-        clear_wflag(pBuf, WF_HIDDEN);
-	while (pBuf != pWidget) {
-          pBuf->gfx = pBuf->prev->gfx;
-          pBuf->prev->gfx = NULL;
-          pBuf->size.x = pBuf->prev->size.x;
-          pBuf->size.y = pBuf->prev->size.y;
+        pDlg->pActiveWidgetList = pDlg->pActiveWidgetList->next;
+        clear_wflag(pDlg->pActiveWidgetList, WF_HIDDEN);
+        
+        /* look for the widget in the non-visible part */
+        pBuf = pDlg->pEndActiveWidgetList;
+        while (pBuf != pDlg->pActiveWidgetList) {
+          if (pBuf == pWidget) {
+            widget_found = TRUE;
+            pBuf = pDlg->pActiveWidgetList;
+            break;
+          }
           pBuf = pBuf->prev;
         }
+        
+        /* if we haven't found it yet, look in the visible part and update the
+           positions of the other widgets */
+        if (!widget_found) {
+          while (pBuf != pWidget) {
+            pBuf->gfx = pBuf->prev->gfx;
+            pBuf->prev->gfx = NULL;
+            pBuf->size.x = pBuf->prev->size.x;
+            pBuf->size.y = pBuf->prev->size.y;
+            pBuf = pBuf->prev;
+          }
+        }
       } else {
 	pBuf = pLast;
 	/* undraw last widget */
@@ -1402,8 +1438,8 @@
       }
     }
     
-    if((pDlg->pScroll->count - 1 <=
-	      (pDlg->pScroll->active * pDlg->pScroll->step))) {
+    if ((pDlg->pScroll->count - 1) <= (pDlg->pScroll->active * pDlg->pScroll->step)) {
+      /* scrollbar not needed anymore */
       hide_scrollbar(pDlg->pScroll);
       pDlg->pActiveWidgetList = NULL;
     }
@@ -1411,9 +1447,11 @@
     
     if(pDlg->pActiveWidgetList) {
       if (pDlg->pScroll->pScrollBar) {
-      pDlg->pScroll->pScrollBar->size.h = scrollbar_size(pDlg->pScroll);
+        widget_undraw(pDlg->pScroll->pScrollBar);
+        pDlg->pScroll->pScrollBar->size.h = scrollbar_size(pDlg->pScroll);
+        refresh_widget_background(pDlg->pScroll->pScrollBar);
+      }
     }
-    }
     
   } else { /* no scrollbar */
     pBuf = pDlg->pBeginActiveWidgetList;
@@ -1437,36 +1475,38 @@
         
   }
 
+  if (pWidget == pDlg->pBeginWidgetList) {
+    pDlg->pBeginWidgetList = pWidget->next;
+  }
+
   if (pWidget == pDlg->pBeginActiveWidgetList) {
     pDlg->pBeginActiveWidgetList = pWidget->next;
   }
 
-  if (pWidget == pDlg->pBeginWidgetList) {
-    pDlg->pBeginWidgetList = pWidget->next;
-  }
-  
   if (pWidget == pDlg->pEndActiveWidgetList) {
 
-    if (pDlg->pActiveWidgetList == pWidget) {
+    if (pWidget == pDlg->pEndWidgetList) {
+      pDlg->pEndWidgetList = pWidget->prev;
+    }
+
+    if (pWidget == pDlg->pActiveWidgetList) {
       pDlg->pActiveWidgetList = pWidget->prev;
     }
 
-    if (pWidget == pDlg->pEndWidgetList) {
-      pDlg->pEndWidgetList = pWidget->prev;
-    }
-    
     pDlg->pEndActiveWidgetList = pWidget->prev;
 
   }
 
-  if (pDlg->pActiveWidgetList && pDlg->pActiveWidgetList == pWidget) {
+  if (pDlg->pActiveWidgetList && (pDlg->pActiveWidgetList == pWidget)) {
     pDlg->pActiveWidgetList = pWidget->prev;
   }
 
   del_widget_from_gui_list(pWidget);
   
   if(pDlg->pScroll && pDlg->pScroll->pScrollBar && pDlg->pActiveWidgetList) {
+    widget_undraw(pDlg->pScroll->pScrollBar);
     pDlg->pScroll->pScrollBar->size.y = get_position(pDlg);
+    refresh_widget_background(pDlg->pScroll->pScrollBar);
   }
   
   return TRUE;
Index: client/gui-sdl/widget_checkbox.c
===================================================================
--- client/gui-sdl/widget_checkbox.c	(Revision 12407)
+++ client/gui-sdl/widget_checkbox.c	(Arbeitskopie)
@@ -45,10 +45,6 @@
     return -3;
   }
 
-  if (pIcon->gfx) {
-    widget_undraw(pIcon);
-  }
-
   src.x = (pIcon->theme->w / 4) * (Uint8) (get_wstate(pIcon));
   src.y = 0;
   src.w = (pIcon->theme->w / 4);
@@ -91,15 +87,6 @@
   
   pCBox->theme = pIcon;
 
-  /* if label transparen then clear background under widget or save this background */
-  if (get_wflags(pCBox) & WF_RESTORE_BACKGROUND) {
-    if (pCBox->gfx) {
-      widget_undraw(pCBox);
-    } else {
-      pCBox->gfx = crop_rect_from_surface(pCBox->dst->surface, &pCBox->size);
-    }
-  }
-
   /* redraw icon label */
   ret = redraw_iconlabel(pCBox);
 
Index: client/gui-sdl/gui_stuff.c
===================================================================
--- client/gui-sdl/gui_stuff.c	(Revision 12411)
+++ client/gui-sdl/gui_stuff.c	(Arbeitskopie)
@@ -2050,6 +2050,7 @@
     /* scrollbar exist and active, start mod. from last seen label */
     
     struct GUI *pLast;
+    bool widget_found = FALSE;
       
     /* this is always true becouse no-scrolbar case (active*step < count)
        will be suported in other part of code (see "else" part) */
@@ -2070,16 +2071,31 @@
     
     if(pLast == pDlg->pBeginActiveWidgetList) {
       if(pDlg->pScroll->step == 1) {
-        pBuf = pDlg->pActiveWidgetList->next;
-        pDlg->pActiveWidgetList = pBuf;
-        clear_wflag(pBuf, WF_HIDDEN);
-	while (pBuf != pWidget) {
-          pBuf->gfx = pBuf->prev->gfx;
-          pBuf->prev->gfx = NULL;
-          pBuf->size.x = pBuf->prev->size.x;
-          pBuf->size.y = pBuf->prev->size.y;
+        pDlg->pActiveWidgetList = pDlg->pActiveWidgetList->next;
+        clear_wflag(pDlg->pActiveWidgetList, WF_HIDDEN);
+        
+        /* look for the widget in the non-visible part */
+        pBuf = pDlg->pEndActiveWidgetList;
+        while (pBuf != pDlg->pActiveWidgetList) {
+          if (pBuf == pWidget) {
+            widget_found = TRUE;
+            pBuf = pDlg->pActiveWidgetList;
+            break;
+          }
           pBuf = pBuf->prev;
         }
+
+        /* if we haven't found it yet, look in the visible part and update the
+           positions of the other widgets */
+        if (!widget_found) {
+          while (pBuf != pWidget) {
+            pBuf->gfx = pBuf->prev->gfx;
+            pBuf->prev->gfx = NULL;
+            pBuf->size.x = pBuf->prev->size.x;
+            pBuf->size.y = pBuf->prev->size.y;
+            pBuf = pBuf->prev;
+          }
+        }
       } else {
 	pBuf = pLast;
 	/* undraw last widget */
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to