| 1 |
/* |
| 2 |
* AiksaurusGTK - A GTK interface to the Aiksaurus library |
| 3 |
* Copyright (C) 2001 by Jared Davis |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License |
| 7 |
* as published by the Free Software Foundation; either version 2 |
| 8 |
* of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 18 |
* 02111-1307, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "Replacebar.h" |
| 22 |
#include "DialogMediator.h" |
| 23 |
#include <gdk/gdkkeysyms.h> |
| 24 |
|
| 25 |
namespace AiksaurusGTK_impl |
| 26 |
{ |
| 27 |
|
| 28 |
Replacebar::Replacebar(DialogMediator& mediator) throw() |
| 29 |
: d_mediator(mediator) |
| 30 |
{ |
| 31 |
// Build GUI widgets. |
| 32 |
d_replacebar_ptr = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); |
| 33 |
d_replacewith_label_ptr = gtk_label_new(" Replace with:"); |
| 34 |
d_replacewith_ptr = gtk_entry_new(); |
| 35 |
d_replacebutton_hold_ptr = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); |
| 36 |
d_replacebutton_ptr = gtk_button_new_with_label(" Replace "); |
| 37 |
d_cancelbutton_ptr = gtk_button_new_with_label("Cancel"); |
| 38 |
|
| 39 |
// Add them to the main hbox. |
| 40 |
gtk_box_pack_start(GTK_BOX(d_replacebar_ptr), d_replacewith_label_ptr, 0, 0, 0); |
| 41 |
gtk_box_pack_start(GTK_BOX(d_replacebar_ptr), d_replacewith_ptr, 0, 0, 2); |
| 42 |
gtk_box_pack_end(GTK_BOX(d_replacebar_ptr), d_replacebutton_hold_ptr, 0, 0, 5); |
| 43 |
gtk_box_pack_start(GTK_BOX(d_replacebutton_hold_ptr), d_replacebutton_ptr, 0, 0, 0); |
| 44 |
gtk_box_pack_start(GTK_BOX(d_replacebutton_hold_ptr), d_cancelbutton_ptr, 1, 1, 0); |
| 45 |
|
| 46 |
// Connect relevant signals. |
| 47 |
g_signal_connect( |
| 48 |
G_OBJECT(d_replacewith_ptr), "key-press-event", |
| 49 |
G_CALLBACK(_keyPressed), this |
| 50 |
); |
| 51 |
g_signal_connect( |
| 52 |
G_OBJECT(d_replacebutton_ptr), "clicked", |
| 53 |
G_CALLBACK(_replaceClicked), this |
| 54 |
); |
| 55 |
g_signal_connect( |
| 56 |
G_OBJECT(d_cancelbutton_ptr), "clicked", |
| 57 |
G_CALLBACK(_cancelClicked), this |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
Replacebar::~Replacebar() throw() |
| 63 |
{ |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
void Replacebar::_cancelClicked(GtkWidget*, gpointer data) |
| 68 |
{ |
| 69 |
Replacebar* rb = static_cast<Replacebar*>(data); |
| 70 |
rb->d_mediator.eventCancel(); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
void Replacebar::_replaceClicked(GtkWidget*, gpointer data) |
| 75 |
{ |
| 76 |
Replacebar* rb = static_cast<Replacebar*>(data); |
| 77 |
rb->d_mediator.eventReplace( rb->getText() ); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
void Replacebar::_keyPressed(GtkWidget* w, GdkEventKey* k, gpointer data) |
| 82 |
{ |
| 83 |
if (k->keyval == GDK_KEY_Return) |
| 84 |
_replaceClicked(w, data); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
GtkWidget* Replacebar::getReplacebar() throw() |
| 89 |
{ |
| 90 |
return d_replacebar_ptr; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
const char* Replacebar::getText() const throw() |
| 95 |
{ |
| 96 |
return gtk_entry_get_text(GTK_ENTRY(d_replacewith_ptr)); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
void Replacebar::setText(const char* word) throw() |
| 101 |
{ |
| 102 |
gtk_entry_set_text(GTK_ENTRY(d_replacewith_ptr), word); |
| 103 |
} |
| 104 |
|
| 105 |
} |