summaryrefslogtreecommitdiffstats
path: root/SidebarManager.cpp
blob: 15bff818a7d329f0485eaed824eb723c4f967888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "SidebarManager.h"
#include "Window.h"


SidebarManager::SidebarManager(Window *window)
 : sidebarToolbox(window), toolGrab(&window->getEditManager()),
   toolRotate(&window->getEditManager()), toolAddRect(&window->getEditManager()),
   toolAddPolygon(&window->getEditManager())
{
  this->window = window;
  activeSidebar = NULL;
  
  sidebar = gtk_vbox_new(FALSE, 0);
  g_object_ref_sink(G_OBJECT(sidebar));  
  
  gtk_box_pack_start(GTK_BOX(sidebar), sidebarToolbox.getWidget(), FALSE, FALSE, 0);
  
  gtk_box_pack_start(GTK_BOX(sidebar), gtk_hseparator_new(), FALSE, FALSE, 5);
  
  toolLabel = gtk_label_new(sidebarToolbox.getActiveTool().getName());
  
  gtk_box_pack_start(GTK_BOX(sidebar), toolLabel, FALSE, FALSE, 0);
  
  scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start_defaults(GTK_BOX(sidebar), scrolledWindow);
  gtk_widget_show(scrolledWindow);
  
  viewport = gtk_viewport_new(NULL, NULL);
  gtk_container_add(GTK_CONTAINER(scrolledWindow), viewport);
  
  sidebarToolbox.addTool(&toolGrab);
  sidebarToolbox.addTool(&toolRotate);
  sidebarToolbox.addTool(&toolAddRect);
  sidebarToolbox.addTool(&toolAddPolygon);
  
  gtk_widget_show(sidebar);
}

SidebarManager::~SidebarManager() {
  g_object_unref(G_OBJECT(sidebar));
}

void SidebarManager::update() {
  Sidebar *newSidebar = activeSidebar;
  
  newSidebar = window->getActiveTool()->getSidebar();
  
  if(activeSidebar != newSidebar) {
    if(activeSidebar) 
      gtk_container_remove(GTK_CONTAINER(viewport), gtk_bin_get_child(GTK_BIN(viewport)));
    
    gtk_container_add(GTK_CONTAINER(viewport), newSidebar->getWidget());
    
    activeSidebar = newSidebar;
  }
  
  gtk_label_set_text(GTK_LABEL(toolLabel), sidebarToolbox.getActiveTool().getName());
  
  sidebarToolbox.update();
  activeSidebar->update();
}