File: tool.c

package info (click to toggle)
dia 0.98%2Bgit20250126-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 52,072 kB
  • sloc: ansic: 155,381; xml: 14,056; python: 6,250; cpp: 3,598; sh: 439; perl: 137; makefile: 25
file content (173 lines) | stat: -rw-r--r-- 4,336 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Dia -- an diagram creation/manipulation program
 * Copyright (C) 1998 Alexander Larsson
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

#include <glib/gi18n-lib.h>

#include "tool.h"
#include "create_object.h"
#include "magnify.h"
#include "modify_tool.h"
#include "scroll_tool.h"
#include "textedit_tool.h"
#include "interface.h"
#include "defaults.h"
#include "object.h"
#include "dia-guide-tool.h"

Tool *active_tool = NULL;
Tool *transient_tool = NULL;
static GtkWidget *active_button = NULL;
static GtkWidget *former_button = NULL;

void
tool_select_former(void)
{
  if (former_button) {
    g_signal_emit_by_name(G_OBJECT(former_button), "clicked",
                          GTK_BUTTON(former_button), NULL);
  }
}

void
tool_reset(void)
{
  g_signal_emit_by_name(G_OBJECT(modify_tool_button), "clicked",
			GTK_BUTTON(modify_tool_button), NULL);
}

void
tool_get(ToolState *state)
{
  state->type = active_tool->type;
  state->button = active_button;
  if (state->type == CREATE_OBJECT_TOOL) {
    state->user_data = ((CreateObjectTool *)active_tool)->user_data;
    state->extra_data = ((CreateObjectTool *)active_tool)->objtype->name;
    state->invert_persistence = ((CreateObjectTool *)active_tool)->invert_persistence;
  }
  else
  {
    state->user_data = NULL;
    state->extra_data = NULL;
    state->invert_persistence = 0;
  }
}

void
tool_restore(const ToolState *state)
{
  tool_select(state->type, state->extra_data, state->user_data, state->button,
              state->invert_persistence);
}

void
tool_free(Tool *tool)
{
  switch(tool->type) {
  case MODIFY_TOOL:
    free_modify_tool(tool);
    break;
  case CREATE_OBJECT_TOOL:
    free_create_object_tool(tool);
    break;
  case MAGNIFY_TOOL:
    free_magnify_tool(tool);
    break;
  case SCROLL_TOOL:
    free_scroll_tool(tool);
    break;
  case TEXTEDIT_TOOL :
    free_textedit_tool(tool);
    break;
  case GUIDE_TOOL:
    free_guide_tool(tool);
    break;
  default:
    g_assert(0);
  }
}

void
tool_select(ToolType type, gpointer extra_data,
            gpointer user_data, GtkWidget *button,
            int invert_persistence)
{
  if (button)
    former_button = active_button;

  tool_free(active_tool);
  switch(type) {
  case MODIFY_TOOL:
    active_tool = create_modify_tool();
    break;
  case CREATE_OBJECT_TOOL:
    active_tool =
      create_create_object_tool(object_get_type((char *)extra_data),
				(void *) user_data, invert_persistence);
    break;
  case MAGNIFY_TOOL:
    active_tool = create_magnify_tool();
    break;
  case SCROLL_TOOL:
    active_tool = create_scroll_tool();
    break;
  case TEXTEDIT_TOOL :
    active_tool = create_textedit_tool();
    break;
  case GUIDE_TOOL :
    active_tool = create_guide_tool ();
    guide_tool_set_guide (active_tool, extra_data);
    guide_tool_set_orientation (active_tool, GPOINTER_TO_INT(user_data));
    break;
  default:
    g_assert(0);
  }
  if (button)
    active_button = button;
}


void
tool_options_dialog_show (ToolType   type,
                          gpointer   extra_data,
                          gpointer   user_data,
                          GtkWidget *button,
                          int        invert_persistence)
{
  DiaObjectType *objtype;

  if (active_tool->type != type) {
    tool_select (type, extra_data, user_data, button, invert_persistence);
  }

  switch (type) {
    case CREATE_OBJECT_TOOL:
      objtype = object_get_type ((char *) extra_data);
      defaults_show (objtype, user_data);
      break;
    case MODIFY_TOOL:
    case MAGNIFY_TOOL:
    case SCROLL_TOOL:
    case TEXTEDIT_TOOL:
    case GUIDE_TOOL:
    default:
      break;
  }
}