tv_pb_funcs.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 1,053 行 · 第 1/2 页

ERL
1,053
字号
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %%     $Id$%%-module(tv_pb_funcs).-export([init_btns/10, 	 update_hbtns/3, 	 update_vbtns/5, 	 update_keys/2, 	 set_new_sort_col/2]).-include("tv_int_def.hrl").-include("tv_pb_int_def.hrl").%%%*********************************************************************%%% EXTERNAL FUNCTIONS%%%*********************************************************************%%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================init_btns(ParentId, Ypos, HbtnH, 	  VbtnW, ResbtnW, FirstColShown, ColsShown, NofRows, RowH, ProcVars) ->    #process_variables{key_numbers = KeyNos,		       key_ids     = KeyIds} = ProcVars,%    C = gs:canvas(ParentId, [{width, VbtnW - 1},%			     {height, HbtnH},%			     {x, 0},%			     {y, HbtnH + 1},%			     {bg, white}%			    ]),%    gs:create(image, C, [{load_gif, "erlang.gif"}]),    {HbtnsShown, ResBtnsShown} = update_hbtns(ColsShown, [], [], 					      FirstColShown, ParentId, Ypos,					      HbtnH, ResbtnW, VbtnW),    NewKeyIds = update_keys(KeyNos, KeyIds, FirstColShown, 			    FirstColShown + length(ColsShown) - 1, HbtnsShown, 			    ParentId, []),    VbtnsShown = create_vbtns(ParentId, Ypos, NofRows, RowH, VbtnW, HbtnH),    ProcVars#process_variables{grid_frame_id   = ParentId,			       ypos            = Ypos,			       hbtn_height     = HbtnH,			       vbtn_width      = VbtnW,			       resbtn_width    = ResbtnW,			       first_col_shown = FirstColShown,			       hbtns_shown     = HbtnsShown,			       resbtns_shown   = ResBtnsShown,			       vbtns_shown     = VbtnsShown,			       cols_shown      = ColsShown,			       key_ids         = NewKeyIds			      }.%%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================update_hbtns(FirstColShown, ColsShown, ProcVars) ->    #process_variables{grid_frame_id   = ParentId,		       first_col_shown = OldFirstColShown,		       cols_shown      = OldColsShown,		       ypos            = Ypos,		       hbtn_height     = HbtnH,		       vbtn_width      = VbtnW,		       resbtn_width    = ResbtnW,		       hbtns_shown     = HbtnsShown,		       resbtns_shown   = ResbtnsShown,		       key_numbers     = KeyNos,		       key_ids         = KeyIds,		       col_mark_params = ColMarkP}  = ProcVars,       % Only if the grid has been scrolled horizontally need we move the       % col mark!    case FirstColShown of	OldFirstColShown ->	    done;	_NewValue ->	    #col_mark_params{col_btn_id         = MarkedBtnId,			     virtual_col_marked = ColMarked,			     sort_btn_id        = SortBtnId,			     virtual_sort_col   = SortCol}  = ColMarkP,	    unmark_marked_col(MarkedBtnId, ColMarked, SortCol),	    unmark_sort_col(SortBtnId, ColMarked, SortCol)    end,    {NewHbtns, NewResbtns, NewKeys} = 	case {FirstColShown, ColsShown} of	    {OldFirstColShown, OldColsShown} ->		{HbtnsShown, ResbtnsShown, KeyIds};	    _Other ->		{NewHbtnsShown, NewResbtnsShown} = update_hbtns(ColsShown, 								HbtnsShown, 								ResbtnsShown, 								FirstColShown, 								ParentId, 								Ypos, 								HbtnH, 								ResbtnW,								VbtnW),		NewKeyIds = update_keys(KeyNos, KeyIds, FirstColShown, 					FirstColShown + length(ColsShown) - 1, 					NewHbtnsShown, ParentId, []),		{NewHbtnsShown, NewResbtnsShown, NewKeyIds}	end,	           % Now mark the marked column again!    NewColMarkP = mark_marked_col(NewHbtns, FirstColShown, ColMarkP),    ProcVars#process_variables{first_col_shown = FirstColShown,			       hbtns_shown     = NewHbtns,			       resbtns_shown   = NewResbtns,			       cols_shown      = ColsShown,			       key_ids         = NewKeys,			       col_mark_params = NewColMarkP			      }.        		       %%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================update_vbtns(NofRowsShown, FirstRowShown, Colors, BlinkEnabled, ProcVars) ->    #process_variables{vbtns_shown      = Vbtns,		       blink_color_list = BlinkList} = ProcVars,        update_vbtns(1, NofRowsShown, FirstRowShown, Vbtns, Colors, BlinkEnabled, BlinkList),    NewProcVars = update_sort_btn_mark(ProcVars),    NewProcVars.%%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================set_new_sort_col(SortCol, ProcVars) ->    #process_variables{hbtns_shown     = HbtnsShown,		       col_mark_params = ColMarkP} = ProcVars,        #col_mark_params{col_btn_id         = MarkedColBtnId,		     sort_btn_id        = OldSortBtnId}  = ColMarkP,           % Set the new color of the sort btn, and remove the mark, if it is the same       % column!    case MarkedColBtnId of	undefined ->	    done;	_AnyId ->	    gs:config(MarkedColBtnId, [{bg, ?DEFAULT_BG_COLOR},				       {fg, {0, 0, 0}}				      ])    end,        SortBtnId = get_btn_id(SortCol, HbtnsShown),    case SortBtnId of 	undefined ->	       % The btn isn't visible, or no sorting shall be performed!	    gs:config(OldSortBtnId, [{bg, ?DEFAULT_BG_COLOR},				     {fg, {0, 0, 0}}				    ]);	_Other ->	       % Unmark the old sort btn id!	    gs:config(OldSortBtnId, [{bg, ?DEFAULT_BG_COLOR},				     {fg, {0, 0, 0}}				    ]),	    gs:config(SortBtnId, [{bg, ?SORT_MARK_COLOR},				  {fg, {0, 0, 0}}				 ])    end,        NewColMarkP = ColMarkP#col_mark_params{col_btn_id         = undefined,					   virtual_col_marked = undefined,					   sort_btn_id        = SortBtnId,					   virtual_sort_col   = SortCol					  },    ProcVars#process_variables{col_mark_params = NewColMarkP}.    %%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================update_keys(KeyList, ProcVars) ->    #process_variables{key_numbers     = OldKeyList,		       key_ids         = KeyIds,		       first_col_shown = FirstColShown,		       cols_shown      = ColsShown,		       hbtns_shown     = HbtnsShown,		       grid_frame_id   = ParentId} = ProcVars,    NewKeyIds = case KeyList of		    OldKeyList ->			KeyIds;		    NewKeyList ->			update_keys(NewKeyList, KeyIds, FirstColShown, 				    FirstColShown + length(ColsShown) - 1, 				    HbtnsShown, ParentId, [])		end,    ProcVars#process_variables{key_numbers = KeyList,			       key_ids     = NewKeyIds			      }.%%%*********************************************************************%%% INTERNAL FUNCTIONS%%%*********************************************************************%%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================unmark_sort_col(undefined, _ColMarked, _SortCol) ->    done;unmark_sort_col(SortBtnId, _ColMarked, _SortCol) ->    gs:config(SortBtnId, [{bg, ?DEFAULT_BG_COLOR},			  {fg, {0, 0, 0}}			 ]).%%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================mark_marked_col(HbtnsShown, _FirstColShown, ColMarkP) ->    #col_mark_params{virtual_col_marked = VirtualCol,		     virtual_sort_col   = SortCol} = ColMarkP,    {NewMarkBtnId, NewSortBtnId} = 	case VirtualCol of	    SortCol ->		   % Same btn!		BtnId = get_btn_id(VirtualCol, 				   HbtnsShown),		gs:config(BtnId, [{bg, ?SORT_MARK_COLOR},				  {fg, {0, 0, 0}}				 ]),		{BtnId, BtnId};	    _OtherCol ->		MarkBtnId = get_btn_id(VirtualCol, HbtnsShown),		case MarkBtnId of		    undefined ->			done;		    _Else ->			gs:config(MarkBtnId, [{bg, ?COL_MARK_COLOR},					      {fg, {255, 255, 255}}					     ])		end,		SortBtnId = get_btn_id(SortCol, HbtnsShown),		case SortBtnId of		    undefined ->			done;		    _OtherId ->			gs:config(SortBtnId, [{bg, ?SORT_MARK_COLOR},					      {fg, {0, 0, 0}}					     ])		end,		{MarkBtnId, SortBtnId}	end,        ColMarkP#col_mark_params{col_btn_id = NewMarkBtnId,			     sort_btn_id = NewSortBtnId}.    %%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================unmark_marked_col(undefined, _ColMarked, _SortCol) ->    done;unmark_marked_col(BtnId, _ColMarked, _SortCol) ->    gs:config(BtnId, [{bg, ?DEFAULT_BG_COLOR},		      {fg, {0,0,0}}		     ]).%%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================update_sort_btn_mark(ProcVars) ->    #process_variables{hbtns_shown     = HbtnsShown,		       col_mark_params = ColMarkP}  = ProcVars,    #col_mark_params{col_btn_id         = MarkedColBtnId,		     virtual_col_marked = ColMarked,		     sort_btn_id        = OldSortBtnId,		     virtual_sort_col   = SortCol}  = ColMarkP,        {NewMarkedColBtnId, NewColMarked} = case ColMarked of					    SortCol ->						{undefined, undefined};					    _Other ->						{MarkedColBtnId, ColMarked}					end,    NewSortBtnId = set_sort_btn_color(OldSortBtnId, SortCol, HbtnsShown),    NewColMarkP = ColMarkP#col_mark_params{col_btn_id         = NewMarkedColBtnId,					   virtual_col_marked = NewColMarked,					   sort_btn_id        = NewSortBtnId},    ProcVars#process_variables{col_mark_params = NewColMarkP}.    %%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================get_btn_id(VirtualCol, HbtnsShown) ->    case lists:keysearch(VirtualCol, #hbtn.virtual_col, HbtnsShown) of	false ->	    undefined;	{value, HbtnRec} ->	    HbtnRec#hbtn.id    end.    %%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================set_sort_btn_color(undefined, SortCol, HbtnsShown) ->    case lists:keysearch(SortCol, #hbtn.virtual_col, HbtnsShown) of	false ->	    undefined;	{value, HbtnRec} ->	    BtnId = HbtnRec#hbtn.id,	    gs:config(BtnId, [{bg, ?SORT_MARK_COLOR}]),	    BtnId    end;set_sort_btn_color(BtnId, undefined, _HbtnsShown) ->    gs:config(BtnId, [{bg, ?DEFAULT_BG_COLOR}]);set_sort_btn_color(OldSortBtnId, SortCol, HbtnsShown) ->    case gs:read(OldSortBtnId, bg) of 	SortCol ->	       % Btn is already marked!	    OldSortBtnId;	_OtherColor ->	       % Unmark old btn, mark new btn, if visible.	    gs:config(OldSortBtnId, [{bg, ?DEFAULT_BG_COLOR}]),	    case lists:keysearch(SortCol, #hbtn.virtual_col, HbtnsShown) of		false ->

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?