[Gtk-sharp-list] Scrollwindow don't works inside Gtk.Fixed

Thomas Zühlke muell_muell_ at gmx.net
Sat Apr 22 10:21:27 EDT 2006


Hi *,

i have build a "mini" example for my problem (please see the 
attachment). There is a Gkt.Window and it is filled with a 
Scrolledwindow. This Scolledwindow is filled with a EventBox and this 
EventBox is filled with a Fixed. :-)
If you perform a right-mouse-button-press on the window, a black filled 
DrawingArea is created on the Fixed. This DrawingArea can be moved by 
holding down left-mouse-button.
The problem is that there should be created scollbars when i move the 
DrawingArea out of the windowborder or if i make the window smaller. Is 
this possible that there will be scrollbars shown?

Thomas
-------------- next part --------------
using System;
using System.Collections.Generic;
using System.Text;
using Gtk;

namespace GtkFixed_Scrollbars {
    class Program {
        static void Main(string[] args) {
            Application.Init();
            MainWindow hp = new MainWindow("Hallo");
            hp.ShowAll();
            Application.Run();
        }
    }

    public class MainWindow : Gtk.Window{
        public Gtk.Fixed FixedWidget;
        public Gtk.EventBox EventBoxWidget;
        public List<Gtk.DrawingArea> drawings = new List<DrawingArea>();

        private Gdk.GC gc_black;
        private double mouse_x,mouse_y;

        public MainWindow(string title):base(title){
            this.Destroyed += new EventHandler(MainWindow_Destroyed);
            this.SetDefaultSize(500, 500);

            FixedWidget = new Fixed();
            EventBoxWidget = new EventBox();
            EventBoxWidget.Events = Gdk.EventMask.AllEventsMask;
            EventBoxWidget.ButtonPressEvent += new ButtonPressEventHandler(event_box_ButtonPressEvent);
            
            // putting all things together
            EventBoxWidget.Add(FixedWidget);
            Gtk.ScrolledWindow sw = new ScrolledWindow();
            sw.Add(EventBoxWidget);
            this.Add(sw);
        }

        void MainWindow_Destroyed(object sender, EventArgs e) {
            Application.Quit();
        }

        private void event_box_ButtonPressEvent(object o, ButtonPressEventArgs args) {
            if (args.Event.Button == 3) {
                AddDrawingArea(
                    FixedWidget,
                    (int)args.Event.X,
                    (int)args.Event.Y);
            }
        }
        
        #region some stupid DrawingArea functions
        private void AddDrawingArea(Gtk.Fixed FixedOn, int x, int y) {
            MyDA da = new MyDA();
            da.SetSizeRequest(30, 30);
            da.Events = Gdk.EventMask.AllEventsMask;
            da.MotionNotifyEvent += new MotionNotifyEventHandler(DrawingArea_MotionNotifyEvent);
            da.Realized += new EventHandler(DrawingArea_Realized);
            da.ExposeEvent += new ExposeEventHandler(DrawingArea_ExposeEvent);
            da.ButtonPressEvent += new ButtonPressEventHandler(DrawingArea_ButtonPressEvent);
            da.Position = new Gdk.Point(x, y);
            FixedOn.Put(da, x, y);
            FixedOn.ShowAll();
        }

        private void DrawingArea_ButtonPressEvent(object o, ButtonPressEventArgs args) {
            mouse_x = args.Event.X;
            mouse_y = args.Event.Y;
        }

        private void DrawingArea_ExposeEvent(object o, ExposeEventArgs args) {
            MyDA da = (MyDA)o;
            da.GdkWindow.DrawRectangle(gc_black, true, 0, 0, da.Allocation.Width, da.Allocation.Height);
        }

        private void DrawingArea_Realized(object sender, EventArgs e) {
            MyDA da = (MyDA)sender;
            da.ModifyBase(Gtk.StateType.Normal, new Gdk.Color(0, 0, 0));
            gc_black = da.Style.BaseGC(Gtk.StateType.Normal);
        }

        private void DrawingArea_MotionNotifyEvent(object o, MotionNotifyEventArgs args) {
            MyDA da = (MyDA)o;
            Gdk.EventMotion ev = args.Event;
            Gdk.ModifierType state;
            state = ev.State;
            if (state == Gdk.ModifierType.Button1Mask) {
                // holding down left mousebutton and moving
                double move_x_to = (da.Position.X + ev.X) - mouse_x;
                double move_y_to = (da.Position.Y + ev.Y) - mouse_y; ;
                da.Position = new Gdk.Point((int)move_x_to, (int)move_y_to);
                FixedWidget.Move(da, (int)move_x_to, (int)move_y_to);
            }
        }
        #endregion
    }

    public class MyDA : Gtk.DrawingArea {
        public Gdk.Point Position;
        public MyDA() : base() { }
    }

}


More information about the Gtk-sharp-list mailing list