2006-07-31

CSS Basic layout

This has:
  • Top div, includes logo and "slogan"
  • Left side menu bar
  • Main content
Surely not foolproof but it works. position: absolute and margin-{top,left}: {px,%} are used in positioning.
body {
  font-family: verdana, "trebuchet MS", helvetica, sans-serif;  
  margin: 35px;
  text-align: center; /* IE hack */
}

img { border: 0px; }

#main {
  margin: 0 auto 0 auto;
  text-align: left;
}

#top {
  position: absolute;
  margin: 0px;
  height: 100px;
}

#logo { float: left; }

#slogan {
  float: right;
  font-size: large;
  font-weight: bold;
  margin-right: 35px;
  margin-top: 35px;
}

#menu {
  position: absolute;
  float: left;
  width: 25%;
  margin-top: 120px;
}

#content {
  position: absolute;
  padding: 5px;
  margin-top: 120px;
  margin-left: 25%;
  width: 70%;
}

Center content using CSS

With IE (v. 6 at least), things can get quite ugly. One has to use all sorts of dirty little tricks to make stuff render in at least approximately similar way across browsers. Here we center a fixed width <div id="main"/> on the page:

body {
 ...
 text-align: center; /* IE hack */
 ...
}

#main {  /* the main container div */
 min-height: 555px;
 height: 555px;
 min-width: 888px;
 width: 888px;
 margin: 0 auto 0 auto;
 text-align: left;  /* "cancel" the IE hack above */
}

2006-07-26

GtkTreeView, GtkListStore basics

enum
  {
    COLUMN_ID,
    N_COLUMNS
  };

GtkListStore *store;
GtkTreeIter iter;
GtkWidget *view;
GtkCellRenderer *renderer;
GtkTreeSelection *selection;


store =gtk_list_store_new( N_COLUMNS, G_TYPE_INT);

// gtk_list_store_clear( store);

gtk_list_store_append( store, &iter);
gtk_list_store_set( store, &iter,
      COLUMN_ID, ( guint) some_int_value,
      -1);


/* ... */


view =gtk_tree_view_new_with_model( GTK_TREE_MODEL( store));

renderer =gtk_cell_renderer_text_new( );

gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW( view),
          -1,
          "Id",
          renderer,
          "text",
          COLUMN_ID,
          NULL);

selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view));

gtk_tree_selection_set_mode( selection, GTK_SELECTION_SINGLE);

g_signal_connect( G_OBJECT( selection), "changed",
    G_CALLBACK( selection_changed_cb),
    NULL);


/* ... */


static void selection_changed_cb( GtkTreeSelection *selection, gpointer data)
{
  GtkTreeIter iter;
  GtkTreeModel *model;
  int id;

    if( gtk_tree_selection_get_selected( selection, &model, &iter))
    {
      gtk_tree_model_get( model, &iter, COLUMN_ID, &id, -1);
      /* do something w/id... */
    }
}

2006-07-06

xmalloc(), xfree()

void *xmalloc(size_t size)
{
  void *ptr =malloc( size);
  if( ptr ==NULL)
    diediedie( "xmalloc(): out of memory");
  return ptr;
}

void xfree(void *ptr)
{
  if( ptr ==NULL)
    diediedie( "xfree(): NULL argument");
  free( ptr);
}

2006-07-01

SQLite, prepare/step/finalize

rc =sqlite3_prepare( Db, qry_getnewid, -1, &stmt, NULL);
if( SQLITE_OK !=rc)
  diediedie( "...");

rc =sqlite3_step( stmt);
if( SQLITE_ROW !=rc)
  {
    sqlite3_finalize( stmt);
    diediedie( "...");
  }

...

a->id =sqlite3_column_int( stmt, 0);

...

sqlite3_finalize( stmt);

SQLite, open db and exec sql

rc =sqlite3_open(DB_FILENAME, &Db);
if( rc)
  diediedie( "...");

rc =sqlite3_exec( Db, tbldef_accounts, NULL, 0, &zErrMsg);
if( SQLITE_OK !=rc)
  diediedie( zErrMsg);

...

sqlite3_close( Db);