ReactOS  0.4.13-dev-249-gcba1a2f
convert.c File Reference
#include "calc.h"
Include dependency graph for convert.c:

Go to the source code of this file.

Classes

struct  conv_t
 
struct  conv_category_t
 

Macros

#define DECLARE_CONV_CAT(_category)   { IDS_CONV_##_category, conv_##_category },
 
#define DECLARE_CONV_UNIT(_category, _unit, _from, _to)   { IDS_##_category##_##_unit, _from, _to },
 
#define DECLARE_CONV_END   { 0, NULL, NULL },
 

Functions

void ConvExecute (HWND hWnd)
 
void ConvAdjust (HWND hWnd, int n_cat)
 
void ConvInit (HWND hWnd)
 

Variables

static const conv_t conv_ANGLE []
 
static const conv_t conv_AREA []
 
static const conv_t conv_CONSUMPTION []
 
static const conv_t conv_CURRENCY []
 
static const conv_t conv_ENERGY []
 
static const conv_t conv_LENGTH []
 
static const conv_t conv_POWER []
 
static const conv_t conv_PRESSURE []
 
static const conv_t conv_TIME []
 
static const conv_t conv_TEMPERATURE []
 
static const conv_t conv_VELOCITY []
 
static const conv_t conv_VOLUME []
 
static const conv_t conv_WEIGHT []
 
static const conv_category_t conv_table []
 

Macro Definition Documentation

◆ DECLARE_CONV_CAT

#define DECLARE_CONV_CAT (   _category)    { IDS_CONV_##_category, conv_##_category },

Definition at line 57 of file convert.c.

◆ DECLARE_CONV_END

#define DECLARE_CONV_END   { 0, NULL, NULL },

Definition at line 63 of file convert.c.

◆ DECLARE_CONV_UNIT

#define DECLARE_CONV_UNIT (   _category,
  _unit,
  _from,
  _to 
)    { IDS_##_category##_##_unit, _from, _to },

Definition at line 60 of file convert.c.

Function Documentation

◆ ConvAdjust()

void ConvAdjust ( HWND  hWnd,
int  n_cat 
)

Definition at line 621 of file convert.c.

622 {
623  TCHAR txt[128];
624  TCHAR txt_cat[128];
625  HWND hFromWnd = GetDlgItem(hWnd, IDC_COMBO_FROM);
626  HWND hToWnd = GetDlgItem(hWnd, IDC_COMBO_TO);
627  const conv_t *item;
628  unsigned int n;
629 
631  for (n=0; n<SIZEOF(conv_table); n++) {
632  item = conv_table[n].items;
634  if (!_tcscmp(txt_cat, txt))
635  break;
636  }
637 
638  SendMessage(hFromWnd, CB_RESETCONTENT, 0, 0);
639  SendMessage(hToWnd, CB_RESETCONTENT, 0, 0);
640  while (item->unit) {
641  LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
642  SendMessage(hFromWnd, CB_ADDSTRING, 0, (LPARAM)txt);
643  SendMessage(hToWnd, CB_ADDSTRING, 0, (LPARAM)txt);
644  item++;
645  }
646  SendMessage(hFromWnd, CB_SETCURSEL, 0, 0);
647  SendMessage(hToWnd, CB_SETCURSEL, 0, 0);
648 }
Definition: convert.c:46
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define CB_GETLBTEXT
Definition: winuser.h:1913
HWND hWnd
Definition: settings.c:17
GLdouble n
Definition: glext.h:7729
#define SendDlgItemMessage
Definition: winuser.h:5708
const conv_t * items
Definition: convert.c:54
#define SIZEOF(_ar)
Definition: calc.h:97
#define CB_ADDSTRING
Definition: winuser.h:1897
LONG_PTR LPARAM
Definition: windef.h:208
HINSTANCE hInstance
Definition: calc.h:167
#define IDC_COMBO_CATEGORY
Definition: resource.h:107
#define CB_RESETCONTENT
Definition: winuser.h:1920
char TCHAR
Definition: xmlstorage.h:189
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDC_COMBO_FROM
Definition: resource.h:108
#define CB_SETCURSEL
Definition: winuser.h:1922
const DWORD category
Definition: convert.c:53
#define IDC_COMBO_TO
Definition: resource.h:109
static ATOM item
Definition: dde.c:856
static const conv_category_t conv_table[]
Definition: convert.c:552
#define SendMessage
Definition: winuser.h:5709
calc_t calc
Definition: winmain.c:247
#define LoadString
Definition: winuser.h:5685

Referenced by ConvInit(), and DlgMainProc().

◆ ConvExecute()

void ConvExecute ( HWND  hWnd)

Definition at line 568 of file convert.c.

569 {
571  const conv_t *items = NULL;
574  TCHAR txt_cb[128];
575  TCHAR txt[128];
576  const conv_t *item;
577 
578  /* do nothing if the indexes point to the same unit */
579  if (from == to)
580  return;
581 
582  /* Search correct category, since it can be sorted too */
584  for (c_cat=0; c_cat < SIZEOF(conv_table); c_cat++) {
585  LoadString(calc.hInstance, conv_table[c_cat].category, txt, SIZEOF(txt));
586  if (!_tcscmp(txt_cb, txt)) {
587  items = conv_table[c_cat].items;
588  break;
589  }
590  }
591 
592  /* The units can be sorted, so I must search the exact match */
593  item = items;
595  while (item->unit) {
596  LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
597  if (!_tcscmp(txt_cb, txt)) {
598  from = item-items;
599  break;
600  }
601  item++;
602  }
604  item = items;
605  while (item->unit) {
606  LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
607  if (!_tcscmp(txt_cb, txt)) {
608  to = item-items;
609  break;
610  }
611  item++;
612  }
613 
614  calc.Convert[0].data = (char *)items[from].formula_from;
615  calc.Convert[1].data = (char *)items[to].formula_to;
619 }
sequence_t Convert[2]
Definition: calc.h:196
Definition: convert.c:46
UINT wm_msg
Definition: calc.h:151
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define CB_GETLBTEXT
Definition: winuser.h:1913
#define MAKELPARAM(l, h)
Definition: winuser.h:3915
HWND hWnd
Definition: settings.c:17
#define WM_HANDLE_FROM
Definition: calc.h:29
#define SendDlgItemMessage
Definition: winuser.h:5708
const conv_t * items
Definition: convert.c:54
#define DWORD
Definition: nt_native.h:44
#define CB_GETCURSEL
Definition: winuser.h:1904
#define SIZEOF(_ar)
Definition: calc.h:97
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
HINSTANCE hInstance
Definition: calc.h:167
#define IDC_COMBO_CATEGORY
Definition: resource.h:107
#define PostMessage
Definition: winuser.h:5698
char TCHAR
Definition: xmlstorage.h:189
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDC_COMBO_FROM
Definition: resource.h:108
#define WM_START_CONV
Definition: calc.h:28
const DWORD category
Definition: convert.c:53
char * data
Definition: calc.h:149
#define IDC_COMBO_TO
Definition: resource.h:109
static ATOM item
Definition: dde.c:856
static const conv_category_t conv_table[]
Definition: convert.c:552
#define WM_HANDLE_TO
Definition: calc.h:30
CardRegion * from
Definition: spigame.cpp:19
static TCHAR * items[]
Definition: page1.c:45
calc_t calc
Definition: winmain.c:247
#define LoadString
Definition: winuser.h:5685

Referenced by DlgMainProc().

◆ ConvInit()

void ConvInit ( HWND  hWnd)

Definition at line 650 of file convert.c.

651 {
653  TCHAR txt[128];
654  unsigned int n;
655 
656  /* Fill category combo */
657  for (n=0; n<SIZEOF(conv_table); n++) {
659  SendMessage(hCatWnd, CB_ADDSTRING, 0, (LPARAM)txt);
660  }
661  SendMessage(hCatWnd, CB_SETCURSEL, 0, 0);
662  ConvAdjust(hWnd, 0);
663 }
void ConvAdjust(HWND hWnd, int n_cat)
Definition: convert.c:621
HWND hWnd
Definition: settings.c:17
GLdouble n
Definition: glext.h:7729
#define SIZEOF(_ar)
Definition: calc.h:97
#define CB_ADDSTRING
Definition: winuser.h:1897
LONG_PTR LPARAM
Definition: windef.h:208
HINSTANCE hInstance
Definition: calc.h:167
#define IDC_COMBO_CATEGORY
Definition: resource.h:107
char TCHAR
Definition: xmlstorage.h:189
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define CB_SETCURSEL
Definition: winuser.h:1922
const DWORD category
Definition: convert.c:53
static const conv_category_t conv_table[]
Definition: convert.c:552
#define SendMessage
Definition: winuser.h:5709
calc_t calc
Definition: winmain.c:247
#define LoadString
Definition: winuser.h:5685

Referenced by DlgMainProc().

Variable Documentation

◆ conv_ANGLE

const conv_t conv_ANGLE[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 72 of file convert.c.

◆ conv_AREA

const conv_t conv_AREA[]
static

Definition at line 116 of file convert.c.

◆ conv_CONSUMPTION

const conv_t conv_CONSUMPTION[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 159 of file convert.c.

◆ conv_CURRENCY

const conv_t conv_CURRENCY[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 167 of file convert.c.

◆ conv_ENERGY

const conv_t conv_ENERGY[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 204 of file convert.c.

◆ conv_LENGTH

const conv_t conv_LENGTH[]
static

Definition at line 268 of file convert.c.

◆ conv_POWER

const conv_t conv_POWER[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 326 of file convert.c.

◆ conv_PRESSURE

const conv_t conv_PRESSURE[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 344 of file convert.c.

◆ conv_table

const conv_category_t conv_table[]
static
Initial value:
= {
}

Definition at line 552 of file convert.c.

Referenced by ConvAdjust(), ConvExecute(), and ConvInit().

◆ conv_TEMPERATURE

const conv_t conv_TEMPERATURE[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 382 of file convert.c.

◆ conv_TIME

const conv_t conv_TIME[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 364 of file convert.c.

◆ conv_VELOCITY

const conv_t conv_VELOCITY[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 399 of file convert.c.

◆ conv_VOLUME

const conv_t conv_VOLUME[]
static

Definition at line 446 of file convert.c.

◆ conv_WEIGHT

const conv_t conv_WEIGHT[]
static
Initial value:
= {
}
#define DECLARE_CONV_END
Definition: convert.c:63

Definition at line 522 of file convert.c.