rnd-20031202-1-src
[rocksndiamonds.git] / src / editor.c
index 0fb85a1a7fdc0c710f15e71333b11cfafc1ee6a8..e7d703496190a21ce327829015cf2e7418bac395 100644 (file)
 #define ED_WIN_MB_RIGHT_YPOS           ED_WIN_MB_LEFT_YPOS
 
 /* values for the control window */
-#define ED_CTRL_BUTTONS_GFX_YPOS       236
-#define ED_CTRL_BUTTONS_ALT_GFX_YPOS   142
+#define ED_CTRL_NO_BUTTONS_GFX_XPOS    6
+#define ED_CTRL_NO_BUTTONS_GFX_YPOS    286
+#define ED_CTRL1_BUTTONS_GFX_YPOS      236
+#define ED_CTRL2_BUTTONS_GFX_YPOS      236
+#define ED_CTRL3_BUTTONS_GFX_YPOS      324
+#define ED_CTRL1_BUTTONS_ALT_GFX_YPOS  142
+#define ED_CTRL3_BUTTONS_ALT_GFX_YPOS  302
 
-#define ED_CTRL1_BUTTONS_HORIZ         4
-#define ED_CTRL1_BUTTONS_VERT          4
 #define ED_CTRL1_BUTTON_XSIZE          22
 #define ED_CTRL1_BUTTON_YSIZE          22
 #define ED_CTRL1_BUTTONS_XPOS          6
 #define ED_CTRL1_BUTTONS_YPOS          6
-#define ED_CTRL2_BUTTONS_HORIZ         3
-#define ED_CTRL2_BUTTONS_VERT          2
 #define ED_CTRL2_BUTTON_XSIZE          30
 #define ED_CTRL2_BUTTON_YSIZE          20
 #define ED_CTRL2_BUTTONS_XPOS          5
 #define ED_CTRL2_BUTTONS_YPOS          99
+#define ED_CTRL3_BUTTON_XSIZE          22
+#define ED_CTRL3_BUTTON_YSIZE          22
+#define ED_CTRL3_BUTTONS_XPOS          6
+#define ED_CTRL3_BUTTONS_YPOS          6
+
+#define ED_CTRL1_BUTTONS_HORIZ         4
+#define ED_CTRL1_BUTTONS_VERT          4
+#define ED_CTRL2_BUTTONS_HORIZ         3
+#define ED_CTRL2_BUTTONS_VERT          2
+#define ED_CTRL3_BUTTONS_HORIZ         3
+#define ED_CTRL3_BUTTONS_VERT          1
+
 #define ED_NUM_CTRL1_BUTTONS   (ED_CTRL1_BUTTONS_HORIZ * ED_CTRL1_BUTTONS_VERT)
 #define ED_NUM_CTRL2_BUTTONS   (ED_CTRL2_BUTTONS_HORIZ * ED_CTRL2_BUTTONS_VERT)
-#define ED_NUM_CTRL_BUTTONS    (ED_NUM_CTRL1_BUTTONS + ED_NUM_CTRL2_BUTTONS)
+#define ED_NUM_CTRL3_BUTTONS   (ED_CTRL3_BUTTONS_HORIZ * ED_CTRL3_BUTTONS_VERT)
+#define ED_NUM_CTRL1_2_BUTTONS (ED_NUM_CTRL1_BUTTONS + ED_NUM_CTRL2_BUTTONS)
+#define ED_NUM_CTRL_BUTTONS    (ED_NUM_CTRL1_BUTTONS + \
+                               ED_NUM_CTRL2_BUTTONS + \
+                               ED_NUM_CTRL3_BUTTONS)
 
 /* values for the element list */
 #define ED_ELEMENTLIST_XPOS            5
 #define GADGET_ID_GRAB_BRUSH           (GADGET_ID_TOOLBOX_FIRST + 13)
 #define GADGET_ID_WRAP_DOWN            (GADGET_ID_TOOLBOX_FIRST + 14)
 #define GADGET_ID_PICK_ELEMENT         (GADGET_ID_TOOLBOX_FIRST + 15)
+
 #define GADGET_ID_UNDO                 (GADGET_ID_TOOLBOX_FIRST + 16)
 #define GADGET_ID_INFO                 (GADGET_ID_TOOLBOX_FIRST + 17)
 #define GADGET_ID_SAVE                 (GADGET_ID_TOOLBOX_FIRST + 18)
 #define GADGET_ID_TEST                 (GADGET_ID_TOOLBOX_FIRST + 20)
 #define GADGET_ID_EXIT                 (GADGET_ID_TOOLBOX_FIRST + 21)
 
+#define GADGET_ID_CUSTOM_COPY_FROM     (GADGET_ID_TOOLBOX_FIRST + 22)
+#define GADGET_ID_CUSTOM_COPY_TO       (GADGET_ID_TOOLBOX_FIRST + 23)
+#define GADGET_ID_CUSTOM_EXCHANGE      (GADGET_ID_TOOLBOX_FIRST + 24)
+
 /* counter button identifiers */
-#define GADGET_ID_COUNTER_FIRST                (GADGET_ID_TOOLBOX_FIRST + 22)
+#define GADGET_ID_COUNTER_FIRST                (GADGET_ID_TOOLBOX_FIRST + 25)
 
 #define GADGET_ID_SELECT_LEVEL_DOWN    (GADGET_ID_COUNTER_FIRST + 0)
 #define GADGET_ID_SELECT_LEVEL_TEXT    (GADGET_ID_COUNTER_FIRST + 1)
@@ -736,28 +758,33 @@ static struct
   char *text;
 } control_info[ED_NUM_CTRL_BUTTONS] =
 {
-  { 's',       "draw single items"             },
-  { 'd',       "draw connected items"          },
-  { 'l',       "draw lines"                    },
-  { 'a',       "draw arcs"                     },
-  { 'r',       "draw outline rectangles"       },
-  { 'R',       "draw filled rectangles"        },
-  { '\0',      "wrap (rotate) level up"        },
-  { 't',       "enter text elements"           },
-  { 'f',       "flood fill"                    },
-  { '\0',      "wrap (rotate) level left"      },
-  { '?',       "properties of drawing element" },
-  { '\0',      "wrap (rotate) level right"     },
-  { '\0',      "random element placement"      },
-  { 'b',       "grab brush"                    },
-  { '\0',      "wrap (rotate) level down"      },
-  { ',',       "pick drawing element"          },
-  { 'U',       "undo last operation"           },
-  { 'I',       "level properties"              },
-  { 'S',       "save level"                    },
-  { 'C',       "clear level"                   },
-  { 'T',       "test level"                    },
-  { 'E',       "exit level editor"             }
+  { 's',       "draw single items"                     },
+  { 'd',       "draw connected items"                  },
+  { 'l',       "draw lines"                            },
+  { 'a',       "draw arcs"                             },
+  { 'r',       "draw outline rectangles"               },
+  { 'R',       "draw filled rectangles"                },
+  { '\0',      "wrap (rotate) level up"                },
+  { 't',       "enter text elements"                   },
+  { 'f',       "flood fill"                            },
+  { '\0',      "wrap (rotate) level left"              },
+  { '?',       "properties of drawing element"         },
+  { '\0',      "wrap (rotate) level right"             },
+  { '\0',      "random element placement"              },
+  { 'b',       "grab brush"                            },
+  { '\0',      "wrap (rotate) level down"              },
+  { ',',       "pick drawing element"                  },
+
+  { 'U',       "undo last operation"                   },
+  { 'I',       "level properties"                      },
+  { 'S',       "save level"                            },
+  { 'C',       "clear level"                           },
+  { 'T',       "test level"                            },
+  { 'E',       "exit level editor"                     },
+
+  { '\0',      "copy settings from other element"      },
+  { '\0',      "copy settings to other element"        },
+  { '\0',      "exchange settings with other element"  },
 };
 
 static int random_placement_value = 10;
@@ -950,7 +977,7 @@ static struct
     GADGET_ID_CHANGE_CONT_RND_DOWN,    GADGET_ID_CHANGE_CONT_RND_UP,
     GADGET_ID_CHANGE_CONT_RND_TEXT,    GADGET_ID_NONE,
     &custom_element_change.random,
-    NULL,                              "use random change:", "(%)"
+    NULL,                              "use random replace:", "%"
   },
 };
 
@@ -1043,6 +1070,7 @@ static struct ValueTextInfo options_move_pattern[] =
   { MV_ALONG_RIGHT_SIDE,       "along right side"              },
   { MV_TURNING_LEFT,           "turning left"                  },
   { MV_TURNING_RIGHT,          "turning right"                 },
+  { MV_WHEN_PUSHED,            "when pushed"                   },
   { -1,                                NULL                            }
 };
 
@@ -1104,20 +1132,21 @@ static struct ValueTextInfo options_consistency[] =
 
 static struct ValueTextInfo options_time_units[] =
 {
-  { FRAMES_PER_SECOND,         "seconds"                       },
   { 1,                         "frames"                        },
+  { FRAMES_PER_SECOND,         "seconds"                       },
   { -1,                                NULL                            }
 };
 
 static struct ValueTextInfo options_change_direct_action[] =
 {
-  { CE_TOUCHED_BY_PLAYER,      "touched by player"             },
-  { CE_PRESSED_BY_PLAYER,      "pressed by player"             },
-  { CE_PUSHED_BY_PLAYER,       "pushed by player"              },
-  { CE_ENTERED_BY_PLAYER,      "entered by player"             },
-  { CE_LEFT_BY_PLAYER,         "left by player"                },
+  { CE_TOUCHED_BY_PLAYER,      "touched by player ..."         },
+  { CE_PRESSED_BY_PLAYER,      "pressed by player ..."         },
+  { CE_PUSHED_BY_PLAYER,       "pushed by player ..."          },
+  { CE_ENTERED_BY_PLAYER,      "entered by player ..."         },
+  { CE_LEFT_BY_PLAYER,         "left by player ..."            },
   { CE_DROPPED_BY_PLAYER,      "dropped by player"             },
-  { CE_COLLISION,              "collision"                     },
+  { CE_SWITCHED,               "switched ..."                  },
+  { CE_COLLISION,              "collision ..."                 },
   { CE_IMPACT,                 "impact"                        },
   { CE_SMASHED,                        "smashed"                       },
   { -1,                                NULL                            }
@@ -1125,15 +1154,16 @@ static struct ValueTextInfo options_change_direct_action[] =
 
 static struct ValueTextInfo options_change_other_action[] =
 {
-  { CE_OTHER_GETS_TOUCHED,     "player touches"                },
-  { CE_OTHER_GETS_PRESSED,     "player presses"                },
-  { CE_OTHER_GETS_PUSHED,      "player pushes"                 },
-  { CE_OTHER_GETS_ENTERED,     "player enters"                 },
-  { CE_OTHER_GETS_LEFT,                "player leaves"                 },
+  { CE_OTHER_GETS_TOUCHED,     "player touches ..."            },
+  { CE_OTHER_GETS_PRESSED,     "player presses ..."            },
+  { CE_OTHER_GETS_PUSHED,      "player pushes ..."             },
+  { CE_OTHER_GETS_ENTERED,     "player enters ..."             },
+  { CE_OTHER_GETS_LEFT,                "player leaves ..."             },
   { CE_OTHER_GETS_DIGGED,      "player digs"                   },
   { CE_OTHER_GETS_COLLECTED,   "player collects"               },
   { CE_OTHER_GETS_DROPPED,     "player drops"                  },
   { CE_OTHER_IS_TOUCHING,      "touching ..."                  },
+  { CE_OTHER_IS_SWITCHING,     "switch of ..."                 },
   { CE_OTHER_IS_CHANGING,      "change of"                     },
   { CE_OTHER_IS_EXPLODING,     "explosion of"                  },
   { -1,                                NULL                            }
@@ -1514,7 +1544,7 @@ static struct
   {
     -1,                                        ED_COUNTER_YPOS(6) - MINI_TILEY,
     GADGET_ID_GRAVITY,                 GADGET_ID_DOUBLE_SPEED,
-    &level.gravity,
+    &level.initial_gravity,
     " ", "gravity",                    "set level gravity"
   },
   {
@@ -1659,13 +1689,13 @@ static struct
     ED_SETTINGS_XPOS(2),               ED_SETTINGS_YPOS(11),
     GADGET_ID_CHANGE_ONLY_COMPLETE,    GADGET_ID_NONE,
     &custom_element_change.only_complete,
-    NULL, "only use complete change",  "only use complete extended content"
+    NULL, "replace all or nothing",    "only replace when all can be changed"
   },
   {
     ED_SETTINGS_XPOS(2),               ED_SETTINGS_YPOS(12),
     GADGET_ID_CHANGE_USE_RANDOM,       GADGET_ID_NONE,
     &custom_element_change.use_random_change,
-    NULL, NULL,                                "use random value for new content"
+    NULL, NULL,                                "use percentage for random replace"
   },
   {
     ED_SETTINGS_XPOS(0),               ED_SETTINGS_YPOS(13),
@@ -1842,6 +1872,7 @@ static void RedrawDrawingElements();
 static void DrawDrawingWindow();
 static void DrawLevelInfoWindow();
 static void DrawPropertiesWindow();
+static void UpdateCustomElementGraphicGadgets();
 static boolean checkPropertiesConfig();
 static void CopyLevelToUndoBuffer(int);
 static void HandleDrawingAreas(struct GadgetInfo *);
@@ -1919,6 +1950,8 @@ static int editor_el_boulderdash[] =
   EL_BD_FIREFLY_DOWN,
   EL_EMPTY,
 };
+static int *editor_hl_boulderdash_ptr = editor_hl_boulderdash;
+static int *editor_el_boulderdash_ptr = editor_el_boulderdash;
 static int num_editor_hl_boulderdash = SIZEOF_ARRAY_INT(editor_hl_boulderdash);
 static int num_editor_el_boulderdash = SIZEOF_ARRAY_INT(editor_el_boulderdash);
 
@@ -2024,6 +2057,8 @@ static int editor_el_emerald_mine[] =
   EL_EM_GATE_3_GRAY,
   EL_EM_GATE_4_GRAY,
 };
+static int *editor_hl_emerald_mine_ptr = editor_hl_emerald_mine;
+static int *editor_el_emerald_mine_ptr = editor_el_emerald_mine;
 static int num_editor_hl_emerald_mine=SIZEOF_ARRAY_INT(editor_hl_emerald_mine);
 static int num_editor_el_emerald_mine=SIZEOF_ARRAY_INT(editor_el_emerald_mine);
 
@@ -2092,17 +2127,17 @@ static int editor_el_more[] =
   EL_PIG,
   EL_DRAGON,
 
-  EL_EMPTY,
+  EL_BUG,
   EL_MOLE_UP,
-  EL_EMPTY,
-  EL_EMPTY,
+  EL_BD_BUTTERFLY,
+  EL_BD_FIREFLY,
 
   EL_MOLE_LEFT,
   EL_EMPTY,
   EL_MOLE_RIGHT,
-  EL_EMPTY,
+  EL_PACMAN,
 
-  EL_EMPTY,
+  EL_SPACESHIP,
   EL_MOLE_DOWN,
   EL_BALLOON,
   EL_BALLOON_SWITCH_ANY,
@@ -2132,6 +2167,8 @@ static int editor_el_more[] =
   EL_EMC_WALL_6,
   EL_EMC_WALL_7,
 };
+static int *editor_hl_more_ptr = editor_hl_more;
+static int *editor_el_more_ptr = editor_el_more;
 static int num_editor_hl_more = SIZEOF_ARRAY_INT(editor_hl_more);
 static int num_editor_el_more = SIZEOF_ARRAY_INT(editor_el_more);
 
@@ -2155,6 +2192,8 @@ static int editor_el_sokoban[] =
   EL_SOKOBAN_FIELD_FULL,
   EL_STEELWALL,
 };
+static int *editor_hl_sokoban_ptr = editor_hl_sokoban;
+static int *editor_el_sokoban_ptr = editor_el_sokoban;
 static int num_editor_hl_sokoban = SIZEOF_ARRAY_INT(editor_hl_sokoban);
 static int num_editor_el_sokoban = SIZEOF_ARRAY_INT(editor_el_sokoban);
 
@@ -2227,6 +2266,8 @@ static int editor_el_supaplex[] =
   EL_SP_CHIP_TOP,
   EL_SP_CHIP_BOTTOM,
 };
+static int *editor_hl_supaplex_ptr = editor_hl_supaplex;
+static int *editor_el_supaplex_ptr = editor_el_supaplex;
 static int num_editor_hl_supaplex = SIZEOF_ARRAY_INT(editor_hl_supaplex);
 static int num_editor_el_supaplex = SIZEOF_ARRAY_INT(editor_el_supaplex);
 
@@ -2320,6 +2361,8 @@ static int editor_el_diamond_caves[] =
   EL_EXTRA_TIME,
   EL_EMPTY,
 };
+static int *editor_hl_diamond_caves_ptr = editor_hl_diamond_caves;
+static int *editor_el_diamond_caves_ptr = editor_el_diamond_caves;
 static int num_editor_hl_diamond_caves = SIZEOF_ARRAY_INT(editor_hl_diamond_caves);
 static int num_editor_el_diamond_caves = SIZEOF_ARRAY_INT(editor_el_diamond_caves);
 
@@ -2368,6 +2411,8 @@ static int editor_el_dx_boulderdash[] =
   EL_EMPTY,
   EL_EMPTY
 };
+static int *editor_hl_dx_boulderdash_ptr = editor_hl_dx_boulderdash;
+static int *editor_el_dx_boulderdash_ptr = editor_el_dx_boulderdash;
 static int num_editor_hl_dx_boulderdash = SIZEOF_ARRAY_INT(editor_hl_dx_boulderdash);
 static int num_editor_el_dx_boulderdash = SIZEOF_ARRAY_INT(editor_el_dx_boulderdash);
 
@@ -2471,6 +2516,8 @@ static int editor_el_chars[] =
   EL_CHAR(FONT_ASCII_CURSOR),
   EL_CHAR(' ')
 };
+static int *editor_hl_chars_ptr = editor_hl_chars;
+static int *editor_el_chars_ptr = editor_el_chars;
 static int num_editor_hl_chars = SIZEOF_ARRAY_INT(editor_hl_chars);
 static int num_editor_el_chars = SIZEOF_ARRAY_INT(editor_el_chars);
 
@@ -2659,6 +2706,8 @@ static int editor_el_custom[] =
   EL_CUSTOM_START + 126,
   EL_CUSTOM_START + 127
 };
+static int *editor_hl_custom_ptr = editor_hl_custom;
+static int *editor_el_custom_ptr = editor_el_custom;
 static int num_editor_hl_custom = SIZEOF_ARRAY_INT(editor_hl_custom);
 static int num_editor_el_custom = SIZEOF_ARRAY_INT(editor_el_custom);
 
@@ -2828,9 +2877,44 @@ static int editor_el_custom_more[] =
   EL_CUSTOM_START + 254,
   EL_CUSTOM_START + 255
 };
+static int *editor_hl_custom_more_ptr = editor_hl_custom_more;
+static int *editor_el_custom_more_ptr = editor_el_custom_more;
 static int num_editor_hl_custom_more = SIZEOF_ARRAY_INT(editor_hl_custom_more);
 static int num_editor_el_custom_more = SIZEOF_ARRAY_INT(editor_el_custom_more);
 
+static int editor_hl_user_defined[] =
+{
+  EL_CHAR('U'),
+  EL_CHAR('S'),
+  EL_CHAR('E'),
+  EL_CHAR('R'),
+
+  EL_CHAR('D'),
+  EL_CHAR('E'),
+  EL_CHAR('F'),
+  EL_CHAR('I'),
+
+  EL_CHAR('-'),
+  EL_CHAR('N'),
+  EL_CHAR('E'),
+  EL_CHAR('D'),
+};
+
+static int *editor_hl_user_defined_ptr = editor_hl_user_defined;
+static int *editor_el_user_defined_ptr = NULL;
+static int num_editor_hl_user_defined=SIZEOF_ARRAY_INT(editor_hl_user_defined);
+static int num_editor_el_user_defined = 0;
+
+static int editor_hl_empty[] = { };
+static int editor_el_empty[ED_NUM_ELEMENTLIST_BUTTONS];
+
+static int *editor_hl_empty_ptr = editor_hl_empty;
+static int *editor_el_empty_ptr = editor_el_empty;
+static int num_editor_hl_empty = 0;
+static int num_editor_el_empty = 0;    /* dynamically determined, if needed */
+
+static boolean use_el_empty = FALSE;
+
 static int *editor_elements = NULL;    /* dynamically allocated */
 static int num_editor_elements = 0;    /* dynamically determined */
 
@@ -2838,10 +2922,10 @@ static struct
 {
   boolean *setup_value;
 
-  int *headline_list;
+  int **headline_list;
   int *headline_list_size;
 
-  int *element_list;
+  int **element_list;
   int *element_list_size;
 
   boolean last_setup_value;
@@ -2850,53 +2934,63 @@ editor_elements_info[] =
 {
   {
     &setup.editor.el_boulderdash,
-    editor_hl_boulderdash,             &num_editor_hl_boulderdash,
-    editor_el_boulderdash,             &num_editor_el_boulderdash
+    &editor_hl_boulderdash_ptr,                &num_editor_hl_boulderdash,
+    &editor_el_boulderdash_ptr,                &num_editor_el_boulderdash
   },
   {
     &setup.editor.el_emerald_mine,
-    editor_hl_emerald_mine,            &num_editor_hl_emerald_mine,
-    editor_el_emerald_mine,            &num_editor_el_emerald_mine
+    &editor_hl_emerald_mine_ptr,       &num_editor_hl_emerald_mine,
+    &editor_el_emerald_mine_ptr,       &num_editor_el_emerald_mine
   },
   {
     &setup.editor.el_more,
-    editor_hl_more,                    &num_editor_hl_more,
-    editor_el_more,                    &num_editor_el_more
+    &editor_hl_more_ptr,               &num_editor_hl_more,
+    &editor_el_more_ptr,               &num_editor_el_more
   },
   {
     &setup.editor.el_sokoban,
-    editor_hl_sokoban,                 &num_editor_hl_sokoban,
-    editor_el_sokoban,                 &num_editor_el_sokoban
+    &editor_hl_sokoban_ptr,            &num_editor_hl_sokoban,
+    &editor_el_sokoban_ptr,            &num_editor_el_sokoban
   },
   {
     &setup.editor.el_supaplex,
-    editor_hl_supaplex,                        &num_editor_hl_supaplex,
-    editor_el_supaplex,                        &num_editor_el_supaplex
+    &editor_hl_supaplex_ptr,           &num_editor_hl_supaplex,
+    &editor_el_supaplex_ptr,           &num_editor_el_supaplex
   },
   {
     &setup.editor.el_diamond_caves,
-    editor_hl_diamond_caves,           &num_editor_hl_diamond_caves,
-    editor_el_diamond_caves,           &num_editor_el_diamond_caves
+    &editor_hl_diamond_caves_ptr,      &num_editor_hl_diamond_caves,
+    &editor_el_diamond_caves_ptr,      &num_editor_el_diamond_caves
   },
   {
     &setup.editor.el_dx_boulderdash,
-    editor_hl_dx_boulderdash,          &num_editor_hl_dx_boulderdash,
-    editor_el_dx_boulderdash,          &num_editor_el_dx_boulderdash
+    &editor_hl_dx_boulderdash_ptr,     &num_editor_hl_dx_boulderdash,
+    &editor_el_dx_boulderdash_ptr,     &num_editor_el_dx_boulderdash
   },
   {
     &setup.editor.el_chars,
-    editor_hl_chars,                   &num_editor_hl_chars,
-    editor_el_chars,                   &num_editor_el_chars
+    &editor_hl_chars_ptr,              &num_editor_hl_chars,
+    &editor_el_chars_ptr,              &num_editor_el_chars
   },
   {
     &setup.editor.el_custom,
-    editor_hl_custom,                  &num_editor_hl_custom,
-    editor_el_custom,                  &num_editor_el_custom
+    &editor_hl_custom_ptr,             &num_editor_hl_custom,
+    &editor_el_custom_ptr,             &num_editor_el_custom
   },
   {
     &setup.editor.el_custom_more,
-    editor_hl_custom_more,             &num_editor_hl_custom_more,
-    editor_el_custom_more,             &num_editor_el_custom_more
+    &editor_hl_custom_more_ptr,                &num_editor_hl_custom_more,
+    &editor_el_custom_more_ptr,                &num_editor_el_custom_more
+  },
+  {
+    &setup.editor.el_user_defined,
+    &editor_hl_user_defined_ptr,       &num_editor_hl_user_defined,
+    &editor_el_user_defined_ptr,       &num_editor_el_user_defined
+  },
+  {
+    &use_el_empty,
+    &editor_hl_empty_ptr,              &num_editor_hl_empty,
+    &editor_el_empty_ptr,              &num_editor_el_empty,
   },
   {
     NULL,
@@ -2967,14 +3061,22 @@ static void ReinitializeElementList()
   if (editor_elements != NULL)
     free(editor_elements);
 
-  /* do some sanity check for each element from element list at startup */
   if (!initialized)
   {
-    for (i=0; editor_elements_info[i].setup_value != NULL; i++)
+    /* initialize optional user defined element list */
+    LoadUserDefinedEditorElementList(&editor_el_user_defined_ptr,
+                                    &num_editor_el_user_defined);
+
+    /* initialize list of empty elements (used for padding, if needed) */
+    for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
+      editor_el_empty[i] = EL_EMPTY;
+
+    /* do some sanity checks for each element from element list */
+    for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
     {
-      for (j=0; j < *editor_elements_info[i].element_list_size; j++)
+      for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
       {
-       int element = editor_elements_info[i].element_list[j];
+       int element = (*editor_elements_info[i].element_list)[j];
 
        if (element >= NUM_FILE_ELEMENTS)
          Error(ERR_WARN, "editor element %d is runtime element", element);
@@ -2988,9 +3090,10 @@ static void ReinitializeElementList()
   }
 
   num_editor_elements = 0;
+  use_el_empty = FALSE;
 
   /* determine size of element list */
-  for (i=0; editor_elements_info[i].setup_value != NULL; i++)
+  for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
   {
     if (*editor_elements_info[i].setup_value)
     {
@@ -3003,26 +3106,26 @@ static void ReinitializeElementList()
 
   if (num_editor_elements < ED_NUM_ELEMENTLIST_BUTTONS)
   {
-    /* workaround: offer at least as many elements as element buttons exist */
-    int list_nr = 1;   /* see above: editor_elements_info for Emerald Mine */
+    /* offer at least as many elements as element buttons exist */
+    use_el_empty = TRUE;
+    num_editor_el_empty = ED_NUM_ELEMENTLIST_BUTTONS - num_editor_elements;
 
-    *editor_elements_info[list_nr].setup_value = TRUE;
-    num_editor_elements += *editor_elements_info[list_nr].element_list_size;
+    num_editor_elements += num_editor_el_empty;
   }
 
   editor_elements = checked_malloc(num_editor_elements * sizeof(int));
 
   /* fill element list */
-  for (i=0; editor_elements_info[i].setup_value != NULL; i++)
+  for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
   {
     if (*editor_elements_info[i].setup_value)
     {
       if (setup.editor.el_headlines)
-       for (j=0; j < *editor_elements_info[i].headline_list_size; j++)
-         editor_elements[pos++] = editor_elements_info[i].headline_list[j];
+       for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
+         editor_elements[pos++] = (*editor_elements_info[i].headline_list)[j];
 
-      for (j=0; j < *editor_elements_info[i].element_list_size; j++)
-       editor_elements[pos++] = editor_elements_info[i].element_list[j];
+      for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
+       editor_elements[pos++] = (*editor_elements_info[i].element_list)[j];
     }
   }
 
@@ -3033,6 +3136,35 @@ static void ReinitializeElementList()
     element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
 }
 
+void PrintEditorElementList()
+{
+  boolean *stop = &setup.editor.el_user_defined;
+  int i, j;
+
+  for (i = 0; editor_elements_info[i].setup_value != stop; i++)
+  {
+    for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
+    {
+      int element = (*editor_elements_info[i].headline_list)[j];
+
+      printf("# %s\n", element_info[element].token_name);
+    }
+
+    if (j > 0)
+      printf("#\n");
+
+    for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
+    {
+      int element = (*editor_elements_info[i].element_list)[j];
+
+      printf("# %s\n", element_info[element].token_name);
+    }
+
+    if (j > 0)
+      printf("#\n");
+  }
+}
+
 static void ReinitializeElementListButtons()
 {
   static boolean last_setup_value_headlines = FALSE;
@@ -3044,7 +3176,7 @@ static void ReinitializeElementListButtons()
     if (last_setup_value_headlines != setup.editor.el_headlines)
       initialization_needed = TRUE;
 
-    for (i=0; editor_elements_info[i].setup_value != NULL; i++)
+    for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
       if (editor_elements_info[i].last_setup_value !=
          *editor_elements_info[i].setup_value)
        initialization_needed = TRUE;
@@ -3058,7 +3190,7 @@ static void ReinitializeElementListButtons()
 
   /* store current setup values for next invocation of this function */
   last_setup_value_headlines = setup.editor.el_headlines;
-  for (i=0; editor_elements_info[i].setup_value != NULL; i++)
+  for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
     editor_elements_info[i].last_setup_value =
       *editor_elements_info[i].setup_value;
 
@@ -3078,8 +3210,8 @@ static void DrawElementBorder(int dest_x, int dest_y, int width, int height,
 
   getMiniGraphicSource(border_graphic, &src_bitmap, &src_x, &src_y);
 
-  for (y=0; y < num_mini_tiley; y++)
-    for (x=0; x < num_mini_tilex; x++)
+  for (y = 0; y < num_mini_tiley; y++)
+    for (x = 0; x < num_mini_tilex; x++)
       BlitBitmap(src_bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
                 dest_x - MINI_TILEX / 2 + x * MINI_TILEX,
                 dest_y - MINI_TILEY / 2 + y * MINI_TILEY);
@@ -3101,8 +3233,8 @@ static void DrawDrawingArea(int id)
     DrawMiniGraphicExt(drawto, gi->x, gi->y,
                       el2edimg(custom_element.gfx_element));
   else if (id == ED_DRAWING_ID_CUSTOM_CONTENT)
-    for (y=0; y<3; y++)
-      for (x=0; x<3; x++)
+    for (y = 0; y < 3; y++)
+      for (x = 0; x < 3; x++)
        DrawMiniGraphicExt(drawto,
                           gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
                           el2edimg(custom_element.content[x][y]));
@@ -3110,8 +3242,8 @@ static void DrawDrawingArea(int id)
     DrawMiniGraphicExt(drawto, gi->x, gi->y,
                       el2edimg(custom_element_change.target_element));
   else if (id == ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT)
-    for (y=0; y < 3; y++)
-      for (x=0; x < 3; x++)
+    for (y = 0; y < 3; y++)
+      for (x = 0; x < 3; x++)
        DrawMiniGraphicExt(drawto,
                           gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
                           el2edimg(custom_element_change.content[x][y]));
@@ -3123,8 +3255,8 @@ static void DrawDrawingArea(int id)
   {
     int nr = id - ED_DRAWING_ID_ELEMENT_CONTENT_0;
 
-    for (y=0; y < 3; y++)
-      for (x=0; x < 3; x++)
+    for (y = 0; y < 3; y++)
+      for (x = 0; x < 3; x++)
        DrawMiniGraphicExt(drawto,
                           gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
                           el2edimg(level.yamyam_content[nr][x][y]));
@@ -3147,13 +3279,13 @@ static void ScrollMiniLevel(int from_x, int from_y, int scroll)
   if (dx)
   {
     x = (dx == 1 ? 0 : ed_fieldx - 1);
-    for(y=0; y<ed_fieldy; y++)
+    for (y = 0; y < ed_fieldy; y++)
       DrawMiniElementOrWall(x, y, from_x, from_y);
   }
   else if (dy)
   {
     y = (dy == 1 ? 0 : ed_fieldy - 1);
-    for(x=0; x<ed_fieldx; x++)
+    for (x = 0; x < ed_fieldx; x++)
       DrawMiniElementOrWall(x, y, from_x, from_y);
   }
 
@@ -3169,7 +3301,7 @@ static void CreateControlButtons()
   int i;
 
   /* create toolbox buttons */
-  for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
+  for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
   {
     int id = i;
     int width, height;
@@ -3188,7 +3320,10 @@ static void CreateControlButtons()
        id == GADGET_ID_FILLED_BOX ||
        id == GADGET_ID_FLOOD_FILL ||
        id == GADGET_ID_GRAB_BRUSH ||
-       id == GADGET_ID_PICK_ELEMENT)
+       id == GADGET_ID_PICK_ELEMENT ||
+       id == GADGET_ID_CUSTOM_COPY_FROM ||
+       id == GADGET_ID_CUSTOM_COPY_TO ||
+       id == GADGET_ID_CUSTOM_EXCHANGE)
     {
       button_type = GD_TYPE_RADIO_BUTTON;
       radio_button_nr = RADIO_NR_DRAWING_TOOLBOX;
@@ -3219,8 +3354,13 @@ static void CreateControlButtons()
       gd_yoffset = ED_CTRL1_BUTTONS_YPOS + y * ED_CTRL1_BUTTON_YSIZE;
       width = ED_CTRL1_BUTTON_XSIZE;
       height = ED_CTRL1_BUTTON_YSIZE;
+
+      gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
+      gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
+      gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL1_BUTTONS_GFX_YPOS     + gd_yoffset;
+      gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL1_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
     }
-    else
+    else if (id < ED_NUM_CTRL1_2_BUTTONS)
     {
       int x = (i - ED_NUM_CTRL1_BUTTONS) % ED_CTRL2_BUTTONS_HORIZ;
       int y = (i - ED_NUM_CTRL1_BUTTONS) / ED_CTRL2_BUTTONS_HORIZ;
@@ -3229,12 +3369,27 @@ static void CreateControlButtons()
       gd_yoffset = ED_CTRL2_BUTTONS_YPOS + y * ED_CTRL2_BUTTON_YSIZE;
       width = ED_CTRL2_BUTTON_XSIZE;
       height = ED_CTRL2_BUTTON_YSIZE;
-    }
 
-    gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
-    gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
-    gd_y1  = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_GFX_YPOS + gd_yoffset;
-    gd_y2  = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
+      gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
+      gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
+      gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL2_BUTTONS_GFX_YPOS + gd_yoffset;
+      gd_y2 = 0;       /* no alternative graphic for these buttons */
+    }
+    else
+    {
+      int x = (i - ED_NUM_CTRL1_2_BUTTONS) % ED_CTRL3_BUTTONS_HORIZ + 1;
+      int y = (i - ED_NUM_CTRL1_2_BUTTONS) / ED_CTRL3_BUTTONS_HORIZ;
+
+      gd_xoffset = ED_CTRL3_BUTTONS_XPOS + x * ED_CTRL3_BUTTON_XSIZE;
+      gd_yoffset = ED_CTRL3_BUTTONS_YPOS + y * ED_CTRL3_BUTTON_YSIZE;
+      width = ED_CTRL3_BUTTON_XSIZE;
+      height = ED_CTRL3_BUTTON_YSIZE;
+
+      gd_x1 = DOOR_GFX_PAGEX6 + gd_xoffset;
+      gd_x2 = DOOR_GFX_PAGEX5 + gd_xoffset;
+      gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL3_BUTTONS_GFX_YPOS     + gd_yoffset;
+      gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL3_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
+    }
 
     gi = CreateGadget(GDI_CUSTOM_ID, id,
                      GDI_CUSTOM_TYPE_ID, i,
@@ -3263,7 +3418,7 @@ static void CreateControlButtons()
   }
 
   /* create buttons for scrolling of drawing area and element list */
-  for (i=0; i<ED_NUM_SCROLLBUTTONS; i++)
+  for (i = 0; i < ED_NUM_SCROLLBUTTONS; i++)
   {
     int id = scrollbutton_info[i].gadget_id;
     int x, y, width, height;
@@ -3321,7 +3476,7 @@ static void CreateControlButtons()
   }
 
   /* create buttons for element list */
-  for (i=0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
+  for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
   {
     Bitmap *deco_bitmap;
     int deco_x, deco_y, deco_xpos, deco_ypos;
@@ -3377,7 +3532,7 @@ static void CreateCounterButtons()
   int max_infotext_len = getMaxInfoTextLength();
   int i;
 
-  for (i=0; i<ED_NUM_COUNTERBUTTONS; i++)
+  for (i = 0; i < ED_NUM_COUNTERBUTTONS; i++)
   {
     int j;
     int x = SX + counterbutton_info[i].x;      /* down count button */
@@ -3392,7 +3547,7 @@ static void CreateCounterButtons()
     if (counterbutton_info[i].text_left != NULL)
       x += getTextWidthForGadget(counterbutton_info[i].text_left);
 
-    for (j=0; j<2; j++)
+    for (j = 0; j < 2; j++)
     {
       Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
       struct GadgetInfo *gi;
@@ -3528,7 +3683,7 @@ static void CreateDrawingAreas()
 {
   int i;
 
-  for (i=0; i<ED_NUM_DRAWING_AREAS; i++)
+  for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
   {
     struct GadgetInfo *gi;
     unsigned long event_mask;
@@ -3577,7 +3732,7 @@ static void CreateTextInputGadgets()
   int max_infotext_len = getMaxInfoTextLength();
   int i;
 
-  for (i=0; i<ED_NUM_TEXTINPUT; i++)
+  for (i = 0; i < ED_NUM_TEXTINPUT; i++)
   {
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     int gd_x, gd_y;
@@ -3625,7 +3780,7 @@ static void CreateTextAreaGadgets()
   int max_infotext_len = getMaxInfoTextLength();
   int i;
 
-  for (i=0; i<ED_NUM_TEXTAREAS; i++)
+  for (i = 0; i < ED_NUM_TEXTAREAS; i++)
   {
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     int gd_x, gd_y;
@@ -3674,7 +3829,7 @@ static void CreateSelectboxGadgets()
   int max_infotext_len = getMaxInfoTextLength();
   int i, j;
 
-  for (i=0; i<ED_NUM_SELECTBOX; i++)
+  for (i = 0; i < ED_NUM_SELECTBOX; i++)
   {
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     int gd_x, gd_y;
@@ -3692,7 +3847,7 @@ static void CreateSelectboxGadgets()
         implicitely cast -1 to an unsigned integer value!) */
       selectbox_info[i].size = 0;
 
-      for (j=0; selectbox_info[i].options[j].text != NULL; j++)
+      for (j = 0; selectbox_info[i].options[j].text != NULL; j++)
        if (strlen(selectbox_info[i].options[j].text) > selectbox_info[i].size)
          selectbox_info[i].size = strlen(selectbox_info[i].options[j].text);
 
@@ -3751,7 +3906,7 @@ static void CreateTextbuttonGadgets()
   int max_infotext_len = getMaxInfoTextLength();
   int i;
 
-  for (i=0; i<ED_NUM_TEXTBUTTONS; i++)
+  for (i = 0; i < ED_NUM_TEXTBUTTONS; i++)
   {
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     int gd_x1, gd_x2, gd_y1, gd_y2;
@@ -3832,7 +3987,7 @@ static void CreateGraphicbuttonGadgets()
   int i;
 
   /* create buttons for scrolling of drawing area and element list */
-  for (i=0; i < ED_NUM_GRAPHICBUTTONS; i++)
+  for (i = 0; i < ED_NUM_GRAPHICBUTTONS; i++)
   {
     int id = graphicbutton_info[i].gadget_id;
     int gd_x1, gd_x2, gd_y1, gd_y2;
@@ -3884,7 +4039,7 @@ static void CreateScrollbarGadgets()
 {
   int i;
 
-  for (i=0; i<ED_NUM_SCROLLBARS; i++)
+  for (i = 0; i < ED_NUM_SCROLLBARS; i++)
   {
     int id = scrollbar_info[i].gadget_id;
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
@@ -3966,7 +4121,7 @@ static void CreateCheckbuttonGadgets()
   gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
   gd_y  = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
 
-  for (i=0; i<ED_NUM_CHECKBUTTONS; i++)
+  for (i = 0; i < ED_NUM_CHECKBUTTONS; i++)
   {
     int id = checkbutton_info[i].gadget_id;
     int x = SX + checkbutton_info[i].x;
@@ -4029,7 +4184,7 @@ static void CreateRadiobuttonGadgets()
   gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
   gd_y  = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
 
-  for (i=0; i<ED_NUM_RADIOBUTTONS; i++)
+  for (i = 0; i < ED_NUM_RADIOBUTTONS; i++)
   {
     int id = radiobutton_info[i].gadget_id;
     int x = SX + radiobutton_info[i].x;
@@ -4105,7 +4260,7 @@ void FreeLevelEditorGadgets()
 {
   int i;
 
-  for (i=0; i<NUM_EDITOR_GADGETS; i++)
+  for (i = 0; i < NUM_EDITOR_GADGETS; i++)
     FreeGadget(level_editor_gadget[i]);
 }
 
@@ -4155,12 +4310,12 @@ static void MapControlButtons()
   int counter_id;
   int i;
 
-  /* map toolbox buttons */
-  for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
+  /* map toolbox buttons (excluding special CE toolbox buttons) */
+  for (i = 0; i < ED_NUM_CTRL1_2_BUTTONS; i++)
     MapGadget(level_editor_gadget[i]);
 
   /* map buttons to select elements */
-  for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
+  for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
     MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
@@ -4216,7 +4371,7 @@ static void MapTextInputGadget(int id)
   int y_above = textinput_info[id].y + yoffset_above;
 
   if (textinput_info[id].text_above)
-    DrawTextF(x_above, y_above, FONT_TEXT_1, textinput_info[id].text_above);
+    DrawTextS(x_above, y_above, FONT_TEXT_1, textinput_info[id].text_above);
 
   ModifyGadget(gi, GDI_TEXT_VALUE, textinput_info[id].value, GDI_END);
 
@@ -4232,7 +4387,7 @@ static void MapTextAreaGadget(int id)
   int y_above = textarea_info[id].y + yoffset_above;
 
   if (textarea_info[id].text_above)
-    DrawTextF(x_above, y_above, FONT_TEXT_1, textarea_info[id].text_above);
+    DrawTextS(x_above, y_above, FONT_TEXT_1, textarea_info[id].text_above);
 
   ModifyGadget(gi, GDI_TEXT_VALUE, textarea_info[id].value, GDI_END);
 
@@ -4356,7 +4511,7 @@ static void MapMainDrawingArea()
   boolean no_vertical_scrollbar = (lev_fieldy + 2 <= ed_fieldy);
   int i;
 
-  for (i=ED_SCROLLBUTTON_ID_AREA_FIRST; i<=ED_SCROLLBUTTON_ID_AREA_LAST; i++)
+  for (i=ED_SCROLLBUTTON_ID_AREA_FIRST; i <= ED_SCROLLBUTTON_ID_AREA_LAST; i++)
   {
     if (((i == ED_SCROLLBUTTON_ID_AREA_LEFT ||
          i == ED_SCROLLBUTTON_ID_AREA_RIGHT) &&
@@ -4369,7 +4524,7 @@ static void MapMainDrawingArea()
     MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
   }
 
-  for (i=ED_SCROLLBAR_ID_AREA_FIRST; i<=ED_SCROLLBAR_ID_AREA_LAST; i++)
+  for (i = ED_SCROLLBAR_ID_AREA_FIRST; i <= ED_SCROLLBAR_ID_AREA_LAST; i++)
   {
     if ((i == ED_SCROLLBAR_ID_AREA_HORIZONTAL && no_horizontal_scrollbar) ||
        (i == ED_SCROLLBAR_ID_AREA_VERTICAL && no_vertical_scrollbar))
@@ -4381,16 +4536,84 @@ static void MapMainDrawingArea()
   MapDrawingArea(ED_DRAWING_ID_DRAWING_LEVEL);
 }
 
+static void MapOrUnmapLevelEditorToolboxCustomGadgets(boolean map)
+{
+  int i;
+
+  for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
+  {
+    if (i == GADGET_ID_CUSTOM_COPY_FROM ||
+        i == GADGET_ID_CUSTOM_COPY_TO ||
+        i == GADGET_ID_CUSTOM_EXCHANGE)
+    {
+      if (map)
+       MapGadget(level_editor_gadget[i]);
+      else
+       UnmapGadget(level_editor_gadget[i]);
+    }
+  }
+}
+
+static void MapLevelEditorToolboxCustomGadgets()
+{
+  MapOrUnmapLevelEditorToolboxCustomGadgets(TRUE);
+}
+
+static void UnmapLevelEditorToolboxCustomGadgets()
+{
+  MapOrUnmapLevelEditorToolboxCustomGadgets(FALSE);
+}
+
+static void MapOrUnmapLevelEditorToolboxDrawingGadgets(boolean map)
+{
+  Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
+  int i;
+
+  for (i = 0; i < ED_NUM_CTRL1_BUTTONS; i++)
+  {
+    if (i != GADGET_ID_SINGLE_ITEMS &&
+       i != GADGET_ID_PROPERTIES &&
+       i != GADGET_ID_PICK_ELEMENT)
+    {
+      struct GadgetInfo *gi = level_editor_gadget[i];
+
+      if (map)
+       MapGadget(gi);
+      else
+      {
+       UnmapGadget(gi);
+
+       BlitBitmap(gd_bitmap, drawto,
+                  DOOR_GFX_PAGEX6 + ED_CTRL_NO_BUTTONS_GFX_XPOS,
+                  DOOR_GFX_PAGEY1 + ED_CTRL_NO_BUTTONS_GFX_YPOS,
+                  gi->width, gi->height, gi->x, gi->y);
+
+       redraw_mask |= REDRAW_DOOR_3;
+      }
+    }
+  }
+}
+
+static void MapLevelEditorToolboxDrawingGadgets()
+{
+  MapOrUnmapLevelEditorToolboxDrawingGadgets(TRUE);
+}
+
+static void UnmapLevelEditorToolboxDrawingGadgets()
+{
+  MapOrUnmapLevelEditorToolboxDrawingGadgets(FALSE);
+}
+
 static void UnmapDrawingArea(int id)
 {
   UnmapGadget(level_editor_gadget[id]);
 }
 
-void UnmapLevelEditorWindowGadgets()
+static void UnmapLevelEditorWindowGadgets()
 {
   int i;
 
-  for (i=0; i<NUM_EDITOR_GADGETS; i++)
+  for (i = 0; i < NUM_EDITOR_GADGETS; i++)
     if (level_editor_gadget[i]->x < SX + SXSIZE)
       UnmapGadget(level_editor_gadget[i]);
 }
@@ -4399,7 +4622,7 @@ void UnmapLevelEditorGadgets()
 {
   int i;
 
-  for (i=0; i<NUM_EDITOR_GADGETS; i++)
+  for (i = 0; i < NUM_EDITOR_GADGETS; i++)
     UnmapGadget(level_editor_gadget[i]);
 }
 
@@ -4428,8 +4651,8 @@ static boolean LevelChanged()
   boolean level_changed = FALSE;
   int x, y;
 
-  for(y=0; y<lev_fieldy; y++) 
-    for(x=0; x<lev_fieldx; x++)
+  for (y = 0; y < lev_fieldy; y++) 
+    for (x = 0; x < lev_fieldx; x++)
       if (Feld[x][y] != level.field[x][y])
        level_changed = TRUE;
 
@@ -4441,8 +4664,8 @@ static boolean LevelContainsPlayer()
   boolean player_found = FALSE;
   int x, y;
 
-  for(y=0; y<lev_fieldy; y++) 
-    for(x=0; x<lev_fieldx; x++)
+  for (y = 0; y < lev_fieldy; y++) 
+    for (x = 0; x < lev_fieldx; x++)
       if (Feld[x][y] == EL_PLAYER_1 ||
          Feld[x][y] == EL_SP_MURPHY) 
        player_found = TRUE;
@@ -4455,8 +4678,8 @@ static void CopyPlayfield(short src[MAX_LEV_FIELDX][MAX_LEV_FIELDY],
 {
   int x, y;
 
-  for(x=0; x<lev_fieldx; x++)
-    for(y=0; y<lev_fieldy; y++) 
+  for (x = 0; x < lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++) 
       dst[x][y] = src[x][y];
 }
 
@@ -4465,7 +4688,7 @@ static int setSelectboxValue(int selectbox_id, int new_value)
   int new_index_value = 0;
   int i;
 
-  for(i=0; selectbox_info[selectbox_id].options[i].text != NULL; i++)
+  for (i = 0; selectbox_info[selectbox_id].options[i].text != NULL; i++)
     if (selectbox_info[selectbox_id].options[i].value == new_value)
       new_index_value = i;
 
@@ -4475,13 +4698,164 @@ static int setSelectboxValue(int selectbox_id, int new_value)
   return new_index_value;
 }
 
+static void copy_custom_element_settings(int element_from, int element_to)
+{
+  struct ElementInfo *ei_from = &element_info[element_from];
+  struct ElementInfo *ei_to = &element_info[element_to];
+  int i, x, y;
+
+  /* ---------- copy element description ---------- */
+  for (i = 0; i < MAX_ELEMENT_NAME_LEN + 1; i++)
+    ei_to->description[i] = ei_from->description[i];
+
+  /* ---------- copy element properties ---------- */
+  Properties[element_to][EP_BITFIELD_BASE] =
+    Properties[element_from][EP_BITFIELD_BASE];
+
+  /* ---------- copy custom property values ---------- */
+
+  ei_to->use_gfx_element = ei_from->use_gfx_element;
+  ei_to->gfx_element = ei_from->gfx_element;
+
+  ei_to->collect_score = ei_from->collect_score;
+  ei_to->collect_count = ei_from->collect_count;
+
+  ei_to->push_delay_fixed = ei_from->push_delay_fixed;
+  ei_to->push_delay_random = ei_from->push_delay_random;
+  ei_to->move_delay_fixed = ei_from->move_delay_fixed;
+  ei_to->move_delay_random = ei_from->move_delay_random;
+
+  ei_to->move_pattern = ei_from->move_pattern;
+  ei_to->move_direction_initial = ei_from->move_direction_initial;
+  ei_to->move_stepsize = ei_from->move_stepsize;
+
+  ei_to->slippery_type = ei_from->slippery_type;
+
+  for (y = 0; y < 3; y++)
+    for (x = 0; x < 3; x++)
+      ei_to->content[x][y] = ei_from->content[x][y];
+
+  ei_to->num_change_pages = ei_from->num_change_pages;
+  setElementChangePages(ei_to, ei_to->num_change_pages);
+
+  for (i=0; i < ei_to->num_change_pages; i++)
+  {
+    struct ElementChangeInfo *change_to = &ei_to->change_page[i];
+    struct ElementChangeInfo *change_from = &ei_from->change_page[i];
+
+    /* always start with reliable default values */
+    setElementChangeInfoToDefaults(change_to);
+
+    change_to->events = change_from->events;
+
+    change_to->target_element = change_from->target_element;
+
+    change_to->delay_fixed = change_from->delay_fixed;
+    change_to->delay_random = change_from->delay_random;
+    change_to->delay_frames = change_from->delay_frames;
+
+    change_to->trigger_element = change_from->trigger_element;
+
+    change_to->explode = change_from->explode;
+    change_to->use_content = change_from->use_content;
+    change_to->only_complete = change_from->only_complete;
+    change_to->use_random_change = change_from->use_random_change;
+
+    change_to->random = change_from->random;
+    change_to->power = change_from->power;
+
+    for (y = 0; y < 3; y++)
+      for (x = 0; x < 3; x++)
+       change_to->content[x][y] = change_from->content[x][y];
+
+    change_to->can_change = change_from->can_change;
+
+    change_to->sides = change_from->sides;
+  }
+
+  /* mark this custom element as modified */
+  ei_to->modified_settings = TRUE;
+}
+
+static void replace_custom_element_in_settings(int element_from,
+                                              int element_to)
+{
+  int i, j, x, y;
+
+  for (i = 0; i < NUM_FILE_ELEMENTS; i++)
+  {
+    struct ElementInfo *ei = &element_info[i];
+
+    for (y = 0; y < 3; y++)
+      for (x = 0; x < 3; x++)
+       if (ei->content[x][y] == element_from)
+         ei->content[x][y] = element_to;
+
+    for (j=0; j < ei->num_change_pages; j++)
+    {
+      struct ElementChangeInfo *change = &ei->change_page[j];
+
+      if (change->target_element == element_from)
+       change->target_element = element_to;
+
+      if (change->trigger_element == element_from)
+       change->trigger_element = element_to;
+
+      for (y = 0; y < 3; y++)
+       for (x = 0; x < 3; x++)
+         if (change->content[x][y] == element_from)
+           change->content[x][y] = element_to;
+    }
+  }
+}
+
+static void replace_custom_element_in_playfield(int element_from,
+                                               int element_to)
+{
+  int x, y;
+
+  for (x = 0; x < lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++)
+      if (Feld[x][y] == element_from)
+       Feld[x][y] = element_to;
+}
+
+static void CopyCustomElement(int element_old, int element_new, int copy_mode)
+{
+  if (copy_mode == GADGET_ID_CUSTOM_COPY_FROM)
+  {
+    copy_custom_element_settings(element_new, element_old);
+  }
+  else if (copy_mode == GADGET_ID_CUSTOM_COPY_TO)
+  {
+    copy_custom_element_settings(element_old, element_new);
+  }
+  else if (copy_mode == GADGET_ID_CUSTOM_EXCHANGE)
+  {
+    copy_custom_element_settings(element_old, EL_DUMMY);
+    copy_custom_element_settings(element_new, element_old);
+    copy_custom_element_settings(EL_DUMMY, element_new);
+
+    replace_custom_element_in_settings(element_old, EL_DUMMY);
+    replace_custom_element_in_settings(element_new, element_old);
+    replace_custom_element_in_settings(EL_DUMMY, element_new);
+
+    replace_custom_element_in_playfield(element_old, EL_DUMMY);
+    replace_custom_element_in_playfield(element_new, element_old);
+    replace_custom_element_in_playfield(EL_DUMMY, element_new);
+  }
+
+  UpdateCustomElementGraphicGadgets();
+  DrawPropertiesWindow();
+}
+
 static void CopyCustomElementPropertiesToEditor(int element)
 {
   int i;
   int current_change_page = element_info[element].current_change_page;
 
   /* dynamically (re)build selectbox for selecting change page */
-  for (i=0; i < element_info[element].num_change_pages; i++)
+  for (i = 0; i < element_info[element].num_change_pages; i++)
   {
     sprintf(options_change_page_strings[i], "%d", i + 1);
 
@@ -4502,13 +4876,13 @@ static void CopyCustomElementPropertiesToEditor(int element)
   custom_element_change = *element_info[element].change;
 
   /* needed to initially set selectbox value variables to reliable defaults */
-  for (i=0; i < ED_NUM_SELECTBOX; i++)
+  for (i = 0; i < ED_NUM_SELECTBOX; i++)
     setSelectboxValue(i, *selectbox_info[i].value);
 
-  for (i=0; i < NUM_ELEMENT_PROPERTIES; i++)
+  for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
     custom_element_properties[i] = HAS_PROPERTY(element, i);
 
-  for (i=0; i < NUM_CHANGE_EVENTS; i++)
+  for (i = 0; i < NUM_CHANGE_EVENTS; i++)
     custom_element_change_events[i] = HAS_CHANGE_EVENT(element, i);
 
   /* ---------- element settings: configure (custom elements) ------------- */
@@ -4592,6 +4966,7 @@ static void CopyCustomElementPropertiesToEditor(int element)
      HAS_CHANGE_EVENT(element, CE_ENTERED_BY_PLAYER) ? CE_ENTERED_BY_PLAYER :
      HAS_CHANGE_EVENT(element, CE_LEFT_BY_PLAYER) ? CE_LEFT_BY_PLAYER :
      HAS_CHANGE_EVENT(element, CE_DROPPED_BY_PLAYER) ? CE_DROPPED_BY_PLAYER :
+     HAS_CHANGE_EVENT(element, CE_SWITCHED) ? CE_SWITCHED :
      HAS_CHANGE_EVENT(element, CE_COLLISION) ? CE_COLLISION :
      HAS_CHANGE_EVENT(element, CE_IMPACT) ? CE_IMPACT :
      HAS_CHANGE_EVENT(element, CE_SMASHED) ? CE_SMASHED :
@@ -4608,6 +4983,7 @@ static void CopyCustomElementPropertiesToEditor(int element)
      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_COLLECTED) ? CE_OTHER_GETS_COLLECTED :
      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_DROPPED) ? CE_OTHER_GETS_DROPPED :
      HAS_CHANGE_EVENT(element, CE_OTHER_IS_TOUCHING) ? CE_OTHER_IS_TOUCHING :
+     HAS_CHANGE_EVENT(element, CE_OTHER_IS_SWITCHING) ? CE_OTHER_IS_SWITCHING :
      HAS_CHANGE_EVENT(element, CE_OTHER_IS_CHANGING) ? CE_OTHER_IS_CHANGING :
      HAS_CHANGE_EVENT(element, CE_OTHER_IS_EXPLODING) ? CE_OTHER_IS_EXPLODING :
      custom_element_change.other_action);
@@ -4708,6 +5084,7 @@ static void CopyCustomElementPropertiesToGame(int element)
   custom_element_change_events[CE_ENTERED_BY_PLAYER] = FALSE;
   custom_element_change_events[CE_LEFT_BY_PLAYER] = FALSE;
   custom_element_change_events[CE_DROPPED_BY_PLAYER] = FALSE;
+  custom_element_change_events[CE_SWITCHED] = FALSE;
   custom_element_change_events[CE_COLLISION] = FALSE;
   custom_element_change_events[CE_IMPACT] = FALSE;
   custom_element_change_events[CE_SMASHED] = FALSE;
@@ -4724,15 +5101,16 @@ static void CopyCustomElementPropertiesToGame(int element)
   custom_element_change_events[CE_OTHER_GETS_COLLECTED] = FALSE;
   custom_element_change_events[CE_OTHER_GETS_DROPPED] = FALSE;
   custom_element_change_events[CE_OTHER_IS_TOUCHING] = FALSE;
+  custom_element_change_events[CE_OTHER_IS_SWITCHING] = FALSE;
   custom_element_change_events[CE_OTHER_IS_CHANGING] = FALSE;
   custom_element_change_events[CE_OTHER_IS_EXPLODING] = FALSE;
   custom_element_change_events[custom_element_change.other_action] =
     custom_element_change_events[CE_BY_OTHER_ACTION];
 
-  for (i=0; i < NUM_ELEMENT_PROPERTIES; i++)
+  for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
     SET_PROPERTY(element, i, custom_element_properties[i]);
 
-  for (i=0; i < NUM_CHANGE_EVENTS; i++)
+  for (i = 0; i < NUM_CHANGE_EVENTS; i++)
     SET_CHANGE_EVENT(element, i, custom_element_change_events[i]);
 
   /* copy change events also to special level editor variable */
@@ -4935,7 +5313,7 @@ static void ModifyEditorElementList()
 {
   int i;
 
-  for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
+  for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
   {
     int gadget_id = GADGET_ID_ELEMENTLIST_FIRST + i;
     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
@@ -4992,7 +5370,9 @@ static void DrawDrawingWindow()
 
   SetMainBackgroundImage(IMG_UNDEFINED);
   ClearWindow();
+
   UnmapLevelEditorWindowGadgets();
+  UnmapLevelEditorToolboxCustomGadgets();
 
   AdjustDrawingAreaGadgets();
   AdjustLevelScrollPosition();
@@ -5000,7 +5380,9 @@ static void DrawDrawingWindow()
   AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
 
   DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
+
   MapMainDrawingArea();
+  MapLevelEditorToolboxDrawingGadgets();
 }
 
 static void DrawLevelInfoWindow()
@@ -5019,19 +5401,19 @@ static void DrawLevelInfoWindow()
           "Editor Settings", FONT_TITLE_1);
 
   /* draw counter gadgets */
-  for (i=ED_COUNTER_ID_LEVEL_FIRST; i<=ED_COUNTER_ID_LEVEL_LAST; i++)
+  for (i = ED_COUNTER_ID_LEVEL_FIRST; i <= ED_COUNTER_ID_LEVEL_LAST; i++)
     MapCounterButtons(i);
 
   /* draw checkbutton gadgets */
-  for (i=ED_CHECKBUTTON_ID_LEVEL_FIRST; i<=ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
+  for (i=ED_CHECKBUTTON_ID_LEVEL_FIRST; i <= ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
     MapCheckbuttonGadget(i);
 
   /* draw radiobutton gadgets */
-  for (i=ED_RADIOBUTTON_ID_LEVEL_FIRST; i<=ED_RADIOBUTTON_ID_LEVEL_LAST; i++)
+  for (i=ED_RADIOBUTTON_ID_LEVEL_FIRST; i <= ED_RADIOBUTTON_ID_LEVEL_LAST; i++)
     MapRadiobuttonGadget(i);
 
   /* draw text input gadgets */
-  for (i=ED_TEXTINPUT_ID_LEVEL_FIRST; i<=ED_TEXTINPUT_ID_LEVEL_LAST; i++)
+  for (i = ED_TEXTINPUT_ID_LEVEL_FIRST; i <= ED_TEXTINPUT_ID_LEVEL_LAST; i++)
     MapTextInputGadget(i);
 
   /* draw drawing area */
@@ -5078,7 +5460,7 @@ static void DrawElementContentAreas()
   /* display counter to choose number of element content areas */
   MapCounterButtons(ED_COUNTER_ID_ELEMENT_CONTENT);
 
-  for (i=0; i < MAX_ELEMENT_CONTENTS; i++)
+  for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
   {
     int id = ED_DRAWING_ID_ELEMENT_CONTENT_0 + i;
     int font_height = getFontHeight(FONT_TEXT_1);
@@ -5148,7 +5530,7 @@ char *getElementDescriptionFilename(int element)
   return NULL;
 }
 
-static boolean PrintInfoText(char *text, int font_nr, int screen_line)
+static boolean PrintInfoText(char *text, int font_nr, int start_line)
 {
   int font_height = getFontHeight(font_nr);
   int pad_x = ED_SETTINGS_XPOS(0);
@@ -5157,26 +5539,54 @@ static boolean PrintInfoText(char *text, int font_nr, int screen_line)
   int sy = SY + pad_y;
   int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
 
-  if (screen_line >= max_lines_per_screen)
+  if (start_line >= max_lines_per_screen)
     return FALSE;
 
-  DrawText(sx, sy + screen_line * font_height, text, font_nr);
+  DrawText(sx, sy + start_line * font_height, text, font_nr);
 
   return TRUE;
 }
 
-static int PrintElementDescriptionFromFile(char *filename, int screen_line)
+#if 1
+
+static int PrintElementDescriptionFromFile(char *filename, int start_line)
+{
+  int font_nr = FONT_TEXT_2;
+  int font_width = getFontWidth(font_nr);
+  int font_height = getFontHeight(font_nr);
+  int pad_x = ED_SETTINGS_XPOS(0);
+  int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
+  int sx = SX + pad_x;
+  int sy = SY + pad_y + start_line * font_height;
+  int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
+  int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
+
+  return DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
+                         max_lines_per_screen);
+}
+
+#else
+
+static int PrintElementDescriptionFromFile(char *filename, int start_line)
 {
   int font_nr = FONT_TEXT_2;
   int font_width = getFontWidth(font_nr);
+  int font_height = getFontHeight(font_nr);
   int pad_x = ED_SETTINGS_XPOS(0);
+  int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
+  int sx = SX + pad_x;
+  int sy = SY + pad_y;
   int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
+  int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
+  int current_line = start_line;
   char line[MAX_LINE_LEN];
   char buffer[max_chars_per_line + 1];
   int buffer_len;
-  int lines_printed = 0;
   FILE *file;
 
+  if (current_line >= max_lines_per_screen)
+    return 0;
+
   if (filename == NULL)
     return 0;
 
@@ -5186,9 +5596,9 @@ static int PrintElementDescriptionFromFile(char *filename, int screen_line)
   buffer[0] = '\0';
   buffer_len = 0;
 
-  while(!feof(file))
+  while (!feof(file) && current_line < max_lines_per_screen)
   {
-    char *line_ptr, *word_ptr;
+    char *line_ptr;
     boolean last_line_was_empty = TRUE;
 
     /* read next line of input file */
@@ -5212,92 +5622,40 @@ static int PrintElementDescriptionFromFile(char *filename, int screen_line)
     if (strlen(line) == 0)             /* special case: force empty line */
       strcpy(line, "\n");
 
-    word_ptr = line;
+    line_ptr = line;
 
-    while (*word_ptr)
+    while (*line_ptr && current_line < max_lines_per_screen)
     {
-      boolean print_buffer = FALSE;
-      int word_len;
-
-      /* skip leading whitespaces */
-      while (*word_ptr == ' ' || *word_ptr == '\t')
-       word_ptr++;
-
-      line_ptr = word_ptr;
-      word_len = 0;
-
-      /* look for end of next word */
-      while (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0')
-      {
-       line_ptr++;
-       word_len++;
-      }
-
-      if (word_len == 0)
-      {
-       continue;
-      }
-      else if (*word_ptr == '\n')      /* special case: force empty line */
-      {
-       if (buffer_len == 0)
-         word_ptr++;
-
-       /* prevent printing of multiple empty lines */
-       if (buffer_len > 0 || !last_line_was_empty)
-         print_buffer = TRUE;
-      }
-      else if (word_len < max_chars_per_line - buffer_len)
-      {
-       /* word fits into text buffer -- add word */
-
-       if (buffer_len > 0)
-         buffer[buffer_len++] = ' ';
-
-       strncpy(&buffer[buffer_len], word_ptr, word_len);
-       buffer_len += word_len;
-       buffer[buffer_len] = '\0';
-       word_ptr += word_len;
-      }
-      else if (buffer_len > 0)
-      {
-       /* not enough space left for word in text buffer -- print buffer */
-
-       print_buffer = TRUE;
-      }
-      else
-      {
-       /* word does not fit at all into empty text buffer -- cut word */
-
-       strncpy(buffer, word_ptr, max_chars_per_line);
-       buffer[max_chars_per_line] = '\0';
-       word_ptr += max_chars_per_line;
-       print_buffer = TRUE;
-      }
-
-      if (print_buffer)
+      boolean buffer_filled = RenderLineToBuffer(&line_ptr,
+                                                buffer, &buffer_len,
+                                                last_line_was_empty,
+                                                max_chars_per_line);
+      if (buffer_filled)
       {
-       if (!PrintInfoText(buffer, font_nr, screen_line + lines_printed))
-         return lines_printed;
+       DrawText(sx, sy + current_line * font_height, buffer, font_nr);
+       current_line++;
 
        last_line_was_empty = (buffer_len == 0);
-       lines_printed++;
 
        buffer[0] = '\0';
        buffer_len = 0;
-       print_buffer = FALSE;
       }
     }
   }
 
   fclose(file);
 
-  if (buffer_len > 0)
-    if (PrintInfoText(buffer, font_nr, screen_line + lines_printed))
-      lines_printed++;
+  if (buffer_len > 0 && current_line < max_lines_per_screen)
+  {
+    DrawText(sx, sy + current_line * font_height, buffer, font_nr);
+    current_line++;
+  }
 
-  return lines_printed;
+  return (current_line - start_line);
 }
 
+#endif
+
 static void DrawPropertiesTabulatorGadgets()
 {
   struct GadgetInfo *gd_gi = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
@@ -5313,7 +5671,7 @@ static void DrawPropertiesTabulatorGadgets()
   if (IS_CUSTOM_ELEMENT(properties_element))
     id_last = ED_TEXTBUTTON_ID_PROPERTIES_ADVANCED;
 
-  for (i=id_first; i <= id_last; i++)
+  for (i = id_first; i <= id_last; i++)
   {
     int gadget_id = textbutton_info[i].gadget_id;
     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
@@ -5405,16 +5763,25 @@ static void DrawPropertiesInfo()
   int screen_line = 0;
   int i, x, y;
 
+#if DEBUG
+  if (IS_CUSTOM_ELEMENT(properties_element))
+  {
+    DrawTextF(pad_x, pad_y + screen_line++ * font2_height, FONT_TEXT_3,
+             "[Custom Element %d]", properties_element - EL_CUSTOM_START + 1);
+    screen_line++;
+  }
+#endif
+
   /* ----- print number of elements / percentage of this element in level */
 
   num_elements_in_level = 0;
-  for (y=0; y<lev_fieldy; y++) 
-    for (x=0; x<lev_fieldx; x++)
+  for (y = 0; y < lev_fieldy; y++) 
+    for (x = 0; x < lev_fieldx; x++)
       if (Feld[x][y] == properties_element)
        num_elements_in_level++;
   percentage = num_elements_in_level * 100.0 / (lev_fieldx * lev_fieldy);
 
-  DrawTextF(pad_x, pad_y + screen_line * font2_height, font1_nr,
+  DrawTextS(pad_x, pad_y + screen_line * font2_height, font1_nr,
            percentage_text);
   DrawTextF(pad_x + strlen(percentage_text) * font1_width,
            pad_y + screen_line++ * font2_height, font2_nr,
@@ -5424,21 +5791,21 @@ static void DrawPropertiesInfo()
 
   /* ----- print standard properties of this element */
 
-  DrawTextF(pad_x, pad_y + screen_line++ * font2_height, font1_nr,
+  DrawTextS(pad_x, pad_y + screen_line++ * font2_height, font1_nr,
            properties_text);
 
-  for (i=0; properties[i].value != -1; i++)
+  for (i = 0; properties[i].value != -1; i++)
   {
     if (!HAS_PROPERTY(properties_element, properties[i].value))
       continue;
 
-    DrawTextF(pad_x, pad_y + screen_line++ * font2_height, font2_nr,
+    DrawTextS(pad_x, pad_y + screen_line++ * font2_height, font2_nr,
              properties[i].text);
     num_standard_properties++;
   }
 
   if (num_standard_properties == 0)
-    DrawTextF(pad_x + strlen(properties_text) * font1_width,
+    DrawTextS(pad_x + strlen(properties_text) * font1_width,
              pad_y + (screen_line - 1) * font2_height, font2_nr, "none");
 
   screen_line++;
@@ -5539,7 +5906,7 @@ static boolean checkPropertiesConfig()
       HAS_CONTENT(properties_element))
     return TRUE;
   else
-    for (i=0; elements_with_counter[i].element != -1; i++)
+    for (i = 0; elements_with_counter[i].element != -1; i++)
       if (elements_with_counter[i].element == properties_element)
        return TRUE;
 
@@ -5558,7 +5925,7 @@ static void DrawPropertiesConfig()
   }
 
   /* check if there are elements where a score can be chosen for */
-  for (i=0; elements_with_counter[i].element != -1; i++)
+  for (i = 0; elements_with_counter[i].element != -1; i++)
   {
     if (elements_with_counter[i].element == properties_element)
     {
@@ -5617,7 +5984,7 @@ static void DrawPropertiesConfig()
       MapCheckbuttonGadget(i);
 
     /* draw counter gadgets */
-    for (i=ED_COUNTER_ID_CUSTOM_FIRST; i<=ED_COUNTER_ID_CUSTOM_LAST; i++)
+    for (i = ED_COUNTER_ID_CUSTOM_FIRST; i <= ED_COUNTER_ID_CUSTOM_LAST; i++)
       MapCounterButtons(i);
 
     /* draw selectbox gadgets */
@@ -5658,15 +6025,15 @@ static void DrawPropertiesAdvanced()
     MapCheckbuttonGadget(i);
 
   /* draw counter gadgets */
-  for (i=ED_COUNTER_ID_CHANGE_FIRST; i<=ED_COUNTER_ID_CHANGE_LAST; i++)
+  for (i = ED_COUNTER_ID_CHANGE_FIRST; i <= ED_COUNTER_ID_CHANGE_LAST; i++)
     MapCounterButtons(i);
 
   /* draw selectbox gadgets */
-  for (i=ED_SELECTBOX_ID_CHANGE_FIRST; i<=ED_SELECTBOX_ID_CHANGE_LAST; i++)
+  for (i = ED_SELECTBOX_ID_CHANGE_FIRST; i <= ED_SELECTBOX_ID_CHANGE_LAST; i++)
     MapSelectboxGadget(i);
 
   /* draw textbutton gadgets */
-  for (i=ED_TEXTBUTTON_ID_CHANGE_FIRST; i<=ED_TEXTBUTTON_ID_CHANGE_LAST; i++)
+  for (i=ED_TEXTBUTTON_ID_CHANGE_FIRST; i <= ED_TEXTBUTTON_ID_CHANGE_LAST; i++)
     MapTextbuttonGadget(i);
 
   /* draw graphicbutton gadgets */
@@ -5689,7 +6056,7 @@ static void DrawElementName(int x, int y, int element)
   char buffer[max_chars_per_line + 1];
 
   if (strlen(element_name) <= max_chars_per_line)
-    DrawTextF(x, y, font_nr, element_name);
+    DrawTextS(x, y, font_nr, element_name);
   else
   {
     int next_pos = max_chars_per_line;
@@ -5714,12 +6081,12 @@ static void DrawElementName(int x, int y, int element)
       }
     }
 
-    DrawTextF(x, y - font_height / 2, font_nr, buffer);
+    DrawTextS(x, y - font_height / 2, font_nr, buffer);
 
     strncpy(buffer, &element_name[next_pos], max_chars_per_line);
     buffer[max_chars_per_line] = '\0';
 
-    DrawTextF(x, y + font_height / 2, font_nr, buffer);
+    DrawTextS(x, y + font_height / 2, font_nr, buffer);
   }
 }
 
@@ -5739,6 +6106,11 @@ static void DrawPropertiesWindow()
     CopyCustomElementPropertiesToEditor(properties_element);
 
   UnmapLevelEditorWindowGadgets();
+  UnmapLevelEditorToolboxDrawingGadgets();
+  UnmapLevelEditorToolboxCustomGadgets();
+
+  if (IS_CUSTOM_ELEMENT(properties_element))
+    MapLevelEditorToolboxCustomGadgets();
 
   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
   ClearWindow();
@@ -5801,7 +6173,7 @@ static void DrawLine(int from_x, int from_y, int to_x, int to_y,
     if (from_x > to_x)
       swap_numbers(&from_x, &to_x);
 
-    for (x=from_x; x<=to_x; x++)
+    for (x = from_x; x <= to_x; x++)
       DrawLineElement(x, y, element, change_level);
   }
   else if (from_x == to_x)             /* vertical line */
@@ -5812,7 +6184,7 @@ static void DrawLine(int from_x, int from_y, int to_x, int to_y,
     if (from_y > to_y)
       swap_numbers(&from_y, &to_y);
 
-    for (y=from_y; y<=to_y; y++)
+    for (y = from_y; y <= to_y; y++)
       DrawLineElement(x, y, element, change_level);
   }
   else                                 /* diagonal line */
@@ -5828,7 +6200,7 @@ static void DrawLine(int from_x, int from_y, int to_x, int to_y,
       if (from_x > to_x)
        swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
 
-      for (x=0; x<=len_x; x++)
+      for (x = 0; x <= len_x; x++)
       {
        y = (int)(a * x + 0.5) * (to_y < from_y ? -1 : +1);
        DrawLineElement(from_x + x, from_y + y, element, change_level);
@@ -5841,7 +6213,7 @@ static void DrawLine(int from_x, int from_y, int to_x, int to_y,
       if (from_y > to_y)
        swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
 
-      for (y=0; y<=len_y; y++)
+      for (y = 0; y <= len_y; y++)
       {
        x = (int)(a * y + 0.5) * (to_x < from_x ? -1 : +1);
        DrawLineElement(from_x + x, from_y + y, element, change_level);
@@ -5867,7 +6239,7 @@ static void DrawFilledBox(int from_x, int from_y, int to_x, int to_y,
   if (from_y > to_y)
     swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
 
-  for (y=from_y; y<=to_y; y++)
+  for (y = from_y; y <= to_y; y++)
     DrawLine(from_x, y, to_x, y, element, change_level);
 }
 
@@ -5885,7 +6257,7 @@ static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
   /* not optimal (some points get drawn twice) but simple,
      and fast enough for the few points we are drawing */
 
-  for (x=0; x<=radius; x++)
+  for (x = 0; x <= radius; x++)
   {
     int sx, sy, lx, ly;
 
@@ -5900,7 +6272,7 @@ static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
       DrawLineElement(sx, sy, element, change_level);
   }
 
-  for (y=0; y<=radius; y++)
+  for (y = 0; y <= radius; y++)
   {
     int sx, sy, lx, ly;
 
@@ -6013,9 +6385,9 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
     from_lx = from_x + level_xpos;
     from_ly = from_y + level_ypos;
 
-    for (y=0; y<brush_height; y++)
+    for (y = 0; y < brush_height; y++)
     {
-      for (x=0; x<brush_width; x++)
+      for (x=0; x < brush_width; x++)
       {
        brush_buffer[x][y] = Feld[from_lx + x][from_ly + y];
 
@@ -6049,9 +6421,9 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
       return;
     }
 
-    for (y=0; y<brush_height; y++)
+    for (y = 0; y < brush_height; y++)
     {
-      for (x=0; x<brush_width; x++)
+      for (x = 0; x < brush_width; x++)
       {
        int sx = cursor_from_x + x;
        int sy = cursor_from_y + y;
@@ -6127,7 +6499,7 @@ static void FloodFill(int from_x, int from_y, int fill_element)
   old_element = Feld[from_x][from_y];
   Feld[from_x][from_y] = fill_element;
 
-  for(i=0;i<4;i++)
+  for (i = 0; i < 4; i++)
   {
     x = from_x + check[i][0];
     y = from_y + check[i][1];
@@ -6296,8 +6668,8 @@ static void CopyLevelToUndoBuffer(int mode)
       undo_buffer_steps++;
   }
 
-  for(x=0; x<lev_fieldx; x++)
-    for(y=0; y<lev_fieldy; y++)
+  for (x = 0; x < lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++)
       UndoBuffer[undo_buffer_position][x][y] = Feld[x][y];
 
   /* check if drawing operation forces change of border style */
@@ -6318,8 +6690,8 @@ static void RandomPlacement(int new_element)
   /* determine number of free positions for the new elements */
   /* (maybe this statement should be formatted a bit more readable...) */
   num_free_positions = 0;
-  for (x=0; x<lev_fieldx; x++)
-    for (y=0; y<lev_fieldy; y++)
+  for (x = 0; x < lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++)
       if ((free_position[x][y] =
           ((random_placement_background_restricted &&
             Feld[x][y] == random_placement_background_element) ||
@@ -6335,8 +6707,8 @@ static void RandomPlacement(int new_element)
   /* if not more free positions than elements to place, fill whole level */
   if (num_elements >= num_free_positions)
   {
-    for (x=0; x<lev_fieldx; x++)
-      for (y=0; y<lev_fieldy; y++)
+    for (x = 0; x < lev_fieldx; x++)
+      for (y = 0; y < lev_fieldy; y++)
        Feld[x][y] = new_element;
 
     DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
@@ -6368,12 +6740,12 @@ void WrapLevel(int dx, int dy)
   int wrap_dy = lev_fieldy - dy;
   int x, y;
 
-  for(x=0; x<lev_fieldx; x++)
-    for(y=0; y<lev_fieldy; y++)
+  for (x = 0; x < lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++)
       FieldBackup[x][y] = Feld[x][y];
 
-  for(x=0; x<lev_fieldx; x++)
-    for(y=0; y<lev_fieldy; y++)
+  for (x = 0; x < lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++)
       Feld[x][y] =
        FieldBackup[(x + wrap_dx) % lev_fieldx][(y + wrap_dy) % lev_fieldy];
 
@@ -6474,9 +6846,9 @@ static void HandleDrawingAreas(struct GadgetInfo *gi)
          if (new_element == EL_PLAYER_1)
          {
            /* remove player at old position */
-           for(y=0; y<lev_fieldy; y++)
+           for (y = 0; y < lev_fieldy; y++)
            {
-             for(x=0; x<lev_fieldx; x++)
+             for (x = 0; x < lev_fieldx; x++)
              {
                if (Feld[x][y] == EL_PLAYER_1)
                {
@@ -6905,6 +7277,9 @@ static void HandleCheckbuttons(struct GadgetInfo *gi)
 
 static void HandleControlButtons(struct GadgetInfo *gi)
 {
+  static int last_level_drawing_function = GADGET_ID_SINGLE_ITEMS;
+  static int last_edit_mode = ED_MODE_DRAWING;
+  static int last_custom_copy_mode = -1;
   int id = gi->custom_id;
   int button = gi->event.button;
   int step = BUTTON_STEPSIZE(button);
@@ -6914,8 +7289,11 @@ static void HandleControlButtons(struct GadgetInfo *gi)
   if (edit_mode == ED_MODE_DRAWING && drawing_function == GADGET_ID_TEXT)
     DrawLevelText(0, 0, 0, TEXT_END);
 
-  if (id < ED_NUM_CTRL1_BUTTONS && id != GADGET_ID_PROPERTIES &&
-      id != GADGET_ID_PICK_ELEMENT && edit_mode != ED_MODE_DRAWING &&
+  if (id < ED_NUM_CTRL1_BUTTONS &&
+      id != GADGET_ID_SINGLE_ITEMS &&
+      id != GADGET_ID_PROPERTIES &&
+      id != GADGET_ID_PICK_ELEMENT &&
+      edit_mode != ED_MODE_DRAWING &&
       drawing_function != GADGET_ID_PICK_ELEMENT &&
       !(GetKeyModState() & KMOD_Control))
   {
@@ -7077,14 +7455,28 @@ static void HandleControlButtons(struct GadgetInfo *gi)
        properties_element = new_element;
        DrawPropertiesWindow();
        edit_mode = ED_MODE_PROPERTIES;
+
+       last_level_drawing_function = drawing_function;
+       ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
+                     MB_LEFTBUTTON);
       }
       else
       {
        DrawDrawingWindow();
        edit_mode = ED_MODE_DRAWING;
+
+       ClickOnGadget(level_editor_gadget[last_level_drawing_function],
+                     MB_LEFTBUTTON);
       }
       break;
 
+    case GADGET_ID_CUSTOM_COPY_FROM:
+    case GADGET_ID_CUSTOM_COPY_TO:
+    case GADGET_ID_CUSTOM_EXCHANGE:
+      last_custom_copy_mode = id;
+      last_drawing_function = drawing_function;
+      break;
+
     case GADGET_ID_UNDO:
       if (undo_buffer_steps == 0)
       {
@@ -7102,8 +7494,8 @@ static void HandleControlButtons(struct GadgetInfo *gi)
        (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS;
       undo_buffer_steps--;
 
-      for(x=0; x<lev_fieldx; x++)
-       for(y=0; y<lev_fieldy; y++)
+      for (x = 0; x < lev_fieldx; x++)
+       for (y = 0; y < lev_fieldy; y++)
          Feld[x][y] = UndoBuffer[undo_buffer_position][x][y];
       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos,level_ypos);
       break;
@@ -7111,13 +7503,16 @@ static void HandleControlButtons(struct GadgetInfo *gi)
     case GADGET_ID_INFO:
       if (edit_mode != ED_MODE_INFO)
       {
-       DrawLevelInfoWindow();
+       last_edit_mode = edit_mode;
        edit_mode = ED_MODE_INFO;
+
+       DrawLevelInfoWindow();
       }
       else
       {
-       DrawDrawingWindow();
-       edit_mode = ED_MODE_DRAWING;
+       edit_mode = last_edit_mode;
+
+       DrawEditModeWindow();
       }
       break;
 
@@ -7128,8 +7523,8 @@ static void HandleControlButtons(struct GadgetInfo *gi)
        edit_mode = ED_MODE_DRAWING;
       }
 
-      for(x=0; x<MAX_LEV_FIELDX; x++) 
-       for(y=0; y<MAX_LEV_FIELDY; y++) 
+      for (x = 0; x < MAX_LEV_FIELDX; x++) 
+       for (y = 0; y < MAX_LEV_FIELDY; y++) 
          Feld[x][y] = (button == 1 ? EL_EMPTY : new_element);
       CopyLevelToUndoBuffer(GADGET_ID_CLEAR);
 
@@ -7201,6 +7596,19 @@ static void HandleControlButtons(struct GadgetInfo *gi)
        int element_position = id - GADGET_ID_ELEMENTLIST_FIRST;
        int new_element = editor_elements[element_position + element_shift];
 
+       if (last_custom_copy_mode != -1)
+       {
+         CopyCustomElement(properties_element, new_element,
+                           last_custom_copy_mode);
+
+         ClickOnGadget(level_editor_gadget[last_drawing_function],
+                       MB_LEFTBUTTON);
+
+         last_custom_copy_mode = -1;
+
+         break;
+       }
+
        PickDrawingElement(button, new_element);
 
        if (!stick_element_properties_window &&
@@ -7297,7 +7705,7 @@ void HandleLevelEditorKeyInput(Key key)
     else if (key == KSYM_Return || key == setup.shortcut.toggle_pause)
       ClickOnGadget(level_editor_gadget[GADGET_ID_TEST], button);
     else
-      for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
+      for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
        if (letter && letter == control_info[i].shortcut)
          if (!anyTextGadgetActive())
            ClickOnGadget(level_editor_gadget[i], button);
@@ -7536,25 +7944,25 @@ static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
   else
   {
     if (id == GADGET_ID_AMOEBA_CONTENT)
-      DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
+      DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
                "Amoeba content");
     else if (id == GADGET_ID_CUSTOM_GRAPHIC)
-      DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
+      DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
                "Custom graphic element");
     else if (id == GADGET_ID_CUSTOM_CONTENT)
       DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
                "Custom element content position: %d, %d", sx, sy);
     else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
-      DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
+      DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
                "New element after change");
     else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
-      DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
+      DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
                "New extended elements after change");
     else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
-      DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
+      DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
                "Other element triggering change");
     else if (id == GADGET_ID_RANDOM_BACKGROUND)
-      DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
+      DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
                "Random placement background");
     else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
             id <= GADGET_ID_ELEMENT_CONTENT_7)
@@ -7571,10 +7979,12 @@ void RequestExitLevelEditor(boolean ask_if_level_has_changed)
       Request("Level has changed! Exit without saving ?",
              REQ_ASK | REQ_STAY_OPEN))
   {
+#if 1
     CloseDoor(DOOR_CLOSE_1);
-    /*
+    SetDoorState(DOOR_CLOSE_2);
+#else
     CloseDoor(DOOR_CLOSE_ALL);
-    */
+#endif
     game_status = GAME_MODE_MAIN;
     DrawMainMenu();
   }