GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 23, 2014 2:25 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: problem in gtkmm
PostPosted: Tue Jan 17, 2012 9:02 pm 
Offline
GTK+ Geek

Joined: Sun Apr 03, 2011 11:12 am
Posts: 63
Hello Everyone, I am trying to create a gedit like program in C++ using gtkmm.
But, here I am facing two problems.
First One, whenever I click on File->New, then I get error Segmentation Fault.
Using GNU Debugger, I found error in Gtk::TextBuffer::set_text(Glib::ustring&).

Second One, I don't know how to connect the gtksourceview::SourceView signal_key_press_event
to a callback function. I have tried, but nothing happen.

Here's the code
proj.cpp
Code:
#include "proj.h"
#include <iostream>

main_window::main_window()
    : txtinputarray(20),
        scrollwinarray(20)
{
    Gtk::ScrolledWindow *scroll = new Gtk::ScrolledWindow;
    gtksourceview::SourceView *txt = new gtksourceview::SourceView;
    std::fill(scrollwinarray.begin(),scrollwinarray.end(),scroll);
    std::fill(txtinputarray.begin(),txtinputarray.end(),txt);
   
    set_title("IDE C#");
    set_default_size(600,400);
    set_border_width(5);
   
    lang_manager = gtksourceview::SourceLanguageManager::create();
    action_group = Gtk::ActionGroup::create();
    action_group->add(Gtk::Action::create("FileMenu","File"));
    action_group->add(Gtk::Action::create("FileNew",Gtk::Stock::NEW),sigc::mem_fun(*this,&main_window::filenew_activated));
    action_group->add(Gtk::Action::create("FileNewTab",Gtk::Stock::SAVE_AS),sigc::mem_fun(*this,&main_window::filenewtab_activated));
    action_group->add(Gtk::Action::create("FileOpen",Gtk::Stock::OPEN),sigc::mem_fun(*this,&main_window::fileopen_activated));
    action_group->add(Gtk::Action::create("FileSave",Gtk::Stock::SAVE),sigc::mem_fun(*this,&main_window::filesave_activated));
    action_group->add(Gtk::Action::create("FileSaveAs",Gtk::Stock::SAVE_AS),sigc::mem_fun(*this,&main_window::filesaveas_activated));
    action_group->add(Gtk::Action::create("FileSaveAll","Save All",""),sigc::mem_fun(*this,&main_window::filesaveall_activated));
    action_group->add(Gtk::Action::create("FileSaveAllAs","Save All As",""),sigc::mem_fun(*this,&main_window::filesaveallas_activated));
    action_group->add(Gtk::Action::create("FileSaveCopyAs","Save Copy As",""),sigc::mem_fun(*this,&main_window::filesavecopyas_activated));
    action_group->add(Gtk::Action::create("FileRemoveTab","Remove Current Tab",""),sigc::mem_fun(*this,&main_window::fileremovetab_activated));
    action_group->add(Gtk::Action::create("FileQuit",Gtk::Stock::QUIT),sigc::mem_fun(*this,&main_window::filequit_activated));
   
    action_group->add(Gtk::Action::create("EditMenu","Edit"));
    action_group->add(Gtk::Action::create("EditUndo",Gtk::Stock::UNDO),sigc::mem_fun(*this,&main_window::editundo_activated));
    action_group->add(Gtk::Action::create("EditRedo",Gtk::Stock::REDO),sigc::mem_fun(*this,&main_window::editredo_activated));
    action_group->add(Gtk::Action::create("EditCopy",Gtk::Stock::COPY),sigc::mem_fun(*this,&main_window::editcopy_activated));
    action_group->add(Gtk::Action::create("EditCut",Gtk::Stock::CUT),sigc::mem_fun(*this,&main_window::editcut_activated));
    action_group->add(Gtk::Action::create("EditPaste",Gtk::Stock::PASTE),sigc::mem_fun(*this,&main_window::editpaste_activated));
    action_group->add(Gtk::Action::create("EditSelectAll","Select All",""),sigc::mem_fun(*this,&main_window::editselectall_activated));
    action_group->add(Gtk::Action::create("EditGoToLine","Go To Line",""),sigc::mem_fun(*this,&main_window::editgotoline_activated));
    action_group->add(Gtk::Action::create("EditFind",Gtk::Stock::FIND),sigc::mem_fun(*this,&main_window::editfind_activated));
    action_group->add(Gtk::Action::create("EditFindAndReplace",Gtk::Stock::FIND_AND_REPLACE),sigc::mem_fun(*this,&main_window::editfindandreplace_activated));
   
    action_group->add(Gtk::Action::create("FormatMenu","Format"));
    action_group->add(Gtk::Action::create("FormatIndent","Indent Region",""),sigc::mem_fun(*this,&main_window::formatindentregion_activated));
    action_group->add(Gtk::Action::create("FormatDedent","Dedent Region",""),sigc::mem_fun(*this,&main_window::formatdedentregion_activated));
    action_group->add(Gtk::Action::create("FormatComment","Comment Out Region",""),sigc::mem_fun(*this,&main_window::formatcommentout_activated));
    action_group->add(Gtk::Action::create("FormatUncomment","Uncomment Out Region",""),sigc::mem_fun(*this,&main_window::formatuncommentout_activated));
    action_group->add(Gtk::Action::create("FormatStripSpaces","Strip Trailing Spaces",""),sigc::mem_fun(*this,&main_window::formatstripspaces_activated));
   
    ui_manager = Gtk::UIManager::create();
    ui_manager->insert_action_group(action_group);
    Glib::ustring ui_info =
    "<ui>"
    "<menubar name = 'MenuBar'>"
    "<menu action = 'FileMenu'>"
    "<menuitem action = 'FileNew'/>"
    "<menuitem action = 'FileNewTab'/>"
    "<separator/>"
    "<menuitem action = 'FileOpen'/>"
    "<menuitem action = 'FileSave'/>"
    "<menuitem action = 'FileSaveAs'/>"
    "<menuitem action = 'FileSaveAll'/>"
    "<menuitem action = 'FileSaveAllAs'/>"
    "<menuitem action = 'FileSaveCopyAs'/>"
    "<separator/>"
    "<menuitem action = 'FileRemoveTab'/>"
    "<menuitem action = 'FileQuit'/>"     
    "</menu>"
    "<menu action = 'EditMenu'>"
    "<menuitem action = 'EditUndo'/>"
    "<menuitem action = 'EditRedo'/>"
    "<menuitem action = 'EditCopy'/>"
    "<menuitem action = 'EditCut'/>"
    "<menuitem action = 'EditPaste'/>"
    "<menuitem action = 'EditSelectAll'/>"
    "<separator/>"
    "<menuitem action = 'EditGoToLine'/>"
    "<menuitem action = 'EditFind'/>"
    "<menuitem action = 'EditFindAndReplace'/>"
    "</menu>"
    "<menu action = 'FormatMenu'>"
    "<menuitem action = 'FormatIndent'/>"
    "<menuitem action = 'FormatDedent'/>"
    "<menuitem action = 'FormatComment'/>"
    "<menuitem action = 'FormatUncomment'/>"
    "<menuitem action = 'FormatStripSpaces'/>"
    "</menu>"
    "</menubar>"
    "<toolbar name = 'ToolBar'>"
    "<toolitem action = 'FileNew'/>"
    "<toolitem action = 'FileOpen'/>"
    "<toolitem action = 'FileSave'/>"
    "<toolitem action = 'FileSaveAs'/>"
    "<separator/>"
    "<toolitem action = 'EditUndo'/>"
    "<toolitem action = 'EditRedo'/>"
    "<toolitem action = 'EditCopy'/>"
    "<toolitem action = 'EditCut'/>"
    "<toolitem action = 'EditPaste'/>"
    "<toolitem action = 'EditFind'/>"
    "<toolitem action = 'EditFindAndReplace'/>"
    "<separator/>"
    "</toolbar>"
    "</ui>";
    ui_manager->add_ui_from_string(ui_info);
    Gtk::Widget *menu_bar = ui_manager->get_widget("/MenuBar");
    if(menu_bar)
        vbox.pack_start(*menu_bar,Gtk::PACK_SHRINK);
    Gtk::Widget *toolbar = ui_manager->get_widget("/ToolBar");
    if(toolbar)
        vbox.pack_start(*toolbar,Gtk::PACK_SHRINK);
   
    txtinputarray[0]->signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_txtinput_key_press));
           
    scrollwinarray[0]->set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);
    scrollwinarray[0]->add(*txtinputarray[0]);
       
    notebook.append_page(*scrollwinarray[0],"New File");
    vbox.pack_start(notebook,Gtk::PACK_EXPAND_WIDGET);
    add(vbox);
    show_all_children();
    }

main_window::~main_window()
{
   
    }

bool main_window::on_txtinput_key_press(GdkEventKey *event)
{
    if (event->keyval == GDK_Return)
    {
        buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
        Gtk::TextBuffer::iterator current_iter;
        current_iter = buffer->get_iter_at_mark(buffer->get_insert());
        std::cout<<"gggg"<<std::endl;
       
    return false;
    }
void main_window::filenew_activated()
{
    buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
    notebook.set_tab_label_text(*scrollwinarray[notebook.get_current_page()],"New File");
    std::string str = "";
    buffer->set_text(str);
    //filepathsarray[notebook.get_current_page()] = "";   
    std::cout<<"gggg"<<std::endl;
    }

void main_window::filenewtab_activated()
{
    txtinputarray[notebook.get_n_pages()] = new gtksourceview::SourceView;
    scrollwinarray[notebook.get_n_pages()] = new Gtk::ScrolledWindow;
    scrollwinarray[notebook.get_n_pages()]->set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);
    scrollwinarray[notebook.get_n_pages()]->add(*txtinputarray[notebook.get_n_pages()]);
    filepathsarray[notebook.get_n_pages()] = "";
    notebook.append_page(*scrollwinarray[notebook.get_current_page()],"New File");
    }

void main_window::fileopen_activated()
{
    std::string filepath;
    int result;
   
    Gtk::FileChooserDialog dialog("Open File",Gtk::FILE_CHOOSER_ACTION_OPEN);
    dialog.add_button("Cancel",Gtk::RESPONSE_CANCEL);
    dialog.add_button("Open",Gtk::RESPONSE_OK);
    result = dialog.run();
    if(result == Gtk::RESPONSE_OK)
    {
        filepath = dialog.get_filename();
        buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
        buffer->set_text(Glib::file_get_contents(filepath));
        filepathsarray[notebook.get_current_page()] = filepath;
        buffer->set_highlight_syntax(true);
        Glib::RefPtr<gtksourceview::SourceLanguage> lang = lang_manager->guess_language(filepath,Glib::ustring());
        std::string filename;
        for(int i=filepath.rfind("/")+1;i<=filepath.size()-1;i++)
        {
            filename  = filename + filepath[i];
            }
        notebook.set_tab_label_text(*scrollwinarray[notebook.get_current_page()],filename);
        buffer->set_language(lang);
        }
    }

void main_window::filesave_activated()
{
    std::string filepath;
    int result;
   
    Gtk::FileChooserDialog dialog("Save File",Gtk::FILE_CHOOSER_ACTION_SAVE);
    dialog.add_button("Cancel",Gtk::RESPONSE_CANCEL);
    dialog.add_button("Save",Gtk::RESPONSE_OK);
    result = dialog.run();
   
    if(result == Gtk::RESPONSE_OK)
    {
        filepath = dialog.get_filename();
        buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
        Glib::file_set_contents(filepath,buffer->get_text());
        filepathsarray[notebook.get_current_page()] = filepath;
        buffer->set_highlight_syntax(true);
        Glib::RefPtr<gtksourceview::SourceLanguage> lang = lang_manager->guess_language(filepath,Glib::ustring());
        std::string filename;
        for(int i=filepath.rfind("/")+1;i<=filepath.size()-1;i++)
        {
            filename  = filename + filepath[i];
            }
        notebook.set_tab_label_text(*scrollwinarray[notebook.get_current_page()],filename);
        buffer->set_language(lang);
        }
    }

void main_window::filesaveas_activated()
{
    std::string filepath;
    int result;
   
    Gtk::FileChooserDialog dialog("Save As",Gtk::FILE_CHOOSER_ACTION_SAVE);
    dialog.add_button("Cancel",Gtk::RESPONSE_CANCEL);
    dialog.add_button("Save",Gtk::RESPONSE_OK);
    result = dialog.run();
    if(result == Gtk::RESPONSE_OK)
    {
        filepath = dialog.get_filename();
        buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
        Glib::file_set_contents(filepath,buffer->get_text());
        filepathsarray[notebook.get_current_page()] = filepath;
        buffer->set_highlight_syntax(true);
        Glib::RefPtr<gtksourceview::SourceLanguage> lang = lang_manager->guess_language(filepath,Glib::ustring());
        std::string filename;
        for(int i=filepath.rfind("/")+1;i<=filepath.size()-1;i++)
        {
            filename  = filename + filepath[i];
            }
        notebook.set_tab_label_text(*scrollwinarray[notebook.get_current_page()],filename);
        buffer->set_language(lang);
        }
    }

void main_window::filesaveall_activated()
{
    int current_page = notebook.get_current_page();
    for (int i =0; i<notebook.get_n_pages();i++)
    {
        notebook.set_current_page(i);
        filesave_activated();
        }
    notebook.set_current_page(current_page);
    }

void main_window::filesaveallas_activated()
{
    int current_page = notebook.get_current_page();
    for (int i =0; i<notebook.get_n_pages();i++)
    {
        notebook.set_current_page(i);
        filesaveas_activated();
        }
    notebook.set_current_page(current_page);
    }

void main_window::filesavecopyas_activated()
{
    std::string filepath;
    int result;
   
    Gtk::FileChooserDialog dialog("Save As",Gtk::FILE_CHOOSER_ACTION_SAVE);
    dialog.add_button("Cancel",Gtk::RESPONSE_CANCEL);
    dialog.add_button("Save",Gtk::RESPONSE_OK);
    result = dialog.run();
    if(result == Gtk::RESPONSE_OK)
    {
        filepath = dialog.get_filename();
        buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
        Glib::file_set_contents(filepath,buffer->get_text());
        }
    }

void main_window::fileremovetab_activated()
{
    int current_page = notebook.get_current_page();
    for(int i=current_page;i<notebook.get_n_pages();i++)
    {
        txtinputarray[i] = txtinputarray[i+1];
        scrollwinarray[i] = scrollwinarray[i+1];
        filepathsarray[i] = filepathsarray[i+1];
        }
    notebook.remove_page(notebook.get_current_page());
    }

void main_window::filequit_activated()
{
    destroy_();
    }

void main_window::editundo_activated()
{
    buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
    if (buffer->can_undo() == TRUE)
        buffer->undo();
    }

void main_window::editredo_activated()
{
    buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
    if (buffer->can_undo() == FALSE)
        buffer->redo();
    }

void main_window::editcopy_activated()
{
    const Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
    buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
    buffer->copy_clipboard(clipboard);
    }

void main_window::editcut_activated()
{
    const Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
    buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
    buffer->cut_clipboard(clipboard);
    }

void main_window::editpaste_activated()
{
    const Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
    buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
    buffer->paste_clipboard(clipboard);
    }

void main_window::editselectall_activated()
{
    Glib::RefPtr<Gtk::TextBuffer> txtbuffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
    Gtk::TextBuffer::iterator start_iter,end_iter;
    start_iter = buffer->begin();
    end_iter = buffer->end();
    txtbuffer->select_range(start_iter,end_iter);
    }

void main_window::editgotoline_activated()
{
   
    }
void main_window::editfind_activated(){}
void main_window::editfindandreplace_activated(){}

void main_window::formatindentregion_activated(){}
void main_window::formatcommentout_activated(){}
void main_window::formatdedentregion_activated(){}
void main_window::formatuncommentout_activated(){}
void main_window::formatstripspaces_activated(){}


proj.h
Code:
#include<gtkmm.h>
#include<gtksourceviewmm/sourcebuffer.h>
#include<gtksourceviewmm/sourceview.h>
#include<gtksourceviewmm/sourcelanguagemanager.h>
#include<vector>

template<class T>
class collection
{
    enum {size = 10};
    T C[size];
    public:
        T& operator[] (int index)
        {
            if (index>0 && index<10)
                return C[index];
            }
    };

class main_window : public Gtk::Window
{
    public:
        main_window();
        virtual ~main_window();
        bool on_txtinput_key_press(GdkEventKey *event);
       
    protected:
        virtual void filenew_activated();
        virtual void filenewtab_activated();
        virtual void fileopen_activated();
        virtual void filesave_activated();
        virtual void filesaveas_activated();
        virtual void filesaveall_activated();
        virtual void filesaveallas_activated();
        virtual void filesavecopyas_activated();
        virtual void fileremovetab_activated();
        virtual void filequit_activated();
       
        virtual void editundo_activated();
        virtual void editredo_activated();
        virtual void editcopy_activated();
        virtual void editcut_activated();
        virtual void editpaste_activated();
        virtual void editselectall_activated();
        virtual void editgotoline_activated();
        virtual void  editfind_activated();
        virtual void editfindandreplace_activated();
       
        virtual void formatindentregion_activated();
        virtual void formatdedentregion_activated();
        virtual void formatcommentout_activated();
        virtual void formatuncommentout_activated();
        virtual void formatstripspaces_activated();
       
        Gtk::VBox vbox;
        Gtk::Notebook notebook;
        Glib::RefPtr<Gtk::UIManager> ui_manager;
        Glib::RefPtr<Gtk::ActionGroup> action_group;
        std::vector<gtksourceview::SourceView *> txtinputarray;
        std::vector<Gtk::ScrolledWindow *> scrollwinarray;
        Glib::RefPtr<gtksourceview::SourceBuffer> buffer;
        Glib::RefPtr<gtksourceview::SourceLanguageManager> lang_manager;
        std::string filepathsarray[20];
    };


Code:
#include"proj.h"

int main(int argc,char *argv[])
{
    Gtk::Main kit(argc,argv);
   
    main_window main_win;
    Gtk::Main::run(main_win);
   
    return 0;
    }


Top
 Profile  
 
 Post subject: Re: problem in gtkmm
PostPosted: Wed Jan 18, 2012 1:08 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 747
Location: UK
Hi,

I shall start with the signal_key_press_event signal. This is a common problem, you need to enable which events are to be monitored by a widget by using the set_events(Gdk::EventsMask) method on the widget. This is often forgotten and blamed as a bug. See http://developer.gnome.org/gtkmm/unstable/classGtk_1_1Widget.html#adeb38a3d5988a0e31055bbd2edb2e954 in the documentation.

As for the rest of you code, you have serious problems with the basic structure. The major problem is that you have set a hard limit of 20 Notebook tabs, but as you have no bounds checking it is possible to access more than this causing memory access problems. For some odd reason you have set all 20 of your array of pointers to the same Notebook tab!

Note Glib does have functions to help with file names such as getting the base name, full path names etc. please use these instead of writing your own, it will make you code easier to read and much more portable.

C++ is very much an object orientated language, but you are making poor use of its features. You are using the object orientated features for GTKmm because you are forced to but for handling the array of notebook tabs you are doing this in a C way and in a way that is very error prone.

Think about using a class for each page which is derived from gtksourceview::SourveView and which can hold other information such as the full file name and other text editing information. And containing methods to "load", "save" and "save as" the page.

Have a separate class derived from Gtk::Notebook which also contains information to handle the array of tabs. This can include methods to "save all" and others that will be done to all pages. Avoid the use of index numbers to pages, but use pointers to the wigets instead. Indexes could fail if you delete or add a page to the notebook or if the pages get reordered. If you use a std::list you will avoid some of the memory copying that you have been doing and with care can have any number of pages depending on memory. You will lose some features compared to std::vector such as quick indexing, but that is a small trade off.

_________________
E.


Top
 Profile  
 
 Post subject: Re: problem in gtkmm
PostPosted: Wed Jan 18, 2012 5:31 pm 
Offline
GTK+ Geek

Joined: Sun Apr 03, 2011 11:12 am
Posts: 63
thx for reply errol, i have added the following line just above the line which connects signal_key_press_event
Code:
txtinputarray[0]->set_events(Gdk::KEY_PRESS_MASK)

but still nothing happening.


Top
 Profile  
 
 Post subject: Re: problem in gtkmm
PostPosted: Thu Jan 19, 2012 7:52 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 747
Location: UK
Maybe GtkSourceView has overridden that signal and chosen not to carry on the signal once it has done with its processing. So you will need to try and connect your signal handler before everybody else.

_________________
E.


Top
 Profile  
 
 Post subject: Re: problem in gtkmm
PostPosted: Thu Jan 19, 2012 6:03 pm 
Offline
GTK+ Geek

Joined: Sun Apr 03, 2011 11:12 am
Posts: 63
I have tried the following but still nothing happens

proj.cpp
Code:
main_window::main_window()
    : txtinputarray(20),
        scrollwinarray(20)
{
    Gtk::ScrolledWindow* scroll = new Gtk::ScrolledWindow;
    gtksourceview::SourceView* txt = new gtksourceview::SourceView;
    std::fill(scrollwinarray.begin(),scrollwinarray.begin()+1,scroll);
    std::fill(txtinputarray.begin(),txtinputarray.begin()+1,txt);
   
    txtinputarray[0]->set_events(Gdk::KEY_PRESS_MASK);
    txtinputarray[0]->signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_txtinput_key_press));   
   
    /**************Other code*****************/
   
    scrollwinarray[0]->set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);
    scrollwinarray[0]->add(*txtinputarray[0]);
       
    notebook.append_page(*scrollwinarray[0],"New File");
    vbox.pack_start(notebook,Gtk::PACK_EXPAND_WIDGET);
    add(vbox);
    show_all_children();
    }

main_window::~main_window(){}

bool main_window::on_txtinput_key_press(GdkEventKey *event)
{
    if (event->keyval == GDK_Return)
    {
        buffer = txtinputarray[notebook.get_current_page()]->get_source_buffer();
        Gtk::TextBuffer::iterator current_iter;
        current_iter = buffer->get_iter_at_mark(buffer->get_insert());
        std::cout<<"gggg"<<std::endl;
        }
    return true;
    }



proj.h

Code:
#include<gtkmm.h>
#include<gtksourceviewmm/sourcebuffer.h>
#include<gtksourceviewmm/sourceview.h>
#include<gtksourceviewmm/sourcelanguagemanager.h>
#include<vector>

template<class T>
class collection
{
    enum {size = 10};
    T C[size];
    public:
        T& operator[] (int index)
        {
            if (index>0 && index<10)
                return C[index];
            }
    };

class main_window : public Gtk::Window
{
    public:
        main_window();
        virtual ~main_window();
        bool on_txtinput_key_press(GdkEventKey *event);
    protected:
        /****Other functions****/
        Gtk::VBox vbox;
        Gtk::Notebook notebook;
        Glib::RefPtr<Gtk::UIManager> ui_manager;
        Glib::RefPtr<Gtk::ActionGroup> action_group;
        Glib::RefPtr<gtksourceview::SourceBuffer> buffer;
        Glib::RefPtr<gtksourceview::SourceLanguageManager> lang_manager;
        std::vector<gtksourceview::SourceView*> txtinputarray;
        std::vector<Gtk::ScrolledWindow*> scrollwinarray;
        std::string filepathsarray[20];
    };


Top
 Profile  
 
 Post subject: Re: problem in gtkmm
PostPosted: Thu Jan 19, 2012 6:48 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 747
Location: UK
Use this to set the signal handler to be connected before the default handler. Note the default final argument is "true" which you normally do not need to specify.
Code:
    txtinputarray[0]->signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_txtinput_key_press), false);


But first I would reconsider why I would be using this signal and why it is only used on the first page only. I am not sure why you need to use this signal, but I am sure there are better signals at a higher level that would give better information and fit in better with the gtk source view widget. Also as I said in my previous post I would consider re-writing your code so that widget and memory handling is done correctly and that you make better use of classes.

_________________
E.


Top
 Profile  
 
 Post subject: Re: problem in gtkmm
PostPosted: Fri Jan 20, 2012 11:31 am 
Offline
GTK+ Geek

Joined: Sun Apr 03, 2011 11:12 am
Posts: 63
Thx for the help errol, the problem was solved. Yeah, now I am using std::vector. Thank you very much!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group