Hi,

I'm in the process of writing the gtk+ search/replace dialog, and have
hit a problem which has frustrated me for some hours.  I'm not too
experienced with C++ (as opposed to C), so forgive me if I'm missing
something obvious.

typeid is reporting the return type of bcview() in GSearch to be
N3lyx8frontend8xformsBCE, which I assume is the name-mangled version of
something related to xforms.  However, a similar test in GMathPanel
gives N3lyx8frontend3GBCE which is more correct (GBC being the Gtk-ified
GuiBC).

This is causing segfaults along the lines of:
#0  0x4096e206 in fl_activate_composite () from
/usr/X11R6/lib/libforms.so.1
#1  0x4099a09c in fl_activate_object () from
/usr/X11R6/lib/libforms.so.1
#2  0x082ab012 in lyx::frontend::setEnabled (ob=0x8714758)
    at xforms_helpers.C:99
#3  0x082aa4db in lyx::frontend::xformsBC::setWidgetEnabled
(this=0x86e3c80,
    obj=0x29) at xformsBC.C:40
#4  0x082aab3b in lyx::frontend::GuiBC<flobjs_,
flobjs_>::refreshReadOnly (
    this=0x86e3c80) at stl_list.h:167
#5  0x08301409 in lyx::frontend::ButtonController::readOnly
(this=0x86f1298,
    ro=false) at ButtonController.C:113
#6  0x082f5a84 in lyx::frontend::Dialog::show (this=0x86dd818,
    [EMAIL PROTECTED]) at Dialog.h:82

So it's segfaulting because it's trying to feed xforms my gtk+ objects. 
GSearch code attached, which doesn't even mention any xforms stuff
whatever.  

For contrast (or lack thereof) my class is:
class GSearch : public GViewCB<ControlSearch, GViewGladeB>

Where the (working) MathPanel is:
class GMathPanel : public GViewCB<ControlMath, GViewGladeB>

I just can't find what I'm doing differently to cause this problem.

Any hints appreciated.

John
/**
 * \file GSearch.C
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author John Spray
 *
 * Full author contact details are available in file CREDITS.
 */

#include <config.h>
#include <gtkmm.h>

#include "GSearch.h"
#include "ControlSearch.h"
#include "ghelpers.h"
#include <libglademm.h>

#include <iostream>

using std::string;

namespace lyx {
namespace frontend {

typedef GViewCB<ControlSearch, GViewGladeB> base_class;

GSearch::GSearch(Dialog & parent)
	: base_class(parent, _("Find and Replace"), false)
{}


void GSearch::doBuild()
{
	std::cout << "bcview() has type:" << typeid(bcview()).name() << "\n";
	
	string const gladeName = findGladeFile("search");
	xml_ = Gnome::Glade::Xml::create(gladeName);
	Gtk::Button * button;
	Gtk::Entry * entry;

	xml_->get_widget("Cancel", button);
	if (button)
		setCancel(button);

	xml_->get_widget("FindNext", button);
	button->signal_clicked().connect(
		SigC::slot(*this, &GSearch::onFindNext));
	xml_->get_widget("Replace", button);
	button->signal_clicked().connect(
		SigC::slot(*this, &GSearch::onReplace));
	xml_->get_widget("ReplaceAll", button);
	button->signal_clicked().connect(
		SigC::slot(*this, &GSearch::onReplaceAll));		
	
	xml_->get_widget("FindEntry", findentry);
	xml_->get_widget("ReplaceEntry", replaceentry);
	xml_->get_widget("CaseSensitive", casecheck);
	xml_->get_widget("MatchWord", matchwordcheck);
	xml_->get_widget("SearchBackwards", backwardscheck);

	// disable for read-only documents
	xml_->get_widget("ReplaceEntry", entry);
	std::cout << entry << "\n";
	bcview().addReadOnly(entry);
	xml_->get_widget("Replace", button);
	std::cout << button << "\n";
	bcview().addReadOnly(button);
	xml_->get_widget("ReplaceAll", button);
	std::cout << button << "\n";
	bcview().addReadOnly(button);
}


void GSearch::update()
{
	//fl_set_input_selected(dialog_->input_search, true);
	findentry->grab_focus();
}
	
void GSearch::onFindNext()
{
	controller().find(findentry->get_text(),
	                  casecheck->get_active(),
	                  matchwordcheck->get_active(),
	                  !backwardscheck->get_active());
}

void GSearch::onReplace()
{
	controller().replace(findentry->get_text(),
	                     replaceentry->get_text(),
	                     casecheck->get_active(),
	                     matchwordcheck->get_active(),
	                     !backwardscheck->get_active(),
	                     false);			     
}

void GSearch::onReplaceAll()
{
	controller().replace(findentry->get_text(),
	                     replaceentry->get_text(),
	                     casecheck->get_active(),
	                     matchwordcheck->get_active(),
	                     !backwardscheck->get_active(),
	                     true);			     
}

} // namespace frontend
} // namespace lyx
// -*- C++ -*-
/**
 * \file GSearch.h
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author John Spray
 * (based on Edwin Leuven's xforms frontend)
 *
 * Full author contact details are available in file CREDITS.
 */

#ifndef GSEARCH_H
#define GSEARCH_H

#include "GViewBase.h"

namespace lyx {
namespace frontend {

class ControlSearch;

/** This class provides a GTK+ implementation of the FormSearch Dialog.
 */
class GSearch : public GViewCB<ControlSearch, GViewGladeB>
{
public:
	GSearch(Dialog & parent);
private:
	virtual void apply() {}
	virtual void doBuild();
	virtual void update();
	
	void onFindNext();
	void onReplace();
	void onReplaceAll();		
	
	Gtk::Entry * findentry;
	Gtk::Entry * replaceentry;
	Gtk::CheckButton * casecheck;
	Gtk::CheckButton * matchwordcheck;
	Gtk::CheckButton * backwardscheck;		
};

} // namespace frontend
} // namespace lyx

#endif // GSEARCH_H

Reply via email to