~ubuntu-branches/ubuntu/vivid/winefish/vivid

« back to all changes in this revision

Viewing changes to src/html_diag.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Leidert (dale)
  • Date: 2006-04-14 14:41:11 UTC
  • Revision ID: james.westby@ubuntu.com-20060414144111-wi90w6pr70ifwxtw
Tags: upstream-1.3.3
ImportĀ upstreamĀ versionĀ 1.3.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: html_diag.c 1712 2006-01-28 09:59:34Z kyanh $ */
 
2
/* Winefish LaTeX Editor (based on Bluefish HTML Editor)
 
3
 * html_diag.c - general functions to create HTML dialogs
 
4
 *
 
5
 * Copyright (C) 2000-2002 Olivier Sessink
 
6
 * Modified for Winefish (C) 2005 Ky Anh <kyanh@o2.pl> 
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 */
 
22
 
 
23
#include <gtk/gtk.h>
 
24
#include <string.h>     /* strrchr */
 
25
#include <stdlib.h> /* strtod */
 
26
/* #define DEBUG */
 
27
 
 
28
#include "bluefish.h"
 
29
#include "html_diag.h" /* myself */
 
30
#include "gtk_easy.h" /* window_full() */
 
31
#include "bf_lib.h"
 
32
#include "stringlist.h" /* add_to_stringlist */
 
33
#include "document.h" /* doc_save_selection */
 
34
 
 
35
/* kyanh, removed, 20050225
 
36
Trecent_attribs recent_attribs;
 
37
*/
 
38
 
 
39
/*****************************************/
 
40
/********** DIALOG FUNCTIONS *************/
 
41
/*****************************************/
 
42
 
 
43
void html_diag_destroy_cb(GtkWidget * widget, Thtml_diag *dg) {
 
44
        /* kyanh, removed, 20050225,
 
45
        dg->tobedestroyed = TRUE; */
 
46
        if (dg->mark_ins) {
 
47
                gtk_text_buffer_delete_mark(dg->doc->buffer,dg->mark_ins);
 
48
        }
 
49
        if (dg->mark_sel) {
 
50
                gtk_text_buffer_delete_mark(dg->doc->buffer,dg->mark_sel);
 
51
        }
 
52
        window_destroy(dg->dialog); /* kyanh, from: gtk_easy.h */
 
53
        DEBUG_MSG("html_diag_destroy_cb, about to free dg=%p\n",dg);
 
54
        g_free(dg);
 
55
}
 
56
 
 
57
void html_diag_cancel_clicked_cb(GtkWidget *widget, gpointer data) {
 
58
        html_diag_destroy_cb(NULL, data);
 
59
}
 
60
 
 
61
Thtml_diag *html_diag_new(Tbfwin *bfwin, gchar *title) {
 
62
        Thtml_diag *dg;
 
63
        
 
64
        dg = g_malloc(sizeof(Thtml_diag));
 
65
        /* kyanh, removed, 20050225,
 
66
        dg->tobedestroyed = FALSE;
 
67
        */
 
68
        DEBUG_MSG("html_diag_new, dg=%p\n",dg);
 
69
        dg->dialog = window_full2(title, GTK_WIN_POS_MOUSE, 12,G_CALLBACK(html_diag_destroy_cb), dg, TRUE/* escape key close the winow */,  bfwin ? bfwin->main_window : NULL);
 
70
        gtk_window_set_type_hint(GTK_WINDOW(dg->dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
 
71
        gtk_window_set_role(GTK_WINDOW(dg->dialog), "html_dialog");
 
72
        dg->vbox = gtk_vbox_new(FALSE, 1);
 
73
        gtk_container_add(GTK_CONTAINER(dg->dialog), dg->vbox);
 
74
        {
 
75
                if (!gtk_text_buffer_get_mark(bfwin->current_document->buffer,"diag_ins")) {
 
76
                        GtkTextIter iter;
 
77
                        GtkTextMark* mark = gtk_text_buffer_get_mark(bfwin->current_document->buffer,"insert");
 
78
                        gtk_text_buffer_get_iter_at_mark(bfwin->current_document->buffer,&iter,mark);
 
79
                        dg->mark_ins = gtk_text_buffer_create_mark(bfwin->current_document->buffer,"diag_ins",&iter,TRUE);
 
80
                        mark = gtk_text_buffer_get_mark(bfwin->current_document->buffer,"selection_bound");
 
81
                        gtk_text_buffer_get_iter_at_mark(bfwin->current_document->buffer,&iter,mark);
 
82
                        dg->mark_sel = gtk_text_buffer_create_mark(bfwin->current_document->buffer,"diag_sel",&iter,TRUE);
 
83
                } else {
 
84
                        dg->mark_ins = dg->mark_sel = NULL;
 
85
                }
 
86
        }
 
87
/*      
 
88
        dg->range.pos = -1;
 
89
        dg->range.end = -1;
 
90
*/
 
91
 
 
92
        if (main_v->props.view_bars & MODE_MAKE_LATEX_TRANSIENT) {
 
93
                /* must be set before realizing */
 
94
                DEBUG_MSG("html_diag_finish, setting dg->dialog=%p transient!\n", dg->dialog);
 
95
                gtk_window_set_transient_for(GTK_WINDOW(dg->dialog), GTK_WINDOW(bfwin->main_window));
 
96
        }
 
97
        gtk_widget_realize(dg->dialog);
 
98
        dg->bfwin = bfwin;
 
99
        dg->doc = bfwin->current_document;
 
100
        return dg;
 
101
}
 
102
 
 
103
GtkWidget *html_diag_table_in_vbox(Thtml_diag *dg, gint rows, gint cols) {
 
104
        GtkWidget *returnwidget = gtk_table_new(rows, cols, FALSE);
 
105
        gtk_table_set_row_spacings(GTK_TABLE(returnwidget), 12);
 
106
        gtk_table_set_col_spacings(GTK_TABLE(returnwidget), 12);
 
107
        gtk_box_pack_start(GTK_BOX(dg->vbox), returnwidget, FALSE, FALSE, 0);
 
108
        return returnwidget;
 
109
}
 
110
 
 
111
void html_diag_finish(Thtml_diag *dg, GtkSignalFunc ok_func) {
 
112
        GtkWidget *hbox;
 
113
 
 
114
        gtk_box_pack_start(GTK_BOX(dg->vbox), gtk_hseparator_new(), FALSE, FALSE, 12);
 
115
        hbox = gtk_hbutton_box_new();
 
116
        gtk_hbutton_box_set_layout_default(GTK_BUTTONBOX_END);
 
117
        gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 12);
 
118
        
 
119
        dg->obut = bf_stock_ok_button(ok_func, dg);
 
120
        dg->cbut = bf_stock_cancel_button(G_CALLBACK(html_diag_cancel_clicked_cb), dg);
 
121
 
 
122
        gtk_box_pack_start(GTK_BOX(hbox),dg->cbut , FALSE, FALSE, 0);
 
123
        gtk_box_pack_start(GTK_BOX(hbox),dg->obut , FALSE, FALSE, 0);
 
124
        gtk_window_set_default(GTK_WINDOW(dg->dialog), dg->obut);
 
125
 
 
126
        gtk_box_pack_start(GTK_BOX(dg->vbox), hbox, FALSE, FALSE, 0);
 
127
        gtk_widget_show_all(GTK_WIDGET(dg->dialog));
 
128
}
 
129
 
 
130
/*************************************************/
 
131
/********** HTML -> DIALOG FUNCTIONS *************/
 
132
/*************************************************/
 
133
 
 
134
/* TODO: removed this function */
 
135
void fill_dialogvalues(gchar *dialogitems[], gchar *dialogvalues[], gchar **custom, Ttagpopup *data, Thtml_diag *diag) {
 
136
 
 
137
        gint count=0;
 
138
        
 
139
        while (dialogitems[count]) {
 
140
                dialogvalues[count] = NULL;
 
141
                count++;
 
142
        }
 
143
}
 
144
 
 
145
GList *add_entry_to_stringlist(GList *which_list, GtkWidget *entry) {
 
146
        if (entry) {
 
147
                gchar *temp = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
 
148
                which_list = add_to_stringlist(which_list, temp);
 
149
                g_free(temp);
 
150
        }
 
151
        return which_list;
 
152
}
 
153
 
 
154
/* END OF FILE */