📄 tv_pd_display.erl
字号:
%% ``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$%%%%%*********************************************************************%%% %%% Description: Part of pd controlling the graphics.%%%%%%*********************************************************************-module(tv_pd_display).-export([init_display/4, display_data/8, resize_display/3, resize_column/4, scroll_horizontally/2, scroll_vertically/2, perform_horizontal_scroll/2, perform_vertical_scroll/2, marked_cell/5, update_toolbar_label/5, update_toolbar_editor/2, get_data_element/4, hide_toolbar_editor/1, show_toolbar_editor/1]).-include("tv_int_def.hrl").-include("tv_int_msg.hrl").-include("tv_pd_int_def.hrl").-include("tv_pd_int_msg.hrl").%%%*********************************************************************%%% EXTERNAL FUNCTIONS%%%*********************************************************************%%======================================================================%% Function: init_display.%%%% Return Value: Id of the display (here:canvas) created.%%%% Description: Creates the canvas and the scale.%%%% Parameters: Id of the window the display shall be created in.%%======================================================================init_display(WindowId, WindowWidth, WindowHeight, ProcVars) -> % Get all necessary window parameters! #process_variables{pg_pid = PgPid, pb_pid = PbPid, frame_params = FrameP, scale_params = ScaleP, toolbar_params = ToolP} = ProcVars, NewFrameP = tv_pd_frames:create_display_frames(WindowId, WindowWidth, WindowHeight, FrameP), #frame_params{grid_frame_id = GridParentId, grid_frame_width = GridParentWidth, grid_frame_height = GridParentHeight} = NewFrameP, PgPid ! #pg_init_grid{sender = self(), parent_id = GridParentId, width = GridParentWidth, height = GridParentHeight, xpos = ?VBTN_WIDTH - 1, ypos = ?KEY_MARK_AREA_HEIGHT + ?HBTN_HEIGHT - 1, nof_rows = ?NOF_GRIDROWS, row_height = ?ROW_HEIGHT }, receive #pg_col_info{first_col_shown = FirstColShown, width_of_cols_shown = ColsShown, nof_rows_shown = NofRowsShown} -> PbPid ! #pb_init_btns{sender = self(), parent_id = GridParentId, parent_width = GridParentWidth, parent_height = GridParentHeight, ypos = ?KEY_MARK_AREA_HEIGHT, hbtn_height = ?HBTN_HEIGHT, resbtn_width = ?RESBTN_WIDTH, vbtn_width = ?VBTN_WIDTH, nof_rows = ?NOF_GRIDROWS, row_height = ?ROW_HEIGHT, first_col_shown = FirstColShown, cols_shown = ColsShown }, NewScaleP = tv_pd_scale:init_scale(NewFrameP, ScaleP), NewToolP = init_toolbar(NewFrameP, ToolP), ProcVars#process_variables{window_id = WindowId, window_width = WindowWidth, window_height = WindowHeight, first_col_shown = FirstColShown, nof_rows_shown = NofRowsShown, cols_shown = ColsShown, frame_params = NewFrameP, scale_params = NewScaleP, toolbar_params = NewToolP } end. resize_display(NewWinW, NewWinH, ProcVars) -> #process_variables{pg_pid = PgPid, pb_pid = PbPid, color_list = ColorList, first_row_shown = FirstRowShown, frame_params = FrameP, scale_params = ScaleP, toolbar_params = ToolP} = ProcVars, NewFrameP = tv_pd_frames:resize_display_frames(NewWinW, NewWinH, FrameP), #frame_params{grid_frame_width = GridParentWidth, grid_frame_height = GridParentHeight} = NewFrameP, PgPid ! #pg_resize_grid{sender = self(), width = GridParentWidth, height = GridParentHeight }, receive #pg_col_info{first_col_shown = FirstColShown, width_of_cols_shown = ColsShown, nof_rows_shown = NofRowsShown} -> PbPid ! #pb_update_hbtns{sender = self(), parent_width = GridParentWidth, parent_height = GridParentHeight, first_col_shown = FirstColShown, cols_shown = ColsShown }, PbPid ! #pb_update_vbtns{sender = self(), color_list = ColorList, first_row_shown = FirstRowShown, nof_rows_shown = NofRowsShown, blinking_enabled = false }, NewScaleP = tv_pd_scale:resize_scale(NewFrameP, ScaleP), NewToolP = resize_toolbar(NewFrameP, ToolP), ProcVars#process_variables{window_width = NewWinW, window_height = NewWinH, first_col_shown = FirstColShown, nof_rows_shown = NofRowsShown, cols_shown = ColsShown, frame_params = NewFrameP, scale_params = NewScaleP, toolbar_params = NewToolP } end. resize_column(RealCol, VirtualCol, Xdiff, ProcVars) -> #process_variables{pg_pid = PgPid, pb_pid = PbPid, frame_params = FrameP} = ProcVars, PgPid ! #pg_resize_grid_col{sender = self(), real_col_no = RealCol, virtual_col_no = VirtualCol, xdiff = Xdiff }, #frame_params{grid_frame_width = GridFrameWidth, grid_frame_height = GridFrameHeight} = FrameP, receive #pg_col_info{first_col_shown = FirstColShown, width_of_cols_shown = ColsShown, nof_rows_shown = NofRowsShown} -> PbPid ! #pb_update_hbtns{parent_width = GridFrameWidth, parent_height = GridFrameHeight, first_col_shown = FirstColShown, cols_shown = ColsShown }, ProcVars#process_variables{first_col_shown = FirstColShown, nof_rows_shown = NofRowsShown, cols_shown = ColsShown } end. display_data(Pos, Range, _MaxValue, List, KeyList, MaxElemSize, MarkedRowData,ProcVars) -> #process_variables{master_pid = PcPid, rec_pid = RecPid, pg_pid = PgPid, pb_pid = PbPid, writable = Writable, sorting_on = SortingOn, nof_rows_shown = NofRowsShown, scale_params = ScaleP, toolbar_params = ToolP, mark_params = MarkP} = ProcVars, {DataList, ColorList} = split_dblist(List, [], []), NewMarkP = update_marks(SortingOn, DataList, ColorList, MarkedRowData, Pos, NofRowsShown, Writable, Range, PcPid, PgPid, RecPid, ToolP, MarkP), PgPid ! #pg_data{sender = self(), data = DataList, first_row_shown = Pos }, PbPid ! #pb_update_vbtns{sender = self(), color_list = ColorList, first_row_shown = Pos, nof_rows_shown = NofRowsShown, blinking_enabled = false }, PbPid ! #pb_key_info{sender = self(), list_of_keys = KeyList }, % May be new number of elements in the total list! ?SCALE_FUNC_FILE:set_scale_range(vscale, Range, ScaleP), % May be new vertical scale position required! NewScaleP = ?SCALE_FUNC_FILE:set_scale_pos(vscale, Pos, ScaleP), % May be new maximum size of elements! ?SCALE_FUNC_FILE:set_scale_range(hscale, {1, MaxElemSize}, NewScaleP), ProcVars#process_variables{data_list = DataList, color_list = ColorList, first_row_shown = Pos, initialising = false, scale_params = NewScaleP, mark_params = NewMarkP }.scroll_vertically(MouseBtn, ProcVars) -> #process_variables{scale_params = ScaleP} = ProcVars, OldScalePos = ScaleP#scale_params.vscale_pos, NewScalePos = get_new_scalepos(MouseBtn, OldScalePos), case NewScalePos of OldScalePos -> ProcVars; NewValue -> perform_vertical_scroll(NewValue, ProcVars) end.scroll_horizontally(MouseBtn, ProcVars) -> #process_variables{scale_params = ScaleP} = ProcVars, OldScalePos = ScaleP#scale_params.hscale_pos, NewScalePos = get_new_scalepos(MouseBtn, OldScalePos), case NewScalePos of OldScalePos -> ProcVars; NewValue -> perform_horizontal_scroll(NewValue, ProcVars) end.perform_vertical_scroll(NewScalePos, ProcVars) -> #process_variables{master_pid = MasterPid, initialising = Init, scale_params = ScaleP} = ProcVars, %% To avoid erroneous scrollbar signals during creation of the display. case Init of true -> done; false -> MasterPid ! #pc_data_req{sender = self(), element = NewScalePos, nof_elements = ?NOF_GRIDROWS} end, % Since the order of click/buttonrelease messages isn't % precise, set the scale to the returned pos (may otherwise % differ one unit). NewScaleP = ?SCALE_FUNC_FILE:set_scale_pos(vscale, NewScalePos, ScaleP), ProcVars#process_variables{scale_params = NewScaleP}.perform_horizontal_scroll(NewScalePos, ProcVars) -> #process_variables{pg_pid = PgPid, pb_pid = PbPid, frame_params = FrameP, scale_params = ScaleP} = ProcVars, % Since the order of click/buttonrelease messages isn't % precise, set the scale to the returned pos (may otherwise % differ one unit). NewScaleP = ?SCALE_FUNC_FILE:set_scale_pos(hscale, NewScalePos, ScaleP), PgPid ! #pg_horizontal_scroll{sender = self(), leftmost_virtual_col = NewScalePos }, #frame_params{grid_frame_width = GridFrameWidth, grid_frame_height = GridFrameHeight} = FrameP, receive #pg_col_info{first_col_shown = FirstColShown, width_of_cols_shown = ColsShown, nof_rows_shown = NofRowsShown} -> PbPid ! #pb_update_hbtns{parent_width = GridFrameWidth, parent_height = GridFrameHeight, first_col_shown = FirstColShown, cols_shown = ColsShown }, ProcVars#process_variables{first_col_shown = FirstColShown, cols_shown = ColsShown, nof_rows_shown = NofRowsShown, scale_params = NewScaleP } end.marked_cell(true, VirtualCol, RealRow, VirtualRow, ProcVars) -> #process_variables{master_pid = MasterPid, rec_pid = RecPid, data_list = DataList, color_list = ColorList, writable = Writable, mark_params = MarkP, toolbar_params = ToolP} = ProcVars, {DataElement, MarkedRowObject} = get_data_element(cell, DataList, RealRow, VirtualCol), update_toolbar_label(DataElement, ToolP, VirtualRow, VirtualCol, Writable), send_to_rec_edit(RecPid, {update_mode,MarkedRowObject}), MarkedRowColor = lists:nth(RealRow, ColorList), MasterPid ! #pc_marked_row{sender = self(), row_no = VirtualRow, object = MarkedRowObject, color = MarkedRowColor }, NewMarkP = MarkP#mark_params{cell_col_no = VirtualCol, row_no = RealRow, virtual_row_no = VirtualRow, marked_object = MarkedRowObject, marked_color = MarkedRowColor }, ProcVars#process_variables{mark_params = NewMarkP };marked_cell(false, VirtualCol, _RealRow, VirtualRow, ProcVars) -> #process_variables{master_pid = MasterPid, rec_pid = RecPid, pb_pid = PbPid, writable = Writable, mark_params = MarkP} = ProcVars, PbPid ! #pb_remove_marks{sender = self()}, case VirtualRow of undefined -> done; _AnyRow -> update_toolbar_label(notext, ProcVars#process_variables.toolbar_params, VirtualRow, VirtualCol, Writable), send_to_rec_edit(RecPid, insert_mode) end, MasterPid ! #pc_marked_row{sender = self(), %% row_no = VirtualRow row_no = undefined, object = undefined, color = undefined }, NewMarkP = MarkP#mark_params{cell_col_no = undefined, row_no = undefined, virtual_row_no = undefined, marked_object = undefined, marked_color = undefined }, ProcVars#process_variables{mark_params = NewMarkP }. update_toolbar_label(notext, ToolP, _VirtualRowNo, _VirtualColNo, Writable) -> #toolbar_params{row_col_label_id = RowColLblId, fg_label_id = FgLblId, editor_id = EdId} = ToolP, gs:config(RowColLblId, [{label, {text,""}}]), gs:config(FgLblId, [{enable,true}]), gs:config(FgLblId, [{delete, {0,1000000000}}]), gs:config(FgLblId, [{insert, {0, ""}}]), case Writable of true -> gs:config(FgLblId, [{cursor, text}, {setfocus, true}]); false -> gs:config(FgLblId, [{enable, false}, {cursor, arrow}, {setfocus, false}]) end, update_toolbar_editor(EdId, notext);update_toolbar_label({DataToShow}, ToolP, VirtualRowNo, VirtualColNo, Writable) -> #toolbar_params{row_col_label_id = RowColLblId, fg_label_id = FgLblId, editor_id = EdId} = ToolP, case VirtualRowNo of undefined -> %% No row - nothing can possibly be marked! case Writable of true -> gs:config(FgLblId, [{setfocus,true}, {cursor, text}]); false -> gs:config(FgLblId, [{enable,false}, {setfocus, false}, {cursor, arrow}]) end; _AnyRow -> RowStr = "R" ++ integer_to_list(VirtualRowNo), ColStr = case VirtualColNo of undefined -> ""; _AnyCol -> " x C" ++ integer_to_list(VirtualColNo) end, DataStr = lists:flatten(tv_io_lib:format("~p", [DataToShow])), gs:config(RowColLblId, [{label, {text,RowStr++ColStr}}]), gs:config(FgLblId, [{enable,true}]), gs:config(FgLblId, [{delete, {0,10000000}}]), gs:config(FgLblId, [{insert, {0,DataStr}}]), case Writable of true -> gs:config(FgLblId, [{setfocus,true}, {cursor, text}]); false -> gs:config(FgLblId, [{enable,false}, {setfocus, false}, {cursor, arrow}]) end, update_toolbar_editor(EdId, {DataToShow}) end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -