]> git.decadent.org.uk Git - ion3.git/blobdiff - mod_query/wmessage.c
Imported Upstream version 20090110
[ion3.git] / mod_query / wmessage.c
index aa6002da42518053a62dbe45794929bfee4e5873..096fdcf3888769c678b0700371d62b4f13f61f1d 100644 (file)
@@ -1,21 +1,21 @@
 /*
  * ion/mod_query/wmessage.c
  *
- * Copyright (c) Tuomo Valkonen 1999-2006
+ * Copyright (c) Tuomo Valkonen 1999-2009
  *
- * Ion is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
+ * See the included file LICENSE for details.
  */
 
 #include <string.h>
 
-#include <ioncore/common.h>
 #include <libtu/objp.h>
+#include <ioncore/common.h>
 #include <ioncore/strings.h>
 #include <ioncore/global.h>
 #include <ioncore/event.h>
+#include <ioncore/gr-util.h>
+#include <ioncore/sizehint.h>
+#include <ioncore/resize.h>
 #include "wmessage.h"
 #include "inputp.h"
 
@@ -71,15 +71,43 @@ static void wmsg_calc_size(WMessage *wmsg, WRectangle *geom)
 }
 
 
+void wmsg_size_hints(WMessage *wmsg, WSizeHints *hints_ret)
+{
+    int w=1, h=1;
+    
+    if(WMSG_BRUSH(wmsg)!=NULL){
+        mod_query_get_minimum_extents(WMSG_BRUSH(wmsg), FALSE, &w, &h);
+
+        w+=grbrush_get_text_width(WMSG_BRUSH(wmsg), "xxxxx", 5);
+    }
+    
+    hints_ret->min_set=TRUE;
+    hints_ret->min_width=w;
+    hints_ret->min_height=h;
+}
+
+
 /*}}}*/
 
 
 /*{{{ Draw */
 
 
+GR_DEFATTR(active);
+GR_DEFATTR(inactive);
+
+
+static void init_attr()
+{
+    GR_ALLOCATTR_BEGIN;
+    GR_ALLOCATTR(active);
+    GR_ALLOCATTR(inactive);
+    GR_ALLOCATTR_END;
+}
+
+
 static void wmsg_draw(WMessage *wmsg, bool complete)
 {
-    const char *style=(REGION_IS_ACTIVE(wmsg) ? "active" : "inactive");
     WRectangle geom;
     
     if(WMSG_BRUSH(wmsg)==NULL)
@@ -90,8 +118,12 @@ static void wmsg_draw(WMessage *wmsg, bool complete)
     grbrush_begin(WMSG_BRUSH(wmsg), &geom, 
                   (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
     
+    grbrush_set_attr(WMSG_BRUSH(wmsg), REGION_IS_ACTIVE(wmsg)
+                                       ? GR_ATTR(active)
+                                       : GR_ATTR(inactive));
+    
     draw_listing(WMSG_BRUSH(wmsg), &geom, &(wmsg->listing), 
-                 FALSE, style, style);
+                 FALSE, GRATTR_NONE);
     
     grbrush_end(WMSG_BRUSH(wmsg));
 }
@@ -174,6 +206,8 @@ static bool wmsg_init(WMessage *wmsg, WWindow *par, const WFitParams *fp,
         p=p+l+1;
     }
     
+    init_attr();
+    
     init_listing(&(wmsg->listing));
     setup_listing(&(wmsg->listing), ptr, k, TRUE);
     
@@ -214,12 +248,12 @@ static const char *wmsg_style(WMessage *wmsg)
 
 
 static DynFunTab wmsg_dynfuntab[]={
-    {window_draw,        wmsg_draw},
-    {input_calc_size,     wmsg_calc_size},
-    {input_scrollup,     wmsg_scrollup},
-    {input_scrolldown,    wmsg_scrolldown},
-    {(DynFun*)input_style,
-     (DynFun*)wmsg_style},
+    {window_draw, wmsg_draw},
+    {input_calc_size, wmsg_calc_size},
+    {input_scrollup, wmsg_scrollup},
+    {input_scrolldown, wmsg_scrolldown},
+    {(DynFun*)input_style, (DynFun*)wmsg_style},
+    {region_size_hints, wmsg_size_hints},
     END_DYNFUNTAB
 };