예제 #1
0
파일: IconList.cs 프로젝트: emtees/old-code
	void ButtonHandler (object obj, ButtonPressEventArgs args)
	{
		Gdk.EventButton pos = args.Event;
		bool double_click = false;

		int item_clicked = ItemAtPixel ((int) pos.X, (int) pos.Y);

                int begin = ItemAt (0, 0);
                int end = Math.Min (ItemAt (visible_cols, visible_rows - 1), image_count);
                int count = visible_cols * visible_rows;

		if (item_clicked < begin || item_clicked >= end) {
			args.RetVal = true;
			return;
		}

		GrabFocus ();
		switch (pos.Button){
		case 1:
			bool [] repaint = new bool [count];

			bool control_pressed = (pos.State & Gdk.ModifierType.ControlMask) != 0;
			bool shift_pressed = (pos.State & Gdk.ModifierType.ShiftMask) != 0;
			
			if (shift_pressed && selection_start_item != -1){
				int first;
				int last;

				if (selection_start_item != item_clicked) {
					Selection.SetAll (false);
					if (selection_start_item < item_clicked) {
						first = selection_start_item;
						last = item_clicked;
					} else {
						first = item_clicked;
						last = selection_start_item;
					}

					for (int i = first; i <= last; i++) {
						Selection [i] = true;
                                                if (i >= begin)
                                                        repaint [i - begin] = true;
						select_count++;
					}
				} else {
					Selection[selection_start_item] = ! Selection[selection_start_item];
					repaint[selection_start_item] = true;
				}
			} else if (control_pressed){
				select_count++;
				if (Selection [item_clicked]){
					Selection [item_clicked] = true;
					select_count--;
				} else {
					Selection [item_clicked] = true;
					select_count++;
				}
				Selection [item_clicked] = !Selection [item_clicked];
				repaint [item_clicked-begin] = true;
			} else {
				if (select_count != 0){
					for (int i = begin; i < end; i++){
						if (Selection [i])
							repaint [i - begin] = true;
					}
					
					Selection.SetAll (false);
				}
				select_count = 1;
				Selection [item_clicked] = true;
				repaint [item_clicked-begin] = true;
				selection_start_item = item_clicked;
			} 

			for (int i = begin; i < end; i++){
				if (repaint [i - begin]){
					DrawCell (i);
				}
			}

			if (SelectionChanged != null)
				SelectionChanged ();
			
			break;

		case 3:
                        IconListPopup ip = new IconListPopup (this, item_clicked);
			ip.Activate (pos);
			break;

		default:
			return;
		}

		if (last_click_time != 0) {
			if (pos.Time - last_click_time <= double_click_time &&
                            item_clicked == last_item_clicked)
                        {
				double_click = true;
			}
		}

		if (double_click) {
                        if (this.Activated != null)
                                this.Activated (this, EventArgs.Empty);
			last_click_time = 0;
                        last_item_clicked = 0;
		} else {
			last_click_time = pos.Time;
                        last_item_clicked = item_clicked;
		}

		args.RetVal = true;
	}
예제 #2
0
    void ButtonHandler(object obj, ButtonPressEventArgs args)
    {
        Gdk.EventButton pos          = args.Event;
        bool            double_click = false;

        int item_clicked = ItemAtPixel((int)pos.X, (int)pos.Y);

        int begin = ItemAt(0, 0);
        int end   = Math.Min(ItemAt(visible_cols, visible_rows - 1), image_count);
        int count = visible_cols * visible_rows;

        if (item_clicked < begin || item_clicked >= end)
        {
            args.RetVal = true;
            return;
        }

        GrabFocus();
        switch (pos.Button)
        {
        case 1:
            bool [] repaint = new bool [count];

            bool control_pressed = (pos.State & Gdk.ModifierType.ControlMask) != 0;
            bool shift_pressed   = (pos.State & Gdk.ModifierType.ShiftMask) != 0;

            if (shift_pressed && selection_start_item != -1)
            {
                int first;
                int last;

                if (selection_start_item != item_clicked)
                {
                    Selection.SetAll(false);
                    if (selection_start_item < item_clicked)
                    {
                        first = selection_start_item;
                        last  = item_clicked;
                    }
                    else
                    {
                        first = item_clicked;
                        last  = selection_start_item;
                    }

                    for (int i = first; i <= last; i++)
                    {
                        Selection [i] = true;
                        if (i >= begin)
                        {
                            repaint [i - begin] = true;
                        }
                        select_count++;
                    }
                }
                else
                {
                    Selection[selection_start_item] = !Selection[selection_start_item];
                    repaint[selection_start_item]   = true;
                }
            }
            else if (control_pressed)
            {
                select_count++;
                if (Selection [item_clicked])
                {
                    Selection [item_clicked] = true;
                    select_count--;
                }
                else
                {
                    Selection [item_clicked] = true;
                    select_count++;
                }
                Selection [item_clicked]       = !Selection [item_clicked];
                repaint [item_clicked - begin] = true;
            }
            else
            {
                if (select_count != 0)
                {
                    for (int i = begin; i < end; i++)
                    {
                        if (Selection [i])
                        {
                            repaint [i - begin] = true;
                        }
                    }

                    Selection.SetAll(false);
                }
                select_count                   = 1;
                Selection [item_clicked]       = true;
                repaint [item_clicked - begin] = true;
                selection_start_item           = item_clicked;
            }

            for (int i = begin; i < end; i++)
            {
                if (repaint [i - begin])
                {
                    DrawCell(i);
                }
            }

            if (SelectionChanged != null)
            {
                SelectionChanged();
            }

            break;

        case 3:
            IconListPopup ip = new IconListPopup(this, item_clicked);
            ip.Activate(pos);
            break;

        default:
            return;
        }

        if (last_click_time != 0)
        {
            if (pos.Time - last_click_time <= double_click_time &&
                item_clicked == last_item_clicked)
            {
                double_click = true;
            }
        }

        if (double_click)
        {
            if (this.Activated != null)
            {
                this.Activated(this, EventArgs.Empty);
            }
            last_click_time   = 0;
            last_item_clicked = 0;
        }
        else
        {
            last_click_time   = pos.Time;
            last_item_clicked = item_clicked;
        }

        args.RetVal = true;
    }