493520f0c584e1962f88bb9686b1b87c06db7502
[xonotic/netradiant.git] / radiant / mainframe.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 //
23 // Main Window for Q3Radiant
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include "stdafx.h"
29 #ifdef _WIN32
30 extern "C" {
31 #include <gdk/gdkwin32.h>
32 #define COMPILE_MULTIMON_STUBS
33 #include <multimon.h>
34 }
35 #endif
36 #include <gtk/gtk.h>
37 #include <glib/gi18n.h>
38 #include <gdk/gdkkeysyms.h>
39 #include <gdk/gdkprivate.h>
40 #include <sys/stat.h>
41 #if defined (__linux__) || defined (__APPLE__)
42   #include <unistd.h>
43 #endif
44 #include "gtkmisc.h"
45 #include "groupdialog.h"
46 #include "patchdialog.h"
47 #include "filters.h"
48
49 // use this to verbose what happens with the beyboard
50 #ifdef _DEBUG
51 //  #define DBG_KBD
52 #endif
53
54 // globals
55 CString g_strAppPath;                   ///< holds the full path of the executable
56 CString g_strDTDPath;                   ///< path to the DTD files
57 CString g_pidFile;                      ///< the global .pid file (only for global part of the startup)
58 CString g_pidGameFile;                  ///< the game-specific .pid file
59 CString g_strBitmapsPath;               // directory where the bitmaps are stored
60
61 /*!
62 points to the game tools directory, for instance
63 C:\Program Files\Quake III Arena\GtkRadiant
64 (or other games)
65 this is one of the main variables that are configured by the game selection on startup
66 <g_strGameToolsPath>/plugins
67 <g_strGameToolsPath>/modules
68 and also q3map, bspc
69 */
70 CString g_strGameToolsPath;             ///< this is set by g_PrefsDlg.mGamesDialog
71 CGameDescription *g_pGameDescription;   ///< shortcut to g_PrefsDlg.mGamesDialog.m_pCurrentDescription
72 CString g_strPluginsDir;                ///< name of plugins directory, always sub-directory of toolspath
73 CString g_strModulesDir;                ///< name of modules directory, always sub-directory of toolspath
74
75 /*!
76 directory for temp files
77 NOTE: on *nix this is were we check for .pid
78 */
79 CString g_strTempPath;
80 MainFrame* g_pParentWnd = NULL;         // used to precast to CMainFrame
81 PrefsDlg g_Preferences;                 // global prefs instance
82 PrefsDlg& g_PrefsDlg = g_Preferences;   // reference used throughout
83 int g_nUpdateBits = 0;                  // window update flags
84 bool g_bScreenUpdates = true;           // whether window painting is active, used in a few places
85                                         // to disable updates for speed reasons
86                                         // both of the above should be made members of CMainFrame
87 int g_bIgnoreCommands;                  // Used to ignore commands when checking menus/toolbars
88 GSList *g_BSPFrontendCommands;          // List of commands in the BSP menu
89
90 const int CMD_TEXTUREWAD_END = CMD_TEXTUREWAD + MAX_TEXTUREDIRS - 1;
91 const int CMD_BSPCOMMAND_END = CMD_BSPCOMMAND + 127;
92
93 extern bool g_bCrossHairs;
94 extern int g_argc;
95 extern char** g_argv;
96 extern PatchDialog g_PatchDialog;
97
98 GtkAccelGroup* global_accel;
99
100 void Select_Ungroup ();
101
102 // command mapping stuff
103 //
104 // m_strCommand is the command string
105 // m_nKey is the GDK_??? equivelant
106 // m_nModifiers are key states as follows
107 //  bit
108 //    1 - shift
109 //    2 - alt
110 //    4 - control
111 //    8 - press only
112 //
113 #define SPEED_MOVE      32
114 #define SPEED_TURN      22.5
115
116 // NOTE: the menu item field is REQUIRED, Gtk uses it to bind the keyboard shortcut
117 // - if you add a command here and you don't want a menu item, use the "hidden" menu
118 // - if you decide to add a menu item, check if it's not in the "hidden" menu already
119 SCommandInfo g_Commands[] =
120 {
121   {"CycleOutlineStyle", 'J', 0x00, ID_SELECTION_OUTLINESTYLE, "menu_selection_outlinestyle"},
122   {"CSGMerge", 'U', 0x04, ID_SELECTION_CSGMERGE, "menu_selection_csgmerge"},
123   {"CSGSubtract", 'U', 0x01, ID_SELECTION_CSGSUBTRACT, "menu_selection_csgsubstract"},
124   //  {"ViewGroups", 'G', 0x00, ID_VIEW_GROUPS, "menu_view_groups"}, (temporary disabled)
125   {"SelectFuncGroup", 'G', 0x00, ID_SELECT_FUNC_GROUP, "menu_select_func_group"},
126   {"HideSelected", 'H', 0x00, ID_VIEW_HIDESHOW_HIDESELECTED, "menu_view_hideshow_hideselected"},
127   {"ShowHidden", 'H', 0x01, ID_VIEW_HIDESHOW_SHOWHIDDEN, "menu_view_hideshow_showhidden"},
128   {"BendMode", 'B', 0x00, ID_PATCH_BEND, "menu_patch_bend"},
129   {"FitTexture", 'B', 0x01, IDC_BTN_FACEFIT, "menu_idc_btn_facefit"},
130   {"ViewTextures", 'T', 0, ID_VIEW_TEXTURE, "menu_view_texture"},
131   {"ThickenPatch", 'T', 0x04, ID_CURVE_THICKEN, "menu_curve_thicken"},
132   {"MakeOverlayPatch", 'Y', 0, ID_CURVE_OVERLAY_SET, "menu_curve_overlay_set"},
133   {"ClearPatchOverlays", 'L', 0x04, ID_CURVE_OVERLAY_CLEAR, "menu_curve_overlay_clear"},
134   {"SurfaceInspector", 'S', 0, ID_TEXTURES_INSPECTOR, "menu_textures_inspector"},
135   {"PatchInspector", 'S', 0x01, ID_PATCH_INSPECTOR, "menu_patch_inspector"},
136   {"RedisperseRows", 'E', 0x04, ID_CURVE_REDISPERSE_ROWS, "menu_curve_redisperse_rows"},
137   {"RedisperseIntermediateCols", 'E', 0x05, ID_CURVE_REDISPERSE_INTERMEDIATE_COLS, "menu_curve_redisperse_cols"},
138   {"InvertCurveTextureX", 'I', 0x05, ID_CURVE_NEGATIVETEXTUREY, "menu_curve_negativetexturey"},
139   {"InvertCurveTextureY", 'I', 0x01, ID_CURVE_NEGATIVETEXTUREX, "menu_curve_negativetexturex"},
140   {"InvertCurve", 'I', 0x04, ID_CURVE_NEGATIVE, "menu_curve_negative"},
141   {"IncPatchColumn", GDK_KP_Add, 0x05, ID_CURVE_INSERTCOLUMN, "menu_curve_insertcolumn"},
142   {"IncPatchRow", GDK_KP_Add, 0x04, ID_CURVE_INSERTROW, "menu_curve_insertrow"},
143   {"DecPatchColumn", GDK_KP_Subtract, 0x05, ID_CURVE_DELETECOLUMN, "menu_curve_deletecolumn"},
144   {"DecPatchRow", GDK_KP_Subtract, 0x04, ID_CURVE_DELETEROW, "menu_curve_deleterow"},
145   {"Patch TAB", GDK_Tab, 0x00, ID_PATCH_TAB, "menu_patch_tab"},
146   {"Patch TAB", GDK_Tab, 0x01, ID_PATCH_TAB, "menu_patch_tab"},
147   {"SelectNudgeDown", GDK_Down, 0x02, ID_SELECTION_SELECT_NUDGEDOWN, "menu_selection_select_nudgedown"},
148   {"EntityColor",'K', 0, ID_MISC_SELECTENTITYCOLOR, "menu_misc_select_entitycolor"},
149   {"CameraForward", GDK_Up, 0, ID_CAMERA_FORWARD, "menu_camera_forward"},
150   {"CameraBack", GDK_Down, 0, ID_CAMERA_BACK, "menu_camera_back"},
151   {"CameraLeft", GDK_Left, 0, ID_CAMERA_LEFT, "menu_camera_left"},
152   {"CameraRight", GDK_Right, 0, ID_CAMERA_RIGHT, "menu_camera_right"},
153   {"CameraUp", 'D', 0, ID_CAMERA_UP, "menu_camera_up"},
154   {"CameraDown", 'C', 0, ID_CAMERA_DOWN, "menu_camera_down"},
155   {"CameraAngleUp", 'A', 0, ID_CAMERA_ANGLEUP, "menu_camera_angleup"},
156   {"CameraAngleDown", 'Z', 0, ID_CAMERA_ANGLEDOWN, "menu_camera_angledown"},
157   {"CameraStrafeRight", GDK_period, 0, ID_CAMERA_STRAFERIGHT, "menu_camera_straferight"},
158   {"CameraStrafeLeft", GDK_comma, 0, ID_CAMERA_STRAFELEFT, "menu_camera_strafeleft"},
159   {"ToggleGrid", '0', 0, ID_GRID_TOGGLE, "menu_grid_toggle"},
160   {"SetGrid1", '1', 0, ID_GRID_1, "menu_grid_1"},
161   {"SetGrid2", '2', 0, ID_GRID_2, "menu_grid_2"},
162   {"SetGrid4", '3', 0, ID_GRID_4, "menu_grid_4"},
163   {"SetGrid8", '4', 0, ID_GRID_8, "menu_grid_8"},
164   {"SetGrid16", '5', 0, ID_GRID_16, "menu_grid_16"},
165   {"SetGrid32", '6', 0, ID_GRID_32, "menu_grid_32"},
166   {"SetGrid64", '7', 0, ID_GRID_64, "menu_grid_64"},
167   {"SetGrid128", '8', 0, ID_GRID_128, "menu_grid_128"},
168   {"SetGrid256", '9', 0, ID_GRID_256, "menu_grid_256"},
169   {"DragEdges", 'E', 0, ID_SELECTION_DRAGEDGES, "menu_selection_dragedges"},
170   {"DragVertices", 'V', 0, ID_SELECTION_DRAGVERTECIES, "menu_selection_dragvertecies"},
171   {"ViewEntityInfo", 'N', 0, ID_VIEW_ENTITY, "menu_view_entity"},
172   //  {"ViewConsole", 'O', 0, ID_VIEW_CONSOLE, "menu_0,"},
173   {"CloneSelection", GDK_space, 0, ID_SELECTION_CLONE, "menu_selection_clone"},
174   {"DeleteSelection", GDK_BackSpace, 0, ID_SELECTION_DELETE, "menu_selection_delete"},
175   {"UnSelectSelection", GDK_Escape, 0, ID_SELECTION_DESELECT, "menu_selection_deselect"},
176   {"CenterView", GDK_End, 0, ID_VIEW_CENTER, "menu_view_center"},
177   {"ZoomOut", GDK_Insert, 0, ID_VIEW_ZOOMOUT, "menu_view_zoomout"},
178   {"ZoomIn", GDK_Delete, 0, ID_VIEW_ZOOMIN, "menu_view_zoomin"},
179   {"UpFloor", GDK_Prior, 0, ID_VIEW_UPFLOOR, "menu_view_upfloor"},
180   {"DownFloor", GDK_Next, 0, ID_VIEW_DOWNFLOOR, "menu_view_downfloor"},
181   {"ToggleClipper", 'X', 0, ID_VIEW_CLIPPER, "menu_view_clipper"},
182   {"ToggleCrosshairs", 'X', 0x01, ID_VIEW_CROSSHAIR, "menu_view_crosshair"},
183   {"TogTexLock", 'T', 0x01, ID_TOGGLE_LOCK, "menu_toggle_lock"},
184   {"TogTexRotLock", 'R', 0x01, ID_TOGGLE_ROTATELOCK, "menu_toggle_rotatelock"},
185   {"ToggleRealtime", 'R', 0x04, ID_VIEW_CAMERAUPDATE, "menu_view_cameraupdate"},
186   {"EntityList", 'L', 0, ID_EDIT_ENTITYINFO, "menu_edit_entityinfo"},
187   {"Preferences", 'P', 0, ID_PREFS, "menu_prefs"},
188   {"ToggleCamera", 'C', 0x05, ID_TOGGLECAMERA, "menu_togglecamera"},
189   {"ToggleConsole", 'O', 0, ID_TOGGLECONSOLE, "menu_toggleconsole"},
190   {"ToggleView", 'V', 0x05, ID_TOGGLEVIEW, "menu_toggleview"},
191   {"ToggleZ", 'Z', 0x05, ID_TOGGLEZ, "menu_togglez"},
192   {"ConnectSelection", 'K', 0x04, ID_SELECTION_CONNECT, "menu_selection_connect"},
193   {"Brush3Sided", '3', 0x04, ID_BRUSH_3SIDED, "menu_brush_3sided"},
194   {"Brush4Sided", '4', 0x04, ID_BRUSH_4SIDED, "menu_brush_4sided"},
195   {"Brush5Sided", '5', 0x04, ID_BRUSH_5SIDED, "menu_brush_5sided"},
196   {"Brush6Sided", '6', 0x04, ID_BRUSH_6SIDED, "menu_brush_6sided"},
197   {"Brush7Sided", '7', 0x04, ID_BRUSH_7SIDED, "menu_brush_7sided"},
198   {"Brush8Sided", '8', 0x04, ID_BRUSH_8SIDED, "menu_brush_8sided"},
199   {"Brush9Sided", '9', 0x04, ID_BRUSH_9SIDED, "menu_brush_9sided"},
200   {"MatrixTranspose", 'M', 0x05, ID_CURVE_MATRIX_TRANSPOSE, "menu_curve_matrix_transpose"},
201   {"MakeDetail", 'M', 0x04, ID_SELECTION_MAKE_DETAIL, "menu_selection_make_detail"},
202   {"MapInfo", 'M', 0, ID_EDIT_MAPINFO, "menu_edit_mapinfo"},
203   {"NextLeakSpot", 'K', 0x05, ID_MISC_NEXTLEAKSPOT, "menu_misc_nextleakspot"},
204   {"PrevLeakSpot", 'L', 0x05, ID_MISC_PREVIOUSLEAKSPOT, "menu_misc_previousleakspot"},
205   {"FileOpen", 'O', 0x04, ID_FILE_OPEN, "menu_file_open"},
206   {"FileSave", 'S', 0x04, ID_FILE_SAVE, "menu_file_save"},
207   //% {"Exit", 'X', 0x04, ID_FILE_EXIT, "menu_file_exit"}, // ydnar: Ctrl+X should be cut
208   {"CenterXYView", GDK_Tab, 0x05, ID_VIEW_CENTERVIEW, "menu_view_centerview"},
209   {"NextView", GDK_Tab, 0x04, ID_VIEW_NEXTVIEW, "menu_view_nextview"},
210   {"ClipSelected", GDK_Return, 0x00, ID_CLIP_SELECTED, "menu_clip_selected"},
211   {"SplitSelected", GDK_Return, 0x01, ID_SPLIT_SELECTED, "menu_split_selected"},
212   {"FlipClip", GDK_Return, 0x04, ID_FLIP_CLIP, "menu_flip_clip"},
213   {"MouseRotate", 'R', 0x00, ID_SELECT_MOUSEROTATE, "menu_select_mouserotate"},
214   {"Copy", 'C', 0x04, ID_EDIT_COPYBRUSH, "menu_edit_copybrush"},
215   {"Paste", 'V', 0x04, ID_EDIT_PASTEBRUSH, "menu_edit_pastebrush"},
216   {"PasteToCamera", 'V', RAD_ALT, ID_EDIT_PASTEBRUSHTOCAMERA, "menu_edit_pastebrushtocamera"},
217   {"Undo", 'Z', 0x04, ID_EDIT_UNDO, "menu_edit_undo"},
218   {"Redo", 'Y', 0x04, ID_EDIT_REDO, "menu_edit_redo"},
219   {"ZZoomOut", GDK_Insert, 0x04, ID_VIEW_ZZOOMOUT, "menu_view_zzoomout"},
220   {"ZZoomIn", GDK_Delete, 0x04, ID_VIEW_ZZOOMIN, "menu_view_zzoomin"},
221   {"TexRotateClock", GDK_Next, 0x01, ID_SELECTION_TEXTURE_ROTATECLOCK, "menu_selection_texture_rotateclock"},
222   {"TexRotateCounter", GDK_Prior, 0x01, ID_SELECTION_TEXTURE_ROTATECOUNTER, "menu_selection_texture_rotatecounter"},
223   {"TexScaleUp", GDK_Up, 0x04, ID_SELECTION_TEXTURE_SCALEUP, "menu_selection_texture_scaleup"},
224   {"TexScaleDown", GDK_Down, 0x04, ID_SELECTION_TEXTURE_SCALEDOWN, "menu_selection_texture_scaledown"},
225   {"TexShiftLeft", GDK_Left, 0x01, ID_SELECTION_TEXTURE_SHIFTLEFT, "menu_selection_texture_shiftleft"},
226   {"TexShiftRight", GDK_Right, 0x01, ID_SELECTION_TEXTURE_SHIFTRIGHT, "menu_selection_texture_shiftright"},
227   {"TexShiftUp", GDK_Up, 0x01, ID_SELECTION_TEXTURE_SHIFTUP, "menu_selection_texture_shiftup"},
228   {"TexShiftDown", GDK_Down, 0x01, ID_SELECTION_TEXTURE_SHIFTDOWN, "menu_selection_texture_shiftdown"},
229   {"GridDown", '[', 0x00, ID_GRID_PREV, "menu_grid_prev"},
230   {"GridUp", ']', 0x00, ID_GRID_NEXT, "menu_grid_next"},
231   {"TexScaleLeft", GDK_Left, 0x04, ID_SELECTION_TEXTURE_SCALELEFT, "menu_selection_texture_scaleleft"},
232   {"TexScaleRight", GDK_Right, 0x04, ID_SELECTION_TEXTURE_SCALERIGHT, "menu_selection_texture_scaleright"},
233   {"CubicClipZoomOut", ']', 0x04, ID_VIEW_CUBEOUT, "menu_view_cubeout"},
234   {"CubicClipZoomIn", '[', 0x04, ID_VIEW_CUBEIN, "menu_view_cubein"},
235   {"ToggleCubicClip", '\\', 0x04, ID_VIEW_CUBICCLIPPING, "menu_view_cubicclipping"},
236   {"MoveSelectionDOWN", GDK_KP_Subtract, 0x00, ID_SELECTION_MOVEDOWN, "menu_selection_movedown"},
237   {"MoveSelectionUP", GDK_KP_Add, 0x00, ID_SELECTION_MOVEUP, "menu_selection_moveup"},
238   {"DumpSelectedBrush", 'D', 0x01, ID_SELECTION_PRINT, "menu_selection_print"},
239   {"ToggleSizePaint", 'Q', 0x00, ID_SELECTION_TOGGLESIZEPAINT, "menu_selection_togglesizepaint"},
240   {"SelectNudgeLeft", GDK_Left, 0x02, ID_SELECTION_SELECT_NUDGELEFT, "menu_selection_select_nudgeleft"},
241   {"SelectNudgeRight", GDK_Right, 0x02, ID_SELECTION_SELECT_NUDGERIGHT, "menu_selection_select_nudgeright"},
242   {"SelectNudgeUp", GDK_Up, 0x02, ID_SELECTION_SELECT_NUDGEUP, "menu_selection_select_nudgeup"},
243   {"CycleCapTexturePatch", 'N', 0x05, ID_CURVE_CYCLECAP, "menu_curve_cyclecap"},
244   {"NaturalizePatch", 'N', 0x04, ID_PATCH_NATURALIZE, "menu_patch_naturalize"},
245   {"SnapToGrid", 'G', 0x04, ID_SELECT_SNAPTOGRID, "menu_select_snaptogrid"},
246   {"ShowAllTextures", 'A', 0x04, ID_TEXTURES_SHOWALL, "menu_textures_showall"},
247   {"SelectAllOfType", 'A', 0x01, ID_SELECT_ALL, "menu_select_all"},
248   {"CapCurrentCurve", 'C', 0x01, ID_CURVE_CAP, "menu_curve_cap"},
249   {"MakeStructural", 'S', 0x05, ID_SELECTION_MAKE_STRUCTURAL, "menu_selection_make_structural"},
250   {"RegionSetSelection", 'R', 0x05, ID_REGION_SETSELECTION, "menu_region_setselection"},
251   {"ShowInUse", 'U', 0, ID_TEXTURES_SHOWINUSE, "menu_textures_showinuse"},
252   {"InvertSelection", 'I', 0, ID_SELECTION_INVERT, "menu_selection_invert"},
253   {"Sleep", 'P', 0x05, ID_FILE_SLEEP, "menu_file_sleep"},
254   {"SimplePatchMesh", 'P', 0x01, ID_CURVE_SIMPLEPATCHMESH, "menu_simplepatchmesh"},
255   {"FilterWorldBrushes", '1', RAD_ALT, ID_FILTER_WORLD, "menu_filter_world"},
256   {"FilterEntities", '2', RAD_ALT, ID_FILTER_ENTITIES, "menu_filter_entities"},
257   {"FilterAreaportals", '3', RAD_ALT, ID_FILTER_AREAPORTALS, "menu_filter_areaportals"},
258   {"FilterTranslucent", '4', RAD_ALT, ID_FILTER_TRANSLUCENT, "menu_filter_translucent"},
259   {"FilterLiquids", '5', RAD_ALT, ID_FILTER_LIQUIDS, "menu_filter_liquids"},
260   {"FilterCaulk", '6', RAD_ALT , ID_FILTER_CAULK, "menu_filter_caulk"},
261   {"FilterClips", '7', RAD_ALT, ID_FILTER_CLIPS, "menu_filter_clips"},
262   {"FilterBotClips", 'M', RAD_ALT, ID_FILTER_BOTCLIPS, "menu_filter_botclips"},
263   {"FilterPaths", '8', RAD_ALT, ID_FILTER_PATHS, "menu_filter_paths"},
264   {"FilterClusterportals", '9', RAD_ALT, ID_FILTER_CLUSTERPORTALS, "menu_filter_clusterportals"},
265   {"FilterLights", '0', RAD_ALT, ID_FILTER_LIGHTS, "menu_filter_lights"},
266   {"FilterPatches", 'P', RAD_CONTROL, ID_FILTER_PATCHES, "menu_filter_patches"},
267   {"FilterDetails", 'D', RAD_CONTROL, ID_FILTER_DETAILS, "menu_filter_details"},
268   {"FilterStructural", 'D', RAD_CONTROL|RAD_SHIFT, ID_FILTER_STRUCTURAL, "menu_filter_structural"},
269   {"FilterHintsSkips", 'H', RAD_CONTROL, ID_FILTER_HINTSSKIPS, "menu_filter_hintsskips"},
270   {"FilterModels", 'M', RAD_SHIFT, ID_FILTER_MODELS, "menu_filter_models"},
271   {"FilterTriggers", 'T', RAD_CONTROL|RAD_SHIFT, ID_FILTER_TRIGGERS, "menu_filter_triggers"},
272   {"LoadPointfile", 'L', RAD_SHIFT, ID_FILE_POINTFILE, "menu_load_pointfile"},
273   {"TextureWindowScaledown", GDK_Insert, RAD_ALT, ID_TEXTUREWINDOW_SCALEDOWN, "menu_texturewindow_scaledown"},
274   {"TextureWindowScaleup", GDK_Delete, RAD_ALT, ID_TEXTUREWINDOW_SCALEUP, "menu_texturewindow_scaleup"},
275 };
276
277 int g_nCommandCount = sizeof(g_Commands) / sizeof(SCommandInfo);
278
279 SKeyInfo g_Keys[] =
280 {
281   {"Space", GDK_space},
282   {"Backspace", GDK_BackSpace},
283   {"Escape", GDK_Escape},
284   {"End", GDK_End},
285   {"Insert", GDK_Insert},
286   {"Delete", GDK_Delete},
287   {"PageUp", GDK_Prior},
288   {"PageDown", GDK_Next},
289   {"Up", GDK_Up},
290   {"Down", GDK_Down},
291   {"Left", GDK_Left},
292   {"Right", GDK_Right},
293   {"F1", GDK_F1},
294   {"F2", GDK_F2},
295   {"F3", GDK_F3},
296   {"F4", GDK_F4},
297   {"F5", GDK_F5},
298   {"F6", GDK_F6},
299   {"F7", GDK_F7},
300   {"F8", GDK_F8},
301   {"F9", GDK_F9},
302   {"F10", GDK_F10},
303   {"F11", GDK_F11},
304   {"F12", GDK_F12},
305   {"Tab", GDK_Tab},
306   {"Return", GDK_Return},
307   {"Comma", GDK_comma},
308   {"Period", GDK_period},
309   {"Plus", GDK_KP_Add},
310   {"Multiply", GDK_multiply},
311   {"Subtract", GDK_KP_Subtract},
312   {"NumPad0", GDK_KP_0},
313   {"NumPad1", GDK_KP_1},
314   {"NumPad2", GDK_KP_2},
315   {"NumPad3", GDK_KP_3},
316   {"NumPad4", GDK_KP_4},
317   {"NumPad5", GDK_KP_5},
318   {"NumPad6", GDK_KP_6},
319   {"NumPad7", GDK_KP_7},
320   {"NumPad8", GDK_KP_8},
321   {"NumPad9", GDK_KP_9},
322   {"[", 219},
323   {"]", 221},
324   {"\\", 220},
325   {"Home", GDK_Home}
326 };
327
328 int g_nKeyCount = sizeof(g_Keys) / sizeof(SKeyInfo);
329
330 // =============================================================================
331 // global functions
332
333 void WINAPI Sys_UpdateWindows (int nBits)
334 {
335   g_nUpdateBits |= nBits;
336 }
337
338 // =============================================================================
339 // Static functions
340
341 // Gef: Separate handling for keyup events
342 void HandleKeyUp (GtkWidget *widget, gpointer data)
343 {
344   int id = GPOINTER_TO_INT (data);
345 #ifdef DBG_KBD
346   Sys_Printf("HandleKeyUp: %d\n", id);
347 #endif
348
349   if(g_bIgnoreCommands)
350     return;
351
352   switch (id)
353   {
354     case ID_CAMERA_FORWARD: g_pParentWnd->OnCameraForward (FALSE); break;
355     case ID_CAMERA_BACK: g_pParentWnd->OnCameraBack (FALSE); break;
356     case ID_CAMERA_LEFT: g_pParentWnd->OnCameraLeft (FALSE); break;
357     case ID_CAMERA_RIGHT: g_pParentWnd->OnCameraRight (FALSE); break;
358     case ID_CAMERA_STRAFELEFT: g_pParentWnd->OnCameraStrafeleft (FALSE); break;
359     case ID_CAMERA_STRAFERIGHT: g_pParentWnd->OnCameraStraferight (FALSE); break;
360   }
361 }
362
363 gint HandleCommand (GtkWidget *widget, gpointer data)
364 {
365   int id = GPOINTER_TO_INT (data);
366 #ifdef DBG_KBD
367   Sys_Printf("HandleCommand %d\n", id);
368 #endif
369
370   if ( g_bIgnoreCommands ) {
371 #ifdef DBG_KBD
372     Sys_Printf( "g_bIgnoreCommands %d, returning FALSE\n", g_bIgnoreCommands );
373 #endif
374     return FALSE;
375   }
376
377   if (id >= CMD_TEXTUREWAD && id <= CMD_TEXTUREWAD_END) g_pParentWnd->OnTextureWad (id);
378   else if (id >= CMD_BSPCOMMAND && id <= CMD_BSPCOMMAND_END) g_pParentWnd->OnBspCommand (id);
379   else if (id >= ID_FILE_RECENT1 && id <= ID_FILE_RECENT4) g_pParentWnd->OnMru (id);
380   else if (id >= ID_VIEW_NEAREST && id <= ID_TEXTURES_FLATSHADE)
381   {
382     if (GTK_CHECK_MENU_ITEM (widget)->active)
383       g_pParentWnd->OnViewNearest (id);
384   } else if (id >= ID_GRID_025 && id <= ID_GRID_256) g_pParentWnd->OnGrid (id);
385   else if (id >= ID_PLUGIN_START && id <= ID_PLUGIN_END)
386   {
387     char *str;
388     gtk_label_get (GTK_LABEL (GTK_BIN (widget)->child), &str);
389     g_pParentWnd->OnPlugIn (id, str);
390   } else if (id >= ID_ENTITY_START && id <= ID_ENTITY_END)
391   {
392     char *str;
393     gtk_label_get (GTK_LABEL (GTK_BIN (widget)->child), &str);
394     g_pParentWnd->ActiveXY()->OnEntityCreate (str);
395   }
396   else switch (id)
397     {
398     case ID_FILE_NEW: g_pParentWnd->OnFileNew (); break;
399     case ID_FILE_SLEEP: g_pParentWnd->OnSleep(); break;
400     case ID_FILE_OPEN: g_pParentWnd->OnFileOpen (); break;
401     case ID_FILE_SAVE: g_pParentWnd->OnFileSave (); break;
402     case ID_FILE_SAVEAS: g_pParentWnd->OnFileSaveas (); break;
403     case ID_FILE_EXPORTMAP: g_pParentWnd->OnFileExportmap (); break;
404     case ID_FILE_SAVEREGION: g_pParentWnd->OnFileSaveregion (); break;
405     case ID_FILE_NEWPROJECT: g_pParentWnd->OnFileNewproject (); break;
406     case ID_FILE_LOADPROJECT: g_pParentWnd->OnFileLoadproject (); break;
407     case ID_FILE_PROJECTSETTINGS: g_pParentWnd->OnFileProjectsettings (); break;
408     case ID_FILE_POINTFILE: g_pParentWnd->OnFilePointfile (); break;
409     case ID_FILE_CHECKUPDATE: g_pParentWnd->OnFileCheckUpdate (); break;
410     case ID_FILE_EXIT: g_pParentWnd->OnFileExit (); break;
411     case ID_FILE_IMPORTMAP: g_pParentWnd->OnFileImportmap (); break;
412     case ID_EDIT_UNDO: g_pParentWnd->OnEditUndo (); break;
413     case ID_EDIT_REDO: g_pParentWnd->OnEditRedo (); break;
414     case ID_EDIT_COPYBRUSH: g_pParentWnd->OnEditCopybrush (); break;
415     case ID_EDIT_PASTEBRUSH: g_pParentWnd->OnEditPastebrush (); break;
416     case ID_EDIT_PASTEBRUSHTOCAMERA: g_pParentWnd->OnEditPastebrushToCamera (); break;
417     case ID_SELECTION_DELETE: g_pParentWnd->OnSelectionDelete (); break;
418     case ID_EDIT_MAPINFO: g_pParentWnd->OnEditMapinfo (); break;
419     case ID_EDIT_ENTITYINFO: g_pParentWnd->OnEditEntityinfo (); break;
420     case ID_BRUSH_SCRIPTS: g_pParentWnd->OnBrushScripts (); break;
421     case ID_EDIT_LOADPREFAB: g_pParentWnd->OnEditLoadprefab (); break;
422     case ID_EDIT_SAVEPREFAB: g_pParentWnd->OnEditSaveprefab (); break;
423     case ID_PREFS: g_pParentWnd->OnPrefs (); break;
424     case ID_TOGGLECAMERA: g_pParentWnd->OnTogglecamera (); break;
425     case ID_TOGGLECONSOLE: g_pParentWnd->OnToggleconsole (); break;
426     case ID_VIEW_ENTITY: g_pParentWnd->OnViewEntity (); break;
427     case ID_VIEW_GROUPS: g_pParentWnd->OnViewGroups (); break;
428         case ID_SELECT_FUNC_GROUP: g_pParentWnd->OnSelectFuncGroup(); break;
429     case ID_TOGGLEVIEW: g_pParentWnd->OnToggleview (); break;
430     case ID_TOGGLEVIEW_YZ: g_pParentWnd->OnToggleviewYz (); break;
431     case ID_TOGGLEVIEW_XZ: g_pParentWnd->OnToggleviewXz (); break;
432     case ID_TOGGLEZ: g_pParentWnd->OnTogglez (); break;
433     case ID_VIEW_CENTER: g_pParentWnd->OnViewCenter (); break;
434     case ID_VIEW_UPFLOOR: g_pParentWnd->OnViewUpfloor (); break;
435     case ID_VIEW_DOWNFLOOR: g_pParentWnd->OnViewDownfloor (); break;
436     case ID_VIEW_CENTERVIEW: g_pParentWnd->OnViewCenterview (); break;
437     case ID_VIEW_NEXTVIEW: g_pParentWnd->OnViewNextview (); break;
438     case ID_VIEW_XY: g_pParentWnd->OnViewXy (); break;
439     case ID_VIEW_SIDE: g_pParentWnd->OnViewSide (); break;
440     case ID_VIEW_FRONT: g_pParentWnd->OnViewFront (); break;
441     case ID_VIEW_100: g_pParentWnd->OnView100 (); break;
442     case ID_VIEW_ZOOMIN: g_pParentWnd->OnViewZoomin (); break;
443     case ID_VIEW_ZOOMOUT: g_pParentWnd->OnViewZoomout (); break;
444     case ID_VIEW_Z100: g_pParentWnd->OnViewZ100 (); break;
445     case ID_VIEW_ZZOOMIN: g_pParentWnd->OnViewZzoomin (); break;
446     case ID_VIEW_ZZOOMOUT: g_pParentWnd->OnViewZzoomout (); break;
447     case ID_VIEW_CUBEIN: g_pParentWnd->OnViewCubein (); break;
448     case ID_VIEW_CUBEOUT: g_pParentWnd->OnViewCubeout (); break;
449     case ID_VIEW_SHOWNAMES: g_pParentWnd->OnViewShownames (); break;
450     case ID_VIEW_SHOWBLOCKS: g_pParentWnd->OnViewShowblocks (); break;
451     case ID_VIEW_SHOWCOORDINATES: g_pParentWnd->OnViewShowcoordinates (); break;
452     case ID_VIEW_SHOWOUTLINE: g_pParentWnd->OnViewShowOutline (); break;
453     case ID_VIEW_SHOWAXES: g_pParentWnd->OnViewShowAxes (); break;
454     case ID_VIEW_SHOWWORKZONE: g_pParentWnd->OnViewShowWorkzone (); break;
455     case ID_VIEW_SHOWANGLES: g_pParentWnd->OnViewShowAngles (); break;
456     case ID_VIEW_HIDESHOW_HIDESELECTED: g_pParentWnd->OnViewHideshowHideselected (); break;
457     case ID_VIEW_HIDESHOW_SHOWHIDDEN: g_pParentWnd->OnViewHideshowShowhidden (); break;
458     case ID_VIEW_ENTITIESAS_BOUNDINGBOX:
459     case ID_VIEW_ENTITIESAS_WIREFRAME:
460     case ID_VIEW_ENTITIESAS_SELECTEDWIREFRAME:
461     case ID_VIEW_ENTITIESAS_SELECTEDSKINNED:
462     case ID_VIEW_ENTITIESAS_SKINNED:
463     case ID_VIEW_ENTITIESAS_SKINNEDANDBOXED:
464       g_pParentWnd->OnEntitiesSetViewAs(id);
465       break;
466     case ID_VIEW_CUBICCLIPPING: g_pParentWnd->OnViewCubicclipping (); break;
467     case ID_VIEW_OPENGLLIGHTING: g_pParentWnd->OnViewOpengllighting (); break;
468     case ID_SELECTION_DRAGEDGES: g_pParentWnd->OnSelectionDragedges (); break;
469     case ID_SELECTION_DRAGVERTECIES: g_pParentWnd->OnSelectionDragvertecies (); break;
470     case ID_SELECTION_CLONE: g_pParentWnd->OnSelectionClone (); break;
471     case ID_SELECTION_DESELECT: g_pParentWnd->OnSelectionDeselect (); break;
472     case ID_BRUSH_FLIPX: g_pParentWnd->OnBrushFlipx (); break;
473     case ID_BRUSH_FLIPY: g_pParentWnd->OnBrushFlipy (); break;
474     case ID_BRUSH_FLIPZ: g_pParentWnd->OnBrushFlipz (); break;
475     case ID_BRUSH_ROTATEX: g_pParentWnd->OnBrushRotatex (); break;
476     case ID_BRUSH_ROTATEY: g_pParentWnd->OnBrushRotatey (); break;
477     case ID_BRUSH_ROTATEZ: g_pParentWnd->OnBrushRotatez (); break;
478     case ID_SELECTION_ARBITRARYROTATION: g_pParentWnd->OnSelectionArbitraryrotation (); break;
479     case ID_SELECT_SCALE: g_pParentWnd->OnSelectScale (); break;
480     case ID_SELECTION_MAKEHOLLOW: g_pParentWnd->OnSelectionMakehollow (); break;
481     case ID_SELECTION_CSGSUBTRACT: g_pParentWnd->OnSelectionCsgsubtract (); break;
482     case ID_SELECTION_CSGMERGE: g_pParentWnd->OnSelectionCsgmerge (); break;
483     case ID_SELECTION_NOOUTLINE: g_pParentWnd->OnSelectionNoOutline (); break;
484     case ID_SELECTION_OUTLINESTYLE: g_pParentWnd->OnSelectionOutlineStyle (); break;
485     case ID_SELECTION_SELECTCOMPLETETALL: g_pParentWnd->OnSelectionSelectcompletetall (); break;
486     case ID_SELECTION_SELECTTOUCHING: g_pParentWnd->OnSelectionSelecttouching (); break;
487     case ID_SELECTION_SELECTPARTIALTALL: g_pParentWnd->OnSelectionSelectpartialtall (); break;
488     case ID_SELECTION_SELECTINSIDE: g_pParentWnd->OnSelectionSelectinside (); break;
489     case ID_SELECTION_SELECT_NUDGELEFT: g_pParentWnd->OnSelectionSelectNudgeleft (); break;
490     case ID_SELECTION_SELECT_NUDGERIGHT: g_pParentWnd->OnSelectionSelectNudgeright (); break;
491     case ID_SELECTION_SELECT_NUDGEUP: g_pParentWnd->OnSelectionSelectNudgeup (); break;
492     case ID_SELECTION_SELECT_NUDGEDOWN: g_pParentWnd->OnSelectionSelectNudgedown (); break;
493     case ID_VIEW_CLIPPER: g_pParentWnd->OnViewClipper (); break;
494     case ID_CLIP_SELECTED: g_pParentWnd->OnClipSelected (); break;
495     case ID_SPLIT_SELECTED: g_pParentWnd->OnSplitSelected (); break;
496     case ID_FLIP_CLIP: g_pParentWnd->OnFlipClip (); break;
497     case ID_SELECTION_CONNECT: g_pParentWnd->OnSelectionConnect (); break;
498     case ID_SELECTION_UNGROUPENTITY: g_pParentWnd->OnSelectionUngroupentity (); break;
499     case ID_SELECTION_MERGE: Select_MergeEntity(); break;
500     case ID_SELECTION_SEPERATE: Select_Seperate(); break;
501     case ID_SELECTION_MAKE_DETAIL: g_pParentWnd->OnSelectionMakeDetail (); break;
502     case ID_SELECTION_MAKE_STRUCTURAL: g_pParentWnd->OnSelectionMakeStructural (); break;
503     case ID_SNAPTOGRID: g_pParentWnd->OnSnaptogrid (); break;
504     case ID_TEXTURES_SHOWINUSE: g_pParentWnd->OnTexturesShowinuse (); break;
505     case ID_TEXTURES_SHOWALL: g_pParentWnd->OnTexturesShowall (); break;
506     case ID_TEXTURES_INSPECTOR: g_pParentWnd->OnTexturesInspector (); break;
507     case ID_TEXTURE_REPLACEALL: g_pParentWnd->OnTextureReplaceall (); break;
508     case ID_TOGGLE_LOCK: g_pParentWnd->OnToggleLock (); break;
509     case ID_TOGGLE_ROTATELOCK: g_pParentWnd->OnToggleRotatelock (); break;
510     case ID_TEXTURES_LOAD: g_pParentWnd->OnTexturesLoad (); break;
511     case ID_TEXTURES_RELOADSHADERS: g_pParentWnd->OnTexturesReloadshaders (); break;
512     case ID_TEXTURES_SHADERS_SHOW: g_pParentWnd->OnTexturesShadersShow (); break;
513     case ID_TEXTURES_TEXTUREWINDOWSCALE_200:
514     case ID_TEXTURES_TEXTUREWINDOWSCALE_100:
515     case ID_TEXTURES_TEXTUREWINDOWSCALE_50:
516     case ID_TEXTURES_TEXTUREWINDOWSCALE_25:
517     case ID_TEXTURES_TEXTUREWINDOWSCALE_10:
518       g_pParentWnd->SetTextureScale (id);
519       break;
520     case ID_TEXTURES_LOADLIST: g_pParentWnd->OnTexturesLoadlist (); break;
521     case ID_TEXTURES_SHADERLISTONLY: g_pParentWnd->OnTexturesShaderlistonly (); break;
522     case ID_TEXTUREWINDOW_SCALEUP: g_pParentWnd->OnTexturewindowScaleup (); break;
523     case ID_TEXTUREWINDOW_SCALEDOWN: g_pParentWnd->OnTexturewindowScaledown (); break;
524     case ID_MISC_BENCHMARK: g_pParentWnd->OnMiscBenchmark (); break;
525     case ID_COLOR_SETORIGINAL: g_pParentWnd->OnColorSetoriginal (); break;
526     case ID_COLOR_SETQER: g_pParentWnd->OnColorSetqer (); break;
527     case ID_COLOR_SETBLACK: g_pParentWnd->OnColorSetblack (); break;
528     case ID_COLOR_SETYDNAR: g_pParentWnd->OnColorSetydnar (); break;  /* ydnar */
529     case ID_TEXTUREBK: g_pParentWnd->OnTexturebk (); break;
530     case ID_COLORS_XYBK: g_pParentWnd->OnColorsXybk (); break;
531     case ID_COLORS_MAJOR: g_pParentWnd->OnColorsMajor (); break;
532     case ID_COLORS_MINOR: g_pParentWnd->OnColorsMinor (); break;
533     case ID_COLORS_GRIDTEXT: g_pParentWnd->OnColorsGridtext (); break;
534     case ID_COLORS_GRIDBLOCK: g_pParentWnd->OnColorsGridblock (); break;
535     case ID_COLORS_CAMERABACK: g_pParentWnd->OnColorsCameraBack (); break;
536     case ID_COLORS_BRUSH: g_pParentWnd->OnColorsBrush (); break;
537     case ID_COLORS_SELECTEDBRUSH: g_pParentWnd->OnColorsSelectedbrush (); break;
538     case ID_COLORS_SELECTEDBRUSH3D: g_pParentWnd->OnColorsSelectedbrush3D (); break;
539     case ID_COLORS_CLIPPER: g_pParentWnd->OnColorsClipper (); break;
540     case ID_COLORS_VIEWNAME: g_pParentWnd->OnColorsViewname (); break;
541     case ID_MISC_GAMMA: g_pParentWnd->OnMiscGamma (); break;
542     case ID_MISC_FINDBRUSH: g_pParentWnd->OnMiscFindbrush (); break;
543     case ID_MISC_NEXTLEAKSPOT: g_pParentWnd->OnMiscNextleakspot (); break;
544     case ID_MISC_PREVIOUSLEAKSPOT: g_pParentWnd->OnMiscPreviousleakspot (); break;
545     case ID_MISC_PRINTXY: g_pParentWnd->OnMiscPrintxy (); break;
546     case ID_MISC_SELECTENTITYCOLOR: g_pParentWnd->OnMiscSelectentitycolor (); break;
547     case ID_CONVERTCURVES: g_pParentWnd->OnConvertcurves (); break;
548     case ID_REGION_OFF: g_pParentWnd->OnRegionOff (); break;
549     case ID_REGION_SETXY: g_pParentWnd->OnRegionSetxy (); break;
550     case ID_REGION_SETTALLBRUSH: g_pParentWnd->OnRegionSettallbrush (); break;
551     case ID_REGION_SETBRUSH: g_pParentWnd->OnRegionSetbrush (); break;
552     case ID_REGION_SETSELECTION: g_pParentWnd->OnRegionSetselection (); break;
553     case ID_BRUSH_3SIDED: g_pParentWnd->OnBrush3sided (); break;
554     case ID_BRUSH_4SIDED: g_pParentWnd->OnBrush4sided (); break;
555     case ID_BRUSH_5SIDED: g_pParentWnd->OnBrush5sided (); break;
556     case ID_BRUSH_6SIDED: g_pParentWnd->OnBrush6sided (); break;
557     case ID_BRUSH_7SIDED: g_pParentWnd->OnBrush7sided (); break;
558     case ID_BRUSH_8SIDED: g_pParentWnd->OnBrush8sided (); break;
559     case ID_BRUSH_9SIDED: g_pParentWnd->OnBrush9sided (); break;
560     case ID_BRUSH_ARBITRARYSIDED: g_pParentWnd->OnBrushArbitrarysided (); break;
561     case ID_BRUSH_MAKECONE: g_pParentWnd->OnBrushMakecone (); break;
562     case ID_BRUSH_PRIMITIVES_SPHERE: g_pParentWnd->OnBrushPrimitivesSphere (); break;
563     case ID_CURVE_PATCHTUBE: g_pParentWnd->OnCurvePatchtube (); break;
564     case ID_CURVE_PATCHDENSETUBE: g_pParentWnd->OnCurvePatchdensetube (); break;
565     case ID_CURVE_PATCHVERYDENSETUBE: g_pParentWnd->OnCurvePatchverydensetube (); break;
566     case ID_CURVE_PATCHSQUARE: g_pParentWnd->OnCurvePatchsquare (); break;
567     case ID_CURVE_PATCHENDCAP: g_pParentWnd->OnCurvePatchendcap (); break;
568     case ID_CURVE_PATCHBEVEL: g_pParentWnd->OnCurvePatchbevel (); break;
569     case ID_CURVE_MOREENDCAPSBEVELS_SQUAREBEVEL: g_pParentWnd->OnCurveMoreendcapsbevelsSquarebevel (); break;
570     case ID_CURVE_MOREENDCAPSBEVELS_SQUAREENDCAP: g_pParentWnd->OnCurveMoreendcapsbevelsSquareendcap();break;
571     case ID_CURVE_PATCHCONE: g_pParentWnd->OnCurvePatchcone (); break;
572     case ID_CURVE_SIMPLEPATCHMESH: g_pParentWnd->OnCurveSimplepatchmesh (); break;
573     case ID_CURVE_INSERT_INSERTCOLUMN: g_pParentWnd->OnCurveInsertInsertcolumn (); break;
574     case ID_CURVE_INSERT_ADDCOLUMN: g_pParentWnd->OnCurveInsertAddcolumn (); break;
575     case ID_CURVE_INSERT_INSERTROW: g_pParentWnd->OnCurveInsertInsertrow (); break;
576     case ID_CURVE_INSERT_ADDROW: g_pParentWnd->OnCurveInsertAddrow (); break;
577     case ID_CURVE_DELETE_FIRSTCOLUMN: g_pParentWnd->OnCurveDeleteFirstcolumn (); break;
578     case ID_CURVE_DELETE_LASTCOLUMN: g_pParentWnd->OnCurveDeleteLastcolumn (); break;
579     case ID_CURVE_DELETE_FIRSTROW: g_pParentWnd->OnCurveDeleteFirstrow (); break;
580     case ID_CURVE_DELETE_LASTROW: g_pParentWnd->OnCurveDeleteLastrow (); break;
581     case ID_CURVE_NEGATIVE: g_pParentWnd->OnCurveNegative (); break;
582     case ID_CURVE_REDISPERSE_ROWS: g_pParentWnd->OnCurveRedisperseRows (); break;
583     case ID_CURVE_REDISPERSE_INTERMEDIATE_COLS: g_pParentWnd->OnCurveRedisperseIntermediateCols (); break;
584     case ID_CURVE_REDISPERSE_INTERMEDIATE_ROWS: g_pParentWnd->OnCurveRedisperseIntermediateRows (); break;
585     case ID_CURVE_MATRIX_TRANSPOSE: g_pParentWnd->OnCurveMatrixTranspose (); break;
586     case ID_CURVE_CAP: g_pParentWnd->OnCurveCap (); break;
587     case ID_CURVE_CYCLECAP: g_pParentWnd->OnCurveCyclecap (); break;
588     case ID_CURVE_OVERLAY_SET: g_pParentWnd->OnCurveOverlaySet (); break;
589     case ID_CURVE_OVERLAY_CLEAR: g_pParentWnd->OnCurveOverlayClear (); break;
590     case ID_CURVE_THICKEN: g_pParentWnd->OnCurveThicken (); break;
591     case ID_PLUGINS_REFRESH: g_pParentWnd->OnPluginsRefresh (); break;
592     case ID_HELP: g_pParentWnd->OnHelp (); break;
593     case ID_HELP_LINKS: g_pParentWnd->OnHelpLinks(); break;
594     case ID_HELP_BUGREPORT: g_pParentWnd->OnHelpBugreport(); break;
595     case ID_HELP_COMMANDLIST: g_pParentWnd->OnHelpCommandlist (); break;
596     case ID_HELP_ABOUT: g_pParentWnd->OnHelpAbout (); break;
597     case ID_DONTSELECTMODEL: g_pParentWnd->OnDontselectmodel (); break;
598     case ID_FILTER_AREAPORTALS: g_pParentWnd->OnFilterAreaportals (); break;
599     case ID_FILTER_CAULK: g_pParentWnd->OnFilterCaulk (); break;
600     case ID_FILTER_STRUCTURAL: g_pParentWnd->OnFilterStructural (); break;
601     case ID_FILTER_CLIPS: g_pParentWnd->OnFilterClips (); break;
602     case ID_FILTER_BOTCLIPS: g_pParentWnd->OnFilterBotClips (); break;
603     case ID_FILTER_DETAILS: g_pParentWnd->OnFilterDetails (); break;
604     case ID_FILTER_ENTITIES: g_pParentWnd->OnFilterEntities (); break;
605     case ID_FILTER_HINTSSKIPS: g_pParentWnd->OnFilterHintsskips (); break;
606     case ID_FILTER_LIGHTS: g_pParentWnd->OnFilterLights (); break;
607     case ID_FILTER_LIQUIDS: g_pParentWnd->OnFilterLiquids (); break;
608     case ID_FILTER_MODELS: g_pParentWnd->OnFilterModels (); break;
609     case ID_FILTER_PATCHES: g_pParentWnd->OnFilterPatches (); break;
610     case ID_FILTER_TRANSLUCENT: g_pParentWnd->OnFilterTranslucent (); break;
611     case ID_FILTER_TRIGGERS: g_pParentWnd->OnFilterTriggers (); break;
612     case ID_FILTER_WORLD: g_pParentWnd->OnFilterWorld (); break;
613     case ID_FILTER_PATHS: g_pParentWnd->OnFilterPaths (); break;
614     case ID_FILTER_CLUSTERPORTALS: g_pParentWnd->OnFilterClusterportals (); break;
615     case ID_FILTER_LIGHTGRID: g_pParentWnd->OnFilterLightgrid (); break;
616
617     case ID_POPUP_SELECTION: g_pParentWnd->OnPopupSelection (); break;
618     case ID_VIEW_CHANGE: g_pParentWnd->OnViewChange (); break;
619     case ID_TEXTURES_POPUP: g_pParentWnd->OnTexturesPopup (); break;
620     case ID_VIEW_CAMERATOGGLE: g_pParentWnd->ToggleCamera (); break;
621     case ID_VIEW_CAMERAUPDATE: g_pParentWnd->OnViewCameraupdate (); break;
622     case ID_SELECT_MOUSEROTATE: g_pParentWnd->OnSelectMouserotate (); break;
623     case ID_SELECT_MOUSESCALE: g_pParentWnd->OnSelectMousescale (); break;
624     case ID_SCALELOCKX: g_pParentWnd->OnScalelockx (); break;
625     case ID_SCALELOCKY: g_pParentWnd->OnScalelocky (); break;
626     case ID_SCALELOCKZ: g_pParentWnd->OnScalelockz (); break;
627     case ID_DONTSELECTCURVE: g_pParentWnd->OnDontselectcurve (); break;
628     case ID_PATCH_SHOWBOUNDINGBOX: g_pParentWnd->OnPatchToggleBox (); break;
629     case ID_PATCH_WIREFRAME: g_pParentWnd->OnPatchWireframe (); break;
630     case ID_PATCH_BEND: g_pParentWnd->OnPatchBend (); break;
631     case ID_PATCH_WELD: g_pParentWnd->OnPatchWeld (); break;
632     case ID_PATCH_DRILLDOWN: g_pParentWnd->OnPatchDrilldown (); break;
633     case ID_DROP_GROUP_NAME: g_pParentWnd->OnDropGroupName (); break;
634     case ID_DROP_GROUP_NEWGROUP: g_pParentWnd->OnDropGroupNewgroup (); break;
635     case ID_DROP_GROUP_REMOVE: g_pParentWnd->OnDropGroupRemove (); break;
636     case ID_SHOW_ENTITIES: g_pParentWnd->OnShowEntities (); break;
637
638     case IDC_BTN_FACEFIT: g_pParentWnd->OnFaceFit (); break;
639     case ID_VIEW_TEXTURE: g_pParentWnd->OnViewTexture (); break;
640     case ID_PATCH_INSPECTOR: g_pParentWnd->OnPatchInspector (); break;
641     case ID_CURVE_NEGATIVETEXTUREX: g_pParentWnd->OnCurveNegativeTextureX (); break;
642     case ID_CURVE_NEGATIVETEXTUREY: g_pParentWnd->OnCurveNegativeTextureY (); break;
643     case ID_CURVE_INSERTCOLUMN: g_pParentWnd->OnCurveInsertcolumn (); break;
644     case ID_CURVE_INSERTROW: g_pParentWnd->OnCurveInsertrow (); break;
645     case ID_CURVE_DELETECOLUMN: g_pParentWnd->OnCurveDeletecolumn (); break;
646     case ID_CURVE_DELETEROW: g_pParentWnd->OnCurveDeleterow (); break;
647     case ID_PATCH_TAB: g_pParentWnd->OnPatchTab (); break;
648     case ID_CAMERA_FORWARD: g_pParentWnd->OnCameraForward (TRUE); break;
649     case ID_CAMERA_BACK: g_pParentWnd->OnCameraBack (TRUE); break;
650     case ID_CAMERA_LEFT: g_pParentWnd->OnCameraLeft (TRUE); break;
651     case ID_CAMERA_RIGHT: g_pParentWnd->OnCameraRight (TRUE); break;
652     case ID_CAMERA_UP: g_pParentWnd->OnCameraUp (); break;
653     case ID_CAMERA_DOWN: g_pParentWnd->OnCameraDown (); break;
654     case ID_CAMERA_ANGLEUP: g_pParentWnd->OnCameraAngleup (); break;
655     case ID_CAMERA_ANGLEDOWN: g_pParentWnd->OnCameraAngledown (); break;
656     case ID_CAMERA_STRAFELEFT: g_pParentWnd->OnCameraStrafeleft (TRUE); break;
657     case ID_CAMERA_STRAFERIGHT: g_pParentWnd->OnCameraStraferight (TRUE); break;
658     case ID_GRID_TOGGLE: g_pParentWnd->OnGridToggle (); break;
659     case ID_VIEW_CONSOLE: g_pParentWnd->OnViewConsole (); break;
660     case ID_VIEW_CROSSHAIR: g_pParentWnd->OnViewCrosshair (); break;
661     case ID_SELECTION_TEXTURE_FIT: g_pParentWnd->OnSelectionTextureFit (); break;
662     case ID_SELECTION_TEXTURE_ROTATECLOCK: g_pParentWnd->OnSelectionTextureRotateclock (); break;
663     case ID_SELECTION_TEXTURE_ROTATECOUNTER: g_pParentWnd->OnSelectionTextureRotatecounter (); break;
664     case ID_SELECTION_TEXTURE_SCALEUP: g_pParentWnd->OnSelectionTextureScaleup (); break;
665     case ID_SELECTION_TEXTURE_SCALEDOWN: g_pParentWnd->OnSelectionTextureScaledown (); break;
666     case ID_SELECTION_TEXTURE_SHIFTLEFT: g_pParentWnd->OnSelectionTextureShiftleft (); break;
667     case ID_SELECTION_TEXTURE_SHIFTRIGHT: g_pParentWnd->OnSelectionTextureShiftright (); break;
668     case ID_SELECTION_TEXTURE_SHIFTUP: g_pParentWnd->OnSelectionTextureShiftup (); break;
669     case ID_SELECTION_TEXTURE_SHIFTDOWN: g_pParentWnd->OnSelectionTextureShiftdown (); break;
670     case ID_GRID_PREV: g_pParentWnd->OnGridPrev (); break;
671     case ID_GRID_NEXT: g_pParentWnd->OnGridNext (); break;
672     case ID_SELECTION_TEXTURE_SCALELEFT: g_pParentWnd->OnSelectionTextureScaleLeft (); break;
673     case ID_SELECTION_TEXTURE_SCALERIGHT: g_pParentWnd->OnSelectionTextureScaleRight (); break;
674     case ID_SELECTION_MOVEDOWN: g_pParentWnd->OnSelectionMovedown (); break;
675     case ID_SELECTION_MOVEUP: g_pParentWnd->OnSelectionMoveup (); break;
676     case ID_SELECTION_PRINT: g_pParentWnd->OnSelectionPrint (); break;
677     case ID_SELECTION_TOGGLESIZEPAINT: g_pParentWnd->OnSelectionTogglesizepaint (); break;
678     case ID_PATCH_NATURALIZE: g_pParentWnd->OnPatchNaturalize (); break;
679     case ID_SELECT_SNAPTOGRID: g_pParentWnd->OnSnapToGrid (); break;
680     case ID_SELECT_ALL: g_pParentWnd->OnSelectAll (); break;
681     case ID_SELECTION_INVERT: g_pParentWnd->OnSelectionInvert (); break;
682     }
683
684     return TRUE;
685 }
686
687 static gint timer (gpointer data)
688 {
689   MainFrame *wnd = (MainFrame*)data;
690   wnd->OnTimer ();
691   return TRUE;
692 }
693
694 static gint mainframe_delete (GtkWidget *widget, GdkEvent *event, gpointer data)
695 {
696   MainFrame *wnd = (MainFrame*)data;
697
698   wnd->OnDelete();
699
700   if (ConfirmModified())
701     return FALSE;
702
703   g_qeglobals_gui.d_edit = NULL;
704
705   return TRUE;
706 }
707
708 static void mainframe_destroy (GtkWidget *widget, gpointer data)
709 {
710   MainFrame *wnd = (MainFrame*)data;
711
712   // avoid saving prefs when the app is minimized
713   if (g_pParentWnd->IsSleeping())
714   {
715     Sys_Printf("Shutdown while sleeping, not saving prefs\n");
716     g_qeglobals.disable_ini = true;
717   }
718
719   // NOTE TTimo this is very clumsy, in MainFrame::OnDestroy we might call SavePrefs again
720   //   we will do more stuff in OnDestroy for window position saving too, so I guess this call is still relevant?
721   g_PrefsDlg.SavePrefs ();
722
723   wnd->OnDestroy ();
724
725   // shutdown modules
726   // NOTE: I've decided to do this before SavePrefs in case we broadcast some shutdown info
727   // and modules / plugins decide to save some stuff
728   g_pParentWnd->GetPlugInMgr().Shutdown();
729
730   delete wnd;
731
732   QGL_Shutdown();
733   g_PrefsDlg.Destroy ();
734   g_dlgSurface.Destroy ();
735   g_dlgFind.Destroy ();
736   g_PatchDialog.Destroy ();
737
738   gtk_main_quit ();
739 }
740
741 static gint mainframe_keypress (GtkWidget* widget, GdkEventKey* event, gpointer data)
742 {
743   unsigned int code = gdk_keyval_to_upper(event->keyval);
744
745   if(code == GDK_ISO_Left_Tab) {
746     code = GDK_Tab;
747   }
748
749 #ifdef DBG_KBD
750   Sys_Printf("key: %d (keyval: %d) (ctrl: %d)\n", code, event->keyval, event->state & GDK_CONTROL_MASK);
751 #endif
752
753   // return only if Texture Viewport  is in main window, otherwise if Tex viewport is in it's own window
754   // the Filter GtkEntry won't release focus
755   if ( g_pParentWnd->GetTexWnd()->m_pFilter == gtk_window_get_focus(GTK_WINDOW(widget)) )
756     if ( gtk_widget_is_focus( g_pParentWnd->GetTexWnd()->m_pFilter ) )
757       return FALSE;
758
759 #ifdef DBG_KBD
760   Sys_Printf("mainframe_keypress processing into a command\n");
761 #endif
762   for (int i = 0; i < g_nCommandCount; i++)
763   {
764     if (g_Commands[i].m_nKey == code)    // find a match?
765     {
766       // check modifiers
767       unsigned int nState = 0;
768       if (Sys_AltDown ())
769         nState |= RAD_ALT;
770       if ((event->state & GDK_CONTROL_MASK) != 0)
771         nState |= RAD_CONTROL;
772       if ((event->state & GDK_SHIFT_MASK) != 0)
773         nState |= RAD_SHIFT;
774       if ((g_Commands[i].m_nModifiers & 0x7) == nState)
775       {
776         HandleCommand (NULL, GINT_TO_POINTER (g_Commands[i].m_nCommand));
777         gtk_signal_emit_stop_by_name (GTK_OBJECT(widget), "key_press_event");
778         return FALSE;
779       }
780     }
781   }
782
783   return TRUE;
784 }
785
786 static gint mainframe_keyrelease (GtkWidget* widget, GdkEventKey* event, gpointer data)
787 {
788   unsigned int code = gdk_keyval_to_upper(event->keyval);
789
790   if (gtk_accelerator_valid (event->keyval, (GdkModifierType)0))
791     return TRUE;
792
793   for (int i = 0; i < g_nCommandCount; i++)
794   {
795     if (g_Commands[i].m_nKey == code)    // find a match?
796     {
797       if(!g_Commands[i].m_nModifiers)
798       {
799         // Gef: Only call the handler if it's a key that needs keyup events
800         switch (g_Commands[i].m_nCommand)
801         {
802           case ID_CAMERA_FORWARD:
803           case ID_CAMERA_BACK:
804           case ID_CAMERA_LEFT:
805           case ID_CAMERA_RIGHT:
806           case ID_CAMERA_STRAFELEFT:
807           case ID_CAMERA_STRAFERIGHT:
808           {
809             HandleKeyUp (NULL, GINT_TO_POINTER (g_Commands[i].m_nCommand));
810             gtk_signal_emit_stop_by_name (GTK_OBJECT(widget), "key_release_event");
811           }
812
813         }
814         return FALSE;
815       }
816     }
817   }
818
819   return TRUE;
820 }
821
822
823 // =============================================================================
824 // Window creation functions
825
826 void AddMenuItem (GtkWidget* item, unsigned int id)
827 {
828   for (int i = 0; i < g_nCommandCount; i++)
829     if (g_Commands[i].m_nCommand == id)
830     {
831       g_object_set_data (G_OBJECT (g_pParentWnd->m_pWidget), g_Commands[i].m_strMenu, item);
832       break;
833     }
834 }
835
836 void MainFrame::handle_help_command(int id)
837 {
838   OpenURL(mHelpURLs[id]->GetBuffer());
839 }
840
841 /*!
842 needed for hooking in Gtk+
843 */
844 void HandleHelpCommand (GtkWidget *widget, gpointer data)
845 {
846   int id = GPOINTER_TO_INT (data);
847   g_pParentWnd->handle_help_command(id);
848 }
849
850 void MainFrame::process_xlink (Str &FileName, const char *menu_name, const char *base_url, GtkWidget *menu, GtkAccelGroup *accel)
851 {
852   xmlDocPtr pDoc;
853   pDoc = xmlParseFile(FileName.GetBuffer());
854   if (pDoc)
855   {
856     Sys_Printf("Processing .xlink file '%s'\n", FileName.GetBuffer());
857     // create sub menu
858     GtkWidget* menu_in_menu = create_menu_in_menu_with_mnemonic(menu, menu_name);
859     // start walking the nodes, find the 'links' one
860     xmlNodePtr pNode = pDoc->children;
861     while (pNode && strcmp((const char*)pNode->name, "links"))
862       pNode=pNode->next;
863     if (pNode)
864     {
865       pNode = pNode->children;
866       while(pNode)
867       {
868         if (!strcmp((const char*)pNode->name, "item"))
869         {
870           // process the URL
871           Str *url;
872           if (strstr((char *)xmlGetProp(pNode, (xmlChar *)"url"), "http://"))
873           {
874             // complete URL
875             url = new Str;
876             *url = (char *)xmlGetProp(pNode, (xmlChar *)"url");
877           }
878           else
879           {
880             // relative URL
881             url = new Str;
882             *url = base_url;
883             *url += (char *)xmlGetProp(pNode, (xmlChar *)"url");
884           }
885           mHelpURLs.push_back(url);
886           create_menu_item_with_mnemonic (menu_in_menu, (char *)xmlGetProp(pNode, (xmlChar *)"name"), GTK_SIGNAL_FUNC(HandleHelpCommand), mHelpURLs.size()-1);
887         }
888         pNode=pNode->next;
889       }
890     }
891     xmlFreeDoc(pDoc);
892   }
893   else
894   {
895     Sys_Printf("'%s' not found / parse failed\n", FileName.GetBuffer());
896   }
897 }
898
899 void MainFrame::create_game_help_menu (GtkWidget *menu, GtkAccelGroup *accel)
900 {
901   Str FileName;
902   list<CGameDescription *>::iterator iGame;
903
904   // start in the global dir
905   FileName = g_strAppPath;
906   FileName += "global.xlink";
907   process_xlink(FileName, "General", g_strAppPath.GetBuffer(), menu, accel);
908
909   for (iGame = g_PrefsDlg.mGamesDialog.mGames.begin(); iGame != g_PrefsDlg.mGamesDialog.mGames.end(); iGame++)
910   {
911     FileName = (*iGame)->mGameToolsPath;
912     FileName += "game.xlink";
913     process_xlink(FileName, (*iGame)->mGameName, (*iGame)->mGameToolsPath.GetBuffer(), menu, accel);
914   }
915 }
916
917 void MainFrame::create_main_menu (GtkWidget *window, GtkWidget *vbox)
918 {
919   GtkWidget *handle_box, *menu_bar, *menu, *menu_in_menu, *menu_3, *item;
920   GtkAccelGroup *accel;
921
922   g_bIgnoreCommands++;
923   accel = gtk_accel_group_new ();
924   global_accel = accel;
925   gtk_window_add_accel_group (GTK_WINDOW (window), accel);
926
927   handle_box = gtk_handle_box_new ();
928   gtk_box_pack_start (GTK_BOX (vbox), handle_box, FALSE, FALSE, 0);
929   gtk_widget_show (handle_box);
930
931   menu_bar = gtk_menu_bar_new ();
932   gtk_container_add (GTK_CONTAINER (handle_box), menu_bar);
933   gtk_widget_show (menu_bar);
934
935   // File menu
936   menu = create_sub_menu_with_mnemonic (menu_bar, _("_File"));
937   if (g_PrefsDlg.m_bDetachableMenus)
938     menu_tearoff (menu);
939
940   create_menu_item_with_mnemonic (menu, _("_New Map"),
941                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_NEW);
942   menu_separator (menu);
943
944   //++timo temporary experimental stuff for sleep mode..
945   item = create_menu_item_with_mnemonic (menu, _("_Sleep"),
946                            GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_SLEEP);
947   g_object_set_data (G_OBJECT (window), "menu_file_sleep", item );
948   menu_separator (menu);
949   // end experimental
950
951   item = create_menu_item_with_mnemonic (menu, _("_Open..."),
952                            GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_OPEN);
953   g_object_set_data (G_OBJECT (window), "menu_file_open", item);
954   create_menu_item_with_mnemonic (menu, _("_Import..."), // Hydra: give it it's proper name
955                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_IMPORTMAP);
956   item = create_menu_item_with_mnemonic (menu, _("_Save"),
957                            GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_SAVE);
958   g_object_set_data (G_OBJECT (window), "menu_file_save", item);
959   create_menu_item_with_mnemonic (menu, _("Save _as..."),
960                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_SAVEAS);
961   create_menu_item_with_mnemonic (menu, _("Save s_elected..."),
962                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_EXPORTMAP);
963   menu_separator (menu);
964   item = create_menu_item_with_mnemonic (menu, _("Save re_gion..."),
965                            GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_SAVEREGION);
966   g_object_set_data (G_OBJECT (window), "menu_file_saveregion", item);
967   menu_separator (menu);
968   create_menu_item_with_mnemonic (menu, _("New p_roject..."),
969                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_NEWPROJECT);
970   create_menu_item_with_mnemonic (menu, _("Load _project..."),
971                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_LOADPROJECT);
972   create_menu_item_with_mnemonic (menu, _("Pro_ject settings..."),
973                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_PROJECTSETTINGS);
974   menu_separator (menu);
975   create_menu_item_with_mnemonic (menu, _("_Pointfile..."),
976                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_POINTFILE);
977   menu_separator (menu);
978   item = create_menu_item_with_mnemonic (menu, _("Recent Files"),
979                            GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_RECENT1);
980   g_object_set_data (G_OBJECT (item), "accel", accel);
981   gtk_widget_set_sensitive (item, FALSE);
982   MRU_AddWidget (item, 0);
983   item = create_menu_item_with_mnemonic (menu, "2",
984                            GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_RECENT2);
985   gtk_widget_hide (item);
986   MRU_AddWidget (item, 1);
987   item = create_menu_item_with_mnemonic (menu, "3",
988                            GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_RECENT3);
989   gtk_widget_hide (item);
990   MRU_AddWidget (item, 2);
991   item = create_menu_item_with_mnemonic (menu, "4",
992                            GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_RECENT4);
993   gtk_widget_hide (item);
994   MRU_AddWidget (item, 3);
995   menu_separator (menu);
996   item = create_menu_item_with_mnemonic (menu, _("Check for GtkRadiant update (web)"),
997     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_CHECKUPDATE);
998   // disable, the functionality is no longer available
999   gtk_widget_set_sensitive( item, FALSE );
1000
1001   create_menu_item_with_mnemonic (menu, _("E_xit"),
1002                     GTK_SIGNAL_FUNC (HandleCommand), ID_FILE_EXIT);
1003
1004   // Edit menu
1005   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Edit"));
1006   if (g_PrefsDlg.m_bDetachableMenus)
1007     menu_tearoff (menu);
1008   item = create_menu_item_with_mnemonic (menu, _("_Undo"),
1009                            GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_UNDO);
1010   g_object_set_data (G_OBJECT (window), "menu_edit_undo", item);
1011   item = create_menu_item_with_mnemonic (menu, _("_Redo"),
1012                            GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_REDO);
1013   g_object_set_data (G_OBJECT (window), "menu_edit_redo", item);
1014   menu_separator (menu);
1015   item = create_menu_item_with_mnemonic (menu, _("_Copy"), GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_COPYBRUSH);
1016   item = create_menu_item_with_mnemonic (menu, _("_Paste"), GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_PASTEBRUSH);
1017   item = create_menu_item_with_mnemonic (menu, _("P_aste To Camera"), GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_PASTEBRUSHTOCAMERA);
1018   item = create_menu_item_with_mnemonic (menu, _("_Delete"), GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_DELETE);
1019   g_object_set_data (G_OBJECT (window), "menu_selection_delete", item);
1020   menu_separator (menu);
1021   create_menu_item_with_mnemonic (menu, _("Map Info..."), GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_MAPINFO);
1022   create_menu_item_with_mnemonic (menu, _("Entity Info..."), GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_ENTITYINFO);
1023   menu_separator (menu);
1024   create_menu_item_with_mnemonic (menu, _("Brush Scripts..."), GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_SCRIPTS);
1025   menu_separator (menu);
1026   create_menu_item_with_mnemonic (menu, _("Load Pre_fab..."), GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_LOADPREFAB);
1027   create_menu_item_with_mnemonic (menu, _("Save Selection as Prefab..."), GTK_SIGNAL_FUNC (HandleCommand), ID_EDIT_SAVEPREFAB);
1028   menu_separator (menu);
1029   create_menu_item_with_mnemonic (menu, _("Preferences..."), GTK_SIGNAL_FUNC (HandleCommand), ID_PREFS);
1030
1031   // View menu
1032   menu = create_sub_menu_with_mnemonic (menu_bar, _("_View"));
1033   if (g_PrefsDlg.m_bDetachableMenus)
1034     menu_tearoff (menu);
1035
1036   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Toggle"));
1037   create_menu_item_with_mnemonic (menu_in_menu, _("Camera View"), GTK_SIGNAL_FUNC (HandleCommand), ID_TOGGLECAMERA);
1038   create_menu_item_with_mnemonic (menu_in_menu, _("Console View"), GTK_SIGNAL_FUNC (HandleCommand), ID_TOGGLECONSOLE);
1039   item = create_menu_item_with_mnemonic (menu_in_menu, _("Entity View"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ENTITY);
1040   g_object_set_data (G_OBJECT (window), "menu_view_entity", item);
1041   //  create_menu_item_with_mnemonic (menu_in_menu, "Groups View", GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_GROUPS);
1042   create_menu_item_with_mnemonic (menu_in_menu, _("XY (Top)"), GTK_SIGNAL_FUNC (HandleCommand), ID_TOGGLEVIEW);
1043   create_menu_item_with_mnemonic (menu_in_menu, _("YZ (Side)"), GTK_SIGNAL_FUNC (HandleCommand), ID_TOGGLEVIEW_YZ);
1044   create_menu_item_with_mnemonic (menu_in_menu, _("XZ (Front)"), GTK_SIGNAL_FUNC (HandleCommand), ID_TOGGLEVIEW_XZ);
1045   create_menu_item_with_mnemonic (menu_in_menu, _("Z View"), GTK_SIGNAL_FUNC (HandleCommand), ID_TOGGLEZ);
1046   menu_separator (menu);
1047   item = create_menu_item_with_mnemonic (menu, _("_Center"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_CENTER);
1048   item = create_menu_item_with_mnemonic (menu, _("_Center 2d"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_CENTERVIEW);
1049   item = create_menu_item_with_mnemonic (menu, _("_Up Floor"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_UPFLOOR);
1050   item = create_menu_item_with_mnemonic (menu, _("_Down Floor"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_DOWNFLOOR);
1051   menu_separator (menu);
1052   item = create_menu_item_with_mnemonic (menu, _("_Next (XY, YZ, XY)"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_NEXTVIEW);
1053   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Layout"));
1054   create_menu_item_with_mnemonic (menu_in_menu, _("XY (Top)"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_XY);
1055   create_menu_item_with_mnemonic (menu_in_menu, _("YZ"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_SIDE);
1056   create_menu_item_with_mnemonic (menu_in_menu, _("XZ"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_FRONT);
1057   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Zoom"));
1058   create_menu_item_with_mnemonic (menu_in_menu, _("_XY 100%"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_100);
1059   item = create_menu_item_with_mnemonic (menu_in_menu, _("XY Zoom _In"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ZOOMIN);
1060   item = create_menu_item_with_mnemonic (menu_in_menu, _("XY Zoom _Out"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ZOOMOUT);
1061   menu_separator (menu_in_menu);
1062   create_menu_item_with_mnemonic (menu_in_menu, _("_Z 100%"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_Z100);
1063   item = create_menu_item_with_mnemonic (menu_in_menu, _("Z Zoo_m In"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ZZOOMIN);
1064   g_object_set_data (G_OBJECT (window), "menu_view_zzoomin", item);
1065   item = create_menu_item_with_mnemonic (menu_in_menu, _("Z Zoom O_ut"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ZZOOMOUT);
1066   g_object_set_data (G_OBJECT (window), "menu_view_zzoomout", item);
1067   menu_separator (menu_in_menu);
1068   item = create_menu_item_with_mnemonic (menu_in_menu, _("Cubic Clip Zoom In"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_CUBEIN);
1069   item = create_menu_item_with_mnemonic (menu_in_menu, _("Cubic Clip Zoom Out"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_CUBEOUT);
1070   menu_separator (menu);
1071
1072   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Show"));
1073   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Show _Angles"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_SHOWANGLES, FALSE);
1074   g_object_set_data (G_OBJECT (window), "menu_view_showangles", item);
1075   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Show _Names"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_SHOWNAMES, TRUE);
1076   g_object_set_data (G_OBJECT (window), "menu_view_shownames", item);
1077   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Show Blocks"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_SHOWBLOCKS, FALSE);
1078   g_object_set_data (G_OBJECT (window), "menu_view_showblocks", item);
1079   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Show C_oordinates"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_SHOWCOORDINATES, TRUE);
1080   g_object_set_data (G_OBJECT (window), "menu_view_showcoordinates", item);
1081   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Show Window Outline"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_SHOWOUTLINE, TRUE);
1082   g_object_set_data (G_OBJECT (window), "menu_view_showoutline", item);
1083   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Show ZBuffered Outline"), GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_NOOUTLINE, TRUE);
1084   g_object_set_data (G_OBJECT (window), "menu_selection_nooutline", item);
1085   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Show Axes"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_SHOWAXES, TRUE);
1086   g_object_set_data (G_OBJECT (window), "menu_view_showaxes", item);
1087   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Show Workzone"), GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_SHOWWORKZONE, FALSE);
1088   g_object_set_data (G_OBJECT (window), "menu_view_showworkzone", item);
1089
1090   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Filter"));
1091   create_check_menu_item_with_mnemonic (menu_in_menu, _("World"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_WORLD, FALSE);
1092   create_check_menu_item_with_mnemonic (menu_in_menu, _("Entities"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_ENTITIES, FALSE);
1093   create_check_menu_item_with_mnemonic (menu_in_menu, _("Areaportals"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_AREAPORTALS, FALSE);
1094   create_check_menu_item_with_mnemonic (menu_in_menu, _("Translucent"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_TRANSLUCENT, FALSE);
1095   create_check_menu_item_with_mnemonic (menu_in_menu, _("Liquids"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_LIQUIDS, FALSE);
1096   create_check_menu_item_with_mnemonic (menu_in_menu, _("Caulk"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_CAULK, FALSE);
1097   create_check_menu_item_with_mnemonic (menu_in_menu, _("Clips"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_CLIPS, FALSE);
1098   create_check_menu_item_with_mnemonic (menu_in_menu, _("Paths"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_PATHS, FALSE);
1099   create_check_menu_item_with_mnemonic (menu_in_menu, _("Clusterportals"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_CLUSTERPORTALS, FALSE);
1100   create_check_menu_item_with_mnemonic (menu_in_menu, _("Lights"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_LIGHTS, FALSE);
1101   create_check_menu_item_with_mnemonic (menu_in_menu, _("Structural"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_STRUCTURAL, FALSE);
1102   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Lightgrid"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_LIGHTGRID, FALSE);
1103   g_object_set_data (G_OBJECT (window), "menu_filter_lightgrid", item);
1104   create_check_menu_item_with_mnemonic (menu_in_menu, _("Patches"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_PATCHES, FALSE);
1105   create_check_menu_item_with_mnemonic (menu_in_menu, _("Details"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_DETAILS, FALSE);
1106   create_check_menu_item_with_mnemonic (menu_in_menu, _("Hints"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_HINTSSKIPS, FALSE);
1107   create_check_menu_item_with_mnemonic (menu_in_menu, _("Models"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_MODELS, FALSE);
1108   create_check_menu_item_with_mnemonic (menu_in_menu, _("Triggers"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_TRIGGERS, FALSE);
1109   create_check_menu_item_with_mnemonic (menu_in_menu, _("Botclips"), GTK_SIGNAL_FUNC (HandleCommand), ID_FILTER_BOTCLIPS, FALSE);
1110
1111   menu_separator (menu);
1112   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Hide/Show"));
1113   create_menu_item_with_mnemonic (menu_in_menu, _("Hide Selected"),
1114                     GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_HIDESHOW_HIDESELECTED);
1115   create_menu_item_with_mnemonic (menu_in_menu, _("Show Hidden"),
1116                     GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_HIDESHOW_SHOWHIDDEN);
1117   menu_separator (menu);
1118   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Entities as"));
1119   g_object_set_data (G_OBJECT (window), "view_entitiesas_menu", menu_in_menu);
1120   item = create_radio_menu_item_with_mnemonic (menu_in_menu, NULL, _("Bounding box"),
1121                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ENTITIESAS_BOUNDINGBOX,FALSE);
1122   g_object_set_data (G_OBJECT (window), "menu_view_entitiesas_boundingbox", item);
1123   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("Wireframe"),
1124                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ENTITIESAS_WIREFRAME,FALSE);
1125   g_object_set_data (G_OBJECT (window), "menu_view_entitiesas_wireframe", item);
1126   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("Selected Wireframe"),
1127                                  GTK_SIGNAL_FUNC (HandleCommand),ID_VIEW_ENTITIESAS_SELECTEDWIREFRAME,FALSE);
1128   g_object_set_data (G_OBJECT (window), "menu_view_entitiesas_selectedwireframe", item);
1129   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("Selected Skinned"),
1130                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ENTITIESAS_SELECTEDSKINNED,FALSE);
1131   g_object_set_data (G_OBJECT (window), "menu_view_entitiesas_selectedskinned", item);
1132   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("Skinned"),
1133                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ENTITIESAS_SKINNED,FALSE);
1134   g_object_set_data (G_OBJECT (window), "menu_view_entitiesas_skinned", item);
1135   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("Skinned and Boxed"),
1136                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_ENTITIESAS_SKINNEDANDBOXED,FALSE);
1137   g_object_set_data (G_OBJECT (window), "menu_view_entitiesas_skinnedandboxed", item);
1138   menu_separator (menu);
1139   item = create_check_menu_item_with_mnemonic (menu, _("Cubic Clipping"),
1140                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_CUBICCLIPPING, TRUE);
1141   g_object_set_data (G_OBJECT (window), "menu_view_cubicclipping", item);
1142   menu_separator (menu);
1143   item = create_check_menu_item_with_mnemonic (menu, _("OpenGL Lighting"),
1144                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_OPENGLLIGHTING, FALSE);
1145   g_object_set_data (G_OBJECT (window), "menu_view_opengllighting", item);
1146
1147   // Selection menu
1148   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Selection"));
1149   if (g_PrefsDlg.m_bDetachableMenus)
1150     menu_tearoff (menu);
1151
1152   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Drag"));
1153   create_menu_item_with_mnemonic (menu_in_menu, _("Drag _Edges"),
1154                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_DRAGEDGES);
1155   create_menu_item_with_mnemonic (menu_in_menu, _("Drag _Vertices"),
1156                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_DRAGVERTECIES);
1157   menu_separator (menu);
1158   create_menu_item_with_mnemonic (menu, _("_Clone"),
1159                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_CLONE);
1160   item = create_menu_item_with_mnemonic (menu, _("Deselect"),
1161                            GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_DESELECT);
1162   item = create_menu_item_with_mnemonic (menu, _("Invert"),
1163                            GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_INVERT);
1164 #ifndef QUAKE3
1165   create_menu_item_with_mnemonic (menu, _("_Delete"),
1166                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_DELETE);
1167 #endif
1168   menu_separator (menu);
1169   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Flip"));
1170   create_menu_item_with_mnemonic (menu_in_menu, _("Flip _X"),
1171                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_FLIPX);
1172   create_menu_item_with_mnemonic (menu_in_menu, _("Flip _Y"),
1173                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_FLIPY);
1174   create_menu_item_with_mnemonic (menu_in_menu, _("Flip _Z"),
1175                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_FLIPZ);
1176   menu_separator (menu);
1177   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Rotate"));
1178   create_menu_item_with_mnemonic (menu_in_menu, _("Rotate X"),
1179                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_ROTATEX);
1180   create_menu_item_with_mnemonic (menu_in_menu, _("Rotate Y"),
1181                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_ROTATEY);
1182   create_menu_item_with_mnemonic (menu_in_menu, _("Rotate Z"),
1183                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_ROTATEZ);
1184   create_menu_item_with_mnemonic (menu_in_menu, _("Arbitrary rotation..."),
1185                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_ARBITRARYROTATION);
1186   menu_separator (menu);
1187   create_menu_item_with_mnemonic (menu, _("Scale..."), GTK_SIGNAL_FUNC (HandleCommand), ID_SELECT_SCALE);
1188   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("CSG"));
1189   create_menu_item_with_mnemonic (menu_in_menu, _("Make _Hollow"),
1190                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_MAKEHOLLOW);
1191   create_menu_item_with_mnemonic (menu_in_menu, _("CSG _Subtract"),
1192                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_CSGSUBTRACT);
1193   create_menu_item_with_mnemonic (menu_in_menu, _("CSG _Merge"),
1194                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_CSGMERGE);
1195   menu_separator (menu);
1196   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Select"));
1197   create_menu_item_with_mnemonic (menu_in_menu, _("Select Complete _Tall"),
1198                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECTCOMPLETETALL);
1199   create_menu_item_with_mnemonic (menu_in_menu, _("Select T_ouching"),
1200                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECTTOUCHING);
1201   create_menu_item_with_mnemonic (menu_in_menu, _("Select _Partial Tall"),
1202                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECTPARTIALTALL);
1203   create_menu_item_with_mnemonic (menu_in_menu, _("Select _Inside"),
1204                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECTINSIDE);
1205   create_menu_item_with_mnemonic (menu_in_menu, "Select Func _Group", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECT_FUNC_GROUP);
1206 #ifndef QUAKE3
1207   create_menu_item_with_mnemonic (menu_in_menu, _("Nudge Left"),
1208                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECT_NUDGELEFT);
1209   create_menu_item_with_mnemonic (menu_in_menu, _("Nudge Right"),
1210                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECT_NUDGERIGHT);
1211   create_menu_item_with_mnemonic (menu_in_menu, _("Nudge Up"),
1212                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECT_NUDGEUP);
1213   create_menu_item_with_mnemonic (menu_in_menu, _("Nudge Down"),
1214                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECT_NUDGEDOWN);
1215 #endif
1216   menu_separator (menu);
1217   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Clipper"));
1218   create_menu_item_with_mnemonic (menu_in_menu, _("Toggle Clipper"),
1219                     GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_CLIPPER);
1220   menu_separator (menu_in_menu);
1221   create_menu_item_with_mnemonic (menu_in_menu, _("Clip selection"),
1222                     GTK_SIGNAL_FUNC (HandleCommand), ID_CLIP_SELECTED);
1223   create_menu_item_with_mnemonic (menu_in_menu, _("Split selection"),
1224                     GTK_SIGNAL_FUNC (HandleCommand), ID_SPLIT_SELECTED);
1225   create_menu_item_with_mnemonic (menu_in_menu, _("Flip Clip orientation"),
1226                     GTK_SIGNAL_FUNC (HandleCommand), ID_FLIP_CLIP);
1227   menu_separator (menu);
1228   create_menu_item_with_mnemonic (menu, _("Connect entities"),
1229                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_CONNECT);
1230   create_menu_item_with_mnemonic (menu, _("Ungroup entity"),
1231                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_UNGROUPENTITY);
1232   create_menu_item_with_mnemonic (menu, _("Make detail"),
1233                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_MAKE_DETAIL);
1234   create_menu_item_with_mnemonic (menu, _("Make structural"),
1235                     GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_MAKE_STRUCTURAL);
1236
1237   // BSP menu
1238   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Bsp"));
1239
1240   menu_separator (menu);
1241   g_object_set_data (G_OBJECT (window), "menu_bsp", menu);
1242
1243   // Grid menu
1244   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Grid"));
1245   if (g_PrefsDlg.m_bDetachableMenus)
1246     menu_tearoff (menu);
1247
1248   item = create_radio_menu_item_with_mnemonic (menu, NULL, _("Grid0.25"),
1249                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_025, FALSE);
1250   g_object_set_data (G_OBJECT (window), "menu_grid_025", item);
1251   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid0.5"),
1252                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_05, FALSE);
1253   g_object_set_data (G_OBJECT (window), "menu_grid_05", item);
1254   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid1"),
1255                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_1, FALSE);
1256   g_object_set_data (G_OBJECT (window), "menu_grid_1", item);
1257   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid2"),
1258                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_2, FALSE);
1259   g_object_set_data (G_OBJECT (window), "menu_grid_2", item);
1260   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid4"),
1261                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_4, FALSE);
1262   g_object_set_data (G_OBJECT (window), "menu_grid_4", item);
1263   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid8"),
1264                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_8, TRUE);
1265   g_object_set_data (G_OBJECT (window), "menu_grid_8", item);
1266   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid16"),
1267                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_16, FALSE);
1268   g_object_set_data (G_OBJECT (window), "menu_grid_16", item);
1269   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid32"),
1270                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_32, FALSE);
1271   g_object_set_data (G_OBJECT (window), "menu_grid_32", item);
1272   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid64"),
1273                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_64, FALSE);
1274   g_object_set_data (G_OBJECT (window), "menu_grid_64", item);
1275   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid128"),
1276                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_128, FALSE);
1277   g_object_set_data (G_OBJECT (window), "menu_grid_128", item);
1278   item = create_radio_menu_item_with_mnemonic (menu, item, _("Grid256"),
1279                                  GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_256, FALSE);
1280   g_object_set_data (G_OBJECT (window), "menu_grid_256", item);
1281   menu_separator (menu);
1282   item = create_check_menu_item_with_mnemonic (menu, _("Snap to grid"),
1283                                  GTK_SIGNAL_FUNC (HandleCommand), ID_SNAPTOGRID, TRUE);
1284   g_object_set_data (G_OBJECT (window), "menu_snaptogrid", item);
1285
1286   // Textures menu
1287   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Textures"));
1288   if (g_PrefsDlg.m_bDetachableMenus)
1289     menu_tearoff (menu);
1290
1291   item = create_check_menu_item_with_mnemonic (menu, _("Show In _Use"),
1292                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_SHOWINUSE, FALSE);
1293   g_object_set_data (G_OBJECT (window), "menu_textures_showinuse", item);
1294   item = create_check_menu_item_with_mnemonic (menu, _("Show _All"),
1295                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_SHOWALL, FALSE);
1296   g_object_set_data (G_OBJECT (window), "menu_textures_showall", item);
1297   menu_separator (menu);
1298   item = create_check_menu_item_with_mnemonic (menu, _("Show shaders"),
1299                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_SHADERS_SHOW, FALSE);
1300   g_object_set_data (G_OBJECT (window), "menu_textures_shaders_show", item);
1301   item = create_menu_item_with_mnemonic (menu, _("Flush & Reload Shaders"),
1302                            GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_RELOADSHADERS);
1303   g_object_set_data (G_OBJECT (window), "menu_textures_reloadshaders", item);
1304   item = create_menu_item_with_mnemonic (menu, _("Load directory..."),
1305                            GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_LOAD);
1306   g_object_set_data (G_OBJECT (window), "menu_textures_load", item);
1307   item = create_menu_item_with_mnemonic (menu, _("Directory list..."),
1308                            GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_LOADLIST);
1309   menu_separator (menu);
1310
1311   item = create_menu_item_with_mnemonic (menu, _("_Surface Inspector"),
1312                            GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_INSPECTOR);
1313   menu_separator (menu);
1314   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Render Quality"));
1315   g_object_set_data (G_OBJECT (window), "render_quality_menu", menu_in_menu);
1316   item = create_radio_menu_item_with_mnemonic (menu_in_menu, NULL, _("_Wireframe"),
1317                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_WIREFRAME, FALSE);
1318   g_object_set_data (G_OBJECT (window), "menu_textures_wireframe", item);
1319   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("_Flat shade"),
1320                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_FLATSHADE, FALSE);
1321   g_object_set_data (G_OBJECT (window), "menu_textures_flatshade", item);
1322   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("_Nearest"),
1323                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_NEAREST, FALSE);
1324   g_object_set_data (G_OBJECT (window), "menu_view_nearest", item);
1325   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("Nearest _Mipmap"),
1326                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_NEARESTMIPMAP, FALSE);
1327   g_object_set_data (G_OBJECT (window), "menu_view_nearestmipmap", item);
1328   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("_Linear"),
1329                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_LINEAR, FALSE);
1330   g_object_set_data (G_OBJECT (window), "menu_view_linear", item);
1331   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("_Bilinear"),
1332                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_BILINEAR, FALSE);
1333   g_object_set_data (G_OBJECT (window), "menu_view_bilinear", item);
1334   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("B_ilinear Mipmap"),
1335                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_BILINEARMIPMAP, FALSE);
1336   g_object_set_data (G_OBJECT (window), "menu_view_bilinearmipmap", item);
1337   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("T_rilinear"),
1338                                  GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_TRILINEAR, FALSE);
1339   g_object_set_data (G_OBJECT (window), "menu_view_trilinear", item);
1340   create_menu_item_with_mnemonic (menu, _("Find / Replace..."),
1341                     GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURE_REPLACEALL);
1342
1343   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Texture Lock"));
1344   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Moves"),
1345                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TOGGLE_LOCK, TRUE);
1346   g_object_set_data (G_OBJECT (window), "menu_toggle_lock", item);
1347   item = create_check_menu_item_with_mnemonic (menu_in_menu, _("Rotations"),
1348                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TOGGLE_ROTATELOCK, TRUE);
1349   g_object_set_data (G_OBJECT (window), "menu_toggle_rotatelock", item);
1350   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Texture Window Scale"));
1351   item = create_radio_menu_item_with_mnemonic (menu_in_menu, NULL, _("200%"),
1352                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_TEXTUREWINDOWSCALE_200, FALSE);
1353   g_object_set_data (G_OBJECT (window), "menu_textures_texturewindowscale_200", item);
1354   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("100%"),
1355                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_TEXTUREWINDOWSCALE_100, FALSE);
1356   g_object_set_data (G_OBJECT (window), "menu_textures_texturewindowscale_100", item);
1357   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("50%"),
1358                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_TEXTUREWINDOWSCALE_50, FALSE);
1359   g_object_set_data (G_OBJECT (window), "menu_textures_texturewindowscale_50", item);
1360   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("25%"),
1361                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_TEXTUREWINDOWSCALE_25, FALSE);
1362   g_object_set_data (G_OBJECT (window), "menu_textures_texturewindowscale_25", item);
1363   item = create_radio_menu_item_with_mnemonic (menu_in_menu, item, _("10%"),
1364                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_TEXTUREWINDOWSCALE_10, FALSE);
1365   g_object_set_data (G_OBJECT (window), "menu_textures_texturewindowscale_10", item);
1366   item = menu_separator (menu);
1367   item = create_check_menu_item_with_mnemonic (menu, _("shaderlist.txt only"),
1368                                  GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTURES_SHADERLISTONLY, FALSE);
1369   g_object_set_data (G_OBJECT (window), "menu_textures_shaderlistonly", item);
1370   item = menu_separator (menu);
1371   g_object_set_data (G_OBJECT (window), "menu_textures_separator", item);
1372   g_object_set_data (G_OBJECT (window), "menu_textures", menu);
1373
1374   // Misc menu
1375   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Misc"));
1376   if (g_PrefsDlg.m_bDetachableMenus)
1377     menu_tearoff (menu);
1378
1379   create_menu_item_with_mnemonic (menu, _("_Benchmark"), GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_BENCHMARK);
1380   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Colors"));
1381   menu_3 = create_menu_in_menu_with_mnemonic (menu_in_menu, _("Themes"));
1382   create_menu_item_with_mnemonic (menu_3, _("QE4 Original"), GTK_SIGNAL_FUNC (HandleCommand), ID_COLOR_SETORIGINAL);
1383   create_menu_item_with_mnemonic (menu_3, _("Q3Radiant Original"), GTK_SIGNAL_FUNC (HandleCommand), ID_COLOR_SETQER);
1384   create_menu_item_with_mnemonic (menu_3, _("Black and Green"), GTK_SIGNAL_FUNC (HandleCommand), ID_COLOR_SETBLACK);
1385   create_menu_item_with_mnemonic (menu_3, _("Maya/Max/Lightwave Emulation"), GTK_SIGNAL_FUNC (HandleCommand), ID_COLOR_SETYDNAR);
1386
1387   menu_separator (menu_in_menu);
1388   create_menu_item_with_mnemonic (menu_in_menu, _("_Texture Background..."),
1389                     GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTUREBK);
1390   create_menu_item_with_mnemonic (menu_in_menu, _("Grid Background..."),
1391                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_XYBK);
1392   create_menu_item_with_mnemonic (menu_in_menu, _("Grid Major..."),
1393                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_MAJOR);
1394   create_menu_item_with_mnemonic (menu_in_menu, _("Grid Minor..."),
1395                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_MINOR);
1396   create_menu_item_with_mnemonic (menu_in_menu, _("Grid Major Small..."),
1397                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_MAJOR_ALT);
1398   create_menu_item_with_mnemonic (menu_in_menu, _("Grid Minor Small..."),
1399                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_MINOR_ALT);
1400   create_menu_item_with_mnemonic (menu_in_menu, _("Grid Text..."),
1401                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_GRIDTEXT);
1402   create_menu_item_with_mnemonic (menu_in_menu, _("Grid Block..."),
1403                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_GRIDBLOCK);
1404   create_menu_item_with_mnemonic (menu_in_menu, _("Default Brush..."),
1405                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_BRUSH);
1406   create_menu_item_with_mnemonic (menu_in_menu, _("Camera Background..."),
1407                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_CAMERABACK);
1408   create_menu_item_with_mnemonic (menu_in_menu, _("Selected Brush..."),
1409                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_SELECTEDBRUSH);
1410   create_menu_item_with_mnemonic (menu_in_menu, _("Selected Brush (Camera)..."),
1411                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_SELECTEDBRUSH3D);
1412   create_menu_item_with_mnemonic (menu_in_menu, _("Clipper..."),
1413                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_CLIPPER);
1414   create_menu_item_with_mnemonic (menu_in_menu, _("Active View name..."),
1415                     GTK_SIGNAL_FUNC (HandleCommand), ID_COLORS_VIEWNAME);
1416
1417   create_menu_item_with_mnemonic (menu, _("_Gamma..."),
1418                     GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_GAMMA);
1419   create_menu_item_with_mnemonic (menu, _("Find brush..."),
1420                     GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_FINDBRUSH);
1421   item = create_menu_item_with_mnemonic (menu, _("Next leak spot"),
1422                            GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_NEXTLEAKSPOT);
1423   item = create_menu_item_with_mnemonic (menu, _("Previous leak spot"),
1424                            GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_PREVIOUSLEAKSPOT);
1425   create_menu_item_with_mnemonic (menu, _("_Print XY View"), GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_PRINTXY);
1426   item = create_menu_item_with_mnemonic (menu, _("_Select Entity Color..."),
1427                            GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_SELECTENTITYCOLOR);
1428   g_object_set_data (G_OBJECT (window), "menu_misc_selectentitycolor", item);
1429
1430   // Region menu
1431   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Region"));
1432   if (g_PrefsDlg.m_bDetachableMenus)
1433     menu_tearoff (menu);
1434
1435   create_menu_item_with_mnemonic (menu, _("_Off"),
1436                     GTK_SIGNAL_FUNC (HandleCommand), ID_REGION_OFF);
1437   create_menu_item_with_mnemonic (menu, _("_Set XY"),
1438                     GTK_SIGNAL_FUNC (HandleCommand), ID_REGION_SETXY);
1439   create_menu_item_with_mnemonic (menu, _("Set _Tall Brush"),
1440                     GTK_SIGNAL_FUNC (HandleCommand), ID_REGION_SETTALLBRUSH);
1441   create_menu_item_with_mnemonic (menu, _("Set _Brush"),
1442                     GTK_SIGNAL_FUNC (HandleCommand), ID_REGION_SETBRUSH);
1443   create_menu_item_with_mnemonic (menu, _("Set Se_lected Brushes"),
1444                     GTK_SIGNAL_FUNC (HandleCommand), ID_REGION_SETSELECTION);
1445
1446   // Brush menu
1447   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Brush"));
1448   if (g_PrefsDlg.m_bDetachableMenus)
1449     menu_tearoff (menu);
1450
1451   item = create_menu_item_with_mnemonic (menu, _("3 sided"), GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_3SIDED);
1452   item = create_menu_item_with_mnemonic (menu, _("4 sided"), GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_4SIDED);
1453   item = create_menu_item_with_mnemonic (menu, _("5 sided"), GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_5SIDED);
1454   item = create_menu_item_with_mnemonic (menu, _("6 sided"), GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_6SIDED);
1455   item = create_menu_item_with_mnemonic (menu, _("7 sided"), GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_7SIDED);
1456   item = create_menu_item_with_mnemonic (menu, _("8 sided"), GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_8SIDED);
1457   item = create_menu_item_with_mnemonic (menu, _("9 sided"), GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_9SIDED);
1458   menu_separator (menu);
1459   create_menu_item_with_mnemonic (menu, _("Arbitrary sided..."),
1460                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_ARBITRARYSIDED);
1461   menu_separator (menu);
1462   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Primitives"));
1463   create_menu_item_with_mnemonic (menu_in_menu, _("Cone..."),
1464                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_MAKECONE);
1465   create_menu_item_with_mnemonic (menu_in_menu, _("Sphere..."),
1466                     GTK_SIGNAL_FUNC (HandleCommand), ID_BRUSH_PRIMITIVES_SPHERE);
1467
1468   // Curve menu
1469   if (!g_pGameDescription->mNoPatch)
1470   {
1471   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Curve"));
1472   if (g_PrefsDlg.m_bDetachableMenus)
1473     menu_tearoff (menu);
1474
1475   create_menu_item_with_mnemonic (menu, _("Cylinder"), GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_PATCHTUBE);
1476   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("More Cylinders"));
1477   create_menu_item_with_mnemonic (menu_in_menu, _("Dense Cylinder"),
1478                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_PATCHDENSETUBE);
1479   create_menu_item_with_mnemonic (menu_in_menu, _("Very Dense Cylinder"),
1480                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_PATCHVERYDENSETUBE);
1481   create_menu_item_with_mnemonic (menu_in_menu, _("Square Cylinder"),
1482                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_PATCHSQUARE);
1483   menu_separator (menu);
1484   create_menu_item_with_mnemonic (menu, _("End cap"), GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_PATCHENDCAP);
1485   create_menu_item_with_mnemonic (menu, _("Bevel"), GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_PATCHBEVEL);
1486   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("More End caps, Bevels"));
1487   create_menu_item_with_mnemonic (menu_in_menu, _("Square Endcap"),
1488                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_MOREENDCAPSBEVELS_SQUAREBEVEL);
1489   create_menu_item_with_mnemonic (menu_in_menu, _("Square Bevel"),
1490                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_MOREENDCAPSBEVELS_SQUAREENDCAP);
1491   menu_separator (menu);
1492   create_menu_item_with_mnemonic (menu, _("Cone"), GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_PATCHCONE);
1493   item = create_menu_item_with_mnemonic (menu, _("Sphere"),
1494                            GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_PRIMITIVES_SPHERE);
1495   gtk_widget_set_sensitive (item, FALSE);
1496   menu_separator (menu);
1497   item = create_menu_item_with_mnemonic (menu, _("Simple Patch Mesh..."),
1498                            GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_SIMPLEPATCHMESH);
1499   g_object_set_data (G_OBJECT (window), "menu_simplepatchmesh", item);
1500   menu_separator (menu);
1501   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Insert"));
1502   create_menu_item_with_mnemonic (menu_in_menu, _("Insert (2) Columns"),
1503                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_INSERT_INSERTCOLUMN);
1504   create_menu_item_with_mnemonic (menu_in_menu, _("Add (2) Columns"),
1505                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_INSERT_ADDCOLUMN);
1506   menu_separator (menu_in_menu);
1507   create_menu_item_with_mnemonic (menu_in_menu, _("Insert (2) Rows"),
1508                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_INSERT_INSERTROW);
1509   create_menu_item_with_mnemonic (menu_in_menu, _("Add (2) Rows"),
1510                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_INSERT_ADDROW);
1511   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Delete"));
1512   create_menu_item_with_mnemonic (menu_in_menu, _("First (2) Columns"),
1513                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_DELETE_FIRSTCOLUMN);
1514   create_menu_item_with_mnemonic (menu_in_menu, _("Last (2) Columns"),
1515                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_DELETE_LASTCOLUMN);
1516   menu_separator (menu_in_menu);
1517   create_menu_item_with_mnemonic (menu_in_menu, _("First (2) Rows"),
1518                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_DELETE_FIRSTROW);
1519   create_menu_item_with_mnemonic (menu_in_menu, _("Last (2) Rows"),
1520                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_DELETE_LASTROW);
1521   menu_separator (menu);
1522   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Matrix"));
1523   create_menu_item_with_mnemonic (menu_in_menu, _("Invert"),
1524                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_NEGATIVE);
1525   menu_3 = create_menu_in_menu_with_mnemonic (menu_in_menu, _("Re-disperse"));
1526   create_menu_item_with_mnemonic (menu_3, _("Rows"), GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_REDISPERSE_ROWS);
1527   create_menu_item_with_mnemonic (menu_3, _("Cols (Intermediate)"), GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_REDISPERSE_INTERMEDIATE_COLS);
1528   create_menu_item_with_mnemonic (menu_3, _("Rows (Intermediate)"), GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_REDISPERSE_INTERMEDIATE_ROWS);
1529   create_menu_item_with_mnemonic (menu_in_menu, _("Transpose"),
1530                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_MATRIX_TRANSPOSE);
1531   menu_separator (menu);
1532   create_menu_item_with_mnemonic (menu, _("Cap Selection"),
1533                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_CAP);
1534   create_menu_item_with_mnemonic (menu, _("Cycle Cap Texture"),
1535                         GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_CYCLECAP);
1536   menu_separator (menu);
1537   menu_in_menu = create_menu_in_menu_with_mnemonic (menu, _("Overlay"));
1538   create_menu_item_with_mnemonic (menu_in_menu, _("Set"),
1539                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_OVERLAY_SET);
1540   create_menu_item_with_mnemonic (menu_in_menu, _("Clear"),
1541                     GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_OVERLAY_CLEAR);
1542   menu_separator (menu);
1543   create_menu_item_with_mnemonic (menu, _("Thicken..."), GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_THICKEN);
1544   }
1545   // Plugins menu
1546   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Plugins"));
1547   if (g_PrefsDlg.m_bDetachableMenus)
1548     menu_tearoff (menu);
1549
1550   /*
1551   create_menu_item_with_mnemonic (menu, "Refresh", GTK_SIGNAL_FUNC (HandleCommand), ID_PLUGINS_REFRESH);
1552   */
1553   // NOTE: the seperator is used when doing a refresh of the list, everything past the seperator is removed
1554   item = menu_separator (menu);
1555   g_object_set_data (G_OBJECT (window), "menu_plugin_separator", item);
1556   g_object_set_data (G_OBJECT (window), "menu_plugin", menu);
1557
1558   // Help menu
1559   menu = create_sub_menu_with_mnemonic (menu_bar, _("_Help"));
1560   if (g_PrefsDlg.m_bDetachableMenus)
1561     menu_tearoff (menu);
1562
1563   item = create_menu_item_with_mnemonic (menu, _("Manual"),
1564                            GTK_SIGNAL_FUNC (HandleCommand), ID_HELP);
1565   gtk_widget_add_accelerator (item, "activate", accel, GDK_F1, (GdkModifierType)0, GTK_ACCEL_VISIBLE);
1566
1567   // this creates all the per-game drop downs for the game pack helps
1568   // it will take care of hooking the Sys_OpenURL calls etc.
1569   create_game_help_menu(menu, accel);
1570
1571   // TTimo: this is in global.xlink now
1572   //create_menu_item_with_mnemonic (menu, "Links",
1573   //                  GTK_SIGNAL_FUNC (HandleCommand), ID_HELP_LINKS);
1574   create_menu_item_with_mnemonic (menu, _("Bug report"),
1575                     GTK_SIGNAL_FUNC (HandleCommand), ID_HELP_BUGREPORT);
1576   create_menu_item_with_mnemonic (menu, _("Shortcuts list"),
1577                     GTK_SIGNAL_FUNC (HandleCommand), ID_HELP_COMMANDLIST);
1578   create_menu_item_with_mnemonic (menu, _("_About"),
1579                     GTK_SIGNAL_FUNC (HandleCommand), ID_HELP_ABOUT);
1580
1581
1582   // leo: Hidden menu to make the accelerators work,
1583   // this is a hack that needs to be changed later if someone has a better idea.
1584   // NOTE TTimo
1585   // maybe the better idea would be NOT to use any such accelerator scheme and do all key listening and interpret ourselves
1586   menu = create_sub_menu_with_mnemonic (menu_bar, "Hidden");
1587   if (g_PrefsDlg.m_bDetachableMenus)
1588     menu_tearoff (menu);
1589
1590   gtk_widget_hide (gtk_menu_get_attach_widget (GTK_MENU (menu)));
1591
1592   create_menu_item_with_mnemonic (menu, "BendMode", GTK_SIGNAL_FUNC (HandleCommand), ID_PATCH_BEND);
1593   create_menu_item_with_mnemonic (menu, "FitTexture", GTK_SIGNAL_FUNC (HandleCommand), IDC_BTN_FACEFIT);
1594   create_menu_item_with_mnemonic (menu, "ViewTextures", GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_TEXTURE);
1595   create_menu_item_with_mnemonic (menu, "PatchInspector", GTK_SIGNAL_FUNC (HandleCommand), ID_PATCH_INSPECTOR);
1596   create_menu_item_with_mnemonic (menu, "InvertCurveTextureX", GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_NEGATIVETEXTUREY);
1597   create_menu_item_with_mnemonic (menu, "InvertCurveTextureY", GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_NEGATIVETEXTUREX);
1598   create_menu_item_with_mnemonic (menu, "IncPatchColumn", GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_INSERTCOLUMN);
1599   create_menu_item_with_mnemonic (menu, "IncPatchRow", GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_INSERTROW);
1600   create_menu_item_with_mnemonic (menu, "DecPatchColumn", GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_DELETECOLUMN);
1601   create_menu_item_with_mnemonic (menu, "DecPatchRow", GTK_SIGNAL_FUNC (HandleCommand), ID_CURVE_DELETEROW);
1602   create_menu_item_with_mnemonic (menu, "Patch TAB", GTK_SIGNAL_FUNC (HandleCommand), ID_PATCH_TAB);
1603   create_menu_item_with_mnemonic (menu, "Patch TAB", GTK_SIGNAL_FUNC (HandleCommand), ID_PATCH_TAB);
1604   create_menu_item_with_mnemonic (menu, "SelectNudgeDown", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECT_NUDGEDOWN);
1605   create_menu_item_with_mnemonic (menu, "CameraForward", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_FORWARD);
1606   create_menu_item_with_mnemonic (menu, "CameraBack", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_BACK);
1607   create_menu_item_with_mnemonic (menu, "CameraLeft", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_LEFT);
1608   create_menu_item_with_mnemonic (menu, "CameraRight", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_RIGHT);
1609   create_menu_item_with_mnemonic (menu, "CameraUp", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_UP);
1610   create_menu_item_with_mnemonic (menu, "CameraDown", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_DOWN);
1611   create_menu_item_with_mnemonic (menu, "CameraAngleUp", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_ANGLEUP);
1612   create_menu_item_with_mnemonic (menu, "CameraAngleDown", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_ANGLEDOWN);
1613   create_menu_item_with_mnemonic (menu, "CameraStrafeRight", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_STRAFERIGHT);
1614   create_menu_item_with_mnemonic (menu, "CameraStrafeLeft", GTK_SIGNAL_FUNC (HandleCommand), ID_CAMERA_STRAFELEFT);
1615   create_menu_item_with_mnemonic (menu, "ToggleGrid", GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_TOGGLE);
1616   create_menu_item_with_mnemonic (menu, "ToggleCrosshairs", GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_CROSSHAIR);
1617   create_menu_item_with_mnemonic (menu, "ToggleRealtime", GTK_SIGNAL_FUNC (HandleCommand), ID_VIEW_CAMERAUPDATE);
1618   create_menu_item_with_mnemonic (menu, "MouseRotate", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECT_MOUSEROTATE);
1619   create_menu_item_with_mnemonic (menu, "TexRotateClock", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_ROTATECLOCK);
1620   create_menu_item_with_mnemonic (menu, "TexRotateCounter", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_ROTATECOUNTER);
1621   create_menu_item_with_mnemonic (menu, "TexScaleUp", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_SCALEUP);
1622   create_menu_item_with_mnemonic (menu, "TexScaleDown", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_SCALEDOWN);
1623   create_menu_item_with_mnemonic (menu, "TexShiftLeft", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_SHIFTLEFT);
1624   create_menu_item_with_mnemonic (menu, "TexShiftRight", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_SHIFTRIGHT);
1625   create_menu_item_with_mnemonic (menu, "TexShiftUp", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_SHIFTUP);
1626   create_menu_item_with_mnemonic (menu, "TexShiftDown", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_SHIFTDOWN);
1627   create_menu_item_with_mnemonic (menu, "GridDown", GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_PREV);
1628   create_menu_item_with_mnemonic (menu, "GridUp", GTK_SIGNAL_FUNC (HandleCommand), ID_GRID_NEXT);
1629   create_menu_item_with_mnemonic (menu, "TexScaleLeft", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_SCALELEFT);
1630   create_menu_item_with_mnemonic (menu, "TexScaleRight", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TEXTURE_SCALERIGHT);
1631   create_menu_item_with_mnemonic (menu, "MoveSelectionDOWN", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_MOVEDOWN);
1632   create_menu_item_with_mnemonic (menu, "MoveSelectionUP", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_MOVEUP);
1633   create_menu_item_with_mnemonic (menu, "DumpSelectedBrush", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_PRINT);
1634   create_menu_item_with_mnemonic (menu, "ToggleSizePaint", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_TOGGLESIZEPAINT);
1635   create_menu_item_with_mnemonic (menu, "SelectNudgeLeft", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECT_NUDGELEFT);
1636   create_menu_item_with_mnemonic (menu, "SelectNudgeRight", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECT_NUDGERIGHT);
1637   create_menu_item_with_mnemonic (menu, "SelectNudgeUp", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_SELECT_NUDGEUP);
1638   create_menu_item_with_mnemonic (menu, "NaturalizePatch", GTK_SIGNAL_FUNC (HandleCommand), ID_PATCH_NATURALIZE);
1639   create_menu_item_with_mnemonic (menu, "SnapPatchToGrid", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECT_SNAPTOGRID);
1640   create_menu_item_with_mnemonic (menu, "SelectAllOfType", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECT_ALL);
1641   create_menu_item_with_mnemonic (menu, "CycleOutlineStyle", GTK_SIGNAL_FUNC (HandleCommand), ID_SELECTION_OUTLINESTYLE);
1642   create_menu_item_with_mnemonic (menu, "TextureWindowScaleup", GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTUREWINDOW_SCALEUP);
1643   create_menu_item_with_mnemonic (menu, "TextureWindowScaledown", GTK_SIGNAL_FUNC (HandleCommand), ID_TEXTUREWINDOW_SCALEDOWN);
1644
1645   g_bIgnoreCommands--;
1646 }
1647
1648 void MainFrame::create_main_toolbar (GtkWidget *window, GtkWidget *vbox)
1649 {
1650   GtkWidget *handle_box, *toolbar, *w;
1651
1652   handle_box = gtk_handle_box_new ();
1653   gtk_box_pack_start (GTK_BOX (vbox), handle_box, FALSE, FALSE, 0);
1654   gtk_widget_show (handle_box);
1655   g_object_set_data (G_OBJECT (window), "tb_handle_box", handle_box);
1656
1657   toolbar = gtk_toolbar_new ();
1658   gtk_toolbar_set_orientation (GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1659   gtk_toolbar_set_style (GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
1660   //  gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), user_rc.toolbar_style);
1661   gtk_container_add (GTK_CONTAINER (handle_box), toolbar);
1662
1663   gtk_widget_show (toolbar);
1664
1665   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), _("Open"), _("Open an existing map"), "",
1666                                new_pixmap (window, "file_open.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1667                                GINT_TO_POINTER (ID_FILE_OPEN));
1668   g_object_set_data (G_OBJECT (window), "tb_file_open", w);
1669   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), _("Save"), _("Save the active map"), "",
1670                                new_pixmap (window, "file_save.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1671                                GINT_TO_POINTER (ID_FILE_SAVE));
1672   g_object_set_data (G_OBJECT (window), "tb_file_save", w);
1673   gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1674   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("x-axis Flip"), "",
1675                                new_pixmap (window, "brush_flipx.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1676                                GINT_TO_POINTER (ID_BRUSH_FLIPX));
1677   g_object_set_data (G_OBJECT (window), "tb_brush_flipx", w);
1678   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("x-axis Rotate"), "",
1679                                new_pixmap (window, "brush_rotatex.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1680                                GINT_TO_POINTER (ID_BRUSH_ROTATEX));
1681   g_object_set_data (G_OBJECT (window), "tb_brush_rotatex", w);
1682   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("y-axis Flip"), "",
1683                                new_pixmap (window, "brush_flipy.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1684                                GINT_TO_POINTER (ID_BRUSH_FLIPY));
1685   g_object_set_data (G_OBJECT (window), "tb_brush_flipy", w);
1686   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("y-axis Rotate"), "",
1687                                new_pixmap (window, "brush_rotatey.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1688                                GINT_TO_POINTER (ID_BRUSH_ROTATEY));
1689   g_object_set_data (G_OBJECT (window), "tb_brush_rotatey", w);
1690   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("z-axis Flip"), "",
1691                                new_pixmap (window, "brush_flipz.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1692                                GINT_TO_POINTER (ID_BRUSH_FLIPZ));
1693   g_object_set_data (G_OBJECT (window), "tb_brush_flipz", w);
1694   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("z-axis Rotate"), "",
1695                                new_pixmap (window, "brush_rotatez.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1696                                GINT_TO_POINTER (ID_BRUSH_ROTATEZ));
1697   g_object_set_data (G_OBJECT (window), "tb_brush_rotatez", w);
1698   gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1699
1700   if (g_PrefsDlg.m_bWideToolbar)
1701   {
1702     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Complete Tall"), "",
1703                                  new_pixmap (window, "selection_selectcompletetall.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1704                                  GINT_TO_POINTER (ID_SELECTION_SELECTCOMPLETETALL));
1705     g_object_set_data (G_OBJECT (window), "tb_selection_selectcompletetall", w);
1706     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Select Touching"), "",
1707                                  new_pixmap (window, "selection_selecttouching.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1708                                  GINT_TO_POINTER (ID_SELECTION_SELECTTOUCHING));
1709     g_object_set_data (G_OBJECT (window), "tb_selection_selecttouching", w);
1710     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Select Partial Tall"), "",
1711                                  new_pixmap (window, "selection_selectpartialtall.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1712                                  GINT_TO_POINTER (ID_SELECTION_SELECTPARTIALTALL));
1713     g_object_set_data (G_OBJECT (window), "tb_selection_selectpartialtall", w);
1714     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Select Inside"), "",
1715                                  new_pixmap (window, "selection_selectinside.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1716                                  GINT_TO_POINTER (ID_SELECTION_SELECTINSIDE));
1717     g_object_set_data (G_OBJECT (window), "tb_selection_selectinside", w);
1718   } else
1719   {
1720     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Selection"), "",
1721                                  new_pixmap (window, "popup_selection.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1722                                  GINT_TO_POINTER (ID_POPUP_SELECTION));
1723     g_object_set_data (G_OBJECT (window), "tb_popup_selection", w);
1724   }
1725   gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1726
1727   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("CSG Subtract"), "",
1728                                new_pixmap (window, "selection_csgsubtract.bmp"),
1729                                GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_SELECTION_CSGSUBTRACT));
1730   g_object_set_data (G_OBJECT (window), "tb_selection_csgsubtract", w);
1731
1732   if (g_PrefsDlg.m_bWideToolbar)
1733   {
1734     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("CSG Merge"), "",
1735                                  new_pixmap (window, "selection_csgmerge.bmp"),
1736                                  GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_SELECTION_CSGMERGE));
1737     g_object_set_data (G_OBJECT (window), "tb_selection_csgmerge", w);
1738   }
1739
1740   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Hollow"), "",
1741                                new_pixmap (window, "selection_makehollow.bmp"),
1742                                GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_SELECTION_MAKEHOLLOW));
1743   g_object_set_data (G_OBJECT (window), "tb_selection_makehollow", w);
1744
1745   if (g_PrefsDlg.m_bWideToolbar)
1746   {
1747     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1748                                     "", _("Clipper"), "", new_pixmap (window, "view_clipper.bmp"),
1749                                     GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_VIEW_CLIPPER));
1750     g_object_set_data (G_OBJECT (window), "tb_view_clipper", w);
1751   }
1752
1753   gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1754
1755   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Change views"), "",
1756                                new_pixmap (window, "view_change.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1757                                GINT_TO_POINTER (ID_VIEW_CHANGE));
1758   g_object_set_data (G_OBJECT (window), "tb_view_change", w);
1759
1760   if (!g_PrefsDlg.m_bWideToolbar)
1761   {
1762     gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1763   }
1764
1765   w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Texture view mode"), "",
1766                                new_pixmap (window, "textures_popup.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1767                                GINT_TO_POINTER (ID_TEXTURES_POPUP));
1768   g_object_set_data (G_OBJECT (window), "tb_textures_popup", w);
1769
1770   if (g_PrefsDlg.m_bWideToolbar)
1771   {
1772     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1773                                     "", _("Cubic clip the camera view"), "",
1774                                     new_pixmap (window, "view_cubicclipping.bmp"),
1775                                     GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_VIEW_CUBICCLIPPING));
1776     g_object_set_data (G_OBJECT (window), "tb_view_cubicclipping", w);
1777   }
1778
1779   gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1780
1781   if (!g_PrefsDlg.m_bWideToolbar)
1782   {
1783     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1784                                 "", _("Camera preview"), "", new_pixmap (window, "view_cameratoggle.bmp"),
1785                                 GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_VIEW_CAMERATOGGLE));
1786     g_object_set_data (G_OBJECT (window), "tb_view_cameratoggle", w);
1787     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", "Update Camera", "",
1788                              new_pixmap (window, "view_cameraupdate.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1789                              GINT_TO_POINTER (ID_VIEW_CAMERAUPDATE));
1790     g_object_set_data (G_OBJECT (window), "tb_view_cameraupdate", w);
1791     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1792                                 "", _("Cubic clip the camera view"), "",
1793                                 new_pixmap (window, "view_cubicclipping.bmp"),
1794                                 GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_VIEW_CUBICCLIPPING));
1795     g_object_set_data (G_OBJECT (window), "tb_view_cubicclipping", w);
1796     gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1797     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1798                                     "", _("Entity inspector"), "", new_pixmap (window, "view_entity.bmp"),
1799                                     GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_VIEW_ENTITY));
1800     g_object_set_data (G_OBJECT (window), "tb_view_entity", w);
1801     gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1802     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1803                                     "", _("Clipper"), "", new_pixmap (window, "view_clipper.bmp"),
1804                                     GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_VIEW_CLIPPER));
1805     g_object_set_data (G_OBJECT (window), "tb_view_clipper", w);
1806     gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1807   }
1808
1809   w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1810                               "", _("Free Rotation"), "", new_pixmap (window, "select_mouserotate.bmp"),
1811                               GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_SELECT_MOUSEROTATE));
1812   g_object_set_data (G_OBJECT (window), "tb_select_mouserotate", w);
1813   gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1814   w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1815                               "", _("Free Scaling"), "", new_pixmap (window, "select_mousescale.bmp"),
1816                               GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_SELECT_MOUSESCALE));
1817   g_object_set_data (G_OBJECT (window), "tb_select_mousescale", w);
1818   w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1819                                   "", _("Scale X"), "", new_pixmap (window, "scalelockx.bmp"),
1820                                   GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_SCALELOCKX));
1821   g_object_set_data (G_OBJECT (window), "tb_scalelockx", w);
1822   w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1823                                   "", _("Scale Y"), "", new_pixmap (window, "scalelocky.bmp"),
1824                                   GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_SCALELOCKY));
1825   g_object_set_data (G_OBJECT (window), "tb_scalelocky", w);
1826   w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1827                                   "", _("Scale Z"), "", new_pixmap (window, "scalelockz.bmp"),
1828                                   GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_SCALELOCKZ));
1829   g_object_set_data (G_OBJECT (window), "tb_scalelockz", w);
1830
1831   if (g_PrefsDlg.m_bWideToolbar)
1832   {
1833     gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1834     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1835                              "", _("Don't select model brushes"), "",
1836                              new_pixmap (window, "dontselectmodel.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1837                              GINT_TO_POINTER (ID_DONTSELECTMODEL));
1838     gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1839     g_object_set_data (G_OBJECT (window), "tb_dontselectmodel", w);
1840
1841     if (!g_pGameDescription->mNoPatch)
1842     {
1843       w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1844                              "", _("Don't select curved brushes"), "",
1845                              new_pixmap (window, "dontselectcurve.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1846                              GINT_TO_POINTER (ID_DONTSELECTCURVE));
1847       g_object_set_data (G_OBJECT (window), "tb_dontselectcurve", w);
1848     }
1849   }
1850
1851   // bug #292, patch toolbar option
1852   if (g_PrefsDlg.m_bPatchToolbar)
1853   {
1854     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1855                              "", _("Show patch bounding box"), "",
1856                              new_pixmap (window, "patch_showboundingbox.bmp"),
1857                              GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_PATCH_SHOWBOUNDINGBOX));
1858     g_object_set_data (G_OBJECT (window), "tb_patch_showboundingbox", w);
1859     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1860                                     "", _("Show patches as wireframes"), "",
1861                                     new_pixmap (window, "patch_wireframe.bmp"),
1862                                     GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (ID_PATCH_WIREFRAME));
1863     g_object_set_data (G_OBJECT (window), "tb_patch_wireframe", w);
1864     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1865                              "", _("Patch Bend mode"), "",
1866                              new_pixmap (window, "patch_bend.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1867                              GINT_TO_POINTER (ID_PATCH_BEND));
1868     g_object_set_data (G_OBJECT (window), "tb_patch_bend", w);
1869     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Put caps on the current patch"), "",
1870                              new_pixmap (window, "curve_cap.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1871                              GINT_TO_POINTER (ID_CURVE_CAP));
1872     g_object_set_data (G_OBJECT (window), "tb_curve_cap", w);
1873     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1874                                  "", _("Welds equal patch points during moves"), "",
1875                                  new_pixmap (window, "patch_weld.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1876                                  GINT_TO_POINTER (ID_PATCH_WELD));
1877     g_object_set_data (G_OBJECT (window), "tb_patch_weld", w);
1878     w = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
1879                              "", _("Selects drill down rows and columns"), "",
1880                              new_pixmap (window, "patch_drilldown.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1881                              GINT_TO_POINTER (ID_PATCH_DRILLDOWN));
1882     g_object_set_data (G_OBJECT (window), "tb_patch_drilldown", w);
1883   }
1884
1885   if (g_PrefsDlg.m_bWideToolbar)
1886   {
1887     gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
1888     w = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "", _("Show Entities as"), "",
1889                              new_pixmap (window, "show_entities.bmp"), GTK_SIGNAL_FUNC (HandleCommand),
1890                              GINT_TO_POINTER (ID_SHOW_ENTITIES));
1891     g_object_set_data (G_OBJECT (window), "tb_show_entities", w);
1892   }
1893
1894   /*
1895   uh? that is OLD
1896 #ifndef QUAKE3
1897   w = g_object_get_data (G_OBJECT (window), "tb_dontselectcurve");
1898   gtk_widget_hide (w);
1899   w = g_object_get_data (G_OBJECT (window), "tb_patch_showboundingbox");
1900   gtk_widget_hide (w);
1901   w = g_object_get_data (G_OBJECT (window), "tb_patch_weld");
1902   gtk_widget_hide (w);
1903   w = g_object_get_data (G_OBJECT (window), "tb_patch_wireframe");
1904   gtk_widget_hide (w);
1905 #endif
1906   */
1907
1908   m_bCamPreview = true;
1909   g_nScaleHow = (SCALE_X | SCALE_Y | SCALE_Z);
1910 }
1911
1912 void MainFrame::create_plugin_toolbar (GtkWidget *window, GtkWidget *vbox)
1913 {
1914   GtkWidget *handle_box, *toolbar;
1915
1916   handle_box = gtk_handle_box_new ();
1917   gtk_box_pack_start (GTK_BOX (vbox), handle_box, FALSE, FALSE, 0);
1918   if (g_PrefsDlg.m_bPluginToolbar)
1919     gtk_widget_show (handle_box);
1920   g_object_set_data (G_OBJECT (window), "tb_handle_box", handle_box);
1921
1922   toolbar = gtk_toolbar_new();
1923   gtk_toolbar_set_orientation (GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1924   gtk_toolbar_set_style (GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
1925   //  gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), user_rc.toolbar_style);
1926   gtk_container_add (GTK_CONTAINER (handle_box), toolbar);
1927   g_object_set_data (G_OBJECT (window), "toolbar_plugin", toolbar);
1928   gtk_widget_show (toolbar);
1929 }
1930
1931 void MainFrame::create_main_statusbar (GtkWidget *window, GtkWidget *vbox)
1932 {
1933   GtkWidget *hbox, *hbox1;
1934   GtkWidget *frame;
1935   GtkWidget *label;
1936
1937   hbox = gtk_hbox_new (FALSE, 0);
1938   gtk_widget_show (hbox);
1939   gtk_widget_set_usize (hbox, -1, 24);
1940   gtk_container_border_width (GTK_CONTAINER (hbox), 1);
1941   gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, TRUE, 2);
1942
1943   frame = gtk_frame_new ((char*)NULL);
1944   gtk_widget_show (frame);
1945   gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
1946   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
1947
1948   hbox1 = gtk_hbox_new (FALSE, 0);
1949   gtk_container_add (GTK_CONTAINER (frame), hbox1);
1950   gtk_container_border_width (GTK_CONTAINER (hbox1), 0);
1951   gtk_widget_show (hbox1);
1952
1953   label = gtk_label_new (_(" Label "));
1954   gtk_widget_show (label);
1955   gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, TRUE, 0);
1956   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1957   gtk_misc_set_padding (GTK_MISC (label), 3, 0);
1958   m_pStatusLabel[0] = label;
1959
1960   for (int i = 1; i < 6; i++)
1961   {
1962     frame = gtk_frame_new ((char*)NULL);
1963     gtk_widget_show (frame);
1964     gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
1965     gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
1966
1967     label = gtk_label_new (_(" Label "));
1968     gtk_widget_show (label);
1969     gtk_container_add (GTK_CONTAINER (frame), label);
1970     m_pStatusLabel[i] = label;
1971   }
1972 }
1973
1974 guint s_idle_id;
1975 static gint mainframe_idle (gpointer user_data)
1976 {
1977   g_pParentWnd->RoutineProcessing ();
1978   return TRUE;
1979 }
1980
1981 static void Sys_Iconify (GtkWidget *w);
1982 static void Sys_Restore (GtkWidget *w);
1983
1984 inline void CHECK_RESTORE(GtkWidget* w)
1985 {
1986   if (g_object_get_data (G_OBJECT (w), "was_mapped") != NULL)
1987     gtk_widget_show (w);
1988 }
1989
1990
1991 // this is called when the window is restored from the iconified state
1992 static void mainframe_map (GtkWidget *widget)
1993 {
1994   if (g_pParentWnd->IsSleeping ())
1995     g_pParentWnd->OnSleep ();
1996
1997   if ((g_pParentWnd->CurrentStyle() == MainFrame::eFloating) && (widget == g_pParentWnd->m_pWidget))
1998   {
1999     // restore previously visible windows
2000     CHECK_RESTORE (g_pParentWnd->GetCamWnd ()->m_pParent);
2001     if (g_PrefsDlg.m_bFloatingZ)
2002       CHECK_RESTORE (g_pParentWnd->GetZWnd ()->m_pParent);
2003     CHECK_RESTORE (g_pParentWnd->GetXYWnd ()->m_pParent);
2004     CHECK_RESTORE (g_pParentWnd->GetXZWnd ()->m_pParent);
2005     CHECK_RESTORE (g_pParentWnd->GetYZWnd ()->m_pParent);
2006     CHECK_RESTORE (g_pGroupDlg->m_pWidget);
2007   }
2008 }
2009
2010 inline void CHECK_MINIMIZE(GtkWidget* w)
2011 {
2012   g_object_set_data (G_OBJECT (w), "was_mapped", (void*)(GTK_WIDGET_VISIBLE (w) != 0));
2013   gtk_widget_hide (w);
2014 }
2015
2016 static void mainframe_unmap (GtkWidget *widget)
2017 {
2018
2019   if ((g_pParentWnd->CurrentStyle() == MainFrame::eFloating) && (widget == g_pParentWnd->m_pWidget))
2020   {
2021     // minimize all other windows when the main window is minimized
2022     CHECK_MINIMIZE (g_pParentWnd->GetCamWnd ()->m_pParent);
2023     if (g_PrefsDlg.m_bFloatingZ)
2024       CHECK_MINIMIZE (g_pParentWnd->GetZWnd ()->m_pParent);
2025     CHECK_MINIMIZE (g_pParentWnd->GetXYWnd ()->m_pParent);
2026     CHECK_MINIMIZE (g_pParentWnd->GetXZWnd ()->m_pParent);
2027     CHECK_MINIMIZE (g_pParentWnd->GetYZWnd ()->m_pParent);
2028     CHECK_MINIMIZE (g_pGroupDlg->m_pWidget);
2029   }
2030 }
2031
2032 static GtkWidget* create_floating (MainFrame* mainframe)
2033 {
2034   GtkWidget *wnd = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2035   //if (mainframe->CurrentStyle() != MainFrame::eFloating)
2036     gtk_window_set_transient_for (GTK_WINDOW (wnd), GTK_WINDOW (mainframe->m_pWidget));
2037   gtk_widget_set_events (wnd, GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
2038   gtk_signal_connect (GTK_OBJECT (wnd), "delete_event", GTK_SIGNAL_FUNC (widget_delete_hide), NULL);
2039   gtk_signal_connect (GTK_OBJECT (wnd), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroy), NULL);
2040   gtk_signal_connect (GTK_OBJECT (wnd), "key_press_event",
2041                       GTK_SIGNAL_FUNC (mainframe_keypress), mainframe);
2042   gtk_signal_connect (GTK_OBJECT (wnd), "key_release_event",
2043                       GTK_SIGNAL_FUNC (mainframe_keyrelease), mainframe);
2044   gtk_signal_connect (GTK_OBJECT (wnd), "map_event",
2045                       GTK_SIGNAL_FUNC (mainframe_map), mainframe);
2046
2047   gtk_window_set_default_size (GTK_WINDOW (wnd), 100, 100);
2048
2049 #ifdef DBG_WINDOWPOS
2050   Sys_Printf("create_floating: %p, gtk_window_set_default_size 100, 100\n", wnd);
2051 #endif
2052
2053   return wnd;
2054 }
2055
2056 void console_populate_popup(GtkTextView* textview, GtkMenu* menu, gpointer user_data)
2057 {
2058   menu_separator(GTK_WIDGET(menu));
2059
2060   GtkWidget* item = gtk_menu_item_new_with_label (_("Clear"));
2061   gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (Sys_ClearPrintf), NULL);
2062   gtk_widget_show (item);
2063   gtk_menu_append (GTK_MENU (menu), item);
2064 }
2065
2066 void console_construct(GtkWidget* textview)
2067 {
2068   g_signal_connect(G_OBJECT(textview), "populate-popup", G_CALLBACK(console_populate_popup), NULL);
2069 }
2070
2071 extern MemStream g_Clipboard;
2072
2073 void Clipboard_CopyMap()
2074 {
2075   g_Clipboard.SetLength(0);
2076   Map_Export (&g_Clipboard, "xmap", false, true);
2077 }
2078
2079 void Clipboard_PasteMap()
2080 {
2081   if (g_Clipboard.GetLength() > 0)
2082   {
2083     g_Clipboard.Seek(0, SEEK_SET);
2084     Map_Import(&g_Clipboard, "xmap", true);
2085   }
2086 }
2087
2088 /*!
2089 Platform-independent GTK clipboard support.
2090 \todo Using GDK_SELECTION_CLIPBOARD fails on win32, so we use the win32 API directly for now.
2091 */
2092 #if defined (__linux__) || defined (__APPLE__)
2093
2094 enum
2095 {
2096   RADIANT_CLIPPINGS = 23,
2097 };
2098
2099 static const GtkTargetEntry clipboard_targets[] = {
2100   { "RADIANT_CLIPPINGS", 0, RADIANT_CLIPPINGS, },
2101 };
2102
2103 static void clipboard_get (GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, gpointer user_data_or_owner)
2104 {
2105   guchar *buffer;
2106   gint len;
2107   GdkAtom type = GDK_NONE;
2108
2109   len = g_Clipboard.GetLength();
2110
2111   if (!len)
2112   {
2113     buffer = NULL;
2114   } else
2115   {
2116     buffer = g_Clipboard.GetBuffer ();
2117   }
2118
2119   if(info == clipboard_targets[0].info)
2120   {
2121     type = gdk_atom_intern(clipboard_targets[0].target, FALSE);
2122   }
2123
2124   gtk_selection_data_set (selection_data, type, 8, buffer, len);
2125 }
2126
2127 static void clipboard_clear (GtkClipboard *clipboard, gpointer user_data_or_owner)
2128 {
2129 }
2130
2131 static void clipboard_received (GtkClipboard *clipboard, GtkSelectionData *data, gpointer user_data)
2132 {
2133   g_Clipboard.SetLength (0);
2134
2135   if (data->length < 0)
2136     Sys_FPrintf(SYS_ERR, "Error retrieving selection\n");
2137   else if(strcmp(gdk_atom_name(data->type), clipboard_targets[0].target) == 0)
2138     g_Clipboard.Write (data->data, data->length);
2139
2140   Clipboard_PasteMap();
2141 }
2142
2143 void clipboard_copy()
2144 {
2145   Clipboard_CopyMap();
2146
2147   GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
2148
2149   gtk_clipboard_set_with_data (clipboard, clipboard_targets, 1, clipboard_get, clipboard_clear, NULL);
2150 }
2151
2152 void clipboard_paste()
2153 {
2154   GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
2155
2156   gtk_clipboard_request_contents (clipboard, gdk_atom_intern(clipboard_targets[0].target, FALSE), clipboard_received, NULL);
2157 }
2158
2159
2160 #elif defined(WIN32)
2161
2162 void clipboard_copy()
2163 {
2164   Clipboard_CopyMap();
2165
2166   bool bClipped = false;
2167   UINT nClipboard = ::RegisterClipboardFormat("RadiantClippings");
2168   if (nClipboard > 0)
2169   {
2170     if (::OpenClipboard(NULL))
2171     {
2172       EmptyClipboard();
2173                 long lSize = g_Clipboard.GetLength();
2174       HANDLE h = ::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, lSize + sizeof(long));
2175       if (h != NULL)
2176       {
2177         unsigned char *cp = reinterpret_cast<unsigned char*>(::GlobalLock(h));
2178                                 memcpy(cp, &lSize, sizeof(long));
2179                                 cp += sizeof(long);
2180         g_Clipboard.Seek(0, SEEK_SET);
2181         g_Clipboard.Read(cp, lSize);
2182         ::GlobalUnlock(h);
2183         ::SetClipboardData(nClipboard, h);
2184         ::CloseClipboard();
2185         bClipped = true;
2186       }
2187     }
2188   }
2189
2190   if (!bClipped)
2191   {
2192     Sys_Printf("Unable to register Windows clipboard formats, copy/paste between editors will not be possible\n");
2193   }
2194 }
2195
2196 void clipboard_paste()
2197 {
2198   bool bPasted = false;
2199   UINT nClipboard = ::RegisterClipboardFormat("RadiantClippings");
2200   if (nClipboard > 0 && ::OpenClipboard(NULL))
2201   {
2202     if(IsClipboardFormatAvailable(nClipboard))
2203     {
2204       HANDLE h = ::GetClipboardData(nClipboard);
2205       if (h)
2206       {
2207         g_Clipboard.SetLength(0);
2208                           unsigned char *cp = reinterpret_cast<unsigned char*>(::GlobalLock(h));
2209                           long lSize = 0;
2210                           memcpy(&lSize, cp, sizeof(long));
2211                           cp += sizeof(long);
2212         g_Clipboard.Write(cp, lSize);
2213         ::GlobalUnlock(h);
2214       }
2215     }
2216     ::CloseClipboard();
2217   }
2218
2219   Clipboard_PasteMap();
2220 }
2221
2222 #endif
2223
2224 void MainFrame::Copy()
2225 {
2226   clipboard_copy();
2227 }
2228
2229 void MainFrame::Paste()
2230 {
2231   clipboard_paste();
2232   UpdateSurfaceDialog();
2233 }
2234
2235
2236 #ifdef DBG_WINDOWPOS
2237 GtkWidget *watchit = NULL;
2238
2239 void CheckWatchit(char *msg)
2240 {
2241   static int width = 0;
2242