static void SetCellColour(int row, int col, moverecord *pmr) { GtkStyle *pStyle = NULL; if (fStyledGamelist) { if (pmr->lt == LUCK_VERYGOOD) pStyle = psLucky[LUCK_VERYGOOD]; if (pmr->lt == LUCK_VERYBAD) pStyle = psLucky[LUCK_VERYBAD]; if (pmr->n.stMove == SKILL_DOUBTFUL) AddStyle(&pStyle, psChequerErrors[SKILL_DOUBTFUL]); if (pmr->stCube == SKILL_DOUBTFUL) AddStyle(&pStyle, psCubeErrors[SKILL_DOUBTFUL]); if (pmr->n.stMove == SKILL_BAD) AddStyle(&pStyle, psChequerErrors[SKILL_BAD]); if (pmr->stCube == SKILL_BAD) AddStyle(&pStyle, psCubeErrors[SKILL_BAD]); if (pmr->n.stMove == SKILL_VERYBAD) AddStyle(&pStyle, psChequerErrors[SKILL_VERYBAD]); if (pmr->stCube == SKILL_VERYBAD) AddStyle(&pStyle, psCubeErrors[SKILL_VERYBAD]); } if (!pStyle) pStyle = psGameList; gtk_clist_set_cell_style(GTK_CLIST(pwGameList), row, col, pStyle); }
static void update_row (int row, XSettingsSetting *setting) { char buffer[256]; GtkStyle *style; const char *type; if (setting->type != XSETTINGS_TYPE_COLOR) gtk_clist_set_cell_style (GTK_CLIST (settings_clist), row, VALUE, NULL); switch (setting->type) { case XSETTINGS_TYPE_INT: type = "INT"; sprintf (buffer, "%d", setting->data.v_int); gtk_clist_set_text (GTK_CLIST (settings_clist), row, VALUE, buffer); break; case XSETTINGS_TYPE_STRING: type = "STRING"; gtk_clist_set_text (GTK_CLIST (settings_clist), row, VALUE, setting->data.v_string); break; case XSETTINGS_TYPE_COLOR: type = "COLOR"; gtk_clist_set_text (GTK_CLIST (settings_clist), row, VALUE, ""); style = gtk_style_copy (settings_clist->style); style->base[GTK_STATE_NORMAL].red = setting->data.v_color.red; style->base[GTK_STATE_NORMAL].green = setting->data.v_color.green; style->base[GTK_STATE_NORMAL].blue = setting->data.v_color.blue; style->bg[GTK_STATE_SELECTED].red = setting->data.v_color.red; style->bg[GTK_STATE_SELECTED].green = setting->data.v_color.green; style->bg[GTK_STATE_SELECTED].blue = setting->data.v_color.blue; gtk_clist_set_cell_style (GTK_CLIST (settings_clist), row, VALUE, style); gtk_style_unref (style); break; default: g_assert_not_reached (); } gtk_clist_set_text (GTK_CLIST (settings_clist), row, TYPE, type); sprintf (buffer, "%ld", setting->last_change_serial); gtk_clist_set_text (GTK_CLIST (settings_clist), row, SERIAL, buffer); }
void ghack_menu_window_add_menu( GtkWidget *menuWin, gpointer menu_item, gpointer data) { GHackMenuItem* item; GtkWidget *clist; gchar buf[BUFSZ]="", accelBuf[BUFSZ]=""; gchar *pbuf; char *text[4] = { buf, NULL, NULL, NULL }; gint nCurrentRow = -1, numItems = -1; MenuWinType isMenu; GtkStyle *bigStyle = NULL; gboolean item_selectable; GdkImlibImage* image; static gboolean special; g_assert (menu_item != NULL); item = (GHackMenuItem*) menu_item; item_selectable = ( item->identifier->a_int == 0)? FALSE : TRUE; isMenu = (MenuWinType) GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu")); clist = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (menuWin), "clist")); g_assert (clist != NULL); /* This is a special kludge to make the special hidden help menu item work as designed */ if ( special==TRUE ) { special=FALSE; item_selectable=TRUE; } if ( ! strcmp( item->str, "The NetHack license.")) { special=TRUE; } if (item->str) { /* First, make a new blank entry in the clist */ nCurrentRow = gtk_clist_append (GTK_CLIST (clist), text); if (item->glyph != NO_GLYPH) { image = ghack_image_from_glyph( item->glyph, FALSE); if (image==NULL || image->pixmap==NULL) { g_warning("Bummer -- having to force rendering for glyph %d!", item->glyph); /* wierd -- pixmap is NULL so retry rendering it */ image = ghack_image_from_glyph( item->glyph, TRUE); } if (image==NULL || image->pixmap==NULL) { g_error("Aiiee! glyph is still NULL for item\n\"%s\"", item->str); } else gtk_clist_set_pixmap (GTK_CLIST (clist), nCurrentRow, 1, gdk_imlib_move_image( image), gdk_imlib_move_mask( image)); } if (item->accelerator) { /* FIXME: handle accelerator, */ g_snprintf(accelBuf, sizeof(accelBuf), "%c ", item->accelerator); gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 0, accelBuf); g_snprintf(buf, sizeof(buf), "%s", item->str); gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); } else { if (item->group_accel) { /* FIXME: maybe some day I should try to handle * group accelerators... */ } if (( (item->attr == 0) && (item->identifier->a_int != 0)) || (special ==TRUE) ) { numItems = GPOINTER_TO_INT( gtk_object_get_data( GTK_OBJECT(clist), "numItems") )+1; /* Ok, now invent a unique accelerator */ if ( ('a'+numItems) <= 'z' ) { g_snprintf(accelBuf, sizeof(accelBuf), "%c ", 'a'+numItems); gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf); } else if ( ('A'+numItems-26)<='Z') { g_snprintf(accelBuf, sizeof(accelBuf), "%c ", 'A'+numItems-26); gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf); } else { accelBuf[0] = buf[0] = 0; } g_snprintf(buf, sizeof(buf), "%s", item->str); gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); gtk_object_set_data (GTK_OBJECT (clist), "numItems", GINT_TO_POINTER (numItems)); /* This junk is to specially handle the options menu */ pbuf = strstr( buf, " ["); if (pbuf == NULL) { pbuf = strstr( buf, "\t["); } if (pbuf != NULL) { *pbuf=0; pbuf++; gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 3, pbuf); } } /* FIXME: handle more than 26*2 accelerators (but how? * since I only have so many keys to work with???) else { foo(); } */ else { g_snprintf(buf, sizeof(buf), "%s", item->str); pbuf = strstr( buf, " ["); if (pbuf == NULL) { pbuf = strstr( buf, "\t["); } if (pbuf != NULL) { *pbuf=0; pbuf++; gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 3, pbuf); } gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); } } if (item->attr) { switch(item->attr) { case ATR_ULINE: case ATR_BOLD: case ATR_BLINK: case ATR_INVERSE: bigStyle = gtk_style_copy (GTK_WIDGET (clist)->style); g_assert (bigStyle != NULL); gdk_font_unref (bigStyle->font); bigStyle->font = gdk_font_load ( "-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); bigStyle->fg[GTK_STATE_NORMAL] = color_blue; gtk_clist_set_cell_style (GTK_CLIST (clist), nCurrentRow, 2, bigStyle); item_selectable = FALSE; } } g_assert (nCurrentRow >= 0); gtk_clist_set_selectable (GTK_CLIST (clist), nCurrentRow, item_selectable); if ( item_selectable==TRUE && item->presel== TRUE) { /* pre-select this item */ gtk_clist_select_row( GTK_CLIST (clist), nCurrentRow, 0); } gtk_object_set_data (GTK_OBJECT (clist), "numRows", GINT_TO_POINTER (nCurrentRow)); /* We have to allocate memory here, since the menu_item currently * lives on the stack, and will otherwise go to the great bit bucket * in the sky as soon as this function exits, which would leave a * pointer to crap in the row_data. Use g_memdup to make a private, * persistant copy of the item identifier. * * We need to arrange to blow away this memory somewhere (like * ghack_menu_destroy and ghack_menu_window_clear for example). * * -Erik */ { menuItem newItem; menuItem *pNewItem; newItem.identifier = *item->identifier; newItem.itemNumber=nCurrentRow; newItem.selected=FALSE; newItem.accelerator[0]=0; /* only copy 1 char, since accel keys are by definition 1 char */ if (accelBuf[0]) { strncpy(newItem.accelerator, accelBuf, 1); } newItem.accelerator[1]=0; pNewItem = g_memdup(&newItem, sizeof( menuItem)); gtk_clist_set_row_data (GTK_CLIST (clist), nCurrentRow, (gpointer) pNewItem); } } /* Now adjust the column widths to match the contents */ gtk_clist_columns_autosize (GTK_CLIST (clist)); }
/* Select a moverecord as the "current" one. NOTE: This function must be called _after_ applying the moverecord. */ extern void GTKSetMoveRecord( moverecord *pmr ) { /* highlighted row/col in game record */ static int yCurrent = -1, xCurrent = -1; GtkCList *pcl = GTK_CLIST( pwGameList ); gamelistrow *pglr; int i; /* Avoid lots of screen updates */ if (!frozen) SetAnnotation( pmr ); #ifdef UNDEF { GtkWidget* pwWin = GetPanelWidget(WINDOW_HINT); if (pwWin) { hintdata *phd = g_object_get_data(G_OBJECT(pwWin), "user_data"); phd->fButtonsValid = FALSE; CheckHintButtons(phd); } } #endif if (yCurrent != -1 && xCurrent != -1) { moverecord *pmrLast = NULL; pglr = gtk_clist_get_row_data(pcl, yCurrent); if (pglr) { pmrLast = pglr->apmr[xCurrent - 1]; if (pmrLast) SetCellColour(yCurrent, xCurrent, pmrLast); } if (!pmrLast) gtk_clist_set_cell_style(pcl, yCurrent, xCurrent, psGameList); } yCurrent = xCurrent = -1; if( !pmr ) return; if( pmr == plGame->plNext->p ) { g_assert( pmr->mt == MOVE_GAMEINFO ); yCurrent = 0; if( plGame->plNext->plNext->p ) { moverecord *pmrNext = plGame->plNext->plNext->p; if( pmrNext->mt == MOVE_NORMAL && pmrNext->fPlayer == 1 ) xCurrent = 2; else xCurrent = 1; } else xCurrent = 1; } else { for( i = pcl->rows - 1; i >= 0; i-- ) { pglr = gtk_clist_get_row_data( pcl, i ); if( pglr->apmr[ 1 ] == pmr ) { xCurrent = 2; break; } else if( pglr->apmr[ 0 ] == pmr ) { xCurrent = 1; break; } } yCurrent = i; if( yCurrent >= 0 && !( pmr->mt == MOVE_SETDICE && yCurrent == pcl->rows - 1 ) ) { do { if( ++xCurrent > 2 ) { xCurrent = 1; yCurrent++; } pglr = gtk_clist_get_row_data( pcl, yCurrent ); } while( yCurrent < pcl->rows - 1 && !pglr->apmr[ xCurrent - 1 ] ); if( yCurrent >= pcl->rows ) AddMoveRecordRow(); } } /* Highlight current move */ gtk_clist_set_cell_style(pcl, yCurrent, xCurrent, psCurrent); if( gtk_clist_row_is_visible( pcl, yCurrent ) != GTK_VISIBILITY_FULL ) gtk_clist_moveto( pcl, yCurrent, xCurrent, 0.8f, 0.5f ); }