/* micros * Copyright (C) 2000, CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include "microssig.h" #include "micros.h" #include #include #include MainWindow *mainWindow = NULL; GtkWidget* get_widget (GtkWidget *widget, gchar *widget_name) { GtkWidget *found_widget; if (widget->parent) widget = gtk_widget_get_toplevel (widget); found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget), widget_name); if (!found_widget) g_warning ("Widget not found: %s", widget_name); return found_widget; } /* This is an internally used function to set notebook tab widgets. */ void set_notebook_tab (GtkWidget *notebook, gint page_num, GtkWidget *widget) { GtkNotebookPage *page; GtkWidget *notebook_page; page = (GtkNotebookPage*) g_list_nth (GTK_NOTEBOOK (notebook)->children, page_num)->data; notebook_page = page->child; gtk_widget_ref (notebook_page); gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page_num); gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), notebook_page, widget, page_num); gtk_widget_unref (notebook_page); } MainWindow::MainWindow() { searchType_group = NULL; mainMgr = new SWMgr(); curMod = NULL; chapDisplay = 0; // set in create entryDisplay = 0; // set in create skipLookup = false; } MainWindow::~MainWindow() { delete mainMgr; if (chapDisplay) delete chapDisplay; if (entryDisplay) delete entryDisplay; } GtkWidget* create_mainWindow () { GtkWidget *retWidget; mainWindow = new MainWindow(); retWidget = mainWindow->create(); mainWindow->initSWORD(); return retWidget; } GtkWidget *MainWindow::create() { mainWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_object_set_data (GTK_OBJECT (mainWindow), "mainWindow", mainWindow); gtk_window_set_title (GTK_WINDOW (mainWindow), "Micros - SWORD PDA UI"); gtk_window_set_policy (GTK_WINDOW (mainWindow), TRUE, TRUE, FALSE); gtk_widget_set_usize(GTK_WIDGET(mainWindow), 315, 225); gtk_signal_connect(GTK_OBJECT(mainWindow), "destroy", GTK_SIGNAL_FUNC(gtk_main_quit), NULL); mainPanel = gtk_vbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "mainPanel", mainPanel); gtk_widget_show (mainPanel); gtk_container_add (GTK_CONTAINER (mainWindow), mainPanel); headerPanel = gtk_hbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "headerPanel", headerPanel); gtk_widget_show (headerPanel); gtk_box_pack_start (GTK_BOX (mainPanel), headerPanel, FALSE, TRUE, 0); handlebox3 = gtk_handle_box_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "handlebox3", handlebox3); gtk_widget_show (handlebox3); gtk_box_pack_start (GTK_BOX (headerPanel), handlebox3, TRUE, TRUE, 0); menubar4 = gtk_menu_bar_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "menubar4", menubar4); gtk_widget_show (menubar4); gtk_container_add (GTK_CONTAINER (handlebox3), menubar4); /* File3 = gtk_menu_item_new_with_label ("File"); gtk_object_set_data (GTK_OBJECT (mainWindow), "File3", File3); gtk_widget_show (File3); gtk_container_add (GTK_CONTAINER (menubar4), File3); menu13 = gtk_menu_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "menu13", menu13); gtk_menu_item_set_submenu (GTK_MENU_ITEM (File3), menu13); Exit3 = gtk_menu_item_new_with_label ("Exit"); gtk_object_set_data (GTK_OBJECT (mainWindow), "Exit3", Exit3); gtk_widget_show (Exit3); gtk_container_add (GTK_CONTAINER (menu13), Exit3); gtk_signal_connect (GTK_OBJECT (Exit3), "activate", GTK_SIGNAL_FUNC (gtk_main_quit), NULL); */ View3 = gtk_menu_item_new_with_label ("View"); gtk_object_set_data (GTK_OBJECT (mainWindow), "View3", View3); gtk_widget_show (View3); gtk_container_add (GTK_CONTAINER (menubar4), View3); gtk_signal_connect (GTK_OBJECT (View3), "activate", GTK_SIGNAL_FUNC (on_View3_activate), NULL); menuView = gtk_menu_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "menuView", menuView); gtk_menu_item_set_submenu (GTK_MENU_ITEM (View3), menuView); commentaries = gtk_menu_item_new_with_label ("Commentaries"); gtk_object_set_data (GTK_OBJECT (mainWindow), "commentaries", commentaries); gtk_widget_show (commentaries); menuCommentaries = gtk_menu_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "menuCommentaries", menuCommentaries); gtk_menu_item_set_submenu (GTK_MENU_ITEM (commentaries), menuCommentaries); dictionaries = gtk_menu_item_new_with_label ("Dictionaries"); gtk_object_set_data (GTK_OBJECT (mainWindow), "Dictionaries", dictionaries); gtk_widget_show (dictionaries); menuDictionaries = gtk_menu_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "menuDictionaries", menuDictionaries); gtk_menu_item_set_submenu (GTK_MENU_ITEM (dictionaries), menuDictionaries); /* Help = gtk_menu_item_new_with_label ("Help"); gtk_object_set_data (GTK_OBJECT (mainWindow), "Help", Help); gtk_widget_show (Help); gtk_container_add (GTK_CONTAINER (menubar4), Help); gtk_signal_connect (GTK_OBJECT (Help), "activate", GTK_SIGNAL_FUNC (on_Help_activate), NULL); gtk_menu_item_right_justify (GTK_MENU_ITEM (Help)); menu14 = gtk_menu_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "menu14", menu14); gtk_menu_item_set_submenu (GTK_MENU_ITEM (Help), menu14); About = gtk_menu_item_new_with_label ("About"); gtk_object_set_data (GTK_OBJECT (mainWindow), "About", About); gtk_widget_show (About); gtk_container_add (GTK_CONTAINER (menu14), About); gtk_signal_connect (GTK_OBJECT (About), "activate", GTK_SIGNAL_FUNC (on_About_activate), NULL); */ handlebox4 = gtk_handle_box_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "handlebox4", handlebox4); gtk_widget_show (handlebox4); gtk_box_pack_start (GTK_BOX (headerPanel), handlebox4, TRUE, TRUE, 0); hbox6 = gtk_hbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "hbox6", hbox6); gtk_widget_show (hbox6); gtk_container_add (GTK_CONTAINER (handlebox4), hbox6); showSearchButton = gtk_button_new_with_label ("-O"); gtk_object_set_data (GTK_OBJECT (mainWindow), "showSearchButton", showSearchButton); gtk_widget_show (showSearchButton); gtk_box_pack_start (GTK_BOX (hbox6), showSearchButton, FALSE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (showSearchButton), "clicked", GTK_SIGNAL_FUNC (on_showSearchButton_clicked), NULL); label2 = gtk_label_new ("Verse"); gtk_object_set_data (GTK_OBJECT (mainWindow), "label2", label2); gtk_widget_show (label2); gtk_box_pack_start (GTK_BOX (hbox6), label2, FALSE, TRUE, 0); gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_RIGHT); gtk_misc_set_padding (GTK_MISC (label2), 2, 0); GtkWidget *combo1 = gtk_combo_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "combo1", combo1); gtk_widget_show (combo1); gtk_box_pack_start (GTK_BOX (hbox6), combo1, FALSE, TRUE, 0); gtk_widget_set_usize (combo1, 90, -2); // GtkRequisition req = {90, 175}; // gtk_widget_size_request(GTK_WIDGET(GTK_COMBO(combo1)->list), &req); // gtk_widget_size_request(GTK_WIDGET(combo1), &req); // gtk_widget_size_allocate(GTK_WIDGET(GTK_COMBO(combo1)->list), &allc); // gtk_widget_set_usize(GTK_WIDGET(GTK_COMBO(combo1)->list), -2, 175); // gtk_list_scroll_vertical(GTK_LIST(GTK_COMBO(combo1)->list), // GTK_SCROLL_STEP_FORWARD, // 0); GList *combo1_items = NULL; VerseKey *myVk = new VerseKey(); myVk->Error(); //clear error (*myVk) = TOP; char *buf; while (!myVk->Error()) { const char *bname = myVk->books[myVk->Testament()-1][myVk->Book()-1].name; int len = strlen(bname); buf = new char [ len + 1 ]; strcpy(buf, bname); combo1_items = g_list_append (combo1_items, buf); myVk->Book(myVk->Book() + 1); } delete myVk; gtk_combo_set_popdown_strings (GTK_COMBO (combo1), combo1_items); lookupText = GTK_COMBO (combo1)->entry; gtk_object_set_data(GTK_OBJECT(mainWindow), "lookupText", lookupText); gtk_widget_show (lookupText); gtk_entry_set_text (GTK_ENTRY (lookupText),(char *)g_list_nth_data (combo1_items, 0)); gtk_signal_connect (GTK_OBJECT (lookupText), "changed", GTK_SIGNAL_FUNC (on_lookupText_changed), NULL); for (GList *i = g_list_first(combo1_items); i; i = g_list_next(i)) delete [] i->data; g_list_free (combo1_items); gtk_widget_set_usize (GTK_COMBO(combo1)->popup, 90, 175); // GtkAllocation allc = {-2, -2, 90, 175}; // gtk_widget_size_allocate(GTK_WIDGET(combo1), &allc); // gtk_widget_set_usize(GTK_WIDGET(GTK_COMBO(combo1)->list), 90, 175); //GTK_WIDGET(GTK_COMBO(combo1))->allocation.height = 175; //GTK_WIDGET(GTK_COMBO(combo1))->allocation.width = 90; //GTK_WIDGET(GTK_COMBO(combo1)->list)->allocation.height = 175; //GTK_WIDGET(GTK_COMBO(combo1)->list)->allocation.width = 90; //GTK_WIDGET(GTK_COMBO(combo1))->requisition.height = 175; //GTK_WIDGET(GTK_COMBO(combo1))->requisition.width = 90; //GTK_WIDGET(GTK_COMBO(combo1)->list)->requisition.height = 175; //GTK_WIDGET(GTK_COMBO(combo1)->list)->requisition.width = 90; //GTK_WIDGET(GTK_COMBO(combo1)->popwin)->allocation.height = 175; //GTK_WIDGET(GTK_COMBO(combo1)->popwin)->allocation.width = 90; //GTK_WIDGET(GTK_COMBO(combo1)->popwin)->requisition.height = 175; //GTK_WIDGET(GTK_COMBO(combo1)->popwin)->requisition.width = 90; GtkObject *spinbutton_adj = gtk_adjustment_new (1, 1, 200, 1, 10, 10); chapBox = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_adj), 1, 0); gtk_widget_ref (chapBox); gtk_object_set_data(GTK_OBJECT (mainWindow), "chapBox", chapBox); gtk_widget_show (chapBox); gtk_box_pack_start (GTK_BOX (hbox6), chapBox, FALSE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (chapBox), "changed", GTK_SIGNAL_FUNC (on_lookupText_changed), NULL); gtk_widget_set_usize (chapBox, 40, -2); spinbutton_adj = gtk_adjustment_new (1, 1, 200, 1, 10, 10); verseBox = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_adj), 1, 0); gtk_widget_ref (verseBox); gtk_object_set_data(GTK_OBJECT (mainWindow), "verseBox", verseBox); gtk_widget_show (verseBox); gtk_box_pack_start (GTK_BOX (hbox6), verseBox, FALSE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (verseBox), "changed", GTK_SIGNAL_FUNC (on_lookupText_changed), NULL); gtk_widget_set_usize (verseBox, 40, -2); hbox2 = gtk_hbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "hbox2", hbox2); gtk_widget_show (hbox2); gtk_box_pack_start (GTK_BOX (mainPanel), hbox2, TRUE, TRUE, 0); /* textScrolledWindow = gtk_scrolled_window_new (NULL, NULL); gtk_object_set_data (GTK_OBJECT (mainWindow), "textScrolledWindow", textScrolledWindow); gtk_widget_show (textScrolledWindow); gtk_box_pack_start (GTK_BOX (hbox2), textScrolledWindow, FALSE, FALSE, 0); */ moduleText = gtk_text_new (NULL, NULL); gtk_object_set_data (GTK_OBJECT (mainWindow), "moduleText", moduleText); gtk_widget_show (moduleText); // gtk_container_add (GTK_CONTAINER (textScrolledWindow), moduleText); gtk_box_pack_start (GTK_BOX (hbox2), moduleText, TRUE, TRUE, 0); gtk_text_set_editable (GTK_TEXT (moduleText), FALSE); gtk_text_set_word_wrap (GTK_TEXT (moduleText), TRUE); gtk_widget_realize (moduleText); /* Add a vertical scrollbar to the GtkText widget */ textScrollbar = gtk_vscrollbar_new (GTK_TEXT (moduleText)->vadj); gtk_box_pack_start (GTK_BOX (hbox2), textScrollbar, FALSE, FALSE, 0); gtk_widget_show (textScrollbar); /* handlebox5 = gtk_handle_box_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "handlebox5", handlebox5); gtk_widget_show (handlebox5); gtk_box_pack_start (GTK_BOX (hbox2), handlebox5, FALSE, FALSE, 0); gtk_container_border_width (GTK_CONTAINER (handlebox5), 5); */ searchPanel = gtk_vbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "searchPanel", searchPanel); gtk_widget_hide (searchPanel); gtk_box_pack_start (GTK_BOX (hbox2), searchPanel, FALSE, FALSE, 0); // gtk_container_add (GTK_CONTAINER (handlebox5), searchPanel); hbox4 = gtk_hbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "hbox4", hbox4); gtk_widget_show (hbox4); gtk_box_pack_start (GTK_BOX (searchPanel), hbox4, FALSE, FALSE, 0); searchText = gtk_entry_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "searchText", searchText); gtk_widget_show (searchText); gtk_box_pack_start (GTK_BOX (hbox4), searchText, TRUE, TRUE, 0); gtk_widget_set_usize (searchText, 90, -2); searchButton = gtk_button_new_with_label ("Go"); gtk_object_set_data (GTK_OBJECT (mainWindow), "searchButton", searchButton); gtk_widget_show (searchButton); gtk_box_pack_start (GTK_BOX (hbox4), searchButton, FALSE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (searchButton), "clicked", GTK_SIGNAL_FUNC (on_searchButton_clicked), NULL); searchSettingsPanel = gtk_hbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "searchSettingsPanel", searchSettingsPanel); gtk_widget_show (searchSettingsPanel); gtk_box_pack_start (GTK_BOX (searchPanel), searchSettingsPanel, FALSE, FALSE, 0); searchTypePanel = gtk_vbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "searchTypePanel", searchTypePanel); gtk_widget_show (searchTypePanel); gtk_box_pack_start (GTK_BOX (searchSettingsPanel), searchTypePanel, FALSE, FALSE, 0); multiWordSearch = gtk_radio_button_new_with_label (searchType_group, "Multi Word"); searchType_group = gtk_radio_button_group (GTK_RADIO_BUTTON (multiWordSearch)); gtk_object_set_data (GTK_OBJECT (mainWindow), "multiWordSearch", multiWordSearch); gtk_widget_show (multiWordSearch); gtk_box_pack_start (GTK_BOX (searchTypePanel), multiWordSearch, FALSE, FALSE, 0); phraseSearch = gtk_radio_button_new_with_label (searchType_group, "Exact Phrase"); searchType_group = gtk_radio_button_group (GTK_RADIO_BUTTON (phraseSearch)); gtk_object_set_data (GTK_OBJECT (mainWindow), "phraseSearch", phraseSearch); gtk_widget_show (phraseSearch); gtk_box_pack_start (GTK_BOX (searchTypePanel), phraseSearch, FALSE, FALSE, 0); regexSearch = gtk_radio_button_new_with_label (searchType_group, "Regular Expression"); searchType_group = gtk_radio_button_group (GTK_RADIO_BUTTON (regexSearch)); gtk_object_set_data (GTK_OBJECT (mainWindow), "regexSearch", regexSearch); gtk_widget_show (regexSearch); gtk_box_pack_start (GTK_BOX (searchTypePanel), regexSearch, FALSE, FALSE, 0); /* searchOptionsPanel = gtk_vbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "searchOptionsPanel", searchOptionsPanel); gtk_widget_show (searchOptionsPanel); gtk_box_pack_start (GTK_BOX (searchSettingsPanel), searchOptionsPanel, FALSE, FALSE, 0); */ caseSensitive = gtk_check_button_new_with_label ("Case Sensitive"); gtk_object_set_data (GTK_OBJECT (mainWindow), "caseSensitive", caseSensitive); gtk_widget_show (caseSensitive); // gtk_box_pack_start (GTK_BOX (searchOptionsPanel), caseSensitive, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (searchTypePanel), caseSensitive, FALSE, FALSE, 0); GtkWidget *resultPanel = gtk_hbox_new (FALSE, 0); gtk_object_set_data (GTK_OBJECT (mainWindow), "resultPanel", resultPanel); gtk_widget_show (resultPanel); gtk_box_pack_start (GTK_BOX (searchPanel), resultPanel, TRUE, TRUE, 0); resultList = gtk_clist_new(1); gtk_object_set_data(GTK_OBJECT (mainWindow), "resultList", resultList); // gtk_clist_set_policy(GTK_CLIST(resultList), GTK_POLICY_AUTOMATIC, 0); // gtk_clist_set_border(GTK_CLIST(resultList), GTK_SHADOW_ETCHED_IN); gtk_widget_show (resultList); gtk_box_pack_start (GTK_BOX (resultPanel), resultList, TRUE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (resultList), "select_row", GTK_SIGNAL_FUNC (on_resultList_selection_changed), NULL); /* Add a vertical scrollbar to the GtkCList widget */ textScrollbar = gtk_vscrollbar_new (NULL); gtk_clist_set_vadjustment (GTK_CLIST(resultList), gtk_range_get_adjustment(GTK_RANGE(textScrollbar))); gtk_box_pack_start (GTK_BOX (resultPanel), textScrollbar, FALSE, FALSE, 0); gtk_widget_show (textScrollbar); /* statusbar1 = gtk_statusbar_new (); gtk_object_set_data (GTK_OBJECT (mainWindow), "statusbar1", statusbar1); gtk_widget_show (statusbar1); gtk_box_pack_start (GTK_BOX (mainPanel), statusbar1, FALSE, TRUE, 0); */ /* arrow1 = gtk_button_new_with_label ("[<]"); gtk_object_set_data (GTK_OBJECT (mainWindow), "arrow1", arrow1); gtk_widget_show (arrow1); gtk_box_pack_start (GTK_BOX (headerPanel), arrow1, FALSE, FALSE, 0); gtk_signal_connect (GTK_OBJECT (arrow1), "clicked", GTK_SIGNAL_FUNC (on_arrow1_button_press_event), NULL); arrow2 = gtk_button_new_with_label ("[>]"); gtk_object_set_data (GTK_OBJECT (mainWindow), "arrow2", arrow2); gtk_widget_show (arrow2); gtk_box_pack_start (GTK_BOX (headerPanel), arrow2, FALSE, FALSE, 0); gtk_signal_connect (GTK_OBJECT (arrow2), "clicked", GTK_SIGNAL_FUNC (on_arrow2_button_press_event), NULL); */ statusbar1 = gtk_label_new (""); gtk_object_set_data (GTK_OBJECT (mainWindow), "statusbar1", statusbar1); gtk_widget_show (statusbar1); gtk_box_pack_start (GTK_BOX (mainPanel), statusbar1, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (statusbar1), GTK_JUSTIFY_LEFT); gtk_misc_set_padding (GTK_MISC (statusbar1), 2, 0); GTKEntryDisp::__initialize(); chapDisplay = new GTKChapDisp(moduleText); entryDisplay = new GTKEntryDisp(moduleText); return mainWindow; } void MainWindow::initSWORD() { GtkWidget *menuChoice; int viewNumber = 1; char menuName[64]; ModMap::iterator it; SectionMap::iterator sit; ConfigEntMap::iterator eit; char *font; SWModule *curMod; for (it = mainMgr->Modules.begin(); it != mainMgr->Modules.end(); it++) { curMod = (*it).second; menuChoice = gtk_menu_item_new_with_label (curMod->Name()); sprintf(menuName, "viewMod%d", viewNumber++); gtk_object_set_data (GTK_OBJECT (mainWindow), menuName, menuChoice); gtk_widget_show (menuChoice); gtk_signal_connect(GTK_OBJECT (menuChoice), "activate", GTK_SIGNAL_FUNC (on_viewMod_activate), g_strdup(curMod->Name())); if (!strcmp((*it).second->Type(), "Biblical Texts")) { gtk_container_add (GTK_CONTAINER (menuView), menuChoice); font = 0; if ((sit = mainMgr->config->Sections.find((*it).second->Name())) != mainMgr->config->Sections.end()) { if ((eit = (*sit).second.find("Font")) != (*sit).second.end()) { font = (char *)(*eit).second.c_str(); } } // CreateTextPane((*it).second, font); curMod->Disp(chapDisplay); // set our GTKChapDisp object up for the diplayer of each Biblical Text module if (!this->curMod) // set currently selected module for app to first module from SWMgr (Bible Texts get first preference this->curMod = curMod; } else { curMod->Disp(entryDisplay); // set our GTKEntryDisp object up for the diplayer of each module other than Biblical Texts if (!strcmp((*it).second->Type(), "Commentaries")) { gtk_container_add (GTK_CONTAINER (menuCommentaries), menuChoice); // CreateCommentPane((*it).second); } if (!strcmp((*it).second->Type(), "Lexicons / Dictionaries")) { gtk_container_add (GTK_CONTAINER (menuDictionaries), menuChoice); // CreateLDPane((*it).second); } } } gtk_container_add (GTK_CONTAINER (menuView), commentaries); gtk_container_add (GTK_CONTAINER (menuView), dictionaries); if (!this->curMod) // set currently selected module for app to first module from SWMgr this->curMod = curMod; } void MainWindow::lookupTextChanged() { string keyText; gchar *entryText; char tmpBuf[255]; if (!skipLookup) { entryText = gtk_entry_get_text(GTK_ENTRY(lookupText)); keyText = entryText; entryText = gtk_entry_get_text(GTK_ENTRY(chapBox)); keyText += " "; keyText += entryText; entryText = gtk_entry_get_text(GTK_ENTRY(verseBox)); keyText += ":"; keyText += entryText; if (curMod) { curMod->setKey(keyText.c_str()); curMod->Display(); sprintf(tmpBuf, "%s (%s)", curMod->KeyText(), curMod->Name()); gtk_label_set(GTK_LABEL(statusbar1), tmpBuf); } } } void MainWindow::viewModActivate(GtkMenuItem *sender, gchar *modName) { ModMap::iterator it; it = mainMgr->Modules.find(modName); if (it != mainMgr->Modules.end()) { curMod = (*it).second; lookupTextChanged(); } else curMod = 0; } void MainWindow::navigateButtonClicked(int direction) { if (curMod) { if (direction) (*curMod)++; else (*curMod)--; (const char *)*curMod; // snap to closest locations const gchar *text = curMod->KeyText(); gtk_entry_set_text(GTK_ENTRY(lookupText), text); // curMod->Display(); } } void MainWindow::showSearchButtonClicked() { static bool showing = false; if (showing) gtk_widget_hide(searchPanel); else gtk_widget_show(searchPanel); showing = !showing; } void statusUpdate(char percent, void *userData) { char buf[5]; GtkWidget *button = (GtkWidget *)userData; sprintf(buf, "%d%%", percent); gtk_label_set_text(GTK_LABEL(GTK_BIN(button)->child), buf); // gtk_widget_draw_focus(button); } void MainWindow::searchButtonClicked() { string srchText; gchar *entryText; const gchar *resultText; gchar **clistText = (gchar **)&resultText; gtk_clist_clear(GTK_CLIST(resultList)); entryText = gtk_entry_get_text(GTK_ENTRY(searchText)); srchText = entryText; if (curMod) { int searchType = GTK_TOGGLE_BUTTON(regexSearch)->active ? 0 : GTK_TOGGLE_BUTTON(phraseSearch)->active ? -1 : -2; int searchParams = GTK_TOGGLE_BUTTON(caseSensitive)->active ? 0 : REG_ICASE; gtk_clist_freeze(GTK_CLIST(resultList)); for (ListKey searchResults = curMod->Search(srchText.c_str(), searchType, searchParams, 0, 0, statusUpdate, searchButton); !searchResults.Error(); searchResults++) { resultText = (const char *)searchResults; gtk_clist_append(GTK_CLIST(resultList), clistText); } gtk_clist_thaw(GTK_CLIST(resultList)); gtk_label_set_text(GTK_LABEL(GTK_BIN(searchButton)->child), "Go"); } } void MainWindow::resultListSelectionChanged(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data) { gchar *text; char buf[256]; gtk_clist_get_text(GTK_CLIST(resultList), row, column, &text); VerseKey vkey(text); if (text) { skipLookup = true; memset(buf, 0, 256); int len = strlen((const char *)vkey); if (len > 255) len = 255; strncpy(buf, (const char *)vkey, len-4); gtk_entry_set_text(GTK_ENTRY(lookupText), vkey.books[vkey.Testament()-1][vkey.Book()-1].name); sprintf(buf, "%d", vkey.Chapter()); gtk_entry_set_text(GTK_ENTRY(chapBox), buf); skipLookup = false; sprintf(buf, "%d", vkey.Verse()); gtk_entry_set_text(GTK_ENTRY(verseBox), buf); } } GdkColor GTKEntryDisp::colourBlue; GdkColor GTKEntryDisp::colourGreen; char GTKEntryDisp::Display(SWModule &imodule) { char tmpBuf[255]; gtk_text_set_point(GTK_TEXT(gtkText), 0); gtk_text_forward_delete (GTK_TEXT (gtkText), gtk_text_get_length((GTK_TEXT(gtkText)))); int curPos = 0; (const char *)imodule; // snap to entry gtk_text_freeze (GTK_TEXT(gtkText)); sprintf(tmpBuf, "[%s] ", imodule.KeyText()); gtk_text_insert(GTK_TEXT(gtkText), NULL, &colourBlue, NULL, tmpBuf, -1); gtk_text_insert(GTK_TEXT(gtkText), NULL, >kText->style->black, NULL, imodule.StripText(), -1); gtk_text_set_point(GTK_TEXT(gtkText), curPos); gtk_text_thaw(GTK_TEXT(gtkText)); } char GTKChapDisp::Display(SWModule &imodule) { char tmpBuf[255]; gtk_text_set_point(GTK_TEXT(gtkText), 0); gtk_text_forward_delete (GTK_TEXT (gtkText), gtk_text_get_length((GTK_TEXT(gtkText)))); VerseKey *key = (VerseKey *)(SWKey *)imodule; int curVerse = key->Verse(); int curChapter = key->Chapter(); int curBook = key->Book(); int curPos = 0; gfloat adjVal; gtk_text_freeze (GTK_TEXT(gtkText)); for (key->Verse(1); (key->Book() == curBook && key->Chapter() == curChapter && !imodule.Error()); imodule++) { sprintf(tmpBuf, "%d. ", key->Verse()); gtk_text_insert(GTK_TEXT(gtkText), NULL, &colourBlue, NULL, tmpBuf, -1); if (key->Verse() == curVerse) { gtk_text_thaw(GTK_TEXT(gtkText)); adjVal = GTK_TEXT(gtkText)->vadj->upper; curPos = gtk_text_get_length(GTK_TEXT(gtkText)); gtk_text_insert(GTK_TEXT(gtkText), NULL, &colourGreen, NULL, imodule.StripText(), -1); gtk_text_freeze (GTK_TEXT(gtkText)); } else { gtk_text_insert(GTK_TEXT(gtkText), NULL, >kText->style->black, NULL, imodule.StripText(), -1); } gtk_text_insert(GTK_TEXT(gtkText), NULL, >kText->style->black, NULL, " ", -1); } gtk_text_set_point(GTK_TEXT(gtkText), curPos); gtk_text_thaw(GTK_TEXT(gtkText)); adjVal -= (GTK_TEXT(gtkText)->vadj->page_size / 2); gtk_adjustment_set_value(GTK_TEXT(gtkText)->vadj, (adjVal>0)?adjVal:0); key->Verse(1); key->Chapter(1); key->Book(curBook); key->Chapter(curChapter); key->Verse(curVerse); }