using dia-manual.chm instead of dia.chm
[dia.git] / app / tool.c
blobc91b29dee669980de0339b4401a0c43975a6f13a
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #include <config.h>
20 #include "tool.h"
21 #include "create_object.h"
22 #include "magnify.h"
23 #include "modify_tool.h"
24 #include "scroll_tool.h"
25 #include "interface.h"
26 #include "defaults.h"
28 Tool *active_tool = NULL;
29 Tool *transient_tool = NULL;
30 static GtkWidget *active_button = NULL;
31 static GtkWidget *former_button = NULL;
33 void
34 tool_select_former(void)
36 if (former_button) {
37 gtk_signal_emit_by_name(GTK_OBJECT(former_button), "clicked",
38 GTK_BUTTON(former_button), NULL);
42 void
43 tool_reset(void)
45 gtk_signal_emit_by_name(GTK_OBJECT(modify_tool_button), "clicked",
46 GTK_BUTTON(modify_tool_button), NULL);
49 void
50 tool_get(ToolState *state)
52 state->type = active_tool->type;
53 state->button = active_button;
54 if (state->type == CREATE_OBJECT_TOOL) {
55 state->user_data = ((CreateObjectTool *)active_tool)->user_data;
56 state->extra_data = ((CreateObjectTool *)active_tool)->objtype->name;
57 state->invert_persistence = ((CreateObjectTool *)active_tool)->invert_persistence;
59 else
61 state->user_data = NULL;
62 state->extra_data = NULL;
63 state->invert_persistence = 0;
67 void
68 tool_restore(const ToolState *state)
70 tool_select(state->type, state->extra_data, state->user_data, state->button,
71 state->invert_persistence);
74 void
75 tool_free(Tool *tool)
77 switch(tool->type) {
78 case MODIFY_TOOL:
79 free_modify_tool(tool);
80 break;
81 case CREATE_OBJECT_TOOL:
82 free_create_object_tool(tool);
83 break;
84 case MAGNIFY_TOOL:
85 free_magnify_tool(tool);
86 break;
87 case SCROLL_TOOL:
88 free_scroll_tool(tool);
89 break;
90 default:
91 g_assert(0);
95 void
96 tool_select(ToolType type, gpointer extra_data,
97 gpointer user_data, GtkWidget *button,
98 int invert_persistence)
100 if (button)
101 former_button = active_button;
103 tool_free(active_tool);
104 switch(type) {
105 case MODIFY_TOOL:
106 active_tool = create_modify_tool();
107 break;
108 case CREATE_OBJECT_TOOL:
109 active_tool =
110 create_create_object_tool(object_get_type((char *)extra_data),
111 (void *) user_data, invert_persistence);
112 break;
113 case MAGNIFY_TOOL:
114 active_tool = create_magnify_tool();
115 break;
116 case SCROLL_TOOL:
117 active_tool = create_scroll_tool();
118 break;
119 default:
120 g_assert(0);
122 if (button)
123 active_button = button;
126 void
127 tool_options_dialog_show(ToolType type, gpointer extra_data,
128 gpointer user_data, GtkWidget *button,
129 int invert_persistence)
131 ObjectType *objtype;
133 if (active_tool->type != type)
134 tool_select(type,extra_data,user_data,button,invert_persistence);
136 switch(type) {
137 case MODIFY_TOOL:
138 break;
139 case CREATE_OBJECT_TOOL:
140 objtype = object_get_type((char *)extra_data);
141 defaults_show(objtype);
142 break;
143 case MAGNIFY_TOOL:
144 break;
145 case SCROLL_TOOL:
146 break;