public GroupChatView(GroupChatModel groupChat) : base(groupChat) { Trace.Call(groupChat); _GroupChatModel = groupChat; // person list Participants = new List<PersonModel>(); _OutputHPaned = new Gtk.HPaned(); _OutputHPaned.ButtonPressEvent += (sender, e) => {; // reset person list size on double click if (e.Event.Type == Gdk.EventType.TwoButtonPress && e.Event.Button == 1) { GLib.Timeout.Add(200, delegate { _OutputHPaned.Position = -1; return false; }); } }; Gtk.TreeView tv = new Gtk.TreeView(); _PersonTreeView = tv; Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow(); PersonScrolledWindow = sw; sw.HscrollbarPolicy = Gtk.PolicyType.Never; sw.SizeRequested += (o, args) => { // predict and set useful treeview width var persons = SyncedPersons; if (persons == null || persons.Count == 0) { return; } int longestNameWidth = 0; foreach (var person in persons.Values) { int lineWidth, lineHeigth; using (var layout = _PersonTreeView.CreatePangoLayout(person.IdentityName)) { layout.GetPixelSize(out lineWidth, out lineHeigth); } if (lineWidth > longestNameWidth) { longestNameWidth = lineWidth; } } var bestSize = new Gtk.Requisition() { Width = longestNameWidth }; args.Requisition = bestSize; }; //tv.CanFocus = false; tv.BorderWidth = 0; tv.Selection.Mode = Gtk.SelectionMode.Multiple; sw.Add(tv); Gtk.TreeViewColumn column; Gtk.CellRendererText cellr = new Gtk.CellRendererText(); IdentityNameCellRenderer = cellr; column = new Gtk.TreeViewColumn(String.Empty, cellr); column.SortColumnId = 0; column.Spacing = 0; column.SortIndicator = false; column.Sizing = Gtk.TreeViewColumnSizing.Autosize; // FIXME: this callback leaks memory column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(RenderPersonIdentityName)); tv.AppendColumn(column); _IdentityNameColumn = column; Gtk.ListStore liststore = new Gtk.ListStore(typeof(PersonModel)); liststore.SetSortColumnId(0, Gtk.SortType.Ascending); liststore.SetSortFunc(0, new Gtk.TreeIterCompareFunc(SortPersonListStore)); _PersonListStore = liststore; tv.Model = liststore; tv.SearchColumn = 0; tv.SearchEqualFunc = (model, col, key, iter) => { var person = (PersonModel) model.GetValue(iter, col); // Ladies and gentlemen welcome to C // 0 means it matched but 0 as bool is false. So if it matches // we have to return false. Still not clear? true is false and // false is true, weirdo! If you think this is retarded, // yes it is. return !person.IdentityName.StartsWith(key, StringComparison.InvariantCultureIgnoreCase); }; tv.EnableSearch = true; tv.RowActivated += new Gtk.RowActivatedHandler(OnPersonsRowActivated); tv.FocusOutEvent += OnPersonTreeViewFocusOutEvent; // popup menu _PersonMenu = new Gtk.Menu(); // don't loose the focus else we lose the selection too! // see OnPersonTreeViewFocusOutEvent() _PersonMenu.TakeFocus = false; _PersonMenu.Shown += OnPersonMenuShown; _PersonTreeView.ButtonPressEvent += _OnPersonTreeViewButtonPressEvent; _PersonTreeView.KeyPressEvent += OnPersonTreeViewKeyPressEvent; // frame needed for events when selecting something in the treeview _PersonTreeViewFrame = new Gtk.Frame(); _PersonTreeViewFrame.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler(_OnUserListButtonReleaseEvent); _PersonTreeViewFrame.Add(sw); // topic // don't worry, ApplyConfig() will add us to the OutputVBox! _OutputVBox = new Gtk.VBox(); _TopicTextView = new MessageTextView(); _TopicTextView.Editable = false; _TopicTextView.WrapMode = Gtk.WrapMode.WordChar; _TopicScrolledWindow = new Gtk.ScrolledWindow(); _TopicScrolledWindow.ShadowType = Gtk.ShadowType.In; _TopicScrolledWindow.HscrollbarPolicy = Gtk.PolicyType.Never; _TopicScrolledWindow.Add(_TopicTextView); // make sure the topic is invisible and remains by default and // visible when a topic gets set _TopicScrolledWindow.ShowAll(); _TopicScrolledWindow.Visible = false; _TopicScrolledWindow.NoShowAll = true; _TopicScrolledWindow.SizeRequested += delegate(object o, Gtk.SizeRequestedArgs args) { // predict and set useful topic heigth int lineWidth, lineHeight; using (var layout = _TopicTextView.CreatePangoLayout("Test Topic")) { layout.GetPixelSize(out lineWidth, out lineHeight); } var lineSpacing = _TopicTextView.PixelsAboveLines + _TopicTextView.PixelsBelowLines; var it = _TopicTextView.Buffer.StartIter; int newLines = 1; // move to end of next visual line while (_TopicTextView.ForwardDisplayLineEnd(ref it)) { newLines++; // calling ForwardDisplayLineEnd repeatedly stays on the same position // therefor we move one cursor position further it.ForwardCursorPosition(); } newLines = Math.Min(newLines, 3); var bestSize = new Gtk.Requisition() { Height = ((lineHeight + lineSpacing) * newLines) + 4 }; args.Requisition = bestSize; }; Add(_OutputHPaned); //ApplyConfig(Frontend.UserConfig); ShowAll(); }
public GroupChatView(GroupChatModel groupChat) : base(groupChat) { Trace.Call(groupChat); _GroupChatModel = groupChat; // person list Participants = new List <PersonModel>(); _OutputHPaned = new Gtk.HPaned(); _OutputHPaned.ButtonPressEvent += (sender, e) => {; // reset person list size on double click if (e.Event.Type == Gdk.EventType.TwoButtonPress && e.Event.Button == 1) { GLib.Timeout.Add(200, delegate { _OutputHPaned.Position = -1; return(false); }); } }; Gtk.TreeView tv = new Gtk.TreeView(); _PersonTreeView = tv; Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow(); PersonScrolledWindow = sw; sw.HscrollbarPolicy = Gtk.PolicyType.Never; sw.SizeRequested += (o, args) => { // predict and set useful treeview width var persons = SyncedPersons; if (persons == null || persons.Count == 0) { return; } int longestNameWidth = 0; foreach (var person in persons.Values) { int lineWidth, lineHeigth; using (var layout = _PersonTreeView.CreatePangoLayout(person.IdentityName)) { layout.GetPixelSize(out lineWidth, out lineHeigth); } if (lineWidth > longestNameWidth) { longestNameWidth = lineWidth; } } var bestSize = new Gtk.Requisition() { Width = longestNameWidth }; args.Requisition = bestSize; }; //tv.CanFocus = false; tv.BorderWidth = 0; tv.Selection.Mode = Gtk.SelectionMode.Multiple; sw.Add(tv); Gtk.TreeViewColumn column; Gtk.CellRendererText cellr = new Gtk.CellRendererText(); IdentityNameCellRenderer = cellr; column = new Gtk.TreeViewColumn(String.Empty, cellr); column.SortColumnId = 0; column.Spacing = 0; column.SortIndicator = false; column.Sizing = Gtk.TreeViewColumnSizing.Autosize; // FIXME: this callback leaks memory column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(RenderPersonIdentityName)); tv.AppendColumn(column); _IdentityNameColumn = column; Gtk.ListStore liststore = new Gtk.ListStore(typeof(PersonModel)); liststore.SetSortColumnId(0, Gtk.SortType.Ascending); liststore.SetSortFunc(0, new Gtk.TreeIterCompareFunc(SortPersonListStore)); _PersonListStore = liststore; tv.Model = liststore; tv.SearchColumn = 0; tv.SearchEqualFunc = (model, col, key, iter) => { var person = (PersonModel)model.GetValue(iter, col); // Ladies and gentlemen welcome to C // 0 means it matched but 0 as bool is false. So if it matches // we have to return false. Still not clear? true is false and // false is true, weirdo! If you think this is retarded, // yes it is. return(!person.IdentityName.StartsWith(key, StringComparison.InvariantCultureIgnoreCase)); }; tv.EnableSearch = true; tv.RowActivated += new Gtk.RowActivatedHandler(OnPersonsRowActivated); tv.FocusOutEvent += OnPersonTreeViewFocusOutEvent; // popup menu _PersonMenu = new Gtk.Menu(); // don't loose the focus else we lose the selection too! // see OnPersonTreeViewFocusOutEvent() _PersonMenu.TakeFocus = false; _PersonMenu.Shown += OnPersonMenuShown; _PersonTreeView.ButtonPressEvent += _OnPersonTreeViewButtonPressEvent; _PersonTreeView.KeyPressEvent += OnPersonTreeViewKeyPressEvent; // frame needed for events when selecting something in the treeview _PersonTreeViewFrame = new Gtk.Frame(); _PersonTreeViewFrame.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler(_OnUserListButtonReleaseEvent); _PersonTreeViewFrame.Add(sw); // topic // don't worry, ApplyConfig() will add us to the OutputVBox! _OutputVBox = new Gtk.VBox(); _TopicTextView = new MessageTextView(); _TopicTextView.Editable = false; _TopicTextView.WrapMode = Gtk.WrapMode.WordChar; _TopicScrolledWindow = new Gtk.ScrolledWindow(); _TopicScrolledWindow.ShadowType = Gtk.ShadowType.In; _TopicScrolledWindow.HscrollbarPolicy = Gtk.PolicyType.Never; _TopicScrolledWindow.Add(_TopicTextView); // make sure the topic is invisible and remains by default and // visible when a topic gets set _TopicScrolledWindow.ShowAll(); _TopicScrolledWindow.Visible = false; _TopicScrolledWindow.NoShowAll = true; _TopicScrolledWindow.SizeRequested += delegate(object o, Gtk.SizeRequestedArgs args) { // predict and set useful topic heigth int lineWidth, lineHeight; using (var layout = _TopicTextView.CreatePangoLayout("Test Topic")) { layout.GetPixelSize(out lineWidth, out lineHeight); } var lineSpacing = _TopicTextView.PixelsAboveLines + _TopicTextView.PixelsBelowLines; var it = _TopicTextView.Buffer.StartIter; int newLines = 1; // move to end of next visual line while (_TopicTextView.ForwardDisplayLineEnd(ref it)) { newLines++; // calling ForwardDisplayLineEnd repeatedly stays on the same position // therefor we move one cursor position further it.ForwardCursorPosition(); } newLines = Math.Min(newLines, 3); var bestSize = new Gtk.Requisition() { Height = ((lineHeight + lineSpacing) * newLines) + 4 }; args.Requisition = bestSize; }; Add(_OutputHPaned); //ApplyConfig(Frontend.UserConfig); ShowAll(); }