ReactOS  0.4.12-dev-43-g63b00d8
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 37 of file convert.c.

◆ DECLARE_CONV_END

#define DECLARE_CONV_END   { 0, NULL, NULL },

Definition at line 43 of file convert.c.

◆ DECLARE_CONV_UNIT

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

Definition at line 40 of file convert.c.

Function Documentation

◆ ConvAdjust()

void ConvAdjust ( HWND  hWnd,
int  n_cat 
)

Definition at line 586 of file convert.c.

Referenced by ConvInit(), and DlgMainProc().

587 {
588  TCHAR txt[128];
589  TCHAR txt_cat[128];
590  HWND hFromWnd = GetDlgItem(hWnd, IDC_COMBO_FROM);
591  HWND hToWnd = GetDlgItem(hWnd, IDC_COMBO_TO);
592  const conv_t *item;
593  unsigned int n;
594 
595  SendDlgItemMessage(hWnd, IDC_COMBO_CATEGORY, CB_GETLBTEXT, n_cat, (LPARAM)txt_cat);
596  for (n=0; n<SIZEOF(conv_table); n++) {
597  item = conv_table[n].items;
599  if (!_tcscmp(txt_cat, txt))
600  break;
601  }
602 
603  SendMessage(hFromWnd, CB_RESETCONTENT, 0, 0);
604  SendMessage(hToWnd, CB_RESETCONTENT, 0, 0);
605  while (item->unit) {
606  LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
607  SendMessage(hFromWnd, CB_ADDSTRING, 0, (LPARAM)txt);
608  SendMessage(hToWnd, CB_ADDSTRING, 0, (LPARAM)txt);
609  item++;
610  }
611  SendMessage(hFromWnd, CB_SETCURSEL, 0, 0);
612  SendMessage(hToWnd, CB_SETCURSEL, 0, 0);
613 }
DWORD unit
Definition: convert.c:27
Definition: convert.c:26
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define CB_GETLBTEXT
Definition: winuser.h:1913
#define SendDlgItemMessage
Definition: winuser.h:5708
const conv_t * items
Definition: convert.c:34
GLuint n
Definition: s_context.h:57
#define SIZEOF(_ar)
Definition: calc.h:48
LONG_PTR LPARAM
Definition: windef.h:208
#define CB_ADDSTRING
Definition: winuser.h:1897
HINSTANCE hInstance
Definition: calc.h:118
#define IDC_COMBO_CATEGORY
Definition: resource.h:100
#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:101
#define CB_SETCURSEL
Definition: winuser.h:1922
const DWORD category
Definition: convert.c:33
#define IDC_COMBO_TO
Definition: resource.h:102
static ATOM item
Definition: dde.c:856
static const conv_category_t conv_table[]
Definition: convert.c:517
#define SendMessage
Definition: winuser.h:5709
calc_t calc
Definition: winmain.c:226
#define LoadString
Definition: winuser.h:5685

◆ ConvExecute()

void ConvExecute ( HWND  hWnd)

Definition at line 533 of file convert.c.

Referenced by DlgMainProc().

534 {
536  const conv_t *items = NULL;
539  TCHAR txt_cb[128];
540  TCHAR txt[128];
541  const conv_t *item;
542 
543  /* do nothing if the indexes point to the same unit */
544  if (from == to)
545  return;
546 
547  /* Search correct category, since it can be sorted too */
549  for (c_cat=0; c_cat < SIZEOF(conv_table); c_cat++) {
550  LoadString(calc.hInstance, conv_table[c_cat].category, txt, SIZEOF(txt));
551  if (!_tcscmp(txt_cb, txt)) {
552  items = conv_table[c_cat].items;
553  break;
554  }
555  }
556 
557  /* The units can be sorted, so I must search the exact match */
558  item = items;
559  SendDlgItemMessage(hWnd, IDC_COMBO_FROM, CB_GETLBTEXT, from, (LPARAM)txt_cb);
560  while (item->unit) {
561  LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
562  if (!_tcscmp(txt_cb, txt)) {
563  from = item-items;
564  break;
565  }
566  item++;
567  }
568  SendDlgItemMessage(hWnd, IDC_COMBO_TO, CB_GETLBTEXT, to, (LPARAM)txt_cb);
569  item = items;
570  while (item->unit) {
571  LoadString(calc.hInstance, item->unit, txt, SIZEOF(txt));
572  if (!_tcscmp(txt_cb, txt)) {
573  to = item-items;
574  break;
575  }
576  item++;
577  }
578 
579  calc.Convert[0].data = (char *)items[from].formula_from;
580  calc.Convert[1].data = (char *)items[to].formula_to;
584 }
DWORD unit
Definition: convert.c:27
sequence_t Convert[2]
Definition: calc.h:145
Definition: convert.c:26
UINT wm_msg
Definition: calc.h:102
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define CB_GETLBTEXT
Definition: winuser.h:1913
#define DWORD
Definition: msvc.h:34
#define MAKELPARAM(l, h)
Definition: winuser.h:3915
#define WM_HANDLE_FROM
Definition: calc.h:21
#define SendDlgItemMessage
Definition: winuser.h:5708
const conv_t * items
Definition: convert.c:34
#define CB_GETCURSEL
Definition: winuser.h:1904
#define SIZEOF(_ar)
Definition: calc.h:48
LONG_PTR LPARAM
Definition: windef.h:208
smooth NULL
Definition: ftsmooth.c:416
HINSTANCE hInstance
Definition: calc.h:118
#define IDC_COMBO_CATEGORY
Definition: resource.h:100
#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:101
#define WM_START_CONV
Definition: calc.h:20
const DWORD category
Definition: convert.c:33
char * data
Definition: calc.h:100
#define IDC_COMBO_TO
Definition: resource.h:102
static ATOM item
Definition: dde.c:856
static const conv_category_t conv_table[]
Definition: convert.c:517
#define WM_HANDLE_TO
Definition: calc.h:22
CardRegion * from
Definition: spigame.cpp:19
static TCHAR * items[]
Definition: page1.c:45
calc_t calc
Definition: winmain.c:226
#define LoadString
Definition: winuser.h:5685

◆ ConvInit()

void ConvInit ( HWND  hWnd)

Definition at line 615 of file convert.c.

Referenced by DlgMainProc().

616 {
617  HWND hCatWnd = GetDlgItem(hWnd, IDC_COMBO_CATEGORY);
618  TCHAR txt[128];
619  unsigned int n;
620 
621  /* Fill category combo */
622  for (n=0; n<SIZEOF(conv_table); n++) {
624  SendMessage(hCatWnd, CB_ADDSTRING, 0, (LPARAM)txt);
625  }
626  SendMessage(hCatWnd, CB_SETCURSEL, 0, 0);
627  ConvAdjust(hWnd, 0);
628 }
void ConvAdjust(HWND hWnd, int n_cat)
Definition: convert.c:586
GLuint n
Definition: s_context.h:57
#define SIZEOF(_ar)
Definition: calc.h:48
LONG_PTR LPARAM
Definition: windef.h:208
#define CB_ADDSTRING
Definition: winuser.h:1897
HINSTANCE hInstance
Definition: calc.h:118
#define IDC_COMBO_CATEGORY
Definition: resource.h:100
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:33
static const conv_category_t conv_table[]
Definition: convert.c:517
#define SendMessage
Definition: winuser.h:5709
calc_t calc
Definition: winmain.c:226
#define LoadString
Definition: winuser.h:5685

Variable Documentation

◆ conv_ANGLE

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

Definition at line 50 of file convert.c.

◆ conv_AREA

const conv_t conv_AREA[]
static

Definition at line 92 of file convert.c.

◆ conv_CONSUMPTION

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

Definition at line 135 of file convert.c.

◆ conv_CURRENCY

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

Definition at line 143 of file convert.c.

◆ conv_ENERGY

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

Definition at line 180 of file convert.c.

◆ conv_LENGTH

const conv_t conv_LENGTH[]
static

Definition at line 244 of file convert.c.

◆ conv_POWER

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

Definition at line 302 of file convert.c.

◆ conv_PRESSURE

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

Definition at line 320 of file convert.c.

◆ conv_table

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

Definition at line 517 of file convert.c.

◆ conv_TEMPERATURE

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

Definition at line 358 of file convert.c.

◆ conv_TIME

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

Definition at line 340 of file convert.c.

◆ conv_VELOCITY

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

Definition at line 375 of file convert.c.

◆ conv_VOLUME

const conv_t conv_VOLUME[]
static

Definition at line 422 of file convert.c.

◆ conv_WEIGHT

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

Definition at line 487 of file convert.c.