void wqq_qqchat_append_message_from_buddy(WqqQQChat * chat, const gchar * avatar, WqqQQChatMessage * msg) { g_return_if_fail(WQQ_IS_QQCHAT(chat) && msg != NULL); while (chat->loading) { gtk_main_iteration_do(TRUE); } WebKitDOMDocument *doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(chat->webview)); WebKitDOMElement *body = webkit_dom_document_query_selector(doc, "body", NULL); WebKitDOMElement *chat_content_group = webkit_element_chat_content_group(doc, avatar, msg); webkit_dom_element_set_attribute(chat_content_group, "class", "chat_content_group buddy", NULL); webkit_dom_node_append_child(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(chat_content_group), NULL); }
void disp_tsin_select(int index) { int x,y; #if WIN32 if (test_mode) return; #endif if (index < 0) return; // dbg("gcin_edit_display_ap_only() %d\n", gcin_edit_display_ap_only()); if (gcin_edit_display_ap_only()) { getRootXY(current_CS->client_win, current_CS->spot_location.x, current_CS->spot_location.y, &x, &y); } else { #if 1 int i; // bug in GTK, widget position is wrong, repeat util find one for(i=index;i>=0; i--) { gtk_widget_show_now(chars[i].label); gtk_widget_show(chars[i].vbox); gtk_main_iteration_do(FALSE); int tx = get_widget_xy(gwin0, chars[i].vbox, &x, &y); if (tx>=0) break; } #else get_widget_xy(gwin0, chars[index].vbox, &x, &y); #endif get_win0_geom(); } disp_selections(x, y); }
int main(int argc, char* argv[]) { gtk_init(&argc, &argv); window_main_init(); window_main_show(); window_settings_init(); window_reference_signal_init(); window_signal_init(); window_difficulty_init(); window_calibration_init(); window_music_init(); window_shutdown_init(); while(1) { gtk_main_iteration_do(FALSE); if(window_signal_is_stop()==FALSE) { window_signal_main(); } else if(window_calibration_is_stop()==FALSE) { window_calibration_main(); } else if(window_music_is_stop()==FALSE) { window_music_main(); } } //gtk_main(); }
gboolean xmms_fullscreen_enter(GtkWidget * win, gint * w, gint * h) { gint i, close, how_close = -1, t, dummy; gboolean retval = FALSE; fullscreen_window_t *fwin; FULL_LOCK(); fwin = getwindow(win); if (!fwin->display->is_full && !fwin->is_full && fwin->display->can_full) { for (close = 0; close < fwin->display->num_modes; close++) { if ((fwin->display->modes[close]->hdisplay >= *w) && (fwin->display->modes[close]->vdisplay >= *h)) { how_close = fwin->display->modes[close]->hdisplay - *w; break; } } for (i = close + 1; i < fwin->display->num_modes; i++) { if (fwin->display->modes[i]->vdisplay < *h) continue; t = fwin->display->modes[i]->hdisplay - *w; if (t >= 0 && t < how_close) { close = i; how_close = t; } } if (close < fwin->display->num_modes) { *w = fwin->display->modes[close]->hdisplay; *h = fwin->display->modes[close]->vdisplay; /* Save the old position/size */ gdk_window_get_root_origin(fwin->window->window, &fwin->ox, &fwin->oy); gdk_window_get_size(fwin->window->window, &fwin->owidth, &fwin->oheight); /* Move it. */ gdk_window_move_resize(fwin->window->window, 0, 0, fwin->display->modes[close]->hdisplay, fwin->display->modes[close]->vdisplay); /* Tell the WM not to mess with this window (no more decor) */ gdk_window_hide(fwin->window->window); gdk_window_set_override_redirect(fwin->window->window, TRUE); gdk_window_show(fwin->window->window); /* * XXX: HACK * Something is ungrabbing the pointer shortly * after the above unmap/override_redirect=TRUE/map * is done. I don't know what at this time, only * that it's not XMMS, and that it's very very evil. */ gdk_flush(); xmms_usleep(50000); /* Steal the keyboard/mouse */ /* XXX: FIXME, use timeouts.. */ for (t = 0; t < 10; t++) { dummy = gdk_pointer_grab(fwin->window->window, TRUE, 0, fwin->window->window, NULL, GDK_CURRENT_TIME); if (dummy == GrabSuccess) break; gtk_main_iteration_do(FALSE); xmms_usleep(10000); } gdk_keyboard_grab(fwin->window->window, TRUE, GDK_CURRENT_TIME); /* Do the video mode switch.. */ XF86VidModeSwitchToMode(fwin->display->display, DefaultScreen(fwin->display->display), fwin->display->modes[close]); XF86VidModeSetViewPort(fwin->display->display, DefaultScreen(fwin->display->display), 0, 0); retval = TRUE; fwin->is_full = TRUE; fwin->display->is_full = TRUE; } } FULL_UNLOCK(); return retval; }
void mai_info_win_iteration (MaiInfoWin *iw, gboolean blocking) { gtk_main_iteration_do (blocking); }
bool _HYSequencePane::_ProcessOSEvent (Ptr vEvent) { static bool amScrolling = false, vertical; static long localPt_x, localPt_y, originalStart, originalSpan, lastClick, firstClick; if (_HYPlatformComponent::_ProcessOSEvent (vEvent)) return true; _HY_GTK_UI_Message *theMessage = (_HY_GTK_UI_Message*)vEvent; if (active) { gdouble xc, yc; if (gdk_event_get_coords (theMessage->theEvent,&xc,&yc)) { switch (theMessage->theEvent->type) { case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: { GdkEventButton * bevent = (GdkEventButton*)theMessage->theEvent; long globalPt_x = xc, globalPt_y = yc; localPt_x = globalPt_x-rel.left-parentWindow->allocation.x; localPt_y = globalPt_y-rel.top-parentWindow->allocation.y; vertical = (localPt_x<headerWidth)&&(localPt_y>=(GetSlotHeight()+1)); if (((GdkEventButton*)bevent)->button == 1) { if (vertical) ProcessVSelectionChange (localPt_x,localPt_y,bevent->state & GDK_SHIFT_MASK,bevent->state & GDK_CONTROL_MASK, false, bevent->type == GDK_2BUTTON_PRESS); else ProcessSelectionChange (localPt_x,localPt_y,bevent->state & GDK_SHIFT_MASK,bevent->state & GDK_CONTROL_MASK); } else { if ((((GdkEventButton*)bevent)->button == 2 || ((GdkEventButton*)bevent)->button == 3 )&& (vertical&&vselection.lLength || !vertical &&selection.lLength)) { ProcessContextualPopUp (globalPt_x, globalPt_y); return true; } } } break; case GDK_BUTTON_RELEASE: case GDK_LEAVE_NOTIFY: { if (amScrolling) { if (messageRecipient) ((_HYTWindow*)messageRecipient)->trackMouseComponent = (Ptr)nil; /*gdk_pointer_ungrab (((GdkEventButton*)theMessage->theEvent)->time);*/ if (vertical) { _HYRect invalRectH = {parentWindow->allocation.x+rel.left, parentWindow->allocation.y+rel.top+(GetSlotHeight()+1)+1,rel.left+headerWidth,rel.bottom-HY_SCROLLER_WIDTH}; GdkRectangle irect = HYRect2GDKRect(invalRectH); irect.x+=parentWindow->allocation.x; irect.y+=parentWindow->allocation.y; gdk_window_invalidate_rect (parentWindow->window, &irect, false); if ( localPt_x<headerWidth && localPt_x>0 && lastClick>-2) MoveSpecies (firstClick+originalStart,lastClick+startRow); } amScrolling = false; } break; } case GDK_MOTION_NOTIFY: { GdkEventMotion * motEvent = (GdkEventMotion*)theMessage->theEvent; if (motEvent->state & GDK_BUTTON1_MASK) { if (amScrolling) { gint mousePt_x = motEvent->x - rel.left - parentWindow->allocation.x, mousePt_y = motEvent->y - rel.top - parentWindow->allocation.y; if (vertical) // vertical scrolling { long wHeight = rel.bottom-rel.top-HY_SCROLLER_WIDTH, slotHeight = GetSlotHeight(); if ( mousePt_y < GetSlotHeight()+1 || localPt_y != mousePt_y || mousePt_y>wHeight ) { localPt_x = mousePt_x; localPt_y = mousePt_y; if (mousePt_y>wHeight) { // scroll down if ((endRow<=speciesIndex.lLength)&&(vselection.lData[0]!=speciesIndex.lLength-1)) { if (endRow-startRow<originalSpan) break; startRow++; endRow++; _SetVScrollerPos(((double)MAX_CONTROL_VALUE*startRow)/ (speciesIndex.lLength-endRow+startRow+1)); BuildPane(); forceUpdateForScrolling = true; _MarkForUpdate(); forceUpdateForScrolling = false; lastClick = -2; } break; } else { mousePt_y-=(GetSlotHeight()+1); if (mousePt_y<=slotHeight) { if (mousePt_y>=0) { if (mousePt_y<slotHeight/2) mousePt_y = -1; else mousePt_y = 0; } else { // scroll up if (startRow>0) { startRow--; endRow--; _SetVScrollerPos(((double)MAX_CONTROL_VALUE*startRow)/(speciesIndex.lLength-endRow+startRow+1)); BuildPane(); forceUpdateForScrolling = true; _MarkForUpdate(); forceUpdateForScrolling = false; lastClick = -2; } break; } } else mousePt_y=(mousePt_y-(GetSlotHeight()+1))/slotHeight; } if ( mousePt_y<-1 || mousePt_y>= endRow-startRow ) break; if (mousePt_y!=lastClick) { GdkDrawable * tempDr = GDK_DRAWABLE(parentWindow->window); GdkGC * tempGC = gdk_gc_new (tempDr); GdkColor black = HYColorToGDKColor((_HYColor){0,0,0}); gdk_gc_set_foreground (theContext, &black); gdk_gc_set_function (tempGC, GDK_INVERT); gdk_gc_set_line_attributes (tempGC, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER); if (lastClick>=-1) { lastClick = (GetSlotHeight()+1)+slotHeight*(lastClick+1)+rel.top+1; gdk_draw_line (tempDr,tempGC,parentWindow->allocation.x+rel.left+1,parentWindow->allocation.y+lastClick, parentWindow->allocation.x+rel.left+headerWidth-1,parentWindow->allocation.y+lastClick); } lastClick = mousePt_y; if (lastClick+startRow != firstClick+originalStart) { mousePt_y = (GetSlotHeight()+1)+slotHeight*(lastClick+1)+rel.top+1; gdk_draw_line (tempDr,tempGC,parentWindow->allocation.x+rel.left+1,parentWindow->allocation.y+mousePt_y, parentWindow->allocation.x+rel.left+headerWidth-1,parentWindow->allocation.y+mousePt_y); } g_object_unref (tempGC); } } return true; } else // horizontal scrolling { long rightWindowBound = _HYCanvas::GetMaxW()-HY_SCROLLER_WIDTH; guint32 serverTime = gdk_x11_get_server_time (parentWindow->window); if ( mousePt_x<headerWidth && startColumn>0 || localPt_x!=mousePt_x || mousePt_x> rightWindowBound) { forceUpdateForScrolling = true; if (mousePt_x<headerWidth && startColumn>0) { gint wx, wy; gdk_window_get_origin (parentWindow->window,&wx,&wy); wx += parentWindow->allocation.x+rel.left; wy += parentWindow->allocation.y+rel.top; do { guint32 serverTime2 = gdk_x11_get_server_time (parentWindow->window); if (serverTime2-serverTime < 100) ProcessSelectionChange (mousePt_x,mousePt_y,true,true,true); GdkModifierType keyDown; gdk_display_get_pointer (gdk_display_get_default(),NULL,&mousePt_x,&mousePt_y,&keyDown); mousePt_x -= wx; mousePt_y -= wy; serverTime = serverTime2; if ((keyDown & GDK_BUTTON1_MASK)==0) break; gtk_main_iteration_do(true); } while (mousePt_x<headerWidth && startColumn>0); } else { if (mousePt_x> rightWindowBound) { gint wx, wy; gdk_window_get_origin (parentWindow->window,&wx,&wy); wx += parentWindow->allocation.x; wy += parentWindow->allocation.y; do { guint32 serverTime2 = gdk_x11_get_server_time (parentWindow->window); if (serverTime2-serverTime < 100) ProcessSelectionChange (mousePt_x+HY_SCROLLER_WIDTH,mousePt_y,true,true,true); GdkModifierType keyDown; gdk_display_get_pointer (gdk_display_get_default(),NULL,&mousePt_x,&mousePt_y,&keyDown); mousePt_x -= wx; mousePt_y -= wy; serverTime = serverTime2; if ((keyDown & GDK_BUTTON1_MASK)==0) break; gtk_main_iteration_do(true); } while (mousePt_x> rightWindowBound && endColumn < columnStrings.lLength); } else if (serverTime-gdk_event_get_time(theMessage->theEvent) < 100) ProcessSelectionChange (mousePt_x,mousePt_y,true,true,true); } forceUpdateForScrolling = false; localPt_x = mousePt_x; localPt_y = mousePt_y; } return true; } } else { /*gdk_pointer_grab (parentWindow->window,false, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, (((GdkEventMotion*)theMessage->theEvent))->time);*/ if (messageRecipient) ((_HYTWindow*)messageRecipient)->trackMouseComponent = (Ptr)((_HYComponent*)this); amScrolling = true; originalStart = startRow, originalSpan = endRow-startRow; lastClick = -2; firstClick = (localPt_y-(GetSlotHeight()+1))/GetSlotHeight(); return true; } } break; } } } } return false; }
void CInstaller::CoreUpdateUI() { gtk_main_iteration_do(FALSE); }
bool _HYConsoleWindow::_ProcessMenuSelection (long msel) { switch (msel) { case HY_WINDOW_MENU_ID_FILE+1: SaveConsole (); return true; case 14: _DoPrint (); return true; case 16: ((_HYTextBox*)GetObject(0))->_DoUndo(true); return true; case 17: ((_HYTextBox*)GetObject(0))->_DoCut(true); return true; case 18: ((_HYTextBox*)GetObject(0))->_DoCopy(true); return true; case HY_WINDOW_MENU_ID_EDIT+5: ((_HYTextBox*)GetObject(0))->_DoSelectAll(true); return true; case 21: SetStatusLine ("Canceling"); terminateExecution = true; return true; case 22: { GtkWidget * suspendItem = gtk_item_factory_get_widget_by_action(menu_items,22); if (!isSuspended) { isSuspended = true; SetStatusLine (empty,empty,empty,-1,HY_SL_SUSPEND); gtk_label_set_text (GTK_LABEL (gtk_bin_get_child(GTK_BIN(suspendItem))), "Resume"); updateTimer = false; while (isSuspended) { gtk_main_iteration_do(true); } } else { isSuspended = false; SetStatusLine (empty,empty,empty,-1,HY_SL_RESUME); gtk_label_set_text (GTK_LABEL (gtk_bin_get_child(GTK_BIN(suspendItem))), "Suspend execution"); timerStart += clock()-lastTimer; updateTimer = true; } return true; } case 23: ShowMessagesLog(); return true; case 24: RunStandardAnalyses(); return true; case 25: displayAbout(false); return true; case HY_WINDOW_MENU_ID_EDIT+4: ((_HYTextBox*)GetObject(0))->_DoClear (true,true); return true; case 27: HandlePreferences (globalPreferencesList,"HYPHY Preferences"); return true; case 29: //WinExec ("hh HYPHY HELP.chm",SW_SHOWNORMAL); return true; case 30: if (OpenBatchFile (false)) { ExecuteBatchFile(); PopFilePath(); } return true; case 31: ((_HYTextBox*)GetObject(0))->_DoRedo(true); return true; case 15: postWindowCloseEvent (GetID()); gtk_main_quit (); return true; case 60: // expression calculator if (calculatorMode) { _HYTextBox *ib = (_HYTextBox*)hyphyConsoleWindow->GetObject(1); ib->SetText ("exit"); hyphyConsoleWindow->ProcessEvent (generateTextEditChangeEvent(ib->GetID(),2)); calculatorMode = false; //ib->SetText (empty); } else { calculatorMode = true; while(calculatorMode&&ExpressionCalculator()) {} calculatorMode = false; } return true; case 61: { // execute selection ExecuteSelection(); return true; } case 70: // New Tree NewTreeWindow(-1); return true; case 71: // New Model NewModel(nil); return true; case 72: // New Chart NewChartWindow(); return true; case 73: // New Genetic Code NewGeneticCodeTable(0); return true; case 74: // New Database NewDatabaseFile(0); return true; case 80: // Open Batch File if (OpenBatchFile()) { ExecuteBatchFile (); } return true; case 81: // Open Data File OpenDataFile(); return true; case 82: // Open Tree OpenTreeFile(); return true; case 83: // Open Text OpenTextFile(); return true; case 84: // Open Table OpenTable (); return true; case 85: // Open SQLite database OpenDatabaseFile (nil); return true; case HY_WINDOW_MENU_ID_FILE-2: ShowObjectInspector (); return true; default: { msel -= 1000; if (msel<availablePostProcessors.lLength) { ExecuteAPostProcessor (*(_String*)(*(_List*)availablePostProcessors(msel))(1)); return 0; } msel-=1000; if (msel<(long)recentPaths.lLength) { if (msel == -1) { for (long mi=0; mi<recentFiles.lLength; mi++) { GtkWidget * recFile = gtk_item_factory_get_widget_by_action(hyphyConsoleWindow->menu_items,2000+mi); if (recFile) { gtk_item_factory_delete_item(hyphyConsoleWindow->menu_items,gtk_item_factory_path_from_widget(recFile)); } } recentPaths.Clear(); recentFiles.Clear(); } else { if (argFileName) { *argFileName = *(_String*)recentPaths(msel); } else { argFileName = new _String (*(_String*)recentPaths(msel)); } if (OpenBatchFile(false)) { ExecuteBatchFile (); } } return true; } return true; } } return _HYTWindow::_ProcessMenuSelection(msel); }
int input_configure(int pnum, int type) { // Configure the input if (confrunning) { return 0; } SDL_Event event, eventbuf; int axis = 0, axisnoise = 0, counter = 0; confrunning = true; while (confrunning) { #ifdef _GTK while (gtk_events_pending()) { gtk_main_iteration_do(FALSE); } #endif while(SDL_PollEvent(&event)) { // Time to quit? switch (event.key.keysym.sym) { case SDLK_ESCAPE: confrunning = false; break; default: break; } // Process the event if (type == 0) { // Keyboard switch(event.type) { case SDL_KEYUP: input_set_item(event, type, pnum, counter); counter++; break; default: break; } } else if (type == 1) { // Joystick switch(event.type) { case SDL_JOYBUTTONDOWN: input_set_item(event, type, pnum, counter); counter++; break; case SDL_JOYHATMOTION: if (event.jhat.value != SDL_HAT_CENTERED) { input_set_item(event, type, pnum, counter); counter++; } break; case SDL_JOYAXISMOTION: if (abs(event.jaxis.value) >= DEADZONE) { eventbuf = event; axisnoise = 1; axis = event.jaxis.axis; } else if (abs(event.jaxis.value) < DEADZONE && axisnoise && event.jaxis.axis == axis) { input_set_item(eventbuf, type, pnum, counter); axisnoise = 0; counter++; } break; default: break; } } if (counter >= NUMBUTTONS) { confrunning = false; } } } return 1; }
static void search_tree(gpointer data) { struct search_info *info = data; GtkTreePath *path; GtkTreeViewColumn *col; GtkTreeModel *model; TraceViewStore *store; GtkTreeIter iter; GtkEntry *entry = GTK_ENTRY(info->entry); GtkComboBox *col_combo = GTK_COMBO_BOX(info->column); GtkComboBox *sel_combo = GTK_COMBO_BOX(info->selection); const gchar *title; const gchar *search_text; gint col_num; gint sel; gint search_val; gint start_row; gboolean found = FALSE; gint i = 0; col_num = gtk_combo_box_get_active(col_combo); sel = gtk_combo_box_get_active(sel_combo); if (col_num >= TRACE_VIEW_STORE_N_COLUMNS) return; search_text = gtk_entry_get_text(entry); if (!search_text || !strlen(search_text)) return; col = gtk_tree_view_get_column(info->treeview, col_num); if (!col) return; title = gtk_tree_view_column_get_title(col); if (!title) return; model = gtk_tree_view_get_model(info->treeview); if (!model) return; store = TRACE_VIEW_STORE(model); if (!trace_view_store_visible_rows(store)) return; start_row = trace_view_get_selected_row(GTK_WIDGET(info->treeview)); if (start_row < 0) start_row = 0; if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, start_row)) return; trace_set_cursor(GDK_WATCH); trace_freeze_all(); search_val = atoi(search_text); while (gtk_tree_model_iter_next(model, &iter)) { /* Needed to process the cursor change */ if (!(i++ & ((1 << 5)-1))) gtk_main_iteration_do(FALSE); found = test_row(model, &iter, sel, col_num, search_val, search_text); if (found) break; } trace_unfreeze_all(); trace_put_cursor(); if (!found) { GtkResponseType ret; gint pages = trace_view_store_get_pages(store); gint page = trace_view_store_get_page(store); if (page < pages) { ret = trace_dialog(NULL, TRACE_GUI_ASK, "Not found on this page\n" "Search next pages?"); if (ret == GTK_RESPONSE_YES) search_next_pages(info->treeview, store, sel, col_num, search_val, search_text); return; } trace_dialog(NULL, TRACE_GUI_INFO, "Not found"); return; } path = gtk_tree_model_get_path(model, &iter); select_row_from_path(info->treeview, path); gtk_tree_path_free(path); }
bool handleGUI (bool yield) { return gtk_main_iteration_do (!yield); }
bool show() { #if defined(WIN32) std::wstring title16 = StringHelp::utf8_to_ucs2(title); std::wstring initial_directory16 = StringHelp::utf8_to_ucs2(initial_directory); if(is_vista_or_later()) { HRESULT result; ComPtr<IFileOpenDialog> open_dialog; result = CoCreateInstance(__uuidof(FileOpenDialog), NULL, CLSCTX_ALL, __uuidof(open_dialog), reinterpret_cast<void**>(open_dialog.output_variable())); throw_if_failed(result, "CoCreateInstance(FileOpenDialog) failed"); result = open_dialog->SetTitle(title16.c_str()); throw_if_failed(result, "IFileOpenDialog.SetTitle failed"); result = open_dialog->SetOptions(FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST); throw_if_failed(result, "IFileOpenDialog.SetOptions((FOS_PICKFOLDERS) failed"); if(initial_directory16.length() > 0) { LPITEMIDLIST item_id_list = NULL; SFGAOF flags = 0; result = SHParseDisplayName(initial_directory16.c_str(), NULL, &item_id_list, SFGAO_FILESYSTEM, &flags); throw_if_failed(result, "SHParseDisplayName failed"); ComPtr<IShellItem> folder_item; result = SHCreateShellItem(NULL, NULL, item_id_list, folder_item.output_variable()); ILFree(item_id_list); throw_if_failed(result, "SHCreateItemFromParsingName failed"); /* This code requires Windows Vista or newer: ComPtr<IShellItem> folder_item; result = SHCreateItemFromParsingName(initial_directory16.c_str(), NULL, IID_PPV_ARGS(folder_item.output_variable())); throw_if_failed(result, "SHCreateItemFromParsingName failed"); */ if(!folder_item.is_null()) { result = open_dialog->SetFolder(folder_item); throw_if_failed(result, "IFileOpenDialog.SetFolder failed"); } } if(owner) result = open_dialog->Show(owner->get_display_window().get_hwnd()); else result = open_dialog->Show(0); if(SUCCEEDED(result)) { ComPtr<IShellItem> chosen_folder; result = open_dialog->GetResult(chosen_folder.output_variable()); throw_if_failed(result, "IFileOpenDialog.GetResult failed"); WCHAR *buffer = 0; result = chosen_folder->GetDisplayName(SIGDN_FILESYSPATH, &buffer); throw_if_failed(result, "IShellItem.GetDisplayName failed"); std::wstring output_directory16; try { output_directory16 = buffer; } catch (...) { CoTaskMemFree(buffer); throw; } CoTaskMemFree(buffer); selected_path = StringHelp::ucs2_to_utf8(output_directory16); return true; } else { return false; } } else { BROWSEINFO bi; ZeroMemory(&bi, sizeof(bi)); std::wstring::value_type path_buffer[FILENAME_MAX] = { 0 }; WCHAR Buffer[MAX_PATH]; memset(Buffer, 0, sizeof(WCHAR) * MAX_PATH); if(owner) bi.hwndOwner = owner->get_display_window().get_hwnd(); else bi.hwndOwner = 0; bi.pszDisplayName = Buffer; bi.lpszTitle = title16.c_str(); bi.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_SHAREABLE; LPCITEMIDLIST pFolder = SHBrowseForFolder(&bi); if (pFolder == NULL) return false; if (!SHGetPathFromIDList(pFolder, path_buffer)) throw Exception("Bad path for Browse Folder Dialog"); selected_path = StringHelp::ucs2_to_utf8(path_buffer); return true; } #elif defined(__APPLE__) // To do: add cocoa code here return false; #elif defined(I_LOVE_AUTOHELL_AND_FIXED_THE_GTK_CHECK) if (!gtk_init_check(NULL, NULL)) throw Exception("gtk_init_check Failed!"); GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new ("Open File", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); //printf("%s\n", filename); g_free (filename); } gtk_widget_destroy (dialog); unsigned int x_time = System::get_time(); while(true) { if(owner) XSync(owner->get_display_window().get_display(), True); gtk_main_iteration_do(FALSE); unsigned int x_time_now = System::get_time(); if ((x_time_now - x_time) > 250) break; } bool success = false; return success; #else return false; #endif }
void idle(void) { gtk_main_iteration_do(FALSE); sched_yield(); }
void gui_poll(bool active) { CURLMcode code; fd_set read_fd_set, write_fd_set, exc_fd_set; int max_fd; GPollFD *fd_list[1000]; unsigned int fd_count = 0; bool block = true; schedule_run(); if (browser_reformat_pending) block = false; if (active) { FD_ZERO(&read_fd_set); FD_ZERO(&write_fd_set); FD_ZERO(&exc_fd_set); code = curl_multi_fdset(fetch_curl_multi, &read_fd_set, &write_fd_set, &exc_fd_set, &max_fd); assert(code == CURLM_OK); for (int i = 0; i <= max_fd; i++) { if (FD_ISSET(i, &read_fd_set)) { GPollFD *fd = malloc(sizeof *fd); fd->fd = i; fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR; g_main_context_add_poll(0, fd, 0); fd_list[fd_count++] = fd; } if (FD_ISSET(i, &write_fd_set)) { GPollFD *fd = malloc(sizeof *fd); fd->fd = i; fd->events = G_IO_OUT | G_IO_ERR; g_main_context_add_poll(0, fd, 0); fd_list[fd_count++] = fd; } if (FD_ISSET(i, &exc_fd_set)) { GPollFD *fd = malloc(sizeof *fd); fd->fd = i; fd->events = G_IO_ERR; g_main_context_add_poll(0, fd, 0); fd_list[fd_count++] = fd; } } } gtk_main_iteration_do(block); for (unsigned int i = 0; i != fd_count; i++) { g_main_context_remove_poll(0, fd_list[i]); free(fd_list[i]); } schedule_run(); if (browser_reformat_pending) nsgtk_window_process_reformats(); }
void doPlatformIteration() { gtk_main_iteration_do(false); }
G_MODULE_EXPORT void on_doIt_clicked( GtkButton *button, gpointer data ) { printf("button clicked\n"); smf_t* smf = smf_new(); smf_track_t* track = smf_track_new(); smf_add_track(smf, track); smf_event_t* event; gboolean prevFrame[NUMBER_OF_KEYS] = { FALSE }; // Start video from beginning currentFrame = startFrame; //upper 9 notes have lyrics //2920 start while (currentFrame <= stopFrame) { int i = 0; if ( currentFrame == stopFrame ) { for (i = 0; i < NUMBER_OF_KEYS; i++ ) { noteOn[i] = FALSE; } } else { redrawFrame(); } // Why NUMBER_OF_KEYS - 10? Well, the lyrics in my example are printed across // the upper 10 notes and were being detected as notes themselves, causing odd // trilling when they scrolled past. This was a quick hack to make that stop. for ( i = 0; i < NUMBER_OF_KEYS - 10; i++ ) { char note = 0xd + i; char eventBytes[3] = { 0 }; eventBytes[1] = note; // which note to play eventBytes[2] = 0x7f; // full velocity (may toy with later) if (prevFrame[i] && (!noteOn[i])) { // Time to generate a note-off eventBytes[0] = 0x80; printf("note-off: %x, at frame %f\n", i + 0xd, currentFrame); } if ((!prevFrame[i]) && noteOn[i]) { // Time to generate a note-on eventBytes[0] = 0x90; printf("note-on: %x, at frame %f\n", i + 0xd, currentFrame); } prevFrame[i] = noteOn[i]; if ( eventBytes[0] ) { event = smf_event_new_from_pointer(eventBytes, 3); smf_track_add_event_seconds(track, event, currentFrame / 30.0); } } currentFrame++; gtk_main_iteration_do( FALSE ); } smf_save(smf, "output.mid"); }
void WebBrowserObject::OnEvent(void) { while (toplevel && gtk_events_pending()) { gtk_main_iteration_do(false); } }
static int build_table_from_csv_fh(FILE *in, GtkWidget **ret_view, GtkTreeModel **ret_store, GtkProgressBar *progress) { GType *column_types; int n, ncol, nrow=0; int sep = ','; GtkListStore *store=NULL; GtkWidget *view=NULL; if (csv_row_fread(in, (unsigned char *)csv_buf, CSV_BUFSIZE, (unsigned char **)csv_row, CSV_COLS, sep, CSV_QUOTES) > 0) { /* Create model with number of columns matching the csv input */ for(ncol=0; csv_row[ncol]; ncol++); column_types = malloc(sizeof(GType) * ncol); for (n=0; n<ncol; n++) { column_types[n] = G_TYPE_STRING; } store = gtk_list_store_newv(ncol, column_types); free(column_types); /* Create view, add colums */ GtkCellRenderer *renderer; GtkTreeViewColumn *column; view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store)); for (n = 0; n < ncol; n++) { renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(csv_row[n], renderer, "text", n, NULL); /* gtk_tree_view_column_set_sort_column_id(column, n); */ /* gtk_tree_view_column_set_reorderable(column, TRUE); */ gtk_tree_view_column_set_resizable(column, TRUE); gtk_tree_view_insert_column(GTK_TREE_VIEW(view), column, n); } /* Populate model */ GtkTreeIter iter; if (progress) { gtk_progress_bar_set_fraction(progress, 0.0); } while (csv_row_fread(in, (unsigned char *)csv_buf, CSV_BUFSIZE, (unsigned char **)csv_row, CSV_COLS, sep, CSV_QUOTES) > 0) { gtk_list_store_append(store, &iter); for(n = 0; n < ncol; n++) { gtk_list_store_set(store, &iter, n, csv_row[n], -1); } if (!(nrow % 256)) { while (gtk_events_pending()) gtk_main_iteration(); } gtk_main_iteration_do(FALSE); nrow++; if (progress) {}; } } g_object_unref(store); /* So only the treeview ref remains - it should be deleted when treeview is destroyed */ if (ret_store) *ret_store = GTK_TREE_MODEL(store); if (ret_view) *ret_view = view; return nrow; }
/********** * Name: process_single_gtk_event() * Input: none * Output: none * Function: Runs a single iteration of the mainloop. If no events are * available return (the FALSE flag). Non blocking. */ void process_single_gtk_event() { gtk_main_iteration_do(FALSE); }
static VALUE rg_s_main_iteration_do(G_GNUC_UNUSED VALUE self, VALUE blocking) { return CBOOL2RVAL(gtk_main_iteration_do(RVAL2CBOOL(blocking))); }
int fileio_load_archive(const char *filename, unsigned char **dataout, int *datasize, int *dataoffset, const char *filetoload, char *outname) { FILE *f; unsigned char idbuf[4]; int filesFound = 0; std::vector<char *> filelist; // list of files we can load in this archive // default case: outname is filename if (outname) { strcpy(outname, filename); } f = fopen(filename, "rb"); if (!f) { return 0; // no good } fread(idbuf, 4, 1, f); fclose(f); // printf("ID bytes %c %c %x %x\n", idbuf[0], idbuf[1], idbuf[2], idbuf[3]); // Handle all archives with common libarchive code if ((idbuf[0] == 'P') && (idbuf[1] == 'K') && (idbuf[2] == 0x03) && (idbuf[3] == 0x04) || // zip ((idbuf[0] == '7') && (idbuf[1] == 'z') && (idbuf[2] == 0xbc) && (idbuf[3] == 0xaf)) || // 7zip ((idbuf[0] == 0xfd) && (idbuf[1] == 0x37) && (idbuf[2] == 0x7a) && (idbuf[3] == 0x58)) || // txz ((idbuf[0] == 0x1f) && (idbuf[1] == 0x8b) && (idbuf[2] == 0x08) && (idbuf[3] == 0x00)) || // tgz ((idbuf[0] == 0x42) && (idbuf[1] == 0x5a) && (idbuf[2] == 0x68) && (idbuf[3] == 0x39)) // tbz ) { a = archive_read_new(); archive_read_support_filter_all(a); archive_read_support_format_all(a); r = archive_read_open_filename(a, filename, 10240); int64_t entry_size; if (r != ARCHIVE_OK) { print_message("Archive failed to open."); } while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { const char *currentFile = archive_entry_pathname(entry); unsigned char *fileContents; entry_size = archive_entry_size(entry); fileContents = (unsigned char *)malloc(entry_size); if (filetoload != NULL) { if (!strcmp(currentFile, filetoload)) { archive_read_data(a, fileContents, entry_size); archive_read_data_skip(a); r = archive_read_free(a); *datasize = entry_size; *dataout = fileContents; *dataoffset = 0; return 1; } } else { if (checkExtension(currentFile)) { char *tmpstr; tmpstr = (char *)malloc(strlen(currentFile)+1); strcpy(tmpstr, currentFile); // add to the file list filelist.push_back(tmpstr); filesFound++; } } } } else if ((idbuf[0] == 'R') && (idbuf[1] == 'a') && (idbuf[2] == 'r') && (idbuf[3] == '!')) { // it's rar print_message("Rar files are not supported."); } // if we found any files and weren't forced to load them, handle accordingly if (filesFound) { // only 1 file found, just run it if (filesFound == 1) { char fname[512]; strcpy(fname, filelist[0]); free(filelist[0]); filelist.clear(); strcpy(outname, fname); return fileio_load_archive(filename, dataout, datasize, dataoffset, fname, NULL); } else // multiple files we can handle found, give the user a choice { int sel; char fname[512]; GtkWidget *archselect = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW (archselect), "Pick game in archive"); gtk_window_set_modal(GTK_WINDOW (archselect), TRUE); GtkWidget *archbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(archselect), archbox); gtk_widget_show(archbox); GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL); gtk_box_pack_start(GTK_BOX(archbox), scrolledwindow, TRUE, TRUE, 0); gtk_widget_set_size_request(scrolledwindow, 340, 340); gtk_widget_show(scrolledwindow); GtkWidget *buttonbox = gtk_widget_new(GTK_TYPE_BOX, "halign", GTK_ALIGN_END, NULL); gtk_box_pack_start(GTK_BOX(archbox), buttonbox, FALSE, TRUE, 0); gtk_widget_show(buttonbox); GtkWidget *archtree = gtk_tree_view_new(); gtk_container_add(GTK_CONTAINER (scrolledwindow), archtree); gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW (archtree), FALSE); g_signal_connect(G_OBJECT(archtree), "button_press_event", G_CALLBACK(check_list_double), NULL); gtk_widget_show(archtree); // set up our tree store treestore = gtk_tree_store_new(1, G_TYPE_STRING); // attach the store to the tree gtk_tree_view_set_model(GTK_TREE_VIEW(archtree), GTK_TREE_MODEL(treestore)); for (int fn = 0; fn < filelist.size(); fn++) { gtk_tree_store_insert(treestore, &treeiters[fn], NULL, 999999); gtk_tree_store_set(treestore, &treeiters[fn], 0, filelist[fn], -1); } // create a cell renderer using the stock text one renderer = gtk_cell_renderer_text_new(); // create a display column using the renderer column = gtk_tree_view_column_new_with_attributes ("NES file", renderer, "text", 0, NULL); // add the display column and renderer to the tree view gtk_tree_view_append_column(GTK_TREE_VIEW (archtree), column); GtkWidget *archcancel = gtk_widget_new(GTK_TYPE_BUTTON, "label", GTK_STOCK_CANCEL, "halign", GTK_ALIGN_END, "margin-top", 8, "margin-bottom", 8, "margin-right", 8, NULL); gtk_button_set_use_stock(GTK_BUTTON(archcancel), TRUE); gtk_box_pack_start(GTK_BOX(buttonbox), archcancel, FALSE, FALSE, 0); gtk_widget_show(archcancel); GtkWidget *archok = gtk_widget_new(GTK_TYPE_BUTTON, "label", GTK_STOCK_OK, "halign", GTK_ALIGN_END, "margin-top", 8, "margin-bottom", 8, "margin-right", 8, NULL); gtk_button_set_use_stock(GTK_BUTTON(archok), TRUE); gtk_box_pack_start(GTK_BOX(buttonbox), archok, FALSE, FALSE, 0); gtk_widget_show(archok); // get the selection object too selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(archtree)); g_signal_connect(G_OBJECT(archcancel), "clicked", G_CALLBACK(on_archcancel_clicked), NULL); g_signal_connect(G_OBJECT(archok), "clicked", G_CALLBACK(on_archok_clicked), NULL); g_signal_connect(G_OBJECT(archselect), "destroy", G_CALLBACK(on_archselect_destroyed), NULL); gtk_widget_show(archselect); run_picker = true; cancelled = false; while (run_picker) { gtk_main_iteration_do(TRUE); } sel = find_current_selection(); gtk_widget_destroy(archselect); // was something picked? if ((sel != -1) && (!cancelled)) { strcpy(fname, filelist[sel]); } // free all the temp filenames for (int fn = 0; fn < filelist.size(); fn++) { free(filelist[fn]); } // and wipe the vector filelist.clear(); if ((sel != -1) && (!cancelled)) { if (outname) { strcpy(outname, fname); } return fileio_load_archive(filename, dataout, datasize, dataoffset, fname, NULL); } } } return 0; }
void note_show(ConboyNote *note, gboolean modify_history, gboolean scroll, gboolean select_row) { AppData *app_data = app_data_get(); UserInterface *ui = app_data->note_window; GtkTextBuffer *buffer = ui->buffer; GtkWindow *window = GTK_WINDOW(ui->window); /* Before we switch to a new note, we save the last one if it was modified. */ if (gtk_text_buffer_get_modified(buffer)) { note_save(ui); } /* Add to history */ if (modify_history || app_data->current_element == NULL) { add_to_history(note); } /* Toggle forward/backward buttons */ gtk_action_set_sensitive(ui->action_back, (gboolean) app_data->current_element->prev); gtk_action_set_sensitive(ui->action_forward, (gboolean) app_data->current_element->next); /* Block signals on TextBuffer until we are done with initializing the content. This is to prevent saves etc. */ g_signal_handlers_block_matched(buffer, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, ui); conboy_note_window_show_note(ui, note); /* Format note title and update window title */ note_format_title(buffer); note_set_window_title_from_buffer(window, buffer); /* Replace this. And use note->title instead */ /* Show widget and set focus to the text view */ gtk_widget_show(GTK_WIDGET(window)); gtk_widget_grab_focus(GTK_WIDGET(ui->view)); while (gtk_events_pending()) { gtk_main_iteration_do(FALSE); } /* Select first row if wanted */ if (select_row) { GtkTextIter start, end; gtk_text_buffer_get_iter_at_line(buffer, &start, 2); end = start; gtk_text_iter_forward_to_line_end(&end); gtk_text_buffer_select_range(buffer, &start, &end); } /* Scroll to cursor position */ if (scroll && !select_row) { GtkTextIter iter; gtk_text_buffer_get_iter_at_offset(buffer, &iter, note->cursor_position); gtk_text_buffer_place_cursor(buffer, &iter); GtkTextMark *mark = gtk_text_buffer_get_insert(buffer); gtk_text_view_scroll_to_mark(ui->view, mark, 0.1, TRUE, 0, 0.5); } /* Set the buffer to unmodified */ gtk_text_buffer_set_modified(buffer, FALSE); /* unblock signals */ g_signal_handlers_unblock_matched(buffer, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, ui); /* Update active tags */ conboy_note_buffer_update_active_tags(CONBOY_NOTE_BUFFER(buffer)); /* Update the state of the buttons */ conboy_note_window_update_button_states(ui); }
// the only difference is we ignore the return value from gtk_main_iteration_do(), since it will always be TRUE if gtk_main() was never called // gtk_main_iteration_do() will still run the main loop regardless static gboolean stepsIteration(gboolean block) { gtk_main_iteration_do(block); return stepsQuit; }
/* static void PreMult (TImage image) { int i; unsigned char *p; p = (unsigned char *) image->data; for (i=0; i<image->width*image->height*4; i+=4, p+=4) { p[0] = (p[0] * p[3] >> 8) + ((0xFF - p[3]) * 0xFF >> 8); p[1] = (p[1] * p[3] >> 8) + ((0xFF - p[3]) * 0xFF >> 8); p[2] = (p[2] * p[3] >> 8) + ((0xFF - p[3]) * 0xFF >> 8); p[3] = 0xFF; } } static GtkWidget *create_pixmap_png (GtkWidget *widget, const gchar *filename) { TImage image; GtkWidget *pixmap; GdkPixmap *gdkpixmap; GdkGC *gc; image = IMG_Read ((char *)filename); if (!image) { printf ("IMG_Read error: can't load %s\n", filename); exit (1); } PreMult (image); //printf ("%ix%i\n", image->width, image->height); gdkpixmap = gdk_pixmap_new (NULL, IMG_GetWidth(image), IMG_GetHeight(image), (gtk_widget_get_visual (widget))->depth); gc = gdk_gc_new (gdkpixmap); gdk_rgb_init (); gdk_draw_rgb_32_image (gdkpixmap, gc, 0, 0, IMG_GetWidth (image), IMG_GetHeight (image), GDK_RGB_DITHER_NONE, (unsigned char *) IMG_GetData (image), IMG_GetWidth (image) * 4); pixmap = gtk_pixmap_new (gdkpixmap, NULL); gdk_gc_unref (gc); gdk_pixmap_unref (gdkpixmap); IMG_Delete (image); return pixmap; } */ void DLG_Show (TDialogData *dd, const char *demo_name) { GtkWidget *window1; GtkWidget *fixed1; GtkWidget *button1; // GtkWidget *pixmap1; GtkWidget *button2; GtkWidget *frame1; GtkWidget *fixed2; GtkWidget *label1; GtkWidget *label2; GtkWidget *combo1; GtkWidget *combo_entry1; GtkWidget *checkbutton1; GList *glist; int dest_signal; char *res; gtk_init (NULL, NULL); window1 = gtk_window_new (GTK_WINDOW_DIALOG); gtk_object_set_data (GTK_OBJECT (window1), "window1", window1); gtk_widget_set_usize (window1, 256+16*2, 150); gtk_window_set_title (GTK_WINDOW (window1), _(demo_name)); gtk_window_set_position (GTK_WINDOW (window1), GTK_WIN_POS_CENTER); gtk_window_set_modal (GTK_WINDOW (window1), TRUE); gtk_window_set_policy (GTK_WINDOW (window1), FALSE, FALSE, FALSE); fixed1 = gtk_fixed_new (); gtk_widget_ref (fixed1); gtk_object_set_data_full (GTK_OBJECT (window1), "fixed1", fixed1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (fixed1); gtk_container_add (GTK_CONTAINER (window1), fixed1); button1 = gtk_button_new_with_label (_("run")); gtk_widget_ref (button1); gtk_object_set_data_full (GTK_OBJECT (window1), "button1", button1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (button1); gtk_fixed_put (GTK_FIXED (fixed1), button1, 64, 112); gtk_widget_set_uposition (button1, 64, 112); gtk_widget_set_usize (button1, 47, 22); gtk_signal_connect (GTK_OBJECT (button1), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit), NULL); //pixmap1 = create_pixmap_xpm (window1, "navmo.xpm"); /* pixmap1 = create_pixmap_png (window1, "menu/navmo.png"); gtk_widget_ref (pixmap1); gtk_object_set_data_full (GTK_OBJECT (window1), "pixmap1", pixmap1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (pixmap1); gtk_fixed_put (GTK_FIXED (fixed1), pixmap1, 128, 64); gtk_widget_set_uposition (pixmap1, 128, 64); gtk_widget_set_usize (pixmap1, 21, 21); */ button2 = gtk_button_new_with_label (_("exit")); gtk_widget_ref (button2); gtk_object_set_data_full (GTK_OBJECT (window1), "button2", button2, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (button2); gtk_fixed_put (GTK_FIXED (fixed1), button2, 174, 112); gtk_widget_set_uposition (button2, 174, 112); gtk_widget_set_usize (button2, 47, 22); gtk_signal_connect (GTK_OBJECT (button2), "clicked", GTK_SIGNAL_FUNC (gtk_exit), NULL); frame1 = gtk_frame_new (_(demo_name)); gtk_widget_ref (frame1); gtk_object_set_data_full (GTK_OBJECT (window1), "frame1", frame1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (frame1); gtk_fixed_put (GTK_FIXED (fixed1), frame1, 16, 11); gtk_widget_set_uposition (frame1, 16, 11); gtk_widget_set_usize (frame1, 256, 95); gtk_frame_set_label_align (GTK_FRAME (frame1), 0.5, 0.5); gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_ETCHED_OUT); fixed2 = gtk_fixed_new (); gtk_widget_ref (fixed2); gtk_object_set_data_full (GTK_OBJECT (window1), "fixed2", fixed2, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (fixed2); gtk_container_add (GTK_CONTAINER (frame1), fixed2); label1 = gtk_label_new (_(">> windowed ::")); gtk_widget_ref (label1); gtk_object_set_data_full (GTK_OBJECT (window1), "label1", label1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (label1); gtk_fixed_put (GTK_FIXED (fixed2), label1, 16, 12); gtk_widget_set_uposition (label1, 16, 12); gtk_widget_set_usize (label1, 100, 16); label2 = gtk_label_new (_(">> resolution ::")); gtk_widget_ref (label2); gtk_object_set_data_full (GTK_OBJECT (window1), "label2", label2, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (label2); gtk_fixed_put (GTK_FIXED (fixed2), label2, 16, 44); gtk_widget_set_uposition (label2, 16, 44); gtk_widget_set_usize (label2, 100, 16); combo1 = gtk_combo_new (); gtk_widget_ref (combo1); gtk_object_set_data_full (GTK_OBJECT (window1), "combo1", combo1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (combo1); gtk_fixed_put (GTK_FIXED (fixed2), combo1, 112, 41); gtk_widget_set_uposition (combo1, 112, 41); gtk_widget_set_usize (combo1, 108, 22); combo_entry1 = GTK_COMBO (combo1)->entry; gtk_widget_ref (combo_entry1); gtk_object_set_data_full (GTK_OBJECT (window1), "combo_entry1", combo_entry1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (combo_entry1); checkbutton1 = gtk_check_button_new_with_label (""); gtk_widget_ref (checkbutton1); gtk_object_set_data_full (GTK_OBJECT (window1), "checkbutton1", checkbutton1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (checkbutton1); gtk_fixed_put (GTK_FIXED (fixed2), checkbutton1, 203, 7); gtk_widget_set_uposition (checkbutton1, 203, 7); gtk_widget_set_usize (checkbutton1, 16, 24); GTK_WIDGET_UNSET_FLAGS (checkbutton1, GTK_CAN_FOCUS); glist = NULL; glist = g_list_append (glist, "320x200"); glist = g_list_append (glist, "320x240"); glist = g_list_append (glist, "640x400"); glist = g_list_append (glist, "640x480"); glist = g_list_append (glist, "800x600"); glist = g_list_append (glist, "1024x768"); glist = g_list_append (glist, "1280x1024"); gtk_combo_set_popdown_strings (GTK_COMBO(combo1), glist); gtk_entry_set_text (GTK_ENTRY(combo_entry1), "800x600"); dest_signal = gtk_signal_connect (GTK_OBJECT (window1), "destroy", GTK_SIGNAL_FUNC (gtk_exit), NULL); gtk_widget_show (window1); gtk_main ( ); // Get resolution res = gtk_entry_get_text (GTK_ENTRY(combo_entry1)); if (!strcmp (res, "320x200")) { dd->width = 320; dd->height = 200; } else if (!strcmp (res, "320x240")) { dd->width = 320; dd->height = 240; } else if (!strcmp (res, "640x400")) { dd->width = 640; dd->height = 400; } else if (!strcmp (res, "640x480")) { dd->width = 640; dd->height = 480; } else if (!strcmp (res, "800x600")) { dd->width = 800; dd->height = 600; } else if (!strcmp (res, "1024x768")) { dd->width = 1024; dd->height = 768; } else if (!strcmp (res, "1280x1024")) { dd->width = 1280; dd->height = 1024; } else { // default 800x600 dd->width = 800; dd->height = 600; } dd->windowed = (int) GTK_TOGGLE_BUTTON (checkbutton1)->active; gtk_signal_disconnect (GTK_OBJECT (window1), dest_signal); gtk_widget_hide (window1); gtk_widget_destroy (window1); gtk_main_iteration_do (0); }
//Creates a list of times which the aubio onset detector thinks are note onset times for the audio Denemo->si->recording //Result is placed in Denemo->si->note_onsets void generate_note_onsets (void) { DenemoRecording *audio = Denemo.project->movement->recording; gint channels = audio->channels; smpl_t threshold = 0.3; smpl_t silence = -90.; uint_t buffer_size = 1024; uint_t overlap_size = 512; uint_t samplerate = 44100; aubio_onset_t *o = new_aubio_onset("default", buffer_size, overlap_size, samplerate); fvec_t *ibuf = new_fvec (overlap_size); fvec_t *onset = new_fvec (2); unsigned int pos = 0; /*frames%dspblocksize */ unsigned int i; /*channels */ unsigned int j; /*frames */ busy_cursor (Denemo.notebook); gtk_window_set_modal (progressbar (_("Analysing Audio"), NULL), TRUE); rewind_audio (); if (audio->notes) { g_list_free_full (audio->notes, g_free); audio->notes = NULL; } for (j = 0; j < (unsigned) audio->nframes; j++) { sf_read_float (audio->sndfile, ibuf->data + pos, 2); //g_debug("\t%f", ibuf->data[0][pos]); if (pos == overlap_size - 1) { /* block loop */ gtk_main_iteration_do (FALSE); aubio_onset_do (o, ibuf, onset); while (gtk_events_pending ()) gtk_main_iteration (); if(onset->data[0] != 0) { DenemoRecordedNote *note = g_malloc0(sizeof(DenemoRecordedNote)); note->timing = aubio_onset_get_last(o);/* aubio_onset_get_delay_s(o) for seconds */ audio->notes = g_list_append (audio->notes, note); } pos = -1; /* so it will be zero next j loop */ } /* end of if pos==overlap_size-1 */ pos++; } del_aubio_onset (o); del_fvec (ibuf); del_fvec (onset); aubio_cleanup (); progressbar_stop (); normal_cursor (Denemo.notebook); }
void create_startwin(void) { GtkWidget *banner, *label, *content, *scroll; GtkWidget *hbox1, *fixed1; GdkPixbuf *startbanner_pixbuf; startwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (startwin), apptitle); gtk_window_set_position (GTK_WINDOW (startwin), GTK_WIN_POS_CENTER); gtk_window_set_resizable (GTK_WINDOW (startwin), FALSE); gtk_window_set_type_hint (GTK_WINDOW (startwin), GDK_WINDOW_TYPE_HINT_DIALOG); hbox1 = gtk_hbox_new (FALSE, 0); gtk_widget_show (hbox1); gtk_container_add (GTK_CONTAINER (startwin), hbox1); startbanner_pixbuf = gdk_pixbuf_from_pixdata(&startbanner_pixdata, FALSE, NULL); banner = gtk_image_new_from_pixbuf(startbanner_pixbuf); g_object_unref((gpointer)startbanner_pixbuf); gtk_widget_show (banner); gtk_box_pack_start (GTK_BOX (hbox1), banner, FALSE, FALSE, 0); fixed1 = gtk_fixed_new (); gtk_widget_show (fixed1); gtk_box_pack_start (GTK_BOX (hbox1), fixed1, TRUE, TRUE, 0); gtk_widget_set_size_request (fixed1, 390, -1); label = gtk_label_new (startwin_labeltext); gtk_widget_show (label); gtk_fixed_put (GTK_FIXED (fixed1), label, 6, 6); gtk_widget_set_size_request (label, 378, 16); gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER); scroll = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scroll); gtk_fixed_put (GTK_FIXED (fixed1), scroll, 6, 28); gtk_widget_set_size_request (scroll, 378, 248); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); content = gtk_text_view_new (); gtk_widget_show (content); gtk_container_add (GTK_CONTAINER(scroll), content); //gtk_fixed_put (GTK_FIXED (fixed1), content, 6, 28); gtk_widget_set_size_request (content, 378, 248); gtk_text_view_set_editable (GTK_TEXT_VIEW (content), FALSE); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (content), GTK_WRAP_WORD); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (content), FALSE); g_signal_connect ((gpointer) startwin, "delete_event", G_CALLBACK (on_startwin_delete_event), NULL); /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (startwin, startwin, "startwin"); GLADE_HOOKUP_OBJECT (startwin, banner, "banner"); GLADE_HOOKUP_OBJECT (startwin, label, "label"); GLADE_HOOKUP_OBJECT (startwin, scroll, "scroll"); GLADE_HOOKUP_OBJECT (startwin, content, "content"); g_signal_connect((gpointer)startwin, "destroy", G_CALLBACK(gtk_widget_destroyed), (gpointer)&startwin); gtk_widget_show (startwin); gtk_main_iteration_do (FALSE); }
void pApplication::processEvents() { while(pendingEvents()) gtk_main_iteration_do(false); }
int MsdDevice::Configure(int port, const std::string& api, void *data) { GtkWidget *ro_frame, *ro_label, *rs_hbox, *rs_label, *rs_cb, *vbox; GtkWidget *dlg = gtk_dialog_new_with_buttons ( "Mass Storage Settings", GTK_WINDOW (data), GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER); gtk_window_set_resizable (GTK_WINDOW (dlg), TRUE); GtkWidget *dlg_area_box = gtk_dialog_get_content_area (GTK_DIALOG (dlg)); ro_frame = gtk_frame_new (NULL); gtk_box_pack_start (GTK_BOX (dlg_area_box), ro_frame, TRUE, FALSE, 5); ro_label = gtk_label_new ("Select USB image:"); gtk_frame_set_label_widget (GTK_FRAME (ro_frame), ro_label); gtk_label_set_use_markup (GTK_LABEL (ro_label), TRUE); vbox = gtk_vbox_new (FALSE, 5); gtk_container_add (GTK_CONTAINER (ro_frame), vbox); rs_hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), rs_hbox, FALSE, TRUE, 0); GtkWidget *entry = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (entry), MAX_PATH); //TODO max length std::string var; if (LoadSetting(port, APINAME, N_CONFIG_PATH, var)) gtk_entry_set_text(GTK_ENTRY(entry), var.c_str()); g_signal_connect (entry, "changed", G_CALLBACK (entryChanged), NULL); GtkWidget *button = gtk_button_new_with_label ("Browse"); gtk_button_set_image(GTK_BUTTON (button), gtk_image_new_from_icon_name ("gtk-open", GTK_ICON_SIZE_BUTTON)); g_signal_connect (button, "clicked", G_CALLBACK (fileChooser), entry); gtk_box_pack_start (GTK_BOX (rs_hbox), entry, TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (rs_hbox), button, FALSE, FALSE, 5); gtk_widget_show_all (dlg); gint result = gtk_dialog_run (GTK_DIALOG (dlg)); std::string path = gtk_entry_get_text(GTK_ENTRY(entry)); gtk_widget_destroy (dlg); // Wait for all gtk events to be consumed ... while (gtk_events_pending ()) gtk_main_iteration_do (FALSE); if (result == GTK_RESPONSE_OK) { if(SaveSetting(port, APINAME, N_CONFIG_PATH, path)) return RESULT_OK; else return RESULT_FAILED; } return RESULT_CANCELED; }
/** * Attempts to initialize the graphical video display. Returns 0 on * success, -1 on failure. */ int InitVideo(FCEUGI *gi) { // XXX soules - const? is this necessary? const SDL_VideoInfo *vinf; int error, flags = 0; int doublebuf, xstretch, ystretch, xres, yres, show_fps; FCEUI_printf("Initializing video..."); // load the relevant configuration variables g_config->getOption("SDL.Fullscreen", &s_fullscreen); g_config->getOption("SDL.DoubleBuffering", &doublebuf); #ifdef OPENGL g_config->getOption("SDL.OpenGL", &s_useOpenGL); #endif g_config->getOption("SDL.SpecialFilter", &s_sponge); g_config->getOption("SDL.XStretch", &xstretch); g_config->getOption("SDL.YStretch", &ystretch); g_config->getOption("SDL.LastXRes", &xres); g_config->getOption("SDL.LastYRes", &yres); g_config->getOption("SDL.ClipSides", &s_clipSides); g_config->getOption("SDL.NoFrame", &noframe); g_config->getOption("SDL.ShowFPS", &show_fps); // check the starting, ending, and total scan lines FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline); s_tlines = s_erendline - s_srendline + 1; // check if we should auto-set x/y resolution // check for OpenGL and set the global flags #if OPENGL if(s_useOpenGL && !s_sponge) { flags = SDL_OPENGL; } #endif // initialize the SDL video subsystem if it is not already active if(!SDL_WasInit(SDL_INIT_VIDEO)) { error = SDL_InitSubSystem(SDL_INIT_VIDEO); if(error) { FCEUD_PrintError(SDL_GetError()); return -1; } } s_inited = 1; // shows the cursor within the display window SDL_ShowCursor(1); // determine if we can allocate the display on the video card vinf = SDL_GetVideoInfo(); if(vinf->hw_available) { flags |= SDL_HWSURFACE; } // get the monitor's current resolution if we do not already have it if(s_nativeWidth < 0) { s_nativeWidth = vinf->current_w; } if(s_nativeHeight < 0) { s_nativeHeight = vinf->current_h; } // check to see if we are showing FPS FCEUI_SetShowFPS(show_fps); // check if we are rendering fullscreen if(s_fullscreen) { int no_cursor; g_config->getOption("SDL.NoFullscreenCursor", &no_cursor); flags |= SDL_FULLSCREEN; SDL_ShowCursor(!no_cursor); } else { SDL_ShowCursor(1); } if(noframe) { flags |= SDL_NOFRAME; } // gives the SDL exclusive palette control... ensures the requested colors // flags |= SDL_HWPALETTE; // enable double buffering if requested and we have hardware support #ifdef OPENGL if(s_useOpenGL) { FCEU_printf("Initializing with OpenGL (Disable with '--opengl 0').\n"); if(doublebuf) { SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); } } else #endif if(doublebuf && (flags & SDL_HWSURFACE)) { flags |= SDL_DOUBLEBUF; } if(s_fullscreen) { int desbpp, autoscale; g_config->getOption("SDL.BitsPerPixel", &desbpp); g_config->getOption("SDL.AutoScale", &autoscale); if (autoscale) { double auto_xscale = GetXScale(xres); double auto_yscale = GetYScale(yres); double native_ratio = ((double)NWIDTH) / s_tlines; double screen_ratio = ((double)xres) / yres; int keep_ratio; g_config->getOption("SDL.KeepRatio", &keep_ratio); // Try to choose resolution if (screen_ratio < native_ratio) { // The screen is narrower than the original. Maximizing width will not clip auto_xscale = auto_yscale = GetXScale(xres); if (keep_ratio) auto_yscale = GetYScale(yres); } else { auto_yscale = auto_xscale = GetYScale(yres); if (keep_ratio) auto_xscale = GetXScale(xres); } s_exs = auto_xscale; s_eys = auto_yscale; } else { g_config->getOption("SDL.XScale", &s_exs); g_config->getOption("SDL.YScale", &s_eys); } g_config->getOption("SDL.SpecialFX", &s_eefx); #ifdef OPENGL if(!s_useOpenGL) { s_exs = (int)s_exs; s_eys = (int)s_eys; } else { desbpp = 0; } // -Video Modes Tag- if(s_sponge) { if(s_sponge == 4 || s_sponge == 5) { s_exs = s_eys = 3; } else { s_exs = s_eys = 2; } s_eefx = 0; if(s_sponge == 1 || s_sponge == 4) { desbpp = 32; } } if((s_useOpenGL && !xstretch) || !s_useOpenGL) #endif if(xres < (NWIDTH * s_exs) || s_exs <= 0.01) { FCEUD_PrintError("xscale out of bounds."); KillVideo(); return -1; } #ifdef OPENGL if((s_useOpenGL && !ystretch) || !s_useOpenGL) #endif if(yres < s_tlines * s_eys || s_eys <= 0.01) { FCEUD_PrintError("yscale out of bounds."); KillVideo(); return -1; } #ifdef OPENGL s_screen = SDL_SetVideoMode(s_useOpenGL ? s_nativeWidth : xres, s_useOpenGL ? s_nativeHeight : yres, desbpp, flags); #else s_screen = SDL_SetVideoMode(xres, yres, desbpp, flags); #endif if(!s_screen) { FCEUD_PrintError(SDL_GetError()); return -1; } } else { int desbpp; g_config->getOption("SDL.BitsPerPixel", &desbpp); g_config->getOption("SDL.XScale", &s_exs); g_config->getOption("SDL.YScale", &s_eys); g_config->getOption("SDL.SpecialFX", &s_eefx); // -Video Modes Tag- if(s_sponge) { if(s_sponge >= 4) { s_exs = s_eys = 3; } else { s_exs = s_eys = 2; } s_eefx = 0; } #ifdef OPENGL if(!s_useOpenGL) { s_exs = (int)s_exs; s_eys = (int)s_eys; } if(s_exs <= 0.01) { FCEUD_PrintError("xscale out of bounds."); KillVideo(); return -1; } if(s_eys <= 0.01) { FCEUD_PrintError("yscale out of bounds."); KillVideo(); return -1; } if(s_sponge && s_useOpenGL) { FCEUD_PrintError("scalers not compatible with openGL mode."); KillVideo(); return -1; } #endif #if defined(_GTK) && defined(SDL_VIDEO_DRIVER_X11) if(noGui == 0) { while (gtk_events_pending()) gtk_main_iteration_do(FALSE); char SDL_windowhack[128]; sprintf(SDL_windowhack, "SDL_WINDOWID=%u", (unsigned int)GDK_WINDOW_XID(gtk_widget_get_window(evbox))); SDL_putenv(SDL_windowhack); // init SDL video if (SDL_WasInit(SDL_INIT_VIDEO)) SDL_QuitSubSystem(SDL_INIT_VIDEO); if ( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't init SDL video: %s\n", SDL_GetError()); gtk_main_quit(); } } #endif s_screen = SDL_SetVideoMode((int)(NWIDTH * s_exs), (int)(s_tlines * s_eys), desbpp, flags); if(!s_screen) { FCEUD_PrintError(SDL_GetError()); return -1; } #ifdef _GTK if(noGui == 0) { GtkRequisition req; gtk_widget_size_request(GTK_WIDGET(MainWindow), &req); gtk_window_resize(GTK_WINDOW(MainWindow), req.width, req.height); } #endif } s_curbpp = s_screen->format->BitsPerPixel; if(!s_screen) { FCEUD_PrintError(SDL_GetError()); KillVideo(); return -1; } #if 0 // XXX soules - this would be creating a surface on the video // card, but was commented out for some reason... s_BlitBuf = SDL_CreateRGBSurface(SDL_HWSURFACE, 256, 240, s_screen->format->BitsPerPixel, s_screen->format->Rmask, s_screen->format->Gmask, s_screen->format->Bmask, 0); #endif FCEU_printf(" Video Mode: %d x %d x %d bpp %s\n", s_screen->w, s_screen->h, s_screen->format->BitsPerPixel, s_fullscreen ? "full screen" : ""); if(s_curbpp != 8 && s_curbpp != 16 && s_curbpp != 24 && s_curbpp != 32) { FCEU_printf(" Sorry, %dbpp modes are not supported by FCE Ultra. Supported bit depths are 8bpp, 16bpp, and 32bpp.\n", s_curbpp); KillVideo(); return -1; } // if the game being run has a name, set it as the window name if(gi) { if(gi->name) { SDL_WM_SetCaption((const char *)gi->name, (const char *)gi->name); } else { SDL_WM_SetCaption(FCEU_NAME_AND_VERSION,"FCE Ultra"); } } // create the surface for displaying graphical messages #ifdef LSB_FIRST s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data, 32, 32, 24, 32 * 3, 0xFF, 0xFF00, 0xFF0000, 0x00); #else s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data, 32, 32, 24, 32 * 3, 0xFF0000, 0xFF00, 0xFF, 0x00); #endif SDL_WM_SetIcon(s_IconSurface,0); s_paletterefresh = 1; // XXX soules - can't SDL do this for us? // if using more than 8bpp, initialize the conversion routines if(s_curbpp > 8) { InitBlitToHigh(s_curbpp >> 3, s_screen->format->Rmask, s_screen->format->Gmask, s_screen->format->Bmask, s_eefx, s_sponge, 0); #ifdef OPENGL if(s_useOpenGL) { int openGLip; g_config->getOption("SDL.OpenGLip", &openGLip); if(!InitOpenGL(NOFFSET, 256 - (s_clipSides ? 8 : 0), s_srendline, s_erendline + 1, s_exs, s_eys, s_eefx, openGLip, xstretch, ystretch, s_screen)) { FCEUD_PrintError("Error initializing OpenGL."); KillVideo(); return -1; } } #endif }
int auxio_load_archive(const char *filename, unsigned char **dataout, int *datasize, int *dataoffset, const char *filetoload, char *outname) { FILE *f; unsigned char idbuf[4]; int filesFound = 0; std::vector<char *> filelist; // list of files we can load in this archive // default case: outname is filename if (outname) { strcpy(outname, filename); } f = fopen(filename, "rb"); if (!f) { return 0; // no good } fread(idbuf, 4, 1, f); fclose(f); // printf("ID bytes %c %c %x %x\n", idbuf[0], idbuf[1], idbuf[2], idbuf[3]); if ((idbuf[0] == 'P') && (idbuf[1] == 'K') && (idbuf[2] == 0x03) && (idbuf[3] == 0x04)) { // it's zip unzFile zipArchive; char file_name[1024]; unz_file_info info; int nlen; int ret = 0; zipArchive = unzOpen(filename); if (!zipArchive) { return 0; } unzGoToFirstFile(zipArchive); for (;;) { if (unzGetCurrentFileInfo(zipArchive, &info, file_name, 1024, NULL, 0, NULL, 0) == UNZ_OK) { if (filetoload != NULL) { if (!strcasecmp(filetoload, file_name)) { int length; unsigned char *buffer; unzOpenCurrentFile(zipArchive); length = info.uncompressed_size; buffer = (unsigned char *)malloc(length); ret = unzReadCurrentFile(zipArchive, buffer, length); if (ret != length) { free(buffer); return 0; } unzCloseCurrentFile(zipArchive); unzClose(zipArchive); *datasize = length; *dataout = buffer; *dataoffset = 0; return 1; } } else { if (checkExtension(file_name)) { char *tmpstr; tmpstr = (char *)malloc(strlen(file_name)+1); strcpy(tmpstr, file_name); // add to the file list filelist.push_back(tmpstr); filesFound++; } } } else { break; } ret = unzGoToNextFile(zipArchive); if (ret == UNZ_END_OF_LIST_OF_FILE) { break; } if (ret != UNZ_OK) { unzClose(zipArchive); return 0; } } unzClose(zipArchive); } else if ((idbuf[0] == '7') && (idbuf[1] == 'z') && (idbuf[2] == 0xbc) && (idbuf[3] == 0xaf)) { // it's 7zip CFileInStream archiveStream; SRes res; CSzArEx db; /* 7z archive database structure */ ISzAlloc allocImp; /* memory functions for main pool */ ISzAlloc allocTempImp; /* memory functions for temporary pool */ archiveStream.File = fopen(filename, "rb"); if (!archiveStream.File) { return 0; } archiveStream.InStream.Read = SzFileReadImp; archiveStream.InStream.Seek = SzFileSeekImp; allocImp.Alloc = SzAlloc; allocImp.Free = SzFree; allocTempImp.Alloc = SzAllocTemp; allocTempImp.Free = SzFreeTemp; // init 7zip internals CrcGenerateTable(); SzArEx_Init(&db); res = SzArEx_Open(&db, &archiveStream.InStream, &allocImp, &allocTempImp); if (res == SZ_OK) { int i; for (i = 0; i < db.db.NumFiles; i++) { CSzFileItem *item = db.db.Files + i; if (!item->IsDirectory) { if (filetoload != NULL) { if (!strcasecmp(filetoload, item->Name)) { UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */ Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */ size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */ size_t offset; size_t outSizeProcessed; res = SzAr_Extract(&db, &archiveStream.InStream, i, &blockIndex, &outBuffer, &outBufferSize, &offset, &outSizeProcessed, &allocImp, &allocTempImp); if (res == SZ_OK) { SzArEx_Free(&db, &allocImp); fclose(archiveStream.File); *datasize = (int)outBufferSize; *dataout = (unsigned char *)outBuffer; *dataoffset = (int)offset; return 1; } else { std::cout << "Error extracting 7zip!\n"; } } } if (checkExtension(item->Name)) { char *tmpstr; tmpstr = (char *)malloc(strlen(item->Name)+1); strcpy(tmpstr, item->Name); // add to the file list filelist.push_back(tmpstr); filesFound++; } } } SzArEx_Free(&db, &allocImp); fclose(archiveStream.File); } } else if ((idbuf[0] == 'R') && (idbuf[1] == 'a') && (idbuf[2] == 'r') && (idbuf[3] == '!')) { // it's rar } // if we found any files and weren't forced to load them, handle accordingly if (filesFound) { // only 1 file found, just run it if (filesFound == 1) { char fname[512]; strcpy(fname, filelist[0]); free(filelist[0]); filelist.clear(); strcpy(outname, fname); return auxio_load_archive(filename, dataout, datasize, dataoffset, fname, NULL); } else // multiple files we can handle found, give the user a choice { int sel; char fname[512]; filepicker = create_archselect(); tree = lookup_widget(filepicker, "archtree"); gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW (tree), FALSE); g_signal_connect(G_OBJECT(tree), "button_press_event", G_CALLBACK(check_list_double), NULL); // set up our tree store treestore = gtk_tree_store_new(1, G_TYPE_STRING); // attach the store to the tree gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(treestore)); // create a cell renderer using the stock text one renderer = gtk_cell_renderer_text_new(); // create a display column using the renderer column = gtk_tree_view_column_new_with_attributes ("NES file", renderer, "text", 0, NULL); // add the display column and renderer to the tree view gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); // get the selection object too selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); // add the filenames for (int fn = 0; fn < filelist.size(); fn++) { gtk_tree_store_insert(treestore, &treeiters[fn], NULL, 999999); gtk_tree_store_set(treestore, &treeiters[fn], 0, filelist[fn], -1); } gtk_widget_show(filepicker); run_picker = true; cancelled = false; while (run_picker) { gtk_main_iteration_do(FALSE); } sel = find_current_selection(); gtk_widget_destroy(filepicker); // was something picked? if ((sel != -1) && (!cancelled)) { strcpy(fname, filelist[sel]); } // free all the temp filenames for (int fn = 0; fn < filelist.size(); fn++) { free(filelist[fn]); } // and wipe the vector filelist.clear(); if ((sel != -1) && (!cancelled)) { if (outname) { strcpy(outname, fname); } return auxio_load_archive(filename, dataout, datasize, dataoffset, fname, NULL); } } } return 0; }