]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
8edfe11e16393a29c99b9f17771ddcf84169da35
[lyx.git] / src / frontends / xforms / FormUrl.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #include FORMS_H_LOCATION
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20
21 #include "gettext.h"
22 #include "Dialogs.h"
23 #include "FormUrl.h"
24 #include "LyXView.h"
25 #include "buffer.h"
26 #include "form_url.h"
27 #include "lyxfunc.h"
28
29 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
30         : FormCommand(lv, d, _("Url")), dialog_(0)
31 {
32         // let the dialog be shown
33         // These are permanent connections so we won't bother
34         // storing a copy because we won't be disconnecting.
35         d->showUrl.connect(slot(this, &FormUrl::showInset));
36         d->createUrl.connect(slot(this, &FormUrl::createInset));
37 }
38
39
40 FormUrl::~FormUrl()
41 {
42         free();
43         delete dialog_;
44 }
45
46
47 void FormUrl::build()
48 {
49         dialog_ = build_url();
50
51         int w = form()->w;
52         int h = form()->h;
53
54         fl_set_form_minsize(form(), w,   h);
55         fl_set_form_maxsize(form(), 2*w, h);
56 }
57
58
59 FL_FORM * const FormUrl::form() const
60 {
61         if( dialog_ ) // no need to test for dialog_->form_url
62                 return dialog_->form_url;
63         else
64                 return 0;
65 }
66
67
68 void FormUrl::update()
69 {
70         fl_set_input(dialog_->url,  params.getContents().c_str());
71         fl_set_input(dialog_->name, params.getOptions().c_str());
72
73         if ( params.getCmdName() == "url" )
74                 fl_set_button(dialog_->radio_html, 0);
75         else
76                 fl_set_button(dialog_->radio_html, 1);
77
78         if( lv_->buffer()->isReadonly() ) {
79                 fl_deactivate_object( dialog_->url );
80                 fl_deactivate_object( dialog_->name );
81                 fl_deactivate_object( dialog_->radio_html );
82                 fl_deactivate_object( dialog_->ok );
83                 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
84         } else {
85                 fl_activate_object( dialog_->url );
86                 fl_activate_object( dialog_->name );
87                 fl_activate_object( dialog_->radio_html );
88                 fl_activate_object( dialog_->ok );
89                 fl_set_object_lcol( dialog_->ok, FL_BLACK );
90         }
91 }
92
93
94 void FormUrl::apply()
95 {
96         if( lv_->buffer()->isReadonly() ) return;
97
98         params.setContents( fl_get_input(dialog_->url) );
99         params.setOptions( fl_get_input(dialog_->name) );
100
101         if (fl_get_button(dialog_->radio_html))
102                 params.setCmdName("htmlurl");
103         else
104                 params.setCmdName("url");
105
106         if( inset_ != 0 )
107         {
108                 // Only update if contents have changed
109                 if( params != inset_->params() ) {
110                         inset_->setParams( params );
111                         lv_->view()->updateInset( inset_, true );
112                 }
113         } else {
114                 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
115                                              params.getAsString().c_str() );
116         }
117 }