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
|
//-----------------------------------------------------------------------------
// Copyright 2007 Jonathan Westhues
//
// This file is part of LDmicro.
//
// LDmicro 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 3 of the License, or
// (at your option) any later version.
//
// LDmicro 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 LDmicro. If not, see <http://www.gnu.org/licenses/>.
//------
//
// Dialog to enter the text of a comment; make it long and skinny to
// encourage people to write it the way it will look on the diagram.
// Jonathan Westhues, Jun 2005
//-----------------------------------------------------------------------------
#include <linuxUI.h>
#include <stdio.h>
//#include <commctrl.h>
#include "ldmicro.h"
static HWID CommentDialog;
static HWID CommentTextbox;
static HWID CommentGrid;
static HWID CommentPackingBox;
static HWID OkButton;
static HWID CancelButton;
static void MakeControls(void)
{
CommentTextbox = gtk_entry_new();
gtk_entry_set_max_length (GTK_ENTRY (CommentTextbox), 0);
gtk_widget_set_hexpand (CommentTextbox, TRUE);
gtk_widget_set_vexpand (CommentTextbox, TRUE);
OkButton = gtk_button_new_with_label ("OK");
CancelButton = gtk_button_new_with_label ("Cancel");
gtk_grid_attach (GTK_GRID (CommentGrid), CommentTextbox, 1, 2, 1, 1);
gtk_grid_attach (GTK_GRID (CommentGrid), OkButton, 5, 2, 1, 1);
gtk_grid_attach (GTK_GRID (CommentGrid), CancelButton, 5, 3, 1, 1);
gtk_grid_set_column_spacing (GTK_GRID (CommentGrid), 1);
gtk_box_pack_start(GTK_BOX(CommentPackingBox), CommentGrid, TRUE, TRUE, 0);
}
void CommentDialogGetData (char* comment){
strncpy (comment, gtk_entry_get_text (GTK_ENTRY (CommentTextbox)),
MAX_COMMENT_LEN-1);
gtk_widget_set_sensitive (MainWindow, TRUE);
DestroyWindow (CommentDialog);
}
// Mouse click callback
void CommentDialogMouseClick (HWID widget, gpointer data){
CommentDialogGetData((char*)data);
}
// Checks for the required key press
gboolean CommentDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data){
if (event -> keyval == GDK_KEY_Return){
CommentDialogGetData((char*)data);
}
else if (event -> keyval == GDK_KEY_Escape){
DestroyWindow (CommentDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
return FALSE;
}
void CommentCallDestroyWindow (HWID widget, gpointer data){
DestroyWindow (CommentDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
void ShowCommentDialog(char *comment)
{
CommentGrid = gtk_grid_new();
CommentPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
CommentDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(CommentDialog), "Comment");
gtk_window_set_default_size(GTK_WINDOW(CommentDialog), 700, 50);
gtk_window_set_resizable (GTK_WINDOW (CommentDialog), FALSE);
gtk_widget_add_events (CommentDialog, GDK_KEY_PRESS_MASK);
gtk_widget_add_events (CommentDialog, GDK_BUTTON_PRESS_MASK);
MakeControls();
gtk_entry_set_text (GTK_ENTRY (CommentTextbox), comment);
gtk_container_add(GTK_CONTAINER(CommentDialog), CommentPackingBox);
gtk_widget_set_sensitive (MainWindow, FALSE);
gtk_widget_show_all (CommentDialog);
gtk_widget_grab_focus (CommentTextbox);
g_signal_connect (G_OBJECT (CommentDialog), "key-press-event",
G_CALLBACK(CommentDialogKeyPress), (gpointer)comment);
g_signal_connect (G_OBJECT (OkButton), "clicked",
G_CALLBACK(CommentDialogMouseClick), (gpointer)comment);
g_signal_connect (G_OBJECT (CancelButton), "clicked",
G_CALLBACK(CommentCallDestroyWindow), NULL);
return;
}
|