关闭

txt-scrolled demo

1866人阅读 评论(0) 收藏 举报

gboolean GtkTreeModelForeachFunction(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);

/*
 *   func: do initialization with scroll struct
 *  
 *   Input: scrolled_str: string needed to be displayed fully
 *             orig: the string you wanna to display when leave current row
 *             widget: treeview handle
 *             scrolled_num: max length of string allowed to be displayed

 *   return: void
 */
 void _init_scrolled(gchar* scrolled_str, gchar* orig, GtkWidget* scrolled_widget, int scrolled_num);
/*
 *  func: permit to change scrolled string length
 *   
 *  Input: num: max length of string allower
 *  Return: void
 */

 void _reset_scrolled_num( int scrolled_num);
/*
 *  func: According to the display requirement, return current string need to be displayed
 *   
 *  Input: void
 *  Return: char*, the dest string,
 */
 gchar* get_scrolled_str();
/*
 *  func:  scroll function called by timer
 *   
 *  Input: void
 *  Return: boolean: TRUE:keep scroll, FALSE: stop it
 */
 gboolean _auto_scrolled();
/*
 *  func:  deconstruct, when you wanna to end scroll-operation, call this function to stop it.
 *   
 *  Input: void
 *  Return: void
 */
 void _deinit_scrolled();
/*
 *  func:  check whether all of the param has been set.
 *   
 *  Input: void
 *  Return: boolean: TRUE:yes, FALSE: no can not scrolled
 */
 gboolean _scrolled_valid();
/*
 *  func:  when focus out of the current row, call this function to set orignal string
 *   
 *  Input: void
 *  Return: void
 */
 void  _scrolled_show_fixed_str();
enum{
 COL_PAD1 = 0,
 COL_NAME,
 COL_WEIGHT,
 COL_WEIGHT_SET,
 COL_AGE,
 COL_IS_NAME_BOLD,
 //COL_PIC,
 NUM_COLS,
};

static gchar  _scrolled_str[64];
static gchar _orig_str[64];
static gint      _scrolled_index;
static gint _scrolled_iteration;  // 1: ++,-1: --, 0: do nothing
static GtkWidget* _scrolled_widget;
static gint _scrolled_num;   //the number of characters scrolled
static gint _scrolled_timer;

typedef struct _Widget_Scroll{
 void (*init_scrolled)(gchar* scrolled_str, gchar* orig, GtkWidget* scrolled_widget, int scrolled_num);
 gboolean  (*scrolled_valid)();
 void (*reset_scroll_num) ( int scrolled_num);
 gchar* (*get_scroll_str)();   
 gboolean  (*scroll_auto)();
 void  (*deinit_scrolled)();
 void  (*show_orig_str) ();
} TextScrollStruct;


TextScrollStruct slScrollTreeView = { _init_scrolled, _scrolled_valid, _reset_scrolled_num, get_scrolled_str,_auto_scrolled,

_deinit_scrolled, _scrolled_show_fixed_str};

void  _scrolled_set_txt( gchar* txt)
{
 GtkTreeSelection* select;
 GtkTreeIter iter;
 gchar* scroll_str;

 select = gtk_tree_view_get_selection( GTK_TREE_VIEW(_scrolled_widget));
 if( select && gtk_tree_selection_get_selected( select, NULL,  &iter))
 {
  gtk_list_store_set( GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(_scrolled_widget))), &iter,

COL_NAME, txt, -1 );
 }
}

void  _scrolled_show_fixed_str()
{
 if( FALSE == _scrolled_valid() )
 {
  _deinit_scrolled();
  return;
 }
 _scrolled_set_txt(_orig_str);
 
}

void _init_scrolled(gchar* scrolled_str,  gchar* orig, GtkWidget* widget, int scrolled_num)
{
 
 if(scrolled_str)
 {
  int cl = 0;
  g_print( "src_str=%s/n", scrolled_str);
  //cl = strlen(scrolled_str)>=sizeof(_scrolled_str) ? sizeof(_scrolled_str)-1  : strlen(scrolled_str);
  //strncpy(_scrolled_str, scrolled_str, cl);
  strcpy(_scrolled_str, scrolled_str);
  g_print( "dest_src=%s%d/n", _scrolled_str,cl+1);
 }
 if(orig)
  strncpy(_orig_str, orig, strlen(orig)>=sizeof(_orig_str) ? sizeof(_orig_str)-1  : strlen(orig));
 _scrolled_widget = widget;
 _scrolled_num = scrolled_num > 0 ? scrolled_num : 1;
 _scrolled_iteration = 1;
 _scrolled_index = 0;
 if(_scrolled_timer)
 { 
  g_source_remove(_scrolled_timer);
 }
 _scrolled_timer = g_timeout_add( 500, (GtkFunction) _auto_scrolled, NULL );
}
void _deinit_scrolled()
{
 g_print( "_deinit_scrolled=/n");
 _scrolled_set_txt(_orig_str);
 if(_scrolled_timer)
 { 
  g_source_remove(_scrolled_timer);
  _scrolled_timer = 0;
 }
 _scrolled_str[0] = 0;
 _orig_str[0] = 0;
 _scrolled_index = 0;
 _scrolled_iteration = 0;
 _scrolled_num = 0;
 _scrolled_widget = NULL;
}
void _reset_scrolled_num( int scrolled_num)
{
 _scrolled_num = scrolled_num > 0 ? scrolled_num : 1;
}

gchar* get_scrolled_str()
{
 static gchar return_str[64];
 gint  src_str_len =0;

 if( 0 == _scrolled_str[0] )
  return NULL;
 src_str_len = strlen(_scrolled_str);

 if(src_str_len <= _scrolled_num )
  return _scrolled_str;
 
 if( _scrolled_index >= strlen(_scrolled_str) -_scrolled_num )
  _scrolled_iteration = -1;
 if( _scrolled_index <= 0 )
  _scrolled_iteration = 1;

 _scrolled_index += _scrolled_iteration;
 strncpy(return_str, _scrolled_str+_scrolled_index, _scrolled_num);
 return_str[_scrolled_num] = 0;
 return return_str;
}

gboolean _scrolled_valid()
{
 if( NULL ==_scrolled_widget )
 {
  return FALSE;
 }
 if( 0 == _scrolled_timer )
 {
  return FALSE;
 }
 return TRUE;
}

 

gboolean _auto_scrolled()
{
 if( FALSE == _scrolled_valid() )
 {
  _deinit_scrolled();
  return FALSE;
 }
 _scrolled_set_txt( slScrollTreeView.get_scroll_str());
 return TRUE;
}
 
// call in when select-change-event happened.
slScrollTreeView.init_scrolled(  name, "origa..", user, 5 );

//called when unselected( before focus out)
slScrollTreeView.show_orig_str();
slScrollTreeView.deinit_scrolled();
 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:178887次
    • 积分:2380
    • 等级:
    • 排名:第16146名
    • 原创:53篇
    • 转载:11篇
    • 译文:0篇
    • 评论:49条
    文章分类
    最新评论