/* initGlobals - Allocates or reallocates global variables for the modules.
 *  Could be improved to reallocate space only when it is necessary.
 */
void initGlobals(int ll, int uu, RMat *data)
{ int l, u;
  if (g_logL!=NULL)
  { for (l = 0; l<g_ll; l++)
    { for (u = 0; u<g_uu; u++)
      { freeRVec(g_logL[l][u]);
	freeRVec(g_gamma[l][u]);}
      free(g_logL[l]);
      free(g_gamma[l]);}
    for (u = 0; u<g_uu; u++) free(g_gamma_r[u]);
    free(g_logL);
    free(g_gamma);
    free(g_gamma_r);}
  g_logL = (RVec **)safe_malloc(sizeof(RVec *)*ll);
  g_gamma = (RVec **)safe_malloc(sizeof(RVec *)*ll);
  g_gamma_r = (RVec **)safe_malloc(sizeof(RVec *)*uu);
  for (l = 0; l<ll; l++)
  { g_logL[l] = (RVec *)safe_malloc(sizeof(RVec)*uu);
    g_gamma[l] = (RVec *)safe_malloc(sizeof(RVec)*uu);
    for (u = 0; u<uu; u++)
    { g_logL[l][u] = allocRVec(COLUMNS(data[l]));
      g_gamma[l][u] = allocRVec(COLUMNS(data[l]));}}
  for (u = 0; u<uu; u++)
  { g_gamma_r[u] = (RVec *)safe_malloc(sizeof(RVec)*ll);
    for (l = 0; l<ll; l++) g_gamma_r[u][l] = g_gamma[l][u];}
  g_uu = uu;
  g_ll = ll;}
Пример #2
0
static gint columns_expose(GtkWidget *widget, GdkEventExpose *event)
{
  Columns *cols;
  ColumnsChild *child;
  GList *children;
  GdkEventExpose child_event;

  g_return_val_if_fail(widget != NULL, FALSE);
  g_return_val_if_fail(IS_COLUMNS(widget), FALSE);
  g_return_val_if_fail(event != NULL, FALSE);

  if (GTK_WIDGET_DRAWABLE(widget)) {
    cols = COLUMNS(widget);
    child_event = *event;

    for (children = cols->children; children && (child = children->data);
         children = children->next) {
      if (child->widget && GTK_WIDGET_DRAWABLE(child->widget) &&
          GTK_WIDGET_NO_WINDOW(child->widget) &&
          gtk_widget_intersect(child->widget, &event->area, &child_event.area))
        gtk_widget_event(child->widget, (GdkEvent *)&child_event);
    }
  }
  return FALSE;
}
Пример #3
0
static void columns_forall(GtkContainer *container,
                           gboolean include_internals,
                           GtkCallback callback,
                           gpointer callback_data)
{
  Columns *cols;
  ColumnsChild *child;
  GList *children, *next;

  g_return_if_fail(container != NULL);
  g_return_if_fail(IS_COLUMNS(container));
  g_return_if_fail(callback != NULL);

  cols = COLUMNS(container);

  for (children = cols->children; children && (child = children->data);
       children = next) {
    /*
     * We can't wait until after the callback to assign
     * `children = children->next', because the callback might
     * be gtk_widget_destroy, which would remove the link
     * `children' from the list! So instead we must get our
     * hands on the value of the `next' pointer _before_ the
     * callback.
     */
    next = children->next;
    if (child->widget)
      callback(child->widget, callback_data);
  }
}
Пример #4
0
static void columns_size_allocate(GtkWidget *widget, GtkAllocation *alloc)
{
  Columns *cols;
  ColumnsChild *child;
  GList *children;
  gint border;

  g_return_if_fail(widget != NULL);
  g_return_if_fail(IS_COLUMNS(widget));
  g_return_if_fail(alloc != NULL);

  cols = COLUMNS(widget);
  gtk_widget_set_allocation(widget, alloc);

  border = gtk_container_get_border_width(GTK_CONTAINER(cols));

  columns_alloc_horiz(cols, alloc->width, columns_gtk2_get_width);
  columns_alloc_vert(cols, alloc->height, columns_gtk2_get_height);

  for (children = cols->children; children && (child = children->data);
       children = children->next) {
    if (child->widget && gtk_widget_get_visible(child->widget)) {
      GtkAllocation call;
      call.x = alloc->x + border + child->x;
      call.y = alloc->y + border + child->y;
      call.width = child->w;
      call.height = child->h;
      gtk_widget_size_allocate(child->widget, &call);
    }
  }
}
Пример #5
0
/*
 * Override GtkContainer's focus movement so the user can
 * explicitly specify the tab order.
 */
static gint columns_focus(GtkContainer *container, GtkDirectionType dir)
{
    Columns *cols;
    GList *pos;
    GtkWidget *focuschild;

    g_return_val_if_fail(container != NULL, FALSE);
    g_return_val_if_fail(IS_COLUMNS(container), FALSE);

    cols = COLUMNS(container);

    if (!GTK_WIDGET_DRAWABLE(cols) ||
	!GTK_WIDGET_IS_SENSITIVE(cols))
	return FALSE;

    if (!GTK_WIDGET_CAN_FOCUS(container) &&
	(dir == GTK_DIR_TAB_FORWARD || dir == GTK_DIR_TAB_BACKWARD)) {

	focuschild = container->focus_child;
	gtk_container_set_focus_child(container, NULL);

	if (dir == GTK_DIR_TAB_FORWARD)
	    pos = cols->taborder;
	else
	    pos = g_list_last(cols->taborder);

	while (pos) {
	    GtkWidget *child = pos->data;

	    if (focuschild) {
		if (focuschild == child) {
		    focuschild = NULL; /* now we can start looking in here */
		    if (GTK_WIDGET_DRAWABLE(child) &&
			GTK_IS_CONTAINER(child) &&
			!GTK_WIDGET_HAS_FOCUS(child)) {
			if (gtk_container_focus(GTK_CONTAINER(child), dir))
			    return TRUE;
		    }
		}
	    } else if (GTK_WIDGET_DRAWABLE(child)) {
		if (GTK_IS_CONTAINER(child)) {
		    if (gtk_container_focus(GTK_CONTAINER(child), dir))
			return TRUE;
		} else if (GTK_WIDGET_CAN_FOCUS(child)) {
		    gtk_widget_grab_focus(child);
		    return TRUE;
		}
	    }

	    if (dir == GTK_DIR_TAB_FORWARD)
		pos = pos->next;
	    else
		pos = pos->prev;
	}

	return FALSE;
    } else
	return columns_inherited_focus(container, dir);
}
Пример #6
0
	/**
	 * Functor operator.
	 */
	void operator() (const particles::IParticleDef& def)
	{
		// Add the ".prt" extension to the name fo display in the list
		std::string prtName = def.getName() + ".prt";

		// Add the Def name to the list store
		wxutil::TreeModel::Row row = _store->AddItem();

		row[COLUMNS().name] = prtName;
	}
Пример #7
0
// Create the tree view
wxWindow* ParticlesChooser::createTreeView(wxWindow* parent)
{
	_treeView = wxutil::TreeView::CreateWithModel(parent, _particlesList);
	_treeView->SetSize(300, -1);

	// Single text column
	_treeView->AppendTextColumn(_("Particle"), COLUMNS().name.getColumnIndex(), 
		wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);

	// Apply full-text search to the column
	_treeView->AddSearchColumn(COLUMNS().name);

	// Start loading particles into the view
	populateParticleList();

	// Connect up the selection changed callback
	_treeView->Connect(wxEVT_DATAVIEW_SELECTION_CHANGED, 
		wxDataViewEventHandler(ParticlesChooser::_onSelChanged), NULL, this);

	return _treeView;
}
/* best_state_sequence -
 *  Calculates the best state sequence of entire model given the feature data.
 */
int *best_state_sequence(Model *m, RMat data)
{ int u, uu = m->uu, *rv;
  RVec *logL;
  logL = (RVec *)safe_malloc(uu*sizeof(RVec));
  for (u = 0; u<uu; u++)
  { assert(ROWS(data)==m->ffm[u]->ii);
    logL[u] = allocRVec(COLUMNS(data));
    FFM_logL(m->ffm[u], logL[u], data);}
  rv = HMM_best_state_sequence(m->hmm, logL);
  for (u = 0; u<uu; u++) freeRVec(logL[u]);
  free(logL);
  return rv;}
Пример #9
0
void ParticlesChooser::_onSelChanged(wxDataViewEvent& ev)
{
	// Get the selection and store it
	wxDataViewItem item = _treeView->GetSelection();

	if (item.IsOk())
	{
		wxutil::TreeModel::Row row(item, *_particlesList);
		_selectedParticle = row[COLUMNS().name];

		_preview->setParticle(_selectedParticle);
	}
}
Пример #10
0
void ParticlesChooser::_onSelChanged()
{
	// Get the selection and store it
	Gtk::TreeModel::iterator iter = _selection->get_selected();

	if (iter)
	{
		Gtk::TreeModel::Row row = *iter;
		_selectedParticle = row[COLUMNS().name];

		_preview->setParticle(_selectedParticle);
	}
}
Пример #11
0
static void columns_size_request(GtkWidget *widget, GtkRequisition *req)
{
  Columns *cols;

  g_return_if_fail(widget != NULL);
  g_return_if_fail(IS_COLUMNS(widget));
  g_return_if_fail(req != NULL);

  cols = COLUMNS(widget);

  req->width = columns_compute_width(cols, columns_gtk2_get_width);
  req->height = columns_compute_height(cols, columns_gtk2_get_height);
}
Пример #12
0
/* HMM_initGlobals -
 *  Given a number of states and a sequence length, allocates or reallocates
 *  memory for internal variables.
 */
void HMM_initGlobals(int uu, int tt)
{ if (g_alpha==NULL||COLUMNS(g_alpha)<tt||ROWS(g_alpha)<uu)
  { if (g_alpha!=NULL)
    { freeRMat(g_alpha);
      freeRMat(g_delta);
      freeRMat(g_deltav);	/* This could be int. */
      freeRMat(g_beta);
      freeRMat3d(g_psi);}
    g_alpha = allocRMat(uu, tt);
    g_delta = allocRMat(uu, tt);
    g_deltav = allocRMat(uu, tt); /* This could be int. */
    g_beta = allocRMat(uu, tt);
    g_psi = allocRMat3d(uu, uu, tt);}}
Пример #13
0
void ParticlesChooser::setSelectedParticle(const std::string& particleName)
{
	wxDataViewItem item = _particlesList->FindString(particleName, COLUMNS().name);

	if (item.IsOk())
	{
		_treeView->Select(item);
		_treeView->EnsureVisible(item);

		_preSelectParticle.clear();

		return;
	}
}
/* logLike -
 *  Calculates log likelihood of entire model given the feature data.
 */
Real logLike(Model *m, RMat data)
{ int u, uu = m->uu;
  RVec *logL;
  Real rv;
  logL = (RVec *)safe_malloc(uu*sizeof(RVec));
  for (u = 0; u<uu; u++)
    { assert(ROWS(data)==m->ffm[u]->ii);
      logL[u] = allocRVec(COLUMNS(data));
      FFM_logL(m->ffm[u], logL[u], data);}
  rv = HMM_logL(m->hmm, logL);
  for (u = 0; u<uu; u++) freeRVec(logL[u]);
  free(logL);
  /* needs work: Why is rv divided by the number of features? */
  return rv/model_ii(m);}
Пример #15
0
static void columns_remove(GtkContainer *container, GtkWidget *widget)
{
  Columns *cols;
  ColumnsChild *child;
  GtkWidget *childw;
  GList *children;
  gboolean was_visible;

  g_return_if_fail(container != NULL);
  g_return_if_fail(IS_COLUMNS(container));
  g_return_if_fail(widget != NULL);

  cols = COLUMNS(container);

  for (children = cols->children; children && (child = children->data);
       children = children->next) {
    if (child->widget != widget)
      continue;

    was_visible = gtk_widget_get_visible(widget);
    gtk_widget_unparent(widget);
    cols->children = g_list_remove_link(cols->children, children);
    g_list_free(children);

    if (child->same_height_as) {
      g_return_if_fail(child->same_height_as->same_height_as == child);
      child->same_height_as->same_height_as = NULL;
      if (gtk_widget_get_visible(child->same_height_as->widget))
        gtk_widget_queue_resize(GTK_WIDGET(container));
    }

    g_free(child);
    if (was_visible)
      gtk_widget_queue_resize(GTK_WIDGET(container));
    break;
  }

  for (children = cols->taborder; children && (childw = children->data);
       children = children->next) {
    if (childw != widget)
      continue;

    cols->taborder = g_list_remove_link(cols->taborder, children);
    g_list_free(children);
#if GTK_CHECK_VERSION(2, 0, 0)
    gtk_container_set_focus_chain(container, cols->taborder);
#endif
    break;
  }
}
Пример #16
0
static void columns_get_preferred_width(GtkWidget *widget, gint *min, gint *nat)
{
  Columns *cols;

  g_return_if_fail(widget != NULL);
  g_return_if_fail(IS_COLUMNS(widget));

  cols = COLUMNS(widget);

  if (min)
    *min = columns_compute_width(cols, columns_gtk3_get_min_width);
  if (nat)
    *nat = columns_compute_width(cols, columns_gtk3_get_nat_width);
}
Пример #17
0
static void columns_base_add(GtkContainer *container, GtkWidget *widget)
{
  Columns *cols;

  g_return_if_fail(container != NULL);
  g_return_if_fail(IS_COLUMNS(container));
  g_return_if_fail(widget != NULL);

  cols = COLUMNS(container);

  /*
   * Default is to add a new widget spanning all columns.
   */
  columns_add(cols, widget, 0, 0); /* 0 means ncols */
}
Пример #18
0
// Populate the particles list
void ParticlesChooser::populateParticleList()
{
	_particlesLoader.reset(new ThreadedParticlesLoader(this));
	
	_particlesList->Clear();

	wxutil::TreeModel::Row row = _particlesList->AddItem();

	row[COLUMNS().name] = "Loading...";
	row.SendItemAdded();
	
	GlobalRadiant().getThreadManager().execute(
		boost::bind(&ThreadedParticlesLoader::run, _particlesLoader.get())
    );
}
Пример #19
0
static void columns_unmap(GtkWidget *widget)
{
  Columns *cols;
  ColumnsChild *child;
  GList *children;

  g_return_if_fail(widget != NULL);
  g_return_if_fail(IS_COLUMNS(widget));

  cols = COLUMNS(widget);
  gtk_widget_set_mapped(GTK_WIDGET(cols), FALSE);

  for (children = cols->children; children && (child = children->data);
       children = children->next) {
    if (child->widget && gtk_widget_get_visible(child->widget) &&
        gtk_widget_get_mapped(child->widget))
      gtk_widget_unmap(child->widget);
  }
}
/* logLike_with_box_scores -
 *  Calculates log likelihood of entire model given the feature data.
 */
Real logLike_with_box_scores(Model *m, RMat data, RMat score_mat)
{ int u, uu = m->uu;
  RVec *logL;
  Real rv;
  Real **scores = MATRIX(score_mat);
  logL = (RVec *)safe_malloc(uu*sizeof(RVec));
  printf("1\n");
  for (u = 0; u<uu; u++)
    { //assert(ROWS(data)==m->ffm[u]->ii);
      //if(ROWS(data)!=m->ffm[u]->ii)
      //printf("@@@@@@@@ data->y = %d  m->ffm[u]->ii = %d\n", ROWS(data), m->ffm[u]->ii);
      logL[u] = allocRVec(COLUMNS(data));
      printf("2.1\n");
      FFM_logL_with_box_scores(m->ffm[u], logL[u], data,scores[u]);}
  printf("3\n");
  rv = HMM_logL(m->hmm, logL);
  for (u = 0; u<uu; u++) freeRVec(logL[u]);
  free(logL);
  /* needs work: Why is rv divided by the number of features? */
  return rv/model_ii(m);}
Пример #21
0
static void columns_get_preferred_height_for_width(GtkWidget *widget,
                                                   gint width,
                                                   gint *min,
                                                   gint *nat)
{
  Columns *cols;

  g_return_if_fail(widget != NULL);
  g_return_if_fail(IS_COLUMNS(widget));

  cols = COLUMNS(widget);

  /* FIXME: which one should the get-height function here be? */
  columns_alloc_horiz(cols, width, columns_gtk3_get_nat_width);

  if (min)
    *min = columns_compute_height(cols, columns_gtk3_get_minfw_height);
  if (nat)
    *nat = columns_compute_height(cols, columns_gtk3_get_natfw_height);
}
Пример #22
0
static void columns_remove(GtkContainer *container, GtkWidget *widget)
{
    Columns *cols;
    ColumnsChild *child;
    GtkWidget *childw;
    GList *children;
    gboolean was_visible;

    g_return_if_fail(container != NULL);
    g_return_if_fail(IS_COLUMNS(container));
    g_return_if_fail(widget != NULL);

    cols = COLUMNS(container);

    for (children = cols->children;
         children && (child = children->data);
         children = children->next) {
        if (child->widget != widget)
            continue;

        was_visible = GTK_WIDGET_VISIBLE(widget);
        gtk_widget_unparent(widget);
        cols->children = g_list_remove_link(cols->children, children);
        g_list_free(children);
        g_free(child);
        if (was_visible)
            gtk_widget_queue_resize(GTK_WIDGET(container));
        break;
    }

    for (children = cols->taborder;
         children && (childw = children->data);
         children = children->next) {
        if (childw != widget)
            continue;

        cols->taborder = g_list_remove_link(cols->taborder, children);
        g_list_free(children);
        break;
    }
}
Пример #23
0
/*
 * These appear to be thoroughly tedious functions; the only reason
 * we have to reimplement them at all is because we defined our own
 * format for our GList of children...
 */
static void columns_map(GtkWidget *widget)
{
    Columns *cols;
    ColumnsChild *child;
    GList *children;

    g_return_if_fail(widget != NULL);
    g_return_if_fail(IS_COLUMNS(widget));

    cols = COLUMNS(widget);
    GTK_WIDGET_SET_FLAGS(cols, GTK_MAPPED);

    for (children = cols->children;
         children && (child = children->data);
         children = children->next) {
        if (child->widget &&
	    GTK_WIDGET_VISIBLE(child->widget) &&
            !GTK_WIDGET_MAPPED(child->widget))
            gtk_widget_map(child->widget);
    }
}
Пример #24
0
static void columns_draw(GtkWidget *widget, GdkRectangle *area)
{
  Columns *cols;
  ColumnsChild *child;
  GList *children;
  GdkRectangle child_area;

  g_return_if_fail(widget != NULL);
  g_return_if_fail(IS_COLUMNS(widget));

  if (GTK_WIDGET_DRAWABLE(widget)) {
    cols = COLUMNS(widget);

    for (children = cols->children; children && (child = children->data);
         children = children->next) {
      if (child->widget && GTK_WIDGET_DRAWABLE(child->widget) &&
          gtk_widget_intersect(child->widget, area, &child_area))
        gtk_widget_draw(child->widget, &child_area);
    }
  }
}
Пример #25
0
ParticlesChooser::ParticlesChooser() :
	gtkutil::BlockingTransientWindow(_("Choose particles"), GlobalMainFrame().getTopLevelWindow()),
	_particlesList(Gtk::ListStore::create(COLUMNS())),
	_selectedParticle(""),
	_preview(new gtkutil::ParticlePreview)
{
	set_border_width(12);

	// Set the default size of the window
	const Glib::RefPtr<Gtk::Window>& mainWindow = GlobalMainFrame().getTopLevelWindow();

	Gdk::Rectangle rect = gtkutil::MultiMonitor::getMonitorForWindow(mainWindow);
	int height = static_cast<int>(rect.get_height() * 0.6f);

	set_default_size(
		static_cast<int>(rect.get_width() * 0.4f), height
	);

	// Set the default size of the window
	_preview->setSize(rect.get_width() * 0.2f, height);

	// Main dialog vbox
	Gtk::VBox* vbox = Gtk::manage(new Gtk::VBox(false, 12));

	// Create a horizontal box to pack the treeview on the left and the preview on the right
	Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox(false, 6));

	hbox->pack_start(createTreeView(), true, true, 0);

	Gtk::VBox* previewBox = Gtk::manage(new Gtk::VBox(false, 0));
	previewBox->pack_start(*_preview, true, true, 0);

	hbox->pack_start(*previewBox, true, true, 0);

	vbox->pack_start(*hbox, true, true, 0);
	vbox->pack_end(createButtons(), false, false, 0);

	// Add main vbox to dialog
	add(*vbox);
}
Пример #26
0
// Create the tree view
Gtk::Widget& ParticlesChooser::createTreeView()
{
	_treeView = Gtk::manage(new Gtk::TreeView(_particlesList));

	_treeView->set_size_request(300, -1);

	// Single text column
	_treeView->append_column(*Gtk::manage(new gtkutil::TextColumn(_("Particle"), COLUMNS().name, false)));

	// Apply full-text search to the column
	_treeView->set_search_equal_func(sigc::ptr_fun(gtkutil::TreeModel::equalFuncStringContains));

	// Populate with particle names
	populateParticleList();

	// Connect up the selection changed callback
	_selection = _treeView->get_selection();
	_selection->signal_changed().connect(sigc::mem_fun(*this, &ParticlesChooser::_onSelChanged));

	// Pack into scrolled window and return
	return *Gtk::manage(new gtkutil::ScrolledFrame(*_treeView));
}
Пример #27
0
ParticlesChooser::ParticlesChooser() :
	DialogBase(_("Choose particles")),
	_particlesList(new wxutil::TreeModel(COLUMNS(), true)),
	_selectedParticle(""),
	_preview(new wxutil::ParticlePreview(this))
{
	// Connect the finish callback to load the treestore
	Connect(wxutil::EV_TREEMODEL_POPULATION_FINISHED, 
		TreeModelPopulationFinishedHandler(ParticlesChooser::onTreeStorePopulationFinished), NULL, this);

	SetSizer(new wxBoxSizer(wxVERTICAL));
	
	wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);

	hbox->Add(createTreeView(this), 1, wxEXPAND);
	hbox->Add(_preview->getWidget(), 0, wxEXPAND | wxLEFT, 6);

	GetSizer()->Add(hbox, 1, wxEXPAND | wxALL, 12);
	GetSizer()->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_RIGHT | wxBOTTOM | wxLEFT | wxRIGHT, 12);

	FitToScreen(0.5f, 0.6f);
}
Пример #28
0
static void columns_size_request(GtkWidget *widget, GtkRequisition *req)
{
    Columns *cols;
    ColumnsChild *child;
    GList *children;
    gint i, ncols, colspan, *colypos;
    const gint *percentages;
    static const gint onecol[] = { 100 };

    g_return_if_fail(widget != NULL);
    g_return_if_fail(IS_COLUMNS(widget));
    g_return_if_fail(req != NULL);

    cols = COLUMNS(widget);

    req->width = 0;
    req->height = cols->spacing;

    ncols = 1;
    colypos = g_new(gint, 1);
    colypos[0] = 0;
    percentages = onecol;

    for (children = cols->children;
         children && (child = children->data);
         children = children->next) {
        GtkRequisition creq;

	if (!child->widget) {
	    /* Column reconfiguration. */
	    for (i = 1; i < ncols; i++) {
		if (colypos[0] < colypos[i])
		    colypos[0] = colypos[i];
	    }
	    ncols = child->ncols;
	    percentages = child->percentages;
	    colypos = g_renew(gint, colypos, ncols);
	    for (i = 1; i < ncols; i++)
		colypos[i] = colypos[0];
	    continue;
	}

        /* Only take visible widgets into account. */
        if (!GTK_WIDGET_VISIBLE(child->widget))
            continue;

        gtk_widget_size_request(child->widget, &creq);
	colspan = child->colspan ? child->colspan : ncols-child->colstart;

        /*
         * To compute width: we know that creq.width plus
         * cols->spacing needs to equal a certain percentage of the
         * full width of the container. So we work this value out,
         * figure out how wide the container will need to be to
         * make that percentage of it equal to that width, and
         * ensure our returned width is at least that much. Very
         * simple really.
         */
        {
            int percent, thiswid, fullwid;

            percent = 0;
            for (i = 0; i < colspan; i++)
                percent += percentages[child->colstart+i];

            thiswid = creq.width + cols->spacing;
            /*
             * Since creq is the _minimum_ size the child needs, we
             * must ensure that it gets _at least_ that size.
             * Hence, when scaling thiswid up to fullwid, we must
             * round up, which means adding percent-1 before
             * dividing by percent.
             */
            fullwid = (thiswid * 100 + percent - 1) / percent;

            /*
             * The above calculation assumes every widget gets
             * cols->spacing on the right. So we subtract
             * cols->spacing here to account for the extra load of
             * spacing on the right.
             */
            if (req->width < fullwid - cols->spacing)
                req->width = fullwid - cols->spacing;
        }

        /*
         * To compute height: the widget's top will be positioned
         * at the largest y value so far reached in any of the
         * columns it crosses. Then it will go down by creq.height
         * plus padding; and the point it reaches at the bottom is
         * the new y value in all those columns, and minus the
         * padding it is also a lower bound on our own size
         * request.
         */
        {
            int topy, boty;

            topy = 0;
            for (i = 0; i < colspan; i++) {
                if (topy < colypos[child->colstart+i])
                    topy = colypos[child->colstart+i];
            }
            boty = topy + creq.height + cols->spacing;
            for (i = 0; i < colspan; i++) {
                colypos[child->colstart+i] = boty;
            }

            if (req->height < boty - cols->spacing)
                req->height = boty - cols->spacing;
        }
    }

    req->width += 2*GTK_CONTAINER(cols)->border_width;
    req->height += 2*GTK_CONTAINER(cols)->border_width;

    g_free(colypos);
}
Пример #29
0
static void columns_size_allocate(GtkWidget *widget, GtkAllocation *alloc)
{
    Columns *cols;
    ColumnsChild *child;
    GList *children;
    gint i, ncols, colspan, border, *colxpos, *colypos;
    const gint *percentages;
    static const gint onecol[] = { 100 };

    g_return_if_fail(widget != NULL);
    g_return_if_fail(IS_COLUMNS(widget));
    g_return_if_fail(alloc != NULL);

    cols = COLUMNS(widget);
    widget->allocation = *alloc;
    border = GTK_CONTAINER(cols)->border_width;

    ncols = 1;
    percentages = onecol;
    /* colxpos gives the starting x position of each column.
     * We supply n+1 of them, so that we can find the RH edge easily.
     * All ending x positions are expected to be adjusted afterwards by
     * subtracting the spacing. */
    colxpos = g_new(gint, 2);
    colxpos[0] = 0;
    colxpos[1] = alloc->width - 2*border + cols->spacing;
    /* As in size_request, colypos is the lowest y reached in each column. */
    colypos = g_new(gint, 1);
    colypos[0] = 0;

    for (children = cols->children;
         children && (child = children->data);
         children = children->next) {
        GtkRequisition creq;
        GtkAllocation call;

	if (!child->widget) {
	    gint percent;

	    /* Column reconfiguration. */
	    for (i = 1; i < ncols; i++) {
		if (colypos[0] < colypos[i])
		    colypos[0] = colypos[i];
	    }
	    ncols = child->ncols;
	    percentages = child->percentages;
	    colypos = g_renew(gint, colypos, ncols);
	    for (i = 1; i < ncols; i++)
		colypos[i] = colypos[0];
	    colxpos = g_renew(gint, colxpos, ncols + 1);
	    colxpos[0] = 0;
	    percent = 0;
	    for (i = 0; i < ncols; i++) {
		percent += percentages[i];
		colxpos[i+1] = (((alloc->width - 2*border) + cols->spacing)
				* percent / 100);
	    }
	    continue;
	}

        /* Only take visible widgets into account. */
        if (!GTK_WIDGET_VISIBLE(child->widget))
            continue;

        gtk_widget_get_child_requisition(child->widget, &creq);
	colspan = child->colspan ? child->colspan : ncols-child->colstart;

        /*
         * Starting x position is cols[colstart].
         * Ending x position is cols[colstart+colspan] - spacing.
	 * 
	 * Unless we're forcing left, in which case the width is
	 * exactly the requisition width.
         */
        call.x = alloc->x + border + colxpos[child->colstart];
	if (child->force_left)
	    call.width = creq.width;
	else
	    call.width = (colxpos[child->colstart+colspan] -
			  colxpos[child->colstart] - cols->spacing);

        /*
         * To compute height: the widget's top will be positioned
         * at the largest y value so far reached in any of the
         * columns it crosses. Then it will go down by creq.height
         * plus padding; and the point it reaches at the bottom is
         * the new y value in all those columns.
         */
        {
            int topy, boty;

            topy = 0;
            for (i = 0; i < colspan; i++) {
                if (topy < colypos[child->colstart+i])
                    topy = colypos[child->colstart+i];
            }
            call.y = alloc->y + border + topy;
            call.height = creq.height;
            boty = topy + creq.height + cols->spacing;
            for (i = 0; i < colspan; i++) {
                colypos[child->colstart+i] = boty;
            }
        }

        gtk_widget_size_allocate(child->widget, &call);
    }

    g_free(colxpos);
    g_free(colypos);    
}
Пример #30
0
	/**
	 * Constructor.
	 */
	ThreadedParticlesLoader(wxEvtHandler* finishedHandler) : 
		_store(new wxutil::TreeModel(COLUMNS(), true)),
		_finishedHandler(finishedHandler)
	{}